White Label Filters
The add_filter function is a key part of WordPress's plugin API that allows developers to modify data at specific points during the execution of the code.
Here's how it works:
add_filter
is used to hook a function or method to a specific filter action.- WordPress core (or plugins) can define these filter actions at specific points in their code, usually just before output is generated or data is saved. This is done using the
apply_filters
function. - When the
apply_filters
function is called, WordPress will execute all functions hooked to that filter action in the order they were added. The data is passed from one function to the next, allowing each to modify it. - The final result is then returned by
apply_filters
and used by the calling code.
add_filter('motionpage/wl/active', '__return_true');
add_filter('motionpage/wl/hidden', '__return_true');
add_filter('motionpage/wl/hideVersion', '__return_true');
In each case, __return_true
is a built-in WordPress function that simply returns true
, overriding the original setting value. You can use __return_false
in a similar way to __return_true
when using the add_filter
function. It allows you to override the original value of a setting or a feature and force it to be false
.
/**
* @param string $value
*/
add_filter('motionpage/wl/name', function($value) {
return 'Motion Page';
});
add_filter('motionpage/wl/description', function($value) {
return "Move it like it's HOT!";
});
add_filter('motionpage/wl/author', function($value) {
return 'By <a href="//motion.page/">HypeWolf OÜ</a>';
});
add_filter('motionpage/wl/icon', function($value) {
return 'dashicons-superhero';
});
add_filter('motionpage/wl/data', function() {
return [
'active' => true,
'name' => 'Motion.page',
'description' => "Move it like it's HOT!",
'author' => 'By <a href="//motion.page" target="_blank">Motion.page</a>',
'icon' => 'dashicons-superhero',
'hidden' => true,
'hideVersion' => true
];
});
/**
* @param array $data White Label data array
*/
add_filter('motionpage/wl/data', function($data) {
return array_merge($data, [
'name' => 'Motion.page',
'description' => "Move it like it's HOT!",
]);
});