Polylang update

This commit is contained in:
Olivier Legat 2021-09-21 15:06:29 +02:00
parent 7f69f27260
commit 3593aeb242
487 changed files with 21758 additions and 8199 deletions

View file

@ -1,27 +1,70 @@
<?php
/**
* @package Polylang
*/
/**
* Base class for both admin
* Setup features available on all admin pages.
*
* @since 1.8
*/
class PLL_Admin_Base extends PLL_Base {
public $filter_lang, $curlang, $pref_lang;
abstract class PLL_Admin_Base extends PLL_Base {
/**
* Current language (used to filter the content).
*
* @var PLL_Language
*/
public $curlang;
/**
* Loads the polylang text domain
* Setups actions needed on all admin pages
* Language selected in the admin language filter.
*
* @var PLL_Language
*/
public $filter_lang;
/**
* Preferred language to assign to new contents.
*
* @var PLL_Language
*/
public $pref_lang;
/**
* @var PLL_Filters_Links
*/
public $filters_links;
/**
* @var PLL_Admin_Links
*/
public $links;
/**
* @var PLL_Admin_Notices
*/
public $notices;
/**
* @var PLL_Admin_Static_Pages
*/
public $static_pages;
/**
* @var PLL_Admin_Default_Term
*/
public $default_term;
/**
* Setups actions needed on all admin pages.
*
* @since 1.8
*
* @param object $links_model
* @param PLL_Links_Model $links_model Reference to the links model.
*/
public function __construct( &$links_model ) {
parent::__construct( $links_model );
// Plugin i18n, only needed for backend
load_plugin_textdomain( 'polylang', false, basename( POLYLANG_DIR ) . '/languages' );
// Adds the link to the languages panel in the WordPress admin menu
add_action( 'admin_menu', array( $this, 'add_menus' ) );
@ -29,10 +72,7 @@ class PLL_Admin_Base extends PLL_Base {
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
add_action( 'admin_print_footer_scripts', array( $this, 'admin_print_footer_scripts' ), 0 ); // High priority in case an ajax request is sent by an immediately invoked function
// Lingotek
if ( ! defined( 'POLYLANG_PRO' ) && ( ! defined( 'PLL_LINGOTEK_AD' ) || PLL_LINGOTEK_AD ) ) {
require_once POLYLANG_DIR . '/lingotek/lingotek.php';
}
add_action( 'customize_controls_enqueue_scripts', array( $this, 'customize_controls_enqueue_scripts' ) );
}
/**
@ -42,6 +82,10 @@ class PLL_Admin_Base extends PLL_Base {
* @since 1.2
*/
public function init() {
parent::init();
$this->notices = new PLL_Admin_Notices( $this );
if ( ! $this->model->get_languages_list() ) {
return;
}
@ -49,10 +93,12 @@ class PLL_Admin_Base extends PLL_Base {
$this->links = new PLL_Admin_Links( $this ); // FIXME needed here ?
$this->static_pages = new PLL_Admin_Static_Pages( $this ); // FIXME needed here ?
$this->filters_links = new PLL_Filters_Links( $this ); // FIXME needed here ?
$this->default_term = new PLL_Admin_Default_Term( $this );
$this->default_term->add_hooks();
// Filter admin language for users
// We must not call user info before WordPress defines user roles in wp-settings.php
add_filter( 'setup_theme', array( $this, 'init_user' ) );
add_action( 'setup_theme', array( $this, 'init_user' ) );
add_filter( 'request', array( $this, 'request' ) );
// Adds the languages in admin bar
@ -63,8 +109,12 @@ class PLL_Admin_Base extends PLL_Base {
* Adds the link to the languages panel in the WordPress admin menu
*
* @since 0.1
*
* @return void
*/
public function add_menus() {
global $admin_page_hooks;
// Prepare the list of tabs
$tabs = array( 'lang' => __( 'Languages', 'polylang' ) );
@ -84,11 +134,14 @@ class PLL_Admin_Base extends PLL_Base {
*/
$tabs = apply_filters( 'pll_settings_tabs', $tabs );
$parent = '';
foreach ( $tabs as $tab => $title ) {
$page = 'lang' === $tab ? 'mlang' : "mlang_$tab";
if ( empty( $parent ) ) {
$parent = $page;
add_menu_page( $title, __( 'Languages', 'polylang' ), 'manage_options', $page, null, 'dashicons-translation' );
add_menu_page( $title, __( 'Languages', 'polylang' ), 'manage_options', $page, '__return_null', 'dashicons-translation' );
$admin_page_hooks[ $page ] = 'languages'; // Hack to avoid the localization of the hook name. See: https://core.trac.wordpress.org/ticket/18857
}
add_submenu_page( $parent, $title, $title, 'manage_options', $page, array( $this, 'languages_page' ) );
@ -99,6 +152,8 @@ class PLL_Admin_Base extends PLL_Base {
* Setup js scripts & css styles ( only on the relevant pages )
*
* @since 0.6
*
* @return void
*/
public function admin_enqueue_scripts() {
$screen = get_current_screen();
@ -108,26 +163,83 @@ class PLL_Admin_Base extends PLL_Base {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
// For each script:
// 0 => the pages on which to load the script
// 1 => the scripts it needs to work
// 2 => 1 if loaded even if languages have not been defined yet, 0 otherwise
// 3 => 1 if loaded in footer
// FIXME: check if I can load more scripts in footer
/*
* For each script:
* 0 => the pages on which to load the script
* 1 => the scripts it needs to work
* 2 => 1 if loaded even if languages have not been defined yet, 0 otherwise
* 3 => 1 if loaded in footer
*/
$scripts = array(
'post' => array( array( 'post', 'media', 'async-upload', 'edit' ), array( 'jquery', 'wp-ajax-response', 'post', 'jquery-ui-autocomplete' ), 0, 0 ),
'media' => array( array( 'upload' ), array( 'jquery' ), 0, 1 ),
'term' => array( array( 'edit-tags', 'term' ), array( 'jquery', 'wp-ajax-response', 'jquery-ui-autocomplete' ), 0, 1 ),
'user' => array( array( 'profile', 'user-edit' ), array( 'jquery' ), 0, 0 ),
'user' => array( array( 'profile', 'user-edit' ), array( 'jquery' ), 0, 0 ),
'widgets' => array( array( 'widgets' ), array( 'jquery' ), 0, 0 ),
);
foreach ( $scripts as $script => $v ) {
if ( in_array( $screen->base, $v[0] ) && ( $v[2] || $this->model->get_languages_list() ) ) {
wp_enqueue_script( 'pll_' . $script, plugins_url( '/js/' . $script . $suffix . '.js', POLYLANG_FILE ), $v[1], POLYLANG_VERSION, $v[3] );
if ( ! empty( $screen->post_type ) && $this->model->is_translated_post_type( $screen->post_type ) ) {
$scripts['post'] = array( array( 'edit', 'upload' ), array( 'jquery', 'wp-ajax-response' ), 0, 1 );
// Classic editor.
if ( ! method_exists( $screen, 'is_block_editor' ) || ! $screen->is_block_editor() ) {
$scripts['classic-editor'] = array( array( 'post', 'media', 'async-upload' ), array( 'jquery', 'wp-ajax-response', 'post', 'jquery-ui-dialog', 'wp-i18n' ), 0, 1 );
}
// Block editor with legacy metabox in WP 5.0+.
if ( method_exists( $screen, 'is_block_editor' ) && $screen->is_block_editor() && ! pll_use_block_editor_plugin() ) {
$scripts['block-editor'] = array( array( 'post' ), array( 'jquery', 'wp-ajax-response', 'wp-api-fetch', 'jquery-ui-dialog', 'wp-i18n' ), 0, 1 );
}
}
wp_enqueue_style( 'polylang_admin', plugins_url( '/css/admin' . $suffix . '.css', POLYLANG_FILE ), array(), POLYLANG_VERSION );
if ( ! empty( $screen->taxonomy ) && $this->model->is_translated_taxonomy( $screen->taxonomy ) ) {
$scripts['term'] = array( array( 'edit-tags', 'term' ), array( 'jquery', 'wp-ajax-response', 'jquery-ui-autocomplete' ), 0, 1 );
}
foreach ( $scripts as $script => $v ) {
if ( in_array( $screen->base, $v[0] ) && ( $v[2] || $this->model->get_languages_list() ) ) {
wp_enqueue_script( 'pll_' . $script, plugins_url( '/js/build/' . $script . $suffix . '.js', POLYLANG_ROOT_FILE ), $v[1], POLYLANG_VERSION, $v[3] );
if ( 'classic-editor' === $script || 'block-editor' === $script ) {
wp_set_script_translations( 'pll_' . $script, 'polylang' );
}
}
}
wp_register_style( 'polylang_admin', plugins_url( '/css/build/admin' . $suffix . '.css', POLYLANG_ROOT_FILE ), array( 'wp-jquery-ui-dialog' ), POLYLANG_VERSION );
wp_enqueue_style( 'polylang_dialog', plugins_url( '/css/build/dialog' . $suffix . '.css', POLYLANG_ROOT_FILE ), array( 'polylang_admin' ), POLYLANG_VERSION );
$this->localize_scripts();
}
/**
* Enqueue scripts to the WP Customizer.
*
* @since 2.4.0
*
* @return void
*/
public function customize_controls_enqueue_scripts() {
if ( $this->model->get_languages_list() ) {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_script( 'pll_widgets', plugins_url( '/js/build/widgets' . $suffix . '.js', POLYLANG_ROOT_FILE ), array( 'jquery' ), POLYLANG_VERSION, true );
$this->localize_scripts();
}
}
/**
* Localize scripts.
*
* @since 2.4.0
*
* @return void
*/
public function localize_scripts() {
if ( wp_script_is( 'pll_widgets', 'enqueued' ) ) {
wp_localize_script(
'pll_widgets',
'pll_widgets',
array(
'flags' => wp_list_pluck( $this->model->get_languages_list(), 'flag', 'slug' ),
)
);
}
}
/**
@ -143,6 +255,8 @@ class PLL_Admin_Base extends PLL_Base {
* see: https://wordpress.org/support/topic/invalid-url-during-wordpress-new-dashboard-widget-operation
*
* @since 1.4
*
* @return void
*/
public function admin_print_footer_scripts() {
global $post_ID, $tag_ID;
@ -157,84 +271,108 @@ class PLL_Admin_Base extends PLL_Base {
}
$str = http_build_query( $params );
$arr = json_encode( $params );
?>
<script type="text/javascript">
if (typeof jQuery != 'undefined') {
(function($){
$.ajaxPrefilter(function (options, originalOptions, jqXHR) {
if ( -1 != options.url.indexOf( ajaxurl ) || -1 != ajaxurl.indexOf( options.url ) ) {
if ( 'undefined' === typeof options.data ) {
options.data = ( 'get' === options.type.toLowerCase() ) ? '<?php echo $str; ?>' : <?php echo $arr; ?>;
} else {
if ( 'string' === typeof options.data ) {
if ( '' === options.data && 'get' === options.type.toLowerCase() ) {
options.url = options.url+'&<?php echo $str; ?>';
} else {
try {
o = $.parseJSON(options.data);
o = $.extend(o, <?php echo $arr; ?>);
options.data = JSON.stringify(o);
$arr = wp_json_encode( $params );
?>
<script type="text/javascript">
if (typeof jQuery != 'undefined') {
jQuery(
function( $ ){
$.ajaxPrefilter( function ( options, originalOptions, jqXHR ) {
if ( -1 != options.url.indexOf( ajaxurl ) || -1 != ajaxurl.indexOf( options.url ) ) {
function addPolylangParametersAsString() {
if ( 'undefined' === typeof options.data || '' === options.data.trim() ) {
// Only Polylang data need to be send. So it could be as a simple query string.
options.data = '<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>';
} else {
/*
* In some cases data could be a JSON string like in third party plugins.
* So we need not to break their process by adding polylang parameters as valid JSON datas.
*/
try {
options.data = JSON.stringify( Object.assign( JSON.parse( options.data ), <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?> ) );
} catch( exception ) {
// Add Polylang data to the existing query string.
options.data = options.data + '&<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>';
}
}
}
catch(e) {
options.data = '<?php echo $str; ?>&'+options.data;
/*
* options.processData set to true is the default jQuery process where the data is converted in a query string by using jQuery.param().
* This step is done before applying filters. Thus here the options.data is already a string in this case.
* @See https://github.com/jquery/jquery/blob/3.5.1/src/ajax.js#L563-L569 jQuery ajax function.
* It is the most case WordPress send ajax request this way however third party plugins or themes could be send JSON string.
* Use JSON format is recommended in jQuery.param() documentation to be able to send complex data structures.
* @See https://api.jquery.com/jquery.param/ jQuery param function.
*/
if ( options.processData ) {
addPolylangParametersAsString();
} else {
/*
* If options.processData is set to false data could be undefined or pass as a string.
* So data as to be processed as if options.processData is set to true.
*/
if ( 'undefined' === typeof options.data || 'string' === typeof options.data ) {
addPolylangParametersAsString();
} else {
// Otherwise options.data is probably an object.
options.data = Object.assign( options.data || {} , <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?> );
}
}
}
} else {
options.data = $.extend(options.data, <?php echo $arr; ?>);
}
});
}
}
});
})(jQuery)
}
</script>
<?php
);
}
</script>
<?php
}
/**
* Sets the admin current language, used to filter the content
*
* @since 2.0
*
* @return void
*/
public function set_current_language() {
$this->curlang = $this->filter_lang;
// POST
if ( isset( $_POST['post_lang_choice'] ) && $lang = $this->model->get_language( $_POST['post_lang_choice'] ) ) {
$this->curlang = $lang;
} elseif ( isset( $_POST['term_lang_choice'] ) && $lang = $this->model->get_language( $_POST['term_lang_choice'] ) ) {
$this->curlang = $lang;
} elseif ( isset( $_POST['inline_lang_choice'] ) && $lang = $this->model->get_language( $_POST['inline_lang_choice'] ) ) {
$this->curlang = $lang;
}
// Edit Post
if ( isset( $_REQUEST['pll_post_id'] ) && $lang = $this->model->post->get_language( (int) $_REQUEST['pll_post_id'] ) ) {
if ( isset( $_REQUEST['pll_post_id'] ) && $lang = $this->model->post->get_language( (int) $_REQUEST['pll_post_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$this->curlang = $lang;
} elseif ( 'post.php' === $GLOBALS['pagenow'] && isset( $_GET['post'] ) && is_numeric( $_GET['post'] ) && $lang = $this->model->post->get_language( (int) $_GET['post'] ) ) {
} elseif ( 'post.php' === $GLOBALS['pagenow'] && isset( $_GET['post'] ) && $this->model->is_translated_post_type( get_post_type( (int) $_GET['post'] ) ) && $lang = $this->model->post->get_language( (int) $_GET['post'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$this->curlang = $lang;
} elseif ( 'post-new.php' === $GLOBALS['pagenow'] && ( empty( $_GET['post_type'] ) || $this->model->is_translated_post_type( $_GET['post_type'] ) ) ) {
$this->curlang = empty( $_GET['new_lang'] ) ? $this->pref_lang : $this->model->get_language( $_GET['new_lang'] );
} elseif ( 'post-new.php' === $GLOBALS['pagenow'] && ( empty( $_GET['post_type'] ) || $this->model->is_translated_post_type( sanitize_key( $_GET['post_type'] ) ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$this->curlang = empty( $_GET['new_lang'] ) ? $this->pref_lang : $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
}
// Edit Term
// FIXME 'edit-tags.php' for backward compatibility with WP < 4.5
elseif ( in_array( $GLOBALS['pagenow'], array( 'edit-tags.php', 'term.php' ) ) && isset( $_GET['tag_ID'] ) && $lang = $this->model->term->get_language( (int) $_GET['tag_ID'] ) ) {
elseif ( isset( $_REQUEST['pll_term_id'] ) && $lang = $this->model->term->get_language( (int) $_REQUEST['pll_term_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$this->curlang = $lang;
} elseif ( isset( $_REQUEST['pll_term_id'] ) && $lang = $this->model->term->get_language( (int) $_REQUEST['pll_term_id'] ) ) {
$this->curlang = $lang;
} elseif ( 'edit-tags.php' === $GLOBALS['pagenow'] && isset( $_GET['taxonomy'] ) && $this->model->is_translated_taxonomy( $_GET['taxonomy'] ) ) {
if ( ! empty( $_GET['new_lang'] ) ) {
$this->curlang = $this->model->get_language( $_GET['new_lang'] );
} elseif ( in_array( $GLOBALS['pagenow'], array( 'edit-tags.php', 'term.php' ) ) && isset( $_GET['taxonomy'] ) && $this->model->is_translated_taxonomy( sanitize_key( $_GET['taxonomy'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
if ( isset( $_GET['tag_ID'] ) && $lang = $this->model->term->get_language( (int) $_GET['tag_ID'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$this->curlang = $lang;
} elseif ( ! empty( $_GET['new_lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$this->curlang = $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
} elseif ( empty( $this->curlang ) ) {
$this->curlang = $this->pref_lang;
}
}
// Ajax
if ( wp_doing_ajax() && ! empty( $_REQUEST['lang'] ) ) {
$this->curlang = $this->model->get_language( $_REQUEST['lang'] );
if ( wp_doing_ajax() && ! empty( $_REQUEST['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$this->curlang = $this->model->get_language( sanitize_key( $_REQUEST['lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
}
// Inform that the admin language has been set.
if ( $this->curlang ) {
/** This action is documented in frontend/choose-lang.php */
do_action( 'pll_language_defined', $this->curlang->slug, $this->curlang );
} else {
/** This action is documented in include/class-polylang.php */
do_action( 'pll_no_language_defined' ); // To load overridden textdomains.
}
}
@ -242,18 +380,15 @@ class PLL_Admin_Base extends PLL_Base {
* Defines the backend language and the admin language filter based on user preferences
*
* @since 1.2.3
*
* @return void
*/
public function init_user() {
// Backend locale
// FIXME: Backward compatibility with WP < 4.7
if ( version_compare( $GLOBALS['wp_version'], '4.7alpha', '<' ) ) {
add_filter( 'locale', array( $this, 'get_locale' ) );
}
// Language for admin language filter: may be empty
// $_GET['lang'] is numeric when editing a language, not when selecting a new language in the filter
if ( ! wp_doing_ajax() && ! empty( $_GET['lang'] ) && ! is_numeric( $_GET['lang'] ) && current_user_can( 'edit_user', $user_id = get_current_user_id() ) ) {
update_user_meta( $user_id, 'pll_filter_content', ( $lang = $this->model->get_language( $_GET['lang'] ) ) ? $lang->slug : '' );
// We intentionally don't use a nonce to update the language filter
if ( ! wp_doing_ajax() && ! empty( $_GET['lang'] ) && ! is_numeric( sanitize_key( $_GET['lang'] ) ) && current_user_can( 'edit_user', $user_id = get_current_user_id() ) ) { // phpcs:ignore WordPress.Security.NonceVerification
update_user_meta( $user_id, 'pll_filter_content', ( $lang = $this->model->get_language( sanitize_key( $_GET['lang'] ) ) ) ? $lang->slug : '' ); // phpcs:ignore WordPress.Security.NonceVerification
}
$this->filter_lang = $this->model->get_language( get_user_meta( get_current_user_id(), 'pll_filter_content', true ) );
@ -262,38 +397,26 @@ class PLL_Admin_Base extends PLL_Base {
$this->pref_lang = empty( $this->filter_lang ) ? $this->model->get_language( $this->options['default_lang'] ) : $this->filter_lang;
/**
* Filter the preferred language on admin side
* The preferred language is used for example to determine the language of a new post
* Filters the preferred language on admin side.
* The preferred language is used for example to determine the language of a new post.
*
* @since 1.2.3
*
* @param object $pref_lang preferred language
* @param PLL_Language $pref_lang Preferred language.
*/
$this->pref_lang = apply_filters( 'pll_admin_preferred_language', $this->pref_lang );
$this->set_current_language();
// Inform that the admin language has been set
// Only if the admin language is one of the Polylang defined language
// FIXME test get_user_locale for backward compatibility with WP 4.7
if ( $curlang = $this->model->get_language( function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale() ) ) {
// FIXME: Backward compatibility with WP < 4.7
if ( version_compare( $GLOBALS['wp_version'], '4.7alpha', '<' ) ) {
$GLOBALS['text_direction'] = $curlang->is_rtl ? 'rtl' : 'ltr'; // force text direction according to language setting
}
/** This action is documented in frontend/choose-lang.php */
do_action( 'pll_language_defined', $curlang->slug, $curlang );
} else {
/** This action is documented in include/class-polylang.php */
do_action( 'pll_no_language_defined' ); // to load overridden textdomains
}
// Plugin i18n, only needed for backend.
load_plugin_textdomain( 'polylang' );
}
/**
* Avoids parsing a tax query when all languages are requested
* Fixes https://wordpress.org/support/topic/notice-undefined-offset-0-in-wp-includesqueryphp-on-line-3877 introduced in WP 4.1
* @see the suggestion of @boonebgorges, https://core.trac.wordpress.org/ticket/31246
*
* @see https://core.trac.wordpress.org/ticket/31246 the suggestion of @boonebgorges.
*
* @since 1.6.5
*
@ -309,24 +432,12 @@ class PLL_Admin_Base extends PLL_Base {
}
/**
* Get the locale based on user preference
* FIXME: Backward compatibility with WP < 4.7
*
* @since 0.4
*
* @param string $locale
* @return string modified locale
*/
public function get_locale( $locale ) {
return ( $loc = get_user_meta( get_current_user_id(), 'locale', 'true' ) ) ? $loc : $locale;
}
/**
* Adds the languages list in admin bar for the admin languages filter
* Adds the languages list in admin bar for the admin languages filter.
*
* @since 0.9
*
* @param object $wp_admin_bar
* @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar global object.
* @return void
*/
public function admin_bar_menu( $wp_admin_bar ) {
$all_item = (object) array(
@ -344,25 +455,46 @@ class PLL_Admin_Base extends PLL_Base {
esc_html( $selected->name )
);
$wp_admin_bar->add_menu( array(
'id' => 'languages',
'title' => $selected->flag . $title,
'href' => esc_url( add_query_arg( 'lang', $selected->slug, remove_query_arg( 'paged' ) ) ),
'meta' => array( 'title' => __( 'Filters content by language', 'polylang' ) ),
) );
/**
* Filters the admin languages filter submenu items
*
* @since 2.6
*
* @param array $items The admin languages filter submenu items.
*/
$items = apply_filters( 'pll_admin_languages_filter', array_merge( array( $all_item ), $this->model->get_languages_list() ) );
foreach ( array_merge( array( $all_item ), $this->model->get_languages_list() ) as $lang ) {
$menu = array(
'id' => 'languages',
'title' => $selected->flag . $title,
'href' => esc_url( add_query_arg( 'lang', $selected->slug, remove_query_arg( 'paged' ) ) ),
'meta' => array(
'title' => __( 'Filters content by language', 'polylang' ),
),
);
if ( 'all' !== $selected->slug ) {
$menu['meta']['class'] = 'pll-filtered-languages';
}
if ( ! empty( $items ) ) {
$wp_admin_bar->add_menu( $menu );
}
foreach ( $items as $lang ) {
if ( $selected->slug === $lang->slug ) {
continue;
}
$wp_admin_bar->add_menu( array(
'parent' => 'languages',
'id' => $lang->slug,
'title' => $lang->flag . esc_html( $lang->name ),
'href' => esc_url( add_query_arg( 'lang', $lang->slug, remove_query_arg( 'paged' ) ) ),
'meta' => 'all' === $lang->slug ? array() : array( 'lang' => esc_attr( $lang->get_locale( 'display' ) ) ),
) );
$wp_admin_bar->add_menu(
array(
'parent' => 'languages',
'id' => $lang->slug,
'title' => $lang->flag . esc_html( $lang->name ),
'href' => esc_url( add_query_arg( 'lang', $lang->slug, remove_query_arg( 'paged' ) ) ),
'meta' => 'all' === $lang->slug ? array() : array( 'lang' => esc_attr( $lang->get_locale( 'display' ) ) ),
)
);
}
}
}

View file

@ -0,0 +1,66 @@
<?php
/**
* @package Polylang
*/
/**
* Manages filters and actions related to the block editor
*
* @since 2.5
*/
class PLL_Admin_Block_Editor {
/**
* @var PLL_Model
*/
protected $model;
/**
* Preferred language to assign to a new post.
*
* @var PLL_Language
*/
protected $pref_lang;
/**
* Constructor: setups filters and actions
*
* @since 2.5
*
* @param object $polylang
*/
public function __construct( &$polylang ) {
$this->model = &$polylang->model;
$this->pref_lang = &$polylang->pref_lang;
new PLL_Block_Editor_Filter_Preload_Paths( array( $this, 'preload_paths' ), 10, 2 );
}
/**
* Filters the preload REST requests by the current language of the post.
* Necessary otherwise subsequent REST requests, all filtered by the language,
* would not hit the preloaded requests.
*
* @since 2.5
*
* @param (string|string[])[] $preload_paths Array of paths to preload.
* @param WP_Post $post The post resource data.
* @return (string|string[])[]
*/
public function preload_paths( $preload_paths, $post ) {
if ( $post instanceof WP_Post && $this->model->is_translated_post_type( $post->post_type ) ) {
$lang = $this->model->post->get_language( $post->ID );
if ( ! $lang ) {
$lang = $this->pref_lang;
}
foreach ( $preload_paths as $k => $path ) {
if ( is_string( $path ) && '/' !== $path ) {
$preload_paths[ $k ] = $path . "&lang={$lang->slug}";
}
}
}
return $preload_paths;
}
}

View file

@ -0,0 +1,362 @@
<?php
/**
* @package Polylang
*/
/**
* Manages filters and actions related to the classic editor
*
* @since 2.4
*/
class PLL_Admin_Classic_Editor {
/**
* @var PLL_Model
*/
public $model;
/**
* @var PLL_Admin_Links
*/
public $links;
/**
* Current language (used to filter the content).
*
* @var PLL_Language
*/
public $curlang;
/**
* Preferred language to assign to new contents.
*
* @var PLL_Language
*/
public $pref_lang;
/**
* Constructor: setups filters and actions
*
* @since 2.4
*
* @param object $polylang
*/
public function __construct( &$polylang ) {
$this->model = &$polylang->model;
$this->links = &$polylang->links;
$this->curlang = &$polylang->curlang;
$this->pref_lang = &$polylang->pref_lang;
// Adds the Languages box in the 'Edit Post' and 'Edit Page' panels
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
// Ajax response for changing the language in the post metabox
add_action( 'wp_ajax_post_lang_choice', array( $this, 'post_lang_choice' ) );
add_action( 'wp_ajax_pll_posts_not_translated', array( $this, 'ajax_posts_not_translated' ) );
// Filters the pages by language in the parent dropdown list in the page attributes metabox
add_filter( 'page_attributes_dropdown_pages_args', array( $this, 'page_attributes_dropdown_pages_args' ), 10, 2 );
// Notice
add_action( 'edit_form_top', array( $this, 'edit_form_top' ) );
}
/**
* Adds the Language box in the 'Edit Post' and 'Edit Page' panels ( as well as in custom post types panels )
*
* @since 0.1
*
* @param string $post_type Current post type
* @return void
*/
public function add_meta_boxes( $post_type ) {
if ( $this->model->is_translated_post_type( $post_type ) ) {
add_meta_box(
'ml_box',
__( 'Languages', 'polylang' ),
array( $this, 'post_language' ),
$post_type,
'side',
'high',
array(
'__back_compat_meta_box' => pll_use_block_editor_plugin(),
)
);
}
}
/**
* Displays the Languages metabox in the 'Edit Post' and 'Edit Page' panels
*
* @since 0.1
*
* @return void
*/
public function post_language() {
global $post_ID;
$post_type = get_post_type( $post_ID );
// phpcs:ignore WordPress.Security.NonceVerification, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$from_post_id = isset( $_GET['from_post'] ) ? (int) $_GET['from_post'] : 0;
$lang = ( $lg = $this->model->post->get_language( $post_ID ) ) ? $lg :
( isset( $_GET['new_lang'] ) ? $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification
$this->pref_lang );
$dropdown = new PLL_Walker_Dropdown();
$id = ( 'attachment' === $post_type ) ? sprintf( 'attachments[%d][language]', (int) $post_ID ) : 'post_lang_choice';
$dropdown_html = $dropdown->walk(
$this->model->get_languages_list(),
-1,
array(
'name' => $id,
'class' => 'post_lang_choice tags-input',
'selected' => $lang ? $lang->slug : '',
'flag' => true,
)
);
wp_nonce_field( 'pll_language', '_pll_nonce' );
// NOTE: the class "tags-input" allows to include the field in the autosave $_POST ( see autosave.js )
printf(
'<p><strong>%1$s</strong></p>
<label class="screen-reader-text" for="%2$s">%1$s</label>
<div id="select-%3$s-language">%4$s</div>',
esc_html__( 'Language', 'polylang' ),
esc_attr( $id ),
( 'attachment' === $post_type ? 'media' : 'post' ),
$dropdown_html // phpcs:ignore WordPress.Security.EscapeOutput
);
/**
* Fires before displaying the list of translations in the Languages metabox for posts
*
* @since 1.8
*/
do_action( 'pll_before_post_translations', $post_type );
echo '<div id="post-translations" class="translations">';
if ( $lang ) {
if ( 'attachment' === $post_type ) {
include __DIR__ . '/view-translations-media.php';
} else {
include __DIR__ . '/view-translations-post.php';
}
}
echo '</div>' . "\n";
}
/**
* Ajax response for changing the language in the post metabox
*
* @since 0.2
*
* @return void
*/
public function post_lang_choice() {
check_ajax_referer( 'pll_language', '_pll_nonce' );
if ( ! isset( $_POST['post_id'], $_POST['lang'], $_POST['post_type'] ) ) {
wp_die( 'The request is missing the parameter "post_type", "lang" and/or "post_id".' );
}
global $post_ID; // Obliged to use the global variable for wp_popular_terms_checklist
$post_ID = (int) $_POST['post_id'];
$lang_slug = sanitize_key( $_POST['lang'] );
$lang = $this->model->get_language( $lang_slug );
$post_type = sanitize_key( $_POST['post_type'] );
if ( empty( $lang ) ) {
wp_die( esc_html( "{$lang_slug} is not a valid language code." ) );
}
$post_type_object = get_post_type_object( $post_type );
if ( empty( $post_type_object ) ) {
wp_die( esc_html( "{$post_type} is not a valid post type." ) );
}
if ( ! current_user_can( $post_type_object->cap->edit_post, $post_ID ) ) {
wp_die( 'You are not allowed to edit this post.' );
}
$this->model->post->update_language( $post_ID, $lang );
ob_start();
if ( 'attachment' === $post_type ) {
include __DIR__ . '/view-translations-media.php';
} else {
include __DIR__ . '/view-translations-post.php';
}
$x = new WP_Ajax_Response( array( 'what' => 'translations', 'data' => ob_get_contents() ) );
ob_end_clean();
// Categories
if ( isset( $_POST['taxonomies'] ) ) { // Not set for pages
$supplemental = array();
foreach ( array_map( 'sanitize_key', $_POST['taxonomies'] ) as $taxname ) {
$taxonomy = get_taxonomy( $taxname );
if ( ! empty( $taxonomy ) ) {
ob_start();
$popular_ids = wp_popular_terms_checklist( $taxonomy->name );
$supplemental['populars'] = ob_get_contents();
ob_end_clean();
ob_start();
// Use $post_ID to remember checked terms in case we come back to the original language
wp_terms_checklist( $post_ID, array( 'taxonomy' => $taxonomy->name, 'popular_cats' => $popular_ids ) );
$supplemental['all'] = ob_get_contents();
ob_end_clean();
$supplemental['dropdown'] = wp_dropdown_categories(
array(
'taxonomy' => $taxonomy->name,
'hide_empty' => 0,
'name' => 'new' . $taxonomy->name . '_parent',
'orderby' => 'name',
'hierarchical' => 1,
'show_option_none' => '&mdash; ' . $taxonomy->labels->parent_item . ' &mdash;',
'echo' => 0,
)
);
$x->Add( array( 'what' => 'taxonomy', 'data' => $taxonomy->name, 'supplemental' => $supplemental ) );
}
}
}
// Parent dropdown list ( only for hierarchical post types )
if ( in_array( $post_type, get_post_types( array( 'hierarchical' => true ) ) ) ) {
$post = get_post( $post_ID );
if ( ! empty( $post ) ) {
// Args and filter from 'page_attributes_meta_box' in wp-admin/includes/meta-boxes.php of WP 4.2.1
$dropdown_args = array(
'post_type' => $post->post_type,
'exclude_tree' => $post->ID,
'selected' => $post->post_parent,
'name' => 'parent_id',
'show_option_none' => __( '(no parent)', 'polylang' ),
'sort_column' => 'menu_order, post_title',
'echo' => 0,
);
/** This filter is documented in wp-admin/includes/meta-boxes.php */
$dropdown_args = apply_filters( 'page_attributes_dropdown_pages_args', $dropdown_args, $post ); // Since WP 3.3
$x->Add( array( 'what' => 'pages', 'data' => wp_dropdown_pages( $dropdown_args ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput
}
}
// Flag
$x->Add( array( 'what' => 'flag', 'data' => empty( $lang->flag ) ? esc_html( $lang->slug ) : $lang->flag ) );
// Sample permalink
$x->Add( array( 'what' => 'permalink', 'data' => get_sample_permalink_html( $post_ID ) ) );
$x->send();
}
/**
* Ajax response for input in translation autocomplete input box
*
* @since 1.5
*
* @return void
*/
public function ajax_posts_not_translated() {
check_ajax_referer( 'pll_language', '_pll_nonce' );
if ( ! isset( $_GET['post_type'], $_GET['post_language'], $_GET['translation_language'], $_GET['term'], $_GET['pll_post_id'] ) ) {
wp_die( 0 );
}
$post_type = sanitize_key( $_GET['post_type'] );
if ( ! post_type_exists( $post_type ) ) {
wp_die( 0 );
}
$term = wp_unslash( $_GET['term'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
$post_language = $this->model->get_language( sanitize_key( $_GET['post_language'] ) );
$translation_language = $this->model->get_language( sanitize_key( $_GET['translation_language'] ) );
$return = array();
$untranslated_posts = $this->model->post->get_untranslated( $post_type, $post_language, $translation_language, $term );
// format output
foreach ( $untranslated_posts as $post ) {
$return[] = array(
'id' => $post->ID,
'value' => $post->post_title,
'link' => $this->links->edit_post_translation_link( $post->ID ),
);
}
// Add current translation in list
if ( $post_id = $this->model->post->get_translation( (int) $_GET['pll_post_id'], $translation_language ) ) {
$post = get_post( $post_id );
if ( ! empty( $post ) ) {
array_unshift(
$return,
array(
'id' => $post_id,
'value' => $post->post_title,
'link' => $this->links->edit_post_translation_link( $post_id ),
)
);
}
}
wp_die( wp_json_encode( $return ) );
}
/**
* Filters the pages by language in the parent dropdown list in the page attributes metabox.
*
* @since 0.6
*
* @param array $dropdown_args Arguments passed to wp_dropdown_pages().
* @param WP_Post $post The page being edited.
* @return array Modified arguments.
*/
public function page_attributes_dropdown_pages_args( $dropdown_args, $post ) {
$dropdown_args['lang'] = isset( $_POST['lang'] ) ? $this->model->get_language( sanitize_key( $_POST['lang'] ) ) : $this->model->post->get_language( $post->ID ); // phpcs:ignore WordPress.Security.NonceVerification
if ( ! $dropdown_args['lang'] ) {
$dropdown_args['lang'] = $this->pref_lang;
}
return $dropdown_args;
}
/**
* Displays a notice if the user has not sufficient rights to overwrite synchronized taxonomies and metas.
*
* @since 2.6
*
* @param WP_Post $post the post currently being edited.
* @return void
*/
public function edit_form_top( $post ) {
if ( ! $this->model->post->current_user_can_synchronize( $post->ID ) ) {
?>
<div class="pll-notice notice notice-warning">
<p>
<?php
esc_html_e( 'Some taxonomies or metadata may be synchronized with existing translations that you are not allowed to modify.', 'polylang' );
echo ' ';
esc_html_e( 'If you attempt to modify them anyway, your changes will not be saved.', 'polylang' );
?>
</p>
</div>
<?php
}
}
}

View file

@ -0,0 +1,268 @@
<?php
/**
* @package Polylang
*/
/**
* Manages filters and actions related to default terms.
*
* @since 3.1
*/
class PLL_Admin_Default_Term {
/**
* A reference to the PLL_Model instance.
*
* @var PLL_Model
*/
protected $model;
/**
* Preferred language to assign to new contents.
*
* @var PLL_Language
*/
protected $pref_lang;
/**
* Reference to Polylang options array
*
* @var array
*/
protected $options;
/**
* Array of registered taxonomy names for which Polylang manages languages and translations.
*
* @var string[]
*/
protected $taxonomies;
/**
* Constructor: setups properties.
*
* @since 3.1
*
* @param object $polylang
*/
public function __construct( &$polylang ) {
$this->model = &$polylang->model;
$this->pref_lang = &$polylang->pref_lang;
$this->options = &$polylang->options;
$this->taxonomies = $this->model->get_translated_taxonomies();
}
/**
* Setups filters and actions needed.
*
* @since 3.1
*
* @return void
*/
public function add_hooks() {
foreach ( $this->taxonomies as $taxonomy ) {
if ( 'category' === $taxonomy ) {
// Allows to get the default terms in all languages
add_filter( 'option_default_' . $taxonomy, array( $this, 'option_default_term' ) );
add_action( 'update_option_default_' . $taxonomy, array( $this, 'update_option_default_term' ), 10, 2 );
// Adds the language column in the 'Terms' table.
add_filter( 'manage_' . $taxonomy . '_custom_column', array( $this, 'term_column' ), 10, 3 );
}
}
add_action( 'pll_add_language', array( $this, 'handle_default_term_on_create_language' ) );
// The default term should be in the default language
add_action( 'pll_update_default_lang', array( $this, 'update_default_term_language' ) );
// Prevents deleting all the translations of the default term
add_filter( 'map_meta_cap', array( $this, 'fix_delete_default_term' ), 10, 4 );
}
/**
* Filters the default term in note below the term list table and in settings->writing dropdown
*
* @since 1.2
*
* @param int $taxonomy_term_id The taxonomy term id.
* @return int A taxonomy term id.
*/
public function option_default_term( $taxonomy_term_id ) {
if ( isset( $this->pref_lang ) && $tr = $this->model->term->get( $taxonomy_term_id, $this->pref_lang ) ) {
$taxonomy_term_id = $tr;
}
return $taxonomy_term_id;
}
/**
* Checks if the new default term is translated in all languages
* If not, create the translations
*
* @since 1.7
*
* @param int $old_value The old option value.
* @param int $value The new option value.
* @return void
*/
public function update_option_default_term( $old_value, $value ) {
$default_cat_lang = $this->model->term->get_language( $value );
// Assign a default language to default term
if ( ! $default_cat_lang ) {
$default_cat_lang = $this->model->get_language( $this->options['default_lang'] );
$this->model->term->set_language( (int) $value, $default_cat_lang );
}
$taxonomy = substr( current_filter(), 22 );
foreach ( $this->model->get_languages_list() as $language ) {
if ( $language->slug != $default_cat_lang->slug && ! $this->model->term->get_translation( $value, $language ) ) {
$this->create_default_term( $language, $taxonomy );
}
}
}
/**
* Create a default term for a language
*
* @since 1.2
*
* @param object|string|int $lang language
* @param string $taxonomy The current taxonomy
* @return void
*/
public function create_default_term( $lang, $taxonomy ) {
$lang = $this->model->get_language( $lang );
// create a new term
// FIXME this is translated in admin language when we would like it in $lang
$cat_name = __( 'Uncategorized', 'polylang' );
$cat_slug = sanitize_title( $cat_name . '-' . $lang->slug );
$cat = wp_insert_term( $cat_name, $taxonomy, array( 'slug' => $cat_slug ) );
// check that the term was not previously created ( in case the language was deleted and recreated )
$cat = isset( $cat->error_data['term_exists'] ) ? $cat->error_data['term_exists'] : $cat['term_id'];
// set language
$this->model->term->set_language( (int) $cat, $lang );
// this is a translation of the default term
$default = (int) get_option( 'default_' . $taxonomy );
$translations = $this->model->term->get_translations( $default );
$this->model->term->save_translations( (int) $cat, $translations );
}
/**
* Manages the default term when new languages are created.
*
* @since 3.1
*
* @param array $args Argument used to create the language. @see PLL_Admin_Model::add_language().
* @return void
*/
public function handle_default_term_on_create_language( $args ) {
foreach ( $this->taxonomies as $taxonomy ) {
if ( 'category' === $taxonomy ) {
$default = (int) get_option( 'default_' . $taxonomy );
// Assign default language to default term
if ( ! $this->model->term->get_language( $default ) ) {
$this->model->term->set_language( $default, $args['slug'] );
} elseif ( empty( $args['no_default_cat'] ) && ! $this->model->term->get( $default, $args['slug'] ) ) {
$this->create_default_term( $args['slug'], $taxonomy );
}
}
}
}
/**
* Identify the default term in the terms list table to disable the language dropdown in js.
*
* @since 3.1
*
* @param string $out The output.
* @param string $column The custom column's name.
* @param int $term_id The term id.
* @return string The HTML string.
*/
public function term_column( $out, $column, $term_id ) {
if ( $column === $this->get_first_language_column() && $this->is_default_term( $term_id ) ) {
$out .= sprintf( '<div class="hidden" id="default_cat_%1$d">%1$d</div>', intval( $term_id ) );
}
return $out;
}
/**
* Returns the first language column in the posts, pages and media library tables
*
* @since 0.9
*
* @return string first language column name
*/
protected function get_first_language_column() {
$columns = array();
foreach ( $this->model->get_languages_list() as $language ) {
$columns[] = 'language_' . $language->slug;
}
return empty( $columns ) ? '' : reset( $columns );
}
/**
* Prevents deleting all the translations of the default term
*
* @since 2.1
*
* @param array $caps The user's actual capabilities.
* @param string $cap Capability name.
* @param int $user_id The user ID.
* @param array $args Adds the context to the cap. The term id.
* @return array
*/
public function fix_delete_default_term( $caps, $cap, $user_id, $args ) {
if ( 'delete_term' === $cap && $this->is_default_term( reset( $args ) ) ) {
$caps[] = 'do_not_allow';
}
return $caps;
}
/**
* Check if the term is the default term.
*
* @since 3.1
*
* @param int $term_id The term id.
* @return bool True if the term is the default term, false otherwise.
*/
public function is_default_term( $term_id ) {
$term = get_term( $term_id );
if ( $term instanceof WP_Term ) {
$default_term_id = get_option( 'default_' . $term->taxonomy );
return $default_term_id && in_array( $default_term_id, $this->model->term->get_translations( $term_id ) );
}
return false;
}
/**
* Updates the default term language.
*
* @since 3.1
*
* @param string $slug Language slug.
* @return void
*/
public function update_default_term_language( $slug ) {
foreach ( $this->taxonomies as $taxonomy ) {
if ( 'category' === $taxonomy ) {
$default_cats = $this->model->term->get_translations( get_option( 'default_' . $taxonomy ) );
if ( isset( $default_cats[ $slug ] ) ) {
update_option( 'default_' . $taxonomy, $default_cats[ $slug ] );
}
}
}
}
}

View file

@ -1,16 +1,34 @@
<?php
/**
* @package Polylang
*/
/**
* adds the language column in posts and terms list tables
* manages quick edit and bulk edit as well
* Adds the language column in posts and terms list tables
* Manages quick edit and bulk edit as well
*
* @since 1.2
*/
class PLL_Admin_Filters_Columns {
public $links, $model, $filter_lang;
/**
* @var PLL_Model
*/
public $model;
/**
* constructor: setups filters and actions
* @var PLL_Admin_Links
*/
public $links;
/**
* Language selected in the admin language filter.
*
* @var PLL_Language
*/
public $filter_lang;
/**
* Constructor: setups filters and actions
*
* @since 1.2
*
@ -21,37 +39,40 @@ class PLL_Admin_Filters_Columns {
$this->model = &$polylang->model;
$this->filter_lang = &$polylang->filter_lang;
// add the language and translations columns in 'All Posts', 'All Pages' and 'Media library' panels
// Hide the column of the filtered language.
add_filter( 'hidden_columns', array( $this, 'hidden_columns' ) ); // Since WP 4.4.
// Add the language and translations columns in 'All Posts', 'All Pages' and 'Media library' panels.
foreach ( $this->model->get_translated_post_types() as $type ) {
// use the latest filter late as some plugins purely overwrite what's done by others :(
// specific case for media
// Use the latest filter late as some plugins purely overwrite what's done by others :(
// Specific case for media.
add_filter( 'manage_' . ( 'attachment' == $type ? 'upload' : 'edit-' . $type ) . '_columns', array( $this, 'add_post_column' ), 100 );
add_action( 'manage_' . ( 'attachment' == $type ? 'media' : $type . '_posts' ) . '_custom_column', array( $this, 'post_column' ), 10, 2 );
}
// quick edit and bulk edit
add_filter( 'quick_edit_custom_box', array( $this, 'quick_edit_custom_box' ), 10, 2 );
add_filter( 'bulk_edit_custom_box', array( $this, 'quick_edit_custom_box' ), 10, 2 );
// Quick edit and bulk edit.
add_filter( 'quick_edit_custom_box', array( $this, 'quick_edit_custom_box' ) );
add_filter( 'bulk_edit_custom_box', array( $this, 'quick_edit_custom_box' ) );
// adds the language column in the 'Categories' and 'Post Tags' tables
// Adds the language column in the 'Categories' and 'Post Tags' tables.
foreach ( $this->model->get_translated_taxonomies() as $tax ) {
add_filter( 'manage_edit-' . $tax . '_columns', array( $this, 'add_term_column' ) );
add_filter( 'manage_' . $tax . '_custom_column', array( $this, 'term_column' ), 10, 3 );
}
// ajax responses to update list table rows
// Ajax responses to update list table rows.
add_action( 'wp_ajax_pll_update_post_rows', array( $this, 'ajax_update_post_rows' ) );
add_action( 'wp_ajax_pll_update_term_rows', array( $this, 'ajax_update_term_rows' ) );
}
/**
* adds languages and translations columns in posts, pages, media, categories and tags tables
* Adds languages and translations columns in posts, pages, media, categories and tags tables.
*
* @since 0.8.2
*
* @param array $columns List of table columns
* @param string $before The column before which we want to add our languages
* @return array modified list of columns
* @param string[] $columns List of table columns.
* @param string $before The column before which we want to add our languages.
* @return string[] Modified list of columns.
*/
protected function add_column( $columns, $before ) {
if ( $n = array_search( $before, array_keys( $columns ) ) ) {
@ -60,56 +81,69 @@ class PLL_Admin_Filters_Columns {
}
foreach ( $this->model->get_languages_list() as $language ) {
// don't add the column for the filtered language
if ( empty( $this->filter_lang ) || $language->slug != $this->filter_lang->slug ) {
$columns[ 'language_' . $language->slug ] = $language->flag ? $language->flag . '<span class="screen-reader-text">' . esc_html( $language->name ) . '</span>' : esc_html( $language->slug );
}
$columns[ 'language_' . $language->slug ] = $this->get_flag_html( $language ) . '<span class="screen-reader-text">' . esc_html( $language->name ) . '</span>';
}
return isset( $end ) ? array_merge( $columns, $end ) : $columns;
}
/**
* returns the first language column in the posts, pages and media library tables
* Returns the first language column in the posts, pages and media library tables
*
* @since 0.9
*
* @return string first language column name
*/
protected function get_first_language_column() {
$columns = array();
foreach ( $this->model->get_languages_list() as $language ) {
if ( empty( $this->filter_lang ) || $language->slug != $this->filter_lang->slug ) {
$columns[] = 'language_' . $language->slug;
}
$columns[] = 'language_' . $language->slug;
}
return empty( $columns ) ? '' : reset( $columns );
}
/**
* adds the language and translations columns ( before the comments column ) in the posts, pages and media library tables
* Hides the column for the filtered language.
*
* @since 2.7
*
* @param string[] $hidden Array of hidden columns.
* @return string[]
*/
public function hidden_columns( $hidden ) {
if ( ! empty( $this->filter_lang ) ) {
$hidden[] = 'language_' . $this->filter_lang->slug;
}
return $hidden;
}
/**
* Adds the language and translations columns ( before the comments column ) in the posts, pages and media library tables.
*
* @since 0.1
*
* @param array $columns list of posts table columns
* @return array modified list of columns
* @param string[] $columns List of posts table columns.
* @return string[] Modified list of columns.
*/
function add_post_column( $columns ) {
public function add_post_column( $columns ) {
return $this->add_column( $columns, 'comments' );
}
/**
* fills the language and translations columns in the posts, pages and media library tables
* Fills the language and translations columns in the posts, pages and media library tables
* take care that when doing ajax inline edit, the post may not be updated in database yet
*
* @since 0.1
*
* @param string $column Column name
* @param int $post_id
* @return void
*/
public function post_column( $column, $post_id ) {
$inline = wp_doing_ajax() && isset( $_REQUEST['action'], $_POST['inline_lang_choice'] ) && 'inline-save' === $_REQUEST['action'];
$lang = $inline ? $this->model->get_language( $_POST['inline_lang_choice'] ) : $this->model->post->get_language( $post_id );
$inline = wp_doing_ajax() && isset( $_REQUEST['action'], $_POST['inline_lang_choice'] ) && 'inline-save' === $_REQUEST['action']; // phpcs:ignore WordPress.Security.NonceVerification
$lang = $inline ? $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) ) : $this->model->post->get_language( $post_id ); // phpcs:ignore WordPress.Security.NonceVerification
if ( false === strpos( $column, 'language_' ) || ! $lang ) {
return;
@ -117,20 +151,24 @@ class PLL_Admin_Filters_Columns {
$language = $this->model->get_language( substr( $column, 9 ) );
// hidden field containing the post language for quick edit
if ( empty( $language ) ) {
return;
}
// Hidden field containing the post language for quick edit
if ( $column == $this->get_first_language_column() ) {
printf( '<div class="hidden" id="lang_%d">%s</div>', intval( $post_id ), esc_html( $lang->slug ) );
}
$post_type_object = get_post_type_object( get_post_type( $post_id ) );
// link to edit post ( or a translation )
// Link to edit post ( or a translation )
if ( $id = $this->model->post->get( $post_id, $language ) ) {
// get_edit_post_link returns nothing if the user cannot edit the post
// thanks to Solinx. See http://wordpress.org/support/topic/feature-request-incl-code-check-for-capabilities-in-admin-screens
// Thanks to Solinx. See http://wordpress.org/support/topic/feature-request-incl-code-check-for-capabilities-in-admin-screens
if ( $link = get_edit_post_link( $id ) ) {
$flag = '';
if ( $id === $post_id ) {
$class = 'pll_icon_tick';
$flag = $this->get_flag_html( $language );
$class = 'pll_column_flag';
/* translators: accessibility text, %s is a native language name */
$s = sprintf( __( 'Edit this item in %s', 'polylang' ), $language->name );
} else {
@ -138,43 +176,52 @@ class PLL_Admin_Filters_Columns {
/* translators: accessibility text, %s is a native language name */
$s = sprintf( __( 'Edit the translation in %s', 'polylang' ), $language->name );
}
printf(
'<a class="%1$s" title="%2$s" href="%3$s"><span class="screen-reader-text">%4$s</span></a>',
esc_attr( $class ), esc_attr( get_post( $id )->post_title ), esc_url( $link ), esc_html( $s )
);
$post = get_post( $id );
if ( ! empty( $post ) ) {
printf(
'<a class="%1$s" title="%2$s" href="%3$s"><span class="screen-reader-text">%4$s</span>%5$s</a>',
esc_attr( $class ),
esc_attr( $post->post_title ),
esc_url( $link ),
esc_html( $s ),
$flag // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
);
}
} elseif ( $id === $post_id ) {
printf(
'<span class="pll_icon_tick"><span class="screen-reader-text">%s</span></span>',
'<span class="pll_column_flag" style=""><span class="screen-reader-text">%1$s</span>%2$s</span>',
/* translators: accessibility text, %s is a native language name */
esc_html( sprintf( __( 'This item is in %s', 'polylang' ), $language->name ) )
esc_html( sprintf( __( 'This item is in %s', 'polylang' ), $language->name ) ),
$this->get_flag_html( $language ) // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
);
}
}
// link to add a new translation
// Link to add a new translation
else {
echo $this->links->new_post_translation_link( $post_id, $language );
echo $this->links->new_post_translation_link( $post_id, $language ); // phpcs:ignore WordPress.Security.EscapeOutput
}
}
/**
* quick edit & bulk edit
* Quick edit & bulk edit
*
* @since 0.9
*
* @param string $column column name
* @param string $type either 'edit-tags' for terms list table or post type for posts list table
* @return string unmodified $column
*/
public function quick_edit_custom_box( $column, $type ) {
public function quick_edit_custom_box( $column ) {
if ( $column == $this->get_first_language_column() ) {
$elements = $this->model->get_languages_list();
if ( current_filter() == 'bulk_edit_custom_box' ) {
array_unshift( $elements, (object) array( 'slug' => -1, 'name' => __( '&mdash; No Change &mdash;' ) ) );
array_unshift( $elements, (object) array( 'slug' => -1, 'name' => __( '&mdash; No Change &mdash;', 'polylang' ) ) );
}
$dropdown = new PLL_Walker_Dropdown();
// the hidden field 'old_lang' allows to pass the old language to ajax request
// The hidden field 'old_lang' allows to pass the old language to ajax request
printf(
'<fieldset class="inline-edit-col-left">
<div class="inline-edit-col">
@ -185,63 +232,85 @@ class PLL_Admin_Filters_Columns {
</div>
</fieldset>',
esc_html__( 'Language', 'polylang' ),
$dropdown->walk( $elements, array( 'name' => 'inline_lang_choice', 'id' => '' ) )
$dropdown->walk( $elements, -1, array( 'name' => 'inline_lang_choice', 'id' => '' ) ) // phpcs:ignore WordPress.Security.EscapeOutput
);
}
return $column;
}
/**
* adds the language column ( before the posts column ) in the 'Categories' or 'Post Tags' table
* Adds the language column ( before the posts column ) in the 'Categories' or 'Post Tags' table.
*
* @since 0.1
*
* @param array $columns list of terms table columns
* @return array modified list of columns
* @param string[] $columns List of terms table columns.
* @return string[] modified List of columns.
*/
public function add_term_column( $columns ) {
$screen = get_current_screen();
// Avoid displaying languages in screen options when editing a term.
if ( $screen instanceof WP_Screen && 'term' === $screen->base ) {
return $columns;
}
return $this->add_column( $columns, 'posts' );
}
/**
* fills the language column in the 'Categories' or 'Post Tags' table
* Fills the language column in the 'Categories' or 'Post Tags' table
*
* @since 0.1
*
* @param string $out
* @param string $column Column name
* @param int $term_id
* @return string
*/
public function term_column( $out, $column, $term_id ) {
$inline = wp_doing_ajax() && isset( $_REQUEST['action'], $_POST['inline_lang_choice'] ) && 'inline-save-tax' === $_REQUEST['action'];
if ( false === strpos( $column, 'language_' ) || ! ( $lang = $inline ? $this->model->get_language( $_POST['inline_lang_choice'] ) : $this->model->term->get_language( $term_id ) ) ) {
$inline = wp_doing_ajax() && isset( $_REQUEST['action'], $_POST['inline_lang_choice'] ) && 'inline-save-tax' === $_REQUEST['action']; // phpcs:ignore WordPress.Security.NonceVerification
if ( false === strpos( $column, 'language_' ) || ! ( $lang = $inline ? $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) ) : $this->model->term->get_language( $term_id ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
return $out;
}
$post_type = isset( $GLOBALS['post_type'] ) ? $GLOBALS['post_type'] : $_REQUEST['post_type']; // 2nd case for quick edit
$taxonomy = isset( $GLOBALS['taxonomy'] ) ? $GLOBALS['taxonomy'] : $_REQUEST['taxonomy'];
if ( isset( $_REQUEST['post_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$post_type = sanitize_key( $_REQUEST['post_type'] ); // phpcs:ignore WordPress.Security.NonceVerification
}
if ( ! post_type_exists( $post_type ) || ! taxonomy_exists( $taxonomy ) ) {
if ( isset( $GLOBALS['post_type'] ) ) {
$post_type = $GLOBALS['post_type'];
}
if ( isset( $_REQUEST['taxonomy'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$taxonomy = sanitize_key( $_REQUEST['taxonomy'] ); // phpcs:ignore WordPress.Security.NonceVerification
}
if ( isset( $GLOBALS['taxonomy'] ) ) {
$taxonomy = $GLOBALS['taxonomy'];
}
if ( ! isset( $taxonomy, $post_type ) || ! post_type_exists( $post_type ) || ! taxonomy_exists( $taxonomy ) ) {
return $out;
}
$term_id = (int) $term_id;
$language = $this->model->get_language( substr( $column, 9 ) );
if ( $column == $this->get_first_language_column() ) {
$out = sprintf( '<div class="hidden" id="lang_%d">%s</div>', intval( $term_id ), esc_html( $lang->slug ) );
// identify the default categories to disable the language dropdown in js
if ( in_array( get_option( 'default_category' ), $this->model->term->get_translations( $term_id ) ) ) {
$out .= sprintf( '<div class="hidden" id="default_cat_%1$d">%1$d</div>', intval( $term_id ) );
}
if ( empty( $language ) ) {
return $out;
}
// link to edit term ( or a translation )
if ( $column == $this->get_first_language_column() ) {
$out = sprintf( '<div class="hidden" id="lang_%d">%s</div>', intval( $term_id ), esc_html( $lang->slug ) );
}
// Link to edit term ( or a translation )
if ( ( $id = $this->model->term->get( $term_id, $language ) ) && $term = get_term( $id, $taxonomy ) ) {
if ( $link = get_edit_term_link( $id, $taxonomy, $post_type ) ) {
$flag = '';
if ( $id === $term_id ) {
$class = 'pll_icon_tick';
$flag = $this->get_flag_html( $language );
$class = 'pll_column_flag';
/* translators: accessibility text, %s is a native language name */
$s = sprintf( __( 'Edit this item in %s', 'polylang' ), $language->name );
} else {
@ -250,19 +319,24 @@ class PLL_Admin_Filters_Columns {
$s = sprintf( __( 'Edit the translation in %s', 'polylang' ), $language->name );
}
$out .= sprintf(
'<a class="%1$s" title="%2$s" href="%3$s"><span class="screen-reader-text">%4$s</span></a>',
$class, esc_attr( $term->name ), esc_url( $link ), esc_html( $s )
'<a class="%1$s" title="%2$s" href="%3$s"><span class="screen-reader-text">%4$s</span>%5$s</a>',
$class,
esc_attr( $term->name ),
esc_url( $link ),
esc_html( $s ),
$flag // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
);
} elseif ( $id === $term_id ) {
$out .= printf(
'<span class="pll_icon_tick"><span class="screen-reader-text">%s</span></span>',
$out .= sprintf(
'<span class="pll_column_flag"><span class="screen-reader-text">%1$s</span>%2$s</span>',
/* translators: accessibility text, %s is a native language name */
esc_html( sprintf( __( 'This item is in %s', 'polylang' ), $language->name ) )
esc_html( sprintf( __( 'This item is in %s', 'polylang' ), $language->name ) ),
$this->get_flag_html( $language ) // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
);
}
}
// link to add a new translation
// Link to add a new translation
else {
$out .= $this->links->new_term_translation_link( $term_id, $taxonomy, $post_type, $language );
}
@ -271,26 +345,36 @@ class PLL_Admin_Filters_Columns {
}
/**
* update rows of translated posts when the language is modified in quick edit
* Update rows of translated posts when the language is modified in quick edit
*
* @since 1.7
*
* @return void
*/
public function ajax_update_post_rows() {
global $wp_list_table;
if ( ! post_type_exists( $post_type = $_POST['post_type'] ) || ! $this->model->is_translated_post_type( $post_type ) ) {
die( 0 );
}
check_ajax_referer( 'inlineeditnonce', '_pll_nonce' );
$x = new WP_Ajax_Response();
$wp_list_table = _get_list_table( 'WP_Posts_List_Table', array( 'screen' => $_POST['screen'] ) );
if ( ! isset( $_POST['post_type'], $_POST['post_id'], $_POST['screen'] ) ) {
wp_die( 0 );
}
$translations = empty( $_POST['translations'] ) ? array() : explode( ',', $_POST['translations'] ); // collect old translations
$translations = array_merge( $translations, array( $_POST['post_id'] ) ); // add current post
$post_type = sanitize_key( $_POST['post_type'] );
if ( ! post_type_exists( $post_type ) || ! $this->model->is_translated_post_type( $post_type ) ) {
wp_die( 0 );
}
/** @var WP_Posts_List_Table $wp_list_table */
$wp_list_table = _get_list_table( 'WP_Posts_List_Table', array( 'screen' => sanitize_key( $_POST['screen'] ) ) );
$x = new WP_Ajax_Response();
// Collect old translations
$translations = empty( $_POST['translations'] ) ? array() : explode( ',', $_POST['translations'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
$translations = array_map( 'intval', $translations );
$translations = array_merge( $translations, array( (int) $_POST['post_id'] ) ); // Add current post
foreach ( $translations as $post_id ) {
$level = is_post_type_hierarchical( $post_type ) ? count( get_ancestors( $post_id, $post_type ) ) : 0;
if ( $post = get_post( $post_id ) ) {
@ -305,27 +389,37 @@ class PLL_Admin_Filters_Columns {
}
/**
* update rows of translated terms when adding / deleting a translation or when the language is modified in quick edit
* Update rows of translated terms when adding / deleting a translation or when the language is modified in quick edit
*
* @since 1.7
*
* @return void
*/
public function ajax_update_term_rows() {
global $wp_list_table;
if ( ! taxonomy_exists( $taxonomy = $_POST['taxonomy'] ) || ! $this->model->is_translated_taxonomy( $taxonomy ) ) {
die( 0 );
}
check_ajax_referer( 'pll_language', '_pll_nonce' );
$x = new WP_Ajax_Response();
$wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => $_POST['screen'] ) );
if ( ! isset( $_POST['taxonomy'], $_POST['term_id'], $_POST['screen'] ) ) {
wp_die( 0 );
}
$translations = empty( $_POST['translations'] ) ? array() : explode( ',', $_POST['translations'] ); // collect old translations
$translations = array_merge( $translations, $this->model->term->get_translations( (int) $_POST['term_id'] ) ); // add current translations
$translations = array_unique( $translations ); // remove duplicates
$taxonomy = sanitize_key( $_POST['taxonomy'] );
if ( ! taxonomy_exists( $taxonomy ) || ! $this->model->is_translated_taxonomy( $taxonomy ) ) {
wp_die( 0 );
}
/** @var WP_Terms_List_Table $wp_list_table */
$wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => sanitize_key( $_POST['screen'] ) ) );
$x = new WP_Ajax_Response();
// Collect old translations
$translations = empty( $_POST['translations'] ) ? array() : explode( ',', $_POST['translations'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
$translations = array_map( 'intval', $translations );
$translations = array_merge( $translations, $this->model->term->get_translations( (int) $_POST['term_id'] ) ); // Add current translations
$translations = array_unique( $translations ); // Remove duplicates
foreach ( $translations as $term_id ) {
$level = is_taxonomy_hierarchical( $taxonomy ) ? count( get_ancestors( $term_id, $taxonomy ) ) : 0;
if ( $tag = get_term( $term_id, $taxonomy ) ) {
@ -338,4 +432,16 @@ class PLL_Admin_Filters_Columns {
$x->send();
}
/**
* Returns the language flag or teh language slug if there is no flag.
*
* @since 2.8
*
* @param PLL_Language $language PLL_Language object.
* @return string
*/
protected function get_flag_html( $language ) {
return $language->flag ? $language->flag : sprintf( '<abbr>%s</abbr>', esc_html( $language->slug ) );
}
}

View file

@ -1,4 +1,7 @@
<?php
/**
* @package Polylang
*/
/**
* Manages filters and actions related to media on admin side
@ -7,6 +10,11 @@
* @since 1.2
*/
class PLL_Admin_Filters_Media extends PLL_Admin_Filters_Post_Base {
/**
* @var PLL_CRUD_Posts
*/
public $posts;
/**
* Constructor: setups filters and actions
*
@ -17,29 +25,29 @@ class PLL_Admin_Filters_Media extends PLL_Admin_Filters_Post_Base {
public function __construct( &$polylang ) {
parent::__construct( $polylang );
$this->posts = &$polylang->posts;
// Adds the language field and translations tables in the 'Edit Media' panel
add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 );
// Adds actions related to languages when creating, saving or deleting media
add_action( 'add_attachment', array( $this, 'set_default_language' ) );
add_filter( 'attachment_fields_to_save', array( $this, 'save_media' ), 10, 2 );
add_filter( 'wp_delete_file', array( $this, 'wp_delete_file' ) );
// Creates a media translation
if ( isset( $_GET['action'], $_GET['new_lang'], $_GET['from_media'] ) && 'translate_media' === $_GET['action'] ) {
if ( isset( $_GET['action'], $_GET['new_lang'], $_GET['from_media'] ) && 'translate_media' === $_GET['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification
add_action( 'admin_init', array( $this, 'translate_media' ) );
}
}
/**
* Adds the language field and translations tables in the 'Edit Media' panel
* Adds the language field and translations tables in the 'Edit Media' panel.
* Needs WP 3.5+
*
* @since 0.9
*
* @param array $fields list of form fields
* @param object $post
* @return array modified list of form fields
* @param array $fields List of form fields.
* @param WP_Post $post The attachment being edited.
* @return array Modified list of form fields.
*/
public function attachment_fields_to_edit( $fields, $post ) {
if ( 'post.php' == $GLOBALS['pagenow'] ) {
@ -53,91 +61,45 @@ class PLL_Admin_Filters_Media extends PLL_Admin_Filters_Post_Base {
$fields['language'] = array(
'label' => __( 'Language', 'polylang' ),
'input' => 'html',
'html' => $dropdown->walk( $this->model->get_languages_list(), array(
'name' => sprintf( 'attachments[%d][language]', $post_id ),
'class' => 'media_lang_choice',
'selected' => $lang ? $lang->slug : '',
) ),
'html' => $dropdown->walk(
$this->model->get_languages_list(),
-1,
array(
'name' => sprintf( 'attachments[%d][language]', $post_id ),
'class' => 'media_lang_choice',
'selected' => $lang ? $lang->slug : '',
)
),
);
return $fields;
}
/**
* Creates a media translation
*
* @since 1.8
*
* @param int $post_id
* @param string|object $lang
* @return int id of the translated media
*/
public function create_media_translation( $post_id, $lang ) {
$post = get_post( $post_id );
if ( empty( $post ) ) {
return $post;
}
$lang = $this->model->get_language( $lang ); // Make sure we get a valid language slug
// Create a new attachment ( translate attachment parent if exists )
$post->ID = null; // Will force the creation
$post->post_parent = ( $post->post_parent && $tr_parent = $this->model->post->get_translation( $post->post_parent, $lang->slug ) ) ? $tr_parent : 0;
$post->tax_input = array( 'language' => array( $lang->slug ) ); // Assigns the language
$tr_id = wp_insert_attachment( $post );
// Copy metadata, attached file and alternative text
foreach ( array( '_wp_attachment_metadata', '_wp_attached_file', '_wp_attachment_image_alt' ) as $key ) {
if ( $meta = get_post_meta( $post_id, $key, true ) ) {
add_post_meta( $tr_id, $key, $meta );
}
}
$this->model->post->set_language( $tr_id, $lang );
$translations = $this->model->post->get_translations( $post_id );
if ( ! $translations && $src_lang = $this->model->post->get_language( $post_id ) ) {
$translations[ $src_lang->slug ] = $post_id;
}
$translations[ $lang->slug ] = $tr_id;
$this->model->post->save_translations( $tr_id, $translations );
/**
* Fires after a media translation is created
*
* @since 1.6.4
*
* @param int $post_id post id of the source media
* @param int $tr_id post id of the new media translation
* @param string $slug language code of the new translation
*/
do_action( 'pll_translate_media', $post_id, $tr_id, $lang->slug );
return $tr_id;
}
/**
* Creates a media translation
*
* @since 0.9
*
* @return void
*/
public function translate_media() {
// Security check
check_admin_referer( 'translate_media' );
$post_id = (int) $_GET['from_media'];
if ( isset( $_GET['from_media'], $_GET['new_lang'] ) ) {
// Security check
check_admin_referer( 'translate_media' );
$post_id = (int) $_GET['from_media'];
// Bails if the translations already exists
// See https://wordpress.org/support/topic/edit-translation-in-media-attachments?#post-7322303
// Or if the source media does not exist
if ( $this->model->post->get_translation( $post_id, $_GET['new_lang'] ) || ! get_post( $post_id ) ) {
wp_safe_redirect( wp_get_referer() );
// Bails if the translations already exists
// See https://wordpress.org/support/topic/edit-translation-in-media-attachments?#post-7322303
// Or if the source media does not exist
if ( $this->model->post->get_translation( $post_id, sanitize_key( $_GET['new_lang'] ) ) || ! get_post( $post_id ) ) {
wp_safe_redirect( wp_get_referer() );
exit;
}
$tr_id = $this->posts->create_media_translation( $post_id, sanitize_key( $_GET['new_lang'] ) );
wp_safe_redirect( admin_url( sprintf( 'post.php?post=%d&action=edit', $tr_id ) ) ); // WP 3.5+
exit;
}
$tr_id = $this->create_media_translation( $post_id, $_GET['new_lang'] );
wp_safe_redirect( admin_url( sprintf( 'post.php?post=%d&action=edit', $tr_id ) ) ); // WP 3.5+
exit;
}
/**
@ -153,43 +115,10 @@ class PLL_Admin_Filters_Media extends PLL_Admin_Filters_Post_Base {
public function save_media( $post, $attachment ) {
// Language is filled in attachment by the function applying the filter 'attachment_fields_to_save'
// All security checks have been done by functions applying this filter
if ( ! empty( $attachment['language'] ) ) {
$this->model->post->set_language( $post['ID'], $attachment['language'] );
}
if ( isset( $_POST['media_tr_lang'] ) ) {
$this->save_translations( $post['ID'], $_POST['media_tr_lang'] );
if ( ! empty( $attachment['language'] ) && current_user_can( 'edit_post', $post['ID'] ) ) {
$this->model->post->update_language( $post['ID'], $this->model->get_language( $attachment['language'] ) );
}
return $post;
}
/**
* Prevents WP deleting files when there are still media using them
* Thanks to Bruno "Aesqe" Babic and its plugin file gallery in which I took all the ideas for this function
*
* @since 0.9
*
* @param string $file
* @return string unmodified $file
*/
public function wp_delete_file( $file ) {
global $wpdb;
$uploadpath = wp_upload_dir();
$ids = $wpdb->get_col( $wpdb->prepare( "
SELECT post_id FROM $wpdb->postmeta
WHERE meta_key = '_wp_attached_file' AND meta_value = %s",
substr_replace( $file, '', 0, strlen( trailingslashit( $uploadpath['basedir'] ) ) )
) );
if ( ! empty( $ids ) ) {
// Regenerate intermediate sizes if it's an image ( since we could not prevent WP deleting them before )
wp_update_attachment_metadata( $ids[0], wp_generate_attachment_metadata( $ids[0], $file ) );
return ''; // Prevent deleting the main file
}
return $file;
}
}

View file

@ -1,15 +1,33 @@
<?php
/**
* @package Polylang
*/
/**
* some common code for PLL_Admin_Filters_Post and PLL_Admin_Filters_Media
* Some common code for PLL_Admin_Filters_Post and PLL_Admin_Filters_Media
*
* @since 1.5
*/
abstract class PLL_Admin_Filters_Post_Base {
public $links, $model, $pref_lang;
/**
* @var PLL_Model
*/
public $model;
/**
* constructor: setups filters and actions
* @var PLL_Links
*/
public $links;
/**
* Language selected in the admin language filter.
*
* @var PLL_Language
*/
public $filter_lang;
/**
* Constructor: setups filters and actions
*
* @since 1.2
*
@ -22,48 +40,19 @@ abstract class PLL_Admin_Filters_Post_Base {
}
/**
* allows to set a language by default for posts if it has no language yet
* Save translations from the languages metabox.
*
* @since 1.5
*
* @param int $post_id
*/
public function set_default_language( $post_id ) {
if ( ! $this->model->post->get_language( $post_id ) ) {
if ( isset( $_GET['new_lang'] ) && $lang = $this->model->get_language( $_GET['new_lang'] ) ) {
$this->model->post->set_language( $post_id, $lang );
}
elseif ( ( $parent_id = wp_get_post_parent_id( $post_id ) ) && $parent_lang = $this->model->post->get_language( $parent_id ) ) {
$this->model->post->set_language( $post_id, $parent_lang );
}
else {
$this->model->post->set_language( $post_id, $this->pref_lang );
}
}
}
/**
* save translations from language metabox
*
* @since 1.5
*
* @param int $post_id
* @param array $arr
* @return array
* @param int $post_id Post id of the post being saved.
* @param int[] $arr An array with language codes as key and post id as value.
* @return int[] The array of translated post ids.
*/
protected function save_translations( $post_id, $arr ) {
// security check
// as 'wp_insert_post' can be called from outside WP admin
// Security check as 'wp_insert_post' can be called from outside WP admin.
check_admin_referer( 'pll_language', '_pll_nonce' );
// save translations after checking the translated post is in the right language
foreach ( $arr as $lang => $tr_id ) {
$translations[ $lang ] = ( $tr_id && $this->model->post->get_language( (int) $tr_id )->slug == $lang ) ? (int) $tr_id : 0;
}
$this->model->post->save_translations( $post_id, $translations );
$translations = $this->model->post->save_translations( $post_id, $arr );
return $translations;
}
}

View file

@ -1,4 +1,7 @@
<?php
/**
* @package Polylang
*/
/**
* Manages filters and actions related to posts on admin side
@ -6,7 +9,12 @@
* @since 1.2
*/
class PLL_Admin_Filters_Post extends PLL_Admin_Filters_Post_Base {
public $options, $curlang;
/**
* Current language (used to filter the content).
*
* @var PLL_Language
*/
public $curlang;
/**
* Constructor: setups filters and actions
@ -17,7 +25,6 @@ class PLL_Admin_Filters_Post extends PLL_Admin_Filters_Post_Base {
*/
public function __construct( &$polylang ) {
parent::__construct( $polylang );
$this->options = &$polylang->options;
$this->curlang = &$polylang->curlang;
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
@ -25,27 +32,10 @@ class PLL_Admin_Filters_Post extends PLL_Admin_Filters_Post_Base {
// Filters posts, pages and media by language
add_action( 'parse_query', array( $this, 'parse_query' ) );
// Adds the Languages box in the 'Edit Post' and 'Edit Page' panels
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 10, 2 );
// Ajax response for changing the language in the post metabox
add_action( 'wp_ajax_post_lang_choice', array( $this, 'post_lang_choice' ) );
add_action( 'wp_ajax_pll_posts_not_translated', array( $this, 'ajax_posts_not_translated' ) );
// Adds actions and filters related to languages when creating, saving or deleting posts and pages
add_action( 'load-post.php', array( $this, 'edit_post' ) );
add_action( 'load-edit.php', array( $this, 'bulk_edit_posts' ) );
add_action( 'wp_ajax_inline-save', array( $this, 'inline_edit_post' ), 0 ); // Before WordPress
add_action( 'save_post', array( $this, 'save_post' ), 21, 3 ); // Priority 21 to come after advanced custom fields ( 20 ) and before the event calendar which breaks everything after 25
add_action( 'set_object_terms', array( $this, 'set_object_terms' ), 10, 4 );
add_filter( 'wp_insert_post_parent', array( $this, 'wp_insert_post_parent' ), 10, 4 );
add_action( 'before_delete_post', array( $this, 'delete_post' ) );
if ( $this->options['media_support'] ) {
add_action( 'delete_attachment', array( $this, 'delete_post' ) ); // Action shared with media
}
// Filters the pages by language in the parent dropdown list in the page attributes metabox
add_filter( 'page_attributes_dropdown_pages_args', array( $this, 'page_attributes_dropdown_pages_args' ), 10, 2 );
// Sets the language in Tiny MCE
add_filter( 'tiny_mce_before_init', array( $this, 'tiny_mce_before_init' ) );
@ -58,13 +48,20 @@ class PLL_Admin_Filters_Post extends PLL_Admin_Filters_Post_Base {
* to filter the parent dropdown per post language in quick edit
*
* @since 1.7
*
* @return void
*/
public function admin_enqueue_scripts() {
$screen = get_current_screen();
if ( empty( $screen ) ) {
return;
}
// Hierarchical taxonomies
if ( 'edit' == $screen->base && $taxonomies = get_object_taxonomies( $screen->post_type, 'object' ) ) {
// Get translated hierarchical taxonomies
$hierarchical_taxonomies = array();
foreach ( $taxonomies as $taxonomy ) {
if ( $taxonomy->hierarchical && $taxonomy->show_in_quick_edit && $this->model->is_translated_taxonomy( $taxonomy->name ) ) {
$hierarchical_taxonomies[] = $taxonomy->name;
@ -72,11 +69,14 @@ class PLL_Admin_Filters_Post extends PLL_Admin_Filters_Post_Base {
}
if ( ! empty( $hierarchical_taxonomies ) ) {
$terms = get_terms( $hierarchical_taxonomies, array( 'get' => 'all' ) );
$terms = get_terms( $hierarchical_taxonomies, array( 'get' => 'all' ) );
$term_languages = array();
foreach ( $terms as $term ) {
if ( $lang = $this->model->term->get_language( $term->term_id ) ) {
$term_languages[ $lang->slug ][ $term->taxonomy ][] = $term->term_id;
if ( is_array( $terms ) ) {
foreach ( $terms as $term ) {
if ( $lang = $this->model->term->get_language( $term->term_id ) ) {
$term_languages[ $lang->slug ][ $term->taxonomy ][] = $term->term_id;
}
}
}
@ -89,7 +89,11 @@ class PLL_Admin_Filters_Post extends PLL_Admin_Filters_Post_Base {
// Hierarchical post types
if ( 'edit' == $screen->base && is_post_type_hierarchical( $screen->post_type ) ) {
$pages = get_pages();
$pages = get_pages( array( 'sort_column' => 'menu_order, post_title' ) ); // Same arguments as the parent pages dropdown to avoid an extra query.
update_post_caches( $pages, $screen->post_type, true, false );
$page_languages = array();
foreach ( $pages as $page ) {
if ( $lang = $this->model->post->get_language( $page->ID ) ) {
@ -105,288 +109,46 @@ class PLL_Admin_Filters_Post extends PLL_Admin_Filters_Post_Base {
}
/**
* Filters posts, pages and media by language
* Filters posts, pages and media by language.
*
* @since 0.1
*
* @param object $query a WP_Query object
* @param WP_Query $query WP_Query object.
* @return void
*/
public function parse_query( $query ) {
$pll_query = new PLL_Query( $query, $this->model );
$pll_query->filter_query( $this->curlang );
}
/**
* Adds the Language box in the 'Edit Post' and 'Edit Page' panels ( as well as in custom post types panels )
*
* @since 0.1
*
* @param string $post_type Current post type
* @param object $post Current post
*/
public function add_meta_boxes( $post_type, $post ) {
if ( $this->model->is_translated_post_type( $post_type ) ) {
add_meta_box( 'ml_box', __( 'Languages', 'polylang' ), array( $this, 'post_language' ), $post_type, 'side', 'high' );
}
}
/**
* Displays the Languages metabox in the 'Edit Post' and 'Edit Page' panels
*
* @since 0.1
*/
public function post_language() {
global $post_ID;
$post_id = $post_ID;
$post_type = get_post_type( $post_ID );
$lang = ( $lg = $this->model->post->get_language( $post_ID ) ) ? $lg :
( isset( $_GET['new_lang'] ) ? $this->model->get_language( $_GET['new_lang'] ) :
$this->pref_lang );
$dropdown = new PLL_Walker_Dropdown();
wp_nonce_field( 'pll_language', '_pll_nonce' );
// NOTE: the class "tags-input" allows to include the field in the autosave $_POST ( see autosave.js )
printf( '
<p><strong>%1$s</strong></p>
<label class="screen-reader-text" for="%2$s">%1$s</label>
<div id="select-%3$s-language">%4$s</div>',
esc_html__( 'Language', 'polylang' ),
$id = ( 'attachment' === $post_type ) ? sprintf( 'attachments[%d][language]', $post_ID ) : 'post_lang_choice',
'attachment' === $post_type ? 'media' : 'post',
$dropdown->walk( $this->model->get_languages_list(), array(
'name' => $id,
'class' => 'post_lang_choice tags-input',
'selected' => $lang ? $lang->slug : '',
'flag' => true,
) )
);
/**
* Fires before displaying the list of translations in the Languages metabox for posts
*
* @since 1.8
*/
do_action( 'pll_before_post_translations', $post_type );
echo '<div id="post-translations" class="translations">';
if ( $lang ) {
include PLL_ADMIN_INC . '/view-translations-' . ( 'attachment' == $post_type ? 'media' : 'post' ) . '.php';
}
echo '</div>' . "\n";
}
/**
* Ajax response for changing the language in the post metabox
*
* @since 0.2
*/
public function post_lang_choice() {
check_ajax_referer( 'pll_language', '_pll_nonce' );
global $post_ID; // Obliged to use the global variable for wp_popular_terms_checklist
$post_id = $post_ID = (int) $_POST['post_id'];
$lang = $this->model->get_language( $_POST['lang'] );
$post_type = $_POST['post_type'];
$post_type_object = get_post_type_object( $post_type );
if ( ! current_user_can( $post_type_object->cap->edit_post, $post_ID ) ) {
wp_die( -1 );
}
$this->model->post->set_language( $post_ID, $lang ); // Save language, useful to set the language when uploading media from post
ob_start();
if ( $lang ) {
include PLL_ADMIN_INC . '/view-translations-' . ( 'attachment' == $post_type ? 'media' : 'post' ) . '.php';
}
$x = new WP_Ajax_Response( array( 'what' => 'translations', 'data' => ob_get_contents() ) );
ob_end_clean();
// Categories
if ( isset( $_POST['taxonomies'] ) ) {
// Not set for pages
foreach ( $_POST['taxonomies'] as $taxname ) {
$taxonomy = get_taxonomy( $taxname );
ob_start();
$popular_ids = wp_popular_terms_checklist( $taxonomy->name );
$supplemental['populars'] = ob_get_contents();
ob_end_clean();
ob_start();
// Use $post_ID to remember checked terms in case we come back to the original language
wp_terms_checklist( $post_ID, array( 'taxonomy' => $taxonomy->name, 'popular_cats' => $popular_ids ) );
$supplemental['all'] = ob_get_contents();
ob_end_clean();
$supplemental['dropdown'] = wp_dropdown_categories( array(
'taxonomy' => $taxonomy->name,
'hide_empty' => 0,
'name' => 'new' . $taxonomy->name . '_parent',
'orderby' => 'name',
'hierarchical' => 1,
'show_option_none' => '&mdash; ' . $taxonomy->labels->parent_item . ' &mdash;',
'echo' => 0,
) );
$x->Add( array( 'what' => 'taxonomy', 'data' => $taxonomy->name, 'supplemental' => $supplemental ) );
}
}
// Parent dropdown list ( only for hierarchical post types )
if ( in_array( $post_type, get_post_types( array( 'hierarchical' => true ) ) ) ) {
$post = get_post( $post_ID );
// Args and filter from 'page_attributes_meta_box' in wp-admin/includes/meta-boxes.php of WP 4.2.1
$dropdown_args = array(
'post_type' => $post->post_type,
'exclude_tree' => $post->ID,
'selected' => $post->post_parent,
'name' => 'parent_id',
'show_option_none' => __( '(no parent)' ),
'sort_column' => 'menu_order, post_title',
'echo' => 0,
);
/** This filter is documented in wp-admin/includes/meta-boxes.php */
$dropdown_args = apply_filters( 'page_attributes_dropdown_pages_args', $dropdown_args, $post ); // Since WP 3.3
$x->Add( array( 'what' => 'pages', 'data' => wp_dropdown_pages( $dropdown_args ) ) );
}
// Flag
$x->Add( array( 'what' => 'flag', 'data' => empty( $lang->flag ) ? esc_html( $lang->slug ) : $lang->flag ) );
// Sample permalink
$x->Add( array( 'what' => 'permalink', 'data' => get_sample_permalink_html( $post_ID ) ) );
$x->send();
}
/**
* Ajax response for input in translation autocomplete input box
*
* @since 1.5
*/
public function ajax_posts_not_translated() {
check_ajax_referer( 'pll_language', '_pll_nonce' );
if ( ! post_type_exists( $_GET['post_type'] ) ) {
die( 0 );
}
$post_language = $this->model->get_language( $_GET['post_language'] );
$translation_language = $this->model->get_language( $_GET['translation_language'] );
// Don't order by title: see https://wordpress.org/support/topic/find-translated-post-when-10-is-not-enough
$args = array(
's' => wp_unslash( $_GET['term'] ),
'suppress_filters' => 0, // To make the post_fields filter work
'lang' => 0, // Avoid admin language filter
'numberposts' => 20, // Limit to 20 posts
'post_status' => 'any',
'post_type' => $_GET['post_type'],
'tax_query' => array(
array(
'taxonomy' => 'language',
'field' => 'term_taxonomy_id', // WP 3.5+
'terms' => $translation_language->term_taxonomy_id,
),
),
);
/**
* Filter the query args when auto suggesting untranslated posts in the Languages metabox
* This should help plugins to fix some edge cases
*
* @see https://wordpress.org/support/topic/find-translated-post-when-10-is-not-enough
*
* @since 1.7
*
* @param array $args WP_Query arguments
*/
$args = apply_filters( 'pll_ajax_posts_not_translated_args', $args );
$posts = get_posts( $args );
$return = array();
foreach ( $posts as $key => $post ) {
if ( ! $this->model->post->get_translation( $post->ID, $post_language ) ) {
$return[] = array(
'id' => $post->ID,
'value' => $post->post_title,
'link' => $this->links->edit_post_translation_link( $post->ID ),
);
}
}
// Add current translation in list
if ( $post_id = $this->model->post->get_translation( (int) $_GET['pll_post_id'], $translation_language ) ) {
$post = get_post( $post_id );
array_unshift( $return, array(
'id' => $post_id,
'value' => $post->post_title,
'link' => $this->links->edit_post_translation_link( $post_id ),
) );
}
wp_die( json_encode( $return ) );
}
/**
* Save language and translation when editing a post (post.php)
*
* @since 2.3
*
* @return void
*/
public function edit_post() {
if ( isset( $_POST['post_lang_choice'], $_POST['post_ID'] ) && $post_id = (int) $_POST['post_ID'] ) {
if ( isset( $_POST['post_lang_choice'], $_POST['post_ID'] ) && $post_id = (int) $_POST['post_ID'] ) { // phpcs:ignore WordPress.Security.NonceVerification
check_admin_referer( 'pll_language', '_pll_nonce' );
$post = get_post( $post_id );
if ( empty( $post ) ) {
return;
}
$post_type_object = get_post_type_object( $post->post_type );
if ( empty( $post_type_object ) ) {
return;
}
if ( current_user_can( $post_type_object->cap->edit_post, $post_id ) ) {
$this->model->post->set_language( $post_id, $this->model->get_language( $_POST['post_lang_choice'] ) );
$this->model->post->set_language( $post_id, $this->model->get_language( sanitize_key( $_POST['post_lang_choice'] ) ) );
if ( isset( $_POST['post_tr_lang'] ) ) {
$this->save_translations( $post_id, $_POST['post_tr_lang'] );
}
}
}
}
/**
* Save language when inline editing or bulk editing a post
* Fix translations if necessary
*
* @since 2.3
*
* @param int $post_id Post ID
* @param object $lang Language
*/
protected function inline_save_language( $post_id, $lang ) {
$post = get_post( $post_id );
$post_type_object = get_post_type_object( $post->post_type );
if ( current_user_can( $post_type_object->cap->edit_post, $post_id ) ) {
$old_lang = $this->model->post->get_language( $post_id ); // Stores the old language
$this->model->post->set_language( $post_id, $lang ); // set new language
// Checks if the new language already exists in the translation group
if ( $old_lang && $old_lang->slug != $lang->slug ) {
$translations = $this->model->post->get_translations( $post_id );
// If yes, separate this post from the translation group
if ( array_key_exists( $lang->slug, $translations ) ) {
$this->model->post->delete_translation( $post_id );
}
elseif ( array_key_exists( $old_lang->slug, $translations ) ) {
unset( $translations[ $old_lang->slug ] );
$this->model->post->save_translations( $post_id, $translations );
$this->save_translations( $post_id, array_map( 'absint', $_POST['post_tr_lang'] ) );
}
}
}
@ -396,15 +158,19 @@ class PLL_Admin_Filters_Post extends PLL_Admin_Filters_Post_Base {
* Save language when bulk editing a post
*
* @since 2.3
*
* @return void
*/
public function bulk_edit_posts() {
if ( isset( $_GET['bulk_edit'], $_GET['inline_lang_choice'] ) && -1 !== $_GET['inline_lang_choice'] ) {
if ( isset( $_GET['bulk_edit'], $_GET['inline_lang_choice'], $_REQUEST['post'] ) && -1 !== $_GET['inline_lang_choice'] ) { // phpcs:ignore WordPress.Security.NonceVerification
check_admin_referer( 'bulk-posts' );
if ( $lang = $this->model->get_language( $_GET['inline_lang_choice'] ) ) {
if ( $lang = $this->model->get_language( sanitize_key( $_GET['inline_lang_choice'] ) ) ) {
$post_ids = array_map( 'intval', (array) $_REQUEST['post'] );
foreach ( $post_ids as $post_id ) {
$this->inline_save_language( $post_id, $lang );
if ( current_user_can( 'edit_post', $post_id ) ) {
$this->model->post->update_language( $post_id, $lang );
}
}
}
}
@ -414,176 +180,21 @@ class PLL_Admin_Filters_Post extends PLL_Admin_Filters_Post_Base {
* Save language when inline editing a post
*
* @since 2.3
*
* @return void
*/
public function inline_edit_post() {
check_admin_referer( 'inlineeditnonce', '_inline_edit' );
if ( isset( $_POST['post_ID'], $_POST['inline_lang_choice'] ) ) {
$post_id = (int) $_POST['post_ID'];
$lang = $this->model->get_language( $_POST['inline_lang_choice'] );
if ( $post_id && $lang ) {
$this->inline_save_language( $post_id, $lang );
$lang = $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) );
if ( $post_id && $lang && current_user_can( 'edit_post', $post_id ) ) {
$this->model->post->update_language( $post_id, $lang );
}
}
}
/**
* Called when a post ( or page ) is saved, published or updated
*
* @since 0.1
* @since 2.3 Does not save the language and translations anymore, unless the post has no language yet
*
* @param int $post_id
* @param object $post
* @param bool $update Whether it is an update or not
*/
public function save_post( $post_id, $post, $update ) {
// Does nothing except on post types which are filterable
if ( $this->model->is_translated_post_type( $post->post_type ) ) {
if ( $id = wp_is_post_revision( $post_id ) ) {
$post_id = $id;
}
$lang = $this->model->post->get_language( $post_id );
if ( empty( $lang ) ) {
$this->set_default_language( $post_id );
}
/**
* Fires after the post language and translations are saved
*
* @since 1.2
*
* @param int $post_id Post id
* @param object $post Post object
* @param array $translations The list of translations post ids
*/
do_action( 'pll_save_post', $post_id, $post, $this->model->post->get_translations( $post_id ) );
}
}
/**
* Make sure saved terms are in the right language (especially tags with same name in different languages)
*
* @since 2.3
*
* @param int $object_id Object ID.
* @param array $terms An array of object terms.
* @param array $tt_ids An array of term taxonomy IDs.
* @param string $taxonomy Taxonomy slug.
*/
public function set_object_terms( $object_id, $terms, $tt_ids, $taxonomy ) {
static $avoid_recursion;
if ( ! $avoid_recursion && $this->model->is_translated_taxonomy( $taxonomy ) && ! empty( $terms ) ) {
$lang = $this->model->post->get_language( $object_id );
if ( ! empty( $lang ) && is_array( $terms ) ) {
// Convert to term ids if we got tag names
$strings = array_filter( $terms, 'is_string' );
if ( ! empty( $strings ) ) {
$_terms = get_terms( $taxonomy, array( 'name' => $strings, 'object_ids' => $object_id, 'fields' => 'ids' ) );
$terms = array_merge( array_diff( $terms, $strings ), $_terms );
}
$term_ids = array_combine( $terms, $terms );
$languages = array_map( array( $this->model->term, 'get_language' ), $term_ids );
$languages = wp_list_pluck( $languages, 'slug' );
$wrong_terms = array_diff( $languages, array( $lang->slug ) );
if ( ! empty( $wrong_terms ) ) {
// We got terms in a wrong language
$wrong_term_ids = array_keys( $wrong_terms );
$terms = get_the_terms( $object_id, $taxonomy );
wp_remove_object_terms( $object_id, $wrong_term_ids, $taxonomy );
if ( is_array( $terms ) ) {
$newterms = array();
foreach ( $terms as $term ) {
if ( in_array( $term->term_id, $wrong_term_ids ) ) {
// Check if the term is in the correct language or if a translation exist ( mainly for default category )
if ( $newterm = $this->model->term->get( $term->term_id, $lang ) ) {
$newterms[] = (int) $newterm;
}
// Or choose the correct language for tags ( initially defined by name )
elseif ( $newterm = $this->model->term_exists( $term->name, $taxonomy, $term->parent, $lang ) ) {
$newterms[] = (int) $newterm; // Cast is important otherwise we get 'numeric' tags
}
// Or create the term in the correct language
elseif ( ! is_wp_error( $term_info = wp_insert_term( $term->name, $taxonomy ) ) ) {
$newterms[] = (int) $term_info['term_id'];
}
}
}
$avoid_recursion = true;
wp_set_object_terms( $object_id, array_unique( $newterms ), $taxonomy, true ); // Append
$avoid_recursion = false;
}
}
}
}
}
/**
* Make sure that the post parent is in the correct language when using bulk edit
*
* @since 1.8
*
* @param int $post_parent Post parent ID.
* @param int $post_id Post ID.
* @param array $new_postarr Array of parsed post data.
* @param array $postarr Array of sanitized, but otherwise unmodified post data.
* @return int
*/
public function wp_insert_post_parent( $post_parent, $post_id, $new_postarr, $postarr ) {
if ( isset( $postarr['bulk_edit'] ) ) {
check_admin_referer( 'bulk-posts' );
$lang = -1 == $postarr['inline_lang_choice'] ?
$this->model->post->get_language( $post_id ) :
$this->model->get_language( $postarr['inline_lang_choice'] );
$post_parent = $this->model->post->get_translation( $post_parent, $lang );
}
return $post_parent;
}
/**
* Called when a post, page or media is deleted
* Don't delete translations if this is a post revision thanks to AndyDeGroo who catched this bug
* http://wordpress.org/support/topic/plugin-polylang-quick-edit-still-breaks-translation-linking-of-pages-in-072
*
* @since 0.1
*
* @param int $post_id
*/
public function delete_post( $post_id ) {
if ( ! wp_is_post_revision( $post_id ) ) {
$this->model->post->delete_translation( $post_id );
}
}
/**
* Filters the pages by language in the parent dropdown list in the page attributes metabox
*
* @since 0.6
*
* @param array $dropdown_args Arguments passed to wp_dropdown_pages
* @param object $post
* @return array Modified arguments
*/
public function page_attributes_dropdown_pages_args( $dropdown_args, $post ) {
$dropdown_args['lang'] = isset( $_POST['lang'] ) ? $this->model->get_language( $_POST['lang'] ) : $this->model->post->get_language( $post->ID ); // ajax or not ?
if ( ! $dropdown_args['lang'] ) {
$dropdown_args['lang'] = $this->pref_lang;
}
return $dropdown_args;
}
/**
* Sets the language attribute and text direction for Tiny MCE
*

View file

@ -1,4 +1,7 @@
<?php
/**
* @package Polylang
*/
/**
* Manages filters and actions related to terms on admin side
@ -6,10 +9,59 @@
* @since 1.2
*/
class PLL_Admin_Filters_Term {
public $links, $model, $options, $curlang, $filter_lang, $pref_lang;
protected $pre_term_name; // Used to store the term name before creating a slug if needed
protected $post_id; // Used to store the current post_id when bulk editing posts
private $tax_query_lang;
/**
* Stores the plugin options.
*
* @var array
*/
public $options;
/**
* @var PLL_Model
*/
public $model;
/**
* @var PLL_Admin_Links
*/
public $links;
/**
* Language selected in the admin language filter.
*
* @var PLL_Language
*/
public $filter_lang;
/**
* Preferred language to assign to the new terms.
*
* @var PLL_Language
*/
public $pref_lang;
/**
* Stores the term name before creating a slug if needed.
*
* @var string
*/
protected $pre_term_name;
/**
* Stores the current post_id when bulk editing posts.
*
* @var int
*/
protected $post_id;
/**
* A reference to the PLL_Admin_Default_Term instance.
*
* @since 2.8
*
* @var PLL_Admin_Default_Term
*/
protected $default_term;
/**
* Constructor: setups filters and actions
@ -20,9 +72,8 @@ class PLL_Admin_Filters_Term {
$this->links = &$polylang->links;
$this->model = &$polylang->model;
$this->options = &$polylang->options;
$this->curlang = &$polylang->curlang;
$this->filter_lang = &$polylang->filter_lang;
$this->pref_lang = &$polylang->pref_lang;
$this->default_term = &$polylang->default_term;
foreach ( $this->model->get_translated_taxonomies() as $tax ) {
// Adds the language field in the 'Categories' and 'Post Tags' panels
@ -30,15 +81,12 @@ class PLL_Admin_Filters_Term {
// Adds the language field and translations tables in the 'Edit Category' and 'Edit Tag' panels
add_action( $tax . '_edit_form_fields', array( $this, 'edit_term_form' ) );
// Adds action related to languages when deleting categories and post tags
add_action( 'delete_' . $tax, array( $this, 'delete_term' ) );
}
// Adds actions related to languages when creating or saving categories and post tags
add_filter( 'wp_dropdown_cats', array( $this, 'wp_dropdown_cats' ) );
add_action( 'create_term', array( $this, 'save_term' ), 999, 3 );
add_action( 'edit_term', array( $this, 'save_term' ), 999, 3 ); // late as it may conflict with other plugins, see http://wordpress.org/support/topic/polylang-and-wordpress-seo-by-yoast
add_action( 'create_term', array( $this, 'save_term' ), 900, 3 );
add_action( 'edit_term', array( $this, 'save_term' ), 900, 3 ); // Late as it may conflict with other plugins, see http://wordpress.org/support/topic/polylang-and-wordpress-seo-by-yoast
add_action( 'pre_post_update', array( $this, 'pre_post_update' ) );
add_filter( 'pre_term_name', array( $this, 'pre_term_name' ) );
add_filter( 'pre_term_slug', array( $this, 'pre_term_slug' ), 10, 2 );
@ -47,18 +95,6 @@ class PLL_Admin_Filters_Term {
add_action( 'wp_ajax_term_lang_choice', array( $this, 'term_lang_choice' ) );
add_action( 'wp_ajax_pll_terms_not_translated', array( $this, 'ajax_terms_not_translated' ) );
// Adds cache domain when querying terms
add_filter( 'get_terms_args', array( $this, 'get_terms_args' ), 10, 2 );
// Filters categories and post tags by language
add_filter( 'terms_clauses', array( $this, 'terms_clauses' ), 10, 3 );
add_action( 'parse_query', array( $this, 'set_tax_query_lang' ) );
add_action( 'posts_selection', array( $this, 'unset_tax_query_lang' ) );
// Allows to get the default categories in all languages
add_filter( 'option_default_category', array( $this, 'option_default_category' ) );
add_action( 'update_option_default_category', array( $this, 'update_option_default_category' ), 10, 2 );
// Updates the translations term ids when splitting a shared term
add_action( 'split_shared_term', array( $this, 'split_shared_term' ), 10, 4 ); // WP 4.2
}
@ -67,77 +103,117 @@ class PLL_Admin_Filters_Term {
* Adds the language field in the 'Categories' and 'Post Tags' panels
*
* @since 0.1
*
* @return void
*/
public function add_term_form() {
$taxonomy = $_GET['taxonomy'];
$post_type = isset( $GLOBALS['post_type'] ) ? $GLOBALS['post_type'] : $_REQUEST['post_type'];
if ( isset( $_GET['taxonomy'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$taxonomy = sanitize_key( $_GET['taxonomy'] ); // phpcs:ignore WordPress.Security.NonceVerification
}
if ( ! taxonomy_exists( $taxonomy ) || ! post_type_exists( $post_type ) ) {
if ( isset( $_REQUEST['post_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$post_type = sanitize_key( $_REQUEST['post_type'] ); // phpcs:ignore WordPress.Security.NonceVerification
}
if ( isset( $GLOBALS['post_type'] ) ) {
$post_type = $GLOBALS['post_type'];
}
if ( ! isset( $taxonomy, $post_type ) || ! taxonomy_exists( $taxonomy ) || ! post_type_exists( $post_type ) ) {
return;
}
$lang = isset( $_GET['new_lang'] ) ? $this->model->get_language( $_GET['new_lang'] ) : $this->pref_lang;
$from_term_id = isset( $_GET['from_tag'] ) ? (int) $_GET['from_tag'] : 0; // phpcs:ignore WordPress.Security.NonceVerification
$lang = isset( $_GET['new_lang'] ) ? $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ) : $this->pref_lang; // phpcs:ignore WordPress.Security.NonceVerification
$dropdown = new PLL_Walker_Dropdown();
$dropdown_html = $dropdown->walk(
$this->model->get_languages_list(),
-1,
array(
'name' => 'term_lang_choice',
'value' => 'term_id',
'selected' => $lang ? $lang->term_id : '',
'flag' => true,
)
);
wp_nonce_field( 'pll_language', '_pll_nonce' );
printf( '
<div class="form-field">
printf(
'<div class="form-field">
<label for="term_lang_choice">%s</label>
<div id="select-add-term-language">%s</div>
<p>%s</p>
</div>',
esc_html__( 'Language', 'polylang' ),
$dropdown->walk( $this->model->get_languages_list(), array(
'name' => 'term_lang_choice',
'value' => 'term_id',
'selected' => $lang ? $lang->term_id : '',
'flag' => true,
) ),
$dropdown_html, // phpcs:ignore
esc_html__( 'Sets the language', 'polylang' )
);
if ( ! empty( $_GET['from_tag'] ) ) {
printf( '<input type="hidden" name="from_tag" value="%d" />', (int) $_GET['from_tag'] );
if ( ! empty( $from_term_id ) ) {
printf( '<input type="hidden" name="from_tag" value="%d" />', (int) $from_term_id );
}
// Adds translation fields
echo '<div id="term-translations" class="form-field">';
if ( $lang ) {
include PLL_ADMIN_INC . '/view-translations-term.php';
include __DIR__ . '/view-translations-term.php';
}
echo '</div>' . "\n";
}
/**
* Adds the language field and translations tables in the 'Edit Category' and 'Edit Tag' panels
* Adds the language field and translations tables in the 'Edit Category' and 'Edit Tag' panels.
*
* @since 0.1
*
* @param object $tag
* @param WP_Term $tag The term being edited.
* @return void
*/
public function edit_term_form( $tag ) {
$post_type = isset( $GLOBALS['post_type'] ) ? $GLOBALS['post_type'] : $_REQUEST['post_type'];
if ( isset( $_REQUEST['post_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$post_type = sanitize_key( $_REQUEST['post_type'] ); // phpcs:ignore WordPress.Security.NonceVerification
}
if ( ! post_type_exists( $post_type ) ) {
if ( isset( $GLOBALS['post_type'] ) ) {
$post_type = $GLOBALS['post_type'];
}
if ( ! isset( $post_type ) || ! post_type_exists( $post_type ) ) {
return;
}
$term_id = $tag->term_id;
$taxonomy = $tag->taxonomy;
$term_id = $tag->term_id;
$taxonomy = $tag->taxonomy; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$lang = $this->model->term->get_language( $term_id );
$lang = empty( $lang ) ? $this->pref_lang : $lang;
// Disable the language dropdown and the translations input fields for default terms to prevent removal
$disabled = $this->default_term->is_default_term( $term_id );
$dropdown = new PLL_Walker_Dropdown();
// Disable the language dropdown and the translations input fields for default categories to prevent removal
$disabled = in_array( get_option( 'default_category' ), $this->model->term->get_translations( $term_id ) );
$dropdown_html = $dropdown->walk(
$this->model->get_languages_list(),
-1,
array(
'name' => 'term_lang_choice',
'value' => 'term_id',
'selected' => $lang->term_id,
'disabled' => $disabled,
'flag' => true,
)
);
printf( '
<tr class="form-field">
wp_nonce_field( 'pll_language', '_pll_nonce' );
printf(
'<tr class="form-field">
<th scope="row">
%s
<label for="term_lang_choice">%s</label>
</th>
<td id="select-edit-term-language">
@ -145,22 +221,13 @@ class PLL_Admin_Filters_Term {
<p class="description">%s</p>
</td>
</tr>',
wp_nonce_field( 'pll_language', '_pll_nonce', true, false ),
esc_html__( 'Language', 'polylang' ),
$dropdown->walk( $this->model->get_languages_list(), array(
'name' => 'term_lang_choice',
'value' => 'term_id',
'selected' => $lang ? $lang->term_id : '',
'disabled' => $disabled,
'flag' => true,
) ),
$dropdown_html, // phpcs:ignore
esc_html__( 'Sets the language', 'polylang' )
);
echo '<tr id="term-translations" class="form-field">';
if ( $lang ) {
include PLL_ADMIN_INC . '/view-translations-term.php';
}
include __DIR__ . '/view-translations-term.php';
echo '</tr>' . "\n";
}
@ -173,10 +240,15 @@ class PLL_Admin_Filters_Term {
* @return string modified html
*/
public function wp_dropdown_cats( $output ) {
if ( isset( $_GET['taxonomy'], $_GET['from_tag'], $_GET['new_lang'] ) && taxonomy_exists( $_GET['taxonomy'] ) ) {
$term = get_term( (int) $_GET['from_tag'], $_GET['taxonomy'] );
if ( $term && $id = $term->parent ) {
$lang = $this->model->get_language( $_GET['new_lang'] );
if ( isset( $_GET['taxonomy'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$taxonomy = sanitize_key( $_GET['taxonomy'] ); // phpcs:ignore WordPress.Security.NonceVerification
}
if ( isset( $taxonomy, $_GET['from_tag'], $_GET['new_lang'] ) && taxonomy_exists( $taxonomy ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$term = get_term( (int) $_GET['from_tag'], $taxonomy ); // phpcs:ignore WordPress.Security.NonceVerification
if ( $term instanceof WP_Term && $id = $term->parent ) {
$lang = $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
if ( $parent = $this->model->term->get_translation( $id, $lang ) ) {
return str_replace( '"' . $parent . '"', '"' . $parent . '" selected="selected"', $output );
}
@ -186,38 +258,19 @@ class PLL_Admin_Filters_Term {
}
/**
* stores the current post_id when bulk editing posts for use in save_language and pre_term_slug
* Stores the current post_id when bulk editing posts for use in save_language and pre_term_slug
*
* @since 1.7
*
* @param int $post_id
* @return void
*/
public function pre_post_update( $post_id ) {
if ( isset( $_GET['bulk_edit'] ) ) {
if ( isset( $_GET['bulk_edit'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$this->post_id = $post_id;
}
}
/**
* Allows to set a language by default for terms if it has no language yet
*
* @since 1.5.4
*
* @param int $term_id
* @param string $taxonomy
*/
protected function set_default_language( $term_id, $taxonomy ) {
if ( ! $this->model->term->get_language( $term_id ) ) {
// Sets language from term parent if exists thanks to Scott Kingsley Clark
if ( ( $term = get_term( $term_id, $taxonomy ) ) && ! empty( $term->parent ) && $parent_lang = $this->model->term->get_language( $term->parent ) ) {
$this->model->term->set_language( $term_id, $parent_lang );
}
else {
$this->model->term->set_language( $term_id, $this->pref_lang );
}
}
}
/**
* Saves language
*
@ -225,6 +278,7 @@ class PLL_Admin_Filters_Term {
*
* @param int $term_id
* @param string $taxonomy
* @return void
*/
protected function save_language( $term_id, $taxonomy ) {
global $wpdb;
@ -233,14 +287,13 @@ class PLL_Admin_Filters_Term {
// Edit tags
if ( isset( $_POST['term_lang_choice'] ) ) {
if ( 'add-' . $taxonomy == $_POST['action'] ) {
check_ajax_referer( $_POST['action'], '_ajax_nonce-add-' . $taxonomy ); // category metabox
}
else {
check_admin_referer( 'pll_language', '_pll_nonce' ); // edit tags or tags metabox
if ( isset( $_POST['action'] ) && sanitize_key( $_POST['action'] ) === 'add-' . $taxonomy ) { // phpcs:ignore WordPress.Security.NonceVerification
check_ajax_referer( 'add-' . $taxonomy, '_ajax_nonce-add-' . $taxonomy ); // Category metabox
} else {
check_admin_referer( 'pll_language', '_pll_nonce' ); // Edit tags or tags metabox
}
$this->model->term->set_language( $term_id, $this->model->get_language( $_POST['term_lang_choice'] ) );
$this->model->term->set_language( $term_id, $this->model->get_language( sanitize_key( $_POST['term_lang_choice'] ) ) );
}
// *Post* bulk edit, in case a new term is created
@ -259,17 +312,22 @@ class PLL_Admin_Filters_Term {
// No WP function to get all terms with the exact same name so let's use a custom query
// $terms = get_terms( $taxonomy, array( 'name' => $term->name, 'hide_empty' => false, 'fields' => 'ids' ) ); should be OK in 4.2
// I may need to rework the loop below
$terms = $wpdb->get_results( $wpdb->prepare( "
SELECT t.term_id FROM $wpdb->terms AS t
INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id
WHERE tt.taxonomy = %s AND t.name = %s",
$taxonomy, $term->name
) );
$terms = $wpdb->get_results(
$wpdb->prepare(
"SELECT t.term_id FROM $wpdb->terms AS t
INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id
WHERE tt.taxonomy = %s AND t.name = %s",
$taxonomy,
$term->name
)
);
// If we have several terms with the same name, they are translations of each other
if ( count( $terms ) > 1 ) {
$translations = array();
foreach ( $terms as $term ) {
$translations[ $this->model->term->get_language( $term->term_id )->slug ] = $term->term_id;
$translations[ $this->model->term->get_language( $term->term_id )->slug ] = $term->term_id;
}
$this->model->term->save_translations( $term_id, $translations );
@ -277,7 +335,9 @@ class PLL_Admin_Filters_Term {
}
else {
$this->model->term->set_language( $term_id, $this->model->get_language( $_GET['inline_lang_choice'] ) );
if ( current_user_can( 'edit_term', $term_id ) ) {
$this->model->term->set_language( $term_id, $this->model->get_language( sanitize_key( $_GET['inline_lang_choice'] ) ) );
}
}
}
@ -288,52 +348,37 @@ class PLL_Admin_Filters_Term {
'_inline_edit'
);
$old_lang = $this->model->term->get_language( $term_id ); // Stores the old language
$lang = $this->model->get_language( $_POST['inline_lang_choice'] ); // New language
$translations = $this->model->term->get_translations( $term_id );
// Checks if the new language already exists in the translation group
if ( $old_lang && $old_lang->slug != $lang->slug ) {
if ( array_key_exists( $lang->slug, $translations ) ) {
$this->model->term->delete_translation( $term_id );
}
elseif ( array_key_exists( $old_lang->slug, $translations ) ) {
unset( $translations[ $old_lang->slug ] );
$this->model->term->save_translations( $term_id, $translations );
}
}
$this->model->term->set_language( $term_id, $lang ); // Set new language
$lang = $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) );
$this->model->term->update_language( $term_id, $lang );
}
// Edit post
elseif ( isset( $_POST['post_lang_choice'] ) ) { // FIXME should be useless now
check_admin_referer( 'pll_language', '_pll_nonce' );
$this->model->term->set_language( $term_id, $this->model->get_language( $_POST['post_lang_choice'] ) );
}
else {
$this->set_default_language( $term_id, $taxonomy );
$this->model->term->set_language( $term_id, $this->model->get_language( sanitize_key( $_POST['post_lang_choice'] ) ) );
}
}
/**
* Save translations from our form
* Save translations from our form.
*
* @since 1.5
*
* @param int $term_id
* @return array
* @param int $term_id The term id of teh term being saved.
* @return int[] The array of translated term ids.
*/
protected function save_translations( $term_id ) {
// Security check as 'wp_update_term' can be called from outside WP admin
// Security check as 'wp_update_term' can be called from outside WP admin.
check_admin_referer( 'pll_language', '_pll_nonce' );
// Save translations after checking the translated term is in the right language ( as well as cast id to int )
foreach ( $_POST['term_tr_lang'] as $lang => $tr_id ) {
$tr_lang = $this->model->term->get_language( (int) $tr_id );
$translations[ $lang ] = $tr_lang && $tr_lang->slug == $lang ? (int) $tr_id : 0;
$translations = array();
// Save translations after checking the translated term is in the right language ( as well as cast id to int ).
if ( isset( $_POST['term_tr_lang'] ) ) {
foreach ( array_map( 'absint', $_POST['term_tr_lang'] ) as $lang => $tr_id ) {
$tr_lang = $this->model->term->get_language( $tr_id );
$translations[ $lang ] = $tr_lang && $tr_lang->slug == $lang ? $tr_id : 0;
}
}
$this->model->term->save_translations( $term_id, $translations );
@ -350,6 +395,7 @@ class PLL_Admin_Filters_Term {
* @param int $term_id
* @param int $tt_id term taxonomy id
* @param string $taxonomy
* @return void
*/
public function save_term( $term_id, $tt_id, $taxonomy ) {
// Does nothing except on taxonomies which are filterable
@ -357,32 +403,21 @@ class PLL_Admin_Filters_Term {
return;
}
$tax = get_taxonomy( $taxonomy );
if ( empty( $tax ) ) {
return;
}
// Capability check
// As 'wp_update_term' can be called from outside WP admin
// 2nd test for creating tags when creating / editing a post
$tax = get_taxonomy( $taxonomy );
if ( current_user_can( $tax->cap->edit_terms ) || ( isset( $_POST['tax_input'][ $taxonomy ] ) && current_user_can( $tax->cap->assign_terms ) ) ) {
if ( current_user_can( $tax->cap->edit_terms ) || ( isset( $_POST['tax_input'][ $taxonomy ] ) && current_user_can( $tax->cap->assign_terms ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$this->save_language( $term_id, $taxonomy );
if ( isset( $_POST['term_tr_lang'] ) ) {
$translations = $this->save_translations( $term_id );
if ( isset( $_POST['term_tr_lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$this->save_translations( $term_id );
}
/**
* Fires after the term language and translations are saved
*
* @since 1.2
*
* @param int $term_id term id
* @param string $taxonomy taxonomy name
* @param array $translations the list of translations term ids
*/
do_action( 'pll_save_term', $term_id, $taxonomy, empty( $translations ) ? $this->model->term->get_translations( $term_id ) : $translations );
}
// Attempts to set a default language even if no capability
else {
$this->set_default_language( $term_id, $taxonomy );
}
}
@ -412,62 +447,57 @@ class PLL_Admin_Filters_Term {
// If the term already exists in another language
if ( ! $slug && $this->model->is_translated_taxonomy( $taxonomy ) && term_exists( $name, $taxonomy ) ) {
if ( isset( $_POST['term_lang_choice'] ) ) {
$slug = $name . '-' . $this->model->get_language( $_POST['term_lang_choice'] )->slug;
if ( isset( $_POST['term_lang_choice'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$lang = $this->model->get_language( sanitize_key( $_POST['term_lang_choice'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
}
elseif ( isset( $_POST['inline_lang_choice'] ) ) {
$slug = $name . '-' . $this->model->get_language( $_POST['inline_lang_choice'] )->slug;
elseif ( isset( $_POST['inline_lang_choice'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$lang = $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
}
// *Post* bulk edit, in case a new term is created
elseif ( isset( $_GET['bulk_edit'], $_GET['inline_lang_choice'] ) ) {
elseif ( isset( $_GET['bulk_edit'], $_GET['inline_lang_choice'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
// Bulk edit does not modify the language
if ( -1 == $_GET['inline_lang_choice'] ) {
$slug = $name . '-' . $this->model->post->get_language( $this->post_id )->slug;
if ( -1 == $_GET['inline_lang_choice'] ) { // phpcs:ignore WordPress.Security.NonceVerification
$lang = $this->model->post->get_language( $this->post_id );
} else {
$slug = $name . '-' . $this->model->get_language( $_GET['inline_lang_choice'] )->slug;
$lang = $this->model->get_language( sanitize_key( $_GET['inline_lang_choice'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
}
}
if ( ! empty( $lang ) && ! $this->model->term_exists_by_slug( $name, $lang, $taxonomy ) ) {
$slug = $name . '-' . $lang->slug;
}
}
return $slug;
}
/**
* Called when a category or post tag is deleted
* Deletes language and translations
*
* @since 0.1
*
* @param int $term_id
*/
public function delete_term( $term_id ) {
$this->model->term->delete_translation( $term_id );
$this->model->term->delete_language( $term_id );
}
/**
* Ajax response for edit term form
*
* @since 0.2
*
* @return void
*/
public function term_lang_choice() {
check_ajax_referer( 'pll_language', '_pll_nonce' );
$lang = $this->model->get_language( $_POST['lang'] );
$term_id = isset( $_POST['term_id'] ) ? (int) $_POST['term_id'] : null;
$taxonomy = $_POST['taxonomy'];
$post_type = $_POST['post_type'];
if ( ! isset( $_POST['taxonomy'], $_POST['post_type'], $_POST['lang'] ) ) {
wp_die( 0 );
}
if ( ! post_type_exists( $post_type ) || ! taxonomy_exists( $taxonomy ) ) {
die( 0 );
$lang = $this->model->get_language( sanitize_key( $_POST['lang'] ) );
$term_id = isset( $_POST['term_id'] ) ? (int) $_POST['term_id'] : null; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$taxonomy = sanitize_key( $_POST['taxonomy'] );
$post_type = sanitize_key( $_POST['post_type'] );
if ( empty( $lang ) || ! post_type_exists( $post_type ) || ! taxonomy_exists( $taxonomy ) ) {
wp_die( 0 );
}
ob_start();
if ( $lang ) {
include PLL_ADMIN_INC . '/view-translations-term.php';
}
include __DIR__ . '/view-translations-term.php';
$x = new WP_Ajax_Response( array( 'what' => 'translations', 'data' => ob_get_contents() ) );
ob_end_clean();
@ -475,14 +505,14 @@ class PLL_Admin_Filters_Term {
// $args copied from edit_tags.php except echo
if ( is_taxonomy_hierarchical( $taxonomy ) ) {
$args = array(
'hide_empty' => 0,
'hide_if_empty' => false,
'taxonomy' => $taxonomy,
'name' => 'parent',
'orderby' => 'name',
'hierarchical' => true,
'show_option_none' => __( 'None' ),
'echo' => 0,
'hide_empty' => 0,
'hide_if_empty' => false,
'taxonomy' => $taxonomy,
'name' => 'parent',
'orderby' => 'name',
'hierarchical' => true,
'show_option_none' => __( 'None', 'polylang' ),
'echo' => 0,
);
$x->Add( array( 'what' => 'parent', 'data' => wp_dropdown_categories( $args ) ) );
}
@ -491,7 +521,7 @@ class PLL_Admin_Filters_Term {
// Tests copied from edit_tags.php
else {
$tax = get_taxonomy( $taxonomy );
if ( ! is_null( $tax->labels->popular_items ) ) {
if ( ! empty( $tax ) && ! is_null( $tax->labels->popular_items ) ) {
$args = array( 'taxonomy' => $taxonomy, 'echo' => false );
if ( current_user_can( $tax->cap->edit_terms ) ) {
$args = array_merge( $args, array( 'link' => 'edit' ) );
@ -514,202 +544,71 @@ class PLL_Admin_Filters_Term {
* Ajax response for input in translation autocomplete input box
*
* @since 1.5
*
* @return void
*/
public function ajax_terms_not_translated() {
check_ajax_referer( 'pll_language', '_pll_nonce' );
$s = wp_unslash( $_GET['term'] );
$post_type = $_GET['post_type'];
$taxonomy = $_GET['taxonomy'];
if ( ! post_type_exists( $post_type ) || ! taxonomy_exists( $taxonomy ) ) {
die( 0 );
if ( ! isset( $_GET['term'], $_GET['post_type'], $_GET['taxonomy'], $_GET['term_language'], $_GET['translation_language'] ) ) {
wp_die( 0 );
}
$term_language = $this->model->get_language( $_GET['term_language'] );
$translation_language = $this->model->get_language( $_GET['translation_language'] );
/** @var string */
$s = wp_unslash( $_GET['term'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
$post_type = sanitize_key( $_GET['post_type'] );
$taxonomy = sanitize_key( $_GET['taxonomy'] );
if ( ! post_type_exists( $post_type ) || ! taxonomy_exists( $taxonomy ) ) {
wp_die( 0 );
}
$term_language = $this->model->get_language( sanitize_key( $_GET['term_language'] ) );
$translation_language = $this->model->get_language( sanitize_key( $_GET['translation_language'] ) );
$terms = array();
$return = array();
// It is more efficient to use one common query for all languages as soon as there are more than 2
foreach ( get_terms( $taxonomy, 'hide_empty=0&lang=0&name__like=' . $s ) as $term ) {
$lang = $this->model->term->get_language( $term->term_id );
// Add current translation in list.
// Not in add term as term_id is not set.
if ( isset( $_GET['term_id'] ) && 'undefined' !== $_GET['term_id'] && $term_id = $this->model->term->get_translation( (int) $_GET['term_id'], $translation_language ) ) {
$terms = array( get_term( $term_id, $taxonomy ) );
}
if ( $lang && $lang->slug == $translation_language->slug && ! $this->model->term->get_translation( $term->term_id, $term_language ) ) {
// It is more efficient to use one common query for all languages as soon as there are more than 2.
$all_terms = get_terms( $taxonomy, 'hide_empty=0&lang=0&name__like=' . $s );
if ( is_array( $all_terms ) ) {
foreach ( $all_terms as $term ) {
$lang = $this->model->term->get_language( $term->term_id );
if ( $lang && $lang->slug == $translation_language->slug && ! $this->model->term->get_translation( $term->term_id, $term_language ) ) {
$terms[] = $term;
}
}
}
// Format the ajax response.
foreach ( $terms as $term ) {
if ( $term instanceof WP_Term ) {
$return[] = array(
'id' => $term->term_id,
'value' => $term->name,
'link' => $this->links->edit_term_translation_link( $term->term_id, $taxonomy, $post_type ),
'id' => $term->term_id,
'value' => rtrim( // Trim the seperator added at the end by WP.
get_term_parents_list(
$term->term_id,
$term->taxonomy,
array(
'separator' => ' > ',
'link' => false,
)
),
' >'
),
'link' => $this->links->edit_term_translation_link( $term->term_id, $term->taxonomy, $post_type ),
);
}
}
// Add current translation in list
// Not in add term for as term_id is not set
if ( 'undefined' !== $_GET['term_id'] && $term_id = $this->model->term->get_translation( (int) $_GET['term_id'], $translation_language ) ) {
$term = get_term( $term_id, $taxonomy );
array_unshift( $return, array(
'id' => $term_id,
'value' => $term->name,
'link' => $this->links->edit_term_translation_link( $term->term_id, $taxonomy, $post_type ),
) );
}
wp_die( json_encode( $return ) );
}
/**
* Get the language(s) to filter get_terms
*
* @since 1.7.6
*
* @param array $taxonomies queried taxonomies
* @param array $args get_terms arguments
* @return object|string|bool the language(s) to use in the filter, false otherwise
*/
protected function get_queried_language( $taxonomies, $args ) {
// Does nothing except on taxonomies which are filterable
// Since WP 4.7, make sure not to filter wp_get_object_terms()
if ( ! $this->model->is_translated_taxonomy( $taxonomies ) || ! empty( $args['object_ids'] ) ) {
return false;
}
if ( isset( $this->tax_query_lang ) ) {
$args['lang'] = $this->tax_query_lang;
}
// If get_terms is queried with a 'lang' parameter
if ( isset( $args['lang'] ) ) {
return $args['lang'];
}
// On tags page, everything should be filtered according to the admin language filter except the parent dropdown
if ( 'edit-tags.php' === $GLOBALS['pagenow'] && empty( $args['class'] ) ) {
return $this->filter_lang;
}
return $this->curlang;
}
/**
* Adds language dependent cache domain when querying terms
* Useful as the 'lang' parameter is not included in cache key by WordPress
*
* @since 1.3
*
* @param array $args
* @param array $taxonomies
* @return array modified arguments
*/
public function get_terms_args( $args, $taxonomies ) {
// don't break _get_term_hierarchy()
if ( 'all' === $args['get'] && 'id' === $args['orderby'] && 'id=>parent' === $args['fields'] ) {
$args['lang'] = '';
}
if ( $lang = $this->get_queried_language( $taxonomies, $args ) ) {
$lang = is_string( $lang ) && strpos( $lang, ',' ) ? explode( ',', $lang ) : $lang;
$key = '_' . ( is_array( $lang ) ? implode( ',', $lang ) : $this->model->get_language( $lang )->slug );
$args['cache_domain'] = empty( $args['cache_domain'] ) ? 'pll' . $key : $args['cache_domain'] . $key;
}
return $args;
}
/**
* Filters categories and post tags by language(s) when needed on admin side
*
* @since 0.5
*
* @param array $clauses list of sql clauses
* @param array $taxonomies list of taxonomies
* @param array $args get_terms arguments
* @return array modified sql clauses
*/
public function terms_clauses( $clauses, $taxonomies, $args ) {
$lang = $this->get_queried_language( $taxonomies, $args );
return ! empty( $lang ) ? $this->model->terms_clauses( $clauses, $lang ) : $clauses; // adds our clauses to filter by current language
}
/**
* Sets the WP_Term_Query language when doing a WP_Query
* Needed since WP 4.9
*
* @since 2.3.2
*
* @param object $query WP_Query object
*/
public function set_tax_query_lang( $query ) {
$this->tax_query_lang = isset( $query->query_vars['lang'] ) ? $query->query_vars['lang'] : '';
}
/**
* Removes the WP_Term_Query language filter for WP_Query
* Needed since WP 4.9
*
* @since 2.3.2
*/
public function unset_tax_query_lang() {
unset( $this->tax_query_lang );
}
/**
* Hack to avoid displaying delete link for the default category in all languages
* Also returns the default category in the right language when called from wp_delete_term
*
* @since 1.2
*
* @param int $value
* @return int
*/
public function option_default_category( $value ) {
// Filters the default category in note below the category list table and in settings->writing dropdown
if ( isset( $this->pref_lang ) && $tr = $this->model->term->get( $value, $this->pref_lang ) ) {
$value = $tr;
}
// FIXME backward compatibility with WP < 4.7
if ( version_compare( $GLOBALS['wp_version'], '4.7alpha', '<' ) ) {
$traces = debug_backtrace();
$n = version_compare( PHP_VERSION, '7', '>=' ) ? 3 : 4; // PHP 7 does not include call_user_func_array
if ( isset( $traces[ $n ] ) ) {
// FIXME 'column_name' for backward compatibility with WP < 4.3
if ( in_array( $traces[ $n ]['function'], array( 'column_cb', 'column_name', 'handle_row_actions' ) ) && in_array( $traces[ $n ]['args'][0]->term_id, $this->model->term->get_translations( $value ) ) ) {
return $traces[ $n ]['args'][0]->term_id;
}
if ( 'wp_delete_term' == $traces[ $n ]['function'] ) {
return $this->model->term->get( $value, $this->model->term->get_language( $traces[ $n ]['args'][0] ) );
}
}
}
return $value;
}
/**
* Checks if the new default category is translated in all languages
* If not, create the translations
*
* @since 1.7
*
* @param int $old_value
* @param int $value
*/
public function update_option_default_category( $old_value, $value ) {
$default_cat_lang = $this->model->term->get_language( $value );
// Assign a default language to default category
if ( ! $default_cat_lang ) {
$default_cat_lang = $this->model->get_language( $this->options['default_lang'] );
$this->model->term->set_language( (int) $value, $default_cat_lang );
}
foreach ( $this->model->get_languages_list() as $language ) {
if ( $language->slug != $default_cat_lang->slug && ! $this->model->term->get_translation( $value, $language ) ) {
$this->model->create_default_category( $language );
}
}
wp_die( wp_json_encode( $return ) );
}
/**
@ -722,6 +621,7 @@ class PLL_Admin_Filters_Term {
* @param int $new_term_id
* @param int $term_taxonomy_id
* @param string $taxonomy
* @return void
*/
public function split_shared_term( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) {
if ( ! $this->model->is_translated_taxonomy( $taxonomy ) ) {
@ -734,8 +634,13 @@ class PLL_Admin_Filters_Term {
return;
}
$avoid_recursion = true;
$lang = $this->model->term->get_language( $term_id );
if ( empty( $lang ) ) {
return;
}
$avoid_recursion = true;
$translations = array();
foreach ( $this->model->term->get_translations( $term_id ) as $key => $tr_id ) {
if ( $lang->slug == $key ) {
@ -746,7 +651,7 @@ class PLL_Admin_Filters_Term {
$translations[ $key ] = _split_shared_term( $tr_id, $tr_term->term_taxonomy_id );
// Hack translation ids sent by the form to avoid overwrite in PLL_Admin_Filters_Term::save_translations
if ( isset( $_POST['term_tr_lang'][ $key ] ) && $_POST['term_tr_lang'][ $key ] == $tr_id ) {
if ( isset( $_POST['term_tr_lang'][ $key ] ) && $_POST['term_tr_lang'][ $key ] == $tr_id ) { // phpcs:ignore WordPress.Security.NonceVerification
$_POST['term_tr_lang'][ $key ] = $translations[ $key ];
}
}

View file

@ -0,0 +1,35 @@
<?php
/**
* @package Polylang
*/
/**
* Class PLL_Widgets_Filters
*
* @since 3.0
*
* Adds new options to {@see https://developer.wordpress.org/reference/classes/wp_widget/ WP_Widget} and saves them.
*/
class PLL_Admin_Filters_Widgets_Options extends PLL_Filters_Widgets_Options {
/**
* Modifies the widgets forms to add our language dropdown list.
*
* @since 0.3
* @since 3.0 Moved from PLL_Admin_Filters
*
* @param WP_Widget $widget Widget instance.
* @param null $return Not used.
* @param array $instance Widget settings.
* @return void
*/
public function in_widget_form( $widget, $return, $instance ) {
$screen = get_current_screen();
// Test the Widgets screen and the Customizer to avoid displaying the option in page builders
// Saving the widget reloads the form. And curiously the action is in $_REQUEST but neither in $_POST, nor in $_GET.
if ( ( isset( $screen ) && 'widgets' === $screen->base ) || ( isset( $_REQUEST['action'] ) && 'save-widget' === $_REQUEST['action'] ) || isset( $GLOBALS['wp_customize'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
parent::in_widget_form( $widget, $return, $instance );
}
}
}

View file

@ -1,4 +1,7 @@
<?php
/**
* @package Polylang
*/
/**
* Setup miscellaneous admin filters as well as filters common to admin and frontend
@ -17,87 +20,19 @@ class PLL_Admin_Filters extends PLL_Filters {
public function __construct( &$polylang ) {
parent::__construct( $polylang );
// Widgets languages filter
add_action( 'in_widget_form', array( $this, 'in_widget_form' ), 10, 3 );
add_filter( 'widget_update_callback', array( $this, 'widget_update_callback' ), 10, 4 );
// Language management for users
add_action( 'personal_options_update', array( $this, 'personal_options_update' ) );
add_action( 'edit_user_profile_update', array( $this, 'personal_options_update' ) );
add_action( 'personal_options', array( $this, 'personal_options' ) );
// Upgrades languages files after a core upgrade ( timing is important )
// Backward compatibility WP < 4.0 *AND* Polylang < 1.6
add_action( '_core_updated_successfully', array( $this, 'upgrade_languages' ), 1 ); // since WP 3.3
// Upgrades plugins and themes translations files
add_filter( 'themes_update_check_locales', array( $this, 'update_check_locales' ) );
add_filter( 'plugins_update_check_locales', array( $this, 'update_check_locales' ) );
// We need specific filters for German and Danish
$specific_locales = array( 'da_DK', 'de_DE', 'de_DE_formal', 'de_CH', 'de_CH_informal', 'ca', 'sr_RS', 'bs_BA' );
if ( array_intersect( $this->model->get_languages_list( array( 'fields' => 'locale' ) ), $specific_locales ) ) {
add_filter( 'sanitize_title', array( $this, 'sanitize_title' ), 10, 3 );
add_filter( 'sanitize_user', array( $this, 'sanitize_user' ), 10, 3 );
}
add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
}
/**
* Modifies the widgets forms to add our language dropdown list
*
* @since 0.3
*
* @param object $widget Widget instance
* @param null $return Not used
* @param array $instance Widget settings
*/
public function in_widget_form( $widget, $return, $instance ) {
$screen = get_current_screen();
// Test the Widgets screen and the Customizer to avoid displaying the option in page builders
// Saving the widget reloads the form. And curiously the action is in $_REQUEST but neither in $_POST, not in $_GET.
if ( ( isset( $screen ) && 'widgets' === $screen->base ) || ( isset( $_REQUEST['action'] ) && 'save-widget' === $_REQUEST['action'] ) || isset( $GLOBALS['wp_customize'] ) ) {
$dropdown = new PLL_Walker_Dropdown();
printf( '<p><label for="%1$s">%2$s %3$s</label></p>',
esc_attr( $widget->id . '_lang_choice' ),
esc_html__( 'The widget is displayed for:', 'polylang' ),
$dropdown->walk(
array_merge(
array( (object) array( 'slug' => 0, 'name' => __( 'All languages', 'polylang' ) ) ),
$this->model->get_languages_list()
),
array(
'name' => $widget->id . '_lang_choice',
'class' => 'tags-input',
'selected' => empty( $instance['pll_lang'] ) ? '' : $instance['pll_lang'],
)
)
);
}
}
/**
* Called when widget options are saved
* saves the language associated to the widget
*
* @since 0.3
*
* @param array $instance Widget options
* @param array $new_instance Not used
* @param array $old_instance Not used
* @param object $widget WP_Widget object
* @return array Widget options
*/
public function widget_update_callback( $instance, $new_instance, $old_instance, $widget ) {
if ( ! empty( $_POST[ $key = $widget->id . '_lang_choice' ] ) && in_array( $_POST[ $key ], $this->model->get_languages_list( array( 'fields' => 'slug' ) ) ) ) {
$instance['pll_lang'] = $_POST[ $key ];
} else {
unset( $instance['pll_lang'] );
}
return $instance;
// Add post state for translations of the privacy policy page
add_filter( 'display_post_states', array( $this, 'display_post_states' ), 10, 2 );
}
/**
@ -106,19 +41,13 @@ class PLL_Admin_Filters extends PLL_Filters {
* @since 0.4
*
* @param int $user_id
* @return void
*/
public function personal_options_update( $user_id ) {
// Admin language
// FIXME Backward compatibility with WP < 4.7
if ( version_compare( $GLOBALS['wp_version'], '4.7alpha', '<' ) ) {
$user_lang = in_array( $_POST['user_lang'], $this->model->get_languages_list( array( 'fields' => 'locale' ) ) ) ? $_POST['user_lang'] : 0;
update_user_meta( $user_id, 'locale', $user_lang );
}
// Biography translations
foreach ( $this->model->get_languages_list() as $lang ) {
$meta = $lang->slug == $this->options['default_lang'] ? 'description' : 'description_' . $lang->slug;
$description = empty( $_POST[ 'description_' . $lang->slug ] ) ? '' : trim( $_POST[ 'description_' . $lang->slug ] );
$description = empty( $_POST[ 'description_' . $lang->slug ] ) ? '' : trim( $_POST[ 'description_' . $lang->slug ] ); // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput
/** This filter is documented in wp-includes/user.php */
$description = apply_filters( 'pre_user_description', $description ); // Applies WP default filter wp_filter_kses
@ -127,44 +56,22 @@ class PLL_Admin_Filters extends PLL_Filters {
}
/**
* Form for language user preference in user profile
* Outputs hidden information to modify the biography form with js.
*
* @since 0.4
*
* @param object $profileuser
* @param WP_User $profileuser The current WP_User object.
* @return void
*/
public function personal_options( $profileuser ) {
// FIXME: Backward compatibility with WP < 4.7
if ( version_compare( $GLOBALS['wp_version'], '4.7alpha', '<' ) ) {
$dropdown = new PLL_Walker_Dropdown();
printf( '
<tr>
<th><label for="user_lang">%s</label></th>
<td>%s</td>
</tr>',
esc_html__( 'Admin language', 'polylang' ),
$dropdown->walk(
array_merge(
array( (object) array( 'locale' => 0, 'name' => __( 'WordPress default', 'polylang' ) ) ),
$this->model->get_languages_list()
),
array(
'name' => 'user_lang',
'value' => 'locale',
'selected' => get_user_meta( $profileuser->ID, 'locale', true ),
)
)
);
}
// Hidden information to modify the biography form with js
foreach ( $this->model->get_languages_list() as $lang ) {
$meta = $lang->slug == $this->options['default_lang'] ? 'description' : 'description_' . $lang->slug;
/** This filter is documented in wp-includes/user.php */
$description = apply_filters( 'user_description', get_user_meta( $profileuser->ID, $meta, true ) ); // Applies WP default filter wp_kses_data
printf( '<input type="hidden" class="biography" name="%s___%s" value="%s" />',
printf(
'<input type="hidden" class="biography" name="%s___%s" value="%s" />',
esc_attr( $lang->slug ),
esc_attr( $lang->name ),
esc_attr( $description )
@ -173,95 +80,15 @@ class PLL_Admin_Filters extends PLL_Filters {
}
/**
* Upgrades languages files after a core upgrade
* only for backward compatibility WP < 4.0 *AND* Polylang < 1.6
*
* @since 0.6
*
* @param string $version new WP version
*/
public function upgrade_languages( $version ) {
// $GLOBALS['wp_version'] is the old WP version
if ( version_compare( $version, '4.0', '>=' ) && version_compare( $GLOBALS['wp_version'], '4.0', '<' ) ) {
/** This filter is documented in wp-admin/includes/update-core.php */
apply_filters( 'update_feedback', __( 'Upgrading language files&#8230;', 'polylang' ) );
PLL_Upgrade::download_language_packs();
}
}
/**
* Allows to update translations files for plugins and themes
* Allows to update translations files for plugins and themes.
*
* @since 1.6
*
* @param array $locales Not used
* @return array list of locales to update
* @param string[] $locales List of locales to update for plugins and themes.
* @return string[]
*/
function update_check_locales( $locales ) {
return $this->model->get_languages_list( array( 'fields' => 'locale' ) );
}
/**
* Filters the locale according to the current language instead of the language
* of the admin interface
*
* @since 2.0
*
* @param string $locale
* @return string
*/
public function get_locale( $locale ) {
return $this->curlang->locale;
}
/**
* Maybe fix the result of sanitize_title() in case the languages include German or Danish
* Without this filter, if language of the title being sanitized is different from the language
* used for the admin interface and if one this language is German or Danish, some specific
* characters such as ä, ö, ü, ß are incorrectly sanitized.
*
* @since 2.0
*
* @param string $title Sanitized title.
* @param string $raw_title The title prior to sanitization.
* @param string $context The context for which the title is being sanitized.
* @return string
*/
public function sanitize_title( $title, $raw_title, $context ) {
static $once = false;
if ( ! $once && 'save' == $context && ! empty( $this->curlang ) && ! empty( $title ) ) {
$once = true;
add_filter( 'locale', array( $this, 'get_locale' ), 20 ); // After the filter for the admin interface
$title = sanitize_title( $raw_title, '', $context );
remove_filter( 'locale', array( $this, 'get_locale' ), 20 );
$once = false;
}
return $title;
}
/**
* Maybe fix the result of sanitize_user() in case the languages include German or Danish
*
* @since 2.0
*
* @param string $username Sanitized username.
* @param string $raw_username The username prior to sanitization.
* @param bool $strict Whether to limit the sanitization to specific characters. Default false.
* @return string
*/
public function sanitize_user( $username, $raw_username, $strict ) {
static $once = false;
if ( ! $once && ! empty( $this->curlang ) ) {
$once = true;
add_filter( 'locale', array( $this, 'get_locale' ), 20 ); // After the filter for the admin interface
$username = sanitize_user( $raw_username, '', $strict );
remove_filter( 'locale', array( $this, 'get_locale' ), 20 );
$once = false;
}
return $username;
public function update_check_locales( $locales ) {
return array_merge( $locales, $this->model->get_languages_list( array( 'fields' => 'locale' ) ) );
}
/**
@ -278,4 +105,23 @@ class PLL_Admin_Filters extends PLL_Filters {
}
return $classes;
}
/**
* Adds post state for translations of the privacy policy page.
*
* @since 2.7
*
* @param string[] $post_states An array of post display states.
* @param WP_Post $post The current post object.
* @return string[]
*/
public function display_post_states( $post_states, $post ) {
$page_for_privacy_policy = get_option( 'wp_page_for_privacy_policy' );
if ( $page_for_privacy_policy && in_array( $post->ID, $this->model->post->get_translations( $page_for_privacy_policy ) ) ) {
$post_states['page_for_privacy_policy'] = __( 'Privacy Policy Page', 'polylang' );
}
return $post_states;
}
}

View file

@ -1,89 +1,52 @@
<?php
/**
* @package Polylang
*/
/**
* manages links related functions
* Manages links related functions.
*
* @since 1.8
*/
class PLL_Admin_Links extends PLL_Links {
/**
* get the link to create a new post translation
* Returns the html markup for a new translation link.
*
* @since 1.5
* @since 2.6
*
* @param int $post_id the source post id
* @param object $language the language of the new translation
* @param string $link The new translation link.
* @param PLL_Language $language The language of the new translation.
* @return string
*/
public function get_new_post_translation_link( $post_id, $language ) {
$post_type = get_post_type( $post_id );
$post_type_object = get_post_type_object( get_post_type( $post_id ) );
if ( ! current_user_can( $post_type_object->cap->create_posts ) ) {
return '';
}
protected function new_translation_link( $link, $language ) {
$str = '';
if ( 'attachment' == $post_type ) {
$args = array(
'action' => 'translate_media',
'from_media' => $post_id,
'new_lang' => $language->slug,
);
// add nonce for media as we will directly publish a new attachment from a click on this link
$link = wp_nonce_url( add_query_arg( $args, admin_url( 'admin.php' ) ), 'translate_media' );
} else {
$args = array(
'post_type' => $post_type,
'from_post' => $post_id,
'new_lang' => $language->slug,
);
$link = add_query_arg( $args, admin_url( 'post-new.php' ) );
}
/**
* Filter the new post translation link
*
* @since 1.8
*
* @param string $link the new post translation link
* @param object $language the language of the new translation
* @param int $post_id the source post id
*/
return apply_filters( 'pll_get_new_post_translation_link', $link, $language, $post_id );
}
/**
* returns html markup for a new post translation link
*
* @since 1.8
*
* @param int $post_id
* @param object $language
* @return string
*/
public function new_post_translation_link( $post_id, $language ) {
$link = $this->get_new_post_translation_link( $post_id, $language );
return $link ? sprintf(
'<a href="%1$s" class="pll_icon_add"><span class="screen-reader-text">%2$s</span></a>',
esc_url( $link ),
if ( $link ) {
/* translators: accessibility text, %s is a native language name */
esc_html( sprintf( __( 'Add a translation in %s', 'polylang' ), $language->name ) )
) : '';
$hint = sprintf( __( 'Add a translation in %s', 'polylang' ), $language->name );
$str = sprintf(
'<a href="%1$s" title="%2$s" class="pll_icon_add"><span class="screen-reader-text">%3$s</span></a>',
esc_url( $link ),
esc_attr( $hint ),
esc_html( $hint )
);
}
return $str;
}
/**
* returns html markup for a translation link
* Returns the html markup for a translation link.
*
* @since 1.4
* @since 2.6
*
* @param int $post_id translation post id
* @param string $link The translation link.
* @param PLL_Language $language The language of the translation.
* @return string
*/
public function edit_post_translation_link( $post_id ) {
$link = get_edit_post_link( $post_id );
$language = $this->model->post->get_language( $post_id );
public function edit_translation_link( $link, $language ) {
return $link ? sprintf(
'<a href="%1$s" class="pll_icon_edit"><span class="screen-reader-text">%2$s</span></a>',
esc_url( $link ),
@ -93,14 +56,111 @@ class PLL_Admin_Links extends PLL_Links {
}
/**
* get the link to create a new term translation
* Get the link to create a new post translation.
*
* @since 1.5
*
* @param int $term_id
* @param string $taxonomy
* @param string $post_type
* @param object $language
* @param int $post_id The source post id.
* @param PLL_Language $language The language of the new translation.
* @param string $context Optional. Defaults to 'display' which encodes '&' to '&amp;'.
* Otherwise, preserves '&'.
* @return string
*/
public function get_new_post_translation_link( $post_id, $language, $context = 'display' ) {
$post_type = get_post_type( $post_id );
$post_type_object = get_post_type_object( get_post_type( $post_id ) );
if ( empty( $post_type_object ) || ! current_user_can( $post_type_object->cap->create_posts ) ) {
return '';
}
// Special case for the privacy policy page which is associated to a specific capability
if ( 'page' === $post_type_object->name && ! current_user_can( 'manage_privacy_options' ) ) {
$privacy_page = get_option( 'wp_page_for_privacy_policy' );
if ( $privacy_page && in_array( $post_id, $this->model->post->get_translations( $privacy_page ) ) ) {
return '';
}
}
if ( 'attachment' === $post_type ) {
$args = array(
'action' => 'translate_media',
'from_media' => $post_id,
'new_lang' => $language->slug,
);
$link = add_query_arg( $args, admin_url( 'admin.php' ) );
// Add nonce for media as we will directly publish a new attachment from a click on this link
if ( 'display' === $context ) {
$link = wp_nonce_url( $link, 'translate_media' );
} else {
$link = add_query_arg( '_wpnonce', wp_create_nonce( 'translate_media' ), $link );
}
} else {
$args = array(
'post_type' => $post_type,
'from_post' => $post_id,
'new_lang' => $language->slug,
);
$link = add_query_arg( $args, admin_url( 'post-new.php' ) );
if ( 'display' === $context ) {
$link = wp_nonce_url( $link, 'new-post-translation' );
} else {
$link = add_query_arg( '_wpnonce', wp_create_nonce( 'new-post-translation' ), $link );
}
}
/**
* Filters the new post translation link.
*
* @since 1.8
*
* @param string $link The new post translation link.
* @param PLL_Language $language The language of the new translation.
* @param int $post_id The source post id.
*/
return apply_filters( 'pll_get_new_post_translation_link', $link, $language, $post_id );
}
/**
* Returns the html markup for a new post translation link.
*
* @since 1.8
*
* @param int $post_id The source post id.
* @param PLL_Language $language The language of the new translation.
* @return string
*/
public function new_post_translation_link( $post_id, $language ) {
$link = $this->get_new_post_translation_link( $post_id, $language );
return $this->new_translation_link( $link, $language );
}
/**
* Returns the html markup for a post translation link.
*
* @since 1.4
*
* @param int $post_id The translation post id.
* @return string
*/
public function edit_post_translation_link( $post_id ) {
$link = get_edit_post_link( $post_id );
$language = $this->model->post->get_language( $post_id );
return $this->edit_translation_link( $link, $language );
}
/**
* Get the link to create a new term translation.
*
* @since 1.5
*
* @param int $term_id Source term id.
* @param string $taxonomy Taxonomy name.
* @param string $post_type Post type name.
* @param PLL_Language $language The language of the new translation.
* @return string
*/
public function get_new_term_translation_link( $term_id, $taxonomy, $post_type, $language ) {
@ -119,59 +179,48 @@ class PLL_Admin_Links extends PLL_Links {
$link = add_query_arg( $args, admin_url( 'edit-tags.php' ) );
/**
* Filter the new term translation link
* Filters the new term translation link.
*
* @since 1.8
*
* @param string $link the new term translation link
* @param object $language the language of the new translation
* @param int $term_id the source term id
* @param string $taxonomy
* @param string $post_type
* @param string $link The new term translation link.
* @param PLL_Language $language The language of the new translation.
* @param int $term_id The source term id.
* @param string $taxonomy Taxonomy name.
* @param string $post_type Post type name.
*/
return apply_filters( 'pll_get_new_term_translation_link', $link, $language, $term_id, $taxonomy, $post_type );
}
/**
* returns html markup for a new term translation
* Returns the html markup for a new term translation.
*
* @since 1.8
*
* @param int $term_id
* @param string $taxonomy
* @param string $post_type
* @param object $language
* @param int $term_id Source term id.
* @param string $taxonomy Taxonomy name.
* @param string $post_type Post type name.
* @param PLL_Language $language The language of the new translation.
* @return string
*/
public function new_term_translation_link( $term_id, $taxonomy, $post_type, $language ) {
$link = $this->get_new_term_translation_link( $term_id, $taxonomy, $post_type, $language );
return $link ? sprintf(
'<a href="%1$s" class="pll_icon_add"><span class="screen-reader-text">%2$s</span></a>',
esc_url( $link ),
/* translators: accessibility text, %s is a native language name */
esc_html( sprintf( __( 'Add a translation in %s', 'polylang' ), $language->name ) )
) : '';
return $this->new_translation_link( $link, $language );
}
/**
* returns html markup for a term translation link
* Returns the html markup for a term translation link.
*
* @since 1.4
*
* @param object $term_id translation term id
* @param string $taxonomy
* @param string $post_type
* @param int $term_id Translation term id.
* @param string $taxonomy Taxonomy name.
* @param string $post_type Post type name.
* @return string
*/
public function edit_term_translation_link( $term_id, $taxonomy, $post_type ) {
$link = get_edit_term_link( $term_id, $taxonomy, $post_type );
$language = $this->model->term->get_language( $term_id );
return $link ? sprintf(
'<a href="%1$s" class="pll_icon_edit"><span class="screen-reader-text">%2$s</span></a>',
esc_url( $link ),
/* translators: accessibility text, %s is a native language name */
esc_html( sprintf( __( 'Edit the translation in %s', 'polylang' ), $language->name ) )
) : '';
return $this->edit_translation_link( $link, $language );
}
}

View file

@ -1,7 +1,10 @@
<?php
/**
* @package Polylang
*/
/**
* Extends the PLL_Model class with methods needed only in Polylang settings pages
* Extends the PLL_Model class with methods needed only in Polylang settings pages.
*
* @since 1.2
*/
@ -9,36 +12,33 @@ class PLL_Admin_Model extends PLL_Model {
/**
* Adds a new language
* Creates a default category for this language
*
* List of arguments that $args must contain:
* name -> language name ( used only for display )
* slug -> language code ( ideally 2-letters ISO 639-1 language code )
* locale -> WordPress locale. If something wrong is used for the locale, the .mo files will not be loaded...
* rtl -> 1 if rtl language, 0 otherwise
* term_group -> language order when displayed
*
* Optional arguments that $args can contain:
* no_default_cat -> if set, no default category will be created for this language
* flag -> country code, see flags.php
* and creates a default category for this language.
*
* @since 1.2
*
* @param array $args
* @return bool true if success / false if failed
* @param array $args {
* @type string $name Language name ( used only for display ).
* @type string $slug Language code ( ideally 2-letters ISO 639-1 language code ).
* @type string $locale WordPress locale. If something wrong is used for the locale, the .mo files will not be loaded...
* @type int $rtl 1 if rtl language, 0 otherwise.
* @type int $term_group Language order when displayed.
* @type string $no_default_cat Optional, if set, no default category will be created for this language.
* @type string $flag Optional, country code, @see flags.php.
* }
* @return WP_Error|true true if success / WP_Error if failed.
*/
public function add_language( $args ) {
if ( ! $this->validate_lang( $args ) ) {
return false;
$errors = $this->validate_lang( $args );
if ( $errors->get_error_code() ) { // Using has_errors() would be more meaningful but is available only since WP 5.0
return $errors;
}
// First the language taxonomy
$description = serialize( array( 'locale' => $args['locale'], 'rtl' => (int) $args['rtl'], 'flag_code' => empty( $args['flag'] ) ? '' : $args['flag'] ) );
$description = maybe_serialize( array( 'locale' => $args['locale'], 'rtl' => (int) $args['rtl'], 'flag_code' => empty( $args['flag'] ) ? '' : $args['flag'] ) );
$r = wp_insert_term( $args['name'], 'language', array( 'slug' => $args['slug'], 'description' => $description ) );
if ( is_wp_error( $r ) ) {
// Avoid an ugly fatal error if something went wrong ( reported once in the forum )
add_settings_error( 'general', 'pll_add_language', __( 'Impossible to add the language.', 'polylang' ) );
return false;
return new WP_Error( 'pll_add_language', __( 'Impossible to add the language.', 'polylang' ) );
}
wp_update_term( (int) $r['term_id'], 'language', array( 'term_group' => (int) $args['term_group'] ) ); // can't set the term group directly in wp_insert_term
@ -52,11 +52,6 @@ class PLL_Admin_Model extends PLL_Model {
// If this is the first language created, set it as default language
$this->options['default_lang'] = $args['slug'];
update_option( 'polylang', $this->options );
// And assign default language to default category
$this->term->set_language( (int) get_option( 'default_category' ), (int) $r['term_id'] );
} elseif ( empty( $args['no_default_cat'] ) ) {
$this->create_default_category( $args['slug'] );
}
// Init a mo_id for this language
@ -64,33 +59,32 @@ class PLL_Admin_Model extends PLL_Model {
$mo->export_to_db( $this->get_language( $args['slug'] ) );
/**
* Fires when a language is added
* Fires when a language is added.
*
* @since 1.9
*
* @param array $args arguments used to create the language
* @param array $args Arguments used to create the language. @see PLL_Admin_Model::add_language().
*/
do_action( 'pll_add_language', $args );
$this->clean_languages_cache(); // Again to set add mo_id in the cached languages list
flush_rewrite_rules(); // Refresh rewrite rules
add_settings_error( 'general', 'pll_languages_created', __( 'Language added.', 'polylang' ), 'updated' );
return true;
}
/**
* Delete a language
* Delete a language.
*
* @since 1.2
*
* @param int $lang_id language term_id
* @param int $lang_id Language term_id.
* @return bool
*/
public function delete_language( $lang_id ) {
$lang = $this->get_language( (int) $lang_id );
if ( empty( $lang ) ) {
return;
return false;
}
// Oops ! we are deleting the default language...
@ -127,7 +121,7 @@ class PLL_Admin_Model extends PLL_Model {
// Delete menus locations
if ( ! empty( $this->options['nav_menus'] ) ) {
foreach ( $this->options['nav_menus'] as $theme => $locations ) {
foreach ( $locations as $location => $languages ) {
foreach ( array_keys( $locations ) as $location ) {
unset( $this->options['nav_menus'][ $theme ][ $location ][ $lang->slug ] );
}
}
@ -141,7 +135,7 @@ class PLL_Admin_Model extends PLL_Model {
// Delete the string translations
$post = wpcom_vip_get_page_by_title( 'polylang_mo_' . $lang->term_id, OBJECT, 'polylang_mo' );
if ( ! empty( $post ) ) {
if ( $post instanceof WP_Post ) {
wp_delete_post( $post->ID );
}
@ -157,32 +151,31 @@ class PLL_Admin_Model extends PLL_Model {
update_option( 'polylang', $this->options );
flush_rewrite_rules(); // refresh rewrite rules
add_settings_error( 'general', 'pll_languages_deleted', __( 'Language deleted.', 'polylang' ), 'updated' );
return true;
}
/**
* Update language properties
*
* List of arguments that $args must contain:
* lang_id -> term_id of the language to modify
* name -> language name ( used only for display )
* slug -> language code ( ideally 2-letters ISO 639-1 language code
* locale -> WordPress locale. If something wrong is used for the locale, the .mo files will not be loaded...
* rtl -> 1 if rtl language, 0 otherwise
* term_group -> language order when displayed
*
* Optional arguments that $args can contain:
* flag -> country code, see flags.php
* Updates language properties.
*
* @since 1.2
*
* @param array $args
* @return bool true if success / false if failed
* @param array $args {
* @type int $lang_id Id of the language to modify.
* @type string $name Language name ( used only for display ).
* @type string $slug Language code ( ideally 2-letters ISO 639-1 language code ).
* @type string $locale WordPress locale. If something wrong is used for the locale, the .mo files will not be loaded...
* @type int $rtl 1 if rtl language, 0 otherwise.
* @type int $term_group Language order when displayed.
* @type string $flag Optional, country code, @see flags.php.
* }
* @return WP_Error|true true if success / WP_Error if failed.
*/
public function update_language( $args ) {
$lang = $this->get_language( (int) $args['lang_id'] );
if ( ! $this->validate_lang( $args, $lang ) ) {
return false;
$errors = $this->validate_lang( $args, $lang );
if ( $errors->get_error_code() ) { // Using has_errors() would be more meaningful but is available only since WP 5.0
return $errors;
}
// Update links to this language in posts and terms in case the slug has been modified
@ -211,7 +204,7 @@ class PLL_Admin_Model extends PLL_Model {
// Update menus locations
if ( ! empty( $this->options['nav_menus'] ) ) {
foreach ( $this->options['nav_menus'] as $theme => $locations ) {
foreach ( $locations as $location => $languages ) {
foreach ( array_keys( $locations ) as $location ) {
if ( ! empty( $this->options['nav_menus'][ $theme ][ $location ][ $old_slug ] ) ) {
$this->options['nav_menus'][ $theme ][ $location ][ $slug ] = $this->options['nav_menus'][ $theme ][ $location ][ $old_slug ];
unset( $this->options['nav_menus'][ $theme ][ $location ][ $old_slug ] );
@ -235,95 +228,118 @@ class PLL_Admin_Model extends PLL_Model {
update_option( 'polylang', $this->options );
// And finally update the language itself
$description = serialize( array( 'locale' => $args['locale'], 'rtl' => (int) $args['rtl'], 'flag_code' => empty( $args['flag'] ) ? '' : $args['flag'] ) );
$description = maybe_serialize( array( 'locale' => $args['locale'], 'rtl' => (int) $args['rtl'], 'flag_code' => empty( $args['flag'] ) ? '' : $args['flag'] ) );
wp_update_term( (int) $lang->term_id, 'language', array( 'slug' => $slug, 'name' => $args['name'], 'description' => $description, 'term_group' => (int) $args['term_group'] ) );
wp_update_term( (int) $lang->tl_term_id, 'term_language', array( 'slug' => 'pll_' . $slug, 'name' => $args['name'] ) );
if ( empty( $lang->tl_term_id ) ) {
// Attempt to repair the term_language if it has been deleted by a database cleaning tool.
wp_insert_term( $args['name'], 'term_language', array( 'slug' => 'pll_' . $slug ) );
} else {
wp_update_term( (int) $lang->tl_term_id, 'term_language', array( 'slug' => 'pll_' . $slug, 'name' => $args['name'] ) );
}
/**
* Fires when a language is added
* Fires when a language is updated.
*
* @since 1.9
*
* @param array $args arguments used to modify the language
* @param array $args Arguments used to modify the language. @see PLL_Admin_Model::update_language().
*/
do_action( 'pll_update_language', $args );
$this->clean_languages_cache();
flush_rewrite_rules(); // Refresh rewrite rules
add_settings_error( 'general', 'pll_languages_updated', __( 'Language updated.', 'polylang' ), 'updated' );
return true;
}
/**
* Validates data entered when creating or updating a language
* @see PLL_Admin_Model::add_language
* Validates data entered when creating or updating a language.
*
* @see PLL_Admin_Model::add_language().
*
* @since 0.4
*
* @param array $args
* @param object $lang optional the language currently updated, the language is created if not set
* @return bool true if success / false if failed
* @param array $args Parameters of {@see PLL_Admin_Model::add_language() or @see PLL_Admin_Model::update_language()}.
* @param PLL_Language $lang Optional the language currently updated, the language is created if not set.
* @return WP_Error
*/
protected function validate_lang( $args, $lang = null ) {
$errors = new WP_Error();
// Validate locale with the same pattern as WP 4.3. See #28303
if ( ! preg_match( '#^[a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?$#', $args['locale'], $matches ) ) {
add_settings_error( 'general', 'pll_invalid_locale', __( 'Enter a valid WordPress locale', 'polylang' ) );
$errors->add( 'pll_invalid_locale', __( 'Enter a valid WordPress locale', 'polylang' ) );
}
// Validate slug characters
if ( ! preg_match( '#^[a-z_-]+$#', $args['slug'] ) ) {
add_settings_error( 'general', 'pll_invalid_slug', __( 'The language code contains invalid characters', 'polylang' ) );
$errors->add( 'pll_invalid_slug', __( 'The language code contains invalid characters', 'polylang' ) );
}
// Validate slug is unique
foreach ( $this->get_languages_list() as $language ) {
if ( $language->slug === $args['slug'] && ( null === $lang || ( isset( $lang ) && $lang->term_id != $language->term_id ) ) ) {
add_settings_error( 'general', 'pll_non_unique_slug', __( 'The language code must be unique', 'polylang' ) );
if ( $language->slug === $args['slug'] && ( null === $lang || $lang->term_id !== $language->term_id ) ) {
$errors->add( 'pll_non_unique_slug', __( 'The language code must be unique', 'polylang' ) );
}
}
// Validate name
// No need to sanitize it as wp_insert_term will do it for us
if ( empty( $args['name'] ) ) {
add_settings_error( 'general', 'pll_invalid_name', __( 'The language must have a name', 'polylang' ) );
$errors->add( 'pll_invalid_name', __( 'The language must have a name', 'polylang' ) );
}
// Validate flag
if ( ! empty( $args['flag'] ) && ! file_exists( POLYLANG_DIR . '/flags/' . $args['flag'] . '.png' ) ) {
add_settings_error( 'general', 'pll_invalid_flag', __( 'The flag does not exist', 'polylang' ) );
$flag = PLL_Language::get_flag_informations( $args['flag'] );
if ( ! empty( $flag['url'] ) ) {
$response = function_exists( 'vip_safe_wp_remote_get' ) ? vip_safe_wp_remote_get( esc_url_raw( $flag['url'] ) ) : wp_remote_get( esc_url_raw( $flag['url'] ) );
}
if ( empty( $response ) || is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
$errors->add( 'pll_invalid_flag', __( 'The flag does not exist', 'polylang' ) );
}
}
return get_settings_errors() ? false : true;
return $errors;
}
/**
* Used to set the language of posts or terms in mass
* Assigns a language to posts or terms in mass.
*
* @since 1.2
*
* @param string $type either 'post' or 'term'
* @param array $ids array of post ids or term ids
* @param object|string $lang object or slug
* @param string $type Either 'post' or 'term'.
* @param int[] $ids Array of post ids or term ids.
* @param PLL_Language|string $lang Language to assign to the posts or terms.
* @return void
*/
public function set_language_in_mass( $type, $ids, $lang ) {
global $wpdb;
$ids = array_map( 'intval', $ids );
$lang = $this->get_language( $lang );
$tt_id = 'term' === $type ? $lang->tl_term_taxonomy_id : $lang->term_taxonomy_id;
if ( empty( $lang ) ) {
return;
}
$tt_id = 'term' === $type ? $lang->tl_term_taxonomy_id : $lang->term_taxonomy_id;
$values = array();
$ids = array_map( 'intval', $ids );
foreach ( $ids as $id ) {
$values[] = $wpdb->prepare( '( %d, %d )', $id, $tt_id );
}
if ( ! empty( $values ) ) {
$values = array_unique( $values );
$wpdb->query( "INSERT INTO $wpdb->term_relationships ( object_id, term_taxonomy_id ) VALUES " . implode( ',', $values ) );
// PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
$wpdb->query( "INSERT INTO {$wpdb->term_relationships} ( object_id, term_taxonomy_id ) VALUES " . implode( ',', array_unique( $values ) ) );
$lang->update_count(); // Updating term count is mandatory ( thanks to AndyDeGroo )
}
if ( 'term' === $type ) {
clean_term_cache( $ids, 'term_language' );
$translations = array();
foreach ( $ids as $id ) {
$translations[] = array( $lang->slug => $id );
@ -338,34 +354,42 @@ class PLL_Admin_Model extends PLL_Model {
}
/**
* Used to create a translations groups in mass
* Creates translations groups in mass.
*
* @since 1.6.3
*
* @param string $type either 'post' or 'term'
* @param array $translations array of translations arrays
* @param string $type Either 'post' or 'term'
* @param array $translations Array of translations arrays.
* @return void
*/
public function set_translation_in_mass( $type, $translations ) {
global $wpdb;
$taxonomy = $type . '_translations';
$taxonomy = $type . '_translations';
$terms = array();
$slugs = array();
$description = array();
$count = array();
foreach ( $translations as $t ) {
$term = uniqid( 'pll_' ); // the term name
$terms[] = $wpdb->prepare( '( %s, %s )', $term, $term );
$slugs[] = $wpdb->prepare( '%s', $term );
$description[ $term ] = serialize( $t );
$description[ $term ] = maybe_serialize( $t );
$count[ $term ] = count( $t );
}
// Insert terms
if ( ! empty( $terms ) ) {
$terms = array_unique( $terms );
$wpdb->query( "INSERT INTO $wpdb->terms ( slug, name ) VALUES " . implode( ',', $terms ) );
// PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
$wpdb->query( "INSERT INTO {$wpdb->terms} ( slug, name ) VALUES " . implode( ',', array_unique( $terms ) ) );
}
// Get all terms with their term_id
$terms = $wpdb->get_results( "SELECT term_id, slug FROM $wpdb->terms WHERE slug IN ( " . implode( ',', $slugs ) . ' )' );
// PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
$terms = $wpdb->get_results( "SELECT term_id, slug FROM {$wpdb->terms} WHERE slug IN ( " . implode( ',', $slugs ) . ' )' );
$term_ids = array();
$tts = array();
// Prepare terms taxonomy relationship
foreach ( $terms as $term ) {
@ -375,20 +399,23 @@ class PLL_Admin_Model extends PLL_Model {
// Insert term_taxonomy
if ( ! empty( $tts ) ) {
$tts = array_unique( $tts );
$wpdb->query( "INSERT INTO $wpdb->term_taxonomy ( term_id, taxonomy, description, count ) VALUES " . implode( ',', $tts ) );
// PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
$wpdb->query( "INSERT INTO {$wpdb->term_taxonomy} ( term_id, taxonomy, description, count ) VALUES " . implode( ',', array_unique( $tts ) ) );
}
// Get all terms with term_taxonomy_id
$terms = get_terms( $taxonomy, array( 'hide_empty' => false ) );
$trs = array();
// Prepare objects relationships
foreach ( $terms as $term ) {
$t = unserialize( $term->description );
if ( in_array( $t, $translations ) ) {
foreach ( $t as $object_id ) {
if ( ! empty( $object_id ) ) {
$trs[] = $wpdb->prepare( '( %d, %d )', $object_id, $term->term_taxonomy_id );
// Prepare objects relationships.
if ( is_array( $terms ) ) {
foreach ( $terms as $term ) {
$t = maybe_unserialize( $term->description );
if ( in_array( $t, $translations ) ) {
foreach ( $t as $object_id ) {
if ( ! empty( $object_id ) ) {
$trs[] = $wpdb->prepare( '( %d, %d )', $object_id, $term->term_taxonomy_id );
}
}
}
}
@ -396,7 +423,8 @@ class PLL_Admin_Model extends PLL_Model {
// Insert term_relationships
if ( ! empty( $trs ) ) {
$wpdb->query( "INSERT INTO $wpdb->term_relationships ( object_id, term_taxonomy_id ) VALUES " . implode( ',', $trs ) );
// PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
$wpdb->query( "INSERT INTO {$wpdb->term_relationships} ( object_id, term_taxonomy_id ) VALUES " . implode( ',', $trs ) );
$trs = array_unique( $trs );
}
@ -404,122 +432,74 @@ class PLL_Admin_Model extends PLL_Model {
}
/**
* Returns untranslated posts and terms ids ( used in settings )
*
* @since 0.9
* @since 2.2.6 Add the $limit argument
*
* @param in $limit Max number of posts or terms to return. Defaults to -1 (no limit).
* @return array Array made of an array of post ids and an array of term ids
*/
public function get_objects_with_no_lang( $limit = -1 ) {
global $wpdb;
/**
* Filters the max number of posts or terms to return when searching objects with no language
* This filter can be used to decrease the memory usage in case the number of objects
* without language is too big. Using a negative value is equivalent to have no limit.
*
* @since 2.2.6
*
* @param int $limit Max number of posts or terms to retrieve from the database
*/
$limit = (int) apply_filters( 'get_objects_with_no_lang_limit', $limit );
$posts = get_posts( array(
'numberposts' => $limit,
'nopaging' => $limit <= 0,
'post_type' => $this->get_translated_post_types(),
'post_status' => 'any',
'fields' => 'ids',
'tax_query' => array(
array(
'taxonomy' => 'language',
'terms' => $this->get_languages_list( array( 'fields' => 'term_id' ) ),
'operator' => 'NOT IN',
),
),
) );
$terms = $wpdb->get_col( sprintf( "
SELECT {$wpdb->term_taxonomy}.term_id FROM {$wpdb->term_taxonomy}
WHERE taxonomy IN ('%s')
AND {$wpdb->term_taxonomy}.term_id NOT IN (
SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN (%s)
)
%s",
implode( "','", array_map( 'esc_sql', $this->get_translated_taxonomies() ) ),
implode( ',', array_map( 'intval', $this->get_languages_list( array( 'fields' => 'tl_term_taxonomy_id' ) ) ) ),
$limit > 0 ? "LIMIT {$limit}" : ''
) );
/**
* Filter the list of untranslated posts ids and terms ids
*
* @since 0.9
*
* @param bool|array $objects false if no ids found, list of post and/or term ids otherwise
*/
return apply_filters( 'pll_get_objects_with_no_lang', empty( $posts ) && empty( $terms ) ? false : array( 'posts' => $posts, 'terms' => $terms ) );
}
/**
* Used to delete translations or update the translations when a language slug has been modified in settings
* Updates the translations when a language slug has been modified in settings
* or deletes them when a language is removed.
*
* @since 0.5
*
* @param string $old_slug the old language slug
* @param string $new_slug optional, the new language slug, if not set it means the correspondent has been deleted
* @param string $old_slug The old language slug.
* @param string $new_slug Optional, the new language slug, if not set it means that the language has been deleted.
* @return void
*/
public function update_translations( $old_slug, $new_slug = '' ) {
global $wpdb;
$terms = get_terms( array( 'post_translations', 'term_translations' ) );
$terms = get_terms( array( 'post_translations', 'term_translations' ) );
$term_ids = array();
$dr = array();
$dt = array();
$ut = array();
foreach ( $terms as $term ) {
$term_ids[ $term->taxonomy ][] = $term->term_id;
$tr = unserialize( $term->description );
if ( ! empty( $tr[ $old_slug ] ) ) {
if ( $new_slug ) {
$tr[ $new_slug ] = $tr[ $old_slug ]; // Suppress this for delete
} else {
$dr['id'][] = (int) $tr[ $old_slug ];
$dr['tt'][] = (int) $term->term_taxonomy_id;
}
unset( $tr[ $old_slug ] );
if ( is_array( $terms ) ) {
foreach ( $terms as $term ) {
$term_ids[ $term->taxonomy ][] = $term->term_id;
$tr = maybe_unserialize( $term->description );
if ( ! empty( $tr[ $old_slug ] ) ) {
if ( $new_slug ) {
$tr[ $new_slug ] = $tr[ $old_slug ]; // Suppress this for delete
} else {
$dr['id'][] = (int) $tr[ $old_slug ];
$dr['tt'][] = (int) $term->term_taxonomy_id;
}
unset( $tr[ $old_slug ] );
if ( empty( $tr ) || 1 == count( $tr ) ) {
$dt['t'][] = (int) $term->term_id;
$dt['tt'][] = (int) $term->term_taxonomy_id;
} else {
$ut['case'][] = $wpdb->prepare( 'WHEN %d THEN %s', $term->term_id, serialize( $tr ) );
$ut['in'][] = (int) $term->term_id;
if ( empty( $tr ) || 1 == count( $tr ) ) {
$dt['t'][] = (int) $term->term_id;
$dt['tt'][] = (int) $term->term_taxonomy_id;
} else {
$ut['case'][] = $wpdb->prepare( 'WHEN %d THEN %s', $term->term_id, maybe_serialize( $tr ) );
$ut['in'][] = (int) $term->term_id;
}
}
}
}
// Delete relationships
if ( ! empty( $dr ) ) {
$wpdb->query( "
DELETE FROM $wpdb->term_relationships
// PHPCS:disable WordPress.DB.PreparedSQL.NotPrepared
$wpdb->query(
"DELETE FROM $wpdb->term_relationships
WHERE object_id IN ( " . implode( ',', $dr['id'] ) . ' )
AND term_taxonomy_id IN ( ' . implode( ',', $dr['tt'] ) . ' )
' );
AND term_taxonomy_id IN ( ' . implode( ',', $dr['tt'] ) . ' )'
);
// PHPCS:enable
}
// Delete terms
if ( ! empty( $dt ) ) {
$wpdb->query( "DELETE FROM $wpdb->terms WHERE term_id IN ( " . implode( ',', $dt['t'] ) . ' )' );
$wpdb->query( "DELETE FROM $wpdb->term_taxonomy WHERE term_taxonomy_id IN ( " . implode( ',', $dt['tt'] ) . ' )' );
$wpdb->query( "DELETE FROM $wpdb->terms WHERE term_id IN ( " . implode( ',', $dt['t'] ) . ' )' ); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
$wpdb->query( "DELETE FROM $wpdb->term_taxonomy WHERE term_taxonomy_id IN ( " . implode( ',', $dt['tt'] ) . ' )' ); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
}
// Update terms
if ( ! empty( $ut ) ) {
$wpdb->query( "
UPDATE $wpdb->term_taxonomy
// PHPCS:disable WordPress.DB.PreparedSQL.NotPrepared
$wpdb->query(
"UPDATE $wpdb->term_taxonomy
SET description = ( CASE term_id " . implode( ' ', $ut['case'] ) . ' END )
WHERE term_id IN ( ' . implode( ',', $ut['in'] ) . ' )
' );
WHERE term_id IN ( ' . implode( ',', $ut['in'] ) . ' )'
);
// PHPCS:enable
}
if ( ! empty( $term_ids ) ) {
@ -531,27 +511,33 @@ class PLL_Admin_Model extends PLL_Model {
/**
* Updates the default language
* taking care to update the default category & the nav menu locations
* taking care to update the default category & the nav menu locations.
*
* @since 1.8
*
* @param string $slug new language slug
* @param string $slug New language slug.
* @return void
*/
public function update_default_lang( $slug ) {
// The nav menus stored in theme locations should be in the default language
$theme = get_stylesheet();
if ( ! empty( $this->options['nav_menus'][ $theme ] ) ) {
$menus = array();
foreach ( $this->options['nav_menus'][ $theme ] as $key => $loc ) {
$menus[ $key ] = empty( $loc[ $slug ] ) ? 0 : $loc[ $slug ];
}
set_theme_mod( 'nav_menu_locations', $menus );
}
// The default category should be in the default language
$default_cats = $this->term->get_translations( get_option( 'default_category' ) );
if ( isset( $default_cats[ $slug ] ) ) {
update_option( 'default_category', $default_cats[ $slug ] );
}
/**
* Fires when a default language is updated.
*
* @since 3.1
*
* @param string $slug Slug.
*/
do_action( 'pll_update_default_lang', $slug );
// Update options
$this->options['default_lang'] = $slug;

View file

@ -1,4 +1,7 @@
<?php
/**
* @package Polylang
*/
/**
* Manages custom menus translations as well as the language switcher menu item on admin side
@ -17,8 +20,6 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu {
public function __construct( &$polylang ) {
parent::__construct( $polylang );
$this->theme = get_option( 'stylesheet' );
// Populates nav menus locations
// Since WP 4.4, must be done before customize_register is fired
add_filter( 'theme_mod_nav_menu_locations', array( $this, 'theme_mod_nav_menu_locations' ), 20 );
@ -32,19 +33,17 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu {
* adds the language switcher metabox and create new nav menu locations
*
* @since 1.1
*
* @return void
*/
public function admin_init() {
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
add_action( 'wp_update_nav_menu_item', array( $this, 'wp_update_nav_menu_item' ), 10, 2 );
add_filter( 'wp_get_nav_menu_items', array( $this, 'translate_switcher_title' ) );
// Translation of menus based on chosen locations
add_filter( 'pre_update_option_theme_mods_' . $this->theme, array( $this, 'pre_update_option_theme_mods' ) );
add_action( 'delete_nav_menu', array( $this, 'delete_nav_menu' ) );
// Filter _wp_auto_add_pages_to_menu by language
add_action( 'transition_post_status', array( $this, 'auto_add_pages_to_menu' ), 5, 3 ); // before _wp_auto_add_pages_to_menu
// FIXME is it possible to choose the order ( after theme locations in WP3.5 and older ) ?
// FIXME not displayed if Polylang is activated before the first time the user goes to nav menus http://core.trac.wordpress.org/ticket/16828
add_meta_box( 'pll_lang_switch_box', __( 'Language switcher', 'polylang' ), array( $this, 'lang_switch' ), 'nav-menus', 'side', 'high' );
@ -58,6 +57,8 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu {
* Thanks to John Morris for his very interesting post http://www.johnmorrisonline.com/how-to-add-a-fully-functional-custom-meta-box-to-wordpress-navigation-menus/
*
* @since 1.1
*
* @return void
*/
public function lang_switch() {
global $_nav_menu_placeholder, $nav_menu_selected_id;
@ -68,17 +69,17 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu {
<ul id="lang-switch-checklist" class="categorychecklist form-no-clear">
<li>
<label class="menu-item-title">
<input type="checkbox" class="menu-item-checkbox" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-object-id]" value="-1"> <?php esc_html_e( 'Language switcher', 'polylang' ); ?>
<input type="checkbox" class="menu-item-checkbox" name="menu-item[<?php echo (int) $_nav_menu_placeholder; ?>][menu-item-object-id]" value="-1"> <?php esc_html_e( 'Languages', 'polylang' ); ?>
</label>
<input type="hidden" class="menu-item-type" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" value="custom">
<input type="hidden" class="menu-item-title" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-title]" value="<?php esc_html_e( 'Language switcher', 'polylang' ); ?>">
<input type="hidden" class="menu-item-url" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-url]" value="#pll_switcher">
<input type="hidden" class="menu-item-type" name="menu-item[<?php echo (int) $_nav_menu_placeholder; ?>][menu-item-type]" value="custom">
<input type="hidden" class="menu-item-title" name="menu-item[<?php echo (int) $_nav_menu_placeholder; ?>][menu-item-title]" value="<?php esc_attr_e( 'Languages', 'polylang' ); ?>">
<input type="hidden" class="menu-item-url" name="menu-item[<?php echo (int) $_nav_menu_placeholder; ?>][menu-item-url]" value="#pll_switcher">
</li>
</ul>
</div>
<p class="button-controls">
<span class="add-to-menu">
<input type="submit" <?php disabled( $nav_menu_selected_id, 0 ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>" name="add-post-type-menu-item" id="submit-posttype-lang-switch">
<input type="submit" <?php disabled( $nav_menu_selected_id, 0 ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu', 'polylang' ); ?>" name="add-post-type-menu-item" id="submit-posttype-lang-switch">
<span class="spinner"></span>
</span>
</p>
@ -90,30 +91,36 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu {
* Prepares javascript to modify the language switcher menu item
*
* @since 1.1
*
* @return void
*/
public function admin_enqueue_scripts() {
$screen = get_current_screen();
if ( 'nav-menus' != $screen->base ) {
if ( empty( $screen ) || 'nav-menus' !== $screen->base ) {
return;
}
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_script( 'pll_nav_menu', plugins_url( '/js/nav-menu' . $suffix . '.js', POLYLANG_FILE ), array( 'jquery' ), POLYLANG_VERSION );
wp_enqueue_script( 'pll_nav_menu', plugins_url( '/js/build/nav-menu' . $suffix . '.js', POLYLANG_ROOT_FILE ), array( 'jquery' ), POLYLANG_VERSION );
$data['strings'] = PLL_Switcher::get_switcher_options( 'menu', 'string' ); // The strings for the options
$data['title'] = __( 'Language switcher', 'polylang' ); // The title
$data = array(
'strings' => PLL_Switcher::get_switcher_options( 'menu', 'string' ), // The strings for the options
'title' => __( 'Languages', 'polylang' ), // The title
'val' => array(),
);
// Get all language switcher menu items
$items = get_posts( array(
'numberposts' => -1,
'nopaging' => true,
'post_type' => 'nav_menu_item',
'fields' => 'ids',
'meta_key' => '_pll_menu_item',
) );
$items = get_posts(
array(
'numberposts' => -1,
'nopaging' => true,
'post_type' => 'nav_menu_item',
'fields' => 'ids',
'meta_key' => '_pll_menu_item',
)
);
// The options values for the language switcher
$data['val'] = array();
foreach ( $items as $item ) {
$data['val'][ $item ] = get_post_meta( $item, '_pll_menu_item', true );
}
@ -129,9 +136,10 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu {
*
* @param int $menu_id not used
* @param int $menu_item_db_id
* @return void
*/
public function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0 ) {
if ( empty( $_POST['menu-item-url'][ $menu_item_db_id ] ) || '#pll_switcher' != $_POST['menu-item-url'][ $menu_item_db_id ] ) {
if ( empty( $_POST['menu-item-url'][ $menu_item_db_id ] ) || '#pll_switcher' !== $_POST['menu-item-url'][ $menu_item_db_id ] ) { // phpcs:ignore WordPress.Security.NonceVerification
return;
}
@ -147,7 +155,7 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu {
}
}
else {
foreach ( $options as $opt => $v ) {
foreach ( array_keys( $options ) as $opt ) {
$options[ $opt ] = empty( $_POST[ 'menu-item-' . $opt ][ $menu_item_db_id ] ) ? 0 : 1;
}
update_post_meta( $menu_item_db_id, '_pll_menu_item', $options ); // Allow us to easily identify our nav menu item
@ -155,23 +163,6 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu {
}
}
/**
* Translates the language switcher menu items title in case the user switches the admin language
*
* @since 1.1.1
*
* @param array $items
* @return array modified $items
*/
public function translate_switcher_title( $items ) {
foreach ( $items as $item ) {
if ( '#pll_switcher' == $item->url ) {
$item->post_title = __( 'Language switcher', 'polylang' );
}
}
return $items;
}
/**
* Assign menu languages and translations based on ( temporary ) locations
*
@ -181,8 +172,6 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu {
* @return array
*/
public function update_nav_menu_locations( $locations ) {
$default = $this->options['default_lang'];
// Extract language and menu from locations
foreach ( $locations as $loc => $menu ) {
$infos = $this->explode_location( $loc );
@ -197,25 +186,25 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu {
}
/**
* Assign menu languages and translations based on ( temporary ) locations
* Assign menu languages and translations based on ( temporary ) locations.
*
* @since 1.1
*
* @param array $mods theme mods
* @return unmodified $mods
* @param mixed $mods Theme mods.
* @return mixed
*/
public function pre_update_option_theme_mods( $mods ) {
if ( current_user_can( 'edit_theme_options' ) && isset( $mods['nav_menu_locations'] ) ) {
// Manage Locations tab in Appearance -> Menus
if ( isset( $_GET['action'] ) && 'locations' == $_GET['action'] ) {
if ( isset( $_GET['action'] ) && 'locations' === $_GET['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification
check_admin_referer( 'save-menu-locations' );
$this->options['nav_menus'][ $this->theme ] = array();
}
// Edit Menus tab in Appearance -> Menus
// Add the test of $_POST['update-nav-menu-nonce'] to avoid conflict with Vantage theme
elseif ( isset( $_POST['action'], $_POST['update-nav-menu-nonce'] ) && 'update' == $_POST['action'] ) {
elseif ( isset( $_POST['action'], $_POST['update-nav-menu-nonce'] ) && 'update' === $_POST['action'] ) {
check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' );
$this->options['nav_menus'][ $this->theme ] = array();
}
@ -253,7 +242,7 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu {
}
if ( is_array( $menus ) ) {
foreach ( $menus as $loc => $menu ) {
foreach ( array_keys( $menus ) as $loc ) {
foreach ( $this->model->get_languages_list() as $lang ) {
if ( ! empty( $this->options['nav_menus'][ $this->theme ][ $loc ][ $lang->slug ] ) && term_exists( $this->options['nav_menus'][ $this->theme ][ $loc ][ $lang->slug ], 'nav_menu' ) ) {
$menus[ $this->combine_location( $loc, $lang ) ] = $this->options['nav_menus'][ $this->theme ][ $loc ][ $lang->slug ];
@ -271,8 +260,9 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu {
* @since 1.7.3
*
* @param int $term_id nav menu id
* @return void
*/
function delete_nav_menu( $term_id ) {
public function delete_nav_menu( $term_id ) {
if ( isset( $this->options['nav_menus'] ) ) {
foreach ( $this->options['nav_menus'] as $theme => $locations ) {
foreach ( $locations as $loc => $languages ) {
@ -287,48 +277,4 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu {
update_option( 'polylang', $this->options );
}
}
/**
* Filters the option nav_menu_options for auto added pages to menu
*
* @since 0.9.4
*
* @param array $options
* @return array Modified options
*/
public function nav_menu_options( $options ) {
$options['auto_add'] = array_intersect( $options['auto_add'], $this->auto_add_menus );
return $options;
}
/**
* Filters _wp_auto_add_pages_to_menu by language
*
* @since 0.9.4
*
* @param string $new_status Transition to this post status.
* @param string $old_status Previous post status.
* @param object $post Post data.
*/
public function auto_add_pages_to_menu( $new_status, $old_status, $post ) {
if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type || ! empty( $post->post_parent ) ) {
return;
}
if ( ! empty( $this->options['nav_menus'][ $this->theme ] ) ) {
$this->auto_add_menus = array();
$lang = $this->model->post->get_language( $post->ID );
$lang = empty( $lang ) ? $this->options['default_lang'] : $lang->slug; // If the page has no language yet, the default language will be assigned
// Get all the menus in the page language
foreach ( $this->options['nav_menus'][ $this->theme ] as $loc ) {
if ( ! empty( $loc[ $lang ] ) ) {
$this->auto_add_menus[] = $loc[ $lang ];
}
}
add_filter( 'option_nav_menu_options', array( $this, 'nav_menu_options' ) );
}
}
}

View file

@ -0,0 +1,270 @@
<?php
/**
* @package Polylang
*/
/**
* A class to manage admin notices
* displayed only to admin, based on 'manage_options' capability
* and only on dashboard, plugins and Polylang admin pages
*
* @since 2.3.9
* @since 2.7 Dismissed notices are stored in an option instead of a user meta
*/
class PLL_Admin_Notices {
/**
* Stores the plugin options.
*
* @var array
*/
protected $options;
/**
* Stores custom notices.
*
* @var string[]
*/
private static $notices = array();
/**
* Constructor
* Setup actions
*
* @since 2.3.9
*
* @param object $polylang
*/
public function __construct( $polylang ) {
$this->options = &$polylang->options;
add_action( 'admin_init', array( $this, 'hide_notice' ) );
add_action( 'admin_notices', array( $this, 'display_notices' ) );
}
/**
* Add a custom notice
*
* @since 2.3.9
*
* @param string $name Notice name
* @param string $html Content of the notice
* @return void
*/
public static function add_notice( $name, $html ) {
self::$notices[ $name ] = $html;
}
/**
* Get custom notices.
*
* @since 2.3.9
*
* @return string[]
*/
public static function get_notices() {
return self::$notices;
}
/**
* Has a notice been dismissed?
*
* @since 2.3.9
*
* @param string $notice Notice name
* @return bool
*/
public static function is_dismissed( $notice ) {
$dismissed = get_option( 'pll_dismissed_notices', array() );
// Handle legacy user meta
$dismissed_meta = get_user_meta( get_current_user_id(), 'pll_dismissed_notices', true );
if ( is_array( $dismissed_meta ) ) {
if ( array_diff( $dismissed_meta, $dismissed ) ) {
$dismissed = array_merge( $dismissed, $dismissed_meta );
update_option( 'pll_dismissed_notices', $dismissed );
}
if ( ! is_multisite() ) {
// Don't delete on multisite to avoid the notices to appear in other sites.
delete_user_meta( get_current_user_id(), 'pll_dismissed_notices' );
}
}
return in_array( $notice, $dismissed );
}
/**
* Should we display notices on this screen?
*
* @since 2.3.9
*
* @param string $notice The notice name.
* @return bool
*/
protected function can_display_notice( $notice ) {
$screen = get_current_screen();
if ( empty( $screen ) ) {
return false;
}
$screen_id = sanitize_title( __( 'Languages', 'polylang' ) );
/**
* Filter admin notices which can be displayed
*
* @since 2.7.0
*
* @param bool $display Whether the notice should be displayed or not.
* @param string $notice The notice name.
*/
return apply_filters(
'pll_can_display_notice',
in_array(
$screen->id,
array(
'dashboard',
'plugins',
'toplevel_page_mlang',
$screen_id . '_page_mlang_strings',
$screen_id . '_page_mlang_settings',
)
),
$notice
);
}
/**
* Stores a dismissed notice in database
*
* @since 2.3.9
*
* @param string $notice
* @return void
*/
public static function dismiss( $notice ) {
$dismissed = get_option( 'pll_dismissed_notices', array() );
if ( ! in_array( $notice, $dismissed ) ) {
$dismissed[] = $notice;
update_option( 'pll_dismissed_notices', array_unique( $dismissed ) );
}
}
/**
* Handle a click on the dismiss button
*
* @since 2.3.9
*
* @return void
*/
public function hide_notice() {
if ( isset( $_GET['pll-hide-notice'], $_GET['_pll_notice_nonce'] ) ) {
$notice = sanitize_key( $_GET['pll-hide-notice'] );
check_admin_referer( $notice, '_pll_notice_nonce' );
self::dismiss( $notice );
wp_safe_redirect( remove_query_arg( array( 'pll-hide-notice', '_pll_notice_nonce' ), wp_get_referer() ) );
exit;
}
}
/**
* Displays notices
*
* @since 2.3.9
*
* @return void
*/
public function display_notices() {
if ( current_user_can( 'manage_options' ) ) {
// Core notices
if ( defined( 'WOOCOMMERCE_VERSION' ) && ! defined( 'PLLWC_VERSION' ) && $this->can_display_notice( 'pllwc' ) && ! $this->is_dismissed( 'pllwc' ) ) {
$this->pllwc_notice();
}
if ( ! defined( 'POLYLANG_PRO' ) && $this->can_display_notice( 'review' ) && ! $this->is_dismissed( 'review' ) && ! empty( $this->options['first_activation'] ) && time() > $this->options['first_activation'] + 15 * DAY_IN_SECONDS ) {
$this->review_notice();
}
// Custom notices
foreach ( $this->get_notices() as $notice => $html ) {
if ( $this->can_display_notice( $notice ) && ! $this->is_dismissed( $notice ) ) {
?>
<div class="pll-notice notice notice-info">
<?php
$this->dismiss_button( $notice );
echo wp_kses_post( $html );
?>
</div>
<?php
}
}
}
}
/**
* Displays a dismiss button
*
* @since 2.3.9
*
* @param string $name Notice name
* @return void
*/
public function dismiss_button( $name ) {
printf(
'<a class="notice-dismiss" href="%s"><span class="screen-reader-text">%s</span></a>',
esc_url( wp_nonce_url( add_query_arg( 'pll-hide-notice', $name ), $name, '_pll_notice_nonce' ) ),
/* translators: accessibility text */
esc_html__( 'Dismiss this notice.', 'polylang' )
);
}
/**
* Displays a notice if WooCommerce is activated without Polylang for WooCommerce
*
* @since 2.3.9
*
* @return void
*/
private function pllwc_notice() {
?>
<div class="pll-notice notice notice-warning">
<?php $this->dismiss_button( 'pllwc' ); ?>
<p>
<?php
printf(
/* translators: %1$s is link start tag, %2$s is link end tag. */
esc_html__( 'We have noticed that you are using Polylang with WooCommerce. To ensure compatibility, we recommend you use %1$sPolylang for WooCommerce%2$s.', 'polylang' ),
'<a href="https://polylang.pro/downloads/polylang-for-woocommerce/">',
'</a>'
);
?>
</p>
</div>
<?php
}
/**
* Displays a notice asking for a review
*
* @since 2.3.9
*
* @return void
*/
private function review_notice() {
?>
<div class="pll-notice notice notice-info">
<?php $this->dismiss_button( 'review' ); ?>
<p>
<?php
printf(
/* translators: %1$s is link start tag, %2$s is link end tag. */
esc_html__( 'We have noticed that you have been using Polylang for some time. We hope you love it, and we would really appreciate it if you would %1$sgive us a 5 stars rating%2$s.', 'polylang' ),
'<a href="https://wordpress.org/support/plugin/polylang/reviews/?rate=5#new-post">',
'</a>'
);
?>
</p>
</div>
<?php
}
}

View file

@ -1,4 +1,7 @@
<?php
/**
* @package Polylang
*/
/**
* Manages the static front page and the page for posts on admin side
@ -6,6 +9,10 @@
* @since 1.8
*/
class PLL_Admin_Static_Pages extends PLL_Static_Pages {
/**
* @var PLL_Admin_Links
*/
protected $links;
/**
* Constructor: setups filters and actions
@ -17,7 +24,10 @@ class PLL_Admin_Static_Pages extends PLL_Static_Pages {
public function __construct( &$polylang ) {
parent::__construct( $polylang );
$this->links = &$polylang->links;
// Removes the editor and the template select dropdown for pages for posts
add_filter( 'use_block_editor_for_post', array( $this, 'use_block_editor_for_post' ), 10, 2 ); // Since WP 5.0
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 10, 2 );
// Add post state for translations of the front page and posts page
@ -26,24 +36,44 @@ class PLL_Admin_Static_Pages extends PLL_Static_Pages {
// Refresh language cache when a static front page has been translated
add_action( 'pll_save_post', array( $this, 'pll_save_post' ), 10, 3 );
// Checks if chosen page on front is translated
add_filter( 'pre_update_option_page_on_front', array( $this, 'update_page_on_front' ), 10, 2 );
add_filter( 'customize_validate_page_on_front', array( $this, 'customize_validate_page_on_front' ), 10, 2 );
// Prevents WP resetting the option
add_filter( 'pre_update_option_show_on_front', array( $this, 'update_show_on_front' ), 10, 2 );
add_action( 'admin_notices', array( $this, 'notice_must_translate' ) );
}
/**
* Removes the editor for translations of the pages for posts
* Removes the page template select dropdown in page attributes metabox too
* Don't use the block editor for the translations of the pages for posts
*
* @since 2.5
*
* @param bool $use_block_editor Whether the post can be edited or not.
* @param WP_Post $post The post being checked.
* @return bool
*/
public function use_block_editor_for_post( $use_block_editor, $post ) {
if ( 'page' === $post->post_type ) {
add_filter( 'option_page_for_posts', array( $this, 'translate_page_for_posts' ) );
if ( ( get_option( 'page_for_posts' ) == $post->ID ) && empty( $post->post_content ) ) {
return false;
}
}
return $use_block_editor;
}
/**
* Removes the editor for the translations of the pages for posts.
* Removes the page template select dropdown in page attributes metabox too.
*
* @since 2.2.2
*
* @param string $post_type Current post type
* @param object $post Current post
* @param string $post_type Current post type.
* @param WP_Post $post Current post.
* @return void
*/
function add_meta_boxes( $post_type, $post ) {
public function add_meta_boxes( $post_type, $post ) {
if ( 'page' === $post_type ) {
add_filter( 'option_page_for_posts', array( $this, 'translate_page_for_posts' ) );
@ -55,34 +85,35 @@ class PLL_Admin_Static_Pages extends PLL_Static_Pages {
}
/**
* Add post state for translations of the front page and posts page
* Adds post state for translations of the front page and posts page.
*
* @since 1.8
*
* @param array $post_states
* @param object $post
* @return array
* @param string[] $post_states An array of post display states.
* @param WP_Post $post The current post object.
* @return string[]
*/
public function display_post_states( $post_states, $post ) {
if ( in_array( $post->ID, $this->model->get_languages_list( array( 'fields' => 'page_on_front' ) ) ) ) {
$post_states['page_on_front'] = __( 'Front Page' );
$post_states['page_on_front'] = __( 'Front Page', 'polylang' );
}
if ( in_array( $post->ID, $this->model->get_languages_list( array( 'fields' => 'page_for_posts' ) ) ) ) {
$post_states['page_for_posts'] = __( 'Posts Page' );
$post_states['page_for_posts'] = __( 'Posts Page', 'polylang' );
}
return $post_states;
}
/**
* Refresh language cache when a static front page has been translated
* Refreshes the language cache when a static front page has been translated.
*
* @since 1.8
*
* @param int $post_id Not used
* @param object $post Not used
* @param array $translations
* @param int $post_id Not used.
* @param WP_Post $post Not used.
* @param int[] $translations Translations of the post being saved.
* @return void
*/
public function pll_save_post( $post_id, $post, $translations ) {
if ( in_array( $this->page_on_front, $translations ) ) {
@ -90,63 +121,6 @@ class PLL_Admin_Static_Pages extends PLL_Static_Pages {
}
}
/**
* Checks if a page is translated in all languages
*
* @since 2.2
*
* @param int $page_id
* @return bool
*/
protected function is_page_translated( $page_id ) {
if ( $page_id ) {
$translations = count( $this->model->post->get_translations( $page_id ) );
$languages = count( $this->model->get_languages_list() );
if ( $languages > 1 && $translations != $languages ) {
return false;
}
}
return true;
}
/**
* Prevents choosing an untranslated static front page
* Displays an error message
*
* @since 1.6
*
* @param int $page_id New page on front page id
* @param int $old_id Old page on front page_id
* @return int
*/
public function update_page_on_front( $page_id, $old_id ) {
if ( ! $this->is_page_translated( $page_id ) ) {
$page_id = $old_id;
add_settings_error( 'reading', 'pll_page_on_front_error', __( 'The chosen static front page must be translated in all languages.', 'polylang' ) );
}
return $page_id;
}
/**
* Displays an error message in the customizer when choosing an untranslated static front page
*
* @since 2.2
*
* @param object $validity WP_Error object
* @param int $page_id New page on front page id
* @return object
*/
public function customize_validate_page_on_front( $validity, $page_id ) {
if ( ! $this->is_page_translated( $page_id ) ) {
return new WP_Error( 'pll_page_on_front_error', __( 'The chosen static front page must be translated in all languages.', 'polylang' ) );
}
return $validity;
}
/**
* Prevents WP resetting the option if the admin language filter is active for a language with no pages
*
@ -162,4 +136,63 @@ class PLL_Admin_Static_Pages extends PLL_Static_Pages {
}
return $value;
}
/**
* Add a notice to translate the static front page if it is not translated in all languages
* This is especially useful after a new language is created.
* The notice is not dismissible and displayed on the Languages pages and the list of pages.
*
* @since 2.6
*
* @return void
*/
public function notice_must_translate() {
$screen = get_current_screen();
if ( ! empty( $screen ) && ( 'toplevel_page_mlang' === $screen->id || 'edit-page' === $screen->id ) ) {
$message = $this->get_must_translate_message();
if ( ! empty( $message ) ) {
printf(
'<div class="error"><p>%s</p></div>',
$message // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
}
}
}
/**
* Returns the message asking to translate the static front page in all languages.
*
* @since 2.8
*
* @return string
*/
public function get_must_translate_message() {
$message = '';
if ( $this->page_on_front ) {
$untranslated = array();
foreach ( $this->model->get_languages_list() as $language ) {
if ( ! $this->model->post->get( $this->page_on_front, $language ) ) {
$untranslated[] = sprintf(
'<a href="%s">%s</a>',
esc_url( $this->links->get_new_post_translation_link( $this->page_on_front, $language ) ),
esc_html( $language->name )
);
}
}
if ( ! empty( $untranslated ) ) {
$message = sprintf(
/* translators: %s is a comma separated list of native language names */
esc_html__( 'You must translate your static front page in %s.', 'polylang' ),
implode( ', ', $untranslated ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
}
}
return $message;
}
}

View file

@ -1,26 +1,47 @@
<?php
/**
* @package Polylang
*/
/**
* a fully static class to manage strings translations on admin side
* A fully static class to manage strings translations on admin side
*
* @since 1.6
*/
class PLL_Admin_Strings {
static protected $strings = array(); // strings to translate
static protected $default_strings; // default strings to register
/**
* Stores the strings to translate.
*
* @var array {
* @type string $name A unique name for the string.
* @type string $string The actual string to translate.
* @type string $context The group in which the string is registered.
* @type bool $multiline Whether the string table should display a multiline textarea or a single line input.
* }
*/
protected static $strings = array();
/**
* init: add filters
* The strings to register by default.
*
* @var string[]
*/
protected static $default_strings;
/**
* Add filters
*
* @since 1.6
*
* @return void
*/
static public function init() {
public static function init() {
// default strings translations sanitization
add_filter( 'pll_sanitize_string_translation', array( __CLASS__, 'sanitize_string_translation' ), 10, 2 );
}
/**
* register strings for translation making sure it is not duplicate or empty
* Register strings for translation making sure it is not duplicate or empty
*
* @since 0.6
*
@ -28,44 +49,28 @@ class PLL_Admin_Strings {
* @param string $string The string to register
* @param string $context Optional, the group in which the string is registered, defaults to 'polylang'
* @param bool $multiline Optional, whether the string table should display a multiline textarea or a single line input, defaults to single line
* @return void
*/
static public function register_string( $name, $string, $context = 'Polylang', $multiline = false ) {
// backward compatibility with Polylang older than 1.1
if ( is_bool( $context ) ) {
$multiline = $context;
$context = 'Polylang';
}
public static function register_string( $name, $string, $context = 'Polylang', $multiline = false ) {
if ( $string && is_scalar( $string ) ) {
self::$strings[ md5( $string ) ] = compact( 'name', 'string', 'context', 'multiline' );
}
}
/**
* get registered strings
* Get registered strings
*
* @since 0.6.1
*
* @return array list of all registered strings
*/
static public function &get_strings() {
public static function &get_strings() {
self::$default_strings = array(
'options' => array(
'blogname' => __( 'Site Title' ),
'blogdescription' => __( 'Tagline' ),
'date_format' => __( 'Date Format' ),
'time_format' => __( 'Time Format' ),
),
'widget_title' => __( 'Widget title', 'polylang' ),
'widget_text' => __( 'Widget text', 'polylang' ),
);
// WP strings
foreach ( self::$default_strings['options'] as $option => $string ) {
self::register_string( $string, get_option( $option ), 'WordPress' );
}
// widgets titles
// Widgets titles
global $wp_registered_widgets;
$sidebars = wp_get_sidebars_widgets();
foreach ( $sidebars as $sidebar => $widgets ) {
@ -74,8 +79,8 @@ class PLL_Admin_Strings {
}
foreach ( $widgets as $widget ) {
// nothing can be done if the widget is created using pre WP2.8 API :(
// there is no object, so we can't access it to get the widget options
// Nothing can be done if the widget is created using pre WP2.8 API :(
// There is no object, so we can't access it to get the widget options
if ( ! isset( $wp_registered_widgets[ $widget ]['callback'][0] ) || ! is_object( $wp_registered_widgets[ $widget ]['callback'][0] ) || ! method_exists( $wp_registered_widgets[ $widget ]['callback'][0], 'get_settings' ) ) {
continue;
}
@ -83,7 +88,7 @@ class PLL_Admin_Strings {
$widget_settings = $wp_registered_widgets[ $widget ]['callback'][0]->get_settings();
$number = $wp_registered_widgets[ $widget ]['params'][0]['number'];
// don't enable widget translation if the widget is visible in only one language or if there is no title
// Don't enable widget translation if the widget is visible in only one language or if there is no title
if ( empty( $widget_settings[ $number ]['pll_lang'] ) ) {
if ( isset( $widget_settings[ $number ]['title'] ) && $title = $widget_settings[ $number ]['title'] ) {
self::register_string( self::$default_strings['widget_title'], $title, 'Widget' );
@ -109,7 +114,7 @@ class PLL_Admin_Strings {
}
/**
* performs the sanitization ( before saving in DB ) of default strings translations
* Performs the sanitization ( before saving in DB ) of default strings translations
*
* @since 1.6
*
@ -117,19 +122,13 @@ class PLL_Admin_Strings {
* @param string $name unique name for the string
* @return string
*/
static public function sanitize_string_translation( $translation, $name ) {
$translation = wp_unslash( trim( $translation ) );
if ( false !== ( $option = array_search( $name, self::$default_strings['options'], true ) ) ) {
$translation = sanitize_option( $option, $translation );
}
public static function sanitize_string_translation( $translation, $name ) {
if ( $name == self::$default_strings['widget_title'] ) {
$translation = strip_tags( $translation );
$translation = sanitize_text_field( $translation );
}
if ( $name == self::$default_strings['widget_text'] && ! current_user_can( 'unfiltered_html' ) ) {
$translation = wp_unslash( wp_filter_post_kses( addslashes( $translation ) ) ); // wp_filter_post_kses() expects slashed
$translation = wp_kses_post( $translation );
}
return $translation;

View file

@ -1,70 +1,104 @@
<?php
/**
* @package Polylang
*/
/**
* admin side controller
* accessible in $polylang global object
*
* properties:
* options => inherited, reference to Polylang options array
* model => inherited, reference to PLL_Model object
* links_model => inherited, reference to PLL_Links_Model object
* links => inherited, reference to PLL_Admin_Links object
* static_pages => inherited, reference to PLL_Admin_Static_Pages object
* filters_links => inherited, reference to PLL_Filters_Links object
* curlang => inherited, optional, current language used to filter the content (language of the post or term being edited, equal to filter_lang otherwise)
* filter_lang => inherited, optional, current status of the admin languages filter (in the admin bar)
* pref_lang => inherited, preferred language used as default when saving posts or terms
* filters => reference to PLL_Filters object
* filters_columns => reference to PLL_Admin_Filters_Columns object
* filters_post => reference to PLL_Admin_Filters_Post object
* filters_term => reference to PLL_Admin_filters_Term object
* nav_menu => reference to PLL_Admin_Nav_Menu object
* filters_media => optional, reference to PLL_Admin_Filters_Media object
* Main Polylang class for admin (except Polylang pages), accessible from @see PLL().
*
* @since 1.2
*/
class PLL_Admin extends PLL_Admin_Base {
public $filters, $filters_columns, $filters_post, $filters_term, $nav_menu, $sync, $filters_media;
/**
* @var PLL_Admin_Filters
*/
public $filters;
/**
* loads the polylang text domain
* setups filters and action needed on all admin pages and on plugins page
* @var PLL_Admin_Filters_Columns
*/
public $filters_columns;
/**
* @var PLL_Admin_Filters_Post
*/
public $filters_post;
/**
* @var PLL_Admin_Filters_Term
*/
public $filters_term;
/**
* @var PLL_Admin_Filters_Media
*/
public $filters_media;
/**
* @since 2.9
*
* @var PLL_Filters_Sanitization
*/
public $filters_sanitization;
/**
* @var PLL_Admin_Block_Editor
*/
public $block_editor;
/**
* @var PLL_Admin_Classic_Editor
*/
public $classic_editor;
/**
* @var PLL_Admin_Nav_Menu
*/
public $nav_menu;
/**
* @var PLL_Admin_Filters_Widgets_Options
*/
public $filters_widgets_options;
/**
* Setups filters and action needed on all admin pages and on plugins page.
*
* @since 1.2
*
* @param object $links_model
* @param PLL_Links_Model $links_model Reference to the links model.
*/
public function __construct( &$links_model ) {
parent::__construct( $links_model );
// adds a 'settings' link in the plugins table
// Adds a 'settings' link in the plugins table
add_filter( 'plugin_action_links_' . POLYLANG_BASENAME, array( $this, 'plugin_action_links' ) );
add_action( 'in_plugin_update_message-' . POLYLANG_BASENAME, array( $this, 'plugin_update_message' ), 10, 2 );
}
/**
* setups filters and action needed on all admin pages and on plugins page
* loads the settings pages or the filters base on the request
* Setups filters and action needed on all admin pages and on plugins page
* Loads the settings pages or the filters base on the request
*
* @since 1.2
*/
public function init() {
parent::init();
// setup filters for admin pages
// priority 5 to make sure filters are there before customize_register is fired
// Setup filters for admin pages
// Priority 5 to make sure filters are there before customize_register is fired
if ( $this->model->get_languages_list() ) {
add_action( 'wp_loaded', array( $this, 'add_filters' ), 5 );
}
}
/**
* adds a 'settings' link in the plugins table
* Adds a 'settings' link for our plugin in the plugins list table.
*
* @since 0.1
*
* @param array $links list of links associated to the plugin
* @return array modified list of links
* @param string[] $links List of links associated to the plugin.
* @return string[] Modified list of links.
*/
public function plugin_action_links( $links ) {
array_unshift( $links, '<a href="admin.php?page=mlang">' . __( 'Settings', 'polylang' ) . '</a>' );
@ -72,29 +106,35 @@ class PLL_Admin extends PLL_Admin_Base {
}
/**
* adds the upgrade notice in plugins table
* Adds the upgrade notice in plugins table
*
* @since 1.1.6
*
* @param array $plugin_data Not used
* @param object $r Plugin update data
* @return void
*/
function plugin_update_message( $plugin_data, $r ) {
public function plugin_update_message( $plugin_data, $r ) {
if ( isset( $r->upgrade_notice ) ) {
printf( '<p style="margin: 3px 0 0 0; border-top: 1px solid #ddd; padding-top: 3px">%s</p>', esc_html( $r->upgrade_notice ) );
}
}
/**
* setup filters for admin pages
* Setup filters for admin pages
*
* @since 1.2
* @since 2.7 instantiate a PLL_Bulk_Translate instance.
* @return void
*/
public function add_filters() {
// all these are separated just for convenience and maintainability
$classes = array( 'Filters', 'Filters_Columns', 'Filters_Post', 'Filters_Term', 'Nav_Menu', 'Sync' );
$this->filters_sanitization = new PLL_Filters_Sanitization( $this->get_locale_for_sanitization() );
$this->filters_widgets_options = new PLL_Admin_Filters_Widgets_Options( $this );
// don't load media filters if option is disabled or if user has no right
// All these are separated just for convenience and maintainability
$classes = array( 'Filters', 'Filters_Columns', 'Filters_Post', 'Filters_Term', 'Nav_Menu', 'Classic_Editor', 'Block_Editor' );
// Don't load media filters if option is disabled or if user has no right
if ( $this->options['media_support'] && ( $obj = get_post_type_object( 'attachment' ) ) && ( current_user_can( $obj->cap->edit_posts ) || current_user_can( $obj->cap->create_posts ) ) ) {
$classes[] = 'Filters_Media';
}
@ -113,4 +153,28 @@ class PLL_Admin extends PLL_Admin_Base {
$this->$obj = new $class( $this );
}
}
/**
* Retrieve the locale according to the current language instead of the language
* of the admin interface.
*
* @since 2.0
*
* @return string
*/
public function get_locale_for_sanitization() {
$locale = get_locale();
if ( isset( $_POST['post_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['post_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$locale = $lang->locale;
} elseif ( isset( $_POST['term_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['term_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$locale = $lang->locale;
} elseif ( isset( $_POST['inline_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$locale = $lang->locale;
} elseif ( ! empty( $this->curlang ) ) {
$locale = $this->curlang->locale;
}
return $locale;
}
}

View file

@ -0,0 +1,59 @@
<?php
/**
* @package Polylang
*/
/**
* This class handles the deprecated filter 'block_editor_preload_paths'
* to replace it by the new filter 'block_editor_rest_api_preload_paths'
* and is used for backward compatibility with WP < 5.8.
*
* @since 3.1
*/
class PLL_Block_Editor_Filter_Preload_Paths {
/**
* @var callable
*/
private $callback;
/**
* PLL_Block_Editor_Filter_Preload_Paths constructor.
*
* @since 3.1
*
* @param callable $callback Function or method to be executed when the filter is triggered.
* @param int $priority Priority of execution for the given callback. Default 10.
* @param int $arguments_number Number of arguments to pass to the callback. Default 1.
*/
public function __construct( $callback, $priority = 10, $arguments_number = 1 ) {
$this->callback = $callback;
if ( class_exists( 'WP_Block_Editor_Context' ) ) { // Since WP 5.8.
add_filter( 'block_editor_rest_api_preload_paths', array( $this, 'block_editor_rest_api_preload_paths' ), $priority, $arguments_number );
} else {
add_filter( 'block_editor_preload_paths', $callback, $priority, $arguments_number );
}
}
/**
* Filters the array of REST API paths that will be used to preloaded common data to use with the block editor.
*
* Converts the WP_Block_Editor_Context object to a WP_Post if provided in the context.
*
* @since 3.1
*
* @param string[] $preload_paths The preload paths loaded by the Block Editor.
* @param WP_Block_Editor_Context $block_editor_context The post resource data.
* @return array|mixed|string[] (string|string[])[]
*/
public function block_editor_rest_api_preload_paths( $preload_paths, $block_editor_context = null ) {
if ( null === $block_editor_context ) {
return call_user_func( $this->callback, $preload_paths );
} elseif ( ! empty( $block_editor_context->post ) ) {
return call_user_func_array( $this->callback, array( $preload_paths, $block_editor_context->post ) );
}
return call_user_func_array( $this->callback, array( $preload_paths, $block_editor_context ) );
}
}

View file

@ -1,8 +1,9 @@
<?php
/**
* Displays the translations fields for media
* Needs WP 3.5+
*
* @package Polylang
*/
if ( ! defined( 'ABSPATH' ) ) {
@ -18,22 +19,20 @@ if ( ! defined( 'ABSPATH' ) ) {
}
?>
<tr>
<td class = "pll-media-language-column"><span class = "pll-translation-flag"><?php echo $language->flag; ?></span><?php echo esc_html( $language->name ); ?></td>
<td class = "pll-media-language-column"><span class = "pll-translation-flag"><?php echo $language->flag; // phpcs:ignore WordPress.Security.EscapeOutput ?></span><?php echo esc_html( $language->name ); ?></td>
<td class = "pll-media-edit-column">
<?php
// The translation exists
if ( ( $translation_id = $this->model->post->get_translation( $post_id, $language ) ) && $translation_id !== $post_id ) {
if ( ( $translation_id = $this->model->post->get_translation( $post_ID, $language ) ) && $translation_id !== $post_ID ) {
// The translation exists
printf(
'<input type="hidden" name="media_tr_lang[%s]" value="%d" />%s',
'<input type="hidden" name="media_tr_lang[%s]" value="%d" />',
esc_attr( $language->slug ),
esc_attr( $translation_id ),
$this->links->edit_post_translation_link( $translation_id )
esc_attr( $translation_id )
);
}
// No translation
else {
echo $this->links->new_post_translation_link( $post_id, $language );
echo $this->links->edit_post_translation_link( $translation_id ); // phpcs:ignore WordPress.Security.EscapeOutput
} else {
// No translation
echo $this->links->new_post_translation_link( $post_ID, $language ); // phpcs:ignore WordPress.Security.EscapeOutput
}
?>
</td>

View file

@ -1,11 +1,12 @@
<?php
/**
* displays the translations fields for posts
* Displays the translations fields for posts
*
* @package Polylang
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // don't access directly
exit; // Don't access directly
};
?>
<p><strong><?php esc_html_e( 'Translations', 'polylang' ); ?></strong></p>
@ -17,12 +18,12 @@ if ( ! defined( 'ABSPATH' ) ) {
}
$value = $this->model->post->get_translation( $post_ID, $language );
if ( ! $value || $value == $post_ID ) { // $value == $post_ID happens if the post has been ( auto )saved before changing the language
if ( ! $value || $value == $post_ID ) { // $value == $post_ID happens if the post has been (auto)saved before changing the language
$value = '';
}
if ( isset( $_GET['from_post'] ) ) {
$value = $this->model->post->get( (int) $_GET['from_post'], $language );
if ( ! empty( $from_post_id ) ) {
$value = $this->model->post->get( $from_post_id, $language );
}
$link = $add_link = $this->links->new_post_translation_link( $post_ID, $language );
@ -33,9 +34,9 @@ if ( ! defined( 'ABSPATH' ) ) {
}
?>
<tr>
<th class = "pll-language-column"><?php echo $language->flag ? $language->flag : esc_html( $language->slug ); ?></th>
<td class = "hidden"><?php echo $add_link; ?></td>
<td class = "pll-edit-column pll-column-icon"><?php echo $link; ?></td>
<th class = "pll-language-column"><?php echo $language->flag ? $language->flag : esc_html( $language->slug ); // phpcs:ignore WordPress.Security.EscapeOutput ?></th>
<td class = "hidden"><?php echo $add_link; // phpcs:ignore WordPress.Security.EscapeOutput ?></td>
<td class = "pll-edit-column pll-column-icon"><?php echo $link; // phpcs:ignore WordPress.Security.EscapeOutput ?></td>
<?php
/**
@ -48,18 +49,17 @@ if ( ! defined( 'ABSPATH' ) ) {
?>
<td class = "pll-translation-column">
<?php
printf( '
<label class="screen-reader-text" for="tr_lang_%1$s">%2$s</label>
printf(
'<label class="screen-reader-text" for="tr_lang_%1$s">%2$s</label>
<input type="hidden" name="post_tr_lang[%1$s]" id="htr_lang_%1$s" value="%3$s" />
<span lang="%6$s" dir="%7$s"><input type="text" class="tr_lang" id="tr_lang_%1$s" value="%4$s"%5$s /></span>',
<span lang="%5$s" dir="%6$s"><input type="text" class="tr_lang" id="tr_lang_%1$s" value="%4$s" /></span>',
esc_attr( $language->slug ),
/* translators: accessibility text */
esc_html__( 'Translation', 'polylang' ),
empty( $value ) ? 0 : esc_attr( $selected->ID ),
empty( $value ) ? '' : esc_attr( $selected->post_title ),
empty( $link ) ? ' disabled="disabled"' : '',
( empty( $value ) ? 0 : esc_attr( $selected->ID ) ),
( empty( $value ) ? '' : esc_attr( $selected->post_title ) ),
esc_attr( $language->get_locale( 'display' ) ),
$language->is_rtl ? 'rtl' : 'ltr'
( $language->is_rtl ? 'rtl' : 'ltr' )
);
?>
</td>

View file

@ -1,7 +1,8 @@
<?php
/**
* Displays the translations fields for terms
*
* @package Polylang
*/
if ( ! defined( 'ABSPATH' ) ) {
@ -34,7 +35,7 @@ else {
if ( isset( $term_id ) && ( $translation_id = $this->model->term->get_translation( $term_id, $language ) ) && $translation_id != $term_id ) {
$translation = get_term( $translation_id, $taxonomy );
}
if ( isset( $_GET['from_tag'] ) && ( $translation_id = $this->model->term->get( (int) $_GET['from_tag'], $language ) ) && ! $this->model->term->get_translation( $translation_id, $lang ) ) {
if ( ! empty( $from_term_id ) && ( $translation_id = $this->model->term->get( $from_term_id, $language ) ) && ! $this->model->term->get_translation( $translation_id, $lang ) ) {
$translation = get_term( $translation_id, $taxonomy );
}
@ -48,7 +49,7 @@ else {
?>
<tr>
<th class = "pll-language-column">
<span class = "pll-translation-flag"><?php echo $language->flag ? $language->flag : esc_html( $language->slug ); ?></span>
<span class = "pll-translation-flag"><?php echo $language->flag ? $language->flag : esc_html( $language->slug ); // phpcs:ignore WordPress.Security.EscapeOutput ?></span>
<?php
printf(
'<span class="pll-language-name%1$s">%2$s</span>',
@ -60,25 +61,25 @@ else {
<?php
if ( isset( $term_id ) ) {
?>
<td class = "hidden"><?php echo $add_link; ?></td>
<td class = "pll-edit-column"><?php echo $link; ?></td>
<td class = "hidden"><?php echo $add_link; // phpcs:ignore WordPress.Security.EscapeOutput ?></td>
<td class = "pll-edit-column"><?php echo $link; // phpcs:ignore WordPress.Security.EscapeOutput ?></td>
<?php
}
?>
<td class = "pll-translation-column">
<?php
printf( '
<label class="screen-reader-text" for="tr_lang_%1$s">%2$s</label>
printf(
'<label class="screen-reader-text" for="tr_lang_%1$s">%2$s</label>
<input type="hidden" class="htr_lang" name="term_tr_lang[%1$s]" id="htr_lang_%1$s" value="%3$s" />
<span lang="%6$s" dir="%7$s"><input type="text" class="tr_lang" id="tr_lang_%1$s" value="%4$s"%5$s /></span>',
esc_attr( $language->slug ),
/* translators: accessibility text */
esc_html__( 'Translation', 'polylang' ),
empty( $translation ) ? 0 : esc_attr( $translation->term_id ),
empty( $translation ) ? '' : esc_attr( $translation->name ),
empty( $disabled ) ? '' : ' disabled="disabled"',
( empty( $translation ) ? 0 : esc_attr( $translation->term_id ) ),
( empty( $translation ) ? '' : esc_attr( $translation->name ) ),
disabled( empty( $disabled ), false, false ),
esc_attr( $language->get_locale( 'display' ) ),
$language->is_rtl ? 'rtl' : 'ltr'
( $language->is_rtl ? 'rtl' : 'ltr' )
);
?>
</td>

View file

@ -2,6 +2,471 @@
This file contains only old changelog. See readme.txt for newer versions.
= 2.9.2 (2021-02-02) =
* Pro: Fix translation of CPTUI plural label and description not working
* Add Spanish (Ecuador) to the list of predefined languages
* Fix typo in "WordPress" string translation group. Props Viktor Szépe #682
= 2.9.1 (2020-12-15) =
* Fix PHP notice: Undefined property: PLL_Cache_Compat::$options with cache plugins. Props bahaa-almahamid. #658
* Fix title of the search results page with Yoast SEO > 14.0
= 2.9 (2020-12-07) =
* Add compatibility with WordPress 5.6
* Pro: Add locale fallback used when the theme or plugins translations are not available
* Pro: Fix SSO and browser preferred language redirect when using multiple domains
* Pro: Fix post slugs for German and Danish in the REST API
* Pro: Fix a fatal error in ACF integration when saving url modifications with multiple domains
* Pro: Fix a deprecated notice fired by ACF since the version 5.9.2
* Pro: Fix ACF relationship fields not reloaded when changing the language in the classic editor
* Update plugin updater to version 1.8
* Add Lower Sorbian to the list of predefined language
* Options are now translated on backend when using the admin language filter
* Keep previous translations when modifying an option value
* Add navigation markup to the language switcher widget
* Fix canonical redirect for taxonomy terms
* Fix a fatal error when deleting a post with a translation group corrupted in the database
* Fix a fatal error when switching to plain permalinks and using multiple domains
* Fix a conflict with WP Sweep which could corrupt languages
* Fix title displayed instead of meta description with Yoast SEO > 14.0
* Fix PHP Notice: Undefined index: wp_the_query in /frontend/choose-lang-content.php on line 92
= 2.8.4 (2020-11-03) =
* Pro: Remove useless bulk translate action for ACF fields groups
* Pro: Fix the translation of the CPTUI labels when the language is set from the content
* Fix sitemaps redirected to the default language since WP 5.5.1
* Fix object cache not flushed for sticky posts #601
* Fix blog page broken when trashing a page and the blog page is not translated in all languages
* Fix custom flags ignored in WPML compatibility mode
* Fix breadcrumb for untranslated post types in Yoast SEO
= 2.8.3 (2020-10-13) =
* Honor install_languages capability to download language packs
* Pro: Fix integrations not loaded (with The Events Calendar, CPTUI, Content blocks)
* Pro: Fix fatal error with ACF if a flexible content includes a repeater and a relationship
* Pro: Fix terms sharing their slug impossible to update without changing the slug
* When available, use wpcom_vip_get_page_by_path() instead of get_page_by_path()
* Fix queries filtered when editing a post that was declared untranslatable after it got a language
* Fix issues with Yoast SEO 14.0+ (breadcrumbs, canonical, title and description)
= 2.8.2 (2020-09-08) =
* Pro: Fix posts sharing the same slug displayed on the same page
* Fix: Don't use a javascript localized string removed in WP 5.5 #568
* Fix fatal error in site health when no language is defined #563
* Fix various issues with Yoast SEO 14.x #65, #503, #505
* Fix fatal error with MU Domain Mapping when saving domains in Polylang settings #569
= 2.8.1 (2020-08-25) =
* Pro: Fix fatal error with WP 4.9
* Fix pll_the_languages() with 'raw' option returning html flag instead of flag url #558
* Fix compatibility with Duplicate Posts not correcly loaded #557
* Fix custom flag size in admin bar language switcher #559
* Fix tag clouds mixed in the classic editor #561
= 2.8 (2020-08-17) =
* Pro: Add a language switcher block
* Pro: Add compatibility with block image edition introduced in WP 5.5
* Pro: Fix our private taxonomies being displayed in the ACF field group rules.
* Pro: Fix incorrect flags loaded from the block editor
* Pro: Fix SSO causing a wrong redirect when using subdomains (introduced in 2.7.4)
* Pro: Fix a performance issue on the plugins list
* Pro: Fix option to automatically duplicate media in all languages when uploading a new file not honored in block image
* Use composer for autoload and Polylang Pro dependency on Polylang
* Display a flag for each post in the posts list tables (same for terms). #515
* Add test for the homepage translations to Site Health
* Add debug information to Site Health
* Add compatibility with the sitemaps introduced in WP 5.5 #451
* Always filter WP_Query by the current language
* Support wildcards in "admin-texts" parent keys in wpml-config.xml
* Fix sticky posts showed for all languages when the admin language filter is active #469
* Fix a performance issue on the pages list
* Fix dependency to jQuery Migrate removed from WP 5.5 #539
* Fix: output secure cookie when using a cache plugin and ssl #542
* Fix the possibility to create 2 terms with the same name in the same language, without specifying the second slug.
* Fix sticky posts appearing 2 times in WP 5.5
= 2.7.4 (2020-06-29) =
* Pro: Allow using our /untranslated-posts REST endpoint for non-public post types
* Pro: Fix broken display in the block editor sidebar when a language has no flag
* Pro: Fix SSO breaking the preview on secondary domains
* Pro: Fix ACF translation option not working for term custom fields
* Pro: Fix a styling issue in the fields group list table in ACF 5.9
* Add Spanish from Puerto Rico to the predefined list of languages
= 2.7.3 (2020-05-26) =
* Security: Slash metas
* Pro: Fix categories not savedafter the language has been switched in the block editor
* Pro: Fix ACF fields stored as integers instead of strings
* Pro: Fix ACF untranslated posts or terms being copied when creating a new translation
* Pro: Fix PHP notice with ACF when a repeater or group is included in a flexible content
* Pro: Fix "DevTools failed to load SourceMap" warning in browser console
* Update plugin updater to 1.7.1
* Honor the filter "pll_the_language_link" when the language switcher displays a dropdown #506
* Fix "Something went wrong" message when quick editing untranslated post types #508
* Fix wpseo_opengraph deprecated warning #509
= 2.7.2 (2020-04-27) =
* Pro: Re-allow to modify the capability for strings translations
* Pro: Fix redirect for posts having the same slug as a media
* Pro: Fix PHP notice with ACF flexible content
* Pro: Fix a fatal error with InfiniteWP
* Update plugin updater to 1.7
* Fix font in setup wizard
= 2.7.1 (2020-04-09) =
* Pro: Fix untranslated post types filtered by the parameter in the REST API #493
* Fix fatal error when the function idn_to_ascii is not available
* Fix PHP warning warning when a 3rd party plugin declares options not stored in DB in wpml-config.xml #492
* Fix fatal error when a 3rd party plugin declares options stored as objects in wpml-config.xml #494
= 2.7 (2020-04-06) =
* Minimum WordPress version is now 4.9
* Pro: Strings translations can now be exported and imported (in PO format)
* Pro: Allow to decide individually which ACF fields to copy or synchronize
* Pro: Add action pll_inactive_language_requested
* Pro; Fix fatal error in The Events Calendar compatibility when no language is defined yet
* Pro: Fix bulk translate when a post has no language
* Pro: Fix reusable block saved without language
* Pro: Fix post requested by slug not filtered in REST API, when the slug is shared
* Add a setup wizard
* Add Swahili, Upper Sorbian, Sindhi and Spanish from Uruguay to the list of predefined languages
* Add flags in the predefined list of languages
* Allow to hide the metaboxes from the screen options
* The deletion of the plugin's data at uninstall is now controlled by a PHP constant instead of an option #456
* Add parent in ajax response when selecting a term in autocomplete field #328
* Add Vary: Accept-Language http header in home page redirect. Props @chesio #452
* Improve performance to register/unregister WPML strings
* Add support for the action wpml_switch_language
* Add post_status to the list of accepted args of pll_count_posts()
* Apply the filter pll_preferred_language in wp-login.php
* Use filtered wrappers to create meta when creating media translations #231
* Allow to translate the Twenty Seventeen header video Youtube url #460
* Notices are now dismissed per site instead of per user #478
* Fix terms not visible in the quick edit when only one language is defined and teh admin language filter is active
* Fix post state not displayed for translations of the privacy policy page #395
* Fix wildcards not correctly interpreted in wpml-config.xml
* Fix product categories with special characters duplicated when importing WooCommerce products #474
= 2.6.10 (2020-02-19) =
* Pro: Fix sticky posts not filtered in REST API (introduced in 2.6.9)
* Fix wrong language detected if a child page uses the slug of another language
* Fix a PHP notice with PHP 7.4. #438
* Fix lang-item-first class in language switcher when the current language is hidden. #445
* Fix partially a conflict with Fusion Builder (the other part of the conflict being in Fusion Builder).
= 2.6.9 (2020-01-15) =
* Pro: Use 'parse_query' rather than 'rest_{$type}_query' to filter REST requests.
* Pro: Filter the comments REST endpoint.
* Pro: Fix duplication of terms without language.
* Pro: Fix fatal error when Admin Columns is activated and no language is defined yet.
* Fix shortlink when using one subdomain or domain per language
= 2.6.8 (2019-12-11) =
* Pro: Fix conflict with JetThemesCore from Crocoblock
* Fix: better detection of REST requests when using plain permalinks
* Fix usage of deprecated action wpmu_new_blog in WP 5.1+
* Fix PHP notices with PHP 7.4
= 2.6.7 (2019-11-14) =
* Require PHP 5.6
* Fix PHP warning in WP 5.3
= 2.6.6 (2019-11-12) =
* Pro: Fix wrong ajax url when using one domain per language
* Pro: Fix conflict with user switching plugin when using multiple domains
* Pro: Fix latest posts block in WP 5.3
* Fix database error when attempting to sync an untranslated page parent
* Fix a conflict with the theme Neptune by Osetin
= 2.6.5 (2019-10-09) =
* Pro: Require ACF 5.7.11+ to activate the compatibility to avoid fatal errors with older versions
* Pro: Avoid translating empty front slug (could cause a wrong redirect to /wp-admin)
* Pro: Fix filter wp_unique_term_slug not always correctly applied.
* Pro: Fix a conflict with Divi causing post synchronization buttons to be displayed multiple times
* Avoid notice in WP CLI context
= 2.6.4 (2019-08-27) =
* Pro: Fix a conflict preventing meta synchronization when ACF is active
* Pro: Fix post metas not correctly copied when translating a Beaver Builder page
* Pro: Fix a fatal error when posts made with Elementor are synchronized
* Pro: Fix Prewiew button not working correctly when using one domain per language
* Pro: Fix post synchronization not available for WP CRON and WP CLI
* Fix future posts not available in the autocomplete input field of the languages metabox
* Fix translations files not loaded on REST requests
* Fix deleted term parent not synchronized
= 2.6.3 (2019-08-06) =
* Pro: Fix fatal error when updating an ACF field from frontend
* Pro: Add action 'pll_post_synchronized'
* Allow to get the current or default language object using the API. Props Jory Hogeveen. #359
* Fix empty span in languages switcher widget when showing only flags
* Fix wpml_register_single_string when updating the original string
= 2.6.2 (2019-07-16) =
* Pro: Fix slow admin in case the translations update server can't be reached
* Pro: Fix value not correctly translated for ACF clone fields in repeater
* Fix strings translations mixed when registered via the WPML compatibility. #381
= 2.6.1 (2019-07-03) =
* Pro: Fix Yoast SEO sitemap for inactive languages when using subdomains or multiple domains
* Fix fatal error in combination with Yoast SEO and Social Warfare
* Fix post type archive url in Yoast SEO sitemap
= 2.6 (2019-06-26) =
* Pro: Remove all languages files. All translations are now maintained on TranslationsPress
* Pro: Move the languages metabox to a block editor plugin
* Pro: Better management of user capabilities when synchronizing posts
* Pro: Separate REST requests from the frontend
* Pro: Copy the post slug when duplicating a post
* Pro: Duplicate ACF term metas when terms are automatically duplicated when creating a new post translation
* Pro: Fix hierarchy lost when duplicating terms
* Pro: Fix page shared slugs with special characters
* Pro: Fix synchronized posts sharing their slug when the language is set from the content
* Pro: Fix PHP warning with ACF Pro 5.8.1
* Pro: Fix ACF clone fields not translated in repeaters
* Better management of user capablities when synchronizing taxonomies terms and custom fields
* Extend string translations search to translated strings #207
* Update plugin updater to 1.6.18
* Honor the filter `pll_flag` when performing the flag validation when creating a new language
* Modify the title and the label for the language switcher menu items #307
* Add support for international domain names
* Add a title to the link icon used to add a translation #325
* Add a notice when a static front page is not translated in a language
* Add support for custom term fields in wpml-config.xml
* Add filter `pll_admin_languages_filter` for the list of items the admin bar language filter
* Add compatibility with WP Offload Media Lite. Props Daniel Berkman
* Yoast SEO: Add post type archive url in all languages to the sitemap
* Fix www. not redirected to not www. for the home page in multiple domains #311
* Fix cropped images not being synchronized
* Fix auto added page to menus when the page is created with the block editor
* Fix embed of translated static front page #318
* Fix a possible infinite redirect if the static front page is not translated
* Fix incorrect behavior of action 'wpml_register_single_string' when updating the string source
* Fix fatal error with Jetpack when no languages has been defined yet #330
* Fix a conflict with Laravel Valet. Props @chesio. #250
* Fix a conflict with Thesis.
* Fix a conflict with Pods in the block editor. Props Jory Hogeveen. #369
* Fix fatal error with Twenty Fourteen introduced in version 2.5.4. #374
= 2.5.4 (2019-05-28) =
* Add Kannada to the predefined languages list
* Yoast SEO: Fix primary product cat not copied or synchronized
* WPMU Domain Mapping: Fix incorrect domain used for the theme
* Fix style-rtl.css not loaded when the language is set from the content #356
* Fix Jetpack featured pages not working. Props Anis Ladram. #357
* Fix Call to undefined function wp_generate_attachment_metadata()
= 2.5.3 (2019-04-16) =
* Add de_AT and pt_AO to the predefined languages list
* Pro: Add filter pll_translate_blocks
* Pro: fix PHP notice when the queried post type has been modified to an array
* Pro: fix PHP warning when combined with The Event Calendar and Page builder by SiteOrigin
= 2.5.2 (2019-02-12) =
* Pro: Fix translated slugs not accepting forward slashes
* Pro: Fix fatal error with ACF Pro 5.7.11
* Fix parent categories incorrectly synchronized #327
= 2.5.1 (2019-01-16) =
* Security: Fix categories and media duplication not protected from CSRF
* Pro: Allow to update the plugin with WP CLI
* Pro: Fix search in the button block not filtered in the correct language (needs WP 5.1)
* Add Saraiki to the predefined languages list
* Fix a conflict causing a blank page with Divi
= 2.5 (2018-12-06) =
* Add compatibility with WP 5.0
* Fix custom flags when the WP content folder is not in the WP install folder
* Fix PHP notice if a language has no flag
= 2.4.1 (2018-11-27) =
* Pro: Add compatibility with REST API changes made in WP 5.0
* Pro: Fix sticky posts in the REST API
* Pro: Fix overwritten custom post slug when the post is updated with the REST API
* Pro: Fix bulk translate for media
* Fix a conflict with Custom sidebars and Content aware sidebars
* Fix a conflict with the theme Pokemania
* Fix PHP notices when using the function 'icl_link_to_element' for terms
* Fix title slugs for posts written in German
= 2.4 (2018-11-12) =
* Minimum WordPress version is now 4.7
* Pro: Add the possibility to bulk duplicate or bulk synchronize posts.
* Pro: Add compatibility with Admin Columns
* Pro: Add synchronized posts to the REST API
* Pro: Fix variations messed when changing WooCommerce attributes slugs
* Pro: Fix incorrect language for ajax requests made on front by The Events Calendar
* Pro: Fix term not duplicated correctly when the language is set from the content
* Refactor the core to activate on front and for the REST api actions that were previously available only in the backend (language checks, synchronizations...).
* Add flags to widgets displayed in only one language (Props Jory Hogeveen) #257
* Honor the filter 'pll_the_language_args' for all options in menus #237
* Add better filters for default flags and custom flags
* Custom flags can now be stored in the polylang directory in the theme
* Custom flags can now use SVG
* Add compatibility with Jetpack featured content module
* Fix Twenty Fourteen featured posts possibly not filtered per language
* Fix home url not working with WordPress MU Domain mapping
* Fix Assigning a parent category breaking the hierarchy of translated category
* Fix: Accept 0,1 and 1.0 as q factors in browser preferred language detection (Props Dominic Rubas)
* Fix performance issue when using hundreds of widgets
* Fix translations possibly wrong if the post language is changed without saving the post after
= 2.3.11 (2018-10-03) =
* Pro: Add action 'pll_created_sync_post'
* Pro: Fix language and translations not included for tags in the REST API
* Fix Assigning a parent category breaking the hierarchy of translated category
= 2.3.10 (2018-08-16) =
* Fix Lingotek notice not dismissable
* Fix fatal error with the widget calendar
= 2.3.9 (2018-08-14) =
* Add a notice to inform about Polylang for WooCommerce
* Deprecate PLL_Pointer
* Fix bulk editing pages with no language breaking hierarchy #281
* Fix an edge case where rewrite rules could be messed on a multisite
* MU Domain Mapping: fix secondary domain redirected to primary domain
= 2.3.8 (2018-07-16) =
* Pro: Duplicate term meta when duplicating a post creates new terms
* Pro: Add compatibility with ACF Pro when it's bundled with the theme
* Pro: Fix a fatal error when duplicating posts
* Set cookie during the home redirect
* Accept a port in the url to detect the site home
* Add filter 'pll_is_cache_active' to allow to load the cache compatibility #270 #274
* Fix potential fatal error when a 3rd party misuses the 'wpml_active_languages' filter #268
* Fix Uncaught TypeError: s.split is not a function. Props Wouter Van Vliet #262
* Fix text alignment for RTL scripts in Lingotek panel #247
* Fix html language attribute filter on admin
* Fix cookie expiration time when set in js. Props Jens Nachtigall #271
* Fix fatal error when a 3rd party misuses the WP_Query tax_query param. Props JanneAalto #252
* Fix an edge case which could mess home pages on a multisite
= 2.3.7 (2018-06-07) =
* Pro: The Events Calendar: Fix untranslated events shown in all languages
* Avoid displaying edit links of translations of the privacy policy page to non-admin
* Fix draft created when creating a new page on multisite
* Do not prevent using the cache for home when using WP Rocket 3.0.5 or later #236
* Fix language filter applied to wrong queries on admin side
= 2.3.6 (2018-05-17) =
* Pro: Fix post type archive slug not translated in ACF page link fields
* WP 4.9.6: Translate the privacy policy page
* WP 4.9.6: Add the translated user descriptions to exported personal data
* Update Plugin updater to version 1.6.16
* Fix conflict with the plugin View Admin As. Props Jory Hogeveen. #253
= 2.3.5 (2018-05-08) =
* Pro: Fix translated CPT slugs when one CPT name is a substring of another one. Props Steve Reimer.
* Pro: Fix canonical redirection for post types archives when the CPT slug is translated
* Pro: Fix ACF private key uselessly synchronized when the public custom field is not synchronized
* Add filter 'pll_filter_query_excluded_query_vars'
* Redirect www. to non www. when using multiple domains
* Fix Yoast SEO category sitemap not filtered by language when using multiple domains
* Fix PLL_COOKIE === false not honored when using a cache plugin. #248
* Fix empty predefined languages list
= 2.3.4 (2018-03-27) =
* Pro: Fix conflict with Pods related to translated slugs for custom post types
* Add Friulian to the predefined languages list
* Fix conflict (javascript error) with Gütenberg #225
* Fix conflict on ajax requests introduced by WooCoommerce 3.3.4
* Fix queries by 'category_name' not auto translated #238
= 2.3.3 (2018-03-15) =
* Pro: Fix tax query using a term sharing slugs (fix a conflict with Fusion Builder)
* Restore Polylang (free) on REST requests, while disabling the language filter as in v2.3
* Rework auto translated query with taxonomy in different language #223
* Synchronize Yoast SEO primary category (needs Yoast SEO 7.0+)
* Fix PHP warning introduced by Yoast SEO 7.0 #229
* Fix tax query when using the relation 'OR'
* Fix a conflict with the combination of Barrel + WP Bakery Page Builder
* Fix broken redirect with MU domain mapping #226
* Fix site title not translated in password change email
= 2.3.2 (2018-03-05) =
* Pro: Fix REST requests not filtered by the requested language (introduced in 2.3).
* Pro: Fix error 404 on single posts if posts are untranslatable
* Deactivate Polylang (free) on REST requests by default.
* Fix translated terms unassigned from posts when deleting a term
* Fix auto translated query with taxonomy in different language returning empty results since WP 4.9 #223
* Fix conflict with a homepage option of the theme Extra
* Fix warning when filtering get_pages()
= 2.3.1 (2018-02-15) =
* Pro: Fix GET REST request with slug parameter deleting the post slug
* Fix http request with a custom query var being redirected to the home page #216
= 2.3 (2018-01-30) =
* Pro: Duplicating a post now duplicates untranslated terms and the featured image (if media are translatable)
* Pro: Add filter 'pll_sync_post_fields'
* Pro: Translate ACF Pro clone fields when creating a new field group translation
* Pro: Allow to share slugs when creating a post or term with the REST API
* Pro: Load asynchronously the script added on front for multiple domains and subdomains
* Pro: Fix 'lang' parameter not interpreted when the query includes 'name'
* Refactor the synchronization of metas for better synchronization and performance improvement
* Refactor the synchronization of taxonomy terms for performance improvement
* Refactor language and translations saving for performance improvement
* Refactor the synchronization of sticky posts
* Remove all languages files. All translations are now maintained on https://translate.wordpress.org/projects/wp-plugins/polylang #199
* Refactor the list of languages to merge predefined languages, Facebook locales and fixes for W3C locales
* Automatically deactivate Polylang when activating Polylang Pro
* Disable programmatically translated post types and taxonomies in settings. Props Ulrich Pogson. #180
* Set the cookie language in Javascript when a cache plugin is active
* Automatically remove the home page from cache when requesting the detection of the browser preferred language
* Use relative urls for the admin language filter in admin bar. #209
* Disable auto translation of WP_Term_Query if it has a 'lang' parameter
* Don't filter REST requests by default. #211
* Fix Yoast SEO statistics in dashboard showing only the default language. #211
* Fix WP Rocket clearing the cache of the wrong adjacent post
* Fix random header image
* Fix home page not correctly loaded when adding a query var
* Fix: Impossible to change the language code when the language code is also a WordPress locale.
= 2.2.8 (2018-01-09) =
* Pro: Fix: Impossible to link past events by translation in The Events Calendar
@ -1470,4 +1935,3 @@ This version does include important changes in database. More than ever, make a
= 0.1 (2011-09-22) =
* Initial release

View file

@ -1 +0,0 @@
#pll-licenses-table td,.translation label{vertical-align:top}#add-lang select{width:95%}.column-locale,.languages .column-slug{width:15%}.column-default_lang{width:5%}.column-count,.column-flag,.column-term_group{width:10%}.icon-default-lang:before{font-family:dashicons;content:"\f155"}.form-field input[type=radio]{width:auto;margin-right:2px}#pll-about-box p,#pll-recommended p{text-align:justify}#pll-about-box input{margin:0;padding:0;float:right}.stringstranslations .column-context,.stringstranslations .column-name{width:10%}.stringstranslations .column-string{width:33%}.translation label{display:inline-block;width:23%}.translation input,.translation textarea{width:72%}.pll-settings{margin-top:20px}.pll-settings .plugin-title{width:25%}#wpbody-content .pll-settings .pll-configure tr{display:table-row}#wpbody-content .pll-settings .pll-configure td{display:table-cell}#wpbody-content .pll-settings .pll-configure>td{padding:20px 20px 20px 40px}.pll-configure legend{font-size:14px;font-weight:600;margin-bottom:.5em}.pll-configure td .description{margin-top:2px;margin-bottom:.5em}.pll-configure p.submit{margin-top:20px}.pll-configure .button{margin-right:20px}.pll-configure fieldset{margin-bottom:1.5em}.pll-inline-block-list{margin:0}.pll-inline-block-list li{display:inline-block;margin:0;width:250px}#pll-domains-table td{padding:2px 2px 2px 1.5em;-webkit-box-shadow:none;box-shadow:none;border:none}.pll-settings-url-col{display:inline-block;width:49%;vertical-align:top}#pll-licenses-table label{font-size:1em;font-weight:600}.pll-configure .pll-deactivate-license{margin:0 0 0 20px}td[class*=column-language_],th[class*=column-language_]{width:1.5em}.pll-dir-rtl input[type=text],.pll-dir-rtl textarea{direction:rtl}.pll-dir-ltr input[type=text],.pll-dir-ltr textarea{direction:ltr}.pll-dir-ltr .tr_lang,.pll-dir-rtl .tr_lang{direction:inherit}#post-translations p{float:left}#post-translations table{table-layout:fixed;width:100%;clear:both}#post-translations a{text-decoration:none}#post-translations .pll-column-icon,#post-translations .pll-language-column{width:20px}#post-translations .tr_lang{width:100%}#post-translations td{padding:2px}#post-translations .spinner,#term-translations .spinner{float:none;margin:0;background-position:center;width:auto}.pll-column-icon{text-align:center}#select-post-language .pll-select-flag{padding:4px;margin-right:32px}#select-media-language .pll-select-flag{padding:4px;margin-right:10px}.pll-media-edit-column{float:right}.pll-translation-flag{margin-right:14px}#select-add-term-language .pll-select-flag{padding:11px;margin-right:13px}#select-edit-term-language .pll-select-flag{padding:11px;margin-right:4px}#term-translations p{font-size:12px;font-style:normal;padding:2px;color:#23282d}#add-term-translations,#edit-term-translations{width:95%}#term-translations .pll-language-column{line-height:28px;width:20%}#add-term-translations .pll-language-column,#term-translations .pll-edit-column{width:20px}#edit-term-translations .pll-language-column{padding:15px 10px;font-weight:400}.pll_icon_tick:before{content:"\f147"}.pll_icon_add:before{content:"\f132"}.pll_icon_edit:before{content:"\f464"}[class^=pll_icon_]{font:20px/1 dashicons;vertical-align:middle}#wpadminbar #wp-admin-bar-languages .ab-item img{margin:0 8px 0 2px}#wpadminbar #wp-admin-bar-languages #wp-admin-bar-all .ab-item .ab-icon{float:none;top:4px}#wpadminbar #wp-admin-bar-languages .ab-icon:before{content:"\f326";top:1px}@media screen and (max-width:782px){#wpbody-content .pll-settings .pll-configure>td{padding:20px}#wpbody-content .pll-settings #cb{padding:20px 9px}.pll-inline-block{width:auto}.pll-settings-url-col{display:block;width:100%}#wpbody-content .pll-settings #pll-licenses-table td{display:block}.pll-configure .pll-deactivate-license{margin:10px 0 5px}.stringstranslations .column-context,.stringstranslations .column-name{display:none}.translation label{display:block;width:95%;padding-left:0}.translation input{width:95%}#edit-term-translations .pll-language-name,#select-add-term-language .pll-select-flag,#select-edit-term-language .pll-select-flag{display:none}#edit-term-translations{width:100%}#add-term-translations .pll-language-column{line-height:38px}#edit-term-translations td{padding:8px 10px}#edit-term-translations .pll-edit-column,#edit-term-translations .pll-language-column{width:20px}.term-translations .pll-edit-column,.term-translations .pll-language-column,.term-translations .pll-translation-column{display:table-cell}.term-translations .hidden{display:none}#wpadminbar #wp-admin-bar-languages{display:block}#wpadminbar #wp-admin-bar-languages>.ab-item{width:50px;text-align:center}#wpadminbar #wp-admin-bar-languages>.ab-item .ab-icon:before{font:32px/1 dashicons;top:-1px}#wpadminbar #wp-admin-bar-languages>.ab-item img{margin:19px 0}#wpadminbar #wp-admin-bar-languages #wp-admin-bar-all .ab-item .ab-icon{margin-right:6px;font-size:20px!important;line-height:20px!important}}

View file

@ -3,6 +3,19 @@
width: 95%;
}
#add-lang label {
margin: 0.35em 0 0.5em;
}
.pll-legend {
display: block;
padding: 2px 0;
color: #1d2327;
font-weight: 400;
text-shadow: none;
margin: 0.35em 0 0.5em;
}
.column-locale,
.languages .column-slug {
width : 15%
@ -21,10 +34,13 @@
font-family: 'dashicons';
content: "\f155";
}
.form-field input[type="radio"] {
width: auto;
margin-right: 2px;
.pll-icon:before{
display: inline-block;
text-align: left;
width: 15px;
}
.pll-circle:before{
content: "\25cf";
}
/* about Polylang metabox */
@ -55,9 +71,22 @@
vertical-align: top;
}
.translation {
display: flex; /* fix #691 to remove default margin bottom */
}
@media screen and (max-width: 782px) { /* reset default display property for small device */
.translation{
display: block;
}
}
.translation textarea{
display: block; /* fix #691 to remove default margin bottom */
}
.translation input,
.translation textarea {
width: 72%;
box-sizing: border-box; /* to be sure field don't overrun outside their wrapper */
margin-bottom: 4px; /* fix #691 set the same margin bottom for both textarea and input tags */
}
/* settings */
@ -143,9 +172,10 @@
}
/* language columns in edit.php and edit-tags.php */
th[class*='column-language_'],
td[class*='column-language_'] {
.wp-list-table th[class*='column-language_'],
.wp-list-table td[class*='column-language_'] {
width: 1.5em;
box-sizing: content-box; /* Override ACF 5.9.0 styles */
}
/* Text direction in post.php and edit-tags.php */
@ -165,8 +195,17 @@ td[class*='column-language_'] {
}
/* languages metabox in post.php */
#ml_box p {
margin-top: 1em;
}
#post-translations p {
float: left;
margin-top: 1em;
}
.rtl #post-translations p {
float: right;
}
#post-translations table {
@ -200,13 +239,15 @@ td[class*='column-language_'] {
width: auto;
}
.pll-column-icon {
text-align: center;
}
#select-post-language .pll-select-flag {
padding: 4px;
margin-right: 32px;
margin-right: 10px;
}
.rtl #select-post-language .pll-select-flag {
padding: 4px;
margin-right: 0px;
margin-left: 10px;
}
/* specific cases for media */
@ -236,7 +277,7 @@ td[class*='column-language_'] {
#term-translations p {
/* same style as label */
font-size: 12px;
font-weight: 400;
font-style: normal;
padding: 2px;
color: #23282d;
@ -263,12 +304,10 @@ td[class*='column-language_'] {
}
/* icon fonts */
.pll_icon_tick:before {
content: "\f147";
}
.pll_icon_add:before {
content: "\f132";
}
.pll_icon_edit:before {
content: "\f464";
}
@ -293,6 +332,47 @@ td[class*='column-language_'] {
top: 1px;
}
#wp-admin-bar-languages.pll-filtered-languages {
background: #a03f3f;
}
/* Enforce white color for WordPress admin light theme. */
#wpadminbar #wp-admin-bar-languages.pll-filtered-languages span.ab-label{
color: #fff;
}
/* Notices */
.pll-notice.notice {
padding-right: 38px;
position: relative;
}
.pll-notice a.notice-dismiss {
text-decoration: none;
}
.pll-notice .button {
margin-right: 10px;
}
/* Metaboxes holder in Strings translations screen */
.languages_page_mlang_strings .metabox-holder > div {
display: flex;
}
.languages_page_mlang_strings .metabox-holder > div > div {
flex-grow: 1;
}
.languages_page_mlang_strings .metabox-holder > div > div:nth-child(2n) {
margin-left: 1rem;
}
.languages_page_mlang_strings .metabox-holder > div > div.closed {
border:0;
background: none;
}
.languages_page_mlang_strings .metabox-holder > div > div.closed .postbox-header{
border: 1px solid #ccd0d4;
background: #fff;
}
@media screen and ( max-width: 782px ) {
/* settings */
#wpbody-content .pll-settings .pll-configure > td {
@ -323,21 +403,25 @@ td[class*='column-language_'] {
}
/* strings translations table */
.stringstranslations .column-context,
.stringstranslations .column-name {
display: none; /* backward compatibility WP < 4.3 */
}
.translation label {
display: block;
width: 95%;
padding-left: 0;
}
.translation input {
.translation input,
.translation textarea {
width: 95%;
}
/* Metaboxes holder in Strings translations screen */
.languages_page_mlang_strings .metabox-holder > div {
flex-direction: column;
}
.languages_page_mlang_strings .metabox-holder > div > div:nth-child(2n) {
margin-left: 0;
}
/* hide selected language flag and translations language name */
#select-add-term-language .pll-select-flag,
#select-edit-term-language .pll-select-flag,

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,85 @@
/* By default Polylang dialog box use WordPress jQuery UI dialog styles.
However WooCommerce loads its own jQuery UI dialog styles and we need to override them by ours
to revert to the default WordPress ones.
*/
.pll-confirmation-modal.ui-widget,
.pll-confirmation-modal.ui-widget .ui-widget,
.pll-confirmation-modal .ui-widget {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
font-size: 13px;
}
.pll-confirmation-modal.ui-dialog {
padding: 0;
z-index: 100102;
background: #fff;
border: 0;
color: #444;
border-radius: 0; /* Override WooCommerce dialog styles - jQuery UI 1.11.4 - WP < 5.6 */
}
.ui-dialog.pll-confirmation-modal .ui-dialog-titlebar {
background: #fcfcfc;
border-radius: 0;
border: 0;
border-bottom: 1px solid #dfdfdf;
height: 36px;
font-size: 18px;
font-weight: 600;
line-height: 2;
padding: 0 36px 0 16px;
color: #444;
position: static;
}
.ui-dialog.pll-confirmation-modal .ui-dialog-title {
float: none;
width: auto;
margin: 0;
}
.pll-confirmation-modal .ui-widget-header .ui-icon {
background: none;
position: static;
}
.pll-confirmation-modal .ui-button.ui-dialog-titlebar-close {
padding: 0;
margin: 0;
top: 0;
right: 0;
width: 36px;
height: 36px;
border: 0; /* Override WooCommerce dialog styles - jQuery UI 1.11.4 - WP < 5.6 */
background: none; /* Override WooCommerce dialog styles - jQuery UI 1.11.4 - WP < 5.6 */
}
.ui-dialog.pll-confirmation-modal .ui-dialog-content {
border: 0;
padding: 16px;
color: #444;
position: static;
box-sizing: border-box;
}
.ui-dialog.pll-confirmation-modal .ui-dialog-buttonpane{
margin: 0;
padding: 16px;
border: 0;
background: #fcfcfc;
border-top: 1px solid #dfdfdf;
}
.ui-dialog.pll-confirmation-modal .ui-dialog-buttonpane .ui-button{
margin: 0 0 0 16px;
padding: 0 10px 1px;
background: #f7f7f7;
border: 1px solid #cccccc;
border-radius: 3px;
position: static;
line-height: 2;
vertical-align: top;
}
.ui-dialog.pll-confirmation-modal .ui-button:hover,
.ui-dialog.pll-confirmation-modal .ui-button:focus {
background: #fafafa;
border-color: #999;
color: #23282d;
}
.pll-confirmation-modal + .ui-widget-overlay {
background: #000;
opacity: 0.7;
z-index: 100101;
}

View file

@ -0,0 +1 @@
.pll-confirmation-modal.ui-widget,.pll-confirmation-modal .ui-widget,.pll-confirmation-modal.ui-widget .ui-widget{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif;font-size:13px}.pll-confirmation-modal.ui-dialog{background:#fff;border:0;border-radius:0;color:#444;padding:0;z-index:100102}.ui-dialog.pll-confirmation-modal .ui-dialog-titlebar{background:#fcfcfc;border:0;border-bottom:1px solid #dfdfdf;border-radius:0;color:#444;font-size:18px;font-weight:600;height:36px;line-height:2;padding:0 36px 0 16px;position:static}.ui-dialog.pll-confirmation-modal .ui-dialog-title{float:none;margin:0;width:auto}.pll-confirmation-modal .ui-widget-header .ui-icon{background:none;position:static}.pll-confirmation-modal .ui-button.ui-dialog-titlebar-close{background:none;border:0;height:36px;margin:0;padding:0;right:0;top:0;width:36px}.ui-dialog.pll-confirmation-modal .ui-dialog-content{border:0;box-sizing:border-box;color:#444;padding:16px;position:static}.ui-dialog.pll-confirmation-modal .ui-dialog-buttonpane{background:#fcfcfc;border:0;border-top:1px solid #dfdfdf;margin:0;padding:16px}.ui-dialog.pll-confirmation-modal .ui-dialog-buttonpane .ui-button{background:#f7f7f7;border:1px solid #ccc;border-radius:3px;line-height:2;margin:0 0 0 16px;padding:0 10px 1px;position:static;vertical-align:top}.ui-dialog.pll-confirmation-modal .ui-button:focus,.ui-dialog.pll-confirmation-modal .ui-button:hover{background:#fafafa;border-color:#999;color:#23282d}.pll-confirmation-modal+.ui-widget-overlay{background:#000;opacity:.7;z-index:100101}

View file

@ -0,0 +1,239 @@
/* Greatly modified version of the jquery-ui.css */
.ui-widget-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.ui-menu {
list-style: none;
padding: 0;
margin: 0;
display: block;
outline: none;
}
.ui-menu .ui-menu {
position: absolute;
}
.ui-menu .ui-menu-item {
position: relative;
margin: 0;
padding: 3px 1em 3px .4em;
cursor: pointer;
min-height: 0; /* support: IE7 */
/* support: IE10, see #8844 */
list-style-image: url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7");
}
/* for jQuery UI 1.12 which introduces a wrapper */
.ui-menu .ui-menu-item:not([role]) {
padding: 0;
}
.ui-menu-item-wrapper {
padding: 3px 1em 3px 2em;
}
.rtl .ui-menu .ui-menu-item {
text-align: right;
}
/* icon support */
.ui-menu-icons {
position: relative;
}
.ui-menu-icons .ui-menu-item[role] {
padding-left: 2em;
}
.rtl .ui-menu-item-wrapper, /* for jQuery UI 1.12 which introduces a wrapper */
.rtl .ui-menu-icons .ui-menu-item[role] {
padding-left: 1em;
padding-right: 2em;
}
/* left-aligned */
.ui-selectmenu-text .ui-icon,
.ui-menu .ui-icon {
position: absolute;
top: 0;
bottom: 0;
left: .3em;
margin: auto 0;
}
.rtl .ui-selectmenu-text .ui-icon,
.rtl .ui-menu .ui-icon {
right: .3em;
left: auto;
}
/* right-aligned */
.ui-menu .ui-menu-icon {
left: auto;
right: 0;
}
.ui-selectmenu-menu {
padding: 0;
margin: 0;
position: absolute;
top: 0;
left: 0;
display: none;
}
.ui-selectmenu-menu .ui-menu {
overflow: auto;
/* Support: IE7 */
overflow-x: hidden;
padding-bottom: 1px;
}
.ui-selectmenu-menu .ui-menu .ui-selectmenu-optgroup {
font-size: 1em;
font-weight: bold;
line-height: 23px;
padding: 2px 0.4em;
margin: 0.5em 0 0 0;
height: auto;
border: 0;
}
.ui-selectmenu-open {
display: block;
}
.ui-selectmenu-button, /* jQuery UI 1.11.4 - WP < 5.6 */
.ui-selectmenu-button.ui-button {
display: inline-block;
overflow: hidden;
position: relative;
text-decoration: none;
box-sizing: border-box; /* To keep width calculation in percent since WP 5.6 */
text-align: left;
white-space: nowrap;
vertical-align: top;
padding: 0;
line-height: normal; /* Override WC Bookings styles with WP < 5.6 */
height: 28px; /* Override WC Bookings styles with WP < 5.6 */
}
.ui-selectmenu-button span.ui-icon {
right: 0.5em;
left: auto;
position: absolute;
top: 26%;
width: 16px;
height: 16px;
text-indent: 0; /* due to text-indent for jquery ui-dialog in wizard */
background: none;
}
.rtl .ui-selectmenu-button span.ui-icon {
left: 0.5em;
right: auto;
}
.ui-selectmenu-button.ui-widget span.ui-selectmenu-text, /* Override WC Bookings styles with WP < 5.6 */
.ui-selectmenu-button span.ui-selectmenu-text {
text-align: left;
padding: 0.1em 2.1em 0.2em 2em;
display: block;
line-height: 23px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
margin: 0;
}
.rtl .ui-selectmenu-button span.ui-selectmenu-text {
text-align: right;
padding: 0.2em 2em 0.2em 2.1em;
}
.ui-widget-content,
.ui-state-default,
.ui-selectmenu-button.ui-state-default, /* Override WC Bookings styles with WP < 5.6 */
.ui-button.ui-selectmenu-button-closed, /* To be compatible jQuery UI 1.12.1 since WordPress 5.6 */
.ui-button.ui-selectmenu-button-open, /* To be compatible jQuery UI 1.12.1 since WordPress 5.6 */
.ui-widget-content .ui-state-default,
.ui-widget-header .ui-state-default {
background: #fff;
border: 1px solid #ddd;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.07) inset;
color: #32373c;
}
/* Override to have same styles as WP form styles since WordPress 5.4 */
.toplevel_page_mlang .ui-selectmenu-button.ui-state-default,
.toplevel_page_mlang .ui-selectmenu-button.ui-selectmenu-button-closed, /* To be compatible jQuery UI 1.12.1 since WordPress 5.6 */
.toplevel_page_mlang .ui-selectmenu-button.ui-selectmenu-button-open{ /* To be compatible jQuery UI 1.12.1 since WordPress 5.6 */
box-shadow: 0 0 0 transparent;
border-radius: 4px;
border: 1px solid #7e8993;
}
/* From this line and below: override WooCommerce bookings plugin styles which overrides default WordPress styles */
.pll-selectmenu-menu .ui-widget,
.pll-selectmenu-button.ui-widget {
font-size: 13px;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}
.toplevel_page_mlang .ui-button.ui-selectmenu-button:focus{
color: #016087; /* Same color as WordPress focused select HTML tag */
border-color: #007cba;
box-shadow: 0 0 0 1px #007cba;
outline: 2px solid transparent;
background: #fff; /* Override bookings plugin styles which overrides default WordPress styles */
}
.toplevel_page_mlang .ui-menu-item,
.toplevel_page_mlang .ui-widget-content .ui-state-hover,
.toplevel_page_mlang .ui-widget-content .ui-state-focus,
.toplevel_page_mlang .ui-widget-content .ui-state-active {
color: #016087; /* Same color as option in a WordPress focused select HTML tag */
margin: 0;
}
.ui-selectmenu-open .ui-widget-content .ui-state-hover, /* Override WC Bookings styles with WP < 5.6 */
.ui-selectmenu-open .ui-widget-content .ui-state-focus, /* Override WC Bookings styles with WP < 5.6 */
.ui-selectmenu-open .ui-widget-content .ui-state-active, /* Override WC Bookings styles with WP < 5.6 */
.pll-selectmenu-menu .ui-widget-content .ui-state-hover,
.pll-selectmenu-menu .ui-widget-content .ui-state-focus,
.pll-selectmenu-menu .ui-widget-content .ui-state-active { /* To be compatible jQuery UI 1.12.1 since WordPress 5.6 */
background: #d5d5d5;
border: 0;
}
.ui-selectmenu-button.ui-state-focus {
border: 1px solid #5b9dd9;
box-shadow: 0 0 2px rgba(30, 140, 190, 0.8);
}
.ui-icon-triangle-1-s:before {
content: "";
background: #fff url(data:image/svg+xml;charset=US-ASCII,%3Csvg%20width%3D%2220%22%20height%3D%2220%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M5%206l5%205%205-5%202%201-7%207-7-7%202-1z%22%20fill%3D%22%23555%22%2F%3E%3C%2Fsvg%3E) no-repeat right 0px top 55%;
background-size: 16px 16px;
box-sizing: border-box;
position: absolute;
width: 16px;
height: 16px;
}
.pll-selectmenu-button.ui-button:hover,
.pll-wizard .ui-button:hover,
.pll-wizard .ui-button:focus {
background: #fff; /* To override jQuery ui-dialog styles provided by WordPress */
}
.ui-widget-content {
max-height: 231px;
box-shadow: 0 2px 6px rgba(100, 100, 100, 0.3);
}

View file

@ -0,0 +1 @@
.ui-widget-overlay{height:100%;left:0;position:fixed;top:0;width:100%}.ui-menu{display:block;list-style:none;margin:0;outline:none;padding:0}.ui-menu .ui-menu{position:absolute}.ui-menu .ui-menu-item{cursor:pointer;list-style-image:url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7");margin:0;min-height:0;padding:3px 1em 3px .4em;position:relative}.ui-menu .ui-menu-item:not([role]){padding:0}.ui-menu-item-wrapper{padding:3px 1em 3px 2em}.rtl .ui-menu .ui-menu-item{text-align:right}.ui-menu-icons{position:relative}.ui-menu-icons .ui-menu-item[role]{padding-left:2em}.rtl .ui-menu-icons .ui-menu-item[role],.rtl .ui-menu-item-wrapper{padding-left:1em;padding-right:2em}.ui-menu .ui-icon,.ui-selectmenu-text .ui-icon{bottom:0;left:.3em;margin:auto 0;position:absolute;top:0}.rtl .ui-menu .ui-icon,.rtl .ui-selectmenu-text .ui-icon{left:auto;right:.3em}.ui-menu .ui-menu-icon{left:auto;right:0}.ui-selectmenu-menu{display:none;left:0;margin:0;padding:0;position:absolute;top:0}.ui-selectmenu-menu .ui-menu{overflow:auto;overflow-x:hidden;padding-bottom:1px}.ui-selectmenu-menu .ui-menu .ui-selectmenu-optgroup{border:0;font-size:1em;font-weight:700;height:auto;line-height:23px;margin:.5em 0 0;padding:2px .4em}.ui-selectmenu-open{display:block}.ui-selectmenu-button,.ui-selectmenu-button.ui-button{box-sizing:border-box;display:inline-block;height:28px;line-height:normal;overflow:hidden;padding:0;position:relative;text-align:left;text-decoration:none;vertical-align:top;white-space:nowrap}.ui-selectmenu-button span.ui-icon{background:none;height:16px;left:auto;position:absolute;right:.5em;text-indent:0;top:26%;width:16px}.rtl .ui-selectmenu-button span.ui-icon{left:.5em;right:auto}.ui-selectmenu-button.ui-widget span.ui-selectmenu-text,.ui-selectmenu-button span.ui-selectmenu-text{display:block;line-height:23px;margin:0;overflow:hidden;padding:.1em 2.1em .2em 2em;text-align:left;text-overflow:ellipsis;white-space:nowrap}.rtl .ui-selectmenu-button span.ui-selectmenu-text{padding:.2em 2em .2em 2.1em;text-align:right}.ui-button.ui-selectmenu-button-closed,.ui-button.ui-selectmenu-button-open,.ui-selectmenu-button.ui-state-default,.ui-state-default,.ui-widget-content,.ui-widget-content .ui-state-default,.ui-widget-header .ui-state-default{background:#fff;border:1px solid #ddd;box-shadow:inset 0 1px 2px rgba(0,0,0,.07);color:#32373c}.toplevel_page_mlang .ui-selectmenu-button.ui-selectmenu-button-closed,.toplevel_page_mlang .ui-selectmenu-button.ui-selectmenu-button-open,.toplevel_page_mlang .ui-selectmenu-button.ui-state-default{border:1px solid #7e8993;border-radius:4px;box-shadow:0 0 0 transparent}.pll-selectmenu-button.ui-widget,.pll-selectmenu-menu .ui-widget{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif;font-size:13px}.toplevel_page_mlang .ui-button.ui-selectmenu-button:focus{background:#fff;border-color:#007cba;box-shadow:0 0 0 1px #007cba;color:#016087;outline:2px solid transparent}.toplevel_page_mlang .ui-menu-item,.toplevel_page_mlang .ui-widget-content .ui-state-active,.toplevel_page_mlang .ui-widget-content .ui-state-focus,.toplevel_page_mlang .ui-widget-content .ui-state-hover{color:#016087;margin:0}.pll-selectmenu-menu .ui-widget-content .ui-state-active,.pll-selectmenu-menu .ui-widget-content .ui-state-focus,.pll-selectmenu-menu .ui-widget-content .ui-state-hover,.ui-selectmenu-open .ui-widget-content .ui-state-active,.ui-selectmenu-open .ui-widget-content .ui-state-focus,.ui-selectmenu-open .ui-widget-content .ui-state-hover{background:#d5d5d5;border:0}.ui-selectmenu-button.ui-state-focus{border:1px solid #5b9dd9;box-shadow:0 0 2px rgba(30,140,190,.8)}.ui-icon-triangle-1-s:before{background:#fff url(data:image/svg+xml;charset=US-ASCII,%3Csvg%20width%3D%2220%22%20height%3D%2220%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M5%206l5%205%205-5%202%201-7%207-7-7%202-1z%22%20fill%3D%22%23555%22%2F%3E%3C%2Fsvg%3E) no-repeat right 0 top 55%;background-size:16px 16px;box-sizing:border-box;content:"";height:16px;position:absolute;width:16px}.pll-selectmenu-button.ui-button:hover,.pll-wizard .ui-button:focus,.pll-wizard .ui-button:hover{background:#fff}.ui-widget-content{box-shadow:0 2px 6px hsla(0,0%,39%,.3);max-height:231px}

View file

@ -0,0 +1,951 @@
@charset "UTF-8";
body {
margin: 65px auto 24px;
box-shadow: none;
background: #f1f1f1;
padding: 0;
border: 0; /* fix-pro #856 override WP install.css */
}
#pll-logo {
border: 0;
margin: 0 0 24px;
padding: 0;
text-align: center;
font-family: sans-serif;
font-size: 64px;
text-transform: uppercase;
color: #000;
line-height: normal;
}
#pll-logo a {
display: flex;
justify-content: center;
color: #000;
text-decoration: none;
}
#pll-logo img {
max-width: 100%;
margin-right: 16px;
}
.rtl #pll-logo img {
margin-right: 0;
margin-left: 16px;
}
.pll-wizard-footer {
text-align: center
}
.pll-wizard .select2-container {
text-align: left;
width: auto
}
.pll-wizard .hidden {
display: none
}
.pll-wizard-content {
box-shadow: 0 1px 3px rgba(0, 0, 0, .13);
padding: 2em;
margin: 0 0 20px;
background: #fff;
overflow: hidden;
zoom: 1;
text-align: left;
}
.rtl .pll-wizard-content{
text-align: right;
}
.pll-wizard-content h1,
.pll-wizard-content h2,
.pll-wizard-content h3,
.pll-wizard-content table {
margin: 0 0 20px;
border: 0;
padding: 0;
color: #666;
clear: none;
font-weight: 500
}
.pll-wizard-content p {
margin: 20px 0;
font-size: 1em;
line-height: 1.75em;
color: #666
}
.pll-wizard-content table {
font-size: 1em;
line-height: 1.75em;
color: #666;
width: 100%;
margin-top: 20px;
}
.pll-wizard-content table td span{
display: inline-block;
}
.pll-wizard-content table caption {
caption-side: bottom;
font-style: italic;
text-align: right;
}
.rtl .pll-wizard-content table caption {
text-align: left;
}
.pll-wizard-content table caption .icon-default-lang{
font-style: normal;
}
.pll-wizard-content a {
color: #a03f3f;
}
.pll-wizard-content a:focus,
.pll-wizard-content a:hover,
.pll-wizard-footer-links:hover {
color: #dd5454
}
.pll-wizard-content .pll-wizard-next-steps {
overflow: hidden;
margin: 0 0 24px;
padding-bottom: 2px
}
.pll-wizard-content .pll-wizard-next-steps h2 {
margin-bottom: 12px
}
.pll-wizard-content .pll-wizard-next-steps .pll-wizard-next-steps-first {
float: left;
width: 50%;
box-sizing: border-box
}
.pll-wizard-content .pll-wizard-next-steps .pll-wizard-next-steps-last {
float: right;
width: 50%;
box-sizing: border-box
}
.pll-wizard-content .pll-wizard-next-steps ul {
padding: 0 2em 0 0;
list-style: none outside;
margin: 0
}
.pll-wizard-content .pll-wizard-next-steps ul li a {
display: block;
padding: 0 0 .75em
}
.pll-wizard-content .pll-wizard-next-steps ul li a::before {
color: #82878c;
font: normal 20px/1 dashicons;
speak: none;
display: inline-block;
padding: 0 10px 0 0;
top: 1px;
position: relative;
text-decoration: none!important;
vertical-align: top
}
.pll-wizard-steps {
padding: 0 0 24px;
margin: 0;
list-style: none outside;
overflow: hidden;
color: #ccc;
width: 100%;
display: -webkit-inline-box;
display: -webkit-inline-flex;
display: inline-flex
}
.pll-wizard-steps li {
width: 100%;
float: left;
padding: 0 0 .8em;
margin: 0;
text-align: center;
position: relative;
border-bottom: 4px solid #ccc;
line-height: 1.4em
}
.pll-wizard-steps li a {
color: #a03f3f;
text-decoration: none;
padding: 1.5em;
margin: -1.5em;
position: relative;
z-index: 1
}
.pll-wizard-steps li a:focus,
.pll-wizard-steps li a:hover {
color: #dd5454;
text-decoration: underline
}
.pll-wizard-steps li::before {
content: "";
border: 4px solid #ccc;
border-radius: 100%;
width: 4px;
height: 4px;
position: absolute;
bottom: 0;
left: 50%;
margin-left: -6px;
margin-bottom: -8px;
background: #fff
}
.pll-wizard-steps li.active {
border-color: #a03f3f;
color: #a03f3f;
font-weight: 700
}
.pll-wizard-steps li.active::before {
border-color: #a03f3f
}
.pll-wizard-steps li.done {
border-color: #a03f3f;
color: #a03f3f
}
.pll-wizard-steps li.done::before {
border-color: #a03f3f;
background: #a03f3f
}
.pll-wizard .pll-wizard-actions {
overflow: hidden;
margin: 20px 0 0;
position: relative
}
.pll-wizard .pll-wizard-actions .button {
font-size: 16px;
font-weight: 300;
padding: 1em 2em;
line-height: 1em;
margin-right: .5em;
margin-bottom: 2px;
margin-top: 10px;
height: auto;
border-radius: 4px;
box-shadow: none;
min-width: auto;
border-color: #a03f3f;
color: #a03f3f;
}
.pll-wizard .pll-wizard-content .button {
border-color: #a03f3f;
color: #a03f3f;
}
.pll-wizard .pll-wizard-content .button-primary,
.pll-wizard .pll-wizard-actions .button-primary {
background-color: #a03f3f;
border-color: #a03f3f;
color: #fff;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #a03f3f;
text-shadow: 0 -1px 1px #a03f3f, 1px 0 1px #a03f3f, 0 1px 1px #a03f3f, -1px 0 1px #a03f3f;
margin: 0;
opacity: 1
}
.pll-wizard .pll-wizard-content .button-small .dashicons {
font-size: 15px;
height: auto;
vertical-align: middle;
}
.pll-wizard .button-primary:active,
.pll-wizard .button-primary:focus,
.pll-wizard input[type="checkbox"]:focus + label.button-primary,
.pll-wizard .button-primary:hover {
background: #dd5454;
border-color: #dd5454;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #dd5454
}
.pll-wizard .pll-wizard-actions .button-primary[disabled],
.pll-wizard .pll-wizard-actions .button-primary:disabled,
.pll-wizard .pll-wizard-actions .button-primary.disabled {
cursor: wait;
background-color: #bb5454 !important;
border-color: #bb5454 !important;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #bb5454 !important;
text-shadow: 0 -1px 1px #bb5454, 1px 0 1px #bb5454, 0 1px 1px #bb5454, -1px 0 1px #bb5454 !important;
color: #ffa3a3 !important;
}
.pll-wizard-content p:last-child {
margin-bottom: 0
}
.pll-wizard-footer-links {
font-size: .85em;
color: #7b7b7b;
margin: 1.18em auto;
display: inline-block;
text-align: center
}
.pll-wizard-services {
border: 1px solid #eee;
padding: 0;
margin: 0 0 1em;
list-style: none outside;
border-radius: 4px;
overflow: hidden
}
.pll-wizard-services p {
margin: 0 0 1em 0;
padding: 0;
font-size: 1em;
line-height: 1.5em
}
.pll-wizard-service-item {
display: -webkit-box;
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: nowrap;
flex-wrap: nowrap;
-webkit-box-pack: justify;
-webkit-justify-content: space-between;
justify-content: space-between;
padding: 0;
border-bottom: 1px solid #eee;
color: #666;
-webkit-box-align: center;
-webkit-align-items: center;
align-items: center
}
.media-step .pll-wizard-service-item{
border: 0;
}
.media-step .pll-wizard-service-item:last-child{
display: block;
}
.media-step .pll-wizard-service-item .pll-wizard-service-enable{
padding-bottom: 0;
}
.pll-wizard-service-item:last-child {
border-bottom: 0
}
.pll-wizard-service-item .pll-wizard-service-name {
-webkit-flex-basis: 0;
flex-basis: 0;
min-width: 160px;
text-align: center;
font-weight: 700;
padding: 2em 0;
-webkit-align-self: stretch;
align-self: stretch;
display: -webkit-box;
display: -webkit-flex;
display: flex;
-webkit-box-align: baseline;
-webkit-align-items: baseline;
align-items: baseline
}
.pll-wizard-service-item .pll-wizard-service-name img {
max-width: 75px
}
.pll-wizard-service-item .pll-wizard-service-description {
-webkit-box-flex: 1;
-webkit-flex-grow: 1;
flex-grow: 1;
padding: 20px
}
.pll-wizard-service-item .pll-wizard-service-example {
padding: 0 20px 20px
}
.pll-wizard-service-item .pll-wizard-service-example p{
text-align: right;
}
.rtl .pll-wizard-service-item .pll-wizard-service-example p{
text-align: left;
}
.pll-wizard-service-item .pll-wizard-service-description p {
margin-bottom: 1em
}
.pll-wizard-service-item .pll-wizard-service-description p:last-child {
margin-bottom: 0
}
.pll-wizard-service-item .pll-wizard-service-description .pll-wizard-service-settings-description {
display: block;
font-style: italic;
color: #999
}
.pll-wizard-service-item .pll-wizard-service-enable {
-webkit-flex-basis: 0;
flex-basis: 0;
min-width: 75px;
text-align: center;
cursor: pointer;
padding: 2em 0;
position: relative;
max-height: 1.5em;
-webkit-align-self: flex-start;
align-self: flex-start;
-webkit-box-ordinal-group: 4;
-webkit-order: 3;
order: 3
}
.pll-wizard-service-item .pll-wizard-service-toggle {
position: relative
}
.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox] {
position:absolute;
opacity: 0;
}
.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox] + label {
position: relative;
display: inline-block;
width: 44px;
height: 20px;
border-radius: 10em;
cursor: pointer;
text-indent: -9999px;
}
.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox]:focus + label {
border:1px dashed #777;
}
.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox] + label::before,
.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox] + label::after {
content: '';
position: absolute;
}
.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox] + label::before {
left: 0;
top: 0;
width: 44px;
height: 20px;
background: #ddd;
border-radius: 10em;
transition: background-color .2s;
}
.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox] + label::after {
width: 16px;
height: 16px;
transition: all .2s;
border-radius: 50%;
background: #fff;
margin: 2px;
top: 0;
left: 0;
}
.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox]:checked + label::before {
background:#a03f3f;
}
.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox]:checked + label::after {
right: 0;
left:auto;
}
.pll-wizard-service-item .pll-wizard-service-settings {
display: none;
margin-top: .75em;
margin-bottom: 0;
cursor: default
}
.pll-wizard-service-item .pll-wizard-service-settings.hide {
display: none
}
.pll-wizard-service-item.checked .pll-wizard-service-settings {
display: inline-block
}
.pll-wizard-service-item.checked .pll-wizard-service-settings.hide {
display: none
}
.pll-wizard-service-item.closed {
border-bottom: 0
}
.step {
text-align: center
}
.pll-wizard .button .dashicons{
vertical-align: middle;
}
.rtl .dashicons-arrow-right-alt2:before {
content: "\f341";
}
.pll-wizard .pll-wizard-actions .button:active,
.pll-wizard .pll-wizard-actions .button:focus,
.pll-wizard .pll-wizard-actions .button:hover {
box-shadow: none
}
.pll-wizard-next-steps {
border: 1px solid #eee;
border-radius: 4px;
list-style: none;
padding: 0
}
.pll-wizard-next-steps li {
padding: 0
}
.pll-wizard-next-steps .pll-wizard-next-step-item {
display: -webkit-box;
display: -webkit-flex;
display: flex;
border-top: 1px solid #eee
}
.pll-wizard-next-steps .pll-wizard-next-step-item.no-border,
.pll-wizard-next-steps .pll-wizard-next-step-item:first-child {
border-top: 0
}
.pll-wizard-next-steps .pll-wizard-next-step-description {
-webkit-box-flex: 1;
-webkit-flex-grow: 1;
flex-grow: 1;
margin: 1.5em
}
.pll-wizard-next-steps .pll-wizard-next-step-action {
-webkit-box-flex: 0;
-webkit-flex-grow: 0;
flex-grow: 0;
display: -webkit-box;
display: -webkit-flex;
display: flex;
-webkit-box-align: center;
-webkit-align-items: center;
align-items: center
}
.pll-wizard-next-steps .pll-wizard-next-step-action .button {
margin: 1em 1.5em
}
.pll-wizard-next-steps .pll-wizard-next-step-item.no-border .pll-wizard-next-step-description,
.pll-wizard-next-steps .pll-wizard-next-step-item.no-border .pll-wizard-actions,
.pll-wizard-next-steps .pll-wizard-next-step-item.no-border .pll-wizard-next-step-action .button{
margin-top: 0;
}
.pll-wizard-next-steps p.next-step-heading {
margin: 0;
font-size: .95em;
font-weight: 400;
font-variant: all-petite-caps
}
.pll-wizard-next-steps p.next-step-extra-info {
margin: 0
}
.pll-wizard-next-steps h3.next-step-description {
margin: 0;
font-size: 16px;
font-weight: 600;
}
.pll-wizard-next-steps .pll-wizard-additional-steps {
border-top: 1px solid #eee;
}
.pll-wizard-next-steps .pll-wizard-additional-steps .pll-wizard-next-step-description {
margin-bottom: 0
}
.pll-wizard-next-steps .pll-wizard-additional-steps .pll-wizard-actions {
margin: 0 0 1.5em 0;
}
.pll-wizard-next-steps .pll-wizard-additional-steps .pll-wizard-actions .button {
font-size: 15px;
margin: 1em 0 1em 1.5em;
}
.rtl .pll-wizard-next-steps .pll-wizard-additional-steps .pll-wizard-actions .button {
margin: 1em 1.5em 1em 0;
}
.pll-wizard-next-steps .pll-wizard-additional-steps .pll-wizard-actions .button::last-child {
margin-right: 1.5em;
}
.pll-wizard-content img{
max-width: 100%;
margin-right: 0.5em;
}
.rtl .pll-wizard-content img{
margin-left: 0.5em;
}
.pll-wizard-content .form-field label{
margin-bottom: 5px;
display: block;
}
.pll-wizard-content .form-field select{
padding: 3px;
}
.pll-wizard-content .languages-step select,
.pll-wizard-content .untranslated-contents-step select{
width: 100%;
}
.languages-step .form-field .button{
margin-left: 15px;
}
.languages-step .form-field .button > span{
margin-right: 0.3em;
}
.rtl .languages-step .form-field .button{
margin-left: 0;
margin-right: 15px;
}
.rtl .languages-step .form-field .button > span{
margin-left: 0.3em;
margin-right: 0;
}
.pll-wizard-content .languages-step .select-language-field{
display: flex;
}
.pll-wizard-content #languages{
display: none;
}
.pll-wizard-content #languages tr th:first-child{
width: 80%;
}
.pll-wizard-content #languages .dashicons{
color: #a03f3f;
}
.pll-wizard-content #languages img{
margin-right: 5px;
}
.pll-wizard-content .error{
color: #a03f3f;
font-weight: bold;
}
.pll-wizard-content #messages .error{
background: #fccfcf;
padding: 0.5rem;
border: 1px solid #a03f3f;
margin-bottom: 0.5rem;
}
.pll-wizard-content #slide-toggle{
position:absolute;
opacity: 0;
}
.pll-wizard-content #slide-toggle + label{
position:relative;
}
.pll-wizard-content #slide-toggle + label + span{
display: block;
}
.pll-wizard-content #slide-toggle + label .dashicons{
margin-right: 0.3em;
}
.rtl .pll-wizard-content #slide-toggle + label .dashicons{
margin-left: 0.3em;
margin-right: 0;
}
.pll-wizard-content #slide-toggle ~ #screenshot > img {
max-height: 500px;
margin-top: 10px;
-webkit-transition: all .5s cubic-bezier(0, 1, 0.5, 1);
transition: all .5s cubic-bezier(0, 1, 0.5, 1);
}
.pll-wizard-content #slide-toggle:checked ~ #screenshot > img {
max-height: 0;
}
.hide {
display: none;
}
input[type="text"].field-in-error,
input[type="password"].field-in-error,
input[type="checkbox"].field-in-error,
input[type="color"].field-in-error,
input[type="date"].field-in-error,
input[type="datetime"].field-in-error,
input[type="datetime-local"].field-in-error,
input[type="email"].field-in-error,
input[type="month"].field-in-error,
input[type="number"].field-in-error,
input[type="search"].field-in-error,
input[type="radio"].field-in-error,
input[type="tel"].field-in-error,
input[type="text"].field-in-error,
input[type="time"].field-in-error,
input[type="url"].field-in-error,
input[type="week"].field-in-error,
select.field-in-error,
textarea.field-in-error,
span.field-in-error,
.field-in-error{
border-color: #a03f3f;
}
input[type="text"].field-in-error:focus,
input[type="password"].field-in-error:focus,
input[type="checkbox"].field-in-error:focus,
input[type="color"].field-in-error:focus,
input[type="date"].field-in-error:focus,
input[type="datetime"].field-in-error:focus,
input[type="datetime-local"].field-in-error:focus,
input[type="email"].field-in-error:focus,
input[type="month"].field-in-error:focus,
input[type="number"].field-in-error:focus,
input[type="search"].field-in-error:focus,
input[type="radio"].field-in-error:focus,
input[type="tel"].field-in-error:focus,
input[type="text"].field-in-error:focus,
input[type="time"].field-in-error:focus,
input[type="url"].field-in-error:focus,
input[type="week"].field-in-error:focus,
select.field-in-error:focus,
textarea.field-in-error:focus,
span.field-in-error:focus,
.field-in-error:focus{
border: 1px solid #a03f3f;
box-shadow: 0 0 2px rgba(160, 63, 63, 0.8);
outline-color: #a03f3f;
outline-style: auto;
outline-width: thin;
}
/* override install styles by returning back to forms styles */
.form-table input.regular-text{
width: 25em;
}
.form-table input.field-in-error{
border-color: #a03f3f;
}
#pll-licenses-table td{
padding: 10px 9px;
}
#pll-licenses-table .license-valid td p{
min-width: 35em;
}
#pll-licenses-table .pll-deactivate-license{
margin: 0 0 0 20px;
}
.rtl #pll-licenses-table .pll-deactivate-license{
margin: 0 10px 0 0;
}
.pll-wizard-content .documentation {
padding: 24px 24px 0;
margin: 0 0 24px;
overflow: hidden;
background: #f5f5f5
}
.pll-wizard-content .documentation p {
padding: 0;
margin: 0 0 12px;
}
.documentation-container {
display: -webkit-box;
display: -webkit-flex;
display: flex;
justify-content: flex-end;
}
.documentation-container .documentation-button-container {
-webkit-box-flex: 0;
-webkit-flex-grow: 0;
flex-grow: 0;
}
.wc-setup .wc-setup-actions .button.documentation-button {
height: 42px;
padding: 0 1em;
margin: 0;
}
#dialog{
display: none;
}
.pll-wizard .ui-dialog.ui-widget-content{
max-height: none;
}
.pll-wizard .ui-dialog-title::before{
content: "\f534";
font-family: dashicons;
display: inline-block;
line-height: 1;
font-weight: 400;
font-style: normal;
speak: none;
text-decoration: inherit;
text-transform: none;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
width: 20px;
height: 20px;
font-size: 20px;
vertical-align: middle;
text-align: center;
margin: 0 5px 5px 0;
transition: color 0.1s ease-in;
}
.rtl.pll-wizard .ui-dialog-title::before{
margin-right: 0;
margin-left: 5px;
}
.pll-wizard .ui-dialog ul{
list-style: disc;
padding-left: 20px;
}
.rtl.pll-wizard .ui-dialog ul{
padding-left: 0;
padding-right: 20px;
}
.pll-wizard li{
margin-bottom: 0;
}
#translations{
border-collapse: collapse;
}
#translations tbody:nth-child(odd){
background-color: #f9f9f9;
}
#translations.striped > tbody > :nth-child(odd) {
background-color: transparent; /* Override common WordPress style */
}
.pll-wizard-content mark{
background: transparent none;
}
.pll-wizard-content mark{
color: #7ad03a;
}
@media screen and (max-width: 782px) {
/* Override WordPress button css rules */
.languages-step .form-field .button{
font-size: 13px;
line-height: 26px;
height: 28px;
padding: 0 10px 1px;
vertical-align: top;
}
#pll-licenses-table .pll-deactivate-license{
margin: 10px 0 5px;
}
}
@media only screen and (max-width:620px) {
/* Override dialog width rule */
.ui-dialog{
width: 100% !important;
}
}
@media only screen and (max-width:500px) {
#pll-logo a,
.select-language-field{
flex-direction: column;
}
.select-language-field .action-buttons{
display: flex;
justify-content: flex-end;
}
.languages-step .form-field .button{
margin: 5px 0 0;
}
}
@media only screen and (max-width:400px) {
#pll-logo {
font-size: 56px;
}
.pll-wizard-steps {
display: none
}
.pll-wizard-service-item {
-webkit-flex-wrap: wrap;
flex-wrap: wrap
}
.pll-wizard-service-item .pll-wizard-service-enable {
-webkit-box-ordinal-group: 3;
-webkit-order: 2;
order: 2;
padding: 20px 0 0
}
.pll-wizard-service-item .pll-wizard-service-description {
-webkit-box-ordinal-group: 4;
-webkit-order: 3;
order: 3
}
.pll-wizard-service-item .pll-wizard-service-name {
padding: 20px 20px 0;
text-align: left;
-webkit-box-pack: justify!important;
-webkit-justify-content: space-between!important;
justify-content: space-between!important
}
.pll-wizard-service-item .pll-wizard-service-name img {
margin: 0
}
.pll-wizard-next-steps .pll-wizard-next-step-item {
-webkit-flex-wrap: wrap;
flex-wrap: wrap
}
.pll-wizard-next-steps .pll-wizard-next-step-item .pll-wizard-next-step-description {
margin-bottom: 0
}
.pll-wizard-next-steps .pll-wizard-next-step-item .pll-wizard-next-step-action p {
margin: 0
}
}
@media only screen and (max-width:360px) {
#pll-logo {
font-size: 48px;
}
}

File diff suppressed because one or more lines are too long

View file

@ -1,140 +0,0 @@
/* Greatly modified version of the jquery-ui.css */
.ui-widget-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.ui-menu {
list-style: none;
padding: 0;
margin: 0;
display: block;
outline: none;
}
.ui-menu .ui-menu {
position: absolute;
}
.ui-menu .ui-menu-item {
position: relative;
margin: 0;
padding: 3px 1em 3px .4em;
min-height: 0; /* support: IE7 */
/* support: IE10, see #8844 */
list-style-image: url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7");
}
/* icon support */
.ui-menu-icons {
position: relative;
}
.ui-menu-icons .ui-menu-item {
padding-left: 2em;
}
/* left-aligned */
.ui-selectmenu-text .ui-icon,
.ui-menu .ui-icon {
position: absolute;
top: 0;
bottom: 0;
left: .2em;
margin: auto 0;
}
/* right-aligned */
.ui-menu .ui-menu-icon {
left: auto;
right: 0;
}
.ui-selectmenu-menu {
padding: 0;
margin: 0;
position: absolute;
top: 0;
left: 0;
display: none;
}
.ui-selectmenu-menu .ui-menu {
overflow: auto;
/* Support: IE7 */
overflow-x: hidden;
padding-bottom: 1px;
}
.ui-selectmenu-menu .ui-menu .ui-selectmenu-optgroup {
font-size: 1em;
font-weight: bold;
line-height: 23px;
padding: 2px 0.4em;
margin: 0.5em 0 0 0;
height: auto;
border: 0;
}
.ui-selectmenu-open {
display: block;
}
.ui-selectmenu-button {
display: inline-block;
overflow: hidden;
position: relative;
text-decoration: none;
}
.ui-selectmenu-button span.ui-icon {
right: 0.5em;
left: auto;
margin-top: -10px;
position: absolute;
top: 50%;
}
.ui-selectmenu-button span.ui-selectmenu-text {
text-align: left;
padding: 0.4em 2.1em 0.4em 2em;
display: block;
line-height: 23px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.ui-widget-content,
.ui-state-default,
.ui-widget-content .ui-state-default,
.ui-widget-header .ui-state-default {
background: #fff;
border: 1px solid #ddd;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.07) inset;
color: #32373c;
}
.ui-widget-content .ui-state-hover,
.ui-widget-content .ui-state-focus {
background: #f5f5f5;
}
.ui-selectmenu-button.ui-state-focus {
border: 1px solid #5b9dd9;
box-shadow: 0 0 2px rgba(30, 140, 190, 0.8);
}
.ui-icon-triangle-1-s:before {
content: "\f140";
font: 20px/1 'dashicons';
}
.ui-widget-content {
max-height: 231px;
box-shadow: 0 2px 6px rgba(100, 100, 100, 0.3);
}

View file

@ -1 +0,0 @@
.ui-widget-overlay{position:fixed;top:0;left:0;width:100%;height:100%}.ui-menu{list-style:none;padding:0;margin:0;display:block;outline:0}.ui-menu .ui-menu{position:absolute}.ui-menu .ui-menu-item{position:relative;margin:0;padding:3px 1em 3px .4em;min-height:0;list-style-image:url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)}.ui-menu-icons{position:relative}.ui-menu-icons .ui-menu-item{padding-left:2em}.ui-menu .ui-icon,.ui-selectmenu-text .ui-icon{position:absolute;top:0;bottom:0;left:.2em;margin:auto 0}.ui-menu .ui-menu-icon{left:auto;right:0}.ui-selectmenu-menu{padding:0;margin:0;position:absolute;top:0;left:0;display:none}.ui-selectmenu-menu .ui-menu{overflow:auto;overflow-x:hidden;padding-bottom:1px}.ui-selectmenu-menu .ui-menu .ui-selectmenu-optgroup{font-size:1em;font-weight:700;line-height:23px;padding:2px .4em;margin:.5em 0 0;height:auto;border:0}.ui-selectmenu-open{display:block}.ui-selectmenu-button{display:inline-block;overflow:hidden;position:relative;text-decoration:none}.ui-selectmenu-button span.ui-icon{right:.5em;left:auto;margin-top:-10px;position:absolute;top:50%}.ui-selectmenu-button span.ui-selectmenu-text{text-align:left;padding:.4em 2.1em .4em 2em;display:block;line-height:23px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.ui-state-default,.ui-widget-content,.ui-widget-content .ui-state-default,.ui-widget-header .ui-state-default{background:#fff;border:1px solid #ddd;box-shadow:0 1px 2px rgba(0,0,0,.07) inset;color:#32373c}.ui-widget-content .ui-state-focus,.ui-widget-content .ui-state-hover{background:#f5f5f5}.ui-selectmenu-button.ui-state-focus{border:1px solid #5b9dd9;box-shadow:0 0 2px rgba(30,140,190,.8)}.ui-icon-triangle-1-s:before{content:"\f140";font:20px/1 dashicons}.ui-widget-content{max-height:231px;box-shadow:0 2px 6px rgba(100,100,100,.3)}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 643 B

After

Width:  |  Height:  |  Size: 378 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 408 B

After

Width:  |  Height:  |  Size: 228 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 604 B

After

Width:  |  Height:  |  Size: 365 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 591 B

After

Width:  |  Height:  |  Size: 379 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 643 B

After

Width:  |  Height:  |  Size: 392 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 600 B

After

Width:  |  Height:  |  Size: 365 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 497 B

After

Width:  |  Height:  |  Size: 254 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 488 B

After

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 428 B

After

Width:  |  Height:  |  Size: 255 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 506 B

After

Width:  |  Height:  |  Size: 260 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 B

After

Width:  |  Height:  |  Size: 184 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 647 B

After

Width:  |  Height:  |  Size: 428 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 403 B

After

Width:  |  Height:  |  Size: 212 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 673 B

After

Width:  |  Height:  |  Size: 402 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 524 B

After

Width:  |  Height:  |  Size: 264 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 663 B

After

Width:  |  Height:  |  Size: 384 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 589 B

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 593 B

After

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 565 B

After

Width:  |  Height:  |  Size: 215 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 585 B

After

Width:  |  Height:  |  Size: 316 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 504 B

After

Width:  |  Height:  |  Size: 251 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 449 B

After

Width:  |  Height:  |  Size: 272 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 497 B

After

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 462 B

After

Width:  |  Height:  |  Size: 255 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 457 B

After

Width:  |  Height:  |  Size: 230 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 675 B

After

Width:  |  Height:  |  Size: 400 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 486 B

After

Width:  |  Height:  |  Size: 248 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 611 B

After

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 639 B

After

Width:  |  Height:  |  Size: 360 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 500 B

After

Width:  |  Height:  |  Size: 297 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 593 B

After

Width:  |  Height:  |  Size: 353 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 526 B

After

Width:  |  Height:  |  Size: 335 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 631 B

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 443 B

After

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 514 B

After

Width:  |  Height:  |  Size: 280 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 600 B

After

Width:  |  Height:  |  Size: 399 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 628 B

After

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 398 B

After

Width:  |  Height:  |  Size: 233 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 625 B

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 528 B

After

Width:  |  Height:  |  Size: 301 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 614 B

After

Width:  |  Height:  |  Size: 355 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 521 B

After

Width:  |  Height:  |  Size: 259 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 367 B

After

Width:  |  Height:  |  Size: 167 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 453 B

After

Width:  |  Height:  |  Size: 226 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 586 B

After

Width:  |  Height:  |  Size: 347 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 450 B

After

Width:  |  Height:  |  Size: 240 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 525 B

After

Width:  |  Height:  |  Size: 310 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 472 B

After

Width:  |  Height:  |  Size: 252 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 483 B

After

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 477 B

After

Width:  |  Height:  |  Size: 270 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 563 B

After

Width:  |  Height:  |  Size: 317 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 529 B

After

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 608 B

After

Width:  |  Height:  |  Size: 385 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 428 B

After

Width:  |  Height:  |  Size: 232 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 476 B

After

Width:  |  Height:  |  Size: 260 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 545 B

After

Width:  |  Height:  |  Size: 357 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 572 B

After

Width:  |  Height:  |  Size: 315 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 495 B

After

Width:  |  Height:  |  Size: 219 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 620 B

After

Width:  |  Height:  |  Size: 386 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 508 B

After

Width:  |  Height:  |  Size: 264 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 582 B

After

Width:  |  Height:  |  Size: 323 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 500 B

After

Width:  |  Height:  |  Size: 306 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 429 B

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 465 B

After

Width:  |  Height:  |  Size: 266 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 508 B

After

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 496 B

After

Width:  |  Height:  |  Size: 248 B

Some files were not shown because too many files have changed in this diff Show more