Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am well aware of the use of child themes for this. I know about get_header($name). I already understand the use of conditional tags.

I want my plugin to remove the function:

function get_header( $name = null ) {
do_action( 'get_header', $name );
$templates = array();
if ( isset($name) )
templates[] = "header-{$name}.php";
$templates[] = 'header.php';
// Backward compat code will be removed in a future release
if ('' == locate_template($templates, true))
load_template( ABSPATH . WPINC . '/theme-compat/header.php');
}

and the replace get_header() with:

function get_header( $name = null ) {
do_action( 'get_header', $name );
$templates = array();
if ( isset($name) )
templates[] = "header-{$name}.php";
$templates[] = 'header.php';
// Backward compat code will be removed in a future release
if ('' == locate_template($templates, true))
load_template( MY PLUGIN PATH/header.php');
}

php.net told me to use runkit_function_remove() but the website I am working on says this is an undefined function.

Any help would be much appreciated.

Leon

share|improve this question
    
Runkit is a php extension that you would need to install on the server level, I doubt it's bundled by default on too many installations. I'd never seen it before, but if there's actually a reliable way to "undefine" functions I'm going to start using it when I have to deal with unfriendly plugins. –  Andrew Bartel May 10 '13 at 14:38
add comment

1 Answer

up vote 1 down vote accepted

I am not sure what you want to do is doable (seems impossible to me but everything seems impossible until someone does it). I thought of a very ugly workaround.

add_filter( 'template_include', function( $template ) {
    $temp = get_temp_dir() . basename( $template );
    file_put_contents( $temp, str_replace( 'get_header(', 'get_header2(', file_get_contents( $template ) ) );
    return $temp;
});

function get_header2( $name = null ) {
    do_action( 'get_header', $name );

    $templates = array();
    if ( isset($name) )
        $templates[] = "header-{$name}.php";

    $templates[] = 'header.php';

    // Backward compat code will be removed in a future release
    if ('' == locate_template($templates, true))
        load_template( MY PLUGIN PATH/header.php');
}

This replaces get_header with get_header2 in all templates before loading.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.