Remove actions/filters that are set with create_function()

In order to remove the hooks and filters, we need to be able to get a reference to the callable that was added, but in this case, create_function was used, so that’s extremely difficult. It’s also the reason you’re getting deprecation notices. Sadly the only way to fix those deprecations is to change the parent theme to fix it.

Fixing The Deprecations

The PHP docs say that create_function works like this:

string create_function ( string $args , string $code )

Creates an anonymous function from the parameters passed, and returns a unique name for it.

And of note, create_function is deprecated in PHP 7.2

So this:

create_function( '$a', 'return $a + 1;' )

Becomes:

function( $a ) {
    return $a + 1;
}

Or even

function add_one( $a ) {
    return $a + 1;
}

This should eliminate the create_function calls, and turn the anonymous functions into normal calls that can be removed in a child theme

Removing The Hooks and Filters

Now that we’ve done that, we can now remove and replace them in the child theme.

To do this, we need 2 things:

  • to run the removal code after they were added
  • to be able to unhook the filters/actions

Putting your replacement in is easy, just use add_filter and add_action, but that adds your version, we need to remove the parent themes version.

Lets assume that this code is in the parent theme:

add_filter('wp_add_numbers_together' 'add_one' );

And that we want to replace it with a multiply_by_two function. First lets do this on the init hook:

function nickm_remove_parent_hooks() {
    //
}
add_action('init', 'nickm_remove_parent_hooks' );

Then call remove_filter and add_filter`:

function nickm_remove_parent_hooks() {
    remove_filter( 'wp_add_numbers_together' 'add_one' );
}
add_action( 'init', 'nickm_remove_parent_hooks' );
add_action( 'wp_add_numbers_together', 'multiply_by_two' );

Keep in mind that child themes let you override templates, but functions.php is not a template, and child themes don’t change how include or require work. A child themes functions.php is loaded first, but otherwise, they’re similar to plugins.

And Finally

You shouldn’t be registering post types, roles, capabilities, and taxonomies in a theme, it’s a big red flag and creates lock in, preventing data portability. These things are supposed to be in plugins, not themes

error code: 523