NF_THREE_Submenu

The Ninja Forms NF THREE Submenu class.

Defined (1)

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

/deprecated/upgrade/class-submenu.php  
  1. class NF_THREE_Submenu 
  2. /** 
  3. * (required) The slug name for the parent menu (or the file name of a standard WordPress admin page) 
  4. * @var string 
  5. */ 
  6. public $parent_slug = ''; 
  7.  
  8. /** 
  9. * (required) The text to be displayed in the title tags of the page when the menu is selected 
  10. * @var string 
  11. */ 
  12. public $page_title = 'Ninja Forms THREE'; 
  13.  
  14. /** 
  15. * (required) The on-screen name text for the menu 
  16. * @var string 
  17. */ 
  18. public $menu_title = 'Ninja Forms THREE'; 
  19.  
  20. /** 
  21. * (required) The capability required for this menu to be displayed to the user. 
  22. * @var string 
  23. */ 
  24. public $capability = 'manage_options'; 
  25.  
  26. /** 
  27. * (required) The slug name to refer to this menu by (should be unique for this menu). 
  28. * @var string 
  29. */ 
  30. public $menu_slug = 'ninja-forms-three'; 
  31.  
  32. /** 
  33. * (optional) The function that displays the page content for the menu page. 
  34. * @var string 
  35. */ 
  36. public $function = 'display'; 
  37.  
  38. public $priority = 9001; 
  39.  
  40. /** 
  41. * Constructor 
  42. * Translate text and add the 'admin_menu' action. 
  43. */ 
  44. public function __construct() 
  45. $this->menu_title = __( 'Update', 'ninja-forms' ); 
  46. $this->page_title = __( 'Update to Ninja Forms THREE', 'ninja-forms' ); 
  47.  
  48. $this->capability = apply_filters( 'submenu_' . $this->menu_slug . '_capability', $this->capability ); 
  49.  
  50. add_action( 'admin_menu', array( $this, 'register' ), $this->priority ); 
  51.  
  52. add_action( 'wp_ajax_ninja_forms_upgrade_check', array( $this, 'upgrade_check' ) ); 
  53.  
  54. add_filter( 'nf_general_settings_advanced', array( $this, 'settings_upgrade_button' ) ); 
  55.  
  56. /** 
  57. * Register the menu page. 
  58. */ 
  59. public function register() 
  60. if( ! ninja_forms_three_calc_check() ) return; 
  61. if( ! ninja_forms_three_addons_version_check() ) return; 
  62.  
  63. if( ! ninja_forms_three_addons_check() ) { 
  64. // Hide the submenu 
  65. $this->parent_slug = ''; 
  66.  
  67. $function = ( $this->function ) ? array( $this, $this->function ) : NULL; 
  68.  
  69. add_submenu_page( 
  70. $this->parent_slug,  
  71. $this->page_title,  
  72. $this->menu_title,  
  73. $this->capability,  
  74. $this->menu_slug,  
  75. $function 
  76. ); 
  77.  
  78. /** 
  79. * Display the menu page. 
  80. */ 
  81. public function display() 
  82. $all_forms = Ninja_Forms()->forms()->get_all(); 
  83.  
  84. wp_enqueue_style( 'ninja-forms-three-upgrade-styles', plugin_dir_url(__FILE__) . 'upgrade.css' ); 
  85.  
  86. wp_enqueue_script( 'ninja-forms-three-upgrade', plugin_dir_url(__FILE__) . 'upgrade.js', array( 'jquery', 'wp-util' ), '', TRUE ); 
  87. wp_localize_script( 'ninja-forms-three-upgrade', 'nfThreeUpgrade', array( 
  88. 'forms' => $all_forms,  
  89. 'redirectURL' => admin_url( 'admin.php?page=ninja-forms&nf-switcher=upgrade' ),  
  90. ) ); 
  91.  
  92. include plugin_dir_path( __FILE__ ) . 'tmpl-submenu.html.php'; 
  93.  
  94. public function upgrade_check() 
  95. if( ! isset( $_POST[ 'formID' ] ) ) $this->respond( array( 'error' => 'Form ID not found.' ) ); 
  96.  
  97. $form_id = absint( $_POST[ 'formID' ] ); 
  98.  
  99. $can_upgrade = TRUE; 
  100.  
  101. $fields = Ninja_Forms()->form( $form_id )->fields; 
  102. $settings = Ninja_Forms()->form( $form_id )->get_all_settings(); 
  103.  
  104. foreach( $fields as $field ) { 
  105. if( '_calc' == $field[ 'type' ] ) { 
  106. // $can_upgrade = FALSE; 
  107.  
  108. $this->respond( array( 
  109. 'id' => $form_id,  
  110. 'title' => $settings[ 'form_title' ],  
  111. 'canUpgrade' => $can_upgrade 
  112. ) ); 
  113.  
  114. private function respond( $response = array() ) 
  115. echo wp_json_encode( $response ); 
  116. wp_die(); // this is required to terminate immediately and return a proper response 
  117.  
  118. public function settings_upgrade_button( $settings ) 
  119. $settings['update_to_three'] = array( 
  120. 'name' => 'update_to_three',  
  121. 'type' => '',  
  122. 'label' => __('Ninja Forms THREE', 'ninja-forms'),  
  123. 'display_function' => array($this, 'settings_upgrade_button_display'),  
  124. 'desc' => __('Upgrade to the Ninja Forms THREE.', 'ninja-forms') 
  125. ); 
  126.  
  127. return $settings; 
  128.  
  129. public function settings_upgrade_button_display() 
  130. include plugin_dir_path( __FILE__ ) . 'tmpl-settings-upgrade-button.html.php';