Giter Site home page Giter Site logo

braadmartin / genesis-rest-api-integration Goto Github PK

View Code? Open in Web Editor NEW
7.0 7.0 0.0 188 KB

A WordPress plugin for adding content output from the Genesis Framework hooks to the response data for posts, pages, and custom post types when using the WP REST API v2.

License: GNU General Public License v2.0

PHP 100.00%

genesis-rest-api-integration's People

Contributors

braadmartin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

genesis-rest-api-integration's Issues

Use a better route name for CPTs

Currently the core routes for posts and pages are /posts/ and /pages/, but we're currently using the CPT 'names' which are generally singular, like movie or book.

I need to look more closely at how core determines what route names to use, as in whether they have a formula for building the route names based on the official post type name.

Ideally the routes for CPTs would be plural to match the core routes, so /movie/ would be /movies/

Possible risk in redeclaring stuff

Hey B-raad. I was just messing around to see how this could be automated further with something like:

// Set up an array of all the genesis hooks we'll support.
global $wp_filter;

$genesis_hooks = array();

foreach ( $wp_filter as $filter => $filter_data ) {

    if ( false !== strpos( $filter, 'genesis' ) ) {
        $genesis_hooks[] = $filter;
    }

}

Checks all hooks and then grabs just the ones containing 'genesis'. When I did this, I got a ton of PHP issue:

Notice: Constant PARENT_THEME_NAME already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 97

Notice: Constant PARENT_THEME_VERSION already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 98

Notice: Constant PARENT_THEME_BRANCH already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 99

Notice: Constant PARENT_DB_VERSION already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 100

Notice: Constant PARENT_THEME_RELEASE_DATE already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 101

Notice: Constant PARENT_DIR already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 105

Notice: Constant CHILD_DIR already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 106

Notice: Constant GENESIS_IMAGES_DIR already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 107

Notice: Constant GENESIS_LIB_DIR already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 108

Notice: Constant GENESIS_ADMIN_DIR already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 109

Notice: Constant GENESIS_ADMIN_IMAGES_DIR already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 110

Notice: Constant GENESIS_JS_DIR already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 111

Notice: Constant GENESIS_CSS_DIR already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 112

Notice: Constant GENESIS_CLASSES_DIR already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 113

Notice: Constant GENESIS_FUNCTIONS_DIR already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 114

Notice: Constant GENESIS_SHORTCODES_DIR already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 115

Notice: Constant GENESIS_STRUCTURE_DIR already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 116

Notice: Constant GENESIS_TOOLS_DIR already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 117

Notice: Constant GENESIS_WIDGETS_DIR already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 118

Notice: Constant PARENT_URL already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 121

Notice: Constant CHILD_URL already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 122

Notice: Constant GENESIS_IMAGES_URL already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 123

Notice: Constant GENESIS_LIB_URL already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 124

Notice: Constant GENESIS_ADMIN_URL already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 125

Notice: Constant GENESIS_ADMIN_IMAGES_URL already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 126

Notice: Constant GENESIS_JS_URL already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 127

Notice: Constant GENESIS_CLASSES_URL already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 128

Notice: Constant GENESIS_CSS_URL already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 129

Notice: Constant GENESIS_FUNCTIONS_URL already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 130

Notice: Constant GENESIS_SHORTCODES_URL already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 131

Notice: Constant GENESIS_STRUCTURE_URL already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 132

Notice: Constant GENESIS_WIDGETS_URL already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 133

Notice: Constant GENESIS_SETTINGS_FIELD already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 136

Notice: Constant GENESIS_SEO_SETTINGS_FIELD already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 137

Notice: Constant GENESIS_CPT_ARCHIVE_SETTINGS_FIELD_PREFIX already defined in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/init.php on line 138

Fatal error: Cannot redeclare class Genesis_Breadcrumb in /srv/www/wordpress-trunk/wp-content/themes/genesis/lib/classes/breadcrumb.php on line 24

The only fatal one is the following:

**Fatal error**:  Cannot redeclare class Genesis_Breadcrumb in **/srv/www/wordpress-trunk/wp-content/themes/genesis/lib/classes/breadcrumb.php** on line **24**

Given, this issue didn't arise with the manually created array of Genesis hooks you've added, but it does make me wonder about the possibility of forcing hooks to run twice that were only meant to run once. The breadcrumb example is one of these, in which a class ends up being defined twice (shame on the dev who's not checking if the class is already defined).

Here's a potential example where things might also get wonky:

add_action( 'genesis_init', function(){
    STATIC $count = 1;
    echo $count++;
});

If your run this code, you'll see that your call of do_action( $genesis_hook ); might cause the static variable to get incremented in a way that's probably not desirable. So genesis_init is clearly not a safe hook to call twice, and my method of auto-detecting genesis hooks maybe isn't such a great idea, but it always brings up the question of whether or not there are other hooks that might get called twice and have negative consequences. I have no idea :)

Thought I'd let you think on this one for a bit. . . I tried just removing genesis_init from the array, and things still fail with just a blank screen - not sure what's going on there. My thought is that it'd be best to just stick with your manually create array of hooks, but possibly think on possible negative affects of calling any of those with do_action() more than once, and if that might ever occur.

Looks awesome though!!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.