/** * Called by Ninja Forms. Adds CSS classes to support multi column layout. */ function before_field($field_id) { // Form data $form = ninja_forms_get_form_by_field_id($field_id); $form_data = isset($form['data']['bti_layout_master']) ? $form['data']['bti_layout_master'] : array(); $rendering = isset($form_data['rendering']) ? $form_data['rendering'] : ''; // Field data $field = ninja_forms_get_field_by_id($field_id); $field_data = isset($field['data']['bti_layout_master']) ? $field['data']['bti_layout_master'] : array(); // Rendering type if ('' == $rendering) { // Data for class name $sizex = isset($field_data['sizex']) ? $field_data['sizex'] : 1; $cols = isset($form_data['cols']) ? $form_data['cols'] : 1; $before = ''; $after = ''; // Before if (isset($field_data['before']) && $field_data['before'] > 0) { $before = 'bti-lm-b-' . $cols . '-' . $field_data['before'] . ' '; } // After if (isset($field_data['after']) && $field_data['after'] > 0) { $after = ' bti-lm-a-' . $cols . '-' . $field_data['after']; } echo '<div class="' . $before . 'bti-lm-col-' . $cols . '-' . $sizex . $after . '">'; } else { $row = isset($field_data['row']) ? $field_data['row'] : 1; $col = isset($field_data['col']) ? $field_data['col'] : 1; $cols = isset($form_data['cols']) ? $form_data['cols'] : 1; if (1 == $row) { echo '<div class="bti-lm-col2-' . $cols . '-' . $col . '">'; } echo '<div class="bti-lm-col2-item">'; } }
function ninja_forms_edit_field_list_term($field_id) { $field_row = ninja_forms_get_field_by_id($field_id); $field_type = $field_row['type']; $field_data = $field_row['data']; if (isset($field_data['populate_term'])) { $populate_term = $field_data['populate_term']; } else { $populate_term = ''; } $form_row = ninja_forms_get_form_by_field_id($field_id); if (isset($form_row['data']['post_type'])) { $post_type = $form_row['data']['post_type']; } else { $post_type = ''; } if ($field_type == '_list' and $post_type != '') { ?> <div> <label> <?php _e('Populate this with the term: ', 'ninja-forms-post-creation'); ?> <select name="ninja_forms_field_<?php echo $field_id; ?> [populate_term]"> <option value=""><?php _e('- None', 'ninja-forms-post-creation'); ?> </option> <?php // Get a list of terms registered to the post type set above and loop through them. foreach (get_object_taxonomies($post_type) as $tax_name) { if ($tax_name != 'post_tag' and $tax_name != 'post_status') { $tax = get_taxonomy($tax_name); ?> <option value="<?php echo $tax_name; ?> " <?php selected($populate_term, $tax_name); ?> ><?php echo $tax->labels->name; ?> </option> <?php } } ?> </select> </div> <?php } }
function wpfg_lookup_ninjaform($form_id) { if (!function_exists('ninja_forms_get_form_by_field_id')) { return false; } $form = ninja_forms_get_form_by_field_id($form_id); if (isset($form['data']['form_title']) && $form['data']['form_title']) { return $form['data']['form_title']; } return false; }
/** * Takes a field ID and returns the admin label if it exists and the label if it does not. * * @since 2.8 * @param int $field_id * @return string $label */ function nf_get_field_admin_label($field_id, $form_id = '') { if (empty($form_id)) { $form = ninja_forms_get_form_by_field_id($field_id); $form_id = $form['id']; } $admin_label = isset(Ninja_Forms()->form($form_id)->fields[$field_id]['data']['admin_label']) ? Ninja_Forms()->form($form_id)->fields[$field_id]['data']['admin_label'] : ''; $field_label = isset(Ninja_Forms()->form($form_id)->fields[$field_id]['data']['label']) ? Ninja_Forms()->form($form_id)->fields[$field_id]['data']['label'] : ''; if (!empty($admin_label)) { $label = $admin_label; } else { $label = $field_label; } return $label; }
function ninja_forms_tab_browse_uploads() { global $wpdb; $plugin_settings = get_option("ninja_forms_settings"); //Check for filters $args = array(); if (isset($_POST['form_id']) and $_POST['form_id'] == 'all') { unset($_SESSION['ninja_forms_form_id']); } else { if (isset($_POST['form_id']) and $_POST['form_id'] != 'all') { $args['form_id'] = $_POST['form_id']; $_SESSION['ninja_forms_form_id'] = $_POST['form_id']; } else { if (isset($_SESSION['ninja_forms_form_id']) and $_SESSION['ninja_forms_form_id'] != 'all') { $args['form_id'] = $_SESSION['ninja_forms_form_id']; } } } if (isset($_POST['begin_date']) and !empty($_POST['begin_date'])) { $args['begin_date'] = $_POST['begin_date']; } else { if (isset($_SESSION['ninja_forms_begin_date']) and !empty($_SESSION['ninja_forms_begin_date'])) { $args['begin_date'] = $_SESSION['ninja_forms_begin_date']; } } if (isset($_POST['end_date']) and !empty($_POST['end_date'])) { $args['end_date'] = $_POST['end_date']; } else { if (isset($_SESSION['ninja_forms_end_date']) and !empty($_SESSION['ninja_forms_end_date'])) { $args['end_date'] = $_SESSION['ninja_forms_end_date']; } } if (isset($_POST['upload_types']) and !empty($_POST['upload_types'])) { $args['upload_types'] = $_POST['upload_types']; } else { if (isset($_SESSION['ninja_forms_upload_types']) and !empty($_SESSION['ninja_forms_upload_types'])) { $args['upload_types'] = $_SESSION['ninja_forms_upload_types']; } } if (isset($_POST['upload_name']) and !empty($_POST['upload_name'])) { $args['upload_name'] = $_POST['upload_name']; } else { if (isset($_SESSION['ninja_forms_upload_name']) and !empty($_SESSION['ninja_forms_upload_name'])) { $args['upload_name'] = $_SESSION['ninja_forms_upload_name']; } } if (isset($_POST['upload_user']) and !empty($_POST['upload_user'])) { $args['upload_user'] = $_POST['upload_user']; } else { if (isset($_SESSION['ninja_forms_upload_user']) and !empty($_SESSION['ninja_forms_upload_user'])) { $args['upload_user'] = $_SESSION['ninja_forms_upload_user']; } } if (isset($_POST['order_by']) and !empty($_POST['order_by'])) { $args['order_by'] = $_POST['order_by']; } else { if (isset($_SESSION['ninja_forms_upload_order_by']) and !empty($_SESSION['ninja_forms_upload_order_by'])) { $args['order_by'] = $_SESSION['ninja_forms_upload_order_by']; } else { $args['order_by'] = 'date_updated'; } } $all_files = ninja_forms_get_uploads($args); $upload_count = count($all_files); if (isset($_POST['limit'])) { $saved_limit = $_POST['limit']; $limit = $_POST['limit']; } else { $saved_limit = 20; $limit = 20; } if ($upload_count < $limit) { $limit = $upload_count; } if (isset($_REQUEST['paged']) and !empty($_REQUEST['paged'])) { $current_page = $_REQUEST['paged']; } else { $current_page = 1; } if ($upload_count > $limit) { $page_count = ceil($upload_count / $limit); } else { $page_count = 1; } if ($current_page > 1) { $start = ($current_page - 1) * $limit; if ($upload_count < $limit) { $end = $upload_count; } else { $end = $current_page * $limit; } if ($end > $upload_count) { $end = $upload_count; } } else { $start = 0; $end = $limit; } ?> <div id="" class="tablenav top"> <div class="alignleft actions"> <select id="" class="" name="bulk_action"> <option value=""><?php _e('Bulk Actions', 'ninja-forms'); ?> </option> <option value="delete"><?php _e('Delete', 'ninja-forms'); ?> </option> </select> <input type="submit" name="submit" value="Apply" class="button-secondary"> </div> <div class="alignleft actions"> <select id="" name="limit"> <option value="20" <?php selected($saved_limit, 20); ?> >20</option> <option value="50" <?php selected($saved_limit, 50); ?> >50</option> <option value="100" <?php selected($saved_limit, 100); ?> >100</option> </select> <?php _e('Uploads Per Page', 'ninja-forms'); ?> <input type="submit" name="submit" value="Go" class="button-secondary"> </div> <div id="" class="alignright navtable-pages"> <?php if ($upload_count != 0 and $current_page <= $page_count) { ?> <span class="displaying-num"><?php if ($start == 0) { echo 1; } else { echo $start; } ?> - <?php echo $end; ?> of <?php echo $upload_count; ?> <?php if ($upload_count == 1) { _e('Upload', 'ninja-forms'); } else { _e('Uploads', 'ninja-forms'); } ?> </span> <?php } if ($page_count > 1) { $first_page = add_query_arg(array('paged' => 1)); $last_page = add_query_arg(array('paged' => $page_count)); if ($current_page > 1) { $prev_page = $current_page - 1; $prev_page = add_query_arg(array('paged' => $prev_page)); } else { $prev_page = $first_page; } if ($current_page != $page_count) { $next_page = $current_page + 1; $next_page = add_query_arg(array('paged' => $next_page)); } else { $next_page = $last_page; } ?> <span class="pagination-links"> <a class="first-page disabled" title="Go to the first page" href="<?php echo $first_page; ?> ">«</a> <a class="prev-page disabled" title="Go to the previous page" href="<?php echo $prev_page; ?> ">‹</a> <span class="paging-input"><input class="current-page" title="Current page" type="text" name="paged" value="<?php echo $current_page; ?> " size="2"> of <span class="total-pages"><?php echo $page_count; ?> </span></span> <a class="next-page" title="Go to the next page" href="<?php echo $next_page; ?> ">›</a> <a class="last-page" title="Go to the last page" href="<?php echo $last_page; ?> ">»</a> </span> <?php } ?> </div> </div> <br /> <table border="1px" class="wp-list-table widefat fixed posts"> <thead> <tr> <th class="check-column"><input type="checkbox" id="ninja_forms_select_all" class="ninja-forms-uploads-bulk-action"></th> <th><?php _e('File Name', 'ninja-forms'); ?> </th> <th><?php _e('Original User Filename', 'ninja-forms'); ?> </th> <th><?php _e('Date', 'ninja-forms'); ?> </th> <th><?php _e('Form Name', 'ninja-forms'); ?> </th> <th><?php _e('User Name', 'ninja-forms'); ?> </th> </tr> </thead> <tbody id="ninja_forms_uploads_tbody"> <?php if (is_array($all_files) and !empty($all_files) and $current_page <= $page_count) { for ($i = $start; $i < $end; $i++) { $field_id = $all_files[$i]['field_id']; $upload_id = $all_files[$i]['id']; $date_updated = strtotime($all_files[$i]['date_updated']); $date_updated = date('m/d/Y', $date_updated); $data = $all_files[$i]['data']; $form_row = ninja_forms_get_form_by_field_id($field_id); $form_data = $form_row['data']; $form_title = $form_data['form_title']; if (isset($data['user_file_name'])) { $user_file_name = stripslashes($data['user_file_name']); } else { $user_file_name = ''; } if (isset($all_files[$i]['user_id']) and !empty($all_files[$i]['user_id'])) { $user_data = get_userdata($all_files[$i]['user_id']); $user_nicename = $user_data->user_nicename; } else { $user_nicename = ''; } if (isset($data['file_url'])) { $file_url = $data['file_url']; } else { $file_url = ''; } if (isset($data['file_name'])) { $file_name = $data['file_name']; } else { $file_name = ''; } ?> <tr id="ninja_forms_upload_<?php echo $upload_id; ?> _tr"> <th scope="row" class="check-column"> <input type="checkbox" id="" name="ninja_forms_uploads[]" value="<?php echo $upload_id; ?> " class="ninja-forms-uploads-bulk-action"> </th> <td> <a href="<?php echo $file_url; ?> " target="_blank"><?php echo $file_name; ?> </a> <div class="row-actions"> <span class="view"><a class="view" title="View this file" href="<?php echo $file_url; ?> " target="_blank" id="">View</a> | </span> <span class="trash"><a class="trash ninja-forms-delete-upload" title="Delete this file" href="#" id="delete_upload_<?php echo $upload_id; ?> ">Delete</a></span> </div> </td> <td> <?php echo $user_file_name; ?> </td> <td> <?php echo $date_updated; ?> </td> <td> <?php echo $form_title; ?> </td> <td> <?php echo $user_nicename; ?> </td> </tr> <?php } } else { ?> <tr id="ninja_forms_files_empty" style=""> <td colspan="5"> <?php _e("No files found", "ninja-forms"); ?> </td> </tr> <?php } ?> </tbody> <tfoot> <tr> <th class="check-column"><input type="checkbox" id="ninja_forms_select_all" class="ninja-forms-uploads-bulk-action"></th> <th><?php _e('File Name', 'ninja-forms'); ?> </th> <th><?php _e('Original User Filename', 'ninja-forms'); ?> </th> <th><?php _e('Date', 'ninja-forms'); ?> </th> <th><?php _e('Form Name', 'ninja-forms'); ?> </th> <th><?php _e('User Name', 'ninja-forms'); ?> </th> </tr> </tfoot> </table> <?php }
function ninja_forms_edit_field_list_term($field_id) { $add_field = apply_filters('ninja_forms_use_post_fields', false); if (!$add_field) { return false; } $field_row = ninja_forms_get_field_by_id($field_id); $field_type = $field_row['type']; $field_data = $field_row['data']; if (isset($field_data['populate_term'])) { $populate_term = $field_data['populate_term']; } else { $populate_term = ''; } if ($populate_term != '') { $display = ''; } else { $display = 'style="display:none;"'; } $form_row = ninja_forms_get_form_by_field_id($field_id); if (isset($form_row['data']['post_type'])) { $post_type = $form_row['data']['post_type']; } else { $post_type = ''; } if ($field_type == '_list' and $post_type != '') { ?> <div> <hr> <label> <?php _e('Populate this with the taxonomy', 'ninja-forms'); ?> : </label> <select name="ninja_forms_field_<?php echo $field_id; ?> [populate_term]" class="ninja-forms-list-populate-term" rel="<?php echo $field_id; ?> "> <option value=""><?php _e('- None', 'ninja-forms'); ?> </option> <?php // Get a list of terms registered to the post type set above and loop through them. foreach (get_object_taxonomies($post_type) as $tax_name) { if ($tax_name != 'post_tag' and $tax_name != 'post_status' and $tax_name != 'post_format') { $tax = get_taxonomy($tax_name); ?> <option value="<?php echo $tax_name; ?> " <?php selected($populate_term, $tax_name); ?> ><?php echo $tax->labels->name; ?> </option> <?php } } ?> </select> <div id="ninja_forms_field_<?php echo $field_id; ?> _exclude_terms" <?php echo $display; ?> > <?php ninja_forms_list_terms_checkboxes($field_id, $populate_term); ?> </div> <br /> <hr> </div> <?php } }
function ninja_forms_calc_filter_list_options_span($class, $field_id) { $field_row = ninja_forms_get_field_by_id($field_id); $add_class = false; // Check to see if this field has cal_auto_include set to 1. If it does, we want to output a class name. if (isset($field_row['data']['calc_auto_include']) and !empty($field_row['data']['calc_auto_include'])) { $add_class = true; } $form = ninja_forms_get_form_by_field_id($field_id); $form_id = $form['id']; $all_fields = ninja_forms_get_fields_by_form_id($form_id); foreach ($all_fields as $field) { if ($field['type'] == '_calc') { if (isset($field['data']['calc_method'])) { $calc_method = $field['data']['calc_method']; } else { $calc_method = 'auto'; } switch ($calc_method) { case 'fields': if (isset($field['data']['calc'])) { foreach ($field['data']['calc'] as $calc) { if ($calc['field'] == $field_id) { $add_class = true; break; } } } break; case 'eq': $eq = $field['data']['calc_eq']; if (preg_match("/\\bfield_" . $field_id . "\\b/i", $eq)) { $add_class = true; break; } break; } } } if ($add_class) { $class .= ' ninja-forms-field-list-options-span-calc-listen'; } return $class; }
function ninja_forms_field_post_tags_display($field_id, $data) { global $ninja_forms_processing; $field_class = ninja_forms_get_field_class($field_id); if (isset($data['default_value'])) { $default_value = $data['default_value']; } else { $default_value = ''; } if (isset($data['label_pos'])) { $label_pos = $data['label_pos']; } else { $label_pos = "left"; } if (isset($data['label'])) { $label = $data['label']; } else { $label = ''; } if (isset($data['adv_tags'])) { $adv_tags = $data['adv_tags']; } else { $adv_tags = 0; } if ($label_pos == 'inside') { $default_value = $label; } if ($default_value == '') { if (is_object($ninja_forms_processing)) { $post_tags = $ninja_forms_processing->get_form_setting('post_tags'); } else { $form_row = ninja_forms_get_form_by_field_id($field_id); $post_tags = $form_row['data']['post_tags']; } if ($post_tags) { $post_tags = explode(',', $post_tags); } } else { $post_tags = $default_value; } if ($adv_tags == 1) { $string_tag = ''; if (is_array($post_tags) and !empty($post_tags)) { $x = 0; foreach ($post_tags as $tag) { if (is_object($tag)) { $tag_name = $tag->name; } else { $tag_name = $tag; } if ($x > 0) { $string_tag .= ', '; } $string_tag .= $tag_name; $x++; } } ?> <div class="tagsdiv" id="post_tag"> <div class="jaxtag"> <input type="hidden" name="ninja_forms_field_<?php echo $field_id; ?> " id="ninja_forms_post_tag_hidden" value="<?php echo $string_tag; ?> " rel="<?php echo $field_id; ?> " > <div class="ajaxtag hide-if-no-js"> <label class="screen-reader-text" for="new-tag-post_tag"><?php _e('Tags', 'ninja_forms'); ?> </label> <div class="taghint" style=""><?php _e('Add New Tag', 'ninja-forms'); ?> </div> <p><input type="text" id="ninja_forms_post_tag" class="newtag form-input-tip" size="16" autocomplete="off" value=""> <input type="button" id="ninja_forms_post_add_tag" class="button" value="Add"></p> </div> <p class="howto"><?php _e('Separate tags with commas', 'ninja-forms'); ?> </p> </div> <div class="tagchecklist"> <?php if (is_array($post_tags) and !empty($post_tags)) { $x = 0; foreach ($post_tags as $tag) { if (is_object($tag)) { $tag_name = $tag->name; } else { $tag_name = $tag; } ?> <span id="<?php echo $tag_name; ?> "> <a id="post_tag-<?php echo $x; ?> " class="ninja-forms-del-tag">X</a> <?php echo $tag_name; ?> </span> <?php $x++; } } ?> </div> <br /> <a href="#" class="" id="ninja_forms_show_tag_cloud">Choose from the most used tags</a> <div id="ninja_forms_tag_cloud" style="display:none;"> <?php $args = array('echo' => false, 'format' => 'array'); $tag_cloud = wp_tag_cloud($args); if (is_array($tag_cloud) and !empty($tag_cloud)) { foreach ($tag_cloud as $tag) { $first_quote = strpos($tag, "href='"); $first_quote = $first_quote + 6; $second_quote = strpos($tag, "'", $first_quote); $length = $second_quote - $first_quote; $url = substr($tag, $first_quote, $length); $tag = str_replace($url, '#', $tag); $first_quote = strpos($tag, "class='"); $first_quote = $first_quote + 7; $second_quote = strpos($tag, "'", $first_quote); $length = $second_quote - $first_quote; $orig_class = substr($tag, $first_quote, $length); $class = $orig_class . ' ninja-forms-tag'; $tag = str_replace($orig_class, $class, $tag); echo $tag . " "; } } ?> </div> </div> <?php } else { if (is_array($post_tags)) { $post_tags = implode(',', $post_tags); } ?> <input id="ninja_forms_field_<?php echo $field_id; ?> " name="ninja_forms_field_<?php echo $field_id; ?> " type="text" class="<?php echo $field_class; ?> " value="<?php echo $post_tags; ?> " rel="<?php echo $field_id; ?> " /> <?php } }
function ninja_forms_field_spam_pre_process($field_id, $user_value) { global $ninja_forms_processing; $plugin_settings = get_option("ninja_forms_settings"); if (isset($plugin_settings['spam_error'])) { $spam_error = $plugin_settings['spam_error']; } $field_row = ninja_forms_get_field_by_id($field_id); $field_data = $field_row['data']; $spam_answer = $field_data['spam_answer']; $form_row = ninja_forms_get_form_by_field_id($field_id); $form_id = $form_row['id']; if ($ninja_forms_processing->get_action() != 'save' and $ninja_forms_processing->get_action() != 'mp_save' and !isset($_POST['_wp_login']) and $user_value != $spam_answer) { if (is_object($ninja_forms_processing)) { if ($user_value != '') { $ninja_forms_processing->add_error('spam-general', $spam_error, 'general'); $ninja_forms_processing->add_error('spam-' . $field_id, $spam_error, $field_id); } } } }
function ninja_forms_field_post_terms_display($field_id, $data) { global $ninja_forms_fields; $form_row = ninja_forms_get_form_by_field_id($field_id); $form_data = $form_row['data']; $field_row = ninja_forms_get_field_by_id($field_id); $field_type = $field_row['type']; $post_tax = $ninja_forms_fields[$field_type]['tax']; $val = get_taxonomies(array('name' => $post_tax), 'objects'); $val = $val[$post_tax]; $post_tax_singular = $val->labels->singular_name; $post_tax_name = $val->labels->name; if (isset($data['default_value'])) { if (isset($data['default_value']['terms'])) { $terms = $data['default_value']['terms']; } else { $terms = $data['default_value']; } } else { if (isset($form_data[$post_tax . '_terms'])) { $terms = $form_data[$post_tax . '_terms']; } } if (!isset($terms) or $terms == '') { $terms = array(); } if (isset($data['adv_' . $post_tax])) { $adv_term = $data['adv_' . $post_tax]; } else { $adv_term = 0; } if (isset($data['add_' . $post_tax])) { $add_term = $data['add_' . $post_tax]; } else { $add_term = 0; } if ($adv_term == 1) { //$all_tax = get_object_taxonomies($post->post_type); delete_option($post_tax . '_children'); $all_terms = get_categories(array('parent' => 0, 'hide_empty' => false, 'taxonomy' => $post_tax)); $all_terms = apply_filters('ninja_forms_display_all_terms', $all_terms, $post_tax); $pop_terms = get_categories(array('parent' => 0, 'orderby' => 'count', 'number' => 5, 'taxonomy' => $post_tax)); ?> <div id="taxonomy_<?php echo $field_id; ?> " class="termdiv"> <ul id="<?php echo $field_id; ?> _tabs" class="term-tabs"> <li class="tabs" id="all_<?php echo $field_id; ?> _tab"><a href="#" name="<?php echo $field_id; ?> " id="<?php echo $field_id; ?> _all_link" class="ninja-forms-terms-tab"><?php _e('All', 'ninja-forms'); ?> <?php echo $post_tax_name; ?> </a></li> <li class="hide-if-no-js"><a href="#" name="<?php echo $field_id; ?> " id="<?php echo $field_id; ?> _pop_link" class="ninja-forms-terms-tab">Most Used</a></li> </ul> <div id="<?php echo $field_id; ?> _pop" class="<?php echo $field_id; ?> -tabs-panel tabs-panel" style="display:none;"> <ul id="<?php echo $field_id; ?> checklist-pop" class="termchecklist form-no-clear"> <?php if (is_array($pop_terms) and !empty($pop_terms)) { foreach ($pop_terms as $term) { ?> <li id="<?php echo $field_id; ?> _<?php echo $term->term_id; ?> " class="popular-term"> <label class="selectit"> <input value="<?php echo $term->term_id; ?> " type="checkbox" name="" id="<?php echo $field_id; ?> -<?php echo $term->term_id; ?> " class="<?php echo $field_id; ?> -checkbox term-<?php echo $term->term_id; ?> " <?php checked(in_array($term->term_id, $terms)); ?> > <?php echo $term->name; ?> </label> </li> <?php } } ?> </ul> </div> <li id="term_<?php echo $field_id; ?> _li_template" class="new-<?php echo $field_id; ?> " style="display:none;"> <label class="selectit"> <input value="" type="hidden" id="ninja_forms_field_<?php echo $field_id; ?> [new][][parent]" class="term-parent"> <input value="" type="checkbox" id="ninja_forms_field_<?php echo $field_id; ?> [new][][name]" checked="checked"> <span></span> </label> </li> <div id="<?php echo $field_id; ?> _all" class="<?php echo $field_id; ?> -tabs-panel tabs-panel" style="display: block;"> <ul id="<?php echo $field_id; ?> _checklist" class="termchecklist form-no-clear"> <?php if (is_array($all_terms) and !empty($all_terms)) { foreach ($all_terms as $term) { ?> <li id="<?php echo $field_id; ?> _<?php echo $term->term_id; ?> _li" class="popular-term"> <label class="selectit"> <input value="<?php echo $term->term_id; ?> " type="checkbox" name="ninja_forms_field_<?php echo $field_id; ?> [terms][]" id="term-<?php echo $term->term_id; ?> " class="<?php echo $field_id; ?> -checkbox term-<?php echo $term->term_id; ?> " <?php checked(in_array($term->term_id, $terms)); ?> > <span><?php echo $term->name; ?> </span> </label> <?php $child_terms = get_categories(array('taxonomy' => $post_tax, 'parent' => $term->term_id, 'hide_empty' => false)); $child_terms = apply_filters('ninja_forms_display_child_terms', $child_terms, $term->term_id); if (is_array($child_terms) and !empty($child_terms)) { ?> <ul class="children termchecklist form-no-clear" id="term_<?php echo $term->term_id; ?> _children"> <?php foreach ($child_terms as $child_term) { ?> <li id="<?php echo $field_id; ?> _<?php echo $child_term->term_id; ?> _li" class="popular-term"> <label class="selectit"> <input value="<?php echo $child_term->term_id; ?> " type="checkbox" name="ninja_forms_field_<?php echo $field_id; ?> [terms][]" id="term-<?php echo $child_term->term_id; ?> " class="<?php echo $field_id; ?> -checkbox term-<?php echo $child_term->term_id; ?> " <?php checked(in_array($child_term->term_id, $terms)); ?> > <span><?php echo $child_term->name; ?> </span> </label> </li> <?php } ?> </ul> <?php } ?> </li> <?php } } ?> </ul> </div> <?php if ($add_term == 1) { ?> <div id="term-adder" class="wp-hidden-children"> <h4> <a id="<?php echo $field_id; ?> _add_toggle" href="#" class="term-add-toggle hide-if-no-js">+ <?php _e('Add New', 'ninja-forms'); ?> <?php echo $post_tax_singular; ?> </a> </h4> <p id="<?php echo $field_id; ?> _add" class="term-add wp-hidden-child" style="display:none;"> <input type="hidden" id="new_<?php echo $field_id; ?> _default" value=""> <input type="text" name="" id="new_<?php echo $field_id; ?> _label" class="new-term-label" value=""> <br /> <select name="" id="<?php echo $field_id; ?> _parent" class=""> <option value="-1">— <?php _e('Parent', 'ninja-forms'); ?> <?php echo $post_tax_singular; ?> —</option> <?php if (is_array($all_terms) and !empty($all_terms)) { foreach ($all_terms as $term) { ?> <option value="<?php echo $term->term_id; ?> "><?php echo $term->name; ?> </option> <?php } } ?> </select> <br /> <input type="button" id="<?php echo $field_id; ?> _add_submit" name="new_<?php echo $field_id; ?> _tax" class="button term-add-submit" value="Add New Term"> </p> </div> <?php } ?> </div> <?php } else { $all_terms = get_terms($post_tax, array('parent' => 0, 'hide_empty' => false)); $all_terms = apply_filters('ninja_forms_display_all_terms', $all_terms, $post_tax); if (!is_object($all_terms) and !isset($all_terms->errors)) { $x = 0; ?> <ul class="termchecklist"> <?php foreach ($all_terms as $t) { ?> <li> <label for="ninja_forms_field_<?php echo $field_id; ?> _<?php echo $x; ?> "> <input type="checkbox" id="ninja_forms_field_<?php echo $field_id; ?> _<?php echo $x; ?> " name="ninja_forms_field_<?php echo $field_id; ?> [terms][]" value="<?php echo $t->term_id; ?> " <?php checked(in_array($t->term_id, $terms)); ?> > <?php echo $t->name; ?> </label> <?php $child_terms = get_categories(array('taxonomy' => $post_tax, 'child_of' => $t->term_id, 'hide_empty' => false)); $child_terms = apply_filters('ninja_forms_display_child_terms', $child_terms, $t->term_id); if (is_array($child_terms) and !empty($child_terms)) { ?> <ul class="children termchecklist form-no-clear" id=""> <?php foreach ($child_terms as $child_term) { ?> <li> <label> <input value="<?php echo $child_term->term_id; ?> " type="checkbox" name="ninja_forms_field_<?php echo $field_id; ?> [terms][]" class="" <?php checked(in_array($child_term->term_id, $terms)); ?> > <span><?php echo $child_term->name; ?> </span> </label> </li> <?php } ?> </ul> <?php } ?> </li> <?php $x++; } ?> </ul> <?php } } }
/** * Processes layout changes */ function update_fields() { if (isset($_POST['gridster_data']) && is_array($_POST['gridster_data'])) { // Retrieve form and all form fields $field_id = $_POST['gridster_data'][0]['field_id']; $form = ninja_forms_get_form_by_field_id($field_id); $form_lm = isset($form['data']['bti_layout_master']) ? $form['data']['bti_layout_master'] : false; $rendering = $form_lm && isset($form_lm['rendering']) ? $form_lm['rendering'] : ''; $fields = ninja_forms_get_fields_by_form_id($form['id']); // Sort POST fields if ('columns' == $rendering) { $sorted = $this->sort_col_fields($_POST['gridster_data']); } else { $sorted = $this->sort_row_fields($_POST['gridster_data']); } // Process fields $order = 0; $items = count($sorted); for ($i = 0; $i < $items; $i++) { $p_field = $i > 0 ? $sorted[$i - 1] : null; $c_field = $sorted[$i]; $n_field = $i < $items - 1 ? $sorted[$i + 1] : null; // Field details $field_id = $c_field['field_id']; $data = array('row' => $c_field['row'], 'col' => $c_field['col'], 'sizex' => $c_field['sizex'], 'order' => $c_field['order'], 'last' => false, 'rendering' => $rendering, 'form_last' => false); // First item is not at 1,1? // Since 1.7.1 if ($i == 0 && null == $p_field && $c_field['row'] == 1 && $c_field['col'] > 1) { $data['before'] = $c_field['col'] - 1; } // Add empty column(s) in front ? if (null != $p_field && $c_field['col'] > 1) { // No columns in front if ($c_field['row'] != $p_field['row']) { $data['before'] = $c_field['col'] - 1; } // Empty space between columns if ($c_field['row'] == $p_field['row'] && $p_field['col'] + $p_field['sizex'] != $c_field['col']) { $data['before'] = $c_field['col'] - ($p_field['col'] + $p_field['sizex']); } } // Break current row ? if ($c_field['row'] < $n_field['row'] && $c_field['col'] + $c_field['sizex'] - 1 < $form['data']['bti_layout_master']['cols']) { $data['after'] = $form['data']['bti_layout_master']['cols'] - ($c_field['col'] + $c_field['sizex'] - 1); } // Is this last column ? if ('' == $rendering) { if (isset($sorted[$i + 1]) && $c_field['row'] < $sorted[$i + 1]['row']) { $data['last'] = true; } } else { if (isset($sorted[$i + 1]) && $c_field['col'] < $sorted[$i + 1]['col']) { $data['last'] = true; } } // Form last if (!isset($sorted[$i + 1])) { $data['form_last'] = true; } // Update field metadata $this->save_field($field_id, $data, $fields); $order++; } } exit; }
function field_recaptcha_pre_process($field_id, $user_value) { global $ninja_forms_processing; $plugin_settings = nf_get_settings(); $recaptcha_error = __("The Captcha didn’t verify.", 'wp-recaptcha-integration'); if (isset($plugin_settings['wp_recaptcha_invalid'])) { $recaptcha_error = $plugin_settings['wp_recaptcha_invalid']; } $field_row = ninja_forms_get_field_by_id($field_id); $field_data = $field_row['data']; $form_row = ninja_forms_get_form_by_field_id($field_id); $form_id = $form_row['id']; $require_recaptcha = WP_reCaptcha::instance()->is_required(); if ($ninja_forms_processing->get_action() != 'save' && $ninja_forms_processing->get_action() != 'mp_save' && $require_recaptcha && !WP_reCaptcha::instance()->recaptcha_check()) { $ninja_forms_processing->add_error('recaptcha-general', $recaptcha_error, 'general'); $ninja_forms_processing->add_error('recaptcha-' . $field_id, $recaptcha_error, $field_id); } }