WordPress at a glance

__return_true() WP 3.0.0

Simply returns true. Helper function of WordPress.

Useful to use in filters to return true.

All such helper functions:
__return_false() — returns false.
__return_true() — returns true.
__return_empty_array() — returns an empty: array().
__return_zero() — returns the number 0.
__return_null() — returns NULL.
__return_empty_string() — returns an empty string: ''.

✈ 1 time = 0.000001s = speed of light | 50000 times = 0.00s = speed of light PHP 7.1.11, WP 4.9.7

No Hooks.






#1 Return true in the filter

Let's say we have a filter 'custom_menu_order' it is responsible for the possibility of arbitrary sorting of the administrative menu. By default it is disabled. We need to enable it, for do this we will use following code in theme functions.php or plugin file:

add_filter( 'custom_menu_order', '__return_true' );

The ability to sort is enabled, now we can sort the admin menu:

add_filter( 'menu_order', 'my_menu_order' );
function my_menu_order( $menu_order ) {
	   return array( 'index.php', 'edit.php', 'edit.php?post_type=page', 'edit-comments.php' );

#2 Other ways to write __return_true

// example of anonymous function (php 5.3+)
add_filter( 'show_admin_bar', function(){ return true; } );

// or so, with function registration 
add_filter( 'show_admin_bar', 'my_return_function' );
function my_return_function(){
	return true;

Code of __return_true: wp-includes/functions.php VER 4.9.8

function __return_true() {
	return true;

Related Functions

From tag: __return (helper functions)

More from category: Helper Functions

No comments
    Hello, !     Log In . Register