priority = 2;
if ($post) {
// save a refference to the action post.
$this->action_post = $post;
// set the action post ID.
$this->action_post_id = $post->ID;
// get the custom action fields.
$this->fields_values = get_post_custom($this->action_post_id);
// get the contact form 7 post id.
$this->wpcf7_id = $this->get_action_wpcf7_id($this->action_post_id);
// get the type of action.
$this->action = self::get_action_type($this->action_post_id);
// get tje status of the action (is it active or not).
$this->action_status = $this->get_action_status($this->action_post_id);
// get conditional logic blocks.
$this->logic_blocks = $this->get('blocks');
// save submission data reference
$this->wpcf7_submission = WPCF7_Submission::get_instance();
}
}
/**
* Returns an html for displaying a link to the form.
*
* @return [string] - a link to the form edit screen.
*/
public function get_cf7_link_html()
{
return WPCF7r_Form_Helper::get_cf7_link_html($this->wpcf7_id);
}
/**
* Connected to manage_columns hooks.
*
* @param [string] $column - key of the column.
* @param [int] $post_id - the id of the relevant post.
* @return void
*/
public function display_action_column_content($column, $post_id)
{
}
/**
* Process validation action
* This function will be called on validation hook
*
* @param $submission
*/
public function process_validation($submission)
{
}
/**
* Get action name
*/
public function get_name()
{
return WPCF7r_Utils::get_action_name($this->action);
}
/**
* Adds a blank select option for select fields
*/
public function get_tags_optional()
{
$tags = $this->get_mail_tags_array();
$tags_optional = array_merge(array(__('Select', 'wpcf7-redirect')), $tags);
return $tags_optional;
}
/**
* save a reference to the lead id in case the save lead action is on
*
* @param $lead_id
*/
public function set_lead_id($lead_id)
{
self::$lead_id = $lead_id;
}
/**
* save a reference to a global feature
*
* @param $lead_id
*/
public function set_global_option($key, $value)
{
self::$global_options[$key] = $value;
}
public function get_global_option($key)
{
return isset(self::$global_options[$key]) ? self::$global_options[$key] : '';
}
/**
* Get all system user roles
*/
public function get_available_user_roles()
{
return wp_roles()->get_names();
}
/**
* Return the current lead id if it is availavle
*/
public static function get_lead_id()
{
return isset(self::$lead_id) ? self::$lead_id : '';
}
/**
* General function to retrieve meta
*
* @param $key
*/
public function get($key,$default='')
{
return isset($this->fields_values[$key][0]) ? $this->fields_values[$key][0] : $default;
}
/**
* Get the contact form 7 related post id
*/
public function get_cf7_post_id()
{
return isset($this->wpcf7_id) ? $this->wpcf7_id : '';
}
/**
* Set action property
*
* @param $key
* @param $value
*/
public function set($key, $value)
{
update_post_meta($this->action_post_id, $key, $value);
$this->fields_values[$key][0] = $value;
}
/**
* Enqueue extension scripts and styles.
*
* @return void
*/
public static function enqueue_backend_scripts()
{
}
/**
* Enqueue extension scripts and styles.
*
* @return void
*/
public static function enqueue_frontend_scripts()
{
}
/**
* Parent get action fields function
*/
public function get_action_fields()
{
return array();
}
/**
* Get a set of fields/specific field settings by key
*
* @param $fields_key
*/
public function get_fields_settings($fields_key)
{
$fields = $this->get_action_fields();
return $fields[$fields_key];
}
/**
* Get the id of the rule
*/
public function get_rule_id()
{
return $this->get('wpcf7_rule_id');
}
/**
* Get all fields values
*/
public function get_fields_values()
{
$fields = $this->get_action_fields();
foreach ($fields as $field) {
$values[$field['name']] = $this->get_field_value($field);
}
return $values;
}
/**
* Get mail tags objects
*/
public function get_mail_tags()
{
$mail_tags = WPCF7R_Form::get_mail_tags();
return $mail_tags;
}
/**
* Get mail tags objects
*/
public function get_mail_tags_array()
{
$mail_tags = WPCF7R_Form::get_mail_tags();
$mail_tags_array = array();
if ($mail_tags) {
foreach ($mail_tags as $mail_tag) {
$mail_tags_array[$mail_tag->name] = $mail_tag->name;
}
}
return $mail_tags_array;
}
/**
* Get mail tags to display on the settings panel
*
* @param boolean $clean
*/
public function get_formatted_mail_tags($clean = false)
{
$formatted_tags = array();
if (!is_array(WPCF7R_Form::get_mail_tags())) {
return;
}
foreach (WPCF7R_Form::get_mail_tags() as $mail_tag) {
$formatted_tags[] = "[{$mail_tag->name}]";
}
// foreach( WPCF7R_Form::get_special_mail_tags() as $mail_tag ){
// $formatted_tags[] = " [".$mail_tag->field_name()."]";
// }
$formatted_tags = implode('', $formatted_tags);
if ($clean) {
$formatted_tags = str_replace(array(']'), ', ', $formatted_tags);
$formatted_tags = str_replace(array('['), '', $formatted_tags);
}
ob_start();
?>
wpcf7_submission) ? $this->wpcf7_submission : null;
}
public function get_submitted_value($key, $default = null)
{
$submission = $this->get_submission_instance();
if(!$submission){
return $default;
}
$submitted_data = $submission->get_posted_data();
return isset($submitted_data[$key]) ? $submitted_data[$key] : $default;
}
/**
* Replace all mail tags in a string
*
* @param $content
* @param $args
*/
public function replace_tags($content, $args = '')
{
if (true === $args) {
$args = array('html' => true);
}
$args = wp_parse_args(
$args,
array(
'html' => false,
'exclude_blank' => false,
)
);
$replaced_tags = wpcf7_mail_replace_tags($content, $args);
$replaced_tags = do_shortcode($replaced_tags);
$replaced_tags = $this->replace_lead_id_tag($replaced_tags);
$files = $this->get_files_shortcodes_from_submitted_data();
if ($files) {
foreach ($files as $file_shortcodes) {
foreach ($file_shortcodes as $file_shortcode => $data) {
$replaced_tags = str_replace($file_shortcode, $data, $replaced_tags);
}
}
}
return $replaced_tags;
}
public function get_files_shortcodes_from_submitted_data()
{
$file_tags = array();
if ($this->get_submission_instance()) {
$files = $this->get_submission_instance()->uploaded_files();
foreach ($files as $file_key => $file_paths) {
$file_paths = is_array($file_paths) ? $file_paths : array($file_paths);
foreach ($file_paths as $file_path) {
$file_tags[$file_key] = array(
'[' . $file_key . '-filename]' => basename($file_path),
'[' . $file_key . '-base_64_file]' => $this->base_64_file($file_path),
'[' . $file_key . '-path]' => $file_path,
);
}
}
}
return $file_tags;
}
/**
* Encode A File to base64
*
* @param [type] $path
* @return void
*/
private function base_64_file($path)
{
$data = file_get_contents($path);
$base64 = base64_encode($data);
return $base64;
}
/**
* Get the value of a specific field
*
* @param $field
*/
public function get_field_value($field)
{
if (is_array($field)) {
return get_post_meta($this->action_post_id, '_wpcf7_redirect_' . $field['name'], true);
} else {
return get_post_meta($this->action_post_id, '_wpcf7_redirect_' . $field, true);
}
}
/**
* Get an instance of the relevant action class
*
* @param $post
*/
public static function get_action($post)
{
if (is_int($post)) {
$post = get_post($post);
}
if (!isset($post->ID)) {
return false;
}
$action_type = self::get_action_type($post->ID);
$class = "WPCF7R_Action_{$action_type}";
$action = '';
if (class_exists($class)) {
$action = new $class($post);
} else {
$action_type = str_replace(' ', '_', ucwords(str_replace('_', ' ', $action_type)));
$class = "WPCF7R_Action_{$action_type}";
if (class_exists($class)) {
$action = new $class($post);
} else {
$action = new WP_Error('get_action', "Class {$class} Does not exist");
}
}
return $action;
}
/**
* Get the action post_id
*/
public function get_id()
{
return $this->action_post_id;
}
/**
* Get the type of the action
*
* @param $post_id
*/
public static function get_action_type($post_id)
{
$action_type = get_post_meta($post_id, 'action_type', true);
$migration_list = array(
'send_mail' => 'SendMail',
'fire_script' => 'FireScript',
);
if (isset($migration_list[$action_type])) {
update_post_meta($post_id, 'action_type', $migration_list[$action_type]);
$action_type = $migration_list[$action_type];
}
return $action_type;
}
/**
* Get action status
*/
public function get_action_status()
{
return $this->get('action_status');
}
/**
* Get action status
*/
public function get_action_status_label()
{
/* translators:%s the action status name */
return $this->get_action_status() === 'on' ? sprintf(__('Enable %s', 'wpcf7-redirect'), $this->get_name()) : __('Disabled', 'wpcf7-redirect');
}
/**
* Get contact form id
*
* @return int form id
*/
public function get_action_wpcf7_id()
{
return $this->get('wpcf7_id');
}
/**
* Get the action title
*
* @return string action title
*/
public function get_title()
{
return $this->action_post->post_title;
}
/**
* Get the action type
*
* @return string action type
*/
public function get_type()
{
return $this->action;
}
/**
* Get the action pretty name
*
* @return string action pretty name
*/
public function get_type_label()
{
$actions = wpcf7r_get_available_actions();
$type = $actions[$this->get_type()]['label'];
return $type;
}
/**
* Get the action status
*
* @return string action status
*/
public function get_status()
{
return $this->action_status;
}
/**
* Get the action menu order
*/
public function get_menu_order()
{
return $this->action_post->menu_order;
}
/**
* Get the tags used on the form
*
* @param string $tag_name
*/
public function get_validation_mail_tags($tag_name = '')
{
$tags = WPCF7R_Form::get_validation_obj_tags();
if ($tag_name) {
foreach ($tags as $tag) {
if ($tag->name === $tag_name) {
return $tag;
}
}
} else {
return $tags;
}
}
/**
* Get default actions field
* This actions will apply for all child action classes
*/
function get_default_fields()
{
$args = array(
'action_status' => array(
'name' => 'action_status',
'type' => 'checkbox',
'label' => $this->get_action_status_label(),
'sub_title' => 'if this is off the rule will not be applied',
'placeholder' => '',
'show_selector' => '',
'toggle-label' => json_encode(
array(
'.field-wrap-action_status .checkbox-label,.column-status a' => array(
__('Enabled', 'wpcf7-redirect'),
__('Disabled', 'wpcf7-redirect'),
),
)
),
'value' => $this->get('action_status'),
),
);
if (conditional_logic_enabled()) {
$args['conditional_logic'] = array(
'name' => 'conditional_logic',
'type' => 'checkbox',
'label' => __('Conditional Logic', 'wpcf7-redirect'),
'sub_title' => '',
'placeholder' => '',
'show_selector' => '.conditional-logic-blocks',
'value' => $this->get('conditional_logic'),
);
} else {
$args['conditional_logic'] = array(
'name' => 'conditional_logic',
'type' => 'notice',
'label' => __('CONDITIONAL LOGIC! ', 'wpcf7-redirect'),
'sub_title' => __('You can purchase and activate conditional logic addon on the extensions tab.', 'wpcf7-redirect'),
'placeholder' => '',
'class' => 'field-notice-alert',
'show_selector' => '',
);
}
$args['blocks'] = array(
'name' => 'blocks',
'type' => 'blocks',
'has_conditional_logic' => $this->get('conditional_logic'),
'blocks' => $this->get_conditional_blocks(),
);
return $args;
}
/**
* Reset all action fields
*/
public function delete_all_fields()
{
$fields = $this->get_action_fields();
foreach ($fields as $field) {
delete_post_meta($this->action_post_id, $field['name']);
if (isset($field['fields']) && $field['fields']) {
foreach ($field['fields'] as $sub_field_key => $sub_field) {
delete_post_meta($this->action_post_id, $sub_field_key);
}
}
}
}
/**
* Get the template to display on the admin field
*
* @param $template
*/
public function get_settings_template($template)
{
$prefix = "[actions][$this->action_post_id]";
include WPCF7_PRO_REDIRECT_ACTIONS_TEMPLATE_PATH . 'rule-title.php';
include WPCF7_PRO_REDIRECT_ACTIONS_TEMPLATE_PATH . $template;
}
/**
* Get a single action row
*/
public function get_action_row()
{
ob_start();
do_action('before_wpcf7r_action_row', $this);
?>