Initial commit xmarticaims

This commit is contained in:
2026-11-02 10:26:32 -06:00
commit e74236f5c1
9764 changed files with 2880647 additions and 0 deletions
@@ -0,0 +1,123 @@
<?php
/**
* @package Polylang Updater
*/
namespace WP_Syntex\Polylang_Pro\Updater;
use PLL_License;
defined( 'ABSPATH' ) || exit;
/**
* Trait that holds common code between `Settings` and `Wizard_Licenses_Step`.
*
* @since 1.0
*/
trait Common_Trait {
/**
* Stores an array of objects allowing to manage a license.
* In case of one plugin is using this new system, and another is using the old one, we must allow both classes.
*
* @var (License|PLL_License)[]|null
*/
private $items;
/**
* Returns a list of license objects.
*
* @since 1.0
*
* @return (License|PLL_License)[] Array of instances of `WP_Syntex\Polylang_Pro\Updater\License` or `PLL_License`,
* keyed by string IDs.
*/
private function get_licenses(): array {
if ( is_array( $this->items ) ) {
return $this->items;
}
/**
* Filters the list of Polylang licenses.
*
* @since 1.0
*
* @param (License|PLL_License)[] $licenses Array of instances of `WP_Syntex\Polylang_Pro\Updater\License`
* or `PLL_License`, keyed by string IDs.
*/
$this->items = (array) apply_filters( 'pll_settings_licenses', array() );
return $this->items;
}
/**
* Launches hooks.
*
* @since 1.0
*
* @return void
*/
private function hooks(): void {
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'wp_ajax_pllu_deactivate_license', array( $this, 'deactivate_license' ) );
}
/**
* Enqueues styles and scripts.
*
* @since 1.0
*
* @return void
*/
public function enqueue_scripts(): void {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
/*
* Use `__DIR__` in `plugins_url()` to get the path to a "file" located at the root of this package. Keep that
* in mind if this file is moved.
*/
$style_url = plugins_url( "/css/build/license{$suffix}.css", __DIR__ );
wp_enqueue_style( 'pll_license', $style_url, array(), Updater::get_version() );
$script_url = plugins_url( "/js/build/license{$suffix}.js", __DIR__ );
wp_enqueue_script( 'pll_license', $script_url, array( 'wp-api-fetch' ), Updater::get_version(), true );
}
/**
* Ajax method to deactivate a license.
* Hooked to `wp_ajax_pllu_deactivate_license`.
*
* Requires the class constant `DEACTIVATE_LICENSE_NONCE_ACTION`.
*
* @since 1.0
*
* @return void
*
* @phpstan-return never
*/
public function deactivate_license(): void {
check_ajax_referer( self::DEACTIVATE_LICENSE_NONCE_ACTION, '_pll_nonce' );
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( -1 );
}
if ( ! isset( $_POST['id'] ) ) {
wp_die( 0 );
}
$id = substr( sanitize_text_field( wp_unslash( $_POST['id'] ) ), 11 );
$licenses = $this->get_licenses();
if ( ! isset( $licenses[ $id ] ) ) {
wp_die( 0 );
}
$license = $licenses[ $id ]->deactivate_license();
wp_send_json_success(
array(
'id' => $id,
'html' => $license->get_form_field(),
)
);
}
}
@@ -0,0 +1,737 @@
<?php
/**
* @package Polylang Updater
*
* Modified version with:
* - 'polylang-pro' text domain,
* - missing comments for translators,
* - a bug fix (https://github.com/polylang/updater/pull/14).
*/
namespace WP_Syntex\Polylang_Pro\Updater;
use stdClass;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Allows plugins to use their own update API.
*
* @author Easy Digital Downloads
* @version 1.9.4
*/
class EDD_SL_Plugin_Updater {
private $api_url = '';
private $api_data = array();
private $plugin_file = '';
private $name = '';
private $slug = '';
private $version = '';
private $wp_override = false;
private $beta = false;
private $failed_request_cache_key;
/**
* Class constructor.
*
* @uses plugin_basename()
* @uses hook()
*
* @param string $_api_url The URL pointing to the custom API endpoint.
* @param string $_plugin_file Path to the plugin file.
* @param array $_api_data Optional data to send with API calls.
*/
public function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
global $edd_plugin_data;
$this->api_url = trailingslashit( $_api_url );
$this->api_data = $_api_data;
$this->plugin_file = $_plugin_file;
$this->name = plugin_basename( $_plugin_file );
$this->slug = basename( dirname( $_plugin_file ) );
$this->version = $_api_data['version'];
$this->wp_override = isset( $_api_data['wp_override'] ) ? (bool) $_api_data['wp_override'] : false;
$this->beta = ! empty( $this->api_data['beta'] ) ? true : false;
$this->failed_request_cache_key = 'edd_sl_failed_http_' . md5( $this->api_url );
$edd_plugin_data[ $this->slug ] = $this->api_data;
/**
* Fires after the $edd_plugin_data is setup.
*
* @since x.x.x
*
* @param array $edd_plugin_data Array of EDD SL plugin data.
*/
do_action( 'post_edd_sl_plugin_updater_setup', $edd_plugin_data );
// Set up hooks.
$this->init();
}
/**
* Set up WordPress filters to hook into WP's update process.
*
* @uses add_filter()
*
* @return void
*/
public function init() {
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
add_action( 'after_plugin_row', array( $this, 'show_update_notification' ), 10, 2 );
add_action( 'admin_init', array( $this, 'show_changelog' ) );
}
/**
* Check for Updates at the defined API endpoint and modify the update array.
*
* This function dives into the update API just when WordPress creates its update array,
* then adds a custom API call and injects the custom plugin data retrieved from the API.
* It is reassembled from parts of the native WordPress plugin update code.
* See wp-includes/update.php line 121 for the original wp_update_plugins() function.
*
* @uses api_request()
*
* @param array $_transient_data Update array build by WordPress.
* @return array Modified update array with custom plugin data.
*/
public function check_update( $_transient_data ) {
if ( ! is_object( $_transient_data ) ) {
$_transient_data = new stdClass();
}
if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[ $this->name ] ) && false === $this->wp_override ) {
return $_transient_data;
}
$current = $this->get_update_transient_data();
if ( false !== $current && is_object( $current ) && isset( $current->new_version ) ) {
if ( version_compare( $this->version, $current->new_version, '<' ) ) {
$_transient_data->response[ $this->name ] = $current;
} else {
// Populating the no_update information is required to support auto-updates in WordPress 5.5.
$_transient_data->no_update[ $this->name ] = $current;
}
}
$_transient_data->last_checked = time();
$_transient_data->checked[ $this->name ] = $this->version;
return $_transient_data;
}
/**
* Get repo API data from store.
* Save to cache.
*
* @return \stdClass
*/
public function get_repo_api_data() {
$version_info = $this->get_cached_version_info();
if ( false === $version_info ) {
$version_info = $this->api_request(
'plugin_latest_version',
array(
'slug' => $this->slug,
'beta' => $this->beta,
)
);
if ( ! $version_info ) {
return false;
}
// This is required for your plugin to support auto-updates in WordPress 5.5.
$version_info->plugin = $this->name;
$version_info->id = $this->name;
$version_info->tested = $this->get_tested_version( $version_info );
if ( ! isset( $version_info->requires ) ) {
$version_info->requires = '';
}
if ( ! isset( $version_info->requires_php ) ) {
$version_info->requires_php = '';
}
$this->set_version_info_cache( $version_info );
}
// Added by Polylang.
$defaults = array(
'url' => '',
'package' => '',
'new_version' => '',
'tested' => '',
'requires' => '',
'requires_php' => '',
'icons' => new stdClass(),
'banners' => new stdClass(),
);
$version_info = (object) array_merge( $defaults, (array) $version_info );
// End of added by Polylang.
return $version_info;
}
/**
* Gets a limited set of data from the API response.
* This is used for the update_plugins transient.
*
* @since 3.8.12
* @return \stdClass|false
*/
private function get_update_transient_data() {
$version_info = $this->get_repo_api_data();
if ( ! $version_info ) {
return false;
}
$limited_data = new \stdClass();
$limited_data->slug = $this->slug;
$limited_data->plugin = $this->name;
$limited_data->url = $version_info->url;
$limited_data->package = $version_info->package;
$limited_data->icons = $this->convert_object_to_array( $version_info->icons );
$limited_data->banners = $this->convert_object_to_array( $version_info->banners );
$limited_data->new_version = $version_info->new_version;
$limited_data->tested = $version_info->tested;
$limited_data->requires = $version_info->requires;
$limited_data->requires_php = $version_info->requires_php;
return $limited_data;
}
/**
* Gets the plugin's tested version.
*
* @since 1.9.2
* @param object $version_info
* @return null|string
*/
private function get_tested_version( $version_info ) {
// There is no tested version.
if ( empty( $version_info->tested ) ) {
return null;
}
// Strip off extra version data so the result is x.y or x.y.z.
list( $current_wp_version ) = explode( '-', get_bloginfo( 'version' ) );
// The tested version is greater than or equal to the current WP version, no need to do anything.
if ( version_compare( $version_info->tested, $current_wp_version, '>=' ) ) {
return $version_info->tested;
}
$current_version_parts = explode( '.', $current_wp_version );
$tested_parts = explode( '.', $version_info->tested );
// The current WordPress version is x.y.z, so update the tested version to match it.
if ( isset( $current_version_parts[2] ) && $current_version_parts[0] === $tested_parts[0] && $current_version_parts[1] === $tested_parts[1] ) {
$tested_parts[2] = $current_version_parts[2];
}
return implode( '.', $tested_parts );
}
/**
* Show the update notification on multisite subsites.
*
* @param string $file
* @param array $plugin
*/
public function show_update_notification( $file, $plugin ) {
// Return early if in the network admin, or if this is not a multisite install.
if ( is_network_admin() || ! is_multisite() ) {
return;
}
// Allow single site admins to see that an update is available.
if ( ! current_user_can( 'activate_plugins' ) ) {
return;
}
if ( $this->name !== $file ) {
return;
}
// Do not print any message if update does not exist.
$update_cache = get_site_transient( 'update_plugins' );
if ( ! isset( $update_cache->response[ $this->name ] ) ) {
if ( ! is_object( $update_cache ) ) {
$update_cache = new stdClass();
}
$update_cache->response[ $this->name ] = $this->get_repo_api_data();
}
// Return early if this plugin isn't in the transient->response or if the site is running the current or newer version of the plugin.
if ( empty( $update_cache->response[ $this->name ] ) || version_compare( $this->version, $update_cache->response[ $this->name ]->new_version, '>=' ) ) {
return;
}
printf(
'<tr class="plugin-update-tr %3$s" id="%1$s-update" data-slug="%1$s" data-plugin="%2$s">',
$this->slug,
$file,
in_array( $this->name, $this->get_active_plugins(), true ) ? 'active' : 'inactive'
);
echo '<td colspan="3" class="plugin-update colspanchange">';
echo '<div class="update-message notice inline notice-warning notice-alt"><p>';
$changelog_link = '';
if ( ! empty( $update_cache->response[ $this->name ]->sections->changelog ) ) {
$changelog_link = add_query_arg(
array(
'edd_sl_action' => 'view_plugin_changelog',
'plugin' => urlencode( $this->name ),
'slug' => urlencode( $this->slug ),
'TB_iframe' => 'true',
'width' => 77,
'height' => 911,
),
self_admin_url( 'index.php' )
);
}
$update_link = add_query_arg(
array(
'action' => 'upgrade-plugin',
'plugin' => urlencode( $this->name ),
),
self_admin_url( 'update.php' )
);
printf(
/* translators: the plugin name. */
esc_html__( 'There is a new version of %1$s available.', 'polylang-pro' ),
esc_html( $plugin['Name'] )
);
if ( ! current_user_can( 'update_plugins' ) ) {
echo ' ';
esc_html_e( 'Contact your network administrator to install the update.', 'polylang-pro' );
} elseif ( empty( $update_cache->response[ $this->name ]->package ) && ! empty( $changelog_link ) ) {
echo ' ';
printf(
/* translators: 1. opening anchor tag, do not translate 2. the new plugin version 3. closing anchor tag, do not translate. */
__( '%1$sView version %2$s details%3$s.', 'polylang-pro' ),
'<a target="_blank" class="thickbox open-plugin-details-modal" href="' . esc_url( $changelog_link ) . '">',
esc_html( $update_cache->response[ $this->name ]->new_version ),
'</a>'
);
} elseif ( ! empty( $changelog_link ) ) {
echo ' ';
printf(
/* translators: 1. and 4. are opening anchor tags 2. the new plugin version 3. and 5. are closing anchor tags. */
__( '%1$sView version %2$s details%3$s or %4$supdate now%5$s.', 'polylang-pro' ),
'<a target="_blank" class="thickbox open-plugin-details-modal" href="' . esc_url( $changelog_link ) . '">',
esc_html( $update_cache->response[ $this->name ]->new_version ),
'</a>',
'<a target="_blank" class="update-link" href="' . esc_url( wp_nonce_url( $update_link, 'upgrade-plugin_' . $file ) ) . '">',
'</a>'
);
} else {
printf(
' %1$s%2$s%3$s',
'<a target="_blank" class="update-link" href="' . esc_url( wp_nonce_url( $update_link, 'upgrade-plugin_' . $file ) ) . '">',
esc_html__( 'Update now.', 'polylang-pro' ),
'</a>'
);
}
do_action( "in_plugin_update_message-{$file}", $plugin, $plugin );
echo '</p></div></td></tr>';
}
/**
* Gets the plugins active in a multisite network.
*
* @return array
*/
private function get_active_plugins() {
$active_plugins = (array) get_option( 'active_plugins' );
$active_network_plugins = (array) get_site_option( 'active_sitewide_plugins' );
return array_merge( $active_plugins, array_keys( $active_network_plugins ) );
}
/**
* Updates information on the "View version x.x details" page with custom data.
*
* @uses api_request()
*
* @param mixed $_data
* @param string $_action
* @param object $_args
* @return object $_data
*/
public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
if ( 'plugin_information' !== $_action ) {
return $_data;
}
if ( ! isset( $_args->slug ) || ( $_args->slug !== $this->slug ) ) {
return $_data;
}
$to_send = array(
'slug' => $this->slug,
'is_ssl' => is_ssl(),
'fields' => array(
'banners' => array(),
'reviews' => false,
'icons' => array(),
),
);
// Get the transient where we store the api request for this plugin for 24 hours
$edd_api_request_transient = $this->get_cached_version_info();
//If we have no transient-saved value, run the API, set a fresh transient with the API value, and return that value too right now.
if ( empty( $edd_api_request_transient ) ) {
$api_response = $this->api_request( 'plugin_information', $to_send );
if ( empty( $api_response ) ) {
return $_data;
}
// Expires in 3 hours
$this->set_version_info_cache( $api_response );
$_data = $api_response;
} else {
$_data = $edd_api_request_transient;
}
// Convert sections into an associative array, since we're getting an object, but Core expects an array.
if ( isset( $_data->sections ) && ! is_array( $_data->sections ) ) {
$_data->sections = $this->convert_object_to_array( $_data->sections );
}
// Convert banners into an associative array, since we're getting an object, but Core expects an array.
if ( isset( $_data->banners ) && ! is_array( $_data->banners ) ) {
$_data->banners = $this->convert_object_to_array( $_data->banners );
}
// Convert icons into an associative array, since we're getting an object, but Core expects an array.
if ( isset( $_data->icons ) && ! is_array( $_data->icons ) ) {
$_data->icons = $this->convert_object_to_array( $_data->icons );
}
// Convert contributors into an associative array, since we're getting an object, but Core expects an array.
if ( isset( $_data->contributors ) && ! is_array( $_data->contributors ) ) {
$_data->contributors = $this->convert_object_to_array( $_data->contributors );
}
if ( ! isset( $_data->plugin ) ) {
$_data->plugin = $this->name;
}
if ( ! isset( $_data->version ) && ! empty( $_data->new_version ) ) {
$_data->version = $_data->new_version;
}
return $_data;
}
/**
* Convert some objects to arrays when injecting data into the update API
*
* Some data like sections, banners, and icons are expected to be an associative array, however due to the JSON
* decoding, they are objects. This method allows us to pass in the object and return an associative array.
*
* @since 3.6.5
*
* @param stdClass $data
*
* @return array
*/
private function convert_object_to_array( $data ) {
if ( ! is_array( $data ) && ! is_object( $data ) ) {
return array();
}
$new_data = array();
foreach ( $data as $key => $value ) {
$new_data[ $key ] = is_object( $value ) ? $this->convert_object_to_array( $value ) : $value;
}
return $new_data;
}
/**
* Disable SSL verification in order to prevent download update failures
*
* @param array $args
* @param string $url
* @return object $array
*/
public function http_request_args( $args, $url ) {
if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
$args['sslverify'] = $this->verify_ssl();
}
return $args;
}
/**
* Calls the API and, if successfull, returns the object delivered by the API.
*
* @uses get_bloginfo()
* @uses wp_remote_post()
* @uses is_wp_error()
*
* @param string $_action The requested action.
* @param array $_data Parameters for the API action.
* @return false|object|void
*/
private function api_request( $_action, $_data ) {
$data = array_merge( $this->api_data, $_data );
if ( $data['slug'] !== $this->slug ) {
return;
}
// Don't allow a plugin to ping itself
if ( trailingslashit( home_url() ) === $this->api_url ) {
return false;
}
if ( $this->request_recently_failed() ) {
return false;
}
return $this->get_version_from_remote();
}
/**
* Determines if a request has recently failed.
*
* @since 1.9.1
*
* @return bool
*/
private function request_recently_failed() {
$failed_request_details = get_option( $this->failed_request_cache_key );
// Request has never failed.
if ( empty( $failed_request_details ) || ! is_numeric( $failed_request_details ) ) {
return false;
}
/*
* Request previously failed, but the timeout has expired.
* This means we're allowed to try again.
*/
if ( time() > $failed_request_details ) {
delete_option( $this->failed_request_cache_key );
return false;
}
return true;
}
/**
* Logs a failed HTTP request for this API URL.
* We set a timestamp for 1 hour from now. This prevents future API requests from being
* made to this domain for 1 hour. Once the timestamp is in the past, API requests
* will be allowed again. This way if the site is down for some reason we don't bombard
* it with failed API requests.
*
* @see EDD_SL_Plugin_Updater::request_recently_failed
*
* @since 1.9.1
*/
private function log_failed_request() {
update_option( $this->failed_request_cache_key, strtotime( '+1 hour' ) );
}
/**
* If available, show the changelog for sites in a multisite install.
*/
public function show_changelog() {
if ( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' !== $_REQUEST['edd_sl_action'] ) {
return;
}
if ( empty( $_REQUEST['plugin'] ) ) {
return;
}
if ( empty( $_REQUEST['slug'] ) || $this->slug !== $_REQUEST['slug'] ) {
return;
}
if ( ! current_user_can( 'update_plugins' ) ) {
wp_die( esc_html__( 'You do not have permission to install plugin updates', 'polylang-pro' ), esc_html__( 'Error', 'polylang-pro' ), array( 'response' => 403 ) );
}
$version_info = $this->get_repo_api_data();
if ( isset( $version_info->sections ) ) {
$sections = $this->convert_object_to_array( $version_info->sections );
if ( ! empty( $sections['changelog'] ) ) {
echo '<div style="background:#fff;padding:10px;">' . wp_kses_post( $sections['changelog'] ) . '</div>';
}
}
exit;
}
/**
* Gets the current version information from the remote site.
*
* @return array|false
*/
private function get_version_from_remote() {
$api_params = array(
'edd_action' => 'get_version',
'license' => ! empty( $this->api_data['license'] ) ? $this->api_data['license'] : '',
'item_name' => isset( $this->api_data['item_name'] ) ? $this->api_data['item_name'] : false,
'item_id' => isset( $this->api_data['item_id'] ) ? $this->api_data['item_id'] : false,
'version' => isset( $this->api_data['version'] ) ? $this->api_data['version'] : false,
'slug' => $this->slug,
'author' => $this->api_data['author'],
'url' => home_url(),
'beta' => $this->beta,
'php_version' => phpversion(),
'wp_version' => get_bloginfo( 'version' ),
);
/**
* Filters the parameters sent in the API request.
*
* @param array $api_params The array of data sent in the request.
* @param array $this->api_data The array of data set up in the class constructor.
* @param string $this->plugin_file The full path and filename of the file.
*/
$api_params = apply_filters( 'edd_sl_plugin_updater_api_params', $api_params, $this->api_data, $this->plugin_file );
$request = wp_remote_post(
$this->api_url,
array(
'timeout' => 15,
'sslverify' => $this->verify_ssl(),
'body' => $api_params,
)
);
if ( is_wp_error( $request ) || ( 200 !== wp_remote_retrieve_response_code( $request ) ) ) {
$this->log_failed_request();
return false;
}
$request = json_decode( wp_remote_retrieve_body( $request ) );
if ( $request && isset( $request->sections ) ) {
$request->sections = maybe_unserialize( $request->sections );
} else {
$request = false;
}
if ( $request && isset( $request->banners ) ) {
$request->banners = maybe_unserialize( $request->banners );
}
if ( $request && isset( $request->icons ) ) {
$request->icons = maybe_unserialize( $request->icons );
}
if ( ! empty( $request->sections ) ) {
foreach ( $request->sections as $key => $section ) {
$request->$key = (array) $section;
}
}
return $request;
}
/**
* Get the version info from the cache, if it exists.
*
* @param string $cache_key
* @return object
*/
public function get_cached_version_info( $cache_key = '' ) {
if ( empty( $cache_key ) ) {
$cache_key = $this->get_cache_key();
}
$cache = get_option( $cache_key );
// Cache is expired
if ( empty( $cache['timeout'] ) || time() > $cache['timeout'] ) {
return false;
}
// We need to turn the icons into an array, thanks to WP Core forcing these into an object at some point.
$cache['value'] = json_decode( $cache['value'] );
if ( ! empty( $cache['value']->icons ) ) {
$cache['value']->icons = (array) $cache['value']->icons;
}
return $cache['value'];
}
/**
* Adds the plugin version information to the database.
*
* @param string $value
* @param string $cache_key
*/
public function set_version_info_cache( $value = '', $cache_key = '' ) {
if ( empty( $cache_key ) ) {
$cache_key = $this->get_cache_key();
}
$data = array(
'timeout' => strtotime( '+3 hours', time() ),
'value' => wp_json_encode( $value ),
);
update_option( $cache_key, $data, 'no' );
// Delete the duplicate option
delete_option( 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) ) );
}
/**
* Returns if the SSL of the store should be verified.
*
* @since 1.6.13
* @return bool
*/
private function verify_ssl() {
return (bool) apply_filters( 'edd_sl_api_request_verify_ssl', true, $this );
}
/**
* Gets the unique key (option name) for a plugin.
*
* @since 1.9.0
* @return string
*/
private function get_cache_key() {
$string = $this->slug . $this->api_data['license'] . $this->beta;
return 'edd_sl_' . md5( serialize( $string ) );
}
}
@@ -0,0 +1,393 @@
<?php
/**
* @package Polylang Updater
*/
namespace WP_Syntex\Polylang_Pro\Updater;
defined( 'ABSPATH' ) || exit;
/**
* A class to easily manage licenses for Polylang Pro and addons.
*
* @since 1.0
*/
class License {
/**
* URL to Polylang's account page.
*
* @var string
*/
public const ACCOUNT_URL = 'https://polylang.pro/my-account/';
/**
* Sanitized plugin name.
*
* @var string
*/
public $id;
/**
* Plugin name.
*
* @var string
*/
public $name;
/**
* License key.
*
* @var string
*/
public $license_key;
/**
* License data, obtained from the API request.
*
* @var \stdClass|null
*/
public $license_data;
/**
* Main plugin file.
*
* @var string
*/
private $file;
/**
* Current plugin version.
*
* @var string
*/
private $version;
/**
* Plugin author.
*
* @var string
*/
private $author = 'WP SYNTEX';
/**
* API url.
*
* @var string.
*/
private $api_url = 'https://polylang.pro';
/**
* Constructor.
*
* @since 1.0
*
* @param string $file The plugin file.
* @param string $item_name The plugin name.
* @param string $version The plugin version.
*/
public function __construct( string $file, string $item_name, string $version ) {
$this->id = sanitize_title( $item_name );
$this->file = $file;
$this->name = $item_name;
$this->version = $version;
$licenses = (array) get_option( 'polylang_licenses', array() );
$license = isset( $licenses[ $this->id ] ) && is_array( $licenses[ $this->id ] ) ? $licenses[ $this->id ] : array();
$this->license_key = ! empty( $license['key'] ) ? (string) $license['key'] : '';
if ( ! empty( $license['data'] ) ) {
$this->license_data = (object) $license['data'];
}
// Updater.
$this->auto_updater();
// Register settings.
add_filter( 'pll_settings_modules', array( $this, 'settings_module' ) );
add_filter( 'pll_settings_licenses', array( $this, 'settings' ) );
// Weekly schedule.
if ( ! wp_next_scheduled( 'polylang_check_licenses' ) ) {
wp_schedule_event( time(), 'weekly', 'polylang_check_licenses' );
}
add_action( 'polylang_check_licenses', array( $this, 'check_license' ) );
}
/**
* Creates a new instance of the auto-updater.
*
* @since 1.0
*
* @return void
*/
public function auto_updater(): void {
$args = array(
'version' => $this->version,
'license' => $this->license_key,
'author' => $this->author,
'item_name' => $this->name,
);
// Setup the updater.
new EDD_SL_Plugin_Updater( $this->api_url, $this->file, $args );
}
/**
* Registers the settings module.
* Hooked to `pll_settings_modules`.
*
* @since 1.0
*
* @param string[] $modules The list of module classes.
* @return string[]
*/
public function settings_module( $modules ) {
/*
* Backward compatibility with Polylang < 3.7.
* Remove old license settings class to avoid duplicate.
*/
$modules = array_diff( $modules, array( 'PLL_Settings_Licenses' ) );
if ( empty( $modules['licenses'] ) ) {
$modules['licenses'] = Settings::class;
}
return $modules;
}
/**
* Registers the licence in the Settings.
* Hooked to `pll_settings_licenses`.
*
* @since 1.0
*
* @param License[] $items Array of objects allowing to manage a license.
* @return License[]
*/
public function settings( $items ) {
$items[ $this->id ] = $this;
return $items;
}
/**
* Activates the license key.
*
* @since 1.0
*
* @param string $license_key Activation key.
* @return self Updated License object.
*/
public function activate_license(
#[\SensitiveParameter]
string $license_key
): self {
$this->license_key = $license_key;
$this->api_request( 'activate_license' );
// Tell WordPress to look for updates.
delete_site_transient( 'update_plugins' );
return $this;
}
/**
* Deactivates the license key.
*
* @since 1.0
*
* @return self Updated License object.
*/
public function deactivate_license(): self {
$this->api_request( 'deactivate_license' );
return $this;
}
/**
* Checks if the license key is valid.
* Hooked to `polylang_check_licenses`.
*
* @since 1.0
*
* @return void
*/
public function check_license(): void {
$this->api_request( 'check_license' );
}
/**
* Sends an API request to check, activate or deactivate the license.
* Updates the licenses option according to the status.
*
* @since 1.0
*
* @param string $request Type of request: check_license | activate_license | deactivate_license.
* @return void
*
* @phpstan-param 'check_license'|'activate_license'|'deactivate_license' $request
*/
private function api_request( string $request ): void {
$licenses = get_option( 'polylang_licenses' );
if ( is_array( $licenses ) ) {
unset( $licenses[ $this->id ] );
} else {
$licenses = array();
}
unset( $this->license_data );
if ( ! empty( $this->license_key ) ) {
// Data to send in our API request.
$api_params = array(
'edd_action' => $request,
'license' => $this->license_key,
'item_name' => rawurlencode( $this->name ),
'url' => home_url(),
);
// Call the API.
$response = wp_remote_post(
$this->api_url,
array(
'timeout' => 3,
'sslverify' => false,
'body' => $api_params,
)
);
// Update the option only if we got a response.
if ( is_wp_error( $response ) ) {
return;
}
// Save new license info.
$licenses[ $this->id ] = array( 'key' => $this->license_key );
$data = (object) json_decode( wp_remote_retrieve_body( $response ) );
if ( isset( $data->license ) && 'deactivated' !== $data->license ) {
$licenses[ $this->id ]['data'] = $data;
$this->license_data = $data;
}
}
update_option( 'polylang_licenses', $licenses ); // FIXME called multiple times when saving all licenses.
}
/**
* Returns the HTML form field in a table row (one per license key) for display.
*
* @since 1.0
*
* @return string
*/
public function get_form_field(): string {
if ( ! empty( $this->license_data ) ) {
$license = $this->license_data;
}
$atts = array(
'id' => $this->id,
'name' => $this->name,
'license_key' => $this->license_key,
'row_class' => 'license-null',
'button_text' => '',
'message' => '',
);
if ( ! empty( $license ) && is_object( $license ) ) {
$now = time();
$expiration = isset( $license->expires ) ? strtotime( $license->expires ) : false;
// Special case: the license expired after the last check.
if ( $license->success && $expiration && $expiration < $now ) {
$license->success = false;
$license->error = 'expired';
}
if ( false === $license->success ) {
$atts['row_class'] = 'notice-error notice-alt';
if ( empty( $license->error ) && ! empty( $license->license ) ) {
$license->error = $license->license;
}
switch ( $license->error ) {
case 'expired':
$atts['message'] = sprintf(
/* translators: %1$s is a date, %2$s is link start tag, %3$s is link end tag. */
__( 'Your license key expired on %1$s. Please %2$srenew your license key%3$s.', 'polylang-pro' ),
date_i18n( get_option( 'date_format' ), $expiration ),
sprintf( '<a href="%s" target="_blank">', self::ACCOUNT_URL ),
'</a>'
);
break;
case 'disabled':
case 'revoked':
$atts['message'] = __( 'Your license key has been disabled.', 'polylang-pro' );
break;
case 'missing':
$atts['message'] = sprintf(
/* translators: %1$s is link start tag, %2$s is link end tag. */
__( 'Invalid license. Please %1$svisit your account page%2$s and verify it.', 'polylang-pro' ),
sprintf( '<a href="%s" target="_blank">', self::ACCOUNT_URL ),
'</a>'
);
break;
case 'invalid':
case 'site_inactive':
$atts['message'] = sprintf(
/* translators: %1$s is a product name, %2$s is link start tag, %3$s is link end tag. */
__( '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-pro' ),
$this->name,
sprintf( '<a href="%s" target="_blank">', self::ACCOUNT_URL ),
'</a>'
);
break;
case 'item_name_mismatch':
/* translators: %s is a product name */
$atts['message'] = sprintf( __( 'This is not a %s license key.', 'polylang-pro' ), $this->name );
break;
case 'no_activations_left':
$atts['message'] = sprintf(
/* translators: %1$s is link start tag, %2$s is link end tag */
__( 'Your license key has reached its activation limit. %1$sView possible upgrades%2$s now.', 'polylang-pro' ),
sprintf( '<a href="%s" target="_blank">', self::ACCOUNT_URL ),
'</a>'
);
break;
}
} else {
$atts['row_class'] = 'license-valid';
$atts['button_text'] = __( 'Deactivate', 'polylang-pro' );
if ( 'lifetime' === $license->expires ) {
$atts['message'] = __( 'The license key never expires.', 'polylang-pro' );
} elseif ( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) {
$atts['row_class'] = 'notice-warning notice-alt';
$atts['message'] = sprintf(
/* translators: %1$s is a date, %2$s is link start tag, %3$s is link end tag. */
__( 'Your license key will expire soon! Precisely, it will expire on %1$s. %2$sRenew your license key today!%3$s', 'polylang-pro' ),
date_i18n( get_option( 'date_format' ), $expiration ),
sprintf( '<a href="%s" target="_blank">', self::ACCOUNT_URL ),
'</a>'
);
} else {
$atts['message'] = sprintf(
/* translators: %s is a date */
__( 'Your license key expires on %s.', 'polylang-pro' ),
date_i18n( get_option( 'date_format' ), $expiration )
);
}
}
}
ob_start();
include __DIR__ . '/views/view-field-row.php';
return (string) ob_get_clean();
}
}
@@ -0,0 +1,198 @@
<?php
/**
* @package Polylang Updater
*/
namespace WP_Syntex\Polylang_Pro\Updater;
use PLL_License;
use PLL_Settings;
use PLL_Settings_Module;
use WP_Ajax_Response;
use WP_Error;
defined( 'ABSPATH' ) || exit;
/**
* Settings class for licenses.
*
* @since 1.0
*/
class Settings extends PLL_Settings_Module {
use Common_Trait;
/**
* Name of the ajax action to get the licenses data.
*
* @since 1.0
*
* @var string
*/
const GET_LICENSES_DATA_ACTION = 'pllu_get_licenses_data';
/**
* Name of the action to create the nonce required to deactivate a license.
*
* @since 1.0
*
* @var string
*/
const DEACTIVATE_LICENSE_NONCE_ACTION = 'pll_options';
/**
* Stores the display order priority.
*
* @var int
*/
public $priority = 100;
/**
* Constructor.
*
* @since 1.0
*
* @param PLL_Settings $polylang Polylang object.
*/
public function __construct( PLL_Settings &$polylang ) {
parent::__construct(
$polylang,
array(
'module' => 'licenses',
'title' => __( 'License keys', 'polylang-pro' ),
'description' => __( 'Manage licenses for Polylang Pro and add-ons.', 'polylang-pro' ),
)
);
$this->buttons['cancel'] = sprintf( '<button type="button" class="button button-secondary cancel">%s</button>', __( 'Close', 'polylang-pro' ) );
$this->hooks();
/*
* Useless because replaced by the following hook, so let's remove it so it doesn't clutter
* the global `$wp_filter`.
*/
remove_action( 'wp_ajax_pll_save_options', array( $this, 'save_options' ) );
/*
* Before `PLL_Settings_Module::save_options()`, to ensure that our response to
* ajax action is executed and not the Polylang legacy licenses system.
*/
add_action( 'wp_ajax_pll_save_options', array( $this, 'save_options' ), 5 );
add_action( 'wp_ajax_' . self::GET_LICENSES_DATA_ACTION, array( $this, 'display_licenses' ) );
}
/**
* Tells if the module is active.
*
* @since 1.0
*
* @return bool
*/
public function is_active(): bool {
return ! empty( $this->get_licenses() );
}
/**
* Displays the settings form.
*
* @since 1.0
*/
protected function form(): void {
if ( ! $this->is_active() ) {
return;
}
$atts = array(
'action' => self::GET_LICENSES_DATA_ACTION,
'nonce' => wp_create_nonce( self::GET_LICENSES_DATA_ACTION ),
);
include __DIR__ . '/views/view-settings-licenses.php';
}
/**
* Ajax method to save the license keys and activate the licenses at the same time.
* Overrides the parent's method.
*
* @since 1.0
*
* @return void
*/
public function save_options(): void {
check_ajax_referer( 'pll_options', '_pll_nonce' );
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( -1 );
}
if ( ! isset( $_POST['module'] ) || $this->module !== $_POST['module'] || empty( $_POST['licenses'] ) ) {
return;
}
$response = new WP_Ajax_Response();
$what = 'success';
foreach ( $this->get_licenses() as $item ) {
if ( ! isset( $_POST['licenses'][ $item->id ] ) ) {
continue;
}
$updated_item = $item->activate_license( sanitize_key( $_POST['licenses'][ $item->id ] ) );
$response->Add(
array(
'what' => 'pllu-license-update',
'data' => $item->id,
'supplemental' => array( 'html' => $updated_item->get_form_field() ),
)
);
if ( empty( $updated_item->license_data->success ) ) {
$what = 'error';
}
}
// Updated message.
pll_add_notice( new WP_Error( 'settings_updated', __( 'Settings saved.', 'polylang-pro' ), 'success' ) );
ob_start();
settings_errors( 'polylang' );
$response->Add(
array(
'what' => $what,
'data' => (string) ob_get_clean(),
)
);
$response->send();
}
/**
* Ajax method to display licenses with their data (deactivation, expiration date).
* Hooked to `wp_ajax_pllu_get_licenses_data`.
*
* @since 1.0
*
* @return void
*
* @phpstan-return never
*/
public function display_licenses(): void {
check_ajax_referer( self::GET_LICENSES_DATA_ACTION, '_pll_nonce' );
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( -1 );
}
$rows = array();
foreach ( $this->get_licenses() as $license ) {
$license->check_license(); // Get the license information from the server to ensure it's up to date.
$rows[] = $license->get_form_field();
}
wp_send_json_success(
array(
'row' => $rows,
)
);
}
}
@@ -0,0 +1,250 @@
<?php
/**
* @package Polylang Updater
*/
namespace WP_Syntex\Polylang_Pro\Updater;
use DateTime;
use stdClass;
defined( 'ABSPATH' ) || exit;
/**
* Allows to download translations from TranslationsPress.
* This is a modified version of the library available at https://github.com/WP-Translations/t15s-registry.
* This version supports only WP Syntex's plugins.
*
* @since 1.0
*/
class Translations {
/**
* Transient key.
*
* @var string
*/
public const TRANSIENT_KEY = 't15s-polylang';
/**
* TranslationsPress API URL for the company.
*
* @var string
*/
private const API_URL = 'https://packages.translationspress.com/wp-syntex/packages.json';
/**
* Project directory slug.
*
* @var string
*/
private $slug;
/**
* Installed translations.
*
* @var array|null
*/
private static $installed_translations;
/**
* Available languages.
*
* @var array|null
*/
private static $available_languages;
/**
* Adds a new project to load translations for.
*
* @since 1.0
*
* @param string $slug Project directory slug.
*/
public function __construct( string $slug ) {
$this->slug = $slug;
add_action( 'init', array( self::class, 'register_clean_translations_cache' ), 9999 );
add_filter( 'translations_api', array( $this, 'translations_api' ), 10, 3 );
add_filter( 'site_transient_update_plugins', array( $this, 'site_transient_update_plugins' ) );
}
/**
* Short-circuits translations API requests for private projects.
* Hooked to `translations_api`.
*
* @since 1.0
*
* @param bool|array $result The result object. Default false.
* @param string $requested_type The type of translations being requested.
* @param object $args Translation API arguments.
* @return bool|array
*/
public function translations_api( $result, $requested_type, $args ) {
$args = (array) $args; // The type of this param ins not clear in WP (object|array|null).
if ( 'plugins' === $requested_type && $this->slug === $args['slug'] ) {
return self::get_translations( $args['slug'] );
}
return $result;
}
/**
* Filters the translations transients to include the private plugin.
* Hooked to `site_transient_update_plugins`.
*
* @see wp_get_translation_updates().
*
* @since 1.0
*
* @param stdClass|false $value The transient value.
* @return stdClass|false
*/
public function site_transient_update_plugins( $value ) {
if ( ! $value instanceof stdClass ) {
$value = new stdClass();
}
if ( ! isset( $value->translations ) ) {
$value->translations = array();
}
$translations = self::get_translations( $this->slug );
if ( ! isset( $translations['translations'] ) ) {
return $value;
}
$installed_translations = self::get_installed_translations();
foreach ( (array) $translations['translations'] as $translation ) {
if ( in_array( $translation['language'], self::get_available_languages(), true ) ) {
if ( isset( $installed_translations[ $this->slug ][ $translation['language'] ] ) && $translation['updated'] ) {
$local = new DateTime( $installed_translations[ $this->slug ][ $translation['language'] ]['PO-Revision-Date'] );
$remote = new DateTime( $translation['updated'] );
if ( $local >= $remote ) {
continue;
}
}
$translation['type'] = 'plugin';
$translation['slug'] = $this->slug;
$value->translations[] = $translation;
}
}
return $value;
}
/**
* Registers actions for clearing translation caches.
* Hooked to `init`.
*
* @since 1.0
*
* @return void
*/
public static function register_clean_translations_cache(): void {
add_action( 'set_site_transient_update_plugins', array( self::class, 'clean_translations_cache' ) );
add_action( 'delete_site_transient_update_plugins', array( self::class, 'clean_translations_cache' ) );
}
/**
* Clears existing translation cache.
*
* @since 1.0
*
* @return void
*/
public static function clean_translations_cache(): void {
$translations = get_site_transient( self::TRANSIENT_KEY );
if ( ! is_object( $translations ) ) {
return;
}
/*
* Don't delete the cache if the transient gets changed multiple times
* during a single request. Set cache lifetime to maximum 15 seconds.
*/
$cache_lifespan = 15;
$time_not_changed = isset( $translations->_last_checked ) && ( time() - $translations->_last_checked ) > $cache_lifespan;
if ( ! $time_not_changed ) {
return;
}
delete_site_transient( self::TRANSIENT_KEY );
}
/**
* Returns the translations for a given project.
*
* @since 1.0
*
* @param string $slug Project directory slug.
* @return array Translation data.
*/
private static function get_translations( string $slug ): array {
$translations = get_site_transient( self::TRANSIENT_KEY );
if ( ! $translations instanceof stdClass ) {
$translations = new stdClass();
}
if ( isset( $translations->{$slug} ) && is_array( $translations->{$slug} ) ) {
return $translations->{$slug};
}
$translations = json_decode( wp_remote_retrieve_body( wp_remote_get( self::API_URL, array( 'timeout' => 3 ) ) ), true );
if ( is_array( $translations ) ) {
$translations = (object) $translations;
} else {
$translations = new stdClass();
}
$translations->_last_checked = time();
set_site_transient( self::TRANSIENT_KEY, $translations );
if ( isset( $translations->{$slug} ) && is_array( $translations->{$slug} ) ) {
return $translations->{$slug};
}
return array();
}
/**
* Returns installed translations.
*
* Used to cache the result of `wp_get_installed_translations()` as it is very expensive.
*
* @since 1.0
*
* @return array
*/
private static function get_installed_translations(): array {
if ( null === self::$installed_translations ) {
self::$installed_translations = wp_get_installed_translations( 'plugins' );
}
return self::$installed_translations;
}
/**
* Returns available languages.
*
* Used to cache the result of `get_available_languages()` as it is very expensive.
*
* @since 1.0
*
* @return array
*/
private static function get_available_languages(): array {
if ( null === self::$available_languages ) {
self::$available_languages = (array) get_available_languages();
}
return self::$available_languages;
}
}
@@ -0,0 +1,83 @@
<?php
/**
* @package Polylang Updater
*/
namespace WP_Syntex\Polylang_Pro\Updater;
use PLL_Base;
defined( 'ABSPATH' ) || exit;
/**
* Updater's main object for the given project.
*
* @since 1.0
*/
class Updater {
/**
* @var License
*/
public $license;
/**
* @var Translations
*/
public $translations;
/**
* @var Wizard_Licenses_Step|null
*/
public $wizard_licenses_step;
/**
* Constructor.
*
* Must be instantiated before `pll_init`.
* Should be instantiated in admin context (`\PLL_Admin_Base`).
*
* @since 1.0
*
* @param string $file The plugin file.
* @param string $name The plugin name.
* @param string $version The plugin version.
* @param string $text_domain Text domain for translations.
*/
public function __construct( string $file, string $name, string $version, string $text_domain ) {
$this->license = new License( $file, $name, $version );
$this->translations = new Translations( $text_domain );
add_action( 'pll_init', array( $this, 'load_wizard' ) );
}
/**
* Loads the wizard's step.
*
* @since 1.0
*
* @param PLL_Base $polylang Polylang object.
* @return void
*/
public function load_wizard( $polylang ): void {
if ( ! empty( $polylang->wizard ) ) {
$this->wizard_licenses_step = new Wizard_Licenses_Step( $polylang->wizard );
}
}
/**
* Returns the updater version.
*
* @since 1.0
*
* @return string
*/
public static function get_version(): string {
// Cache the version to avoid reading the file multiple times.
static $version = null;
if ( null === $version ) {
$version = require __DIR__ . '/../version.php';
}
return $version;
}
}
@@ -0,0 +1,177 @@
<?php
/**
* @package Polylang Updater
*/
namespace WP_Syntex\Polylang_Pro\Updater;
use PLL_Wizard;
defined( 'ABSPATH' ) || exit;
/**
* A class to handle the wizard license step.
* Must be instantiated on `pll_init` or later (after `PLL_Wizard` is instantiated).
*
* @since 1.0
*
* @phpstan-type Steps array<
* string,
* array{
* name: string,
* view: callable,
* handler: callable,
* scripts: non-falsy-string[],
* styles: non-falsy-string[]
* }
* >
*/
class Wizard_Licenses_Step {
use Common_Trait;
/**
* Name of the action to create the nonce required to deactivate a license.
*
* @since 1.0
*
* @var string
*/
const DEACTIVATE_LICENSE_NONCE_ACTION = 'pll-wizard';
/**
* Instance of the wizard.
*
* @var PLL_Wizard
*/
private $wizard;
/**
* Constructor.
*
* @since 1.0
*
* @param PLL_Wizard $wizard Instance of the wizard.
*/
public function __construct( PLL_Wizard $wizard ) {
$this->wizard = $wizard;
add_filter( 'pll_wizard_steps', array( $this, 'add' ), 101 ); // After `PLL_Wizard::add_step_licenses()`, so this can override it.
}
/**
* Adds licenses step to the wizard.
*
* @since 1.0
*
* @param array $steps List of steps.
* @return array List of steps updated.
*
* @phpstan-param Steps $steps
* @phpstan-return Steps
*/
public function add( $steps ) {
if ( isset( $steps['licenses']['view'] ) && is_array( $steps['licenses']['view'] ) && isset( $steps['licenses']['view'][0] ) ) {
$first_step = $steps['licenses']['view'][0];
if ( $first_step instanceof self ) {
// No need to execute this several times.
return $steps;
}
if ( $first_step instanceof PLL_Wizard ) {
// Remove the old system, so we don't send 2 AJAX requests for the same action (deactivate license).
remove_action( 'wp_ajax_pll_deactivate_license', array( $first_step, 'deactivate_license' ) );
wp_dequeue_script( 'pll_settings' );
}
}
$this->hooks();
if ( ! empty( $this->get_licenses() ) ) {
$steps['licenses'] = array(
'name' => esc_html__( 'Licenses', 'polylang-pro' ),
'view' => array( $this, 'display' ),
'handler' => array( $this, 'save' ),
'scripts' => array( 'pll_license' ),
'styles' => array( 'pll_license' ),
);
}
return $steps;
}
/**
* Displays the languages step form.
*
* @since 1.0
*
* @return void
*/
public function display(): void {
$atts = array(
'license_rows' => array(),
'is_error' => isset( $_GET['activate_error'] ) && 'i18n_license_key_error' === sanitize_key( $_GET['activate_error'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended
);
foreach ( $this->get_licenses() as $license ) {
$atts['license_rows'][] = $license->get_form_field();
}
include __DIR__ . '/views/view-wizard-step-licenses.php';
}
/**
* Executes the languages step.
*
* @since 1.0
*
* @return void
*
* @phpstan-return never
*/
public function save(): void {
// User capabilities verified in `PLL_Wizard::setup_wizard_page()`.
check_admin_referer( 'pll-wizard', '_pll_nonce' );
$redirect = $this->wizard->get_next_step_link();
foreach ( $this->get_licenses() as $license ) {
if ( ! isset( $_POST['licenses'][ $license->id ] ) ) {
continue;
}
$updated_license = $license->activate_license( sanitize_key( $_POST['licenses'][ $license->id ] ) );
if ( empty( $updated_license->license_data ) || false !== $updated_license->license_data->success ) {
// Success.
continue;
}
// Stay on this step with an error.
$redirect = add_query_arg(
array(
'step' => $this->get_current_step(),
'activate_error' => 'i18n_license_key_error',
)
);
}
wp_safe_redirect( sanitize_url( $redirect ) );
exit;
}
/**
* Returns the current step.
*
* @since 1.0
* @see PLL_Wizard::setup_wizard_page()
*
* @return string
*/
private function get_current_step(): string {
/** This filter is documented in `PLL_Wizard::setup_wizard_page()`. */
$steps = apply_filters( 'pll_wizard_steps', array() );
$step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification
// @phpstan-var non-empty-array<string, array> $steps
// @phpstan-var string|false $step
return $step && array_key_exists( $step, $steps ) ? $step : key( $steps );
}
}
@@ -0,0 +1,51 @@
<?php
/**
* Displays a license field.
*
* Note: the name of the input is intentionally not prefixed to easily manage
* the Polylang legacy licenses system at the same time.
*
* @package Polylang Updater
*
* @since 1.0
*
* @var array $atts {
* @type string $id ID of the plugin.
* @type string $name Name of the plugin.
* @type string $license_key License key.
* @type string $row_class HTML class for the row.
* @type string $button_text Optional. Text for the deactivation button.
* @type string $message Optional. Message displayed under the field.
* }
*/
use WP_Syntex\Polylang_Pro\Updater\License;
defined( 'ABSPATH' ) || exit;
$tags = array(
'a' => array(
'href' => array(
'values' => array( License::ACCOUNT_URL ),
),
'target' => true,
),
);
?>
<tr id="pllu-license-<?php echo esc_attr( $atts['id'] ); ?>" class="<?php echo esc_attr( $atts['row_class'] ); ?>">
<td><label for="pllu-licenses[<?php echo esc_attr( $atts['id'] ); ?>]"><?php echo esc_html( $atts['name'] ); ?></label></td>
<td><input name="licenses[<?php echo esc_attr( $atts['id'] ); ?>]" id="pllu-licenses[<?php echo esc_attr( $atts['id'] ); ?>]" type="password" value="<?php echo esc_attr( $atts['license_key'] ); ?>" class="regular-text code" />
<?php
if ( ! empty( $atts['button_text'] ) ) {
?>
<button id="deactivate_<?php echo esc_attr( $atts['id'] ); ?>" type="button" class="button button-secondary pllu-deactivate-license"><?php echo esc_html( $atts['button_text'] ); ?></button>
<?php
}
if ( ! empty( $atts['message'] ) ) {
?>
<p><?php echo wp_kses( $atts['message'], $tags ); ?></p>
<?php
}
?>
</tr>
@@ -0,0 +1,18 @@
<?php
/**
* Displays the licenses table.
*
* @package Polylang Updater
*
* @since 1.0
*
* @var array $atts {
* @type string $action AJAX action.
* @type string $nonce AJAX nonce.
* }
*/
defined( 'ABSPATH' ) || exit;
?>
<table id="pllu-licenses-table" class="form-table pll-table-top" data-action="<?php echo esc_attr( $atts['action'] ); ?>" data-nonce="<?php echo esc_attr( $atts['nonce'] ); ?>"></table>
@@ -0,0 +1,37 @@
<?php
/**
* Displays the wizard licenses step.
*
* @package Polylang Updater
*
* @since 1.0
*
* @var array $atts {
* @type string[] $license_rows The license fields.
* @type bool $is_error Whether there is an error with a license key.
* }
*/
defined( 'ABSPATH' ) || exit;
?>
<p>
<?php esc_html_e( 'You are using plugins which require a license key.', 'polylang-pro' ); ?>
<?php echo esc_html( _n( 'Please enter your license key:', 'Please enter your license keys:', count( $atts['license_rows'] ), 'polylang-pro' ) ); ?>
</p>
<h2><?php esc_html_e( 'Licenses', 'polylang-pro' ); ?></h2>
<div id="messages">
<?php if ( $atts['is_error'] ) : ?>
<p class="error"><?php esc_html_e( 'There is an error with a license key.', 'polylang-pro' ); ?></p>
<?php endif; ?>
</div>
<div class="form-field">
<table id="pllu-licenses-table" class="form-table pll-table-top">
<tbody>
<?php
// Escaping is already done in get_form_field method.
echo implode( "\n", $atts['license_rows'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
</tbody>
</table>
</div>