1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Licenses management page |
4
|
|
|
* |
5
|
|
|
* @package SimpleCalendar/Admin |
6
|
|
|
*/ |
7
|
|
|
namespace SimpleCalendar\Admin\Pages; |
8
|
|
|
|
9
|
|
|
use SimpleCalendar\Abstracts\Admin_Page; |
10
|
|
|
|
11
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
12
|
|
|
exit; |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Licenses. |
17
|
|
|
* |
18
|
|
|
* Handles the plugin add-ons licenses if at least one is installed and active. |
19
|
|
|
* |
20
|
|
|
* @since 3.0.0 |
21
|
|
|
*/ |
22
|
|
|
class Licenses extends Admin_Page { |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Constructor. |
26
|
|
|
* |
27
|
|
|
* @since 3.0.0 |
28
|
|
|
*/ |
29
|
|
View Code Duplication |
public function __construct() { |
|
|
|
|
30
|
|
|
|
31
|
|
|
$this->id = $tab = 'licenses'; |
32
|
|
|
$this->option_group = $page = 'settings'; |
33
|
|
|
$this->label = __( 'Add-on Licenses', 'google-calendar-events' ); |
34
|
|
|
//$this->description = __( 'Manage your premium add-on license keys.', 'google-calendar-events' ); |
|
|
|
|
35
|
|
|
$this->sections = $this->add_sections(); |
36
|
|
|
$this->fields = $this->add_fields(); |
37
|
|
|
|
38
|
|
|
// Disabled the 'save changes' button for this page. |
39
|
|
|
add_filter( 'simcal_admin_page_' . $page . '_' . $tab . '_submit', function() { return false; } ); |
40
|
|
|
|
41
|
|
|
// Add html to page. |
42
|
|
|
add_action( 'simcal_admin_page_' . $page . '_' . $tab . '_end', array( __CLASS__, 'html' ) ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Add additional html. |
47
|
|
|
* |
48
|
|
|
* @since 3.0.0 |
49
|
|
|
* |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
|
|
public static function html() { |
53
|
|
|
// Add a nonce field used in ajax. |
54
|
|
|
wp_nonce_field( 'simcal_license_manager', 'simcal_license_manager' ); |
55
|
|
|
// Add a license 'reset' button. |
56
|
|
|
?> |
57
|
|
|
<br><br> |
58
|
|
|
<a href="#" id="simcal-reset-licenses" data-dialog="<?php _e( 'WARNING: Are you sure you want to start over and delete all license keys from the settings?', 'google-calendar-events' ) ?>"> |
59
|
|
|
<?php _e( 'Delete your license keys', 'google-calendar-events' ) ?> |
60
|
|
|
<i class="simcal-icon-spinner simcal-icon-spin" style="display: none;"></i> |
61
|
|
|
</a> |
62
|
|
|
<?php |
63
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Add sections. |
68
|
|
|
* |
69
|
|
|
* @since 3.0.0 |
70
|
|
|
* |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
|
|
public function add_sections() { |
74
|
|
|
$sections = array( |
75
|
|
|
'keys' => array( |
76
|
|
|
'title' => __( 'Premium Add-on License Keys', 'google-calendar-events' ), |
77
|
|
|
'description' => __( 'Enter your add-on license keys below, making sure to activate each one to ensure they are valid.', 'google-calendar-events' ) . |
78
|
|
|
'<br/><br/>' . |
79
|
|
|
'<em>' . __( 'Your license keys are used for access to automatic upgrades and premium support.', 'google-calendar-events' ) . '</em>', |
80
|
|
|
), |
81
|
|
|
); |
82
|
|
|
return apply_filters( 'simcal_add_' . $this->option_group . '_' . $this->id .'_sections', $sections ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Add fields. |
87
|
|
|
* |
88
|
|
|
* @since 3.0.0 |
89
|
|
|
* |
90
|
|
|
* @return array |
91
|
|
|
*/ |
92
|
|
|
public function add_fields() { |
93
|
|
|
|
94
|
|
|
$fields = array(); |
95
|
|
|
$this->values = get_option( 'simple-calendar_' . $this->option_group . '_' . $this->id ); |
96
|
|
|
|
97
|
|
|
foreach ( $this->sections as $section => $contents ) { |
98
|
|
|
|
99
|
|
|
if ( 'keys' == $section ) { |
100
|
|
|
|
101
|
|
|
$addons = apply_filters( 'simcal_installed_addons', array() ); |
102
|
|
|
|
103
|
|
|
if ( ! empty( $addons ) && is_array( $addons ) ) { |
104
|
|
|
|
105
|
|
|
foreach ( $addons as $addon_id => $addon_name ) { |
106
|
|
|
|
107
|
|
|
$fields[ $section ][ $addon_id ] = array( |
108
|
|
|
'type' => 'license', |
109
|
|
|
'addon' => $addon_id, |
110
|
|
|
'title' => esc_attr( $addon_name ), |
111
|
|
|
'name' => 'simple-calendar_' . $this->option_group . '_' . $this->id . '[' . $section . '][' . $addon_id . ']', |
112
|
|
|
'id' => 'simple-calendar-' . $this->option_group . '-' . $this->id . '-' . $section . '-' . sanitize_key( $addon_id ), |
113
|
|
|
'value' => $this->get_option_value( $section, $addon_id ), |
114
|
|
|
'class' => array( |
115
|
|
|
'regular-text', |
116
|
|
|
'ltr', |
117
|
|
|
) |
118
|
|
|
); |
119
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
return apply_filters( 'simcal_add_' . $this->option_group . '_' . $this->id . '_fields', $fields ); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
} |
132
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.