'licenses', 'title' => __( 'License keys', 'polylang' ), 'description' => __( 'Manage licenses for Polylang Pro or addons.', 'polylang' ), ) ); $this->buttons['cancel'] = sprintf( '', __( 'Close' ) ); $this->items = apply_filters( 'pll_settings_licenses', array() ); add_action( 'wp_ajax_pll_deactivate_license', array( $this, 'deactivate_license' ) ); } /** * Tells if the module is active * * @since 1.9 * * @return bool */ public function is_active() { return ! empty( $this->items ); } /** * Displays the settings form * * @since 1.9 */ protected function form() { if ( ! empty( $this->items ) ) { ?> items as $item ) { echo $this->get_row( $item ); } ?>
license_data ) ) { $license = $item->license_data; } $class = 'license-null'; $out = sprintf( '' . '', esc_attr( $item->id ), esc_attr( $item->name ), esc_html( $item->license_key ) ); if ( ! empty( $license ) && is_object( $license ) ) { $now = current_time( 'timestamp' ); $expiration = strtotime( $license->expires, $now ); // Special case: the license expired after the last check if ( $license->success && $expiration < $now ) { $license->success = false; $license->error = 'expired'; } if ( false === $license->success ) { $class = 'notice-error notice-alt'; switch ( $license->error ) { case 'expired' : $message = sprintf( /* translators: %1$s is a date, %2$s and %3$s are html tags */ __( 'Your license key expired on %1$s. Please %2$srenew your license key%3$s.', 'polylang' ), date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ), sprintf( '', 'https://polylang.pro/checkout/?edd_license_key=' . $item->license_key ), '' ); break; case 'missing' : $message = sprintf( /* translators: %s are html tags */ __( 'Invalid license. Please %svisit your account page%s and verify it.', 'polylang' ), sprintf( '', 'https://polylang.pro/account' ), '' ); break; case 'invalid' : case 'site_inactive' : $message = sprintf( /* translators: %1$s is a product name, %2$s and %3$s are html tags */ __( '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' ), $item->name, sprintf( '', 'https://polylang.pro/account' ), '' ); break; case 'item_name_mismatch' : /* translators: %s is a product name */ $message = sprintf( __( 'This is not a %s license key.', 'polylang' ), $item->name ); break; case 'no_activations_left': /* translators: %s are html tags */ $message = sprintf( __( 'Your license key has reached its activation limit. %sView possible upgrades%s now.', 'polylang' ), sprintf( '', 'https://polylang.pro/account' ), '' ); break; } } else { $class = 'license-valid'; $out .= sprintf( '', $item->id, __( 'Deactivate', 'polylang' ) ); if ( 'lifetime' === $license->expires ) { $message = __( 'The license key never expires.', 'polylang' ); } elseif ( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) { $class = 'notice-warning notice-alt'; $message = sprintf( /* translators: %1$s is a date, %2$s and %3$s are html tags */ __( 'Your license key expires soon! It expires on %1$s. %2$sRenew your license key%3$s.', 'polylang' ), date_i18n( get_option( 'date_format' ), strtotime( $license->expires, $now ) ), sprintf( '', 'https://polylang.pro/checkout/?edd_license_key=' . $item->license_key ), '' ); } else { $message = sprintf( /* translators: %s is a date */ __( 'Your license key expires on %s.', 'polylang' ), date_i18n( get_option( 'date_format' ), strtotime( $license->expires, $now ) ) ); } } } if ( ! empty( $message ) ) { $out .= '

' . $message . '

'; } return sprintf( '%s', $item->id, $class, $out ); } /** * Ajax method to save the license keys and activate the licenses at the same time * Overrides parent's method * * @since 1.9 */ public function save_options() { check_ajax_referer( 'pll_options', '_pll_nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_die( -1 ); } if ( $this->module === $_POST['module'] && ! empty( $_POST['licenses'] ) ) { $x = new WP_Ajax_Response(); foreach ( $this->items as $item ) { $updated_item = $item->activate_license( sanitize_text_field( $_POST['licenses'][ $item->id ] ) ); $x->Add( array( 'what' => 'license-update', 'data' => $item->id, 'supplemental' => array( 'html' => $this->get_row( $updated_item ) ) ) ); } // Updated message add_settings_error( 'general', 'settings_updated', __( 'Settings saved.' ), 'updated' ); ob_start(); settings_errors(); $x->Add( array( 'what' => 'success', 'data' => ob_get_clean() ) ); $x->send(); } } /** * Ajax method to deactivate a license * * @since 1.9 */ public function deactivate_license() { check_ajax_referer( 'pll_options', '_pll_nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_die( -1 ); } $id = sanitize_text_field( substr( $_POST['id'], 11 ) ); wp_send_json( array( 'id' => $id, 'html' => $this->get_row( $this->items[ $id ]->deactivate_license() ), ) ); } }