PluginProbe
Embed Privacy / 1.10.0
Embed Privacy v1.10.0
1.14.0 1.13.0 trunk 0.1 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.1.3 1.10.0 1.10.1 1.10.10 1.10.2 1.10.3 1.10.4 1.10.5 1.10.6 1.10.7 1.10.8 1.10.9 1.11.0 1.11.1 1.11.2 All 68 releases
embed-privacy / inc / integration / class-polylang.php

class-polylang.php in Embed Privacy 1.10.0, at inc/integration/class-polylang.php

57 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace epiphyt\Embed_Privacy\integration;
3
4 /**
5 * Polylang integration for Embed Privacy.
6 *
7 * @author Epiphyt
8 * @license GPL2
9 * @package epiphyt\Embed_Privacy
10 * @since 1.10.0
11 */
12 final class Polylang {
13 /**
14 * Initialize functionality.
15 */
16 public static function init() {
17 \add_filter( 'embed_privacy_provider_name', [ self::class, 'sanitize_name' ] );
18 \add_filter( 'pll_get_post_types', [ self::class, 'register_post_type' ], 10, 2 );
19 }
20
21 /**
22 * Register post type in Polylang to allow translation.
23 *
24 * @param array $post_types List of current translatable custom post types
25 * @param bool $is_settings Whether the current page is the settings page
26 * @return array Updated list of translatable custom post types
27 */
28 public static function register_post_type( array $post_types, $is_settings ) {
29 if ( $is_settings ) {
30 unset( $post_types['epi_embed'] );
31 }
32 else {
33 $post_types['epi_embed'] = 'epi_embed';
34 }
35
36 return $post_types;
37 }
38
39 /**
40 * Sanitize the embed provider name.
41 *
42 * @param string $name Current provider name
43 * @return string Sanitized provider name
44 */
45 public static function sanitize_name( $name ) {
46 if (
47 \is_plugin_active( 'polylang/polylang.php' )
48 && \function_exists( 'pll_current_language' )
49 && \str_ends_with( $name, '-' . \pll_current_language() )
50 ) {
51 $name = \preg_replace( '/-' . \preg_quote( \pll_current_language(), '/' ) . '$/', '', $name );
52 }
53
54 return $name;
55 }
56 }
57