| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | 4 | * A class to easily manage licenses for Polylang Pro and addons |
| 8 | 5 | * |
| @@ -134,16 +131,10 @@ | ||
| 134 | 131 | * @param string $request check_license | activate_license | deactivate_license |
| 135 | 132 | */ |
| 136 | 133 | private function api_request( $request ) { |
| 137 | 134 | $licenses = get_option( 'polylang_licenses' ); |
| 135 | + unset( $licenses[ $this->id ], $this->license_data ); | |
| 138 | 136 | |
| 139 | - if ( is_array( $licenses ) ) { | |
| 140 | - unset( $licenses[ $this->id ] ); | |
| 141 | - } else { | |
| 142 | - $licenses = array(); | |
| 143 | - } | |
| 144 | - unset( $this->license_data ); | |
| 145 | - | |
| 146 | 137 | if ( ! empty( $this->license_key ) ) { |
| 147 | 138 | // Data to send in our API request |
| 148 | 139 | $api_params = array( |
| 149 | 140 | 'edd_action' => $request, |
| @@ -155,9 +146,9 @@ | ||
| 155 | 146 | // Call the API |
| 156 | 147 | $response = wp_remote_post( |
| 157 | 148 | $this->api_url, |
| 158 | 149 | array( |
| 159 | - 'timeout' => 3, | |
| 150 | + 'timeout' => 15, | |
| 160 | 151 | 'sslverify' => false, |
| 161 | 152 | 'body' => $api_params, |
| 162 | 153 | ) |
| 163 | 154 | ); |
| @@ -176,124 +167,6 @@ | ||
| 176 | 167 | } |
| 177 | 168 | } |
| 178 | 169 | |
| 179 | 170 | update_option( 'polylang_licenses', $licenses ); // FIXME called multiple times when saving all licenses |
| 180 | - } | |
| 181 | - | |
| 182 | - /** | |
| 183 | - * Get the html form field in a table row (one per license key) for display | |
| 184 | - * | |
| 185 | - * @since 2.7 | |
| 186 | - * | |
| 187 | - * @return string | |
| 188 | - */ | |
| 189 | - public function get_form_field() { | |
| 190 | - if ( ! empty( $this->license_data ) ) { | |
| 191 | - $license = $this->license_data; | |
| 192 | - } | |
| 193 | - | |
| 194 | - $class = 'license-null'; | |
| 195 | - | |
| 196 | - $out = sprintf( | |
| 197 | - '<td><label for="pll-licenses[%1$s]">%2$s</label></td>' . | |
| 198 | - '<td><input name="licenses[%1$s]" id="pll-licenses[%1$s]" type="text" value="%3$s" class="regular-text code" />', | |
| 199 | - esc_attr( $this->id ), | |
| 200 | - esc_attr( $this->name ), | |
| 201 | - esc_html( $this->license_key ) | |
| 202 | - ); | |
| 203 | - | |
| 204 | - if ( ! empty( $license ) && is_object( $license ) ) { | |
| 205 | - $now = time(); | |
| 206 | - $expiration = isset( $license->expires ) ? strtotime( $license->expires ) : false; | |
| 207 | - | |
| 208 | - // Special case: the license expired after the last check | |
| 209 | - if ( $license->success && $expiration && $expiration < $now ) { | |
| 210 | - $license->success = false; | |
| 211 | - $license->error = 'expired'; | |
| 212 | - } | |
| 213 | - | |
| 214 | - if ( false === $license->success ) { | |
| 215 | - $class = 'notice-error notice-alt'; | |
| 216 | - | |
| 217 | - switch ( $license->error ) { | |
| 218 | - case 'expired': | |
| 219 | - $message = sprintf( | |
| 220 | - /* translators: %1$s is a date, %2$s is link start tag, %3$s is link end tag. */ | |
| 221 | - esc_html__( 'Your license key expired on %1$s. Please %2$srenew your license key%3$s.', 'polylang' ), | |
| 222 | - esc_html( date_i18n( get_option( 'date_format' ), $expiration ) ), | |
| 223 | - sprintf( '<a href="%s" target="_blank">', esc_url( 'https://polylang.pro/checkout/?edd_license_key=' . $this->license_key ) ), | |
| 224 | - '</a>' | |
| 225 | - ); | |
| 226 | - break; | |
| 227 | - | |
| 228 | - case 'disabled': | |
| 229 | - case 'revoked': | |
| 230 | - $message = esc_html__( 'Your license key has been disabled.', 'polylang' ); | |
| 231 | - break; | |
| 232 | - | |
| 233 | - case 'missing': | |
| 234 | - $message = sprintf( | |
| 235 | - /* translators: %1$s is link start tag, %2$s is link end tag. */ | |
| 236 | - esc_html__( 'Invalid license. Please %1$svisit your account page%2$s and verify it.', 'polylang' ), | |
| 237 | - sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account' ), | |
| 238 | - '</a>' | |
| 239 | - ); | |
| 240 | - break; | |
| 241 | - | |
| 242 | - case 'invalid': | |
| 243 | - case 'site_inactive': | |
| 244 | - $message = sprintf( | |
| 245 | - /* translators: %1$s is a product name, %2$s is link start tag, %3$s is link end tag. */ | |
| 246 | - esc_html__( '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' ), | |
| 247 | - esc_html( $this->name ), | |
| 248 | - sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account' ), | |
| 249 | - '</a>' | |
| 250 | - ); | |
| 251 | - break; | |
| 252 | - | |
| 253 | - case 'item_name_mismatch': | |
| 254 | - /* translators: %s is a product name */ | |
| 255 | - $message = sprintf( esc_html__( 'This is not a %s license key.', 'polylang' ), esc_html( $this->name ) ); | |
| 256 | - break; | |
| 257 | - | |
| 258 | - case 'no_activations_left': | |
| 259 | - $message = sprintf( | |
| 260 | - /* translators: %1$s is link start tag, %2$s is link end tag */ | |
| 261 | - esc_html__( 'Your license key has reached its activation limit. %1$sView possible upgrades%2$s now.', 'polylang' ), | |
| 262 | - sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account' ), | |
| 263 | - '</a>' | |
| 264 | - ); | |
| 265 | - break; | |
| 266 | - } | |
| 267 | - } else { | |
| 268 | - $class = 'license-valid'; | |
| 269 | - | |
| 270 | - $out .= sprintf( '<button id="deactivate_%s" type="button" class="button button-secondary pll-deactivate-license">%s</button>', esc_attr( $this->id ), esc_html__( 'Deactivate', 'polylang' ) ); | |
| 271 | - | |
| 272 | - if ( 'lifetime' === $license->expires ) { | |
| 273 | - $message = esc_html__( 'The license key never expires.', 'polylang' ); | |
| 274 | - } elseif ( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) { | |
| 275 | - $class = 'notice-warning notice-alt'; | |
| 276 | - $message = sprintf( | |
| 277 | - /* translators: %1$s is a date, %2$s is link start tag, %3$s is link end tag. */ | |
| 278 | - esc_html__( 'Your license key will expire soon! Precisely, it will expire on %1$s. %2$sRenew your license key today!%3$s.', 'polylang' ), | |
| 279 | - esc_html( date_i18n( get_option( 'date_format' ), $expiration ) ), | |
| 280 | - sprintf( '<a href="%s" target="_blank">', esc_url( 'https://polylang.pro/checkout/?edd_license_key=' . $this->license_key ) ), | |
| 281 | - '</a>' | |
| 282 | - ); | |
| 283 | - } else { | |
| 284 | - $message = sprintf( | |
| 285 | - /* translators: %s is a date */ | |
| 286 | - esc_html__( 'Your license key expires on %s.', 'polylang' ), | |
| 287 | - esc_html( date_i18n( get_option( 'date_format' ), $expiration ) ) | |
| 288 | - ); | |
| 289 | - } | |
| 290 | - } | |
| 291 | - } | |
| 292 | - | |
| 293 | - if ( ! empty( $message ) ) { | |
| 294 | - $out .= '<p>' . $message . '</p>'; | |
| 295 | - } | |
| 296 | - | |
| 297 | - return sprintf( '<tr id="pll-license-%s" class="%s">%s</tr>', esc_attr( $this->id ), $class, $out ); | |
| 298 | 171 | } |
| 299 | 172 | } |