Ninja_Forms

The Ninja Forms Ninja Forms class.

Defined (2)

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

/deprecated/ninja-forms.php  
  1. class Ninja_Forms { 
  2.  
  3.  
  4. /** 
  5. * @var Ninja_Forms 
  6. * @since 2.7 
  7. */ 
  8. private static $instance; 
  9.  
  10. /** 
  11. * @var registered_notification_types 
  12. */ 
  13. var $notification_types = array(); 
  14.  
  15. /** 
  16. * Main Ninja_Forms Instance 
  17. * Insures that only one instance of Ninja_Forms exists in memory at any one 
  18. * time. Also prevents needing to define globals all over the place. 
  19. * @since 2.7 
  20. * @static 
  21. * @staticvar array $instance 
  22. * @return The highlander Ninja_Forms 
  23. */ 
  24. public static function instance() { 
  25. if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Ninja_Forms ) ) { 
  26. self::$instance = new Ninja_Forms; 
  27. self::$instance->setup_constants(); 
  28. self::$instance->includes(); 
  29.  
  30. // Start our submissions custom post type class 
  31. self::$instance->subs_cpt = new NF_Subs_CPT(); 
  32.  
  33. // Add our registration class object 
  34. self::$instance->register = new NF_Register(); 
  35.  
  36. // The forms variable won't be interacted with directly. 
  37. // Instead, the forms() methods will act as wrappers for it. 
  38. self::$instance->forms = new NF_Forms(); 
  39.  
  40. // Our session manager wrapper class 
  41. self::$instance->session = new NF_Session(); 
  42.  
  43. register_activation_hook( __FILE__, 'ninja_forms_activation' ); 
  44. add_action( 'plugins_loaded', array( self::$instance, 'load_lang' ) ); 
  45. add_action( 'init', array( self::$instance, 'init' ), 5 ); 
  46. add_action( 'admin_init', array( self::$instance, 'admin_init' ), 5 ); 
  47. add_action( 'update_option_ninja_forms_settings', array( self::$instance, 'refresh_plugin_settings' ), 10 ); 
  48. // add_action( 'admin_head', array( self::$instance, 'admin_head' ) ); 
  49. add_action( 'admin_notices', array( self::$instance, 'admin_notice' ) ); 
  50.  
  51. return self::$instance; 
  52.  
  53. /** 
  54. * Run all of our plugin stuff on init. 
  55. * This allows filters and actions to be used by third-party classes. 
  56. * @since 2.7 
  57. * @return void 
  58. */ 
  59. public function init() { 
  60. // The settings variable will hold our plugin settings. 
  61. self::$instance->plugin_settings = self::$instance->get_plugin_settings(); 
  62.  
  63. // The subs variable won't be interacted with directly. 
  64. // Instead, the subs() methods will act as wrappers for it. 
  65. self::$instance->subs = new NF_Subs(); 
  66.  
  67. // Get our notifications up and running. 
  68. self::$instance->notifications = new NF_Notifications(); 
  69.  
  70. // Get our step processor up and running. 
  71. // We only need this in the admin. 
  72. if ( is_admin() ) { 
  73. self::$instance->step_processing = new NF_Step_Processing(); 
  74. self::$instance->download_all_subs = new NF_Download_All_Subs(); 
  75.  
  76. // Fire our Ninja Forms init action. 
  77. // This will allow other plugins to register items to the instance. 
  78. do_action( 'nf_init', self::$instance ); 
  79.  
  80. /** 
  81. * Run all of our plugin stuff on admin init. 
  82. * @since 2.7.4 
  83. * @return void 
  84. */ 
  85. public function admin_init() { 
  86. // Check and update our version number. 
  87. self::$instance->update_version_number(); 
  88.  
  89. // Add our "Add Form" button and modal to the tinyMCE editor 
  90. self::$instance->add_form_button = new NF_Admin_AddFormModal(); 
  91.  
  92. // Get our admin notices up and running. 
  93. self::$instance->notices = new NF_Notices(); 
  94.  
  95. // Register our admin scripts 
  96. self::$instance->register_admin_scripts(); 
  97.  
  98. // Fire our Ninja Forms init action. 
  99. do_action( 'nf_admin_init', self::$instance ); 
  100.  
  101. /** 
  102. * Run some admin stuff on admin_notices hook. 
  103. * @since 2.9 
  104. * @return void 
  105. */ 
  106. public function admin_notice() { 
  107. // Notices filter and run the notices function. 
  108. $admin_notices = apply_filters( 'nf_admin_notices', array() ); 
  109. self::$instance->notices->admin_notice( $admin_notices ); 
  110.  
  111. /** 
  112. * Throw error on object clone 
  113. * The whole idea of the singleton design pattern is that there is a single 
  114. * object therefore, we don't want the object to be cloned. 
  115. * @since 2.7 
  116. * @access protected 
  117. * @return void 
  118. */ 
  119. public function __clone() { 
  120. // Cloning instances of the class is forbidden 
  121. _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'ninja-forms' ), '2.8' ); 
  122.  
  123. /** 
  124. * Disable unserializing of the class 
  125. * @since 2.7 
  126. * @access protected 
  127. * @return void 
  128. */ 
  129. public function __wakeup() { 
  130. // Unserializing instances of the class is forbidden 
  131. _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'ninja-forms' ), '2.8' ); 
  132.  
  133. /** 
  134. * Function that acts as a wrapper for our individual notification objects. 
  135. * It checks to see if an object exists for this notification id. 
  136. * If it does, it returns that object. Otherwise, it creates a new one and returns it. 
  137. * @access public 
  138. * @param int $n_id 
  139. * @since 2.8 
  140. * @return object self::$instance->$n_var 
  141. */ 
  142. public function notification( $n_id = '' ) { 
  143. // Bail if we don't get a notification id. 
  144. if ( '' == $n_id ) 
  145. return false; 
  146.  
  147. $n_var = 'notification_' . $n_id; 
  148. // Check to see if an object for this notification already exists. 
  149. // Create one if it doesn't exist. 
  150. if ( ! isset ( self::$instance->$n_var ) ) 
  151. self::$instance->$n_var = new NF_Notification( $n_id ); 
  152.  
  153. return self::$instance->$n_var; 
  154.  
  155. /** 
  156. * Function that acts as a wrapper for our individual sub objects. 
  157. * It checks to see if an object exists for this sub id. 
  158. * If it does, it returns that object. Otherwise, it creates a new one and returns it. 
  159. * @access public 
  160. * @param int $sub_id 
  161. * @since 2.7 
  162. * @return object self::$instance->$sub_var 
  163. */ 
  164. public function sub( $sub_id = '' ) { 
  165. // Bail if we don't get a sub id. 
  166. if ( $sub_id == '' ) 
  167. return false; 
  168.  
  169. $sub_var = 'sub_' . $sub_id; 
  170. // Check to see if an object for this sub already exists. 
  171. // Create one if it doesn't exist. 
  172. if ( ! isset( self::$instance->$sub_var ) ) 
  173. self::$instance->$sub_var = new NF_Sub( $sub_id ); 
  174.  
  175. return self::$instance->$sub_var; 
  176.  
  177. /** 
  178. * Function that acts as a wrapper for our subs_var - NF_Subs() class. 
  179. * It doesn't set a sub_id and can be used to interact with methods that affect mulitple submissions 
  180. * @access public 
  181. * @since 2.7 
  182. * @return object self::$instance->subs_var 
  183. */ 
  184. public function subs() { 
  185. return self::$instance->subs; 
  186.  
  187. /** 
  188. * Function that acts as a wrapper for our form_var - NF_Form() class. 
  189. * It sets the form_id and then returns the instance, which is now using the 
  190. * proper form id 
  191. * @access public 
  192. * @param int $form_id 
  193. * @since 2.9.11 
  194. * @return object self::$instance->form_var 
  195. */ 
  196. public function form( $form_id = '' ) { 
  197. // Bail if we don't get a form id. 
  198.  
  199. $form_var = 'form_' . $form_id; 
  200. // Check to see if an object for this form already exists in memory. If it does, return it. 
  201. if ( isset( self::$instance->$form_var ) ) 
  202. return self::$instance->$form_var; 
  203.  
  204. // Check to see if we have a transient object stored for this form. 
  205. if ( is_object ( ( $form_obj = get_transient( 'nf_form_' . $form_id ) ) ) ) { 
  206. self::$instance->$form_var = $form_obj; 
  207. } else { 
  208. // Create a new form object for this form. 
  209. self::$instance->$form_var = new NF_Form( $form_id ); 
  210. // Save it into a transient. 
  211. set_transient( 'nf_form_' . $form_id, self::$instance->$form_var, DAY_IN_SECONDS ); 
  212.  
  213. return self::$instance->$form_var; 
  214.  
  215. /** 
  216. * Function that acts as a wrapper for our forms_var - NF_Form() class. 
  217. * @access public 
  218. * @since 2.9 
  219. * @return object self::$instance->forms_var 
  220. */ 
  221. public function forms( $form_id = '' ) { 
  222. return self::$instance->forms; 
  223.  
  224. /** 
  225. * Setup plugin constants 
  226. * @access private 
  227. * @since 2.7 
  228. * @return void 
  229. */ 
  230. private function setup_constants() { 
  231. global $wpdb; 
  232.  
  233. // Plugin version 
  234. if ( ! defined( 'NF_PLUGIN_VERSION' ) ) 
  235. define( 'NF_PLUGIN_VERSION', '3.1.1' ); 
  236.  
  237. // Plugin Folder Path 
  238. if ( ! defined( 'NF_PLUGIN_DIR' ) ) 
  239. define( 'NF_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); 
  240.  
  241. // Plugin Folder URL 
  242. if ( ! defined( 'NF_PLUGIN_URL' ) ) 
  243. define( 'NF_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); 
  244.  
  245. // Plugin Root File 
  246. if ( ! defined( 'NF_PLUGIN_FILE' ) ) 
  247. define( 'NF_PLUGIN_FILE', __FILE__ ); 
  248.  
  249. // Objects table name 
  250. if ( ! defined( 'NF_OBJECTS_TABLE_NAME') ) 
  251. define( 'NF_OBJECTS_TABLE_NAME', $wpdb->prefix . 'nf_objects' ); 
  252.  
  253. // Meta table name 
  254. if ( ! defined( 'NF_OBJECT_META_TABLE_NAME' ) ) 
  255. define( 'NF_OBJECT_META_TABLE_NAME', $wpdb->prefix . 'nf_objectmeta' ); 
  256.  
  257. // Relationships table name 
  258. if ( ! defined( 'NF_OBJECT_RELATIONSHIPS_TABLE_NAME' ) ) 
  259. define( 'NF_OBJECT_RELATIONSHIPS_TABLE_NAME', $wpdb->prefix . 'nf_relationships' ); 
  260.  
  261. /** Legacy Definitions */ 
  262.  
  263. // Ninja Forms debug mode 
  264. if ( ! defined( 'NINJA_FORMS_JS_DEBUG' ) ) 
  265. define( 'NINJA_FORMS_JS_DEBUG', false ); 
  266.  
  267. // Ninja Forms plugin directory 
  268. if ( ! defined( 'NINJA_FORMS_DIR' ) ) 
  269. define( 'NINJA_FORMS_DIR', NF_PLUGIN_DIR ); 
  270.  
  271. // Ninja Forms plugin url 
  272. if ( ! defined( 'NINJA_FORMS_URL' ) ) 
  273. define( 'NINJA_FORMS_URL', NF_PLUGIN_URL ); 
  274.  
  275. // Ninja Forms Version 
  276. if ( ! defined( 'NINJA_FORMS_VERSION' ) ) 
  277. define( 'NINJA_FORMS_VERSION', NF_PLUGIN_VERSION ); 
  278.  
  279. // Ninja Forms table name 
  280. if ( ! defined( 'NINJA_FORMS_TABLE_NAME' ) ) 
  281. define( 'NINJA_FORMS_TABLE_NAME', $wpdb->prefix . 'ninja_forms' ); 
  282.  
  283. // Fields table name 
  284. if ( ! defined( 'NINJA_FORMS_FIELDS_TABLE_NAME' ) ) 
  285. define( 'NINJA_FORMS_FIELDS_TABLE_NAME', $wpdb->prefix . 'ninja_forms_fields' ); 
  286.  
  287. // Fav fields table name 
  288. if ( ! defined( 'NINJA_FORMS_FAV_FIELDS_TABLE_NAME' ) ) 
  289. define( 'NINJA_FORMS_FAV_FIELDS_TABLE_NAME', $wpdb->prefix . 'ninja_forms_fav_fields' ); 
  290.  
  291. // Subs table name 
  292. if ( ! defined( 'NINJA_FORMS_SUBS_TABLE_NAME' ) ) 
  293. define( 'NINJA_FORMS_SUBS_TABLE_NAME', $wpdb->prefix . 'ninja_forms_subs' ); 
  294.  
  295. /** 
  296. * Include our Class files 
  297. * @access private 
  298. * @since 2.7 
  299. * @return void 
  300. */ 
  301. private function includes() { 
  302. // Include our session manager 
  303. require_once( NF_PLUGIN_DIR . 'classes/session.php' ); 
  304. // Include our sub object. 
  305. require_once( NF_PLUGIN_DIR . 'classes/sub.php' ); 
  306. // Include our subs object. 
  307. require_once( NF_PLUGIN_DIR . 'classes/subs.php' ); 
  308. // Include our subs CPT. 
  309. require_once( NF_PLUGIN_DIR . 'classes/subs-cpt.php' ); 
  310. // Include our form object. 
  311. require_once( NF_PLUGIN_DIR . 'classes/form.php' ); 
  312. // Include our form sobject. 
  313. require_once( NF_PLUGIN_DIR . 'classes/forms.php' ); 
  314. // Include our field, notification, and sidebar registration class. 
  315. require_once( NF_PLUGIN_DIR . 'classes/register.php' ); 
  316. // Include our 'nf_action' watcher. 
  317. require_once( NF_PLUGIN_DIR . 'includes/actions.php' ); 
  318. // Include our single notification object 
  319. require_once( NF_PLUGIN_DIR . 'classes/notification.php' ); 
  320. // Include our notifications object 
  321. require_once( NF_PLUGIN_DIR . 'classes/notifications.php' ); 
  322. // Include our notification table object 
  323. require_once( NF_PLUGIN_DIR . 'classes/notifications-table.php' ); 
  324. // Include our base notification type 
  325. require_once( NF_PLUGIN_DIR . 'classes/notification-base-type.php' ); 
  326. // Include add form button and modal 
  327. require_once( NF_PLUGIN_DIR . 'classes/add-form-modal.php' ); 
  328.  
  329. if ( is_admin () ) { 
  330. // Include our step processing stuff if we're in the admin. 
  331. require_once( NF_PLUGIN_DIR . 'includes/admin/step-processing.php' ); 
  332. require_once( NF_PLUGIN_DIR . 'classes/step-processing.php' ); 
  333.  
  334. // Include our download all submissions php files 
  335. require_once( NF_PLUGIN_DIR . 'classes/download-all-subs.php' ); 
  336.  
  337.  
  338. $upgraded_from = get_option( 'nf_version_upgraded_from', FALSE ); 
  339. if( $upgraded_from && version_compare( $upgraded_from, '2.9', '<=') ) { 
  340.  
  341. // Include Upgrade Base Class 
  342. require_once( NF_PLUGIN_DIR . 'includes/admin/upgrades/class-upgrade.php'); 
  343.  
  344. // Include Upgrades 
  345. require_once( NF_PLUGIN_DIR . 'includes/admin/upgrades/upgrade-functions.php' ); 
  346. require_once( NF_PLUGIN_DIR . 'includes/admin/upgrades/upgrades.php' ); 
  347. require_once( NF_PLUGIN_DIR . 'includes/admin/upgrades/convert-forms-reset.php' ); 
  348.  
  349. // Include Upgrade Handler 
  350. require_once( NF_PLUGIN_DIR . 'includes/admin/upgrades/upgrade-handler-page.php'); 
  351. require_once( NF_PLUGIN_DIR . 'includes/admin/upgrades/class-upgrade-handler.php'); 
  352.  
  353. // Include our upgrade files. 
  354. require_once( NF_PLUGIN_DIR . 'includes/admin/welcome.php' ); 
  355.  
  356. // Include deprecated functions and filters. 
  357. require_once( NF_PLUGIN_DIR . 'includes/deprecated.php' ); 
  358.  
  359. /** Legacy includes */ 
  360.  
  361. /** Require Core Files */ 
  362. require_once( NINJA_FORMS_DIR . "/includes/ninja-settings.php" ); 
  363. require_once( NINJA_FORMS_DIR . "/includes/database.php" ); 
  364. require_once( NINJA_FORMS_DIR . "/includes/functions.php" ); 
  365. require_once( NINJA_FORMS_DIR . "/includes/activation.php" ); 
  366. require_once( NINJA_FORMS_DIR . "/includes/register.php" ); 
  367. require_once( NINJA_FORMS_DIR . "/includes/shortcode.php" ); 
  368. require_once( NINJA_FORMS_DIR . "/includes/widget.php" ); 
  369. require_once( NINJA_FORMS_DIR . "/includes/field-type-groups.php" ); 
  370. require_once( NINJA_FORMS_DIR . "/includes/eos.class.php" ); 
  371. require_once( NINJA_FORMS_DIR . "/includes/from-setting-check.php" ); 
  372. require_once( NINJA_FORMS_DIR . "/includes/reply-to-check.php" ); 
  373. require_once( NINJA_FORMS_DIR . "/includes/import-export.php" ); 
  374.  
  375. require_once( NINJA_FORMS_DIR . "/includes/display/scripts.php" ); 
  376. require_once( NINJA_FORMS_DIR . "/includes/display/upgrade-functions.php" ); 
  377.  
  378. // Include Processing Functions if a form has been submitted. 
  379. require_once( NINJA_FORMS_DIR . "/includes/display/processing/class-ninja-forms-processing.php" ); 
  380. require_once( NINJA_FORMS_DIR . "/includes/display/processing/class-display-loading.php" ); 
  381. require_once( NINJA_FORMS_DIR . "/includes/display/processing/pre-process.php" ); 
  382. require_once( NINJA_FORMS_DIR . "/includes/display/processing/process.php" ); 
  383. require_once( NINJA_FORMS_DIR . "/includes/display/processing/post-process.php" ); 
  384. require_once( NINJA_FORMS_DIR . "/includes/display/processing/save-sub.php" ); 
  385. require_once( NINJA_FORMS_DIR . "/includes/display/processing/filter-msgs.php" ); 
  386. require_once( NINJA_FORMS_DIR . "/includes/display/processing/fields-pre-process.php" ); 
  387. require_once( NINJA_FORMS_DIR . "/includes/display/processing/fields-process.php" ); 
  388. require_once( NINJA_FORMS_DIR . "/includes/display/processing/fields-post-process.php" ); 
  389. require_once( NINJA_FORMS_DIR . "/includes/display/processing/req-fields-pre-process.php" ); 
  390. require_once( NINJA_FORMS_DIR . "/includes/display/processing/honeypot.php" ); 
  391.  
  392. //Display Form Functions 
  393. require_once( NINJA_FORMS_DIR . "/includes/display/form/display-form.php" ); 
  394. require_once( NINJA_FORMS_DIR . "/includes/display/form/not-logged-in.php" ); 
  395. require_once( NINJA_FORMS_DIR . "/includes/display/fields/display-fields.php" ); 
  396. require_once( NINJA_FORMS_DIR . "/includes/display/form/response-message.php" ); 
  397. require_once( NINJA_FORMS_DIR . "/includes/display/fields/label.php" ); 
  398. require_once( NINJA_FORMS_DIR . "/includes/display/fields/help.php" ); 
  399. require_once( NINJA_FORMS_DIR . "/includes/display/fields/desc.php" ); 
  400. require_once( NINJA_FORMS_DIR . "/includes/display/form/form-title.php" ); 
  401. require_once( NINJA_FORMS_DIR . "/includes/display/fields/field-error-message.php" ); 
  402. require_once( NINJA_FORMS_DIR . "/includes/display/form/form-wrap.php" ); 
  403. require_once( NINJA_FORMS_DIR . "/includes/display/form/form-cont.php" ); 
  404. require_once( NINJA_FORMS_DIR . "/includes/display/form/fields-wrap.php" ); 
  405. require_once( NINJA_FORMS_DIR . "/includes/display/form/required-label.php" ); 
  406. require_once( NINJA_FORMS_DIR . "/includes/display/form/open-form-tag.php" ); 
  407. require_once( NINJA_FORMS_DIR . "/includes/display/form/close-form-tag.php" ); 
  408. require_once( NINJA_FORMS_DIR . "/includes/display/form/hidden-fields.php" ); 
  409. require_once( NINJA_FORMS_DIR . "/includes/display/form/form-visibility.php" ); 
  410. require_once( NINJA_FORMS_DIR . "/includes/display/form/sub-limit.php" ); 
  411. require_once( NINJA_FORMS_DIR . "/includes/display/form/nonce.php" ); 
  412. require_once( NINJA_FORMS_DIR . "/includes/display/form/honeypot.php" ); 
  413. require_once( NINJA_FORMS_DIR . "/includes/display/fields/restore-progress.php" ); 
  414. require_once( NINJA_FORMS_DIR . "/includes/display/fields/inside-label-hidden.php" ); 
  415. require_once( NINJA_FORMS_DIR . "/includes/display/fields/field-type.php" ); 
  416. require_once( NINJA_FORMS_DIR . "/includes/display/fields/default-value-filter.php" ); 
  417. require_once( NINJA_FORMS_DIR . "/includes/display/fields/calc-field-class.php" ); 
  418. require_once( NINJA_FORMS_DIR . "/includes/display/fields/clear-complete.php" ); 
  419.  
  420.  
  421. //Require EDD autoupdate file 
  422. if( !class_exists( 'EDD_SL_Plugin_Updater' ) ) { 
  423. // load our custom updater if it doesn't already exist 
  424. require_once(NINJA_FORMS_DIR."/includes/EDD_SL_Plugin_Updater.php"); 
  425.  
  426. require_once( NINJA_FORMS_DIR . "/includes/class-extension-updater.php" ); 
  427.  
  428. require_once( NINJA_FORMS_DIR . "/includes/admin/scripts.php" ); 
  429. require_once( NINJA_FORMS_DIR . "/includes/admin/sidebar.php" ); 
  430. require_once( NINJA_FORMS_DIR . "/includes/admin/tabs.php" ); 
  431. require_once( NINJA_FORMS_DIR . "/includes/admin/post-metabox.php" ); 
  432.  
  433. require_once( NINJA_FORMS_DIR . "/includes/admin/ajax.php" ); 
  434. require_once( NINJA_FORMS_DIR . "/includes/admin/admin.php" ); 
  435. require_once( NINJA_FORMS_DIR . "/includes/admin/sidebar-fields.php" ); 
  436. require_once( NINJA_FORMS_DIR . "/includes/admin/display-screen-options.php" ); 
  437. require_once( NINJA_FORMS_DIR . "/includes/admin/register-screen-options.php" ); 
  438. require_once( NINJA_FORMS_DIR . "/includes/admin/register-screen-help.php" ); 
  439. require_once( NINJA_FORMS_DIR . "/includes/admin/output-tab-metabox.php" ); 
  440. require_once( NINJA_FORMS_DIR . "/includes/admin/form-preview.php" ); 
  441. require_once( NINJA_FORMS_DIR . "/classes/notices-class.php" ); 
  442. require_once( NINJA_FORMS_DIR . "/includes/admin/notices.php" ); 
  443.  
  444. //Edit Field Functions 
  445. require_once( NINJA_FORMS_DIR . "/includes/admin/edit-field/edit-field.php" ); 
  446. require_once( NINJA_FORMS_DIR . "/includes/admin/edit-field/label.php" ); 
  447. require_once( NINJA_FORMS_DIR . "/includes/admin/edit-field/placeholder.php" ); 
  448. require_once( NINJA_FORMS_DIR . "/includes/admin/edit-field/hr.php" ); 
  449. require_once( NINJA_FORMS_DIR . "/includes/admin/edit-field/req.php" ); 
  450. require_once( NINJA_FORMS_DIR . "/includes/admin/edit-field/custom-class.php" ); 
  451. require_once( NINJA_FORMS_DIR . "/includes/admin/edit-field/help.php" ); 
  452. require_once( NINJA_FORMS_DIR . "/includes/admin/edit-field/desc.php" ); 
  453. require_once( NINJA_FORMS_DIR . "/includes/admin/edit-field/li.php" ); 
  454. require_once( NINJA_FORMS_DIR . "/includes/admin/edit-field/remove-button.php" ); 
  455. require_once( NINJA_FORMS_DIR . "/includes/admin/edit-field/save-button.php" ); 
  456. require_once( NINJA_FORMS_DIR . "/includes/admin/edit-field/calc.php" ); 
  457. require_once( NINJA_FORMS_DIR . "/includes/admin/edit-field/user-info-fields.php" ); 
  458. require_once( NINJA_FORMS_DIR . "/includes/admin/edit-field/post-meta-values.php" ); 
  459. require_once( NINJA_FORMS_DIR . "/includes/admin/edit-field/input-limit.php" ); 
  460. require_once( NINJA_FORMS_DIR . "/includes/admin/edit-field/sub-settings.php" ); 
  461. require_once( NINJA_FORMS_DIR . "/includes/admin/edit-field/autocomplete-off.php" ); 
  462.  
  463. /** * * * ninja-forms - Main Form Editing Page 
  464.   
  465. /** Tabs */ 
  466.  
  467. /** Form List */ 
  468. require_once( NINJA_FORMS_DIR . "/includes/admin/pages/ninja-forms/tabs/form-list/form-list.php" ); 
  469.  
  470. /** Form Settings */ 
  471. require_once( NINJA_FORMS_DIR . "/includes/admin/pages/ninja-forms/tabs/form-settings/form-settings.php" ); 
  472. require_once( NINJA_FORMS_DIR . "/includes/admin/pages/ninja-forms/tabs/form-settings/help.php" ); 
  473.  
  474. /** Field Settings */ 
  475. require_once( NINJA_FORMS_DIR . "/includes/admin/pages/ninja-forms/tabs/field-settings/field-settings.php" ); 
  476. require_once( NINJA_FORMS_DIR . "/includes/admin/pages/ninja-forms/tabs/field-settings/empty-rte.php" ); 
  477. require_once( NINJA_FORMS_DIR . "/includes/admin/pages/ninja-forms/tabs/field-settings/edit-field-ul.php" ); 
  478. require_once( NINJA_FORMS_DIR . "/includes/admin/pages/ninja-forms/tabs/field-settings/help.php" ); 
  479. require_once( NINJA_FORMS_DIR . "/includes/admin/pages/ninja-forms/tabs/field-settings/sidebars/def-fields.php" ); 
  480. require_once( NINJA_FORMS_DIR . "/includes/admin/pages/ninja-forms/tabs/field-settings/sidebars/fav-fields.php" ); 
  481. require_once( NINJA_FORMS_DIR . "/includes/admin/pages/ninja-forms/tabs/field-settings/sidebars/template-fields.php" ); 
  482. require_once( NINJA_FORMS_DIR . "/includes/admin/pages/ninja-forms/tabs/field-settings/sidebars/layout-fields.php" ); 
  483. require_once( NINJA_FORMS_DIR . "/includes/admin/pages/ninja-forms/tabs/field-settings/sidebars/user-info.php" ); 
  484. require_once( NINJA_FORMS_DIR . "/includes/admin/pages/ninja-forms/tabs/field-settings/sidebars/payment-fields.php" ); 
  485.  
  486. /** Form Preview */ 
  487. require_once( NINJA_FORMS_DIR . "/includes/admin/pages/ninja-forms/tabs/form-preview/form-preview.php" ); 
  488.  
  489.  
  490. /** * * * ninja-forms-settings - Settings Page 
  491.   
  492. /** Tabs */ 
  493.  
  494. /** General Settings */ 
  495. require_once( NINJA_FORMS_DIR . "/includes/admin/pages/ninja-forms-settings/tabs/general-settings/general-settings.php" ); 
  496.  
  497. /** Label Settings */ 
  498. require_once( NINJA_FORMS_DIR . "/includes/admin/pages/ninja-forms-settings/tabs/label-settings/label-settings.php" ); 
  499.  
  500. /** License Settings */ 
  501. require_once( NINJA_FORMS_DIR . "/includes/admin/pages/ninja-forms-settings/tabs/license-settings/license-settings.php" ); 
  502.  
  503.  
  504. /** * * * ninja-forms-impexp - Import / Export Page 
  505.   
  506. /** Tabs */ 
  507.  
  508. /** Import / Export Forms */ 
  509. require_once( NINJA_FORMS_DIR . "/includes/admin/pages/ninja-forms-impexp/tabs/impexp-forms/impexp-forms.php" ); 
  510.  
  511. /** Import / Export Fields */ 
  512. require_once( NINJA_FORMS_DIR . "/includes/admin/pages/ninja-forms-impexp/tabs/impexp-fields/impexp-fields.php" ); 
  513.  
  514. /** Import / Export Submissions */ 
  515. require_once( NINJA_FORMS_DIR . "/includes/admin/pages/ninja-forms-impexp/tabs/impexp-subs/impexp-subs.php" ); 
  516.  
  517. /** Backup / Restore */ 
  518. require_once( NINJA_FORMS_DIR . "/includes/admin/pages/ninja-forms-impexp/tabs/impexp-backup/impexp-backup.php" ); 
  519.  
  520. /** * * * ninja-forms-subs - Submissions Review Page 
  521.   
  522. /** Tabs */ 
  523.  
  524. /** * * ninja-forms-addons - Addons Manager Page 
  525.   
  526. /** Tabs */ 
  527.  
  528. /** Manage Addons */ 
  529. require_once( NINJA_FORMS_DIR . "/includes/admin/pages/ninja-forms-addons/tabs/addons/addons.php" ); 
  530.  
  531. /** System Status */ 
  532. require_once( NINJA_FORMS_DIR . "/includes/classes/class-nf-system-status.php" ); 
  533.  
  534. /** Require Pre-Registered Fields */ 
  535. require_once( NINJA_FORMS_DIR . "/includes/fields/textbox.php" ); 
  536. require_once( NINJA_FORMS_DIR . "/includes/fields/checkbox.php" ); 
  537. require_once( NINJA_FORMS_DIR . "/includes/fields/list.php" ); 
  538. require_once( NINJA_FORMS_DIR . "/includes/fields/hidden.php" ); 
  539. require_once( NINJA_FORMS_DIR . "/includes/fields/organizer.php" ); 
  540. require_once( NINJA_FORMS_DIR . "/includes/fields/submit.php" ); 
  541. require_once( NINJA_FORMS_DIR . "/includes/fields/spam.php" ); 
  542. require_once( NINJA_FORMS_DIR . "/includes/fields/timed-submit.php" ); 
  543. require_once( NINJA_FORMS_DIR . "/includes/fields/hr.php" ); 
  544. require_once( NINJA_FORMS_DIR . "/includes/fields/desc.php" ); 
  545. require_once( NINJA_FORMS_DIR . "/includes/fields/textarea.php" ); 
  546. require_once( NINJA_FORMS_DIR . "/includes/fields/password.php" ); 
  547. require_once( NINJA_FORMS_DIR . "/includes/fields/rating.php" ); 
  548. require_once( NINJA_FORMS_DIR . "/includes/fields/calc.php" ); 
  549. require_once( NINJA_FORMS_DIR . "/includes/fields/country.php" ); 
  550. require_once( NINJA_FORMS_DIR . "/includes/fields/tax.php" ); 
  551. require_once( NINJA_FORMS_DIR . "/includes/fields/credit-card.php" ); 
  552. require_once( NINJA_FORMS_DIR . "/includes/fields/number.php" ); 
  553. require_once( NINJA_FORMS_DIR . "/includes/fields/recaptcha.php" ); 
  554.  
  555. require_once( NINJA_FORMS_DIR . "/includes/admin/save.php" ); 
  556.  
  557. /** 
  558. * Load our language files 
  559. * @access public 
  560. * @since 2.7 
  561. * @return void 
  562. */ 
  563. public function load_lang() { 
  564. /** Set our unique textdomain string */ 
  565. $textdomain = 'ninja-forms'; 
  566.  
  567. /** The 'plugin_locale' filter is also used by default in load_plugin_textdomain() */ 
  568. $locale = apply_filters( 'plugin_locale', get_locale(), $textdomain ); 
  569.  
  570. /** Set filter for WordPress languages directory */ 
  571. $wp_lang_dir = apply_filters( 
  572. 'ninja_forms_wp_lang_dir',  
  573. WP_LANG_DIR . '/ninja-forms/' . $textdomain . '-' . $locale . '.mo' 
  574. ); 
  575.  
  576. /** Translations: First, look in WordPress' "languages" folder = custom & update-secure! */ 
  577. load_textdomain( $textdomain, $wp_lang_dir ); 
  578.  
  579. /** Translations: Secondly, look in plugin's "lang" folder = default */ 
  580. $plugin_dir = trailingslashit( basename( dirname( dirname( __FILE__ ) ) ) ) . basename( dirname( __FILE__ ) ); 
  581. $lang_dir = apply_filters( 'ninja_forms_lang_dir', $plugin_dir . '/lang/' ); 
  582. load_plugin_textdomain( $textdomain, FALSE, $lang_dir ); 
  583.  
  584. /** 
  585. * Update our version number if necessary 
  586. * @access public 
  587. * @since 2.7 
  588. * @return void 
  589. */ 
  590. public function update_version_number() { 
  591. $plugin_settings = nf_get_settings(); 
  592.  
  593. if ( !isset ( $plugin_settings['version'] ) OR ( NF_PLUGIN_VERSION != $plugin_settings['version'] ) ) { 
  594. $plugin_settings['version'] = NF_PLUGIN_VERSION; 
  595. update_option( 'ninja_forms_settings', $plugin_settings ); 
  596.  
  597. /** 
  598. * Set Ninja_Forms()->session variable used for storing items in transient variables 
  599. * @access public 
  600. * @since 2.7 
  601. * @return string $t_id; 
  602. */ 
  603. public function set_transient_id() { 
  604. $transient_id = $this->session->get( 'nf_transient_id' ); 
  605. if ( ! $transient_id && ! is_admin() ) { 
  606. $transient_id = ninja_forms_random_string(); 
  607. // Make sure that our transient ID isn't currently in use. 
  608. while ( get_transient( $transient_id ) !== false ) { 
  609. $_id = ninja_forms_random_string(); 
  610. $this->session->set( 'nf_transient_id', $transient_id ); 
  611. return $transient_id; 
  612.  
  613. /** 
  614. * Get our plugin settings. 
  615. * @access public 
  616. * @since 2.9 
  617. * @return array $settings 
  618. */ 
  619. public function get_plugin_settings() { 
  620. $settings = apply_filters( "ninja_forms_settings", get_option( "ninja_forms_settings" ) ); 
  621.  
  622. $settings['date_format'] = isset ( $settings['date_format'] ) ? $settings['date_format'] : 'd/m/Y'; 
  623. $settings['currency_symbol'] = isset ( $settings['currency_symbol'] ) ? $settings['currency_symbol'] : '$'; 
  624. $settings['recaptcha_lang'] = isset ( $settings['recaptcha_lang'] ) ? $settings['recaptcha_lang'] : 'en'; 
  625. $settings['req_div_label'] = isset ( $settings['req_div_label'] ) ? $settings['req_div_label'] : sprintf( __( 'Fields marked with an %s*%s are required', 'ninja-forms' ), '<span class="ninja-forms-req-symbol">', '</span>' ); 
  626. $settings['req_field_symbol'] = isset ( $settings['req_field_symbol'] ) ? $settings['req_field_symbol'] : '<strong>*</strong>'; 
  627. $settings['req_error_label'] = isset ( $settings['req_error_label'] ) ? $settings['req_error_label'] : __( 'Please ensure all required fields are completed.', 'ninja-forms' ); 
  628. $settings['req_field_error'] = isset ( $settings['req_field_error'] ) ? $settings['req_field_error'] : __( 'This is a required field', 'ninja-forms' ); 
  629. $settings['spam_error'] = isset ( $settings['spam_error'] ) ? $settings['spam_error'] : __( 'Please answer the anti-spam question correctly.', 'ninja-forms' ); 
  630. $settings['honeypot_error'] = isset ( $settings['honeypot_error'] ) ? $settings['honeypot_error'] : __( 'Please leave the spam field blank.', 'ninja-forms' ); 
  631. $settings['timed_submit_error'] = isset ( $settings['timed_submit_error'] ) ? $settings['timed_submit_error'] : __( 'Please wait to submit the form.', 'ninja-forms' ); 
  632. $settings['javascript_error'] = isset ( $settings['javascript_error'] ) ? $settings['javascript_error'] : __( 'You cannot submit the form without Javascript enabled.', 'ninja-forms' ); 
  633. $settings['invalid_email'] = isset ( $settings['invalid_email'] ) ? $settings['invalid_email'] : __( 'Please enter a valid email address.', 'ninja-forms' ); 
  634. $settings['process_label'] = isset ( $settings['process_label'] ) ? $settings['process_label'] : __( 'Processing', 'ninja-forms' ); 
  635. $settings['password_mismatch'] = isset ( $settings['password_mismatch'] ) ? $settings['password_mismatch'] : __( 'The passwords provided do not match.', 'ninja-forms' ); 
  636.  
  637. $settings['date_format'] = apply_filters( 'ninja_forms_labels/date_format' , $settings['date_format'] ); 
  638. $settings['currency_symbol'] = apply_filters( 'ninja_forms_labels/currency_symbol' , $settings['currency_symbol'] ); 
  639. $settings['req_div_label'] = apply_filters( 'ninja_forms_labels/req_div_label' , $settings['req_div_label'] ); 
  640. $settings['req_field_symbol'] = apply_filters( 'ninja_forms_labels/req_field_symbol' , $settings['req_field_symbol'] ); 
  641. $settings['req_error_label'] = apply_filters( 'ninja_forms_labels/req_error_label' , $settings['req_error_label'] ); 
  642. $settings['req_field_error'] = apply_filters( 'ninja_forms_labels/req_field_error' , $settings['req_field_error'] ); 
  643. $settings['spam_error'] = apply_filters( 'ninja_forms_labels/spam_error' , $settings['spam_error'] ); 
  644. $settings['honeypot_error'] = apply_filters( 'ninja_forms_labels/honeypot_error' , $settings['honeypot_error'] ); 
  645. $settings['timed_submit_error'] = apply_filters( 'ninja_forms_labels/timed_submit_error' , $settings['timed_submit_error'] ); 
  646. $settings['javascript_error'] = apply_filters( 'ninja_forms_labels/javascript_error' , $settings['javascript_error'] ); 
  647. $settings['invalid_email'] = apply_filters( 'ninja_forms_labels/invalid_email' , $settings['invalid_email'] ); 
  648. $settings['process_label'] = apply_filters( 'ninja_forms_labels/process_label' , $settings['process_label'] ); 
  649. $settings['password_mismatch'] = apply_filters( 'ninja_forms_labels/password_mismatch' , $settings['password_mismatch'] ); 
  650.  
  651. return $settings; 
  652.  
  653. /** 
  654. * Refresh our plugin settings if we update the ninja_forms_settings option 
  655. * @access public 
  656. * @since 2.9 
  657. * @return void 
  658. */ 
  659. public function refresh_plugin_settings() { 
  660. self::$instance->plugin_settings = self::$instance->get_plugin_settings(); 
  661.  
  662. /** 
  663. * Register our admin scripts so that they can be enqueued later. 
  664. * @since 2.9.25 
  665. * @return void 
  666. */ 
  667. public function register_admin_scripts() { 
  668. if ( defined( 'NINJA_FORMS_JS_DEBUG' ) && NINJA_FORMS_JS_DEBUG ) { 
  669. $suffix = ''; 
  670. $src = 'dev'; 
  671. } else { 
  672. $suffix = '.min'; 
  673. $src = 'min'; 
  674.  
  675. wp_register_script( 'nf-admin-modal',  
  676. NF_PLUGIN_URL . 'assets/js/' . $src . '/admin-modal' . $suffix . '.js',  
  677. array( 'jquery', 'jquery-ui-core' ) ); 
  678.  
  679.  
  680. } // End Class 
/ninja-forms.php  
  1. final class Ninja_Forms 
  2.  
  3. /** 
  4. * @since 3.0 
  5. */ 
  6. const VERSION = '3.1.1'; 
  7.  
  8. /** 
  9. * @var Ninja_Forms 
  10. * @since 2.7 
  11. */ 
  12. private static $instance; 
  13.  
  14. /** 
  15. * Plugin Directory 
  16. * @since 3.0 
  17. * @var string $dir 
  18. */ 
  19. public static $dir = ''; 
  20.  
  21. /** 
  22. * Plugin URL 
  23. * @since 3.0 
  24. * @var string $url 
  25. */ 
  26. public static $url = ''; 
  27.  
  28. /** 
  29. * Admin Menus 
  30. * @since 3.0 
  31. * @var array 
  32. */ 
  33. public $menus = array(); 
  34.  
  35. /** 
  36. * AJAX Controllers 
  37. * @since 3.0 
  38. * @var array 
  39. */ 
  40. public $controllers = array(); 
  41.  
  42. /** 
  43. * Form Fields 
  44. * @since 3.0 
  45. * @var array 
  46. */ 
  47. public $fields = array(); 
  48.  
  49. /** 
  50. * Form Actions 
  51. * @since 3.0 
  52. * @var array 
  53. */ 
  54. public $actions = array(); 
  55.  
  56. /** 
  57. * Merge Tags 
  58. * @since 3.0 
  59. * @var array 
  60. */ 
  61. public $merge_tags = array(); 
  62.  
  63. /** 
  64. * Metaboxes 
  65. * @since 3.0 
  66. * @var array 
  67. */ 
  68. public $metaboxes = array(); 
  69.  
  70. /** 
  71. * Model Factory 
  72. * @var object 
  73. */ 
  74. public $factory = ''; 
  75.  
  76. /** 
  77. * Logger 
  78. * @var string 
  79. */ 
  80. protected $_logger = ''; 
  81.  
  82. /** 
  83. * @var NF_Session 
  84. */ 
  85. protected $session = ''; 
  86.  
  87. /** 
  88. * @var NF_Tracking 
  89. */ 
  90. public $tracking; 
  91.  
  92. /** 
  93. * Plugin Settings 
  94. * @since 3.0 
  95. * @var array 
  96. */ 
  97. protected $settings = array(); 
  98.  
  99. protected $requests = array(); 
  100.  
  101. protected $processes = array(); 
  102.  
  103. /** 
  104. * Main Ninja_Forms Instance 
  105. * Insures that only one instance of Ninja_Forms exists in memory at any one 
  106. * time. Also prevents needing to define globals all over the place. 
  107. * @since 2.7 
  108. * @static 
  109. * @staticvar array $instance 
  110. * @return Ninja_Forms Highlander Instance 
  111. */ 
  112. public static function instance() 
  113. if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Ninja_Forms ) ) { 
  114. self::$instance = new Ninja_Forms; 
  115.  
  116. self::$dir = plugin_dir_path( __FILE__ ); 
  117.  
  118. // Define old constants for backwards compatibility. 
  119. if( ! defined( 'NF_PLUGIN_DIR' ) ) { 
  120. define( 'NF_PLUGIN_DIR', self::$dir ); 
  121. define( 'NINJA_FORMS_DIR', self::$dir . 'deprecated' ); 
  122.  
  123. self::$url = plugin_dir_url( __FILE__ ); 
  124. if( ! defined( 'NF_PLUGIN_URL' ) ) { 
  125. define( 'NF_PLUGIN_URL', self::$url ); 
  126.  
  127. update_option( 'ninja_forms_version', self::VERSION ); 
  128.  
  129. /** 
  130. * Register our autoloader 
  131. */ 
  132. spl_autoload_register( array( self::$instance, 'autoloader' ) ); 
  133.  
  134. /** 
  135. * Admin Menus 
  136. */ 
  137. self::$instance->menus[ 'forms' ] = new NF_Admin_Menus_Forms(); 
  138. self::$instance->menus[ 'dashboard' ] = new NF_Admin_Menus_Dashboard(); 
  139. self::$instance->menus[ 'add-new' ] = new NF_Admin_Menus_AddNew(); 
  140. self::$instance->menus[ 'submissions'] = new NF_Admin_Menus_Submissions(); 
  141. self::$instance->menus[ 'import-export'] = new NF_Admin_Menus_ImportExport(); 
  142. self::$instance->menus[ 'settings' ] = new NF_Admin_Menus_Settings(); 
  143. self::$instance->menus[ 'licenses'] = new NF_Admin_Menus_Licenses(); 
  144. self::$instance->menus[ 'system_status'] = new NF_Admin_Menus_SystemStatus(); 
  145. self::$instance->menus[ 'add-ons' ] = new NF_Admin_Menus_Addons(); 
  146. self::$instance->menus[ 'divider'] = new NF_Admin_Menus_Divider(); 
  147. self::$instance->menus[ 'mock-data'] = new NF_Admin_Menus_MockData(); 
  148.  
  149. /** 
  150. * AJAX Controllers 
  151. */ 
  152. self::$instance->controllers[ 'form' ] = new NF_AJAX_Controllers_Form(); 
  153. self::$instance->controllers[ 'preview' ] = new NF_AJAX_Controllers_Preview(); 
  154. self::$instance->controllers[ 'submission' ] = new NF_AJAX_Controllers_Submission(); 
  155. self::$instance->controllers[ 'savedfields' ] = new NF_AJAX_Controllers_SavedFields(); 
  156.  
  157. /** 
  158. * REST Controllers 
  159. */ 
  160. self::$instance->controllers[ 'REST' ][ 'forms' ] = new NF_AJAX_REST_Forms(); 
  161. self::$instance->controllers[ 'REST' ][ 'new-form-templates' ] = new NF_AJAX_REST_NewFormTemplates(); 
  162.  
  163. /** 
  164. * Async Requests 
  165. */ 
  166. require_once Ninja_Forms::$dir . 'includes/Libraries/BackgroundProcessing/classes/wp-async-request.php'; 
  167. self::$instance->requests[ 'delete-field' ] = new NF_AJAX_Requests_DeleteField(); 
  168.  
  169. /** 
  170. * Background Processes 
  171. */ 
  172. require_once Ninja_Forms::$dir . 'includes/Libraries/BackgroundProcessing/wp-background-processing.php'; 
  173. self::$instance->requests[ 'update-fields' ] = new NF_AJAX_Processes_UpdateFields(); 
  174.  
  175. /** 
  176. * WP-CLI Commands 
  177. */ 
  178. if( class_exists( 'WP_CLI_Command' ) ) { 
  179. WP_CLI::add_command('ninja-forms', 'NF_WPCLI_NinjaFormsCommand'); 
  180.  
  181. /** 
  182. * Preview Page 
  183. */ 
  184. self::$instance->preview = new NF_Display_Preview(); 
  185.  
  186. /** 
  187. * Shortcodes 
  188. */ 
  189. self::$instance->shortcodes = new NF_Display_Shortcodes(); 
  190.  
  191. /** 
  192. * Submission CPT 
  193. */ 
  194. new NF_Admin_CPT_Submission(); 
  195. new NF_Admin_CPT_DownloadAllSubmissions(); 
  196. require_once Ninja_Forms::$dir . 'lib/StepProcessing/menu.php'; 
  197.  
  198. /** 
  199. * Submission Metabox 
  200. */ 
  201. new NF_Admin_Metaboxes_Calculations(); 
  202.  
  203. /** 
  204. * Logger 
  205. */ 
  206. self::$instance->_logger = new NF_Database_Logger(); 
  207.  
  208. /** 
  209. * Merge Tags 
  210. */ 
  211. self::$instance->merge_tags[ 'wp' ] = new NF_MergeTags_WP(); 
  212. self::$instance->merge_tags[ 'fields' ] = new NF_MergeTags_Fields(); 
  213. self::$instance->merge_tags[ 'calcs' ] = new NF_MergeTags_Calcs(); 
  214. self::$instance->merge_tags[ 'form' ] = new NF_MergeTags_Form(); 
  215. self::$instance->merge_tags[ 'other' ] = new NF_MergeTags_Other(); 
  216. self::$instance->merge_tags[ 'deprecated' ] = new NF_MergeTags_Deprecated(); 
  217.  
  218. /** 
  219. * Add Form Modal 
  220. */ 
  221. self::$instance->add_form_modal = new NF_Admin_AddFormModal(); 
  222.  
  223. /** 
  224. * EOS Parser 
  225. */ 
  226. self::$instance->_eos[ 'parser' ] = require_once 'includes/Libraries/EOS/Parser.php'; 
  227.  
  228. self::$instance->session = new NF_Session(); 
  229.  
  230. /** 
  231. * Plugin Settings 
  232. */ 
  233. self::$instance->settings = apply_filters( 'ninja_forms_settings', get_option( 'ninja_forms_settings' ) ); 
  234.  
  235. /** 
  236. * Admin Notices System 
  237. */ 
  238. self::$instance->notices = new NF_Admin_Notices(); 
  239.  
  240. self::$instance->widgets[] = new NF_Widget(); 
  241.  
  242. /** 
  243. * Opt-In Tracking 
  244. */ 
  245. self::$instance->tracking = new NF_Tracking(); 
  246.  
  247. /** 
  248. * JS Exception Handler 
  249. * TODO: Review PR#2492 for improvements. 
  250. */ 
  251. // self::$instance->exception_handler_js = new NF_ExceptionHandlerJS(); 
  252.  
  253. /** 
  254. * Activation Hook 
  255. * TODO: Move to a permanent home. 
  256. */ 
  257. register_activation_hook( __FILE__, array( self::$instance, 'activation' ) ); 
  258.  
  259. self::$instance->metaboxes[ 'append-form' ] = new NF_Admin_Metaboxes_AppendAForm(); 
  260.  
  261. /** 
  262. * Require EDD auto-update file 
  263. */ 
  264. if( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) { 
  265. // Load our custom updater if it doesn't already exist 
  266. require_once( self::$dir . 'includes/Integrations/EDD/EDD_SL_Plugin_Updater.php'); 
  267. require_once self::$dir . 'includes/Integrations/EDD/class-extension-updater.php'; 
  268.  
  269. add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) ); 
  270.  
  271. add_action( 'plugins_loaded', array( self::$instance, 'plugins_loaded' ) ); 
  272.  
  273. add_action( 'ninja_forms_available_actions', array( self::$instance, 'scrub_available_actions' ) ); 
  274.  
  275. add_action( 'init', array( self::$instance, 'init' ), 5 ); 
  276. add_action( 'admin_init', array( self::$instance, 'admin_init' ), 5 ); 
  277.  
  278. return self::$instance; 
  279.  
  280. public function init() 
  281. do_action( 'nf_init', self::$instance ); 
  282.  
  283. public function admin_init() 
  284. do_action( 'nf_admin_init', self::$instance ); 
  285.  
  286. public function scrub_available_actions( $actions ) 
  287. foreach( $actions as $key => $action ) { 
  288. if ( ! is_plugin_active( $action[ 'plugin_path' ] ) ) continue; 
  289. unset( $actions[ $key ] ); 
  290. return $actions; 
  291.  
  292. public function admin_notices() 
  293. // Notices filter and run the notices function. 
  294. $admin_notices = Ninja_Forms()->config( 'AdminNotices' ); 
  295. self::$instance->notices->admin_notice( apply_filters( 'nf_admin_notices', $admin_notices ) ); 
  296.  
  297. public function plugins_loaded() 
  298. load_plugin_textdomain( 'ninja-forms', false, basename( dirname( __FILE__ ) ) . '/lang' ); 
  299.  
  300. /** 
  301. * Field Class Registration 
  302. */ 
  303. self::$instance->fields = apply_filters( 'ninja_forms_register_fields', self::load_classes( 'Fields' ) ); 
  304.  
  305. if( ! apply_filters( 'ninja_forms_enable_credit_card_fields', false ) ) { 
  306. unset( self::$instance->fields[ 'creditcard' ] ); 
  307. unset( self::$instance->fields[ 'creditcardcvc' ] ); 
  308. unset( self::$instance->fields[ 'creditcardexpiration' ] ); 
  309. unset( self::$instance->fields[ 'creditcardfullname' ] ); 
  310. unset( self::$instance->fields[ 'creditcardnumber' ] ); 
  311. unset( self::$instance->fields[ 'creditcardzip' ] ); 
  312.  
  313. /** 
  314. * Form Action Registration 
  315. */ 
  316. self::$instance->actions = apply_filters( 'ninja_forms_register_actions', self::load_classes( 'Actions' ) ); 
  317.  
  318. /** 
  319. * Merge Tag Registration 
  320. */ 
  321. self::$instance->merge_tags = apply_filters( 'ninja_forms_register_merge_tags', self::$instance->merge_tags ); 
  322.  
  323. /** 
  324. * It's Ninja Time: Hook for Extensions 
  325. */ 
  326. do_action( 'ninja_forms_loaded' ); 
  327.  
  328.  
  329. /** 
  330. * Autoloader 
  331. * Autoload Ninja Forms classes 
  332. * @param $class_name 
  333. */ 
  334. public function autoloader( $class_name ) 
  335. if( class_exists( $class_name ) ) return; 
  336.  
  337. /** Ninja Forms Prefix */ 
  338. if (false !== strpos($class_name, 'NF_')) { 
  339. $class_name = str_replace('NF_', '', $class_name); 
  340. $classes_dir = realpath(plugin_dir_path(__FILE__)) . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR; 
  341. $class_file = str_replace('_', DIRECTORY_SEPARATOR, $class_name) . '.php'; 
  342. if (file_exists($classes_dir . $class_file)) { 
  343. require_once $classes_dir . $class_file; 
  344.  
  345. /** WP Ninjas Prefix */ 
  346. if (false !== strpos($class_name, 'WPN_')) { 
  347. $class_name = str_replace('WPN_', '', $class_name); 
  348. $classes_dir = realpath(plugin_dir_path(__FILE__)) . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR; 
  349. $class_file = str_replace('_', DIRECTORY_SEPARATOR, $class_name) . '.php'; 
  350. if (file_exists($classes_dir . $class_file)) { 
  351. require_once $classes_dir . $class_file; 
  352.  
  353. /** 
  354. * PUBLIC API WRAPPERS 
  355. */ 
  356.  
  357. /** 
  358. * Form Model Factory Wrapper 
  359. * @param $id 
  360. * @return NF_Abstracts_ModelFactory 
  361. */ 
  362. public function form( $id = '' ) 
  363. global $wpdb; 
  364.  
  365. static $forms; 
  366. if ( isset ( $forms[ $id ] ) ) { 
  367. return $forms[ $id ]; 
  368.  
  369. $forms[ $id ] = new NF_Abstracts_ModelFactory( $wpdb, $id ); 
  370. return $forms[ $id ]; 
  371.  
  372. /** 
  373. * Logger Class Wrapper 
  374. * Example Use: 
  375. * Ninja_Forms()->logger()->log( 'debug', "Hello, {name}!", array( 'name' => 'world' ) ); 
  376. * Ninja_Forms()->logger()->debug( "Hello, {name}!", array( 'name' => 'world' ) ); 
  377. * @return string 
  378. */ 
  379. public function logger() 
  380. return $this->_logger; 
  381.  
  382. public function eos() 
  383. return new Parser(); 
  384.  
  385. public function session() 
  386. return $this->session; 
  387.  
  388. public function request( $action ) 
  389. if( ! isset( $this->requests[ $action ] ) ) return new NF_AJAX_Requests_NullRequest(); 
  390.  
  391. return $this->requests[ $action ]; 
  392.  
  393. public function background_process( $action ) 
  394. if( ! isset( $this->requests[ $action ] ) ) return new NF_AJAX_Processes_NullProcess(); 
  395.  
  396. return $this->requests[ $action ]; 
  397.  
  398. /** 
  399. * Get a setting 
  400. * @param string $key 
  401. * @param bool|false $default 
  402. * @return bool 
  403. */ 
  404. public function get_setting( $key = '', $default = false ) 
  405. if( empty( $key ) || ! isset( $this->settings[ $key ] ) ) return $default; 
  406.  
  407. return $this->settings[ $key ]; 
  408.  
  409. /** 
  410. * Get all the settings 
  411. * @return array 
  412. */ 
  413. public function get_settings() 
  414. return ( is_array( $this->settings ) ) ? $this->settings : array(); 
  415.  
  416. /** 
  417. * Update a setting 
  418. * @param string $key 
  419. * @param mixed $value 
  420. * @param bool|false $defer_update Defer the database update of all settings 
  421. */ 
  422. public function update_setting( $key, $value, $defer_update = false ) 
  423. $this->settings[ $key ] = $value; 
  424. if ( ! $defer_update ) { 
  425. $this->update_settings(); 
  426.  
  427. /** 
  428. * Save settings to database 
  429. * @param array $settings 
  430. */ 
  431. public function update_settings( $settings = array() ) 
  432. if( ! is_array( $this->settings ) ) $this->settings = array(); 
  433.  
  434. if( $settings && is_array( $settings ) ) { 
  435. $this->settings = array_merge($this->settings, $settings); 
  436.  
  437. update_option( 'ninja_forms_settings', $this->settings ); 
  438.  
  439.  
  440. /** 
  441. * Display Wrapper 
  442. * @param $form_id 
  443. */ 
  444. public function display( $form_id, $preview = FALSE ) 
  445. if( ! $form_id ) return; 
  446.  
  447. $noscript_message = __( 'Notice: JavaScript is required for this content.', 'ninja-forms' ); 
  448. $noscript_message = apply_filters( 'ninja_forms_noscript_message', $noscript_message ); 
  449.  
  450. Ninja_Forms()->template( 'display-noscript-message.html.php', array( 'message' => $noscript_message ) ); 
  451.  
  452. if( ! $preview ) { 
  453. NF_Display_Render::localize($form_id); 
  454. } else { 
  455. NF_Display_Render::localize_preview($form_id); 
  456.  
  457.  
  458.  
  459. /** 
  460. * PRIVATE METHODS 
  461. */ 
  462.  
  463. /** 
  464. * Load Classes from Directory 
  465. * @param string $prefix 
  466. * @return array 
  467. */ 
  468. private static function load_classes( $prefix = '' ) 
  469. $return = array(); 
  470.  
  471. $subdirectory = str_replace( '_', DIRECTORY_SEPARATOR, str_replace( 'NF_', '', $prefix ) ); 
  472.  
  473. $directory = 'includes/' . $subdirectory; 
  474.  
  475. foreach (scandir( self::$dir . $directory ) as $path) { 
  476.  
  477. $path = explode( DIRECTORY_SEPARATOR, str_replace( self::$dir, '', $path ) ); 
  478. $filename = str_replace( '.php', '', end( $path ) ); 
  479.  
  480. $class_name = 'NF_' . $prefix . '_' . $filename; 
  481.  
  482. if( ! class_exists( $class_name ) ) continue; 
  483.  
  484. $return[ strtolower( $filename ) ] = new $class_name; 
  485.  
  486. return $return; 
  487.  
  488.  
  489.  
  490. /** 
  491. * STATIC METHODS 
  492. */ 
  493.  
  494. /** 
  495. * Template 
  496. * @param string $file_name 
  497. * @param array $data 
  498. */ 
  499. public static function template( $file_name = '', array $data = array(), $return = FALSE ) 
  500. if( ! $file_name ) return FALSE; 
  501.  
  502. extract( $data ); 
  503.  
  504. $path = self::$dir . 'includes/Templates/' . $file_name; 
  505.  
  506. if( ! file_exists( $path ) ) return FALSE; 
  507.  
  508. if( $return ) return file_get_contents( $path ); 
  509.  
  510. include $path; 
  511.  
  512. /** 
  513. * Config 
  514. * @param $file_name 
  515. * @return mixed 
  516. */ 
  517. public static function config( $file_name ) 
  518. return include self::$dir . 'includes/Config/' . $file_name . '.php'; 
  519.  
  520. /** 
  521. * Activation 
  522. */ 
  523. public function activation() { 
  524. $migrations = new NF_Database_Migrations(); 
  525. $migrations->migrate(); 
  526.  
  527. if( Ninja_Forms()->form()->get_forms() ) return; 
  528.  
  529. $form = Ninja_Forms::template( 'formtemplate-contactform.nff', array(), TRUE ); 
  530. Ninja_Forms()->form()->import_form( $form ); 
  531.  
  532. /** 
  533. * Deprecated Notice 
  534. * Example: Ninja_Forms::deprecated_hook( 'ninja_forms_old', '3.0', 'ninja_forms_new', debug_backtrace() ); 
  535. * @param $deprecated 
  536. * @param $version 
  537. * @param null $replacement 
  538. * @param null $backtrace 
  539. */ 
  540. public static function deprecated_notice( $deprecated, $version, $replacement = null, $backtrace = null ) 
  541. do_action( 'ninja_forms_deprecated_call', $deprecated, $replacement, $version ); 
  542.  
  543. $show_errors = current_user_can( 'manage_options' ); 
  544.  
  545. // Allow plugin to filter the output error trigger 
  546. if ( WP_DEBUG && apply_filters( 'ninja_forms_deprecated_function_trigger_error', $show_errors ) ) { 
  547. if ( ! is_null( $replacement ) ) { 
  548. trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since Ninja Forms version %2$s! Use %3$s instead.', 'ninja-forms' ), $deprecated, $version, $replacement ) ); 
  549. // trigger_error( print_r( $backtrace, 1 ) ); // Limited to previous 1028 characters, but since we only need to move back 1 in stack that should be fine. 
  550. // Alternatively we could dump this to a file. 
  551. } else { 
  552. trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since Ninja Forms version %2$s.', 'ninja-forms' ), $deprecated, $version ) ); 
  553. // trigger_error( print_r( $backtrace, 1 ) );// Limited to previous 1028 characters, but since we only need to move back 1 in stack that should be fine. 
  554. // Alternatively we could dump this to a file. 
  555.  
  556. } // End Class Ninja_Forms