Skip to content

Commit

Permalink
Issue #120 - Attempt to improved performance for Parent Page pull dow…
Browse files Browse the repository at this point in the history
…n for hierarchical post types
  • Loading branch information
bobbingwide committed Feb 1, 2019
1 parent 8bb8240 commit 08d573e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
54 changes: 54 additions & 0 deletions oik.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function oik_plugin_file_loaded() {
add_action( 'admin_enqueue_scripts', 'add_thickbox' );
}
add_action( 'init', 'oik_main_init', 20 );
add_action( 'rest_api_init', 'oik_rest_api_init', 20 );

add_filter( "attachment_fields_to_edit", "oik_attachment_fields_to_edit", null, 2 );
add_filter( "attachment_fields_to_save", "oik_attachment_fields_to_save", null, 2 );
Expand Down Expand Up @@ -443,6 +444,59 @@ function oik_oik_sc__help( $help, $shortcode ) {
$help = oik_lazy_sc__help( $help, $shortcode );
return $help;
}


/**
* Implements 'rest_api_init'
*
* Disables the_content processing to save time when the request doesn't need it.
*
*/
function oik_rest_api_init() {
$context = bw_array_get( $_REQUEST, 'context', null );
if ( $context === 'edit') {
remove_all_filters("the_content");
}

}

function oik_is_rest() {
$is_rest = defined( 'REST_REQUEST' ) && REST_REQUEST;
return $is_rest;
}

function oik_is_block_editor() {
$is_block_editor = false;
if ( function_exists( "get_current_screen" ) ) {
$current_screen = get_current_screen();
bw_trace2( $current_screen, "current_screen" );
$is_block_editor = $current_screen && $current_screen->is_block_editor();
} else {
bw_backtrace();
bw_trace2("get_current_screen", "function does not exist", null, BW_TRACE_DEBUG);
}
return $is_block_editor;
}

function oik_is_block_renderer( $renderer=null ) {
static $is_block_renderer = false;
if ( $renderer !== null ) {
$is_block_renderer = $renderer;
}
return $is_block_renderer;
}

function oik_is_shortcode_expansion_necessary() {
$shortcode_expansion_necessary = true;
if ( oik_is_rest() ) {
if ( oik_is_block_renderer() ) {
// We need to do this
} else {
$shortcode_expansion_necessary = false;
}
}
return $shortcode_expansion_necessary;
}

/**
* Initiate oik processing
Expand Down
4 changes: 3 additions & 1 deletion shortcodes/oik-bob-bing-wide.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ function bw_wp( $suffix=false ) {
*/
function bw_editcss( $atts=null ) {
$theme = bw_get_theme();
oik_custom_css( $theme );
if ( function_exists( "oik_custom_css") ) {
oik_custom_css( $theme );
}
return( bw_ret());
}

Expand Down
4 changes: 4 additions & 0 deletions shortcodes/oik-navi.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ function bw_navi_start_from_atts( $atts ) {
* @return string - generated HTML
*/
function bw_navi( $atts=null, $content=null, $tag="bw_navi" ) {
if ( oik_is_rest() ) {
return null;
}
oik_require( "includes/oik-shortcodes.php");
bw_push();
$posts_per_page = bw_array_get( $atts, "posts_per_page", null );
if ( !$posts_per_page ) {
Expand Down

0 comments on commit 08d573e

Please sign in to comment.