Filter
uncanny-automator
automator_do_load_options
Filters the options loaded for Automator plugin actions, allowing modification of the retrieved settings before they are displayed.
add_filter( 'automator_do_load_options', $callback, 10, 1 );
Description
Filters whether recipe trigger options should be loaded in the admin. Developers can use this to conditionally prevent option loading, for example, based on specific user roles or custom request parameters, ensuring efficient admin performance.
Usage
add_filter( 'automator_do_load_options', 'your_function_name', 10, 1 );
Parameters
-
$class_name(mixed) - This parameter is a boolean value indicating whether the options should be loaded.
Return Value
The filtered value.
Examples
add_filter( 'automator_do_load_options', 'my_custom_automator_load_options', 10, 2 );
/**
* Conditionally loads automator options based on custom logic.
*
* This example demonstrates how to use the 'automator_do_load_options' filter
* to conditionally enable or disable the loading of automator options.
* In this specific scenario, we'll only allow options to load if a specific
* query parameter is present in the URL, indicating a custom process.
*
* @param bool $load_options The default value indicating whether to load options (true/false).
* @param string $class_name The name of the class currently being processed.
*
* @return bool Returns true to load options, false otherwise.
*/
function my_custom_automator_load_options( $load_options, $class_name ) {
// Check if a specific custom query parameter is set in the URL
if ( isset( $_GET['my_custom_trigger_process'] ) && '1' === $_GET['my_custom_trigger_process'] ) {
// If the custom parameter is present, force options to load,
// regardless of the default value passed by the filter.
return true;
}
// Otherwise, return the original $load_options value,
// allowing the default logic or other filters to decide.
return $load_options;
}
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/core/lib/helpers/class-automator-recipe-helpers.php:1051
src/core/lib/helpers/class-automator-recipe-helpers.php:1055
public function maybe_load_trigger_options( $class_name = '' ) {
if ( is_admin() && automator_filter_has_var( 'action' ) && 'edit' === automator_filter_input( 'action' ) && automator_filter_has_var( 'post' ) ) {
$post_id = absint( automator_filter_input( 'post' ) );
$post = get_post( $post_id );
if ( $post && $post instanceof WP_Post && AUTOMATOR_POST_TYPE_RECIPE === $post->post_type ) {
return apply_filters( 'automator_do_load_options', true, $class_name );
}
}
return apply_filters( 'automator_do_load_options', false, $class_name );
}