From 4e4280c189e24376c5687ae5d49ac80192b62456 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Tue, 11 Jul 2023 09:09:40 +0100 Subject: [PATCH 01/10] Improve readability --- php/cache/class-cache-point.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/php/cache/class-cache-point.php b/php/cache/class-cache-point.php index 1d39f6863..1f79d4a87 100644 --- a/php/cache/class-cache-point.php +++ b/php/cache/class-cache-point.php @@ -869,9 +869,13 @@ public function query_cached_items( $urls ) { foreach ( $indexes as $key ) { $url = $urls[ $key ]; - if ( ! isset( $meta[ self::META_KEYS['cached_urls'] ][ $url ] ) - || $url === $meta[ self::META_KEYS['cached_urls'] ][ $url ] - && $meta[ self::META_KEYS['last_updated'] ] < time() - MINUTE_IN_SECONDS * 10 ) { + if ( + ! isset( $meta[ self::META_KEYS['cached_urls'] ][ $url ] ) + || ( + $url === $meta[ self::META_KEYS['cached_urls'] ][ $url ] + && $meta[ self::META_KEYS['last_updated'] ] < time() - MINUTE_IN_SECONDS * 10 + ) + ) { // Send to upload prep. $this->prepare_for_sync( $post->ID ); $meta[ self::META_KEYS['cached_urls'] ][ $url ] = $url; From f61f3156033185fc5055bb0aff9d76be223e9663 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Tue, 11 Jul 2023 09:11:32 +0100 Subject: [PATCH 02/10] Ignore veted rules --- php/cache/class-cache-point.php | 2 +- php/class-assets.php | 2 +- php/class-media.php | 6 +++++- php/class-plugin.php | 2 +- php/class-report.php | 2 +- php/class-string-replace.php | 2 +- php/class-utils.php | 2 +- php/media/class-gallery.php | 2 +- php/relate/class-relationship.php | 2 +- php/sync/class-download-sync.php | 2 +- ui-definitions/components/wizard.php | 2 +- ui-definitions/settings-pages.php | 4 ++-- 12 files changed, 17 insertions(+), 13 deletions(-) diff --git a/php/cache/class-cache-point.php b/php/cache/class-cache-point.php index 1f79d4a87..d649235b8 100644 --- a/php/cache/class-cache-point.php +++ b/php/cache/class-cache-point.php @@ -976,6 +976,6 @@ protected function register_post_type() { 'rewrite' => false, 'capability_type' => 'page', ); - $this->post_type = register_post_type( self::POST_TYPE_SLUG, $args ); + $this->post_type = register_post_type( self::POST_TYPE_SLUG, $args ); // phpcs:ignore WordPress.NamingConventions.ValidPostTypeSlug.NotStringLiteral } } diff --git a/php/class-assets.php b/php/class-assets.php index 878d5a830..2eb1989f7 100644 --- a/php/class-assets.php +++ b/php/class-assets.php @@ -1156,7 +1156,7 @@ protected function register_post_type() { 'rewrite' => false, 'capability_type' => 'page', ); - $this->post_type = register_post_type( self::POST_TYPE_SLUG, $args ); + $this->post_type = register_post_type( self::POST_TYPE_SLUG, $args ); // phpcs:ignore WordPress.NamingConventions.ValidPostTypeSlug.NotStringLiteral } /** diff --git a/php/class-media.php b/php/class-media.php index 54b2918d6..b00554771 100644 --- a/php/class-media.php +++ b/php/class-media.php @@ -356,6 +356,7 @@ public function maybe_file_exist_in_url( $url ) { if ( ! filter_var( $url, FILTER_VALIDATE_URL ) ) { return false; } + // phpcs:disable WordPress.WP.AlternativeFunctions $ch = curl_init( $url ); curl_setopt( $ch, CURLOPT_NOBODY, true ); curl_exec( $ch ); @@ -368,6 +369,7 @@ public function maybe_file_exist_in_url( $url ) { } curl_close( $ch ); + // phpcs:enable return $status; } @@ -3033,13 +3035,15 @@ public function apply_media_library_filters( $query ) { if ( SYNC::META_KEYS['unsynced'] === $request ) { global $wpdb; $wpdb->cld_table = Utils::get_relationship_table(); - $result = $wpdb->get_col( "SELECT post_id FROM $wpdb->cld_table WHERE public_id IS NULL" ); + $result = $wpdb->get_col( "SELECT post_id FROM $wpdb->cld_table WHERE public_id IS NULL" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching + // phpcs:disable WordPressVIPMinimum.Hooks.PreGetPosts.PreGetPosts if ( ! empty( $result ) ) { $query->set( 'post__in', $result ); } else { $query->set( 'post__in', array( 0 ) ); } + // phpcs:enable } } } diff --git a/php/class-plugin.php b/php/class-plugin.php index 02204d0d6..39b92da2e 100644 --- a/php/class-plugin.php +++ b/php/class-plugin.php @@ -190,7 +190,7 @@ private function get_settings_page_structure() { foreach ( $parts as $slug => $part ) { if ( file_exists( $this->dir_path . "ui-definitions/settings-{$slug}.php" ) ) { - $parts[ $slug ] = include $this->dir_path . "ui-definitions/settings-{$slug}.php"; + $parts[ $slug ] = include $this->dir_path . "ui-definitions/settings-{$slug}.php"; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable } } diff --git a/php/class-report.php b/php/class-report.php index b69e411fe..9b69765a7 100644 --- a/php/class-report.php +++ b/php/class-report.php @@ -223,7 +223,7 @@ static function( &$row ) { "SELECT * FROM {$wpdb->cld_table} WHERE post_id = %d;", $post->ID ); - $relationship = $wpdb->get_row( $prepare ); // phpcs:ignore WordPress.DB.PreparedSQL + $relationship = $wpdb->get_row( $prepare ); // phpcs:ignore WordPress.DB.PreparedSQL,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching ksort( $attachment ); ksort( $meta ); diff --git a/php/class-string-replace.php b/php/class-string-replace.php index d275c7960..07a2b99d8 100644 --- a/php/class-string-replace.php +++ b/php/class-string-replace.php @@ -168,7 +168,7 @@ public function init_debug( $template ) { if ( defined( 'CLD_DEBUG' ) && true === CLD_DEBUG && ! Utils::get_sanitized_text( '_bypass' ) ) { $this->context = 'view'; ob_start(); - include $template; + include $template; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable $html = ob_get_clean(); echo $this->replace_strings( $html ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $template = $this->plugin->template_path . 'blank-template.php'; diff --git a/php/class-utils.php b/php/class-utils.php index c69e2e050..94bcb47b9 100644 --- a/php/class-utils.php +++ b/php/class-utils.php @@ -500,7 +500,7 @@ public static function pathinfo( $path, $flags = 15 ) { * * @see wp-includes/formatting.php */ - $path = str_replace( array( '%2F', '%5C' ), '/', urlencode( $path ) ); + $path = str_replace( array( '%2F', '%5C' ), '/', urlencode( $path ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode $pathinfo = pathinfo( $path, $flags ); diff --git a/php/media/class-gallery.php b/php/media/class-gallery.php index b4ef33edf..0445f589d 100644 --- a/php/media/class-gallery.php +++ b/php/media/class-gallery.php @@ -212,7 +212,7 @@ public function enqueue_admin_scripts() { * @return array */ private function get_asset() { - $asset = require $this->plugin->dir_path . 'js/gallery.asset.php'; + $asset = require $this->plugin->dir_path . 'js/gallery.asset.php'; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable $asset['dependencies'] = array_filter( $asset['dependencies'], diff --git a/php/relate/class-relationship.php b/php/relate/class-relationship.php index 51ba52963..56a1b9489 100644 --- a/php/relate/class-relationship.php +++ b/php/relate/class-relationship.php @@ -216,7 +216,7 @@ public static function get_ids_by_public_id( $public_id ) { global $wpdb; $table_name = Utils::get_relationship_table(); - $ids = $wpdb->get_col( $wpdb->prepare( "SELECT post_id FROM {$table_name} WHERE public_id = %s", $public_id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared + $ids = $wpdb->get_col( $wpdb->prepare( "SELECT post_id FROM {$table_name} WHERE public_id = %s", $public_id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching return array_map( 'intval', $ids ); } diff --git a/php/sync/class-download-sync.php b/php/sync/class-download-sync.php index 09104a55c..83816e27a 100644 --- a/php/sync/class-download-sync.php +++ b/php/sync/class-download-sync.php @@ -224,7 +224,7 @@ public function import_asset( $attachment_id, $file_path, $transformations = nul $http_class = ABSPATH . WPINC . '/class-wp-http.php'; } if ( ! class_exists( 'WP_Http' ) ) { - require_once $http_class; + require_once $http_class; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable } require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/image.php'; diff --git a/ui-definitions/components/wizard.php b/ui-definitions/components/wizard.php index 01ad95004..4716cc5de 100644 --- a/ui-definitions/components/wizard.php +++ b/ui-definitions/components/wizard.php @@ -152,7 +152,7 @@ - dir_path . 'php/templates/connection-string.php'; ?> + dir_path . 'php/templates/connection-string.php'; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable ?>