__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.000001 sec (speed of light) | 50000 times — 0.00 sec (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;



Since 3.0.0 Introduced.

__return_true() code WP 6.5.2

function __return_true() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
	return true;