Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Assign class methods to hooks.
- */
- public static function init() {
- if ( ! defined( 'REST_REQUEST' ) ) {
- add_filter( 'the_content', array( __class__, 'filter_content' ), 999 );
- }
- add_filter( 'rest_pre_dispatch', array( __class__, 'rest_check_referer' ), 10, 3 );
- }
- public static function rest_check_referer( $result, $server, $request ) {
- if ( null !== $result ) {
- // Core starts with a null value.
- // If it is no longer null, another callback has claimed this request.
- // Up to you how to handle - for this example we will just return early.
- return $result;
- }
- $referer = $request->get_header( 'referer' );
- if ( 'www.test.com' !== $referer ) {
- add_filter( 'the_content', array( __class__, 'filter_content' ), 999 );
- }
- // Otherwise we are good - return original result and let WordPress handle as usual.
- return $result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement