Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter dsanderling

    (@dsanderling)

    I think I have a workaround. I added the following code to functions.php:

     //I found this part on stackexchange
      if (!function_exists('is_rest')) {
        /**
         * Checks if the current request is a WP REST API request.
         * 
         * Case #1: After WP_REST_Request initialisation
         * Case #2: Support "plain" permalink settings
         * Case #3: URL Path begins with wp-json/ (your REST prefix)
         *          Also supports WP installations in subfolders
         * 
         * @returns boolean
         * @author matzeeable
         */
        function is_rest() {
            $prefix = rest_get_url_prefix( );
            if (defined('REST_REQUEST') && REST_REQUEST // (#1)
                || isset($_GET['rest_route']) // (#2)
                    && strpos( trim( $_GET['rest_route'], '\\/' ), $prefix , 0 ) === 0)
                return true;
    
            // (#3)
            $rest_url = wp_parse_url( site_url( $prefix ) );
            $current_url = wp_parse_url( add_query_arg( array( ) ) );
            return strpos( $current_url['path'], $rest_url['path'], 0 ) === 0;
        }
    }

    And I added the && !is_rest() to this if-block, also in functions.php:

    	// Display the default style of the plugin.
    	if ( $args['styles_default'] === true && !is_rest()) {
    		rpwe_custom_styles();
    	}

    I do worry about updates to this plugin breaking my fix, so mayyyybe you could add something like this to the plugin code… 🙂 thank you.

    Actually you can do it with the “Allow PHP in Posts and Pages” plugin you speak of. (I’m using the same one. ;)) You just have to use square brackets instead of angle brackets, so WP doesn’t do it’s black magic on your html tags.

    Example:
    echo ‘[table cellpadding=”0″ cellspacing=”0″]’;
    foreach($myjson->beefs as $beef)
    {
    echo ‘[tr][td]’ . $beef->name . ‘[/td][td]’ . $beef->unit_price . ‘[/td][/tr]’;
    }
    echo ‘[/table]’;

Viewing 2 replies - 1 through 2 (of 2 total)