public function display_form_front_end(array $atts = array()) { if (!isset($atts['id'])) { return; } ob_start(); Ninja_Forms()->display($atts['id']); return ob_get_clean(); }
function nf_csv_attachment($sub_id) { global $ninja_forms_processing; // make sure this form is supposed to attach a CSV if (1 == $ninja_forms_processing->get_form_setting('admin_attach_csv') and 'submit' == $ninja_forms_processing->get_action()) { // create CSV content $csv_content = Ninja_Forms()->sub($sub_id)->export(true); $upload_dir = wp_upload_dir(); $path = trailingslashit($upload_dir['path']); // create temporary file $path = tempnam($path, 'Sub'); $temp_file = fopen($path, 'r+'); // write to temp file fwrite($temp_file, $csv_content); fclose($temp_file); // find the directory we will be using for the final file $path = pathinfo($path); $dir = $path['dirname']; $basename = $path['basename']; // create name for file $new_name = apply_filters('ninja_forms_submission_csv_name', 'ninja-forms-submission'); // remove a file if it already exists if (file_exists($dir . '/' . $new_name . '.csv')) { unlink($dir . '/' . $new_name . '.csv'); } // move file rename($dir . '/' . $basename, $dir . '/' . $new_name . '.csv'); $file1 = $dir . '/' . $new_name . '.csv'; // add new file to array of existing files $files = $ninja_forms_processing->get_form_setting('admin_attachments'); array_push($files, $file1); $ninja_forms_processing->update_form_setting('admin_attachments', $files); $ninja_forms_processing->update_extra_value('_attachment_csv_path', $file1); } }
/** * Process our Push notification * * @access public * @since 0.0.1 * @return void */ public function process($id) { $form_id = $id ? Ninja_Forms()->notification($id)->form_id : ''; $api_key = Ninja_Forms()->notification($id)->get_setting('api_key'); $list_id = Ninja_Forms()->notification($id)->get_setting('list_id'); $email = $this->process_setting($id, 'email'); if (empty($api_key) || empty($list_id) || empty($email)) { //file_put_contents('/tmp/notifications-pushbullet-class.log', "Empty access token\n", FILE_APPEND); return; } $first_name = $this->process_setting($id, 'first_name'); $last_name = $this->process_setting($id, 'last_name'); $merge_fields = array(); if ($first_name) { $merge_fields['FNAME'] = $first_name; } if ($last_name) { $merge_fields['LNAME'] = $last_name; } $mc = new MailChimp($api_key); $added = $mc->post("lists/{$list_id}/members", array('email_address' => $email, 'status' => 'subscribed', 'merge_fields' => $merge_fields)); if ($added) { // } else { // Could be SSL-verify of cURL that fails... } }
function ninja_forms_preview_link($form_id = '', $echo = true) { if ($form_id == '') { if (isset($_REQUEST['form_id'])) { $form_id = absint($_REQUEST['form_id']); } else { $form_id = ''; } } $base = home_url(); $form_data = ninja_forms_get_form_by_id($form_id); $append_page = Ninja_Forms()->form($form_id)->get_setting('append_page'); if (empty($append_page)) { $opt = nf_get_settings(); if (isset($opt['preview_id'])) { $page_id = $opt['preview_id']; } else { $page_id = ''; } } else { $page_id = $append_page; } if ($echo) { $preview_link = '<a target="_blank" href="' . $base . '/?page_id=' . $page_id . '&preview=true&form_id=' . $form_id . '">' . __('Preview Form', 'ninja-forms') . '</a>'; } else { $preview_link = $base . '/?page_id=' . $page_id . '&preview=true&form_id=' . $form_id; } return $preview_link; }
function ninja_forms_export_form($form_id) { if ($form_id == '') { return; } $plugin_settings = nf_get_settings(); $form_title = Ninja_Forms()->form($form_id)->get_setting('form_title'); $form_row = ninja_forms_serialize_form($form_id); $form_title = preg_replace('/[^a-zA-Z0-9-]/', '', $form_title); $form_title = str_replace(" ", "-", $form_title); if (isset($plugin_settings['date_format'])) { $date_format = $plugin_settings['date_format']; } else { $date_format = 'm/d/Y'; } //$today = date($date_format); $current_time = current_time('timestamp'); $today = date($date_format, $current_time); header("Content-type: application/csv"); header('Content-Disposition: attachment; filename="' . $form_title . '"-"' . $today . '".nff"'); header("Pragma: no-cache"); header("Expires: 0"); echo $form_row; die; }
public function process($action_settings, $form_id, $data) { if (isset($data['settings']['is_preview']) && $data['settings']['is_preview']) { return $data; } if (!apply_filters('ninja_forms_save_submission', true, $form_id)) { return $data; } $sub = Ninja_Forms()->form($form_id)->sub()->get(); $hidden_field_types = apply_filters('nf_sub_hidden_field_types', array()); foreach ($data['fields'] as $field) { if (in_array($field['type'], array_values($hidden_field_types))) { $data['actions']['save']['hidden'][] = $field['type']; continue; } $field['value'] = apply_filters('nf_save_sub_user_value', $field['value'], $field['id']); $sub->update_field_value($field['id'], $field['value']); } if (isset($data['extra'])) { $sub->update_extra_values($data['extra']); } do_action('nf_before_save_sub', $sub->get_id()); $sub->save(); do_action('nf_save_sub', $sub->get_id()); do_action('nf_create_sub', $sub->get_id()); do_action('ninja_forms_save_sub', $sub->get_id()); $data['actions']['save']['sub_id'] = $sub->get_id(); return $data; }
public function step() { $exported_subs = get_user_option(get_current_user_id(), 'nf_download_all_subs_ids'); if (!is_array($exported_subs)) { $exported_subs = array(); } $previous_name = get_user_option(get_current_user_id(), 'nf_download_all_subs_filename'); if ($previous_name) { $this->args['filename'] = $previous_name; } $args = array('posts_per_page' => 250, 'paged' => $this->step, 'post_type' => 'nf_sub', 'meta_query' => array(array('key' => '_form_id', 'value' => $this->args['form_id']))); $subs_results = get_posts($args); if (is_array($subs_results) && !empty($subs_results)) { $upload_dir = wp_upload_dir(); $file_path = trailingslashit($upload_dir['path']) . $this->args['filename'] . '.csv'; $myfile = fopen($file_path, 'a') or die('Unable to open file!'); $x = 0; $export = ''; foreach ($subs_results as $sub) { $sub_export = Ninja_Forms()->sub($sub->ID)->export(true); if ($x > 0 || $this->step > 1) { $sub_export = substr($sub_export, strpos($sub_export, "\n") + 1); } if (!in_array($sub->ID, $exported_subs)) { $export .= $sub_export; $exported_subs[] = $sub->ID; } $x++; } fwrite($myfile, $export); fclose($myfile); } update_user_option(get_current_user_id(), 'nf_download_all_subs_ids', $exported_subs); }
/** * Adds our not logged-in message if the user is not logged-in and the form requires the user to be logged-in. * * @since 2.9 * @return void */ function nf_not_logged_in_msg($form_id) { $not_logged_in = Ninja_Forms()->form($form_id)->get_setting('logged_in'); if (!is_user_logged_in() && 1 == $not_logged_in) { echo Ninja_Forms()->form($form_id)->get_setting('not_logged_in_msg'); } }
/** * Update the "attach file to this email" settings on any "Admin" email notifications we may have. * * @since 1.3.8 * @return void */ function nf_fu_upgrade_settings() { // Check to see if we've already done this. $updated = get_option('nf_convert_upload_settings_complete', false); if ($updated || version_compare(NINJA_FORMS_VERSION, '2.8', '<')) { return; } $notifications = nf_get_all_notifications(); // Make sure that there are some notifications. if (!is_array($notifications)) { return; } // Loop through our notifications and see if any of them were "admin emails" foreach ($notifications as $n) { if (Ninja_Forms()->notification($n['id'])->get_setting('admin_email')) { // Grab our form id so that we can loop over our fields. $form_id = Ninja_Forms()->notification($n['id'])->form_id; // Loop over our form fields. If we find an upload field, see if the option is checked. foreach (Ninja_Forms()->form($form_id)->fields as $field_id => $field) { if ('_upload' == $field['type'] && isset($field['data']['email_attachment']) && $field['data']['email_attachment'] == 1) { Ninja_Forms()->notification($n['id'])->update_setting('file_upload_' . $field_id, 1); } } } } update_option('nf_convert_upload_settings_complete', true); }
/** * Function that registers a notification type * * @access public * @param string $slug - Notification type slug. Must be unique. * @param string $classname - Name of the class that should be used for the notification type. * @since 3.0 * @return void */ public function notification_type($slug, $nicename, $classname) { if (!empty($slug) && !empty($classname) && !isset(Ninja_Forms()->registered_field_types[$slug])) { Ninja_Forms()->registered_notification_types[$slug]['nicename'] = $nicename; Ninja_Forms()->registered_notification_types[$slug]['classname'] = $classname; } }
/** * Delete a form if it is created and not saved within 24 hrs. * * @access public * @since 2.9 * @return void */ public function maybe_delete($form_id) { $status = Ninja_Forms()->form($form_id)->get_setting('status'); if ('new' == $status) { Ninja_Forms()->form($form_id)->delete(); } }
function ninja_forms_get_form_by_sub_id($sub_id) { global $wpdb; $form_id = Ninja_Forms()->sub($sub_id)->form_id; $form_row = ninja_forms_get_form_by_id($form_id); return $form_row; }
/** * Process * * @param string $id * @return void */ public function process($id) { global $ninja_forms_processing; $form_id = $ninja_forms_processing->get_form_ID(); $form_title = $ninja_forms_processing->get_form_setting('form_title'); $all_fields = ninja_forms_get_fields_by_form_id($form_id); $total = ''; // Get IDs of fields that are to be sent to PayPal $accepted_fields = $PayPalEmail = Ninja_Forms()->notification($id)->get_setting('accepted_fields'); $accepted_ary = explode(',', $accepted_fields); if (is_array($all_fields)) { foreach ($all_fields as $field) { $value = $ninja_forms_processing->get_field_value($field['id']); if (in_array($field['id'], $accepted_ary)) { $total += $value; } } } // Grab PayPal email from NF setting $paypal_email = Ninja_Forms()->notification($id)->get_setting('paypal_email'); // Format PayPal URL $url = 'https://www.paypal.com/us/cgi-bin/webscr?cmd=_xclick &business=' . urlencode($paypal_email) . ' &item_name=' . urlencode($form_title) . ' &item_number= &amount=' . $total . ' &no_shipping=1 &return=' . site_url() . ' ¤cy_code=USD&lc=US&bn=PP-BuyNowBF'; // Do the redirection to PayPal wp_redirect($url); exit; }
/** * Creates a Form * * ## OPTIONS * * <title> * : The form title. * * ## EXAMPLES * * wp ninja-forms form "My New Form" * * @synopsis <title> * @subcommand form * @alias create-form */ public function create_form($args, $assoc_args) { list($title) = $args; $form = Ninja_Forms()->form()->get(); $form->update_setting('title', $title); $form->save(); }
function ninja_forms_session_class_setup() { $cache = Ninja_Forms()->session->get('nf_cache'); if ($cache && !is_admin()) { add_action('init', 'ninja_forms_setup_processing_class', 5); } }
/** * Process our Success Message notification * * @access public * @since 2.8 * @return void */ public function process($id) { global $ninja_forms_processing; $success_msg = Ninja_Forms()->notification($id)->get_setting('success_msg'); $success_msg = do_shortcode(wpautop($success_msg)); $ninja_forms_processing->add_success_msg('success_msg', $success_msg); }
function nf_save_sub() { global $ninja_forms_processing, $ninja_forms_fields; // save forms by default $save = true; // check if there's some legacy save settings saved in the database if (0 === $ninja_forms_processing->get_form_setting('save_subs')) { $save = false; } $save = apply_filters('ninja_forms_save_submission', $save, $ninja_forms_processing->get_form_ID()); if ($save) { $action = $ninja_forms_processing->get_action(); $user_id = $ninja_forms_processing->get_user_ID(); $sub_id = $ninja_forms_processing->get_form_setting('sub_id'); $form_id = $ninja_forms_processing->get_form_ID(); $field_data = $ninja_forms_processing->get_all_fields(); // If we don't have a submission ID already, create a submission post. if (empty($sub_id)) { $sub_id = Ninja_Forms()->subs()->create($form_id); Ninja_Forms()->sub($sub_id)->update_user_id($user_id); do_action('nf_create_sub', $sub_id); // Update our legacy $ninja_forms_processing with the new sub_id $ninja_forms_processing->update_form_setting('sub_id', $sub_id); } do_action('nf_before_save_sub', $sub_id); Ninja_Forms()->sub($sub_id)->update_action($action); if (is_array($field_data) && !empty($field_data)) { // Loop through our submitted data and add the values found there. // Maintain backwards compatibility with older extensions that use the ninja_forms_save_sub_args filter. $data = array(); // foreach ($field_data as $field_id => $user_value) { $field_row = $ninja_forms_processing->get_field_settings($field_id); $field_type = $field_row['type']; if (isset($ninja_forms_fields[$field_type]['save_sub'])) { $save_sub = $ninja_forms_fields[$field_type]['save_sub']; if ($save_sub) { $user_value = apply_filters('nf_save_sub_user_value', $user_value, $field_id); if (is_array($user_value)) { $user_value = ninja_forms_esc_html_deep($user_value); } else { $user_value = esc_html($user_value); } // Add our submitted field value. Ninja_Forms()->sub($sub_id)->add_field($field_id, $user_value); // Maintain backwards compatibility with older extensions that use the ninja_forms_save_sub_args filter. $data[] = array('field_id' => $field_id, 'user_value' => $user_value); // } } } } // Maintain backwards compatibility with older extensions that still use the ninja_forms_save_sub_args filter. $args = apply_filters('ninja_forms_save_sub_args', array('sub_id' => $sub_id, 'form_id' => $form_id, 'data' => serialize($data))); ninja_forms_update_sub($args); // do_action('nf_save_sub', $sub_id); } }
/** * @return string */ function the_title($title) { if (!in_the_loop()) { return $title; } $form_title = Ninja_Forms()->form($this->_form_id)->get()->get_setting('title'); return $form_title . " " . __('Preview', 'ninja-forms'); }
protected function handle() { if (!isset($_POST['field_id'])) { return; } $field = Ninja_Forms()->form()->get_field($_POST['field_id']); $field->delete(); }
public function render_metabox($post, $metabox) { wp_nonce_field('ninja_forms_append_form', 'nf_append_form'); $forms = Ninja_Forms()->form()->get_forms(); $form_id = get_post_meta($post->ID, 'ninja_forms_form', true); $none_text = '-- ' . __('None', 'ninja-forms'); Ninja_Forms()->template('admin-metabox-append-a-form.html.php', compact('forms', 'form_id', 'none_text')); }
/** * Process our Success Message notification * * @access public * @since 2.8 * @return void */ public function process($id) { global $ninja_forms_processing; $success_msg = apply_filters('nf_success_msg', Ninja_Forms()->notification($id)->get_setting('success_msg'), $id); $success_msg = do_shortcode(wpautop($success_msg)); $success_msg = nf_parse_fields_shortcode($success_msg); $ninja_forms_processing->add_success_msg('success_msg', $success_msg); }
/** * Get things rolling by instantiating our notification type classes. */ function __construct() { foreach (Ninja_Forms()->registered_notification_types as $slug => $type) { $classname = $type['classname']; if (class_exists($classname)) { $this->{$slug} = new $classname(); } } }
public function save() { check_ajax_referer('ninja_forms_ajax_nonce', 'security'); if (!isset($_POST['form'])) { $this->_errors[] = 'Form Not Found'; $this->_respond(); } $form_data = json_decode(stripslashes($_POST['form']), ARRAY_A); if (is_string($form_data['id'])) { $tmp_id = $form_data['id']; $form = Ninja_Forms()->form()->get(); $form->save(); $form_data['id'] = $form->get_id(); $this->_data['new_ids']['forms'][$tmp_id] = $form_data['id']; } else { $form = Ninja_Forms()->form($form_data['id'])->get(); } $form->update_settings($form_data['settings'])->save(); if (isset($form_data['fields'])) { foreach ($form_data['fields'] as $field_data) { $id = $field_data['id']; $field = Ninja_Forms()->form($form_data['id'])->get_field($id); $field->update_settings($field_data['settings'])->save(); if ($field->get_tmp_id()) { $tmp_id = $field->get_tmp_id(); $this->_data['new_ids']['fields'][$tmp_id] = $field->get_id(); } $this->_data['fields'][$id] = $field->get_settings(); } } if (isset($form_data['deleted_fields'])) { foreach ($form_data['deleted_fields'] as $deleted_field_id) { $field = Ninja_Forms()->form()->get_field($deleted_field_id); $field->delete(); } } if (isset($form_data['actions'])) { foreach ($form_data['actions'] as $action_data) { $id = $action_data['id']; $action = Ninja_Forms()->form($form_data['id'])->get_action($action_data['id']); $action->update_settings($action_data['settings'])->save(); if ($action->get_tmp_id()) { $tmp_id = $action->get_tmp_id(); $this->_data['new_ids']['actions'][$tmp_id] = $action->get_id(); } $this->_data['actions'][$id] = $action->get_settings(); } } if (isset($form_data['deleted_actions'])) { foreach ($form_data['deleted_actions'] as $deleted_action_id) { $action = Ninja_Forms()->form()->get_action($deleted_action_id); $action->delete(); } } delete_user_option(get_current_user_id(), 'nf_form_preview_' . $form_data['id']); $this->_respond(); }
function ninja_forms_session_class_setup() { $transient_id = Ninja_Forms()->session->get('nf_transient_id'); if ($transient_id && !is_admin()) { if (get_transient($transient_id) !== false) { add_action('init', 'ninja_forms_setup_processing_class', 5); } } }
/** * Included for backwards compatibility with Visual Composer. */ function ninja_forms_get_all_forms() { // Ninja_Forms::deprecated_notice( 'ninja_forms_get_all_forms', '3.0', 'Ninja_Forms()->form()->get_forms()', debug_backtrace() ); $forms = array(); foreach (Ninja_Forms()->form()->get_forms() as $form) { $forms[] = array('id' => $form->get_id(), 'data' => $form->get_settings(), 'name' => $form->get_setting('title')); } return $forms; }
public function admin_form_element($id, $value) { $field = Ninja_Forms()->form()->get_field($id); $list = ''; foreach ($field->get_setting('options') as $option) { $checked = in_array($option['value'], $value) ? "checked" : ''; $list .= "<li><label><input type='checkbox' value='{$option['value']}' name='fields[{$id}][]' {$checked}> {$option['label']}</label></li>"; } return "<ul>{$list}</ul>"; }
public function set_merge_tags($key, $value) { $callback = is_numeric($key) ? 'calc_' . $key : $key; try { $calculated_value = Ninja_Forms()->eos()->solve($value); } catch (Exception $e) { $calculated_value = FALSE; } $this->merge_tags[$callback] = array('id' => $key, 'tag' => "{calc:{$key}}", 'callback' => $callback, 'calc_value' => $calculated_value); }
public function admin_form_element($id, $value) { $field = Ninja_Forms()->form()->get_field($id); $options = ''; foreach ($field->get_setting('options') as $option) { $selected = in_array($option['value'], $value) ? "selected" : ''; $options .= "<option value='{$option['value']}' {$selected}>{$option['label']}</option>"; } return "<select class='widefat' name='fields[{$id}]' id='' multiple>{$options}</select>"; }
function nf_get_settings() { $instance = Ninja_Forms(); if (!empty($instance) && !empty($instance->plugin_settings)) { $settings = Ninja_Forms()->plugin_settings; } else { $settings = Ninja_Forms()->get_plugin_settings(); } return $settings; }
private function get_options() { $order = 0; $options = array(); foreach (Ninja_Forms()->config('StateList') as $label => $value) { $options[] = array('label' => $label, 'value' => $value, 'calc' => '', 'selected' => 0, 'order' => $order); $order++; } return $options; }