| 1 |
<?php |
| 2 |
/** |
| 3 |
* File: class-wpglobus-admin-post.php |
| 4 |
* Class for post.php page. |
| 5 |
* |
| 6 |
* @since 2.4 |
| 7 |
* @package WPGlobus\Admin |
| 8 |
*/ |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; // Exit if accessed directly |
| 12 |
} |
| 13 |
|
| 14 |
if ( ! class_exists( 'WPGlobus_Admin_Post' ) ) : |
| 15 |
|
| 16 |
/** |
| 17 |
* Class WPGlobus_Admin_Menu. |
| 18 |
*/ |
| 19 |
class WPGlobus_Admin_Post { |
| 20 |
|
| 21 |
/** |
| 22 |
* Static constructor. |
| 23 |
*/ |
| 24 |
public static function construct() { |
| 25 |
|
| 26 |
if ( ! WPGlobus_WP::is_pagenow( 'post.php' ) ) { |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
if ( 'off' === WPGlobus::Config()->toggle ) { |
| 31 |
return; |
| 32 |
} |
| 33 |
|
| 34 |
add_filter( 'preview_post_link', array( __CLASS__, 'filter__preview_post_link' ), 5, 2 ); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Filters the URL used for a post preview in builder mode. |
| 39 |
* |
| 40 |
* @see wp-includes/link-template.php |
| 41 |
* |
| 42 |
* @param string $preview_link URL used for the post preview. |
| 43 |
* @param WP_Post $post Post object (unused). |
| 44 |
* |
| 45 |
* @noinspection PhpUnusedParameterInspection |
| 46 |
*/ |
| 47 |
public static function filter__preview_post_link( $preview_link, $post ) { |
| 48 |
|
| 49 |
if ( ! WPGlobus::Config()->builder->is_builder_page() ) { |
| 50 |
return $preview_link; |
| 51 |
} |
| 52 |
|
| 53 |
if ( WPGlobus::Config()->builder->is_default_language() ) { |
| 54 |
return $preview_link; |
| 55 |
|
| 56 |
} |
| 57 |
|
| 58 |
return WPGlobus_Utils::localize_url( $preview_link, WPGlobus::Config()->builder->get_language() ); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
endif; |
| 63 |
|