PluginProbe
Polylang / 2.0.12
Polylang v2.0.12
3.8.10 3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 All 234 releases
← All changes | settings/settings-licenses.php +121 -35 2.7.3 → 2.0.12 View file →
@@ -15,18 +15,15 @@
15 15 *
16 16 * @param object $polylang polylang object
17 17 */
18 18 public function __construct( &$polylang ) {
19 - parent::__construct(
20 - $polylang,
21 - array(
22 - 'module' => 'licenses',
23 - 'title' => __( 'License keys', 'polylang' ),
24 - 'description' => __( 'Manage licenses for Polylang Pro and add-ons.', 'polylang' ),
25 - )
26 - );
19 + parent::__construct( $polylang, array(
20 + 'module' => 'licenses',
21 + 'title' => __( 'License keys', 'polylang' ),
22 + 'description' => __( 'Manage licenses for Polylang Pro or addons.', 'polylang' ),
23 + ) );
27 24
28 - $this->buttons['cancel'] = sprintf( '<button type="button" class="button button-secondary cancel">%s</button>', __( 'Close', 'polylang' ) );
25 + $this->buttons['cancel'] = sprintf( '<button type="button" class="button button-secondary cancel">%s</button>', __( 'Close' ) );
29 26
30 27 $this->items = apply_filters( 'pll_settings_licenses', array() );
31 28
32 29 add_action( 'wp_ajax_pll_deactivate_license', array( $this, 'deactivate_license' ) );
@@ -49,16 +46,13 @@
49 46 * @since 1.9
50 47 */
51 48 protected function form() {
52 49 if ( ! empty( $this->items ) ) { ?>
53 - <table id="pll-licenses-table" class="form-table">
54 - <?php
55 - foreach ( $this->items as $item ) {
56 - echo $this->get_row( $item ); // phpcs:ignore WordPress.Security.EscapeOutput
57 - }
58 - ?>
59 - </table>
60 - <?php
50 + <table id="pll-licenses-table" class="form-table"><?php
51 + foreach ( $this->items as $item ) {
52 + echo $this->get_row( $item );
53 + } ?>
54 + </table><?php
61 55 }
62 56 }
63 57
64 58 /**
@@ -69,9 +63,109 @@
69 63 * @param array $item licence id, name and key
70 64 * @return string
71 65 */
72 66 protected function get_row( $item ) {
73 - return $item->get_form_field();
67 + if ( ! empty( $item->license_data ) ) {
68 + $license = $item->license_data;
69 + }
70 +
71 + $class = 'license-null';
72 +
73 + $out = sprintf(
74 + '<td><label for="pll-licenses[%1$s]">%2$s</label></td>' .
75 + '<td><input name="licenses[%1$s]" id="pll-licenses[%1$s]" type="text" value="%3$s" class="regular-text code" />',
76 + esc_attr( $item->id ), esc_attr( $item->name ), esc_html( $item->license_key )
77 + );
78 +
79 + if ( ! empty( $license ) && is_object( $license ) ) {
80 + $now = current_time( 'timestamp' );
81 + $expiration = strtotime( $license->expires, $now );
82 +
83 + // Special case: the license expired after the last check
84 + if ( $license->success && $expiration < $now ) {
85 + $license->success = false;
86 + $license->error = 'expired';
87 + }
88 +
89 + if ( false === $license->success ) {
90 + $class = 'notice-error notice-alt';
91 +
92 + switch ( $license->error ) {
93 + case 'expired' :
94 + $message = sprintf(
95 + /* translators: %1$s is a date, %2$s and %3$s are html tags */
96 + __( 'Your license key expired on %1$s. Please %2$srenew your license key%3$s.', 'polylang' ),
97 + date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
98 + sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/checkout/?edd_license_key=' . $item->license_key ),
99 + '</a>'
100 + );
101 + break;
102 +
103 + case 'missing' :
104 + $message = sprintf(
105 + /* translators: %s are html tags */
106 + __( 'Invalid license. Please %svisit your account page%s and verify it.', 'polylang' ),
107 + sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account' ),
108 + '</a>'
109 + );
110 + break;
111 +
112 + case 'invalid' :
113 + case 'site_inactive' :
114 + $message = sprintf(
115 + /* translators: %1$s is a product name, %2$s and %3$s are html tags */
116 + __( 'Your %1$s license key is not active for this URL. Please %2$svisit your account page%3$s to manage your license key URLs.', 'polylang' ),
117 + $item->name,
118 + sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account' ),
119 + '</a>'
120 + );
121 + break;
122 +
123 + case 'item_name_mismatch' :
124 + /* translators: %s is a product name */
125 + $message = sprintf( __( 'This is not a %s license key.', 'polylang' ), $item->name );
126 + break;
127 +
128 + case 'no_activations_left':
129 + /* translators: %s are html tags */
130 + $message = sprintf(
131 + __( 'Your license key has reached its activation limit. %sView possible upgrades%s now.', 'polylang' ),
132 + sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account' ),
133 + '</a>'
134 + );
135 + break;
136 + }
137 + } else {
138 + $class = 'license-valid';
139 +
140 + $out .= sprintf( '<button id="deactivate_%s" type="button" class="button button-secondary pll-deactivate-license">%s</button>', $item->id, __( 'Deactivate', 'polylang' ) );
141 +
142 + if ( 'lifetime' === $license->expires ) {
143 + $message = __( 'The license key never expires.', 'polylang' );
144 + } elseif ( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) {
145 + $class = 'notice-warning notice-alt';
146 + $message = sprintf(
147 + /* translators: %1$s is a date, %2$s and %3$s are html tags */
148 + __( 'Your license key expires soon! It expires on %1$s. %2$sRenew your license key%3$s.', 'polylang' ),
149 + date_i18n( get_option( 'date_format' ), strtotime( $license->expires, $now ) ),
150 + sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/checkout/?edd_license_key=' . $item->license_key ),
151 + '</a>'
152 + );
153 + } else {
154 + $message = sprintf(
155 + /* translators: %s is a date */
156 + __( 'Your license key expires on %s.', 'polylang' ),
157 + date_i18n( get_option( 'date_format' ), strtotime( $license->expires, $now ) )
158 + );
159 + }
160 + }
161 + }
162 +
163 + if ( ! empty( $message ) ) {
164 + $out .= '<p>' . $message . '</p>';
165 + }
166 +
167 + return sprintf( '<tr id="pll-license-%s" class="%s">%s</tr>', $item->id, $class, $out );
74 168 }
75 169
76 170 /**
77 171 * Ajax method to save the license keys and activate the licenses at the same time
@@ -84,19 +178,17 @@
84 178 if ( ! current_user_can( 'manage_options' ) ) {
85 179 wp_die( -1 );
86 180 }
87 181
88 - if ( isset( $_POST['module'] ) && $this->module === $_POST['module'] && ! empty( $_POST['licenses'] ) ) {
182 + if ( $this->module === $_POST['module'] && ! empty( $_POST['licenses'] ) ) {
89 183 $x = new WP_Ajax_Response();
90 184 foreach ( $this->items as $item ) {
91 - if ( ! empty( $_POST['licenses'][ $item->id ] ) ) {
92 - $updated_item = $item->activate_license( sanitize_key( $_POST['licenses'][ $item->id ] ) );
93 - $x->Add( array( 'what' => 'license-update', 'data' => $item->id, 'supplemental' => array( 'html' => $this->get_row( $updated_item ) ) ) );
94 - }
185 + $updated_item = $item->activate_license( sanitize_text_field( $_POST['licenses'][ $item->id ] ) );
186 + $x->Add( array( 'what' => 'license-update', 'data' => $item->id, 'supplemental' => array( 'html' => $this->get_row( $updated_item ) ) ) );
95 187 }
96 188
97 189 // Updated message
98 - add_settings_error( 'general', 'settings_updated', __( 'Settings saved.', 'polylang' ), 'updated' );
190 + add_settings_error( 'general', 'settings_updated', __( 'Settings saved.' ), 'updated' );
99 191 ob_start();
100 192 settings_errors();
101 193 $x->Add( array( 'what' => 'success', 'data' => ob_get_clean() ) );
102 194 $x->send();
@@ -114,17 +206,11 @@
114 206 if ( ! current_user_can( 'manage_options' ) ) {
115 207 wp_die( -1 );
116 208 }
117 209
118 - if ( ! isset( $_POST['id'] ) ) {
119 - wp_die( 0 );
120 - }
121 -
122 - $id = substr( sanitize_text_field( wp_unslash( $_POST['id'] ) ), 11 );
123 - wp_send_json(
124 - array(
125 - 'id' => $id,
126 - 'html' => $this->get_row( $this->items[ $id ]->deactivate_license() ),
127 - )
128 - );
210 + $id = sanitize_text_field( substr( $_POST['id'], 11 ) );
211 + wp_send_json( array(
212 + 'id' => $id,
213 + 'html' => $this->get_row( $this->items[ $id ]->deactivate_license() ),
214 + ) );
129 215 }
130 216 }