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