Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions scripts/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 1 addition & 2 deletions src/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
2 changes: 1 addition & 1 deletion src/php/Admin/Menus/Manage/Manage_Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
);
Expand Down
4 changes: 4 additions & 0 deletions src/php/Core/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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(
Expand All @@ -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 ) ) {
Expand Down
2 changes: 2 additions & 0 deletions src/php/Core/Uninstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/php/Core/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,15 @@ 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",
$scope_name,
$scope_number
)
);
// phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/php/Core/deactivation-notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
20 changes: 11 additions & 9 deletions src/php/Core/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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, [] );
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/php/Integration/Classic_Editor/mce-strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Code_Snippets\Model\Snippet;
use function Code_Snippets\get_snippets;

defined( 'ABSPATH' ) || exit;

/**
* Variable types.
*
Expand Down
2 changes: 2 additions & 0 deletions src/php/Integration/Evaluate_Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,15 @@ 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' ],
[ 'id' => $snippet_id ],
[ '%d' ],
[ '%d' ]
);
// phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
clean_snippets_cache( $table_name );

$network = $table_name === $this->db->ms_table;
Expand Down
2 changes: 1 addition & 1 deletion src/php/Integration/Shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions src/php/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
Expand Down
4 changes: 2 additions & 2 deletions src/php/REST_API/REST_Cache_Bypass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
}
2 changes: 2 additions & 0 deletions src/php/Settings/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions src/php/Utils/editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 2 additions & 0 deletions src/php/Utils/i18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down
2 changes: 2 additions & 0 deletions src/php/Utils/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Code_Snippets\Utils;

defined( 'ABSPATH' ) || exit;

/**
* Resolve whether an operation should apply to the network or the current site.
*
Expand Down
2 changes: 2 additions & 0 deletions src/php/Utils/requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

use WP_Error;

defined( 'ABSPATH' ) || exit;

/**
* Unpack JSON data from a request response.
*
Expand Down
Loading
Loading