first commit
This commit is contained in:
134
wp-content/plugins/polylang-pro/vendor/wpsyntex/polylang/install/install-base.php
vendored
Normal file
134
wp-content/plugins/polylang-pro/vendor/wpsyntex/polylang/install/install-base.php
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Polylang
|
||||
*/
|
||||
|
||||
/**
|
||||
* A generic activation / de-activation class compatible with multisite
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
class PLL_Install_Base {
|
||||
/**
|
||||
* The plugin basename.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $plugin_basename;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @param string $plugin_basename Plugin basename
|
||||
*/
|
||||
public function __construct( $plugin_basename ) {
|
||||
$this->plugin_basename = $plugin_basename;
|
||||
|
||||
// Manages plugin activation and deactivation
|
||||
register_activation_hook( $plugin_basename, array( $this, 'activate' ) );
|
||||
register_deactivation_hook( $plugin_basename, array( $this, 'deactivate' ) );
|
||||
|
||||
// Site creation on multisite.
|
||||
add_action( 'wp_initialize_site', array( $this, 'new_site' ), 50 ); // After WP (prio 10).
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to detect plugin deactivation
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @return bool true if the plugin is currently being deactivated
|
||||
*/
|
||||
public function is_deactivation() {
|
||||
return isset( $_GET['action'], $_GET['plugin'] ) && 'deactivate' === $_GET['action'] && $this->plugin_basename === $_GET['plugin']; // phpcs:ignore WordPress.Security.NonceVerification
|
||||
}
|
||||
|
||||
/**
|
||||
* Activation or deactivation for all blogs.
|
||||
*
|
||||
* @since 1.2
|
||||
*
|
||||
* @param string $what Either 'activate' or 'deactivate'.
|
||||
* @param bool $networkwide Whether the plugin is (de)activated for all sites in the network or just the current site.
|
||||
* @return void
|
||||
*/
|
||||
protected function do_for_all_blogs( $what, $networkwide ) {
|
||||
// Network
|
||||
if ( is_multisite() && $networkwide ) {
|
||||
global $wpdb;
|
||||
|
||||
foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ) as $blog_id ) {
|
||||
switch_to_blog( $blog_id );
|
||||
'activate' == $what ? $this->_activate() : $this->_deactivate();
|
||||
}
|
||||
restore_current_blog();
|
||||
}
|
||||
|
||||
// Single blog
|
||||
else {
|
||||
'activate' == $what ? $this->_activate() : $this->_deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin activation for multisite.
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @param bool $networkwide Whether the plugin is activated for all sites in the network or just the current site.
|
||||
* @return void
|
||||
*/
|
||||
public function activate( $networkwide ) {
|
||||
$this->do_for_all_blogs( 'activate', $networkwide );
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin activation
|
||||
*
|
||||
* @since 0.5
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _activate() {
|
||||
// Can be overridden in child class
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin deactivation for multisite.
|
||||
*
|
||||
* @since 0.1
|
||||
*
|
||||
* @param bool $networkwide Whether the plugin is deactivated for all sites in the network or just the current site.
|
||||
* @return void
|
||||
*/
|
||||
public function deactivate( $networkwide ) {
|
||||
$this->do_for_all_blogs( 'deactivate', $networkwide );
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin deactivation
|
||||
*
|
||||
* @since 0.5
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _deactivate() {
|
||||
// Can be overridden in child class
|
||||
}
|
||||
|
||||
/**
|
||||
* Site creation on multisite ( to set default options )
|
||||
*
|
||||
* @since 2.6.8
|
||||
*
|
||||
* @param WP_Site $new_site New site object.
|
||||
* @return void
|
||||
*/
|
||||
public function new_site( $new_site ) {
|
||||
switch_to_blog( $new_site->id );
|
||||
$this->_activate();
|
||||
restore_current_blog();
|
||||
}
|
||||
}
|
||||
148
wp-content/plugins/polylang-pro/vendor/wpsyntex/polylang/install/install.php
vendored
Normal file
148
wp-content/plugins/polylang-pro/vendor/wpsyntex/polylang/install/install.php
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Polylang
|
||||
*/
|
||||
|
||||
/**
|
||||
* Polylang activation / de-activation class
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
class PLL_Install extends PLL_Install_Base {
|
||||
|
||||
/**
|
||||
* Checks min PHP and WP version, displays a notice if a requirement is not met.
|
||||
*
|
||||
* @since 2.6.7
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function can_activate() {
|
||||
global $wp_version;
|
||||
|
||||
if ( version_compare( PHP_VERSION, PLL_MIN_PHP_VERSION, '<' ) ) {
|
||||
add_action( 'admin_notices', array( $this, 'php_version_notice' ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( version_compare( $wp_version, PLL_MIN_WP_VERSION, '<' ) ) {
|
||||
add_action( 'admin_notices', array( $this, 'wp_version_notice' ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a notice if PHP min version is not met.
|
||||
*
|
||||
* @since 2.6.7
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function php_version_notice() {
|
||||
load_plugin_textdomain( 'polylang' ); // Plugin i18n.
|
||||
|
||||
printf(
|
||||
'<div class="error"><p>%s</p></div>',
|
||||
sprintf(
|
||||
/* translators: 1: Plugin name 2: Current PHP version 3: Required PHP version */
|
||||
esc_html__( '%1$s has deactivated itself because you are using an old version of PHP. You are using using PHP %2$s. %1$s requires PHP %3$s.', 'polylang' ),
|
||||
esc_html( POLYLANG ),
|
||||
PHP_VERSION,
|
||||
esc_html( PLL_MIN_PHP_VERSION )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a notice if WP min version is not met.
|
||||
*
|
||||
* @since 2.6.7
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function wp_version_notice() {
|
||||
global $wp_version;
|
||||
|
||||
load_plugin_textdomain( 'polylang' ); // Plugin i18n.
|
||||
|
||||
printf(
|
||||
'<div class="error"><p>%s</p></div>',
|
||||
sprintf(
|
||||
/* translators: 1: Plugin name 2: Current WordPress version 3: Required WordPress version */
|
||||
esc_html__( '%1$s has deactivated itself because you are using an old version of WordPress. You are using using WordPress %2$s. %1$s requires at least WordPress %3$s.', 'polylang' ),
|
||||
esc_html( POLYLANG ),
|
||||
esc_html( $wp_version ),
|
||||
esc_html( PLL_MIN_WP_VERSION )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default Polylang options.
|
||||
*
|
||||
* @since 1.8
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_default_options() {
|
||||
return array(
|
||||
'browser' => 0, // Default language for the front page is not set by browser preference (was the opposite before 3.1).
|
||||
'rewrite' => 1, // Remove /language/ in permalinks (was the opposite before 0.7.2).
|
||||
'hide_default' => 1, // Remove URL language information for default language (was the opposite before 2.1.5).
|
||||
'force_lang' => 1, // Add URL language information (was 0 before 1.7).
|
||||
'redirect_lang' => 0, // Do not redirect the language page to the homepage.
|
||||
'media_support' => 0, // Do not support languages and translation for media by default (was the opposite before 3.1).
|
||||
'uninstall' => 0, // Do not remove data when uninstalling Polylang.
|
||||
'sync' => array(), // Synchronisation is disabled by default (was the opposite before 1.2).
|
||||
'post_types' => array(),
|
||||
'taxonomies' => array(),
|
||||
'domains' => array(),
|
||||
'version' => POLYLANG_VERSION,
|
||||
'first_activation' => time(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin activation
|
||||
*
|
||||
* @since 0.5
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _activate() {
|
||||
if ( $options = get_option( 'polylang' ) ) {
|
||||
// Check if we will be able to upgrade
|
||||
if ( version_compare( $options['version'], POLYLANG_VERSION, '<' ) ) {
|
||||
$upgrade = new PLL_Upgrade( $options );
|
||||
$upgrade->can_activate();
|
||||
}
|
||||
}
|
||||
// Defines default values for options in case this is the first installation
|
||||
else {
|
||||
update_option( 'polylang', self::get_default_options() );
|
||||
}
|
||||
|
||||
// Avoid 1 query on every pages if no wpml strings is registered
|
||||
if ( ! get_option( 'polylang_wpml_strings' ) ) {
|
||||
update_option( 'polylang_wpml_strings', array() );
|
||||
}
|
||||
|
||||
// Don't use flush_rewrite_rules at network activation. See #32471
|
||||
// Thanks to RavanH for the trick. See https://polylang.wordpress.com/2015/06/10/polylang-1-7-6-and-multisite/
|
||||
// Rewrite rules are created at next page load :)
|
||||
delete_option( 'rewrite_rules' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin deactivation
|
||||
*
|
||||
* @since 0.5
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _deactivate() {
|
||||
delete_option( 'rewrite_rules' ); // Don't use flush_rewrite_rules at network activation. See #32471
|
||||
}
|
||||
}
|
||||
645
wp-content/plugins/polylang-pro/vendor/wpsyntex/polylang/install/plugin-updater.php
vendored
Normal file
645
wp-content/plugins/polylang-pro/vendor/wpsyntex/polylang/install/plugin-updater.php
vendored
Normal file
@@ -0,0 +1,645 @@
|
||||
<?php
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows plugins to use their own update API.
|
||||
* Modified version with 'polylang' text domain and missing comments for translators.
|
||||
*
|
||||
* @author Easy Digital Downloads
|
||||
* @version 1.9.1
|
||||
*/
|
||||
class PLL_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( $_plugin_file, '.php' );
|
||||
$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 ) {
|
||||
|
||||
global $pagenow;
|
||||
|
||||
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_repo_api_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;
|
||||
|
||||
$this->set_version_info_cache( $version_info );
|
||||
}
|
||||
|
||||
return $version_info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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' ),
|
||||
esc_html( $plugin['Name'] )
|
||||
);
|
||||
|
||||
if ( ! current_user_can( 'update_plugins' ) ) {
|
||||
echo ' ';
|
||||
esc_html_e( 'Contact your network administrator to install the update.', 'polylang' );
|
||||
} 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' ),
|
||||
'<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' ),
|
||||
'<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' ),
|
||||
'</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 );
|
||||
|
||||
// Expires in 3 hours
|
||||
$this->set_version_info_cache( $api_response );
|
||||
|
||||
if ( false !== $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;
|
||||
}
|
||||
|
||||
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 successful, 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' ), esc_html__( 'Error', 'polylang' ), 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 ) );
|
||||
}
|
||||
|
||||
}
|
||||
237
wp-content/plugins/polylang-pro/vendor/wpsyntex/polylang/install/t15s.php
vendored
Normal file
237
wp-content/plugins/polylang-pro/vendor/wpsyntex/polylang/install/t15s.php
vendored
Normal file
@@ -0,0 +1,237 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Polylang
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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 aims to be compatible with PHP 5.2, and supports only plugins.
|
||||
*
|
||||
* @since 2.6
|
||||
*/
|
||||
class PLL_T15S {
|
||||
/**
|
||||
* Transient key
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const TRANSIENT_KEY_PLUGIN = 't15s-registry-plugins';
|
||||
|
||||
/**
|
||||
* Project directory slug
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $slug = '';
|
||||
|
||||
/**
|
||||
* Full GlotPress API URL for the project.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $api_url = '';
|
||||
|
||||
/**
|
||||
* 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 2.6
|
||||
*
|
||||
* @param string $slug Project directory slug.
|
||||
* @param string $api_url Full GlotPress API URL for the project.
|
||||
*/
|
||||
public function __construct( $slug, $api_url ) {
|
||||
$this->slug = $slug;
|
||||
$this->api_url = $api_url;
|
||||
|
||||
add_action( 'init', array( __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.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @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 ) {
|
||||
if ( 'plugins' === $requested_type && $this->slug === $args['slug'] ) {
|
||||
return self::get_translations( $args['slug'], $this->api_url );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the translations transients to include the private plugin or theme.
|
||||
*
|
||||
* @see wp_get_translation_updates()
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @param bool|array $value The transient value.
|
||||
* @return bool|array
|
||||
*/
|
||||
public function site_transient_update_plugins( $value ) {
|
||||
if ( ! $value ) {
|
||||
$value = new stdClass();
|
||||
}
|
||||
|
||||
if ( ! isset( $value->translations ) ) {
|
||||
$value->translations = array();
|
||||
}
|
||||
|
||||
$translations = self::get_translations( $this->slug, $this->api_url );
|
||||
|
||||
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() ) ) {
|
||||
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.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function register_clean_translations_cache() {
|
||||
add_action( 'set_site_transient_update_plugins', array( __CLASS__, 'clean_translations_cache' ) );
|
||||
add_action( 'delete_site_transient_update_plugins', array( __CLASS__, 'clean_translations_cache' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears existing translation cache.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function clean_translations_cache() {
|
||||
$translations = get_site_transient( self::TRANSIENT_KEY_PLUGIN );
|
||||
|
||||
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_PLUGIN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the translations for a given project.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @param string $slug Project directory slug.
|
||||
* @param string $url Full GlotPress API URL for the project.
|
||||
* @return array Translation data.
|
||||
*/
|
||||
private static function get_translations( $slug, $url ) {
|
||||
$translations = get_site_transient( self::TRANSIENT_KEY_PLUGIN );
|
||||
|
||||
if ( ! is_object( $translations ) ) {
|
||||
$translations = new stdClass();
|
||||
}
|
||||
|
||||
if ( isset( $translations->{$slug} ) && is_array( $translations->{$slug} ) ) {
|
||||
return $translations->{$slug};
|
||||
}
|
||||
|
||||
$result = json_decode( wp_remote_retrieve_body( wp_remote_get( $url, array( 'timeout' => 3 ) ) ), true );
|
||||
|
||||
// Nothing found.
|
||||
if ( ! is_array( $result ) ) {
|
||||
$result = array();
|
||||
}
|
||||
|
||||
$translations->{$slug} = $result;
|
||||
$translations->_last_checked = time();
|
||||
|
||||
set_site_transient( self::TRANSIENT_KEY_PLUGIN, $translations );
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns installed translations.
|
||||
*
|
||||
* Used to cache the result of wp_get_installed_translations() as it is very expensive.
|
||||
*
|
||||
* @since 2.8
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function get_installed_translations() {
|
||||
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 2.8
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function get_available_languages() {
|
||||
if ( null === self::$available_languages ) {
|
||||
self::$available_languages = get_available_languages();
|
||||
}
|
||||
return self::$available_languages;
|
||||
}
|
||||
}
|
||||
288
wp-content/plugins/polylang-pro/vendor/wpsyntex/polylang/install/upgrade.php
vendored
Normal file
288
wp-content/plugins/polylang-pro/vendor/wpsyntex/polylang/install/upgrade.php
vendored
Normal file
@@ -0,0 +1,288 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Polylang
|
||||
*/
|
||||
|
||||
/**
|
||||
* Manages Polylang upgrades
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
class PLL_Upgrade {
|
||||
/**
|
||||
* Stores the plugin options.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $options;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 1.2
|
||||
*
|
||||
* @param array $options Polylang options
|
||||
*/
|
||||
public function __construct( &$options ) {
|
||||
$this->options = &$options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if upgrade is possible otherwise die to avoid activation
|
||||
*
|
||||
* @since 1.2
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function can_activate() {
|
||||
if ( ! $this->can_upgrade() ) {
|
||||
ob_start();
|
||||
$this->admin_notices(); // FIXME the error message is displayed two times
|
||||
die( ob_get_contents() ); // phpcs:ignore WordPress.Security.EscapeOutput
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrades if possible otherwise returns false to stop Polylang loading
|
||||
*
|
||||
* @since 1.2
|
||||
*
|
||||
* @return bool true if upgrade is possible, false otherwise
|
||||
*/
|
||||
public function upgrade() {
|
||||
if ( ! $this->can_upgrade() ) {
|
||||
add_action( 'all_admin_notices', array( $this, 'admin_notices' ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
delete_transient( 'pll_languages_list' );
|
||||
add_action( 'admin_init', array( $this, '_upgrade' ) );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if we the previous version is not too old
|
||||
* Upgrades if OK
|
||||
* /!\ never start any upgrade before admin_init as it is likely to conflict with some other plugins
|
||||
*
|
||||
* @since 1.2
|
||||
*
|
||||
* @return bool true if upgrade is possible, false otherwise
|
||||
*/
|
||||
public function can_upgrade() {
|
||||
// Don't manage upgrade from version < 1.8
|
||||
return version_compare( $this->options['version'], '1.8', '>=' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a notice when ugrading from a too old version
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function admin_notices() {
|
||||
load_plugin_textdomain( 'polylang' );
|
||||
printf(
|
||||
'<div class="error"><p>%s</p><p>%s</p></div>',
|
||||
esc_html__( 'Polylang has been deactivated because you upgraded from a too old version.', 'polylang' ),
|
||||
sprintf(
|
||||
/* translators: %1$s and %2$s are Polylang version numbers */
|
||||
esc_html__( 'Before upgrading to %2$s, please upgrade to %1$s.', 'polylang' ),
|
||||
'<strong>2.9</strong>',
|
||||
POLYLANG_VERSION // phpcs:ignore WordPress.Security.EscapeOutput
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrades the plugin depending on the previous version
|
||||
*
|
||||
* @since 1.2
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function _upgrade() {
|
||||
foreach ( array( '2.0.8', '2.1', '2.7', '3.4' ) as $version ) {
|
||||
if ( version_compare( $this->options['version'], $version, '<' ) ) {
|
||||
$method_to_call = array( $this, 'upgrade_' . str_replace( '.', '_', $version ) );
|
||||
if ( is_callable( $method_to_call ) ) {
|
||||
call_user_func( $method_to_call );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->options['previous_version'] = $this->options['version']; // Remember the previous version of Polylang since v1.7.7
|
||||
$this->options['version'] = POLYLANG_VERSION;
|
||||
update_option( 'polylang', $this->options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrades if the previous version is < 2.0.8
|
||||
* Changes the user meta 'user_lang' to 'locale' to match WP 4.7 choice
|
||||
*
|
||||
* @since 2.0.8
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function upgrade_2_0_8() {
|
||||
global $wpdb;
|
||||
$wpdb->update( $wpdb->usermeta, array( 'meta_key' => 'locale' ), array( 'meta_key' => 'user_lang' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrades if the previous version is < 2.1.
|
||||
* Moves strings translations from polylang_mo post_content to post meta _pll_strings_translations.
|
||||
*
|
||||
* @since 2.1
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function upgrade_2_1() {
|
||||
$posts = get_posts(
|
||||
array(
|
||||
'post_type' => 'polylang_mo',
|
||||
'post_status' => 'any',
|
||||
'numberposts' => -1,
|
||||
'nopaging' => true,
|
||||
)
|
||||
);
|
||||
|
||||
if ( is_array( $posts ) ) {
|
||||
foreach ( $posts as $post ) {
|
||||
$meta = get_post_meta( $post->ID, '_pll_strings_translations', true );
|
||||
|
||||
if ( empty( $meta ) ) {
|
||||
$strings = maybe_unserialize( $post->post_content );
|
||||
if ( is_array( $strings ) ) {
|
||||
update_post_meta( $post->ID, '_pll_strings_translations', $strings );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrades if the previous version is < 2.7
|
||||
* Replace numeric keys by hashes in WPML registered strings
|
||||
* Dismiss the wizard notice for existing sites
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function upgrade_2_7() {
|
||||
$strings = get_option( 'polylang_wpml_strings' );
|
||||
if ( is_array( $strings ) ) {
|
||||
$new_strings = array();
|
||||
|
||||
foreach ( $strings as $string ) {
|
||||
$context = $string['context'];
|
||||
$name = $string['name'];
|
||||
|
||||
$key = md5( "$context | $name" );
|
||||
$new_strings[ $key ] = $string;
|
||||
}
|
||||
update_option( 'polylang_wpml_strings', $new_strings );
|
||||
}
|
||||
|
||||
PLL_Admin_Notices::dismiss( 'wizard' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrades if the previous version is < 3.4.0.
|
||||
*
|
||||
* @since 3.4
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function upgrade_3_4() {
|
||||
$this->migrate_locale_fallback_to_language_description();
|
||||
|
||||
$this->migrate_strings_translations();
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves strings translations from post meta to term meta _pll_strings_translations.
|
||||
*
|
||||
* @since 3.4
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function migrate_strings_translations() {
|
||||
$posts = get_posts(
|
||||
array(
|
||||
'post_type' => 'polylang_mo',
|
||||
'post_status' => 'any',
|
||||
'numberposts' => -1,
|
||||
'nopaging' => true,
|
||||
)
|
||||
);
|
||||
|
||||
if ( ! is_array( $posts ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $posts as $post ) {
|
||||
$meta = get_post_meta( $post->ID, '_pll_strings_translations', true );
|
||||
|
||||
$term_id = (int) substr( $post->post_title, 12 );
|
||||
|
||||
// Do not delete post metas in case a user needs to rollback to Polylang < 3.4.
|
||||
|
||||
if ( empty( $meta ) || ! is_array( $meta ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
update_term_meta( $term_id, '_pll_strings_translations', wp_slash( $meta ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate locale fallback to language term description.
|
||||
*
|
||||
* @since 3.4
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function migrate_locale_fallback_to_language_description() {
|
||||
// Migrate locale fallbacks from term metas to language term description.
|
||||
$terms = get_terms(
|
||||
array(
|
||||
'taxonomy' => 'language',
|
||||
'hide_empty' => false,
|
||||
'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
||||
array(
|
||||
'key' => 'fallback',
|
||||
'compare_key' => 'EXISTS',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
if ( ! is_array( $terms ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $terms as $term ) {
|
||||
$fallbacks = get_term_meta( $term->term_id, 'fallback', true );
|
||||
|
||||
delete_term_meta( $term->term_id, 'fallback' );
|
||||
|
||||
if ( empty( $fallbacks ) || ! is_array( $fallbacks ) ) {
|
||||
// Empty or invalid value, should not happen.
|
||||
continue;
|
||||
}
|
||||
|
||||
$description = maybe_unserialize( $term->description );
|
||||
$description = is_array( $description ) ? $description : array();
|
||||
|
||||
$description['fallbacks'] = $fallbacks;
|
||||
/** @var string */
|
||||
$description = maybe_serialize( $description );
|
||||
|
||||
wp_update_term( $term->term_id, 'language', array( 'description' => $description ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user