if ( ! defined( 'ABSPATH' ) ) exit; 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; } // nf_get_settings if ( ! defined( 'ABSPATH' ) ) exit; function ninja_forms_register_field($slug, $args = array()){ global $ninja_forms_fields; if( !isset( $ninja_forms_fields ) ){ $ninja_forms_fields = array(); } $defaults = array( 'conditional' => '', 'default_label' => '', 'default_label_pos' => '', 'default_value' => '', 'display_function' => '', 'display_label' => true, 'display_wrap' => true, 'edit_autocomplete_off' => false, 'edit_conditional' => true, 'edit_custom_class' => true, 'edit_function' => '', 'edit_help' => true, 'edit_label' => true, 'edit_label_pos' => true, 'edit_meta' => true, 'edit_options' => '', 'edit_placeholder' => false, 'edit_req' => true, 'edit_settings' => '', 'edit_sub_post_process' => '', 'edit_sub_pre_process' => '', 'edit_sub_process' => '', 'esc_html' => true, 'group' => '', 'interact' => true, 'label_pos_options' => '', 'li_class' => '', 'limit' => '', 'name' => $slug, 'nesting' => false, 'post_process' => '', 'pre_process' => '', 'process' => '', 'process_field' => true, 'req' => false, 'req_validation' => '', 'save_function' => '', 'save_sub' => true, 'show_fav' => true, 'show_field_id' => true, 'show_remove' => true, 'sub_edit' => 'text', 'sub_edit_function' => '', 'use_li' => true, 'visible' => 1, ); // Parse incomming $args into an array and merge it with $defaults $args = wp_parse_args( $args, $defaults ); foreach( $args as $key => $val ){ $ninja_forms_fields[$slug][$key] = $val; } } function ninja_forms_register_field_type_group( $slug, $args ){ global $ninja_forms_field_type_groups; foreach( $args as $key => $val ){ $ninja_forms_field_type_groups[$slug][$key] = $val; } } function ninja_forms_register_tab( $slug, $args ){ global $ninja_forms_tabs; if(!is_array($ninja_forms_tabs)){ $ninja_forms_tabs = array(); } $defaults = array( 'active_class' => '', 'add_form_id' => true, 'disable_no_form_id' => false, 'display_function' => '', 'inactive_class' => '', 'name' => '', 'page' => '', 'save_function' => '', 'show_on_no_form_id' => true, 'show_save' => true, 'show_tab_links' => true, 'show_this_tab_link' => true, 'tab_reload' => false, ); // Parse incomming $args into an array and merge it with $defaults $args = wp_parse_args( $args, $defaults ); $page = $args['page']; foreach( $args as $key => $val ){ $ninja_forms_tabs[$page][$slug][$key] = $val; } } function ninja_forms_register_sidebar( $slug, $args ){ global $ninja_forms_sidebars; if( !is_array($ninja_forms_sidebars ) ){ $ninja_forms_sidebars = array(); } $defaults = array( 'display_function' => 'ninja_forms_sidebar_display_fields', 'name' => '', 'order' => '', 'save_function' => '', 'settings' => '' ); // Parse incomming $args into an array and merge it with $defaults $args = wp_parse_args( $args, $defaults ); extract( $args ); foreach( $args as $key => $val ){ $ninja_forms_sidebars[$page][$tab][$slug][$key] = $val; } } function ninja_forms_register_sidebar_option( $slug, $args ){ global $ninja_forms_sidebars; if( !is_array($ninja_forms_sidebars ) ){ $ninja_forms_sidebars = array(); } $defaults = array( 'desc' => '', 'display_function' => '', 'help' => '', 'name' => '' ); // Parse incomming $args into an array and merge it with $defaults $args = wp_parse_args( $args, $defaults ); extract( $args ); foreach( $args as $key => $val ){ $ninja_forms_sidebars[$page][$tab][$sidebar]['settings'][$slug][$key] = $val; } } function ninja_forms_register_sidebar_options( $args ){ global $ninja_forms_sidebars; extract( $args ); foreach( $args['settings'] as $setting ){ $defaults = array( 'desc' => '', 'display_function' => '', 'help' => '', 'name' => '' ); $slug = $setting['name']; // Parse incomming $setting into an array and merge it with $defaults $setting = wp_parse_args( $setting, $defaults ); foreach( $setting as $key => $val ){ $ninja_forms_sidebars[$page][$tab][$sidebar]['settings'][$slug][$key] = $val; } } } function ninja_forms_field_edit( $slug ){ global $ninja_forms_fields; $function_name = $ninja_forms_fields[$slug]['edit_function']; $arguments = func_get_args(); array_shift( $arguments ); // We need to remove the first arg ($function_name) call_user_func_array( $function_name, $arguments ); } //Screen option registration function function ninja_forms_register_screen_option( $id, $args ){ global $ninja_forms_screen_options; $defaults = array( 'display_function' => '', 'order' => '', 'page' => '', 'save_function' => '', 'tab' => '', ); // Parse incomming $args into an array and merge it with $defaults $args = wp_parse_args( $args, $defaults ); extract( $args ); if($page == '' AND $tab == ''){ $ninja_forms_screen_options['_universal_'][$id]['display_function'] = $display_function; $ninja_forms_screen_options['_universal_'][$id]['save_function'] = $save_function; }elseif($page != '' AND $tab == ''){ $ninja_forms_screen_options[$page]['_universal_'][$id]['display_function'] = $display_function; $ninja_forms_screen_options[$page]['_universal_'][$id]['save_function'] = $save_function; }elseif($page != '' AND $tab != ''){ $ninja_forms_screen_options[$page][$tab][$id]['display_function'] = $display_function; $ninja_forms_screen_options[$page][$tab][$id]['save_function'] = $save_function; } } //Help tab registration function function ninja_forms_register_help_screen_tab( $id, $args ){ global $ninja_forms_help_screen_tabs; $defaults = array( 'display_function' => '', 'order' => '', 'page' => '', 'tab' => '', 'title' => '', ); // Parse incomming $args into an array and merge it with $defaults $args = wp_parse_args( $args, $defaults ); extract( $args ); if($page == '' AND $tab == ''){ $ninja_forms_help_screen_tabs['_universal_'][$id]['title'] = $title; $ninja_forms_help_screen_tabs['_universal_'][$id]['content'] = $display_function; }elseif($page != '' AND $tab == ''){ $ninja_forms_help_screen_tabs[$page]['_universal_'][$id]['title'] = $title; $ninja_forms_help_screen_tabs[$page]['_universal_'][$id]['content'] = $display_function; }elseif($page != '' AND $tab != ''){ $ninja_forms_help_screen_tabs[$page][$tab][$id]['title'] = $title; $ninja_forms_help_screen_tabs[$page][$tab][$id]['content'] = $display_function; } } //Tab - Metaboxes Registration function function ninja_forms_register_tab_metabox($args = array()){ global $ninja_forms_tabs_metaboxes; $defaults = array( 'display_container' => true, 'save_function' => '', 'state' => '' ); // Parse incomming $args into an array and merge it with $defaults $args = wp_parse_args( $args, $defaults ); extract( $args ); foreach($args as $key => $val){ $ninja_forms_tabs_metaboxes[$page][$tab][$slug][$key] = $val; } } //Register Tab Metabox Options function ninja_forms_register_tab_metabox_options( $args = array() ){ global $ninja_forms_tabs_metaboxes; extract( $args ); $new_settings = $args['settings']; if( isset( $ninja_forms_tabs_metaboxes[$page][$tab][$slug]['settings'] ) ){ $settings = $ninja_forms_tabs_metaboxes[$page][$tab][$slug]['settings']; }else{ $settings = array(); } if( is_array( $new_settings ) AND !empty( $new_settings ) ){ foreach( $new_settings as $s ){ if( is_array( $settings ) ){ array_push( $settings, $s ); } } } $ninja_forms_tabs_metaboxes[$page][$tab][$slug]['settings'] = $settings; } if ( ! defined( 'ABSPATH' ) ) exit; /* * Import a serialized ninja form * * @since unknown * @returns int */ function ninja_forms_import_form( $file ){ global $wpdb; $form = unserialize( trim( $file ) ); $form_fields = isset( $form['field'] ) ? $form['field'] : null; $notifications = isset ( $form['notifications'] ) ? $form['notifications'] : null; unset ( $form['field'] ); unset ( $form['notifications'] ); $form = apply_filters( 'ninja_forms_before_import_form', $form ); // Remove our last_sub setting. This is our starting seq_num. if ( isset ( $form['data']['last_sub'] ) ) unset( $form['data']['last_sub'] ); // Create our form $form_id = Ninja_Forms()->form()->create( $form['data'] ); $form['id'] = $form_id; if(is_array($form_fields)){ for ($x=0; $x < count( $form_fields ); $x++) { $form_fields[$x]['form_id'] = $form_id; $form_fields[$x]['data'] = apply_filters( 'nf_before_import_field', $form_fields[$x]['data'], $form_fields[$x]['id'] ); $form_fields[$x]['data'] = serialize( $form_fields[$x]['data'] ); $old_field_id = $form_fields[$x]['id']; $form_fields[$x]['id'] = NULL; $wpdb->insert( NINJA_FORMS_FIELDS_TABLE_NAME, $form_fields[$x] ); $form_fields[$x]['id'] = $wpdb->insert_id; $form_fields[$x]['old_id'] = $old_field_id; $form_fields[$x]['data'] = unserialize( $form_fields[$x]['data'] ); } } $form['field'] = $form_fields; $form['notifications'] = $notifications; // Insert any notifications we might have. if ( is_array( $notifications ) ) { foreach ( $notifications as $n ) { $n_id = nf_insert_notification( $form_id ); $n = apply_filters( 'nf_import_notification_meta', $n, $n_id, $form ); unset( $n['conditions'] ); foreach ( $n as $meta_key => $meta_value ) { foreach ( $form_fields as $field ) { // We need to replace any references to old fields in our notification if ( 'email_message' == $meta_key ) { $meta_value = str_replace( '[ninja_forms_field id=' . $field['old_id'].']', '[ninja_forms_field id='.$field['id'].']', $meta_value ); $meta_value = str_replace( 'ninja_forms_field_' . $field['old_id'], 'ninja_forms_field_' . $field['id'], $meta_value ); } else { $meta_value = preg_replace( '/\bfield_' . $field['old_id'] . '\b/u', 'field_' . $field['id'], $meta_value ); } } nf_update_object_meta( $n_id, $meta_key, $meta_value ); } } } do_action( 'ninja_forms_after_import_form', $form ); return $form['id']; }