Skip to content

Commit

Permalink
Removed is_rest function in favor of removing the lazy loader filters…
Browse files Browse the repository at this point in the history
… using the rest_api_init hook
  • Loading branch information
cjg89 committed Mar 3, 2020
1 parent 3f2da6a commit 383c944
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 31 deletions.
3 changes: 1 addition & 2 deletions includes/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,9 @@ function disable_lazyload_in_rest() {
if (
isset( $lazy_loader )
&& $lazy_loader instanceof FlorianBrinkmann\LazyLoadResponsiveImages\Plugin
&& is_rest()
) {
remove_filter( 'the_content', array( $lazy_loader, 'filter_markup' ), 10001 );
}
}

add_action( 'init', 'disable_lazyload_in_rest' );
add_action( 'rest_api_init', 'disable_lazyload_in_rest' );
29 changes: 0 additions & 29 deletions includes/utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,32 +93,3 @@ function get_attachment_src_by_size( $id, $size ) {
}
return $attachment;
}



if ( ! function_exists( 'is_rest' ) ) {
/**
* Checks if the current request is a WP REST API request.
*
* @return boolean
* @see https://gist.github.com/matzeeable/dfd82239f48c2fedef25141e48c8dc30
*/
function is_rest() {
if (
( defined( 'REST_REQUEST' ) && REST_REQUEST )
|| (
isset( $_GET['rest_route'] )
&& strpos( trim( $_GET['rest_route'], '\\/' ), rest_get_url_prefix() , 0 ) === 0
)
) {
return true;
}

global $wp_rewrite;
if ( $wp_rewrite === null ) $wp_rewrite = new WP_Rewrite();

$rest_url = wp_parse_url( trailingslashit( rest_url() ) );
$current_url = wp_parse_url( add_query_arg( array() ) );
return strpos( $current_url['path'], $rest_url['path'], 0 ) === 0;
}
}

0 comments on commit 383c944

Please sign in to comment.