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

Commit

Permalink
Do not show edit post submit actions for custom post types not transl…
Browse files Browse the repository at this point in the history
…atable

#310
  • Loading branch information
widoz committed Jul 28, 2018
1 parent 85ee210 commit 93e00c3
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 2 deletions.
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',
$this->allowed_post_types,
$this
);

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

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

0 comments on commit 93e00c3

Please sign in to comment.