NF_Admin_Menus_Licenses

Class NF_Admin_Menus_Licenses.

Defined (1)

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

/includes/Admin/Menus/Licenses.php  
  1. final class NF_Admin_Menus_Licenses 
  2. private $licenses = array(); 
  3.  
  4. public function __construct() 
  5. add_action( 'admin_init', array( $this, 'register_licenses' ), 10 ); 
  6. add_action( 'admin_init', array( $this, 'submit_listener' ), 11 ); 
  7. add_action( 'admin_init', array( $this, 'add_meta_boxes' ), 12 ); 
  8.  
  9. public function submit_listener() 
  10. if( ! current_user_can( apply_filters( 'ninja_forms_admin_license_update_capabilities', 'manage_options' ) ) ) return; 
  11.  
  12. if( ! isset( $_POST[ 'ninja_forms_license' ] ) || ! $_POST[ 'ninja_forms_license' ] ) return; 
  13.  
  14. $key = sanitize_text_field( $_POST[ 'ninja_forms_license' ][ 'key' ] ); 
  15. $name = sanitize_text_field( $_POST[ 'ninja_forms_license' ][ 'name' ] ); 
  16. $action = sanitize_text_field( $_POST[ 'ninja_forms_license' ][ 'action' ] ); 
  17.  
  18. switch( $action ) { 
  19. case 'activate': 
  20. $this->activate_license( $name, $key ); 
  21. break; 
  22. case 'deactivate': 
  23. $this->deactivate_license( $name ); 
  24. break; 
  25.  
  26. public function register_licenses() 
  27. $this->licenses = apply_filters( 'ninja_forms_settings_licenses_addons', array() ); 
  28.  
  29. public function add_meta_boxes() 
  30. add_meta_box( 
  31. 'nf_settings_licenses',  
  32. __( 'Add-On Licenses', 'ninja-forms' ),  
  33. array( $this, 'display' ),  
  34. 'nf_settings_licenses' 
  35. ); 
  36.  
  37. public function display() 
  38. $data = array(); 
  39. foreach( $this->licenses as $license ) { 
  40. $data[] = array( 
  41. 'id' => $license->product_name,  
  42. 'name' => $license->product_nice_name,  
  43. 'version' => $license->version,  
  44. 'is_valid' => $license->is_valid(),  
  45. 'license' => $this->get_license( $license->product_name ),  
  46. 'error' => Ninja_Forms()->get_setting( $license->product_name . '_license_error' ),  
  47. ); 
  48.  
  49. Ninja_Forms()->template( 'admin-menu-settings-licenses.html.php', array( 'licenses' => $data ) ); 
  50.  
  51. private function get_license( $name ) 
  52. return Ninja_Forms()->get_setting( $name . '_license' ); 
  53.  
  54. private function activate_license( $name, $key ) 
  55. foreach( $this->licenses as $license ) { 
  56.  
  57. if( $name != $license->product_name ) continue; 
  58.  
  59. $license->activate_license( $key ); 
  60.  
  61. private function deactivate_license( $name ) 
  62. foreach( $this->licenses as $license ) { 
  63.  
  64. if( $name != $license->product_name ) continue; 
  65.  
  66. $license->deactivate_license(); 
  67.  
  68. } // End Class NF_Admin_Menus_Licenses