diff --git a/src/inc/controllers/Mlp_Dashboard_Widget.php b/src/inc/controllers/Mlp_Dashboard_Widget.php index feafa56b..909e32d2 100644 --- a/src/inc/controllers/Mlp_Dashboard_Widget.php +++ b/src/inc/controllers/Mlp_Dashboard_Widget.php @@ -5,6 +5,14 @@ */ class Mlp_Dashboard_Widget { + /** + * @var string[] + */ + private $allowed_post_types = array( + 'post', + 'page', + ); + /** * @var Inpsyde_Nonce_Validator */ @@ -66,6 +74,10 @@ public function post_submitbox_misc_actions() { $is_translated = $this->is_translated( $post_id ); + if ( ! $this->is_allowed_post( $post_id ) ) { + return; + } + /** * Filters the visibility of the 'Translation completed' checkbox. * @@ -261,4 +273,33 @@ private function is_translated( $post_id ) { return false; } + + /** + * Check if post type is allowed to be translated. + * + * @param $post_id + * + * @return bool + */ + private function is_allowed_post( $post_id ) { + + /** + * Filter the allowed post types. + * + * @param string[] $allowed_post_types Allowed post type names. + * @param Mlp_Translation_Metabox $meta_box Translation meta box object. + */ + $allowed = apply_filters( + 'mlp_allowed_post_types', + $this->allowed_post_types, + $this + ); + + $post = get_post( (int) $post_id ); + if ( ! $post ) { + return false; + } + + return in_array( $post->post_type, $allowed, true ); + } } diff --git a/src/inc/controllers/Mlp_Trasher.php b/src/inc/controllers/Mlp_Trasher.php index 2afca659..5848f9db 100644 --- a/src/inc/controllers/Mlp_Trasher.php +++ b/src/inc/controllers/Mlp_Trasher.php @@ -5,6 +5,14 @@ */ class Mlp_Trasher { + /** + * @var string[] + */ + private $allowed_post_types = array( + 'post', + 'page', + ); + /** * @var Mlp_Module_Manager_Interface */ @@ -65,9 +73,14 @@ public function initialize() { */ public function post_submitbox_misc_actions() { - $post_id = absint( filter_input( INPUT_GET, 'post' ) ); + $post_id = $this->get_post_id(); + + if ( ! $this->is_allowed_post( $post_id ) ) { + return; + } + if ( $post_id ) { - // old key + // old key. $trash_the_other_posts = (int) get_post_meta( $post_id, 'trash_the_other_posts', true ); if ( 1 !== $trash_the_other_posts ) { @@ -195,4 +208,43 @@ private function register_setting() { 'description' => $description, ) ); } + + /** + * Returns the current post ID, or 0 on failure. + * + * @return int + */ + private function get_post_id() { + + return absint( filter_input( INPUT_GET, 'post' ) ); + } + + /** + * Check if post type is allowed to be translated. + * + * @param $post_id + * + * @return bool + */ + private function is_allowed_post( $post_id ) { + + /** + * Filter the allowed post types. + * + * @param string[] $allowed_post_types Allowed post type names. + * @param Mlp_Trasher $meta_box Trasher meta box object. + */ + $allowed = apply_filters( + 'mlp_allowed_post_types', + $this->allowed_post_types, + $this + ); + + $post = get_post( (int) $post_id ); + if ( ! $post ) { + return false; + } + + return in_array( $post->post_type, $allowed, true ); + } }