scripts.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. //Load up our WP Ninja Custom Form JS files.
  3. function ninja_forms_admin_css(){
  4. $plugin_settings = nf_get_settings();
  5. wp_enqueue_style( 'jquery-smoothness', NINJA_FORMS_URL .'css/smoothness/jquery-smoothness.css' );
  6. wp_enqueue_style( 'ninja-forms-admin', NINJA_FORMS_URL .'css/ninja-forms-admin.css?nf_ver=' . NF_PLUGIN_VERSION );
  7. wp_enqueue_style( 'nf-admin-modal', NINJA_FORMS_URL .'assets/css/admin-modal.css?nf_ver=' . NF_PLUGIN_VERSION );
  8. add_filter('admin_body_class', 'ninja_forms_add_class');
  9. }
  10. function ninja_forms_add_class($classes) {
  11. // add 'class-name' to the $classes array
  12. $classes .= ' nav-menus-php';
  13. // return the $classes array
  14. return $classes;
  15. }
  16. function ninja_forms_admin_js(){
  17. global $version_compare, $public_query_vars;
  18. $form_id = isset ( $_REQUEST['form_id'] ) ? absint( $_REQUEST['form_id'] ) : '';
  19. if ( defined( 'NINJA_FORMS_JS_DEBUG' ) && NINJA_FORMS_JS_DEBUG ) {
  20. $suffix = '';
  21. $src = 'dev';
  22. } else {
  23. $suffix = '.min';
  24. $src = 'min';
  25. }
  26. $plugin_settings = nf_get_settings();
  27. if(isset($plugin_settings['date_format'])){
  28. $date_format = $plugin_settings['date_format'];
  29. }else{
  30. $date_format = 'm/d/Y';
  31. }
  32. $date_format = ninja_forms_date_to_datepicker($date_format);
  33. $datepicker_args = array();
  34. if ( !empty( $date_format ) ) {
  35. $datepicker_args['dateFormat'] = $date_format;
  36. }
  37. wp_enqueue_script('ninja-forms-admin',
  38. NINJA_FORMS_URL . 'js/' . $src .'/ninja-forms-admin' . $suffix . '.js?nf_ver=' . NF_PLUGIN_VERSION,
  39. array('jquery', 'jquery-ui-core', 'jquery-ui-sortable', 'jquery-ui-datepicker', 'jquery-ui-draggable', 'jquery-ui-droppable', 'nf-admin-modal' ) );
  40. wp_localize_script( 'ninja-forms-admin', 'ninja_forms_settings', array( 'nf_ajax_nonce' => wp_create_nonce( 'nf_ajax'), 'form_id' => $form_id, 'datepicker_args' => apply_filters( 'ninja_forms_admin_forms_datepicker_args', $datepicker_args ), 'add_fav_prompt' => __( 'What would you like to name this favorite?', 'ninja-forms' ), 'add_fav_error' => __( 'You must supply a name for this favorite.', 'ninja-forms' ), 'deactivate_all_licenses_confirm' => __( 'Really deactivate all licenses?', 'ninja-forms' ) ) );
  41. wp_localize_script( 'ninja-forms-admin', 'nf_conversion_title', __( 'Reset the form conversion process for v2.9+', 'ninja-forms' ) );
  42. wp_localize_script( 'ninja-forms-admin', 'nf_nuke_title', __( 'Remove ALL Ninja Forms data upon uninstall?', 'ninja-forms' ) );
  43. if ( isset ( $_REQUEST['page'] ) && $_REQUEST['page'] == 'ninja-forms' && isset ( $_REQUEST['tab'] ) ) {
  44. wp_enqueue_script( 'nf-builder',
  45. NINJA_FORMS_URL . 'assets/js/' . $src .'/builder' . $suffix . '.js?nf_ver=' . NF_PLUGIN_VERSION,
  46. array( 'backbone' ) );
  47. if ( '' != $form_id ) {
  48. $fields = Ninja_Forms()->form( $form_id )->fields;
  49. $current_tab = ninja_forms_get_current_tab();
  50. $current_page = isset ( $_REQUEST['page'] ) ? esc_html( $_REQUEST['page'] ) : '';
  51. foreach ( $fields as $field_id => $field ) {
  52. $fields[ $field_id ]['metabox_state'] = 0;
  53. }
  54. $form_status = Ninja_Forms()->form( $form_id )->get_setting( 'status' );
  55. $form_title = Ninja_Forms()->form( $form_id )->get_setting( 'form_title' );
  56. wp_localize_script( 'nf-builder', 'nf_admin', array( 'edit_form_text' => __( 'Edit Form', 'ninja-forms' ), 'form_title' => $form_title, 'form_status' => $form_status, 'fields' => $fields, 'saved_text' => __( 'Saved', 'ninja-forms' ), 'save_text' => __( 'Save', 'ninja-forms' ), 'saving_text' => __( 'Saving...', 'ninja-forms' ), 'remove_field' => __( 'Remove this field? It will be removed even if you do not save.', 'ninja-forms' ) ) );
  57. $reserved_terms = array(
  58. 'attachment',
  59. 'attachment_id',
  60. 'author',
  61. 'author_name',
  62. 'calendar',
  63. 'cat',
  64. 'category',
  65. 'category__and',
  66. 'category__in',
  67. 'category__not_in',
  68. 'category_name',
  69. 'comments_per_page',
  70. 'comments_popup',
  71. 'customize_messenger_channel',
  72. 'customized',
  73. 'cpage',
  74. 'day',
  75. 'debug',
  76. 'error',
  77. 'exact',
  78. 'feed',
  79. 'hour',
  80. 'link_category',
  81. 'm',
  82. 'minute',
  83. 'monthnum',
  84. 'more',
  85. 'name',
  86. 'nav_menu',
  87. 'nonce',
  88. 'nopaging',
  89. 'offset',
  90. 'order',
  91. 'orderby',
  92. 'p',
  93. 'page',
  94. 'page_id',
  95. 'paged',
  96. 'pagename',
  97. 'pb',
  98. 'perm',
  99. 'post',
  100. 'post__in',
  101. 'post__not_in',
  102. 'post_format',
  103. 'post_mime_type',
  104. 'post_status',
  105. 'post_tag',
  106. 'post_type',
  107. 'posts',
  108. 'posts_per_archive_page',
  109. 'posts_per_page',
  110. 'preview',
  111. 'robots',
  112. 's',
  113. 'search',
  114. 'second',
  115. 'sentence',
  116. 'showposts',
  117. 'static',
  118. 'subpost',
  119. 'subpost_id',
  120. 'tag',
  121. 'tag__and',
  122. 'tag__in',
  123. 'tag__not_in',
  124. 'tag_id',
  125. 'tag_slug__and',
  126. 'tag_slug__in',
  127. 'taxonomy',
  128. 'tb',
  129. 'term',
  130. 'theme',
  131. 'type',
  132. 'w',
  133. 'withcomments',
  134. 'withoutcomments',
  135. 'year',
  136. );
  137. wp_localize_script( 'nf-builder', 'wp_reserved_terms', $reserved_terms );
  138. }
  139. }
  140. }