Skip to main content
added 7 characters in body
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

Note that there's no is_admin() method offor the WP_Query class.

But the interesting part is that PHP will not complain about this:

$query->is_admin()

where $query is an instance of WP_Query.

It will just always return false.

This is the reason why (src#src):

/**
 * Make private/protected methods readable for backwards compatibility.
 *
 * @since 4.0.0
 * @access public
 *
 * @param callable $name      Method to call.
 * @param array    $arguments Arguments to pass when calling.
 * @return mixed|false Return value of the callback, false otherwise.
 */
 public function __call( $name, $arguments ) {
        if ( in_array( $name, $this->compat_methods ) ) {
                return call_user_func_array( array( $this, $name ), $arguments );
        }
        return false;
}

The magic __call method, kicks in when you call the non-existent method is_admin(). This is from the PHP documentation:

__call() is triggered when invoking inaccessible methods in an object context.

The magic __call method, kicks in when we call the non-existent method is_admin().

I assume you're hooking into the pre_get_posts action.

We can use the is_admin() check:

add_action( 'pre_get_posts', function( \WP_QUery\WP_Query $query )
{
    // Only on the front-end
    if( is_admin() )
        return;

    // ... your stuff here ...
    
} );

or we could use the is_admin public attribute of the WP_Query instance:

add_action( 'pre_get_posts', function( \WP_QUery\WP_Query $query )
{
    // Only on the front-end
    if( $query->is_admin )
        return;

    // ... your stuff here ...
    
} );

where it in fact usesit's based on the is_admin() function, in the parse_query() method (src#src):

if ( is_admin() )
    $this->is_admin = true;

Note that there's no is_admin() method of the WP_Query class.

But the interesting part is that PHP will not complain about this:

$query->is_admin()

where $query is an instance of WP_Query.

It will just always return false.

This is the reason why (src):

/**
 * Make private/protected methods readable for backwards compatibility.
 *
 * @since 4.0.0
 * @access public
 *
 * @param callable $name      Method to call.
 * @param array    $arguments Arguments to pass when calling.
 * @return mixed|false Return value of the callback, false otherwise.
 */
 public function __call( $name, $arguments ) {
        if ( in_array( $name, $this->compat_methods ) ) {
                return call_user_func_array( array( $this, $name ), $arguments );
        }
        return false;
}

The magic __call method, kicks in when you call the non-existent method is_admin(). This is from the PHP documentation:

__call() is triggered when invoking inaccessible methods in an object context.

I assume you're hooking into the pre_get_posts action.

We can use the is_admin() check:

add_action( 'pre_get_posts', function( \WP_QUery $query )
{
    // Only on the front-end
    if( is_admin() )
        return;

    // ... your stuff here ...
    
} );

or we could use the is_admin public attribute of the WP_Query instance:

add_action( 'pre_get_posts', function( \WP_QUery $query )
{
    // Only on the front-end
    if( $query->is_admin )
        return;

    // ... your stuff here ...
    
} );

where it in fact uses the is_admin() function, in the parse_query() method (src):

if ( is_admin() )
    $this->is_admin = true;

Note that there's no is_admin() method for the WP_Query class.

But the interesting part is that PHP will not complain about this:

$query->is_admin()

where $query is an instance of WP_Query.

It will just always return false.

This is the reason why (#src):

/**
 * Make private/protected methods readable for backwards compatibility.
 *
 * @since 4.0.0
 * @access public
 *
 * @param callable $name      Method to call.
 * @param array    $arguments Arguments to pass when calling.
 * @return mixed|false Return value of the callback, false otherwise.
 */
 public function __call( $name, $arguments ) {
        if ( in_array( $name, $this->compat_methods ) ) {
                return call_user_func_array( array( $this, $name ), $arguments );
        }
        return false;
}

This is from the PHP documentation:

__call() is triggered when invoking inaccessible methods in an object context.

The magic __call method, kicks in when we call the non-existent method is_admin().

I assume you're hooking into the pre_get_posts action.

We can use the is_admin() check:

add_action( 'pre_get_posts', function( \WP_Query $query )
{
    // Only on the front-end
    if( is_admin() )
        return;

    // ... your stuff here ...
    
} );

or we could use the is_admin public attribute of the WP_Query instance:

add_action( 'pre_get_posts', function( \WP_Query $query )
{
    // Only on the front-end
    if( $query->is_admin )
        return;

    // ... your stuff here ...
    
} );

where in fact it's based on the is_admin() function, in the parse_query() method (#src):

if ( is_admin() )
    $this->is_admin = true;
added 279 characters in body
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

Note that there's no is_admin() method of the WP_Query class.

But the interesting part is that PHP will not complain about it, justthis:

$query->is_admin()

where $query is an instance of WP_Query.

It will just always return false. 

This is the reason why (src):

/**
 * Make private/protected methods readable for backwards compatibility.
 *
 * @since 4.0.0
 * @access public
 *
 * @param callable $name      Method to call.
 * @param array    $arguments Arguments to pass when calling.
 * @return mixed|false Return value of the callback, false otherwise.
 */
 public function __call( $name, $arguments ) {
        if ( in_array( $name, $this->compat_methods ) ) {
                return call_user_func_array( array( $this, $name ), $arguments );
        }
        return false;
}

The magic __call method, kicks in when you call the non-existent method is_admin(). This is from the PHP documentation:

__call() is triggered when invoking inaccessible methods in an object context.

I assume you're hooking into the pre_get_posts action.

We can use the is_admin() check:

add_action( 'pre_get_posts', function( \WP_QUery $query )
{
    // Only on the front-end
    if( is_admin() )
        return;

    // ... your stuff here ...
    
} );

or we could use the is_admin public attribute of the WP_Query instance:

add_action( 'pre_get_posts', function( \WP_QUery $query )
{
    // Only on the front-end
    if( $query->is_admin )
        return;

    // ... your stuff here ...
    
} );

where it in fact uses the is_admin() function, in the parse_query() method (src):

if ( is_admin() )
    $this->is_admin = true;

Note that there's no is_admin() method of the WP_Query class.

But the interesting part is that PHP will not complain about it, just always return false. This is the reason why (src):

/**
 * Make private/protected methods readable for backwards compatibility.
 *
 * @since 4.0.0
 * @access public
 *
 * @param callable $name      Method to call.
 * @param array    $arguments Arguments to pass when calling.
 * @return mixed|false Return value of the callback, false otherwise.
 */
 public function __call( $name, $arguments ) {
        if ( in_array( $name, $this->compat_methods ) ) {
                return call_user_func_array( array( $this, $name ), $arguments );
        }
        return false;
}

I assume you're hooking into the pre_get_posts action.

We can use the is_admin() check:

add_action( 'pre_get_posts', function( \WP_QUery $query )
{
    // Only on the front-end
    if( is_admin() )
        return;

    // ... your stuff here ...
    
} );

or we could use the is_admin public attribute of the WP_Query instance:

add_action( 'pre_get_posts', function( \WP_QUery $query )
{
    // Only on the front-end
    if( $query->is_admin )
        return;

    // ... your stuff here ...
    
} );

where it in fact uses the is_admin() function, in the parse_query() method (src):

if ( is_admin() )
    $this->is_admin = true;

Note that there's no is_admin() method of the WP_Query class.

But the interesting part is that PHP will not complain about this:

$query->is_admin()

where $query is an instance of WP_Query.

It will just always return false. 

This is the reason why (src):

/**
 * Make private/protected methods readable for backwards compatibility.
 *
 * @since 4.0.0
 * @access public
 *
 * @param callable $name      Method to call.
 * @param array    $arguments Arguments to pass when calling.
 * @return mixed|false Return value of the callback, false otherwise.
 */
 public function __call( $name, $arguments ) {
        if ( in_array( $name, $this->compat_methods ) ) {
                return call_user_func_array( array( $this, $name ), $arguments );
        }
        return false;
}

The magic __call method, kicks in when you call the non-existent method is_admin(). This is from the PHP documentation:

__call() is triggered when invoking inaccessible methods in an object context.

I assume you're hooking into the pre_get_posts action.

We can use the is_admin() check:

add_action( 'pre_get_posts', function( \WP_QUery $query )
{
    // Only on the front-end
    if( is_admin() )
        return;

    // ... your stuff here ...
    
} );

or we could use the is_admin public attribute of the WP_Query instance:

add_action( 'pre_get_posts', function( \WP_QUery $query )
{
    // Only on the front-end
    if( $query->is_admin )
        return;

    // ... your stuff here ...
    
} );

where it in fact uses the is_admin() function, in the parse_query() method (src):

if ( is_admin() )
    $this->is_admin = true;
added 279 characters in body
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

Note that there's no is_admin() method of the WP_Query class.

But the interesting part is that PHP will not complain about it, just always return false. This is the reason why (src):

/**
 * Make private/protected methods readable for backwards compatibility.
 *
 * @since 4.0.0
 * @access public
 *
 * @param callable $name      Method to call.
 * @param array    $arguments Arguments to pass when calling.
 * @return mixed|false Return value of the callback, false otherwise.
 */
 public function __call( $name, $arguments ) {
        if ( in_array( $name, $this->compat_methods ) ) {
                return call_user_func_array( array( $this, $name ), $arguments );
        }
        return false;
}

I assume you're hooking into the pre_get_posts action.

We can use the is_admin() check:

add_action( 'pre_get_posts', function( \WP_QUery $query )
{
    // Only on the front-end
    if( is_admin() )
        return;

    // ... your stuff here ...
    
} );

or we could use the is_admin public attribute of the WP_Query instance:

add_action( 'pre_get_posts', function( \WP_QUery $query )
{
    // Only on the front-end
    if( $query->is_admin )
        return;

    // ... your stuff here ...
    
} );

where it in fact uses the is_admin() function, in the parse_query() method (src):

if ( is_admin() )
    $this->is_admin = true;

Note that there's no is_admin() method of the WP_Query class.

But the interesting part is that PHP will not complain about it, just always return false. This is the reason why (src):

/**
 * Make private/protected methods readable for backwards compatibility.
 *
 * @since 4.0.0
 * @access public
 *
 * @param callable $name      Method to call.
 * @param array    $arguments Arguments to pass when calling.
 * @return mixed|false Return value of the callback, false otherwise.
 */
 public function __call( $name, $arguments ) {
        if ( in_array( $name, $this->compat_methods ) ) {
                return call_user_func_array( array( $this, $name ), $arguments );
        }
        return false;
}

I assume you're hooking into the pre_get_posts action.

We can use the is_admin() check:

add_action( 'pre_get_posts', function( \WP_QUery $query )
{
    // Only on the front-end
    if( is_admin() )
        return;

    // ... your stuff here ...
    
} );

or we could use the is_admin attribute of the WP_Query instance:

add_action( 'pre_get_posts', function( \WP_QUery $query )
{
    // Only on the front-end
    if( $query->is_admin )
        return;

    // ... your stuff here ...
    
} );

where it in fact uses the is_admin() function, in the parse_query() method (src):

if ( is_admin() )
    $this->is_admin = true;

Note that there's no is_admin() method of the WP_Query class.

But the interesting part is that PHP will not complain about it, just always return false. This is the reason why (src):

/**
 * Make private/protected methods readable for backwards compatibility.
 *
 * @since 4.0.0
 * @access public
 *
 * @param callable $name      Method to call.
 * @param array    $arguments Arguments to pass when calling.
 * @return mixed|false Return value of the callback, false otherwise.
 */
 public function __call( $name, $arguments ) {
        if ( in_array( $name, $this->compat_methods ) ) {
                return call_user_func_array( array( $this, $name ), $arguments );
        }
        return false;
}

I assume you're hooking into the pre_get_posts action.

We can use the is_admin() check:

add_action( 'pre_get_posts', function( \WP_QUery $query )
{
    // Only on the front-end
    if( is_admin() )
        return;

    // ... your stuff here ...
    
} );

or we could use the is_admin public attribute of the WP_Query instance:

add_action( 'pre_get_posts', function( \WP_QUery $query )
{
    // Only on the front-end
    if( $query->is_admin )
        return;

    // ... your stuff here ...
    
} );

where it in fact uses the is_admin() function, in the parse_query() method (src):

if ( is_admin() )
    $this->is_admin = true;
added 279 characters in body
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251
Loading
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251
Loading