NF_Admin_Menus_Forms

The Ninja Forms NF Admin Menus Forms class.

Defined (1)

The class is defined in the following location(s).

/includes/Admin/Menus/Forms.php  
  1. final class NF_Admin_Menus_Forms extends NF_Abstracts_Menu 
  2. public $page_title = 'Ninja Forms'; 
  3.  
  4. public $menu_slug = 'ninja-forms'; 
  5.  
  6. public $icon_url = 'dashicons-feedback'; 
  7.  
  8. public $position = '35.1337'; 
  9.  
  10. public function __construct() 
  11. parent::__construct(); 
  12.  
  13. if( ! defined( 'DOING_AJAX' ) ) { 
  14. add_action('current_screen', array($this, 'admin_init')); 
  15. add_action( 'current_screen', array( 'NF_Admin_AllFormsTable', 'process_bulk_action' ) ); 
  16.  
  17. add_action( 'admin_body_class', array( $this, 'body_class' ) ); 
  18.  
  19. public function body_class( $classes ) 
  20. // Add class for the builder. 
  21. if( isset( $_GET['page'] ) && isset( $_GET[ 'form_id' ] ) && $_GET['page'] == $this->menu_slug ) { 
  22. $classes = "$classes ninja-forms-app"; 
  23.  
  24. return $classes; 
  25.  
  26. public function get_page_title() 
  27. return __( 'Ninja Forms', 'ninja-forms' ); 
  28.  
  29. public function admin_init() 
  30. /** 
  31. * If we aren't on the Ninja Forms menu page, don't admin_init. 
  32. */ 
  33. if ( empty( $_GET[ 'page' ] ) || 'ninja-forms' !== $_GET[ 'page' ] ) { 
  34. return false; 
  35.  
  36. /** 
  37. * Database Table Check 
  38. * If the nf3_ database tables do not exist, then re-run activation. 
  39. */ 
  40. if ( ! ninja_forms_three_table_exists() ) { 
  41. Ninja_Forms()->activation(); 
  42.  
  43. if( isset( $_GET[ 'form_id' ] ) && ! is_numeric( $_GET[ 'form_id' ] ) && 'new' != $_GET[ 'form_id' ] ) { 
  44. if( current_user_can( apply_filters( 'ninja_forms_admin_import_template_capabilities', 'manage_options' ) ) ) { 
  45. $this->import_from_template(); 
  46.  
  47. /** DISABLE OLD FORMS TABLE IN FAVOR OF NEW DASHBOARD */ 
  48. // $this->table = new NF_Admin_AllFormsTable(); 
  49.  
  50. public function display() 
  51. if( isset( $_GET[ 'form_id' ] ) ) { 
  52.  
  53.  
  54. if( 'new' == $_GET[ 'form_id' ] ) { 
  55. $form_id = 'tmp-' . time(); 
  56. } else { 
  57. $form_id = (is_numeric($_GET['form_id'])) ? absint($_GET['form_id']) : ''; 
  58.  
  59. /** 
  60. * FORM BUILDER 
  61. */ 
  62.  
  63. Ninja_Forms::template( 'admin-menu-new-form.html.php' ); 
  64.  
  65. $this->_enqueue_the_things( $form_id ); 
  66.  
  67. delete_user_option( get_current_user_id(), 'nf_form_preview_' . $form_id ); 
  68.  
  69. if( ! isset( $_GET[ 'ajax' ] ) ) { 
  70. $this->_localize_form_data( $form_id ); 
  71.  
  72. $this->_localize_field_type_data(); 
  73.  
  74. $this->_localize_action_type_data(); 
  75.  
  76. $this->_localize_form_settings(); 
  77.  
  78. $this->_localize_merge_tags(); 
  79. } else { 
  80.  
  81. /** 
  82. * ALL FORMS TABLE 
  83. * - DISABLE IN FAVOR OF NEW DASHBOARD. 
  84. */ 
  85.  
  86. // $this->table->prepare_items(); 
  87. // 
  88. // Ninja_Forms::template( 'admin-menu-all-forms.html.php', array( 
  89. // 'table' => $this->table,  
  90. // 'add_new_url' => admin_url( 'admin.php?page=ninja-forms&form_id=new' ),  
  91. // 'add_new_text' => __( 'Add New Form', 'ninja-forms' ) 
  92. // ) ); 
  93.  
  94. /** 
  95. * DASHBOARD 
  96. */ 
  97. $dash_items = Ninja_Forms()->config('DashboardMenuItems'); 
  98. ?> 
  99. <script> 
  100. var nfDashItems = <?php echo( json_encode( array_values( $dash_items ) ) ); ?>; 
  101. </script> 
  102. <?php 
  103.  
  104. wp_enqueue_script( 'backbone-radio', Ninja_Forms::$url . 'assets/js/lib/backbone.radio.min.js', array( 'jquery', 'backbone' ) ); 
  105. wp_enqueue_script( 'backbone-marionette-3', Ninja_Forms::$url . 'assets/js/lib/backbone.marionette3.min.js', array( 'jquery', 'backbone' ) ); 
  106. wp_enqueue_script( 'nf-jbox', Ninja_Forms::$url . 'assets/js/lib/jBox.min.js', array( 'jquery' ) ); 
  107. wp_enqueue_script( 'nf-moment', Ninja_Forms::$url . 'assets/js/lib/moment-with-locales.min.js', array( 'jquery' ) ); 
  108. wp_enqueue_script( 'nf-dashboard', Ninja_Forms::$url . 'assets/js/min/dashboard.min.js', array( 'backbone-radio', 'backbone-marionette-3' ) ); 
  109.  
  110. wp_enqueue_style( 'nf-builder', Ninja_Forms::$url . 'assets/css/builder.css' ); 
  111. wp_enqueue_style( 'nf-dashboard', Ninja_Forms::$url . 'assets/css/dashboard.min.css' ); 
  112. wp_enqueue_style( 'nf-jbox', Ninja_Forms::$url . 'assets/css/jBox.css' ); 
  113. wp_enqueue_style( 'nf-font-awesome', Ninja_Forms::$url . 'assets/css/font-awesome.min.css' ); 
  114.  
  115. Ninja_Forms::template( 'admin-menu-dashboard.html.php' ); 
  116.  
  117. public function submenu_separators() 
  118. add_submenu_page( 'ninja-forms', '', '', 'read', '', '' ); 
  119.  
  120. private function import_from_template() 
  121. $template = sanitize_title( $_GET['form_id'] ); 
  122.  
  123. $templates = Ninja_Forms::config( 'NewFormTemplates' ); 
  124.  
  125. if( isset( $templates[ $template ] ) && ! empty( $templates[ $template ][ 'form' ] ) ) { 
  126. $form = $templates[ $template ][ 'form' ]; 
  127. } else { 
  128. $form = Ninja_Forms::template( $template . '.nff', array(), TRUE ); 
  129.  
  130. if( ! $form ) die( 'Template not found' ); 
  131.  
  132. $form = json_decode( html_entity_decode( $form ), true ); 
  133.  
  134. $form_id = Ninja_Forms()->form()->import_form( $form ); 
  135.  
  136. if( ! $form_id ) { 
  137. $error_message = ( function_exists( 'json_last_error_msg' ) && json_last_error_msg() ) ? json_last_error_msg() : __( 'Form Template Import Error.', 'ninja-forms' ); 
  138. wp_die( $error_message ); 
  139.  
  140. header( "Location: " . admin_url( "admin.php?page=ninja-forms&form_id=$form_id" ) ); 
  141. exit(); 
  142.  
  143. private function _enqueue_the_things( $form_id ) 
  144. global $wp_locale; 
  145.  
  146. wp_enqueue_media(); 
  147.  
  148. wp_enqueue_style( 'nf-builder', Ninja_Forms::$url . 'assets/css/builder.css' ); 
  149. wp_enqueue_style( 'nf-font-awesome', Ninja_Forms::$url . 'assets/css/font-awesome.min.css' ); 
  150. /** 
  151. * CSS Libraries 
  152. */ 
  153. wp_enqueue_style( 'wp-color-picker' ); 
  154. wp_enqueue_style( 'jBox', Ninja_Forms::$url . 'assets/css/jBox.css' ); 
  155. wp_enqueue_style( 'summernote', Ninja_Forms::$url . 'assets/css/summernote.css' ); 
  156. wp_enqueue_style( 'codemirror', Ninja_Forms::$url . 'assets/css/codemirror.css' ); 
  157. wp_enqueue_style( 'codemirror-monokai', Ninja_Forms::$url . 'assets/css/monokai-theme.css' ); 
  158. wp_enqueue_style( 'pikaday-responsive', Ninja_Forms::$url . 'assets/css/pikaday-package.css' ); 
  159.  
  160. /** 
  161. * JS Libraries 
  162. */ 
  163. wp_enqueue_script( 'wp-util' ); 
  164. wp_enqueue_script( 'jquery-autoNumeric', Ninja_Forms::$url . 'assets/js/lib/jquery.autoNumeric.min.js', array( 'jquery', 'backbone' ) ); 
  165. wp_enqueue_script( 'jquery-maskedinput', Ninja_Forms::$url . 'assets/js/lib/jquery.maskedinput.min.js', array( 'jquery', 'backbone' ) ); 
  166. wp_enqueue_script( 'backbone-marionette', Ninja_Forms::$url . 'assets/js/lib/backbone.marionette.min.js', array( 'jquery', 'backbone' ) ); 
  167. wp_enqueue_script( 'backbone-radio', Ninja_Forms::$url . 'assets/js/lib/backbone.radio.min.js', array( 'jquery', 'backbone' ) ); 
  168. wp_enqueue_script( 'jquery-perfect-scrollbar', Ninja_Forms::$url . 'assets/js/lib/perfect-scrollbar.jquery.min.js', array( 'jquery' ) ); 
  169. wp_enqueue_script( 'jquery-hotkeys-new', Ninja_Forms::$url . 'assets/js/lib/jquery.hotkeys.min.js' ); 
  170. wp_enqueue_script( 'jBox', Ninja_Forms::$url . 'assets/js/lib/jBox.min.js' ); 
  171. wp_enqueue_script( 'jquery-caret', Ninja_Forms::$url . 'assets/js/lib/jquery.caret.min.js' ); 
  172. wp_enqueue_script( 'speakingurl', Ninja_Forms::$url . 'assets/js/lib/speakingurl.js' ); 
  173. wp_enqueue_script( 'jquery-slugify', Ninja_Forms::$url . 'assets/js/lib/slugify.min.js', array( 'jquery', 'speakingurl' ) ); 
  174. wp_enqueue_script( 'jquery-mobile-events', Ninja_Forms::$url . 'assets/js/lib/jquery.mobile-events.min.js', array( 'jquery' ) ); 
  175. wp_enqueue_script( 'jquery-ui-touch-punch', Ninja_Forms::$url . 'assets/js/lib/jquery.ui.touch-punch.min.js', array( 'jquery' ) ); 
  176. wp_enqueue_script( 'jquery-classy-wiggle', Ninja_Forms::$url . 'assets/js/lib/jquery.classywiggle.min.js', array( 'jquery' ) ); 
  177. wp_enqueue_script( 'moment-with-locale', Ninja_Forms::$url . 'assets/js/lib/moment-with-locales.min.js', array( 'jquery' ) ); 
  178. wp_enqueue_script( 'pikaday', Ninja_Forms::$url . 'assets/js/lib/pikaday.min.js', array( 'moment-with-locale' ) ); 
  179. wp_enqueue_script( 'pikaday-responsive', Ninja_Forms::$url . 'assets/js/lib/pikaday-responsive.min.js', array( 'pikaday', 'modernizr' ) ); 
  180.  
  181. wp_enqueue_script( 'bootstrap', Ninja_Forms::$url . 'assets/js/lib/bootstrap.min.js', array( 'jquery' ) ); 
  182. wp_enqueue_script( 'codemirror', Ninja_Forms::$url . 'assets/js/lib/codemirror.min.js', array( 'jquery' ) ); 
  183. wp_enqueue_script( 'codemirror-xml', Ninja_Forms::$url . 'assets/js/lib/codemirror-xml.min.js', array( 'jquery' ) ); 
  184. wp_enqueue_script( 'codemirror-formatting', Ninja_Forms::$url . 'assets/js/lib/codemirror-formatting.min.js', array( 'jquery' ) ); 
  185. wp_enqueue_script( 'summernote', Ninja_Forms::$url . 'assets/js/lib/summernote.min.js', array( 'jquery', 'speakingurl' ) ); 
  186.  
  187.  
  188. wp_enqueue_script( 'nf-builder', Ninja_Forms::$url . 'assets/js/min/builder.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-effects-bounce', 'wp-color-picker' ) ); 
  189. wp_localize_script( 'nf-builder', 'nfi18n', Ninja_Forms::config( 'i18nBuilder' ) ); 
  190.  
  191. wp_localize_script( 'nf-builder', 'nfAdmin', array( 
  192. 'ajaxNonce' => wp_create_nonce( 'ninja_forms_builder_nonce' ),  
  193. 'requireBaseUrl' => Ninja_Forms::$url . 'assets/js/',  
  194. 'previewurl' => home_url() . '/?nf_preview_form=',  
  195. 'wp_locale' => $wp_locale->number_format,  
  196. 'editFormText' => __( 'Edit Form', 'ninja-forms' ),  
  197. 'mobile' => ( wp_is_mobile() ) ? 1: 0,  
  198. 'currencySymbols' => array_merge( array( '' => Ninja_Forms()->get_setting( 'currency_symbol' ) ), Ninja_Forms::config( 'CurrencySymbol' ) ),  
  199. 'dateFormat' => Ninja_Forms()->get_setting( 'date_format' ),  
  200. 'formID' => isset( $_GET[ 'form_id' ] ) ? absint( $_GET[ 'form_id' ] ) : 0 
  201. )); 
  202.  
  203. do_action( 'nf_admin_enqueue_scripts' ); 
  204.  
  205. private function _localize_form_data( $form_id ) 
  206. $form = Ninja_Forms()->form( $form_id )->get(); 
  207.  
  208. if( ! $form->get_tmp_id() ) { 
  209.  
  210. if( $form_cache = get_option( 'nf_form_' . $form_id, false ) ) { 
  211. $fields = $form_cache[ 'fields' ]; 
  212. } else { 
  213. $fields = ($form_id) ? Ninja_Forms()->form($form_id)->get_fields() : array(); 
  214. $actions = ($form_id) ? Ninja_Forms()->form($form_id)->get_actions() : array(); 
  215. } else { 
  216. $fields = array(); 
  217. $actions = array(); 
  218.  
  219. $fields_settings = array(); 
  220.  
  221. // echo "<pre>"; 
  222. // print_r( $fields ); 
  223. // echo "</pre>"; 
  224. // die(); 
  225.  
  226. if( ! empty( $fields ) ) { 
  227.  
  228. // TODO: Replace unique field key checks with a refactored model/factory. 
  229. // $unique_field_keys = array(); 
  230. // $form_cache = get_option( 'nf_form_' . $form_id, false ); 
  231. // $cache_updated = false; 
  232.  
  233. foreach ($fields as $field) { 
  234.  
  235. $field_id = ( is_object( $field ) ) ? $field->get_id() : $field[ 'id' ]; 
  236.  
  237. /** 
  238. * Duplicate field check. 
  239. * TODO: Replace unique field key checks with a refactored model/factory. 
  240. */ 
  241. // $field_key = $field->get_setting( 'key' ); 
  242. // if( in_array( $field_key, $unique_field_keys ) || '' == $field_key ) { 
  243. // 
  244. // // Delete the field. 
  245. // Ninja_Forms()->request( 'delete-field' )->data( array( 'field_id' => $field_id ) )->dispatch(); 
  246. // 
  247. // // Remove the field from cache. 
  248. // if( $form_cache ) { 
  249. // if( isset( $form_cache[ 'fields' ] ) ) { 
  250. // foreach( $form_cache[ 'fields' ] as $cached_field_key => $cached_field ) { 
  251. // if( ! isset( $cached_field[ 'id' ] ) ) continue; 
  252. // if( $field_id != $cached_field[ 'id' ] ) continue; 
  253. // 
  254. // // Flag cache to update. 
  255. // $cache_updated = true; 
  256. // 
  257. // unset( $form_cache[ 'fields' ][ $cached_field_key ] ); // Remove the field. 
  258. // } 
  259. // } 
  260. // } 
  261. // 
  262. // continue; // Skip the duplicate field. 
  263. // } 
  264. // array_push( $unique_field_keys, $field_key ); // Log unique key. 
  265. /** END Duplicate field check. */ 
  266.  
  267. $type = ( is_object( $field ) ) ? $field->get_setting( 'type' ) : $field[ 'settings' ][ 'type' ]; 
  268.  
  269. if( ! isset( Ninja_Forms()->fields[ $type ] ) ) { 
  270. $field = NF_Fields_Unknown::create( $field ); 
  271.  
  272. $settings = ( is_object( $field ) ) ? $field->get_settings() : $field[ 'settings' ]; 
  273. $settings[ 'id' ] = $field_id; 
  274.  
  275.  
  276. // foreach ($settings as $key => $setting) { 
  277. // if (is_numeric($setting)) $settings[$key] = floatval($setting); 
  278. // } 
  279.  
  280. $fields_settings[] = $settings; 
  281.  
  282. // if( $cache_updated ) { 
  283. // update_option('nf_form_' . $form_id, $form_cache); // Update form cache without duplicate fields. 
  284. // } 
  285.  
  286. $actions_settings = array(); 
  287.  
  288. if( ! empty( $actions ) ) { 
  289. foreach ($actions as $action) { 
  290.  
  291. $type = $action->get_setting( 'type' ); 
  292.  
  293. if( ! isset( Ninja_Forms()->actions[ $type ] ) ) continue; 
  294.  
  295. $settings = $action->get_settings(); 
  296. $settings['id'] = $action->get_id(); 
  297.  
  298. $actions_settings[] = $settings; 
  299.  
  300. if( $form->get_tmp_id() ) { 
  301.  
  302. $actions_settings = Ninja_Forms()->config( 'FormActionDefaults' ); 
  303.  
  304. $form_data = array(); 
  305. $form_data['id'] = $form_id; 
  306.  
  307. // Use form cache for form settings. 
  308. // TODO: Defer to refactor of factory/model. 
  309. if( isset( $form_cache[ 'settings' ] ) ) { 
  310. $form_data['settings'] = $form_cache[ 'settings' ]; 
  311. } else { 
  312. $form_data['settings'] = $form->get_settings(); 
  313.  
  314. $form_data['fields'] = $fields_settings; 
  315. $form_data['actions'] = $actions_settings; 
  316.  
  317. ?> 
  318. <script> 
  319. var preloadedFormData = <?php echo wp_json_encode( $form_data ); ?>; 
  320. // console.log( preloadedFormData ); 
  321. </script> 
  322. <?php 
  323.  
  324. private function _localize_field_type_data() 
  325. $field_type_sections = array_values( Ninja_Forms()->config( 'FieldTypeSections' ) ); 
  326. $field_type_settings = array(); 
  327.  
  328. $master_settings = array(); 
  329.  
  330. $setting_defaults = array(); 
  331.  
  332. foreach( Ninja_Forms()->fields as $field ) { 
  333.  
  334. $name = $field->get_name(); 
  335. $settings = $field->get_settings(); 
  336. $groups = Ninja_Forms::config( 'SettingsGroups' ); 
  337.  
  338. $unique_settings = $this->_unique_settings( $settings ); 
  339.  
  340. $master_settings = array_merge( $master_settings, $unique_settings ); 
  341.  
  342. $settings_groups = $this->_group_settings( $settings, $groups ); 
  343.  
  344. $settings_defaults = $this->_setting_defaults( $unique_settings ); 
  345.  
  346. $field_type_settings[ $name ] = array( 
  347. 'id' => $name,  
  348. 'nicename' => $field->get_nicename(),  
  349. 'alias' => $field->get_aliases(),  
  350. 'parentType' => $field->get_parent_type(),  
  351. 'section' => $field->get_section(),  
  352. 'icon' => $field->get_icon(),  
  353. 'type' => $field->get_type(),  
  354. 'settingGroups' => $settings_groups,  
  355. 'settingDefaults' => $settings_defaults 
  356. ); 
  357.  
  358. $saved_fields = Ninja_Forms()->form()->get_fields( array( 'saved' => 1) ); 
  359.  
  360. foreach( $saved_fields as $saved_field ) { 
  361.  
  362. $settings = $saved_field->get_settings(); 
  363.  
  364. $id = $saved_field->get_id(); 
  365. $type = $settings[ 'type' ]; 
  366. $label = $settings[ 'label' ]; 
  367.  
  368. $field_type_settings[ $id ] = $field_type_settings[ $type ]; 
  369. $field_type_settings[ $id ][ 'id' ] = $id; 
  370. $field_type_settings[ $id ][ 'type' ] = $type; 
  371. $field_type_settings[ $id ][ 'nicename' ] = $label; 
  372. $field_type_settings[ $id ][ 'section' ] = 'saved'; 
  373.  
  374. $defaults = $field_type_settings[ $id ][ 'settingDefaults' ]; 
  375. $defaults = array_merge( $defaults, $settings ); 
  376. $defaults[ 'saved' ] = TRUE; 
  377.  
  378. $field_type_settings[ $id ][ 'settingDefaults' ] = $defaults; 
  379.  
  380. ?> 
  381. <script> 
  382. var fieldTypeData = <?php echo wp_json_encode( array_values( $field_type_settings ) ); ?>; 
  383. var fieldSettings = <?php echo wp_json_encode( array_values( $master_settings ) ); ?>; 
  384. var fieldTypeSections = <?php echo wp_json_encode( $field_type_sections ); ?>; 
  385. // console.log( fieldTypeData ); 
  386. </script> 
  387. <?php 
  388.  
  389. private function _localize_action_type_data() 
  390. $action_type_settings = array(); 
  391.  
  392. $master_settings_list = array(); 
  393.  
  394. foreach( Ninja_Forms()->actions as $action ) { 
  395.  
  396. $name = $action->get_name(); 
  397. $settings = $action->get_settings(); 
  398. $groups = Ninja_Forms::config( 'SettingsGroups' ); 
  399.  
  400. $settings_groups = $this->_group_settings( $settings, $groups ); 
  401.  
  402. $master_settings_list = array_merge( $master_settings_list, $settings ); 
  403.  
  404. $action_type_settings[ $name ] = array( 
  405. 'id' => $name,  
  406. 'section' => $action->get_section(),  
  407. 'nicename' => $action->get_nicename(),  
  408. 'image' => $action->get_image(),  
  409. 'settingGroups' => $settings_groups,  
  410. 'settingDefaults' => $this->_setting_defaults( $master_settings_list ) 
  411. ); 
  412.  
  413. $external_actions = $this->_fetch_action_feed(); 
  414. $u_id = get_option( 'nf_aff', false ); 
  415. if ( !$u_id ) $u_id = apply_filters( 'ninja_forms_affiliate_id', false ); 
  416. foreach( $external_actions as $action) { 
  417.  
  418. if( ! isset( $action[ 'name' ] ) || ! $action[ 'name' ] ) continue; 
  419.  
  420. $name = $action[ 'name' ]; 
  421. $nicename = ( isset( $action[ 'nicename' ] ) ) ? $action[ 'nicename' ] : ''; 
  422. $image = ( isset( $action[ 'image' ] ) ) ? $action[ 'image' ] : ''; 
  423. $link = ( isset( $action[ 'link' ] ) ) ? $action[ 'link' ] : ''; 
  424.  
  425. if ( $u_id ) { 
  426. $last_slash = strripos( $link, '/' ); 
  427. $link = substr( $link, 0, $last_slash ); 
  428. $link = urlencode( $link ); 
  429. $link = 'http://www.shareasale.com/r.cfm?u=' . $u_id . '&b=812237&m=63061&afftrack=&urllink=' . $link; 
  430.  
  431. if( isset( $action_type_settings[ $name ] ) ) continue; 
  432.  
  433. $action_type_settings[ $name ] = array( 
  434. 'id' => $name,  
  435. 'section' => 'available',  
  436. 'nicename' => $nicename,  
  437. 'image' => $image,  
  438. 'link' => $link,  
  439. 'settingGroups' => array(),  
  440. 'settingDefaults' => array() 
  441. ); 
  442.  
  443. $action_type_settings = apply_filters( 'ninja_forms_action_type_settings', $action_type_settings ); 
  444.  
  445. ?> 
  446. <script> 
  447. var actionTypeData = <?php echo wp_json_encode( array_values( $action_type_settings ) ); ?>; 
  448. var actionSettings = <?php echo wp_json_encode( array_values( $master_settings_list ) ); ?>; 
  449. // console.log( actionTypeData ); 
  450. </script> 
  451. <?php 
  452.  
  453. protected function _localize_form_settings() 
  454. $form_settings_types = Ninja_Forms::config( 'FormSettingsTypes' ); 
  455.  
  456. $form_settings[ 'display' ] = Ninja_Forms::config( 'FormDisplaySettings' ); 
  457. $form_settings[ 'restrictions' ] = Ninja_Forms::config( 'FormRestrictionSettings' ); 
  458. $form_settings[ 'calculations' ] = Ninja_Forms::config( 'FormCalculationSettings' ); 
  459. $form_settings = apply_filters( 'ninja_forms_localize_forms_settings', $form_settings ); 
  460.  
  461. foreach( $form_settings_types as $group_name => $form_setting_group ) { 
  462. if( ! isset( $form_settings[ $group_name ] ) ) $form_settings[ $group_name ] = array(); 
  463. $form_settings[ $group_name ] = apply_filters( 'ninja_forms_localize_form_' . $group_name . '_settings', $form_settings[ $group_name ] ); 
  464.  
  465. $groups = Ninja_Forms::config( 'SettingsGroups' ); 
  466.  
  467. $master_settings = array(); 
  468.  
  469. foreach( $form_settings_types as $id => $type ) { 
  470.  
  471. if( ! isset( $form_settings[ $id ] ) ) $form_settings[ $id ] = ''; 
  472.  
  473. $unique_settings = $this->_unique_settings( $form_settings[ $id ] ); 
  474. $master_settings = array_merge( $master_settings, $unique_settings ); 
  475.  
  476. $form_settings_types[ $id ]['settingGroups'] = $this->_group_settings($form_settings[ $id ], $groups); 
  477. $form_settings_types[ $id ]['settingDefaults'] = $this->_setting_defaults($unique_settings); 
  478. ?> 
  479. <script> 
  480. var formSettingTypeData = <?php echo wp_json_encode( array_values( $form_settings_types ) )?>; 
  481. var formSettings = <?php echo wp_json_encode( array_values( $master_settings ) )?>; 
  482. </script> 
  483. <?php 
  484.  
  485. protected function _localize_merge_tags() 
  486. $merge_tags = array( 
  487. 'fields' => array( 
  488. 'id' => 'fields',  
  489. 'label' => __( 'Fields', 'ninja-forms' ) 
  490. ); 
  491.  
  492. foreach( Ninja_Forms()->merge_tags as $key => $group ) { 
  493. /** 
  494. * If the merge tag group doesn't have a title, don't localise it. 
  495. *  
  496. * This convention is used to allow merge tags to continue to function,  
  497. * even though they can't be added to new forms. 
  498. */ 
  499. $title = $group->get_title(); 
  500. if ( empty( $title ) ) continue; 
  501.  
  502. $merge_tags[ $key ] = array( 
  503. 'id' => $group->get_id(),  
  504. 'label' => $group->get_title(),  
  505. 'tags' => array_values( $group->get_merge_tags() ),  
  506. 'default_group' => $group->is_default_group() 
  507. ); 
  508. ?> 
  509. <script> 
  510. var mergeTags = <?php echo wp_json_encode( array_values( $merge_tags ) ); ?>; 
  511. </script> 
  512. <?php 
  513.  
  514.  
  515. protected function _group_settings( $settings, $groups ) 
  516. if( ! is_array( $settings ) ) return $groups; 
  517.  
  518. foreach( $settings as $setting ) { 
  519.  
  520. $group = ( isset( $setting[ 'group' ] ) ) ? $setting[ 'group' ] : ''; 
  521.  
  522. if( isset( $setting[ 'type'] ) && 'fieldset' == $setting[ 'type' ] ) { 
  523. $setting[ 'settings' ] = array_values( $setting[ 'settings' ] ); 
  524.  
  525. $groups[ $group ][ 'settings'][] = $setting; 
  526.  
  527. foreach( $groups as $id => $group ) { 
  528. if ( empty( $group[ 'settings' ] ) ) { 
  529. unset( $groups[ $id ] ); 
  530.  
  531. unset( $groups[ "" ] ); 
  532.  
  533. usort($groups, array( $this, 'setting_group_priority' ) ); 
  534.  
  535. return $groups; 
  536.  
  537. protected function _unique_settings( $settings ) 
  538. $unique_settings = array(); 
  539.  
  540. if( ! is_array( $settings ) ) return $unique_settings; 
  541.  
  542. foreach( $settings as $setting ) { 
  543.  
  544. if( 'fieldset' == $setting[ 'type' ] ) { 
  545.  
  546. $unique_settings = array_merge( $unique_settings, $this->_unique_settings( $setting[ 'settings' ] ) ); 
  547. } else { 
  548.  
  549. $name = $setting[ 'name' ]; 
  550. $unique_settings[ $name ] = $setting; 
  551.  
  552.  
  553. return $unique_settings; 
  554.  
  555. protected function _setting_defaults( $settings ) 
  556. $setting_defaults = array(); 
  557.  
  558. foreach( $settings as $setting ) { 
  559.  
  560. $name = ( isset( $setting[ 'name' ] ) ) ? $setting[ 'name' ] : ''; 
  561. $default = ( isset( $setting[ 'value' ] ) ) ? $setting[ 'value' ] : ''; 
  562. $setting_defaults[ $name ] = $default; 
  563.  
  564. return $setting_defaults; 
  565.  
  566. protected function _fetch_action_feed() 
  567. return Ninja_Forms::config( 'AvailableActions' ); 
  568.  
  569. protected function setting_group_priority( $a, $b ) 
  570. $priority[ 0 ] = ( isset( $a[ 'priority' ] ) ) ? $a[ 'priority' ] : 500; 
  571. $priority[ 1 ] = ( isset( $b[ 'priority' ] ) ) ? $b[ 'priority' ] : 500; 
  572.  
  573. return $priority[ 0 ] - $priority[ 1 ]; 
  574.  
  575. public function get_capability() 
  576. return apply_filters( 'ninja_forms_admin_parent_menu_capabilities', $this->capability ); 
  577.