Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Do not show edit post submit actions for custom post types not transl… #316

Merged
merged 3 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/inc/controllers/Mlp_Dashboard_Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
*/
class Mlp_Dashboard_Widget {

/**
* @var string[]
*/
private $allowed_post_types = array(
'post',
'page',
);

/**
* @var Inpsyde_Nonce_Validator
*/
Expand Down Expand Up @@ -66,6 +74,10 @@ public function post_submitbox_misc_actions() {

$is_translated = $this->is_translated( $post_id );

if ( ! $this->isAllowedPost( $post_id ) ) {
return;
}

/**
* Filters the visibility of the 'Translation completed' checkbox.
*
Expand Down Expand Up @@ -261,4 +273,27 @@ private function is_translated( $post_id ) {

return false;
}

/**
* Check if post type is allowed to be translated.
*
* @param $post_id
*
* @return bool
*/
private function isAllowedPost( $post_id ) {

$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 );
}
}
50 changes: 48 additions & 2 deletions src/inc/controllers/Mlp_Trasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
*/
class Mlp_Trasher {

/**
* @var string[]
*/
private $allowed_post_types = array(
'post',
'page',
);

/**
* @var Mlp_Module_Manager_Interface
*/
Expand Down Expand Up @@ -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->isAllowedPost( $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 ) {
Expand Down Expand Up @@ -195,4 +208,37 @@ 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 isAllowedPost( $post_id ) {

$allowed = apply_filters(
'mlp_allowed_post_types',
widoz marked this conversation as resolved.
Show resolved Hide resolved
$this->allowed_post_types,
$this
);

$post = get_post( (int) $post_id );
if ( ! $post ) {
return false;
}

return in_array( $post->post_type, $allowed, true );
}
}