Created
September 22, 2015 17:34
-
-
Save dmitry-korolev/fda3ce4e2d101f5deea3 to your computer and use it in GitHub Desktop.
Return instead of echoing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This function can be used to return (instead of echoing) results | |
* of build-in functions, that cannot return, just echo. | |
* @return mixed Results of called function. | |
*/ | |
function md_rioe() { | |
if (func_num_args() === 0) { | |
trigger_error('Nothing to call', E_USER_WARNING); | |
return; | |
} | |
ob_start(); | |
if (func_num_args() === 1) { | |
call_user_func(func_get_arg(0)); | |
} elseif (func_num_args() > 1) { | |
$args = array_slice(func_get_args(), 1); | |
call_user_func_array(func_get_arg(0), $args); | |
} | |
return ob_get_clean(); | |
} | |
// Examples. | |
// wp_head(); | |
$wp_head = md_rioe('wp_head'); | |
// body_class('additional-class'); | |
$body_class = md_rioe('body_class', 'additional-class'); | |
// wp_editor('content', 'editor_id', [ | |
// 'wpautop' => false | |
// ]); | |
$wp_editor = md_rioe('wp_editor', 'content', 'editor_id', [ | |
'wpautop' => false | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment