| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Polylang |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* Setup miscellaneous admin filters as well as filters common to admin and frontend |
| 8 |
* |
| 9 |
* @since 1.2 |
| 10 |
*/ |
| 11 |
class PLL_Admin_Filters extends PLL_Filters { |
| 12 |
|
| 13 |
/** |
| 14 |
* Constructor: setups filters and actions |
| 15 |
* |
| 16 |
* @since 1.2 |
| 17 |
* |
| 18 |
* @param object $polylang |
| 19 |
*/ |
| 20 |
public function __construct( &$polylang ) { |
| 21 |
parent::__construct( $polylang ); |
| 22 |
|
| 23 |
// Language management for users |
| 24 |
add_action( 'personal_options_update', array( $this, 'personal_options_update' ) ); |
| 25 |
add_action( 'edit_user_profile_update', array( $this, 'personal_options_update' ) ); |
| 26 |
add_action( 'personal_options', array( $this, 'personal_options' ) ); |
| 27 |
|
| 28 |
// Upgrades plugins and themes translations files |
| 29 |
add_filter( 'themes_update_check_locales', array( $this, 'update_check_locales' ) ); |
| 30 |
add_filter( 'plugins_update_check_locales', array( $this, 'update_check_locales' ) ); |
| 31 |
|
| 32 |
add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
| 33 |
|
| 34 |
// Add post state for translations of the privacy policy page |
| 35 |
add_filter( 'display_post_states', array( $this, 'display_post_states' ), 10, 2 ); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Updates language user preference set in user profile |
| 40 |
* |
| 41 |
* @since 0.4 |
| 42 |
* |
| 43 |
* @param int $user_id |
| 44 |
* @return void |
| 45 |
*/ |
| 46 |
public function personal_options_update( $user_id ) { |
| 47 |
// Biography translations |
| 48 |
foreach ( $this->model->get_languages_list() as $lang ) { |
| 49 |
$meta = $lang->slug == $this->options['default_lang'] ? 'description' : 'description_' . $lang->slug; |
| 50 |
$description = empty( $_POST[ 'description_' . $lang->slug ] ) ? '' : trim( $_POST[ 'description_' . $lang->slug ] ); // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput |
| 51 |
|
| 52 |
/** This filter is documented in wp-includes/user.php */ |
| 53 |
$description = apply_filters( 'pre_user_description', $description ); // Applies WP default filter wp_filter_kses |
| 54 |
update_user_meta( $user_id, $meta, $description ); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Outputs hidden information to modify the biography form with js. |
| 60 |
* |
| 61 |
* @since 0.4 |
| 62 |
* |
| 63 |
* @param WP_User $profileuser The current WP_User object. |
| 64 |
* @return void |
| 65 |
*/ |
| 66 |
public function personal_options( $profileuser ) { |
| 67 |
foreach ( $this->model->get_languages_list() as $lang ) { |
| 68 |
$meta = $lang->slug == $this->options['default_lang'] ? 'description' : 'description_' . $lang->slug; |
| 69 |
$description = get_user_meta( $profileuser->ID, $meta, true ); |
| 70 |
|
| 71 |
printf( |
| 72 |
'<input type="hidden" class="biography" name="%s___%s" value="%s" />', |
| 73 |
esc_attr( $lang->slug ), |
| 74 |
esc_attr( $lang->name ), |
| 75 |
sanitize_user_field( 'description', $description, $profileuser->ID, 'edit' ) |
| 76 |
); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Allows to update translations files for plugins and themes. |
| 82 |
* |
| 83 |
* @since 1.6 |
| 84 |
* |
| 85 |
* @param string[] $locales List of locales to update for plugins and themes. |
| 86 |
* @return string[] |
| 87 |
*/ |
| 88 |
public function update_check_locales( $locales ) { |
| 89 |
return array_merge( $locales, $this->model->get_languages_list( array( 'fields' => 'locale' ) ) ); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Adds a text direction dependent class to the body |
| 94 |
* |
| 95 |
* @since 2.2 |
| 96 |
* |
| 97 |
* @param string $classes Space-separated list of CSS classes. |
| 98 |
* @return string |
| 99 |
*/ |
| 100 |
public function admin_body_class( $classes ) { |
| 101 |
if ( ! empty( $this->curlang ) ) { |
| 102 |
$classes .= ' pll-dir-' . ( $this->curlang->is_rtl ? 'rtl' : 'ltr' ); |
| 103 |
} |
| 104 |
return $classes; |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Adds post state for translations of the privacy policy page. |
| 109 |
* |
| 110 |
* @since 2.7 |
| 111 |
* |
| 112 |
* @param string[] $post_states An array of post display states. |
| 113 |
* @param WP_Post $post The current post object. |
| 114 |
* @return string[] |
| 115 |
*/ |
| 116 |
public function display_post_states( $post_states, $post ) { |
| 117 |
$page_for_privacy_policy = get_option( 'wp_page_for_privacy_policy' ); |
| 118 |
|
| 119 |
if ( $page_for_privacy_policy && in_array( $post->ID, $this->model->post->get_translations( $page_for_privacy_policy ) ) ) { |
| 120 |
$post_states['page_for_privacy_policy'] = __( 'Privacy Policy Page', 'polylang' ); |
| 121 |
} |
| 122 |
|
| 123 |
return $post_states; |
| 124 |
} |
| 125 |
} |
| 126 |
|