Filter
uncanny-automator-pro
wpcode_on_demand_ignore_conditional_logic
Filters whether conditional logic should be ignored for on-demand code snippets.
add_filter( 'wpcode_on_demand_ignore_conditional_logic', $callback, 10, 1 );
Description
Filters whether to ignore conditional logic for WPCode snippets executed on demand. Developers can use this to force a snippet's execution regardless of its set conditions. By default, conditional logic is respected, so returning `true` here bypasses it.
Usage
add_filter( 'wpcode_on_demand_ignore_conditional_logic', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the 'wpcode_on_demand_ignore_conditional_logic' filter.
*
* This filter allows you to override the default behavior of the WPCode on-demand
* execution to either force or prevent the execution of conditional logic for
* a specific snippet.
*
* In this example, we'll force conditional logic to be ignored for a specific
* snippet ID ('my-special-snippet-id') for demonstration purposes.
*
* @param bool $ignore_logic The current value of whether to ignore conditional logic.
* Defaults to false.
* @return bool True to ignore conditional logic, false otherwise.
*/
add_filter( 'wpcode_on_demand_ignore_conditional_logic', function( $ignore_logic ) {
// Get the current snippet ID being executed.
// Note: The exact way to get the snippet ID might vary depending on the context
// within Uncanny Automator. For a general example, we'll assume it's accessible.
// In a real scenario, you might need to inspect the Uncanny Automator codebase
// to reliably get the snippet ID within the filter.
// For this example, we'll hardcode a snippet ID for demonstration.
$current_snippet_id_being_executed = 'my-special-snippet-id'; // Replace with actual dynamic retrieval if possible
// If the current snippet ID matches our target, force conditional logic to be ignored.
if ( $current_snippet_id_being_executed === 'my-special-snippet-id' ) {
return true; // Force ignoring conditional logic for this snippet.
}
// Otherwise, return the original value.
return $ignore_logic;
}, 10, 1 );
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
uncanny-automator-pro/src/integrations/wpcode/actions/wpcode-run-on-demand-snippet.php:72
protected function process_action( $user_id, $action_data, $recipe_id, $args, $parsed ) {
$snippet_id = isset( $parsed[ $this->get_action_meta() ] ) ? sanitize_text_field( $parsed[ $this->get_action_meta() ] ) : '';
$snippet = wpcode_get_snippet( absint( $snippet_id ) );
if ( empty( $snippet->id ) ) {
// translators: %s is a WPCode snippet ID
$this->add_log_error( sprintf( esc_attr_x( 'The snippet ID: %s is not valid.', 'WPCode', 'uncanny-automator-pro' ), $snippet_id ) );
return false;
}
wpcode()->execute->doing_activation(); // Mark this to unslash the code.
$snippet->execute( apply_filters( 'wpcode_on_demand_ignore_conditional_logic', false ) );
return true;
}