diff --git a/scripts/bundle.ts b/scripts/bundle.ts index 7c50c00c5..ab32159f8 100644 --- a/scripts/bundle.ts +++ b/scripts/bundle.ts @@ -21,6 +21,7 @@ const BUNDLE_FILES = [ 'src/vendor/**/*', 'src/code-snippets.php', 'src/uninstall.php', + 'src/composer.json', 'src/readme.txt', 'src/license.txt', 'CHANGELOG.md' diff --git a/src/composer.json b/src/composer.json index ecb505d47..1092c1527 100644 --- a/src/composer.json +++ b/src/composer.json @@ -22,8 +22,7 @@ }, "autoload": { "files": [ - "php/Admin/Menus/Manage/Manage_Menu.php", - "php/Utils/requests.php" + "php/Admin/Menus/Manage/Manage_Menu.php" ], "psr-4": { "Code_Snippets\\": "php/" diff --git a/src/php/Admin/Menus/Manage/Manage_Menu.php b/src/php/Admin/Menus/Manage/Manage_Menu.php index c08396f23..58c25b4b9 100644 --- a/src/php/Admin/Menus/Manage/Manage_Menu.php +++ b/src/php/Admin/Menus/Manage/Manage_Menu.php @@ -402,7 +402,7 @@ public static function get_snippets_per_page(): int { return intval( apply_filters( - 'snippets_per_page', + 'snippets_per_page', // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- public filter name kept for existing callbacks. $per_page > 0 ? $per_page : self::get_default_snippets_per_page() ) ); diff --git a/src/php/Core/DB.php b/src/php/Core/DB.php index 0f10c9185..92d22fefb 100644 --- a/src/php/Core/DB.php +++ b/src/php/Core/DB.php @@ -89,7 +89,9 @@ public static function table_exists( string $table_name, bool $refresh = false ) if ( $refresh || ! isset( $checked[ $table_name ] ) ) { // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching, caching is handled through $checked variable. + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Checks whether the plugin's own table exists; no WordPress API does this. $result = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) ) ); + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery $checked[ $table_name ] = $result === $table_name; } @@ -335,6 +337,7 @@ private static function fetch_snippets_from_table( string $table_name, array $sc ? 'AND active=1' : 'AND active <> -1'; + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- The plugin's own table, named from $wpdb->prefix; any values are prepared. $snippets = $wpdb->get_results( // phpcs:disable WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare $wpdb->prepare( @@ -347,6 +350,7 @@ private static function fetch_snippets_from_table( string $table_name, array $sc ), 'ARRAY_A' ); + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter // Cache the full list of snippets. if ( is_array( $snippets ) ) { diff --git a/src/php/Core/Uninstaller.php b/src/php/Core/Uninstaller.php index c4f0a04e1..837feb99d 100644 --- a/src/php/Core/Uninstaller.php +++ b/src/php/Core/Uninstaller.php @@ -73,6 +73,7 @@ public function is_complete_uninstall_enabled(): bool { private function uninstall_current_site() { global $wpdb; + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- Removes the plugin's own table on uninstall. $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}snippets" ); delete_option( 'code_snippets_version' ); @@ -124,6 +125,7 @@ private function uninstall_multisite() { restore_current_blog(); // Remove network snippets table. + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- Removes the plugin's own table on uninstall. $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}ms_snippets" ); // Remove saved options. diff --git a/src/php/Core/Upgrader.php b/src/php/Core/Upgrader.php index ca355af36..e5ce0a9ba 100644 --- a/src/php/Core/Upgrader.php +++ b/src/php/Core/Upgrader.php @@ -217,6 +217,7 @@ private function migrate_scope_data( string $table_name ) { foreach ( $scopes as $scope_number => $scope_name ) { // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching, will flush at end of process. + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- The plugin's own table, named from $wpdb->prefix; any values are prepared. $wpdb->query( $wpdb->prepare( "UPDATE $table_name SET scope = %s WHERE scope = %d", @@ -224,6 +225,7 @@ private function migrate_scope_data( string $table_name ) { $scope_number ) ); + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter } } diff --git a/src/php/Core/deactivation-notice.php b/src/php/Core/deactivation-notice.php index 2a70b51d7..600dd40cd 100644 --- a/src/php/Core/deactivation-notice.php +++ b/src/php/Core/deactivation-notice.php @@ -11,7 +11,11 @@ * phpcs:disable Modernize.FunctionCalls.Dirname.FileConstant */ -if ( ! defined( 'ABSPATH' ) || function_exists( 'code_snippets_deactivation_notice' ) ) { +if ( ! defined( 'ABSPATH' ) ) { + exit; +} + +if ( function_exists( 'code_snippets_deactivation_notice' ) ) { return; } diff --git a/src/php/Core/load.php b/src/php/Core/load.php index 6e00ab865..52e81b819 100644 --- a/src/php/Core/load.php +++ b/src/php/Core/load.php @@ -9,6 +9,8 @@ use Composer\Autoload\ClassLoader; +defined( 'ABSPATH' ) || exit; + /** * The version number for this release of the plugin. * This will later be used for upgrades and enqueuing files. @@ -60,20 +62,20 @@ * After loading, remove any PSR-4 namespace mappings that do not start with our vendor prefix but have a corresponding * prefixed version. These are not removed by Imposter and would cause collisions with other plugins that use the same libraries. * - * @var ClassLoader $autoloader Composer autoloader instance. + * @var ClassLoader $code_snippets_autoloader Composer autoloader instance. */ -$autoloader = require dirname( __DIR__, 2 ) . '/vendor/autoload.php'; +$code_snippets_autoloader = require dirname( __DIR__, 2 ) . '/vendor/autoload.php'; -if ( $autoloader instanceof ClassLoader ) { - $vendor_prefix = __NAMESPACE__ . '\\Vendor\\'; +if ( $code_snippets_autoloader instanceof ClassLoader ) { + $code_snippets_vendor_prefix = __NAMESPACE__ . '\\Vendor\\'; - $prefixes = $autoloader->getPrefixesPsr4(); + $code_snippets_prefixes = $code_snippets_autoloader->getPrefixesPsr4(); - foreach ( $prefixes as $namespace => $paths ) { + foreach ( $code_snippets_prefixes as $code_snippets_namespace => $code_snippets_paths ) { // Remove any non-Code_Snippets namespace that has a corresponding prefixed version. - if ( false === strpos( $namespace, $vendor_prefix ) ) { - if ( isset( $prefixes[ $vendor_prefix . $namespace ] ) ) { - $autoloader->setPsr4( $namespace, [] ); + if ( false === strpos( $code_snippets_namespace, $code_snippets_vendor_prefix ) ) { + if ( isset( $code_snippets_prefixes[ $code_snippets_vendor_prefix . $code_snippets_namespace ] ) ) { + $code_snippets_autoloader->setPsr4( $code_snippets_namespace, [] ); } } } diff --git a/src/php/Integration/Classic_Editor/mce-strings.php b/src/php/Integration/Classic_Editor/mce-strings.php index f9cda2c50..550025c03 100644 --- a/src/php/Integration/Classic_Editor/mce-strings.php +++ b/src/php/Integration/Classic_Editor/mce-strings.php @@ -13,6 +13,8 @@ use Code_Snippets\Model\Snippet; use function Code_Snippets\get_snippets; +defined( 'ABSPATH' ) || exit; + /** * Variable types. * diff --git a/src/php/Integration/Evaluate_Functions.php b/src/php/Integration/Evaluate_Functions.php index 8265c2865..a21ea2c4a 100644 --- a/src/php/Integration/Evaluate_Functions.php +++ b/src/php/Integration/Evaluate_Functions.php @@ -163,6 +163,7 @@ private function quick_deactivate_snippet( int $snippet_id, string $table_name ) update_option( 'active_shared_network_snippets', $active_shared_ids ); clean_active_snippets_cache( $table_name ); } else { + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- The plugin's own table, named from $wpdb->prefix; any values are prepared. $wpdb->update( $table_name, [ 'active' => '0' ], @@ -170,6 +171,7 @@ private function quick_deactivate_snippet( int $snippet_id, string $table_name ) [ '%d' ], [ '%d' ] ); + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching clean_snippets_cache( $table_name ); $network = $table_name === $this->db->ms_table; diff --git a/src/php/Integration/Shortcodes.php b/src/php/Integration/Shortcodes.php index 9bcc30265..e15f206f9 100644 --- a/src/php/Integration/Shortcodes.php +++ b/src/php/Integration/Shortcodes.php @@ -192,7 +192,7 @@ private function evaluate_shortcode_from_db( Snippet $snippet, array $atts ): st extract( $atts, EXTR_SKIP ); ob_start(); - eval( "?>\n\n" . $snippet->code ); + eval( "?>\n\n" . $snippet->code ); // phpcs:ignore Generic.PHP.ForbiddenFunctions.Found -- Running user-written snippets is the purpose of this plugin. return ob_get_clean(); } diff --git a/src/php/Plugin.php b/src/php/Plugin.php index 4c7b3fce4..7861fc73a 100644 --- a/src/php/Plugin.php +++ b/src/php/Plugin.php @@ -115,6 +115,7 @@ public function __construct() { private function load_utilities() { require_once __DIR__ . '/Utils/editor.php'; require_once __DIR__ . '/Utils/options.php'; + require_once __DIR__ . '/Utils/requests.php'; require_once __DIR__ . '/Settings/settings.php'; require_once __DIR__ . '/snippet-ops.php'; } diff --git a/src/php/REST_API/Import/Plugins/Header_Footer_Code_Manager_Plugin_Importer.php b/src/php/REST_API/Import/Plugins/Header_Footer_Code_Manager_Plugin_Importer.php index 6217fcdd7..0fb7bd8ea 100644 --- a/src/php/REST_API/Import/Plugins/Header_Footer_Code_Manager_Plugin_Importer.php +++ b/src/php/REST_API/Import/Plugins/Header_Footer_Code_Manager_Plugin_Importer.php @@ -64,12 +64,16 @@ public function get_data( array $ids_to_import = [] ): array { $ids_format = implode( ',', array_fill( 0, count( $ids_to_import ), '%d' ) ); // phpcs:disable WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Reads the source plugin's own table; the name is built from $wpdb->prefix and IDs are prepared. $snippets = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `$table_name` WHERE script_id IN ($ids_format)", $ids_to_import ), ARRAY_A ); + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter } else { + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Reads the source plugin's own table; the name is built from $wpdb->prefix and IDs are prepared. $snippets = $wpdb->get_results( "SELECT * FROM `$table_name`", ARRAY_A ); + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter } foreach ( $snippets as &$snippet ) { diff --git a/src/php/REST_API/Import/Plugins/Insert_Headers_And_Footers_Plugin_Importer.php b/src/php/REST_API/Import/Plugins/Insert_Headers_And_Footers_Plugin_Importer.php index db738e9be..66f680b51 100644 --- a/src/php/REST_API/Import/Plugins/Insert_Headers_And_Footers_Plugin_Importer.php +++ b/src/php/REST_API/Import/Plugins/Insert_Headers_And_Footers_Plugin_Importer.php @@ -95,7 +95,7 @@ public function get_data( array $ids_to_import = [] ): array { 'title' => $snippet_item->post_title, ]; - $data[] = apply_filters( 'wpcode_export_snippet_data', $snippet_data, $snippet ); + $data[] = apply_filters( 'wpcode_export_snippet_data', $snippet_data, $snippet ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WPCode's own hook, applied as its exporter does. } return array_reverse( $data ); diff --git a/src/php/REST_API/Import/Plugins/Insert_PHP_Code_Snippet_Plugin_Importer.php b/src/php/REST_API/Import/Plugins/Insert_PHP_Code_Snippet_Plugin_Importer.php index 2e11627b8..1ded4379c 100644 --- a/src/php/REST_API/Import/Plugins/Insert_PHP_Code_Snippet_Plugin_Importer.php +++ b/src/php/REST_API/Import/Plugins/Insert_PHP_Code_Snippet_Plugin_Importer.php @@ -64,15 +64,19 @@ public function get_data( array $ids_to_import = [] ): array { $table_name = $wpdb->prefix . 'xyz_ips_short_code'; if ( empty( $ids_to_import ) ) { + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Reads the source plugin's own table; the name is built from $wpdb->prefix and IDs are prepared. $snippets = $wpdb->get_results( "SELECT * FROM `$table_name`", ARRAY_A ); + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter } else { $ids_format = implode( ',', array_fill( 0, count( $ids_to_import ), '%d' ) ); // phpcs:disable WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Reads the source plugin's own table; the name is built from $wpdb->prefix and IDs are prepared. $snippets = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `$table_name` WHERE id IN ($ids_format)", $ids_to_import ), ARRAY_A ); + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter } if ( ! is_array( $snippets ) ) { diff --git a/src/php/REST_API/REST_Cache_Bypass.php b/src/php/REST_API/REST_Cache_Bypass.php index f664e9000..05cd81fd9 100644 --- a/src/php/REST_API/REST_Cache_Bypass.php +++ b/src/php/REST_API/REST_Cache_Bypass.php @@ -91,10 +91,10 @@ private function signal_cache_plugins(): void { // Honoured by WP Super Cache, W3 Total Cache, WP Rocket, WP Fastest Cache, // WP-Optimize, Hummingbird, Cache Enabler, Breeze and LiteSpeed Cache. if ( ! defined( 'DONOTCACHEPAGE' ) ) { - define( 'DONOTCACHEPAGE', true ); + define( 'DONOTCACHEPAGE', true ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- constant read by caching plugins. } // LiteSpeed Cache decides from its own control API, and caches REST responses by default. - do_action( 'litespeed_control_set_nocache', 'Code Snippets REST API response' ); + do_action( 'litespeed_control_set_nocache', 'Code Snippets REST API response' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- LiteSpeed Cache's own hook. } } diff --git a/src/php/Settings/settings.php b/src/php/Settings/settings.php index 08b6f89f0..1300a7239 100644 --- a/src/php/Settings/settings.php +++ b/src/php/Settings/settings.php @@ -21,6 +21,8 @@ use function Code_Snippets\Utils\update_self_option; use const Code_Snippets\CACHE_GROUP; +defined( 'ABSPATH' ) || exit; + const CACHE_KEY = 'code_snippets_settings'; const OPTION_GROUP = 'code-snippets'; const OPTION_NAME = 'code_snippets_settings'; diff --git a/src/php/Utils/editor.php b/src/php/Utils/editor.php index e8b054e54..744cf9572 100644 --- a/src/php/Utils/editor.php +++ b/src/php/Utils/editor.php @@ -13,6 +13,8 @@ use const Code_Snippets\PLUGIN_FILE; use const Code_Snippets\PLUGIN_VERSION; +defined( 'ABSPATH' ) || exit; + /** * Register and load the CodeMirror library. * diff --git a/src/php/Utils/i18n.php b/src/php/Utils/i18n.php index 405907a4e..8c6ef0171 100644 --- a/src/php/Utils/i18n.php +++ b/src/php/Utils/i18n.php @@ -5,6 +5,8 @@ * @package Code_Snippets */ +defined( 'ABSPATH' ) || exit; + __( 'You can now safely remove the free version of Code Snippets', 'code-snippets' ); __( 'Success', 'code-snippets' ); diff --git a/src/php/Utils/options.php b/src/php/Utils/options.php index a1d34de90..7c231e4cd 100644 --- a/src/php/Utils/options.php +++ b/src/php/Utils/options.php @@ -7,6 +7,8 @@ namespace Code_Snippets\Utils; +defined( 'ABSPATH' ) || exit; + /** * Resolve whether an operation should apply to the network or the current site. * diff --git a/src/php/Utils/requests.php b/src/php/Utils/requests.php index 9cfac21f8..1c7eb237c 100644 --- a/src/php/Utils/requests.php +++ b/src/php/Utils/requests.php @@ -9,6 +9,8 @@ use WP_Error; +defined( 'ABSPATH' ) || exit; + /** * Unpack JSON data from a request response. * diff --git a/src/php/snippet-ops.php b/src/php/snippet-ops.php index 6770200de..2c4f288fd 100644 --- a/src/php/snippet-ops.php +++ b/src/php/snippet-ops.php @@ -15,6 +15,8 @@ use function Code_Snippets\Utils\validate_network_param; use function Code_Snippets\Utils\update_self_option; +defined( 'ABSPATH' ) || exit; + /** * Get the locked status for a snippet from wp_options. * @@ -199,7 +201,9 @@ function get_snippets( array $ids = [], ?bool $network = null ): array { // Fetch all snippets from the database if none are cached. if ( ! is_array( $snippets ) ) { + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- The plugin's own table, named from $wpdb->prefix; any values are prepared. $results = $wpdb->get_results( "SELECT * FROM $table_name", ARRAY_A ); + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $snippets = $results ? array_map( @@ -257,7 +261,9 @@ function get_all_snippet_tags() { // Grab all tags from the database. $tags = array(); + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- The plugin's own table, named from $wpdb->prefix; any values are prepared. $all_tags = $wpdb->get_col( "SELECT tags FROM $table_name" ); + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter // Merge all tags into a single array. foreach ( $all_tags as $snippet_tags ) { @@ -335,7 +341,9 @@ function get_snippet( int $id = 0, ?bool $network = null ): ?Snippet { // Otherwise, retrieve the snippet from the database. // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- The plugin's own table, named from $wpdb->prefix; any values are prepared. $snippet_data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table_name WHERE id = %d", $id ) ); + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $snippet = new Snippet( $snippet_data ); } @@ -452,6 +460,7 @@ function activate_snippet( int $id, ?bool $network = null ) { } } + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- The plugin's own table has no WordPress API. $result = $wpdb->update( $table_name, array( 'active' => '1' ), @@ -459,6 +468,7 @@ function activate_snippet( int $id, ?bool $network = null ) { array( '%d' ), array( '%d' ) ); + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery if ( ! $result ) { return __( 'Could not activate snippet.', 'code-snippets' ); @@ -535,7 +545,9 @@ function activate_snippets( array $ids, ?bool $network = null ): ?array { $ids_format = implode( ',', array_fill( 0, count( $valid_ids ), '%d' ) ); // phpcs:disable WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- The plugin's own table, named from $wpdb->prefix; any values are prepared. $rows_updated = $wpdb->query( $wpdb->prepare( "UPDATE $table_name SET active = 1 WHERE id IN ($ids_format)", $valid_ids ) ); + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter if ( ! $rows_updated ) { return null; @@ -566,6 +578,7 @@ function deactivate_snippet( int $id, ?bool $network = null ): ?Snippet { $table = code_snippets()->db->get_table_name( $network ); // Set the snippet to inactive. + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- The plugin's own table has no WordPress API. $result = $wpdb->update( $table, array( 'active' => '0' ), @@ -573,6 +586,7 @@ function deactivate_snippet( int $id, ?bool $network = null ): ?Snippet { array( '%d' ), array( '%d' ) ); + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery if ( ! $result ) { return null; @@ -618,11 +632,13 @@ function delete_snippet( int $id, ?bool $network = null ): bool { return false; } + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- The plugin's own table has no WordPress API. $result = $wpdb->delete( $table, array( 'id' => $id ), array( '%d' ) ); + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery if ( $result ) { clean_snippets_cache( $table ); @@ -662,7 +678,9 @@ function trash_snippet( int $id, ?bool $network = null ): bool { return false; } + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- The plugin's own table has no WordPress API. $wpdb->update( $table, [ 'active' => '-1' ], [ 'id' => $id ], [ '%d' ] ); + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery clean_snippets_cache( $table ); do_action( 'code_snippets/trash_snippet', $snippet, $network ); @@ -686,7 +704,9 @@ function restore_snippet( int $id, ?bool $network = null ): bool { $network = validate_network_param( $network ); $table = code_snippets()->db->get_table_name( $network ); + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- The plugin's own table has no WordPress API. $result = $wpdb->update( $table, [ 'active' => '0' ], [ 'id' => $id ], [ '%d' ] ); + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery if ( $result ) { clean_snippets_cache( $table ); @@ -811,10 +831,14 @@ function save_snippet( $snippet ): ?Snippet { $data['created_by'] = $author_id; $format = '%s'; + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- The plugin's own table has no WordPress API. $result = $wpdb->insert( $table, $data, $format ); + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery if ( false === $result && Core\DB::upgrade_after_unknown_column( $table ) ) { + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- The plugin's own table has no WordPress API. $result = $wpdb->insert( $table, $data, $format ); + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery } if ( false === $result ) { @@ -838,10 +862,14 @@ function save_snippet( $snippet ): ?Snippet { $where = [ 'id' => $snippet->id ]; $where_format = [ '%d' ]; + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- The plugin's own table has no WordPress API. $result = $wpdb->update( $table, $data, $where, null, $where_format ); + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery if ( false === $result && Core\DB::upgrade_after_unknown_column( $table ) ) { + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- The plugin's own table has no WordPress API. $result = $wpdb->update( $table, $data, $where, null, $where_format ); + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery } if ( false === $result ) { @@ -944,7 +972,7 @@ function execute_snippet( string $code, int $id = 0, bool $force = false ) { ob_start(); try { - $result = eval( $code ); + $result = eval( $code ); // phpcs:ignore Generic.PHP.ForbiddenFunctions.Found -- Running user-written snippets is the purpose of this plugin. } catch ( Throwable $throwable ) { $result = $throwable; } @@ -985,8 +1013,10 @@ function get_snippet_by_cloud_id( string $cloud_id, ?bool $multisite = null ): ? } // Otherwise, search for the snippet from the database. + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- The plugin's own table, named from $wpdb->prefix; any values are prepared. $snippet_data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table_name WHERE cloud_id = %s", $cloud_id ) ); // cache pass, db call ok. $snippet = $snippet_data ? new Snippet( $snippet_data ) : null; + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter // Load locked from wp_options if snippet exists. if ( $snippet && $snippet->id > 0 ) { @@ -1091,7 +1121,9 @@ function update_snippet_fields( int $snippet_id, array $fields, ?bool $network = // Update the snippet in the database (excluding locked). if ( ! empty( $clean_fields ) ) { + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- The plugin's own table has no WordPress API. $wpdb->update( $table, $clean_fields, array( 'id' => $snippet->id ), null, array( '%d' ) ); + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery } // Save locked to wp_options if it was provided. diff --git a/src/uninstall.php b/src/uninstall.php index f4907f7b7..268155d89 100755 --- a/src/uninstall.php +++ b/src/uninstall.php @@ -17,9 +17,9 @@ // WordPress runs this file without loading the plugin, so load what the uninstaller needs. if ( ! defined( 'CODE_SNIPPETS_FILE' ) ) { - $plugin_data = get_file_data( __DIR__ . '/code-snippets.php', [ 'Version' => 'Version' ] ); + $code_snippets_plugin_data = get_file_data( __DIR__ . '/code-snippets.php', [ 'Version' => 'Version' ] ); - define( 'CODE_SNIPPETS_VERSION', $plugin_data['Version'] ); + define( 'CODE_SNIPPETS_VERSION', $code_snippets_plugin_data['Version'] ); define( 'CODE_SNIPPETS_FILE', __DIR__ . '/code-snippets.php' ); define( 'CODE_SNIPPETS_PRO', false ); @@ -28,5 +28,5 @@ require_once __DIR__ . '/php/Core/Uninstaller.php'; -$uninstaller = new Uninstaller(); -$uninstaller->uninstall_plugin(); +$code_snippets_uninstaller = new Uninstaller(); +$code_snippets_uninstaller->uninstall_plugin();