| 1 |
<?php |
| 2 |
/** |
| 3 |
* AutomatorWP 4.2.0 compatibility functions |
| 4 |
* |
| 5 |
* @package AutomatorWP\4.2.0 |
| 6 |
* @author AutomatorWP <[email protected]>, Ruben Garcia <[email protected]> |
| 7 |
* @since 4.2.0 |
| 8 |
*/ |
| 9 |
// Exit if accessed directly |
| 10 |
if( !defined( 'ABSPATH' ) ) exit; |
| 11 |
|
| 12 |
/** |
| 13 |
* Get the trigger tags replacements |
| 14 |
* |
| 15 |
* @since 1.0.0 |
| 16 |
* |
| 17 |
* @param stdClass $trigger The trigger object |
| 18 |
* @param int $user_id The user ID |
| 19 |
* @param string $content The content to parse |
| 20 |
* |
| 21 |
* @return array |
| 22 |
*/ |
| 23 |
function automatorwp_get_trigger_tags_replacements_old( $trigger, $user_id, $content = '' ) { |
| 24 |
|
| 25 |
// Get the last completion log for this trigger (where data for tags replacement is) |
| 26 |
$log = automatorwp_get_trigger_last_completion_log( $trigger, $user_id, $content ); |
| 27 |
|
| 28 |
if( ! $log ) { |
| 29 |
return array(); |
| 30 |
} |
| 31 |
|
| 32 |
ct_setup_table( 'automatorwp_logs' ); |
| 33 |
|
| 34 |
$replacements = array(); |
| 35 |
|
| 36 |
// Look for trigger tags |
| 37 |
preg_match_all( "/\{" . $trigger->id . ":\s*(.*?)\s*\}/", $content, $matches ); |
| 38 |
|
| 39 |
if( is_array( $matches ) && isset( $matches[1] ) ) { |
| 40 |
|
| 41 |
foreach( $matches[1] as $tag_name ) { |
| 42 |
|
| 43 |
$replacements[$tag_name] = automatorwp_get_trigger_tag_replacement( $tag_name, $trigger, $user_id, $content, $log ); |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
} |
| 48 |
|
| 49 |
return $replacements; |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Get the post meta tags replacements |
| 55 |
* |
| 56 |
* @since 1.1.0 |
| 57 |
* |
| 58 |
* @param int $trigger_id The trigger ID |
| 59 |
* @param int $post_id The post ID |
| 60 |
* @param string $content The content to parse |
| 61 |
* |
| 62 |
* @return array |
| 63 |
*/ |
| 64 |
function automatorwp_get_post_meta_tags_replacements_old( $trigger_id = 0, $post_id = 0, $content = '' ) { |
| 65 |
|
| 66 |
$replacements = array(); |
| 67 |
|
| 68 |
// Look for post meta tags |
| 69 |
preg_match_all( "/\{" . $trigger_id . ":post_meta:\s*(.*?)\s*\}/", $content, $matches ); |
| 70 |
|
| 71 |
if( is_array( $matches ) && isset( $matches[1] ) ) { |
| 72 |
|
| 73 |
foreach( $matches[1] as $meta_key ) { |
| 74 |
// Replace {ID:post_meta:KEY} by the post meta value |
| 75 |
$replacements['{' . $trigger_id . ':post_meta:' . $meta_key . '}'] = get_post_meta( $post_id, $meta_key, true ); |
| 76 |
} |
| 77 |
|
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Filter to set custom post meta tags replacements |
| 82 |
* |
| 83 |
* @since 1.1.0 |
| 84 |
* |
| 85 |
* @param array $replacements Replacements |
| 86 |
* @param int $post_id The post ID |
| 87 |
* @param string $content The content to parse |
| 88 |
* |
| 89 |
* @return array |
| 90 |
*/ |
| 91 |
return apply_filters( 'automatorwp_get_post_meta_tags_replacements_old', $replacements, $post_id, $content ); |
| 92 |
|
| 93 |
} |
| 94 |
|