function ninja_forms_serialize_form($form_id) { if ($form_id == '') { return; } $plugin_settings = nf_get_settings(); $form_row = ninja_forms_get_form_by_id($form_id); $field_results = ninja_forms_get_fields_by_form_id($form_id); $form_row['id'] = NULL; if (is_array($form_row) and !empty($form_row)) { if (is_array($field_results) and !empty($field_results)) { $x = 0; foreach ($field_results as $field) { $form_row['field'][$x] = $field; $x++; } } } // Get all of our notifications for this form $notifications = nf_get_notifications_by_form_id($form_id); $form_row['notifications'] = $notifications; $form_row = apply_filters('nf_export_form_row', $form_row); $form_row = serialize($form_row); return $form_row; }
/** * Detect Limited List Field */ public function detect_limited_list_field() { global $ninja_forms_loading; if (!$ninja_forms_loading) { return; } $form_id = $ninja_forms_loading->get_form_ID(); $notifications = nf_get_notifications_by_form_id($form_id); if (is_array($notifications)) { foreach ($notifications as $id => $n) { if (nf_get_object_meta_value($id, 'type') == $this->slug && nf_get_object_meta_value($id, 'active') == 1) { $this->is_detect_limited_list_field = $id; break; } } } }
/** * Loop through our notifications and add their processing functions to the appropriate hook. * * @access public * @since 2.8 * @return void */ public function notification_processing() { global $ninja_forms_processing; $form_id = $ninja_forms_processing->get_form_ID(); $notifications = nf_get_notifications_by_form_id($form_id, false); if (is_array($notifications)) { foreach ($notifications as $id) { do_action('nf_notification_before_process', $id); if (Ninja_Forms()->notification($id)->active) { Ninja_Forms()->notification($id)->process(); } } } }
/** ************************************************************************ * REQUIRED! This is where you prepare your data for display. This method will * usually be used to query the database, sort and filter the data, and generally * get it ready to be displayed. At a minimum, we should set $this->items and * $this->set_pagination_args(), although the following properties and methods * are frequently interacted with here... * * @global WPDB $wpdb * @uses $this->_column_headers * @uses $this->items * @uses $this->get_columns() * @uses $this->get_sortable_columns() * @uses $this->get_pagenum() * @uses $this->set_pagination_args() **************************************************************************/ public function prepare_items() { global $wpdb; //This is used only if making any database queries /** * First, lets decide how many records per page to show */ $per_page = 99999; /** * REQUIRED. Now we need to define our column headers. This includes a complete * array of columns to be displayed (slugs & titles), a list of columns * to keep hidden, and a list of columns that are sortable. Each of these * can be defined in another method (as we've done here) before being * used to build the value for our _column_headers property. */ $columns = $this->get_columns(); $hidden = array(); $sortable = $this->get_sortable_columns(); /** * REQUIRED. Finally, we build an array to be used by the class for column * headers. The $this->_column_headers property takes an array which contains * 3 other arrays. One for all columns, one for hidden columns, and one * for sortable columns. */ $this->_column_headers = array($columns, $hidden, $sortable); /** * Optional. You can handle your bulk actions however you see fit. In this * case, we'll handle them within our package just to keep things clean. */ //$this->process_bulk_action(); /** * Instead of querying a database, we're going to fetch the example data * property we created for use in this plugin. This makes this example * package slightly different than one you might build on your own. In * this example, we'll be using array manipulation to sort and paginate * our data. In a real-world implementation, you will probably want to * use sort and pagination data to build a custom query instead, as you'll * be able to use your precisely-queried data immediately. */ $notifications = nf_get_notifications_by_form_id($this->form_id); $data = array(); if (is_array($notifications)) { foreach ($notifications as $id => $n) { if (isset($_REQUEST['type']) && !empty($_REQUEST['type'])) { if (nf_get_object_meta_value($id, 'type') == esc_html($_REQUEST['type'])) { $n['id'] = $id; $data[] = $n; } } else { $n['id'] = $id; $data[] = $n; } } } /** * This checks for sorting input and sorts the data in our array accordingly. * * In a real-world situation involving a database, you would probably want * to handle sorting by passing the 'orderby' and 'order' values directly * to a custom query. The returned data will be pre-sorted, and this array * sorting technique would be unnecessary. */ function usort_reorder($a, $b) { $orderby = !empty($_REQUEST['orderby']) ? esc_html($_REQUEST['orderby']) : 'name'; //If no sort, default to title $order = !empty($_REQUEST['order']) ? esc_html($_REQUEST['order']) : 'asc'; //If no order, default to asc $result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order return $order === 'asc' ? $result : -$result; //Send final sort direction to usort } usort($data, 'usort_reorder'); /*********************************************************************** * --------------------------------------------------------------------- * vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv * * In a real-world situation, this is where you would place your query. * * For information on making queries in WordPress, see this Codex entry: * http://codex.wordpress.org/Class_Reference/wpdb * * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ * --------------------------------------------------------------------- **********************************************************************/ /** * REQUIRED for pagination. Let's figure out what page the user is currently * looking at. We'll need this later, so you should always include it in * your own package classes. */ $current_page = $this->get_pagenum(); /** * REQUIRED for pagination. Let's check how many items are in our data array. * In real-world use, this would be the total number of items in your database, * without filtering. We'll need this later, so you should always include it * in your own package classes. */ $total_items = count($data); /** * The WP_List_Table class does not handle pagination for us, so we need * to ensure that the data is trimmed to only the current page. We can use * array_slice() to */ $data = array_slice($data, ($current_page - 1) * $per_page, $per_page); /** * REQUIRED. Now we can add our *sorted* data to the items property, where * it can be used by the rest of the class. */ $this->items = $data; /** * REQUIRED. We also have to register our pagination options & calculations. */ $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page))); }
function ninja_forms_delete_form($form_id = '') { global $wpdb; // Bail if we aren't in the admin if (!is_admin()) { return false; } // Bail if we don't have proper permissions if (!current_user_can(apply_filters('nf_delete_form_capabilities', 'manage_options'))) { return false; } if ($form_id == '') { $ajax = true; $form_id = absint($_REQUEST['form_id']); check_ajax_referer('nf_ajax', 'nf_ajax_nonce'); } else { $ajax = false; } $wpdb->query($wpdb->prepare("DELETE FROM " . NINJA_FORMS_TABLE_NAME . " WHERE id = %d", $form_id)); $wpdb->query($wpdb->prepare("DELETE FROM " . NINJA_FORMS_FIELDS_TABLE_NAME . " WHERE form_id = %d", $form_id)); // Delete any notifications attached to this form. // Grab notifications. $notifications = nf_get_notifications_by_form_id($form_id, false); foreach ($notifications as $n_id) { nf_delete_object($n_id); } if ($ajax) { die; } }