public static function trigger_delete_actions($entry_id, $entry = false) { if (empty($entry)) { $entry = FrmEntry::getOne($entry_id); } FrmFormActionsController::trigger_actions('delete', $entry->form_id, $entry); }
function _check_repeating_fields_frm_item_metas($args) { $expected_metas = self::_get_expected_repeating_metas($args); foreach ($args['repeating_entry_ids'] as $child_id) { $child_entry = FrmEntry::getOne($child_id, true); $this->assertTrue(!empty($child_entry->metas), 'Data is not imported correctly in repeating fields.'); $this->assertEquals($expected_metas[$child_entry->item_key], $child_entry->metas, 'Data is not imported correctly in repeating fields.'); } }
/** * Constructs and initializes an Formidable Forms payment data object. * * @param string $entry_id * @param string $form_id * @param WP_Post $action */ public function __construct($entry_id, $form_id, $action) { parent::__construct(); $this->entry_id = $entry_id; $this->form_id = $form_id; $this->action = $action; // @see https://github.com/wp-premium/formidable-paypal/blob/3.02/controllers/FrmPaymentsController.php#L285 $this->entry = FrmEntry::getOne($this->entry_id, true); }
function import_xml() { // install test data in older format add_filter('frm_default_templates_files', 'FrmUnitTest::install_data'); FrmXMLController::add_default_templates(); $form = FrmForm::getOne('contact-db12'); $this->assertEquals($form->form_key, 'contact-db12'); $entry = FrmEntry::getOne('utah'); $this->assertNotEmpty($entry); $this->assertEquals($entry->item_key, 'utah'); }
/** * Formidable after submission * @param int $entryId * @param int $formId */ public function formidableSubmission($entryId, $formId) { // Since a lot of form types do not reload the page, we handle the form event server side. $tracker = $this->getGATracker(); if ($tracker) { $entry = \FrmEntry::getOne($entryId); $description = unserialize($entry->description); $referrer = $description['referrer']; $tracker->event("Formidable", "Submit Form ID " . $formId, $referrer); } }
public static function email_value($value, $meta, $entry) { if ($entry->id != $meta->item_id) { $entry = FrmEntry::getOne($meta->item_id); } $field = FrmField::getOne($meta->field_id); if (!$field) { return $value; } if (FrmField::is_option_true($field, 'post_field')) { $value = self::get_post_or_meta_value($entry, $field, array('truncate' => true)); $value = maybe_unserialize($value); } switch ($field->type) { case 'user_id': $value = FrmProFieldsHelper::get_display_name($value); break; case 'data': if (is_array($value)) { $new_value = array(); foreach ($value as $val) { $new_value[] = FrmProFieldsHelper::get_data_value($val, $field); } $value = $new_value; } else { $value = FrmProFieldsHelper::get_data_value($value, $field); } break; case 'file': $value = FrmProFieldsHelper::get_file_name($value); break; case 'date': $value = FrmProFieldsHelper::get_date($value); } if (is_array($value)) { $new_value = ''; foreach ($value as $val) { if (is_array($val)) { // This will affect checkboxes inside of repeating sections $new_value .= implode(', ', $val) . "\n"; } } if ($new_value != '') { $value = $new_value; } else { // Only keep non-empty values in array $value = array_filter($value); } } return $value; }
public static function show_entry($atts) { $atts = shortcode_atts(array('id' => false, 'entry' => false, 'fields' => false, 'plain_text' => false, 'user_info' => false, 'include_blank' => false, 'default_email' => false, 'form_id' => false, 'format' => 'text', 'direction' => 'ltr', 'font_size' => '', 'text_color' => '', 'border_width' => '', 'border_color' => '', 'bg_color' => '', 'alt_bg_color' => '', 'clickable' => false), $atts); if ($atts['format'] != 'text') { //format options are text, array, or json $atts['plain_text'] = true; } if (is_object($atts['entry']) && !isset($atts['entry']->metas)) { // if the entry does not include metas, force it again $atts['entry'] = false; } if (!$atts['entry'] || !is_object($atts['entry'])) { if (!$atts['id'] && !$atts['default_email']) { return ''; } if ($atts['id']) { $atts['entry'] = FrmEntry::getOne($atts['id'], true); } } if ($atts['entry']) { $atts['form_id'] = $atts['entry']->form_id; $atts['id'] = $atts['entry']->id; } if (!$atts['fields'] || !is_array($atts['fields'])) { $atts['fields'] = FrmField::get_all_for_form($atts['form_id'], '', 'include'); } $values = array(); foreach ($atts['fields'] as $f) { if ($f->type != 'password' && $f->type != 'credit_card') { self::fill_entry_values($atts, $f, $values); } unset($f); } self::fill_entry_user_info($atts, $values); if ($atts['format'] == 'json') { return json_encode($values); } else { if ($atts['format'] == 'array') { return $values; } } $content = array(); self::convert_entry_to_content($values, $atts, $content); if ('text' == $atts['format']) { $content = implode('', $content); } if ($atts['clickable']) { $content = make_clickable($content); } return $content; }
/** * @covers FrmEntry::package_entry_to_update */ function test_package_entry_to_update() { $entry = FrmEntry::getOne('post-entry-1', true); $values = self::_setup_test_update_values($entry); $new_values = self::_do_private_package_entry_to_update_function($entry->id, $values); self::_check_packaged_entry_name($values, $new_values); self::_check_packaged_form_id($values, $new_values); self::_check_packaged_is_draft($values, $new_values); self::_check_packaged_updated_at($values, $new_values); self::_check_packaged_updated_by($values, $new_values); self::_check_packaged_post_id($values, $new_values); self::_check_packaged_item_key($values, $new_values); self::_check_packaged_parent_item_id($values, $new_values); self::_check_packaged_frm_user_id($values, $new_values); }
/** * @covers FrmNotification::trigger_email */ public function test_trigger_email() { // get the imported form with the email action $form = $this->factory->form->get_object_by_id($this->contact_form_key); // get the email settings $actions = FrmFormAction::get_action_for_form($form->id, 'email'); $this->assertNotEmpty($actions); $entry_data = $this->factory->field->generate_entry_array($form); $entry_id = $this->factory->entry->create($entry_data); $entry = FrmEntry::getOne($entry_id, true); $this->assertNotEmpty($entry); foreach ($actions as $action) { $expected_to = $action->post_content['email_to']; FrmNotification::trigger_email($action, $entry, $form); $this->assertEquals($expected_to, $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]); //$this->assertNotEmpty( strpos( $GLOBALS['phpmailer']->mock_sent[0]['header'], 'Reply-To: admin@example.org' ) ); // TODO: check email body, reply to, cc, bcc, from } }
function email_value($value, $meta, $entry) { global $frm_field; if ($entry->id != $meta->item_id) { $entry = FrmEntry::getOne($meta->item_id); } $field = $frm_field->getOne($meta->field_id); if (!$field) { return $value; } $field->field_options = maybe_unserialize($field->field_options); if (isset($field->field_options['post_field']) and $field->field_options['post_field']) { if ($entry->post_id) { $value = FrmProEntryMetaHelper::get_post_value($entry->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array('truncate' => false, 'form_id' => $entry->form_id, 'field' => $field, 'type' => $field->type, 'truncate' => true)); } else { if ($meta->field_type == 'tag' or $field->field_options['post_field'] == 'post_category' and !empty($value)) { $value = (array) $value; $new_value = array(); foreach ($value as $tax_id) { if (is_numeric($tax_id)) { $cat = $term = get_term($tax_id, $field->field_options['taxonomy']); $new_value[] = $cat ? $cat->name : $tax_id; unset($cat); } else { $new_value[] = $tax_id; } } $value = $new_value; } } } switch ($field->type) { case 'user_id': $value = FrmProFieldsHelper::get_display_name($value); break; case 'data': if (is_array($value)) { $new_value = array(); foreach ($value as $val) { $new_value[] = FrmProFieldsHelper::get_data_value($val, $field); } $value = $new_value; } else { $value = FrmProFieldsHelper::get_data_value($value, $field); } break; case 'file': $value = FrmProFieldsHelper::get_file_name($value); break; case 'date': $value = FrmProFieldsHelper::get_date($value); } if (is_array($value)) { $new_value = ''; foreach ($value as $val) { if (is_array($val)) { $new_value .= implode(', ', $val) . "\n"; } } if ($new_value != '') { $value = $new_value; } } return $value; }
function get_display_value($replace_with, $field, $atts = array()) { $sep = isset($atts['sep']) ? $atts['sep'] : ', '; if ($field->type == 'user_id') { $user_info = isset($atts['show']) ? $atts['show'] : 'display_name'; $replace_with = FrmProFieldsHelper::get_display_name($replace_with, $user_info, $atts); if (is_array($replace_with)) { $new_val = ''; foreach ($replace_with as $key => $val) { if (!empty($new_val)) { $new_val .= ', '; } $new_val .= $key . '. ' . $val; } $replace_with = $new_val; } } else { if ($field->type == 'date') { if (isset($atts['time_ago'])) { $atts['format'] = 'Y-m-d H:i:s'; } if (!isset($atts['format'])) { $atts['format'] = false; } $replace_with = FrmProFieldsHelper::get_date($replace_with, $atts['format']); if (isset($atts['time_ago'])) { $replace_with = FrmProAppHelper::human_time_diff(strtotime($replace_with), strtotime(date_i18n('Y-m-d'))); } } else { if (is_numeric($replace_with) and $field->type == 'file') { //size options are thumbnail, medium, large, or full $size = isset($atts['size']) ? $atts['size'] : 'thumbnail'; if ($size != 'id') { $replace_with = FrmProFieldsHelper::get_media_from_id($replace_with, $size); } } else { if ($field->type == 'data') { //and (is_numeric($replace_with) or is_array($replace_with)) $field->field_options = maybe_unserialize($field->field_options); if (isset($field->field_options['form_select']) and $field->field_options['form_select'] == 'taxonomy') { return $replace_with; } $replace_with = explode($sep, $replace_with); if (isset($atts['show'])) { if (in_array($atts['show'], array('key', 'created-at', 'created_at', 'updated-at', 'updated_at', 'post_id'))) { global $frm_entry; if (is_array($replace_with)) { $linked_ids = $replace_with; $replace_with = ''; foreach ($linked_ids as $linked_id) { $linked_entry = FrmEntry::getOne($linked_id); if (!empty($replace_with)) { $replace_with .= $sep; } if ($atts['show'] == 'created-at') { $replace_with .= $linked_entry->created_at; } else { if ($atts['show'] == 'updated-at') { $replace_with .= $linked_entry->updated_at; } else { if ($atts['show'] == 'key') { $replace_with .= $linked_entry->item_key; } else { $replace_with .= isset($linked_entry->{$atts['show']}) ? $linked_entry->{$atts['show']} : $linked_entry->item_key; } } } } } else { $linked_entry = FrmEntry::getOne($replace_with); if ($atts['show'] == 'created-at') { $replace_with = $linked_entry->created_at; } else { if ($atts['show'] == 'updated-at') { $replace_with = $linked_entry->updated_at; } else { if ($atts['show'] == 'key') { $replace_with = $linked_entry->item_key; } else { $replace_with = isset($linked_entry->{$atts['show']}) ? $linked_entry->{$atts['show']} : $linked_entry->item_key; } } } } } else { if ($atts['show'] == 'id') { if (is_array($replace_with)) { $replace_with = implode($sep, $replace_with); } //just keep the value since it's already the id } else { if (is_array($replace_with)) { $linked_ids = $replace_with; $replace_with = array(); foreach ($linked_ids as $linked_id) { $new_val = FrmProFieldsHelper::get_data_value($linked_id, $field, $atts); if ($linked_id != $new_val) { $replace_with[] = $new_val; } unset($new_val); } $replace_with = implode($sep, $replace_with); } else { $replace_with = FrmProFieldsHelper::get_data_value($replace_with, $field, $atts); } } } } else { if (is_array($replace_with)) { $linked_ids = $replace_with; $replace_with = array(); foreach ($linked_ids as $linked_id) { $new_val = FrmProFieldsHelper::get_data_value($linked_id, $field, $atts); if ($linked_id != $new_val) { $replace_with[] = $new_val; } unset($new_val); } $replace_with = implode($sep, $replace_with); } else { $replace_with = FrmProFieldsHelper::get_data_value($replace_with, $field, $atts); } } } else { if ($field->type == 'textarea') { $autop = isset($atts['wpautop']) ? $atts['wpautop'] : true; if (apply_filters('frm_use_wpautop', $autop)) { $replace_with = wpautop($replace_with); } unset($autop); } else { if ($field->type == 'number') { if (!isset($atts['decimal'])) { $num = explode('.', $replace_with); $atts['decimal'] = isset($num[1]) ? strlen($num[1]) : 0; } if (!isset($atts['dec_point'])) { $atts['dec_point'] = '.'; } if (!isset($atts['thousands_sep'])) { $atts['thousands_sep'] = ''; } $replace_with = number_format($replace_with, $atts['decimal'], $atts['dec_point'], $atts['thousands_sep']); } } } } } } $replace_with = stripslashes_deep($replace_with); return $replace_with; }
public static function get_data_display_value($replace_with, $atts, $field) { //if ( is_numeric($replace_with) || is_array($replace_with) ) if (!isset($field->field_options['form_select']) || $field->field_options['form_select'] == 'taxonomy') { return $replace_with; } $sep = isset($atts['sep']) ? $atts['sep'] : ', '; $atts['show'] = isset($atts['show']) ? $atts['show'] : false; if (!empty($replace_with) && !is_array($replace_with)) { $replace_with = explode($sep, $replace_with); } $linked_ids = (array) $replace_with; $replace_with = array(); if ($atts['show'] == 'id') { // keep the values the same since we already have the ids $replace_with = $linked_ids; } else { if (in_array($atts['show'], array('key', 'created-at', 'created_at', 'updated-at', 'updated_at, updated-by, updated_by', 'post_id'))) { $nice_show = str_replace('-', '_', $atts['show']); foreach ($linked_ids as $linked_id) { $linked_entry = FrmEntry::getOne($linked_id); if (isset($linked_entry->{$atts['show']})) { $replace_with[] = $linked_entry->{$atts['show']}; } else { if (isset($linked_entry->{$nice_show})) { $replace_with[] = $linked_entry->{$nice_show}; } else { $replace_with[] = $linked_entry->item_key; } } } } else { foreach ($linked_ids as $linked_id) { $new_val = self::get_data_value($linked_id, $field, $atts); if ($linked_id == $new_val) { continue; } if (is_array($new_val)) { $new_val = implode($sep, $new_val); } $replace_with[] = $new_val; unset($new_val); } } } return implode($sep, $replace_with); }
function get_object_by_id($entry_id) { return FrmEntry::getOne($entry_id); }
public static function is_new_entry($entry) { if (is_numeric($entry)) { $frm_entry = new FrmEntry(); $entry = $frm_entry->getOne($entry); } // this function will only be correct if the entry has already gone through FrmProEntriesController::check_draft_status if ($entry->created_at == $entry->updated_at) { return true; } return false; }
public static function repeat_field_set($field_name, $args = array()) { $defaults = array('i' => 0, 'entry_id' => false, 'form' => false, 'fields' => array(), 'errors' => array(), 'parent_field' => 0, 'repeat' => 0, 'row_count' => false, 'value' => '', 'field_name' => ''); $args = wp_parse_args($args, $defaults); if (empty($args['parent_field'])) { return; } if (is_numeric($args['parent_field'])) { $args['parent_field'] = (array) FrmField::getOne($args['parent_field']); $args['parent_field']['format'] = isset($args['parent_field']['field_options']['format']) ? $args['parent_field']['field_options']['format'] : ''; } FrmForm::maybe_get_form($args['form']); if (empty($args['fields'])) { $args['fields'] = FrmField::get_all_for_form($args['form']->id); } $values = array(); if ($args['fields']) { // Get the ID of the form that houses the embedded form or repeating section $parent_form_id = $args['parent_field']['form_id']; if (empty($args['entry_id'])) { $values = FrmEntriesHelper::setup_new_vars($args['fields'], $args['form'], false, array('parent_form_id' => $parent_form_id)); } else { $entry = FrmEntry::getOne($args['entry_id'], true); if ($entry && $entry->form_id == $args['form']->id) { $values = FrmAppHelper::setup_edit_vars($entry, 'entries', $args['fields'], false, array(), array('parent_form_id' => $parent_form_id)); } else { return; } } } $format = isset($args['parent_field']['format']) ? $args['parent_field']['format'] : ''; $end = false; $count = 0; foreach ($values['fields'] as $subfield) { if ('end_divider' == $subfield['type']) { $end = $subfield; } else { if (!in_array($subfield['type'], array('hidden', 'user_id'))) { if (isset($subfield['conf_field']) && $subfield['conf_field']) { $count = $count + 2; } else { $count++; } } } unset($subfield); } if ($args['repeat']) { $count++; } $classes = array(2 => 'half', 3 => 'third', 4 => 'fourth', 5 => 'fifth', 6 => 'sixth', 7 => 'seventh', 8 => 'eighth'); $field_class = !empty($format) && isset($classes[$count]) ? $classes[$count] : ''; echo '<div id="frm_section_' . $args['parent_field']['id'] . '-' . $args['i'] . '" class="frm_repeat_' . (empty($format) ? 'sec' : $format) . ' frm_repeat_' . $args['parent_field']['id'] . ($args['row_count'] === 0 ? ' frm_first_repeat' : '') . '">' . "\n"; self::add_hidden_repeat_entry_id($args); self::add_default_item_meta_field($args); $label_pos = 'top'; $field_num = 1; foreach ($values['fields'] as $subfield) { $subfield_name = $field_name . '[' . $args['i'] . '][' . $subfield['id'] . ']'; $subfield_plus_id = '-' . $args['i']; $subfield_id = $subfield['id'] . '-' . $args['parent_field']['id'] . $subfield_plus_id; if ($args['parent_field'] && !empty($args['parent_field']['value']) && isset($args['parent_field']['value']['form']) && isset($args['parent_field']['value'][$args['i']]) && isset($args['parent_field']['value'][$args['i']][$subfield['id']])) { // this is a posted value from moving between pages, so set the POSTed value $subfield['value'] = $args['parent_field']['value'][$args['i']][$subfield['id']]; } if (!empty($field_class)) { if (1 == $field_num) { $subfield['classes'] .= ' frm_first frm_' . $field_class; } else { $subfield['classes'] .= ' frm_' . $field_class; } } $field_num++; if ('top' == $label_pos && in_array($subfield['label'], array('top', 'hidden', ''))) { // add placeholder label if repeating $label_pos = 'hidden'; } $field_args = array('field_name' => $subfield_name, 'field_id' => $subfield_id, 'field_plus_id' => $subfield_plus_id, 'section_id' => $args['parent_field']['id']); if (apply_filters('frm_show_normal_field_type', true, $subfield['type'])) { echo FrmFieldsHelper::replace_shortcodes($subfield['custom_html'], $subfield, $args['errors'], $args['form'], $field_args); } else { do_action('frm_show_other_field_type', $subfield, $args['form'], $field_args); } unset($subfield_name, $subfield_id); do_action('frm_get_field_scripts', $subfield, $args['form'], $args['parent_field']['form_id']); } if (!$args['repeat']) { // Close frm_repeat div echo '</div>' . "\n"; return; } $args['format'] = $format; $args['label_pos'] = $label_pos; $args['field_class'] = $field_class; echo self::repeat_buttons($args, $end); // Close frm_repeat div echo '</div>' . "\n"; }
public static function show($id = 0) { FrmAppHelper::permission_check('frm_view_entries'); if (!$id) { $id = FrmAppHelper::get_param('id', 0, 'get', 'absint'); if (!$id) { $id = FrmAppHelper::get_param('item_id', 0, 'get', 'absint'); } } $entry = FrmEntry::getOne($id, true); if (!$entry) { echo '<div id="form_show_entry_page" class="wrap">' . __('You are trying to view an entry that does not exist.', 'formidable') . '</div>'; return; } $data = maybe_unserialize($entry->description); if (!is_array($data) || !isset($data['referrer'])) { $data = array('referrer' => $data); } $fields = FrmField::get_all_for_form($entry->form_id, '', 'include'); $to_emails = array(); include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php'; }
public static function show($id = 0) { FrmAppHelper::permission_check('frm_view_entries'); if (!$id) { $id = FrmAppHelper::get_param('id', 0, 'get', 'absint'); if (!$id) { $id = FrmAppHelper::get_param('item_id', 0, 'get', 'absint'); } } $entry = FrmEntry::getOne($id, true); $data = maybe_unserialize($entry->description); if (!is_array($data) || !isset($data['referrer'])) { $data = array('referrer' => $data); } $fields = FrmField::get_all_for_form($entry->form_id, '', 'include'); $to_emails = array(); include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php'; }
private static function get_edit_vars($id, $errors = array(), $message = '') { global $frm_vars; $description = true; $title = false; $record = FrmEntry::getOne($id, true); if (!$record) { wp_die(__('You are trying to access an entry that does not exist.', 'formidable')); return; } $frm_vars['editing_entry'] = $id; $form = FrmForm::getOne($record->form_id); $form = apply_filters('frm_pre_display_form', $form); $fields = FrmFieldsHelper::get_form_fields($form->id, !empty($errors)); $values = FrmAppHelper::setup_edit_vars($record, 'entries', $fields); $frmpro_settings = new FrmProSettings(); $edit_create = $record->is_draft ? isset($values['submit_value']) ? $values['submit_value'] : $frmpro_settings->submit_value : (isset($values['edit_value']) ? $values['edit_value'] : $frmpro_settings->update_value); $submit = isset($frm_vars['next_page'][$form->id]) ? $frm_vars['next_page'][$form->id] : $edit_create; unset($edit_create); if (is_object($submit)) { $submit = $submit->name; } require FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-entries/edit.php'; }
/** * If a form is a child form, get the parent form. Then if the entry is a child entry, get the parent entry. * * @since 2.0.13 * @param int|object $form - pass by reference * @param int|object $entry - pass by reference */ private static function maybe_get_parent_form_and_entry(&$form, &$entry) { // If form is a child form, refer to parent form's settings if ($form->parent_form_id) { $form = FrmForm::getOne($form->parent_form_id); // Make sure we're also checking the parent entry's permissions FrmEntry::maybe_get_entry($entry); if ($entry->parent_item_id) { $entry = FrmEntry::getOne($entry->parent_item_id); } } }
/** * @param string $event */ public static function trigger_actions($event, $form, $entry, $type = 'all', $args = array()) { $form_actions = FrmFormAction::get_action_for_form(is_object($form) ? $form->id : $form, $type); if (empty($form_actions)) { return; } FrmForm::maybe_get_form($form); $link_settings = self::get_form_actions($type); if ('all' != $type) { $link_settings = array($type => $link_settings); } $stored_actions = $action_priority = array(); $importing = in_array($event, array('create', 'update')) && defined('WP_IMPORTING') && WP_IMPORTING; foreach ($form_actions as $action) { $trigger_on_import = $importing && in_array('import', $action->post_content['event']); $skip_this_action = !in_array($event, $action->post_content['event']) && !$trigger_on_import; $skip_this_action = apply_filters('frm_skip_form_action', $skip_this_action, compact('action', 'entry', 'form', 'event')); if ($skip_this_action) { continue; } if (!is_object($entry)) { $entry = FrmEntry::getOne($entry, true); } if (empty($entry) || $entry->is_draft && $event != 'draft') { continue; } $child_entry = $form && is_numeric($form->parent_form_id) && $form->parent_form_id || $entry && ($entry->form_id != $form->id || $entry->parent_item_id) || isset($args['is_child']) && $args['is_child']; if ($child_entry) { // maybe trigger actions for sub forms $trigger_children = apply_filters('frm_use_embedded_form_actions', false, compact('form', 'entry')); if (!$trigger_children) { continue; } } // check conditional logic $stop = FrmFormAction::action_conditions_met($action, $entry); if ($stop) { continue; } // store actions so they can be triggered with the correct priority $stored_actions[$action->ID] = $action; $action_priority[$action->ID] = $link_settings[$action->post_excerpt]->action_options['priority']; unset($action); } if (!empty($stored_actions)) { asort($action_priority); // make sure hooks are loaded new FrmNotification(); foreach ($action_priority as $action_id => $priority) { $action = $stored_actions[$action_id]; do_action('frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event); do_action('frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form); // If post is created, get updated $entry object if ($action->post_excerpt == 'wppost' && $event == 'create') { $entry = FrmEntry::getOne($entry->id, true); } } } }
/** * @param string $event */ public static function trigger_actions($event, $form, $entry, $type = 'all', $args = array()) { $form_actions = FrmFormAction::get_action_for_form(is_object($form) ? $form->id : $form, $type); if (empty($form_actions)) { return; } FrmForm::maybe_get_form($form); $link_settings = self::get_form_actions($type); if ('all' != $type) { $link_settings = array($type => $link_settings); } $stored_actions = $action_priority = array(); foreach ($form_actions as $action) { if (!in_array($event, $action->post_content['event'])) { continue; } if (!is_object($entry)) { $entry = FrmEntry::getOne($entry, true); } if (empty($entry) || $entry->is_draft) { continue; } $child_entry = $form && is_numeric($form->parent_form_id) && $form->parent_form_id || $entry && ($entry->form_id != $form->id || $entry->parent_item_id) || isset($args['is_child']) && $args['is_child']; if ($child_entry) { //don't trigger actions for sub forms continue; } // check conditional logic $stop = FrmFormAction::action_conditions_met($action, $entry); if ($stop) { continue; } // store actions so they can be triggered with the correct priority $stored_actions[$action->ID] = $action; $action_priority[$action->ID] = $link_settings[$action->post_excerpt]->action_options['priority']; unset($action); } if (!empty($stored_actions)) { asort($action_priority); // make sure hooks are loaded new FrmNotification(); foreach ($action_priority as $action_id => $priority) { $action = $stored_actions[$action_id]; do_action('frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event); do_action('frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form); // If post is created, get updated $entry object if ($action->post_excerpt == 'wppost' && $event == 'create') { $entry = FrmEntry::getOne($entry->id, true); } } } }
/** * After the sub entry and parent entry are created, we can update the parent id field * @since 2.0 */ public static function update_parent_id($entry_id, $form_id) { $form_fields = FrmProFormsHelper::has_field('form', $form_id, false); $section_fields = FrmProFormsHelper::has_repeat_field($form_id, false); if (!$form_fields && !$section_fields) { return; } $form_fields = array_merge($section_fields, $form_fields); $entry = FrmEntry::getOne($entry_id, true); if (!$entry || $entry->form_id != $form_id) { return; } $sub_ids = array(); foreach ($form_fields as $field) { if (!isset($entry->metas[$field->id])) { continue; } $ids = maybe_unserialize($entry->metas[$field->id]); if (!empty($ids)) { $sub_ids = array_merge($ids, $sub_ids); } unset($field); } if (!empty($sub_ids)) { $where = array('id' => $sub_ids); FrmDb::get_where_clause_and_values($where); array_unshift($where['values'], $entry_id); global $wpdb; $wpdb->query($wpdb->prepare('UPDATE ' . $wpdb->prefix . 'frm_items SET parent_item_id = %d' . $where['where'], $where['values'])); } }