Filter
uncanny-automator-pro
automator_pro_trigger_update_postmeta_logged_in_req
Filters post meta update to check if the logged-in user has permission before proceeding with the update.
add_filter( 'automator_pro_trigger_update_postmeta_logged_in_req', $callback, 10, 3 );
Description
This filter determines if a logged-in user is required to trigger a post meta update. Developers can return `true` to enforce a logged-in user requirement. If `false` is returned and the user is not logged in, the trigger will not proceed.
Usage
add_filter( 'automator_pro_trigger_update_postmeta_logged_in_req', 'your_function_name', 10, 3 );
Parameters
-
$post_id(mixed) - This parameter is a boolean value that determines whether the post meta update requires the user to be logged in.
-
$meta_key(mixed) - This parameter represents the ID of the post that the post meta is associated with.
-
$_meta_value(mixed) - This parameter represents the meta key associated with the post that is being checked.
Return Value
The filtered value.
Examples
<?php
/**
* Prevent the trigger from running if the post meta key is 'password' and the user is not logged in.
*
* This filter hook allows developers to add custom logic to determine whether the
* 'Post meta is a specific value' trigger should proceed based on the logged-in status
* of the user and specific meta keys.
*
* @param bool $return_value The default return value. If true, the trigger will proceed.
* @param int $post_id The ID of the post being updated.
* @param string $meta_key The meta key of the post meta being updated.
* @param mixed $_meta_value The new value of the post meta.
* @return bool Returns true to allow the trigger to proceed, false to stop it.
*/
add_filter( 'automator_pro_trigger_update_postmeta_logged_in_req', function ( $return_value, $post_id, $meta_key, $_meta_value ) {
// If the meta key is 'password' and the user is not logged in, prevent the trigger.
if ( 'password' === $meta_key && ! is_user_logged_in() ) {
// Returning false will stop the trigger from executing further in this specific scenario.
return false;
}
// For all other cases, allow the trigger to proceed by returning the default or true.
// In this example, we're explicitly returning true to ensure it continues unless the condition above is met.
return true;
}, 10, 4 );
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/wp/triggers/anon-wp-postmetaspecificvalue.php:154
uncanny-automator-pro/src/integrations/wp/triggers/wp-postmetaspecificvalue.php:147
if ( in_array( $meta_key, $ignore_meta_keys, true ) ) {
return;
}
$user_id = get_current_user_id();
if ( true === apply_filters( 'automator_pro_trigger_update_postmeta_logged_in_req', false, $post_id, $meta_key, $_meta_value ) && ! is_user_logged_in() ) {
return;
}
$post = get_post( $post_id );
// sanity check
if ( ! $post instanceof WP_Post ) {
return;