Skip to content

Commit

Permalink
Exclude posts from post types not shown in REST when fixing insecure …
Browse files Browse the repository at this point in the history
…content from the admin
  • Loading branch information
kmgalanakis committed Aug 2, 2023
1 parent df6ab38 commit d2b6321
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
23 changes: 22 additions & 1 deletion includes/classes/class-fixinsecurecontent.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ public static function get_instance() {
return self::$instance;
}

/**
* Gets the "post_type" args for the WP_Query calls for the functionality to fix insecure content from within the admin UI.
*
* @return array
*/
public function get_wp_query_post_type_args(): array {
return array(
'show_ui' => true,
'public' => true,
'show_in_rest' => true,
);
}

/**
* Counts posts to be checked for insecure content.
*
Expand All @@ -74,9 +87,12 @@ public static function get_instance() {
* @return int
*/
public function count_post_to_check( string $post_type, int $posts_per_page, int $post_offset ): int {
// Exclude post from post types not shown in REST when counting insecure content to fix from the admin UI.
$post_types = get_post_types( $this->get_wp_query_post_type_args() );

$args = array(
'posts_per_page' => $posts_per_page,
'post_type' => 'all' === $post_type ? 'any' : $post_type,
'post_type' => 'all' === $post_type ? $post_types : $post_type,
'offset' => $post_offset,
'nopaging' => true,
);
Expand Down Expand Up @@ -117,6 +133,11 @@ public function fix( $include, $all, $post_type, $posts_per_page, $post_offset,
} else {
$total = 0;

// Exclude post from post types not shown in REST when fixing insecure content from the admin UI.
if ( ! defined( 'WP_CLI' ) && 'any' === $post_type ) {
$post_type = get_post_types( $this->get_wp_query_post_type_args() );
}

// Loop through all posts and fix content.
while ( true ) {
$args = array(
Expand Down
11 changes: 4 additions & 7 deletions includes/partials/admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
* @package ICW
*/

use ICW\FIX\FixInsecureContent;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}

$post_types = get_post_types(
array(
'show_ui' => true,
'public' => true,
),
'objects'
);
$fix_insecure_content_class = FixInsecureContent::get_instance();
$post_types = get_post_types( $fix_insecure_content_class->get_wp_query_post_type_args(), 'objects' );
?>

<div class="wrap">
Expand Down

0 comments on commit d2b6321

Please sign in to comment.