← Back
Editing: wp-tokens.php
<?php namespace Uncanny_Automator; /** * Class WP_Anon_Tokens * * @package Uncanny_Automator */ class Wp_Tokens { /** * Integration code * * @var string */ public static $integration = 'WP'; /** * Wp_Tokens constructor. */ public function __construct() { // Hide error for Automator Pro until Pro 3.1 is released. if ( PHP_MAJOR_VERSION >= 7 ) { // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler -- Compatibility shim; hides the 'Declaration of' warnings that older Automator Pro raises from its wp-anon-tokens.php. set_error_handler( function ( $errno, $errstr, $file ) { return strpos( $file, '/tokens/wp-anon-tokens.php' ) !== false && strpos( $errstr, 'Declaration of' ) === 0; }, E_WARNING ); } // Skip legacy token filters when the modern integration is active — // migrated triggers use hydrate_tokens() directly. if ( class_exists( '\Uncanny_Automator\Integrations\Wp\Wp_Integration', false ) ) { return; } add_filter( 'automator_maybe_parse_token', array( $this, 'parse_wproles_token' ), 20, 6 ); } /** * @param $value * @param $pieces * @param $recipe_id * @param $trigger_data * * @param int $user_id * @param $replace_args * * @return mixed */ public function parse_wproles_token( $value, $pieces, $recipe_id, $trigger_data, $user_id, $replace_args ) { $piece = 'WPROLE'; if ( $pieces ) { if ( in_array( $piece, $pieces ) ) { if ( $trigger_data ) { foreach ( $trigger_data as $trigger ) { global $wpdb; $meta_field = $trigger['ID'] . ':' . $pieces[1] . ':' . $pieces[2]; $trigger_id = $trigger['ID']; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Automator's own table; no WordPress API for it. Live run state read; must not be cached. $meta_value = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM {$wpdb->prefix}uap_trigger_log_meta WHERE meta_key LIKE %s AND automator_trigger_id = %d ORDER BY ID DESC LIMIT 0,1", "%%$meta_field%%", $trigger_id ) ); if ( ! empty( $meta_value ) ) { $value = automator_safe_unserialize( $meta_value ); } } } } } return $value; } }
Save File
Cancel