\n", esc_html__( 'For more information:', 'code-snippets' ) );
@@ -143,7 +143,7 @@ private function load_manage_help() {
__( 'Be sure to check your snippets for errors before you activate them, as a faulty snippet could bring your whole blog down. If your site starts doing strange things, deactivate all your snippets and activate them one at a time.', 'code-snippets' ),
__( "If something goes wrong with a snippet, and you can't use WordPress, you can cause all snippets to stop executing by turning on safe mode.", 'code-snippets' ),
/* translators: %s: URL to Code Snippets Pro Docs */
- sprintf( __( 'You can find out how to enable safe mode in the Code Snippets Pro Docs.', 'code-snippets' ), 'https://help.codesnippets.pro/article/12-safe-mode' )
+ sprintf( __( 'You can find out how to enable safe mode in the Code Snippets Pro Docs.', 'code-snippets' ), 'https://codesnippets.pro/doc/safe-mode/' ),
]
);
}
@@ -159,7 +159,7 @@ private function load_edit_help() {
$this->get_intro_text() .
__( 'Here you can add a new snippet, or edit an existing one.', 'code-snippets' ),
/* translators: %s: URL to Code Snippets Pro Docs */
- sprintf( __( "If you're not sure about the types of snippets you can add, take a look at the Code Snippets Pro Docs for inspiration.", 'code-snippets' ), 'https://help.codesnippets.pro/collection/2-adding-snippets' ),
+ sprintf( __( "If you're not sure about the types of snippets you can add, take a look at the Code Snippets Pro Docs for inspiration.", 'code-snippets' ), 'https://codesnippets.pro/docs/adding-snippets/' ),
]
);
diff --git a/src/php/views/partials/list-table-notices.php b/src/php/views/partials/list-table-notices.php
index c3d34561..ff6b16ea 100644
--- a/src/php/views/partials/list-table-notices.php
+++ b/src/php/views/partials/list-table-notices.php
@@ -30,7 +30,7 @@
printf( esc_html( $text ), 'CODE_SNIPPETS_SAFE_MODE', 'wp-config.php' );
?>
-
+
@@ -45,54 +45,54 @@
$result = sanitize_key( $_REQUEST['result'] );
$result_messages = [
- 'executed' => __( 'Snippet executed.', 'code-snippets' ),
- 'activated' => __( 'Snippet activated.', 'code-snippets' ),
- 'activated-multi' => __( 'Selected snippets activated.', 'code-snippets' ),
- 'deactivated' => __( 'Snippet deactivated.', 'code-snippets' ),
- 'deactivated-multi' => __( 'Selected snippets deactivated.', 'code-snippets' ),
- 'deleted' => __( 'Snippet trashed.', 'code-snippets' ),
- 'deleted-multi' => __( 'Selected snippets trashed.', 'code-snippets' ),
- 'deleted_permanently' => __( 'Snippet permanently deleted.', 'code-snippets' ),
+ 'executed' => __( 'Snippet executed.', 'code-snippets' ),
+ 'activated' => __( 'Snippet activated.', 'code-snippets' ),
+ 'activated-multi' => __( 'Selected snippets activated.', 'code-snippets' ),
+ 'deactivated' => __( 'Snippet deactivated.', 'code-snippets' ),
+ 'deactivated-multi' => __( 'Selected snippets deactivated.', 'code-snippets' ),
+ 'deleted' => __( 'Snippet trashed.', 'code-snippets' ),
+ 'deleted-multi' => __( 'Selected snippets trashed.', 'code-snippets' ),
+ 'deleted_permanently' => __( 'Snippet permanently deleted.', 'code-snippets' ),
'deleted-permanently-multi' => __( 'Selected snippets permanently deleted.', 'code-snippets' ),
- 'restored' => __( 'Snippet restored.', 'code-snippets' ),
- 'restored-multi' => __( 'Selected snippets restored.', 'code-snippets' ),
- 'cloned' => __( 'Snippet cloned.', 'code-snippets' ),
- 'cloned-multi' => __( 'Selected snippets cloned.', 'code-snippets' ),
- 'cloud-refreshed' => __( 'Synced cloud data has been successfully refreshed.', 'code-snippets' ),
+ 'restored' => __( 'Snippet restored.', 'code-snippets' ),
+ 'restored-multi' => __( 'Selected snippets restored.', 'code-snippets' ),
+ 'cloned' => __( 'Snippet cloned.', 'code-snippets' ),
+ 'cloned-multi' => __( 'Selected snippets cloned.', 'code-snippets' ),
+ 'cloud-refreshed' => __( 'Synced cloud data has been successfully refreshed.', 'code-snippets' ),
];
// Add undo link for single snippet trash action
if ( 'deleted' === $result && ! empty( $_REQUEST['ids'] ) ) {
$deleted_ids = sanitize_text_field( $_REQUEST['ids'] );
- $undo_url = wp_nonce_url(
- add_query_arg( array(
- 'action' => 'restore',
- 'ids' => $deleted_ids
- ) ),
+ $undo_url = wp_nonce_url(
+ add_query_arg(
+ [
+ 'action' => 'restore',
+ 'ids' => $deleted_ids,
+ ]
+ ),
'bulk-snippets'
);
- $result_messages['deleted'] = sprintf(
- __( 'Snippet trashed. Undo', 'code-snippets' ),
- esc_url( $undo_url )
- );
+ // translators: %s: Undo URL.
+ $undo_message = __( 'Snippet trashed. Undo', 'code-snippets' );
+ $result_messages['deleted'] = sprintf( $undo_message, esc_url( $undo_url ) );
}
// Add undo link for bulk snippet trash action
if ( 'deleted-multi' === $result && ! empty( $_REQUEST['ids'] ) ) {
$deleted_ids = sanitize_text_field( $_REQUEST['ids'] );
- $undo_url = wp_nonce_url(
- add_query_arg( array(
- 'action' => 'restore',
- 'ids' => $deleted_ids
- ) ),
+ $undo_url = wp_nonce_url(
+ add_query_arg( array(
+ 'action' => 'restore',
+ 'ids' => $deleted_ids,
+ ) ),
'bulk-snippets'
);
- $result_messages['deleted-multi'] = sprintf(
- __( 'Selected snippets trashed. Undo', 'code-snippets' ),
- esc_url( $undo_url )
- );
+ // translators: %s: Undo URL.
+ $undo_message = __( 'Selected snippets trashed. Undo', 'code-snippets' );
+ $result_messages['deleted-multi'] = sprintf( $undo_message, esc_url( $undo_url ) );
}
$result_messages = apply_filters( 'code_snippets/manage/result_messages', $result_messages );
@@ -100,7 +100,7 @@
if ( isset( $result_messages[ $result ] ) ) {
$result_kses = [
'strong' => [],
- 'a' => [
+ 'a' => [
'href' => [],
],
];
diff --git a/src/readme.txt b/src/readme.txt
index aa4c3908..2a937083 100644
--- a/src/readme.txt
+++ b/src/readme.txt
@@ -63,10 +63,10 @@ Network Activating Code Snippets through the Network Dashboard will enable a spe
== Frequently Asked Questions ==
-A full list of our Frequently Asked Questions can be found at [help.codesnippets.pro](https://help.codesnippets.pro/collection/3-faq).
+A full list of our Frequently Asked Questions can be found at [codesnippets.pro](https://codesnippets.pro/docs/faq/).
= How can I recover my site if it is crashed by a buggy snippet? =
-You can recover your site by enabling the Code Snippets safe mode feature. Instructions for how to turn it on are available here: .
+You can recover your site by enabling the Code Snippets safe mode feature. Instructions for how to turn it on are available here: .
= Will I lose my snippets if I change the theme or upgrade WordPress? =
No, the snippets are stored in the WordPress database, independent of the theme and unaffected by WordPress upgrades.
From d0e216c17693059f9db850a739d3a11fd6d288b1 Mon Sep 17 00:00:00 2001
From: Code Snippets <139164393+code-snippets-bot@users.noreply.github.com>
Date: Fri, 16 Jan 2026 12:04:19 +0200
Subject: [PATCH 22/28] fix: changelog entries
---
CHANGELOG.md | 8 ++------
src/readme.txt | 8 ++------
2 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e57a2fca..50ab5193 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,18 +1,14 @@
# Changelog
-
-
## [3.9.4] (2026-01-14)
### Added
* New import functionality to migrate snippets from file uploads with drag-and-drop interface
* Support for importing snippets from other popular plugins (Header Footer Code Manager, Insert Headers and Footers, Insert PHP Code Snippet)
-* Enhanced flat files support with improved multisite mode compatibility
+* Enhanced file based execution support with improved multisite mode compatibility
### Changed
-* Improved multisite snippet handling with correct wpAdminbase path resolution
-* Enhanced test infrastructure with multisite support and WP-CLI helpers
-* Enhanced documentation and PHPDoc comments for Snippet_Files class
+* Updated links to more recent documentation pages
### Fixed
* Fixed multisite capability checks in Plugin class
diff --git a/src/readme.txt b/src/readme.txt
index 2a937083..16514bc4 100644
--- a/src/readme.txt
+++ b/src/readme.txt
@@ -104,21 +104,17 @@ You can report security bugs found in the source code of this plugin through the
== Changelog ==
-
-
= 3.9.4 (2026-01-14) =
__Added__
* New import functionality to migrate snippets from file uploads with drag-and-drop interface
* Support for importing snippets from other popular plugins (Header Footer Code Manager, Insert Headers and Footers, Insert PHP Code Snippet)
-* Enhanced flat files support with improved multisite mode compatibility
+* Enhanced file based execution support with improved multisite mode compatibility
__Changed__
-* Improved multisite snippet handling with correct wpAdminbase path resolution
-* Enhanced test infrastructure with multisite support and WP-CLI helpers
-* Enhanced documentation and PHPDoc comments for Snippet_Files class
+* Updated links to more recent documentation pages
__Fixed__
From f6929f1e4abbdfab465c05eae1508cbad401c992 Mon Sep 17 00:00:00 2001
From: Imants
Date: Sat, 17 Jan 2026 23:45:54 +0200
Subject: [PATCH 23/28] fix: eslint @stylistic/quote-props
---
config/webpack-js.ts | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/config/webpack-js.ts b/config/webpack-js.ts
index 0ccacc43..5d50210d 100644
--- a/config/webpack-js.ts
+++ b/config/webpack-js.ts
@@ -25,13 +25,13 @@ const babelConfig = {
export const jsWebpackConfig: Configuration = {
entry: {
'admin-bar': `${SOURCE_DIR}/admin-bar.ts`,
- edit: { import: `${SOURCE_DIR}/edit.tsx`, dependOn: 'editor' },
- editor: `${SOURCE_DIR}/editor.ts`,
- import: `${SOURCE_DIR}/import.tsx`,
- manage: `${SOURCE_DIR}/manage.ts`,
- mce: `${SOURCE_DIR}/mce.ts`,
- prism: `${SOURCE_DIR}/prism.ts`,
- settings: { import: `${SOURCE_DIR}/settings.ts`, dependOn: 'editor' }
+ 'edit': { import: `${SOURCE_DIR}/edit.tsx`, dependOn: 'editor' },
+ 'editor': `${SOURCE_DIR}/editor.ts`,
+ 'import': `${SOURCE_DIR}/import.tsx`,
+ 'manage': `${SOURCE_DIR}/manage.ts`,
+ 'mce': `${SOURCE_DIR}/mce.ts`,
+ 'prism': `${SOURCE_DIR}/prism.ts`,
+ 'settings': { import: `${SOURCE_DIR}/settings.ts`, dependOn: 'editor' }
},
output: {
path: join(resolve(__dirname), '..', DEST_DIR),
From b7e5a74b12186c28ec22a3d72135688dd3f98b73 Mon Sep 17 00:00:00 2001
From: Imants
Date: Sat, 17 Jan 2026 23:50:48 +0200
Subject: [PATCH 24/28] fix: codestyle clean up and delint
---
.../rest-api/class-snippets-rest-controller.php | 16 ++++++++--------
src/php/settings/settings-fields.php | 3 ---
2 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/src/php/rest-api/class-snippets-rest-controller.php b/src/php/rest-api/class-snippets-rest-controller.php
index dac50a87..f8478cb8 100644
--- a/src/php/rest-api/class-snippets-rest-controller.php
+++ b/src/php/rest-api/class-snippets-rest-controller.php
@@ -661,14 +661,14 @@ public function get_item_schema(): array {
'description' => esc_html__( 'Descriptive title for the snippet.', 'code-snippets' ),
'type' => 'string',
],
- 'desc' => [
- 'description' => esc_html__( 'Descriptive text associated with snippet.', 'code-snippets' ),
- 'type' => 'string',
- ],
- 'code' => [
- 'description' => esc_html__( 'Executable snippet code.', 'code-snippets' ),
- 'type' => 'string',
- ],
+ 'desc' => [
+ 'description' => esc_html__( 'Descriptive text associated with snippet.', 'code-snippets' ),
+ 'type' => 'string',
+ ],
+ 'code' => [
+ 'description' => esc_html__( 'Executable snippet code.', 'code-snippets' ),
+ 'type' => 'string',
+ ],
'tags' => [
'description' => esc_html__( 'List of tag categories the snippet belongs to.', 'code-snippets' ),
'type' => 'array',
diff --git a/src/php/settings/settings-fields.php b/src/php/settings/settings-fields.php
index 5802adfc..06033d14 100644
--- a/src/php/settings/settings-fields.php
+++ b/src/php/settings/settings-fields.php
@@ -148,7 +148,6 @@ function get_settings_fields(): array {
'modified-asc' => __( 'Modified (oldest first)', 'code-snippets' ),
],
],
-
'disable_prism' => [
'name' => __( 'Disable Syntax Highlighter', 'code-snippets' ),
'type' => 'checkbox',
@@ -262,14 +261,12 @@ function get_settings_fields(): array {
$fields = apply_filters( 'code_snippets_settings_fields', $fields );
- // Add Admin Bar settings after plugin-provided fields (e.g., file-based execution).
$fields['general']['enable_admin_bar'] = [
'name' => __( 'Enable Admin Bar Menu', 'code-snippets' ),
'type' => 'checkbox',
'label' => __( 'Show a Snippets menu in the admin bar for quick access to snippets.', 'code-snippets' ),
];
- // Only show per-page control if admin bar menu is enabled in settings.
if ( get_setting( 'general', 'enable_admin_bar' ) ) {
$fields['general']['admin_bar_snippet_limit'] = [
'name' => __( 'Admin Bar Snippets Per Page', 'code-snippets' ),
From be4ad85c1e4e11ed22181cb5d5bd85dfeb629b0a Mon Sep 17 00:00:00 2001
From: Imants
Date: Thu, 22 Jan 2026 13:58:57 +0200
Subject: [PATCH 25/28] fix: simplify snippet filtering logic in get_items
method ref:
https://github.com/codesnippetspro/code-snippets/pull/328#discussion_r2711137193
---
.../class-snippets-rest-controller.php | 41 +++++++------------
1 file changed, 14 insertions(+), 27 deletions(-)
diff --git a/src/php/rest-api/class-snippets-rest-controller.php b/src/php/rest-api/class-snippets-rest-controller.php
index f8478cb8..0c54efde 100644
--- a/src/php/rest-api/class-snippets-rest-controller.php
+++ b/src/php/rest-api/class-snippets-rest-controller.php
@@ -238,39 +238,26 @@ public function get_items( $request ): WP_REST_Response {
$status = sanitize_key( (string) $request->get_param( 'status' ) );
- if ( in_array( $status, [ 'active', 'inactive' ], true ) ) {
- $all_snippets = array_filter(
- $all_snippets,
- static function ( Snippet $snippet ): bool {
- return ! $snippet->is_trashed();
- }
- );
- }
-
$exclude_types = $request->get_param( 'exclude_types' );
$exclude_types = is_array( $exclude_types ) ? array_map( 'sanitize_key', $exclude_types ) : [];
- if ( $exclude_types ) {
+ if ( $exclude_types || 'all' !== $status ) {
$all_snippets = array_filter(
$all_snippets,
- static function ( Snippet $snippet ) use ( $exclude_types ): bool {
- return ! in_array( $snippet->type, $exclude_types, true );
- }
- );
- }
+ static function ( Snippet $snippet ) use ( $exclude_types, $status ): bool {
+ if ( $exclude_types && in_array( $snippet->type, $exclude_types, true ) ) {
+ return false;
+ }
- if ( 'active' === $status ) {
- $all_snippets = array_filter(
- $all_snippets,
- static function ( Snippet $snippet ): bool {
- return $snippet->active;
- }
- );
- } elseif ( 'inactive' === $status ) {
- $all_snippets = array_filter(
- $all_snippets,
- static function ( Snippet $snippet ): bool {
- return ! $snippet->active;
+ if ( 'active' === $status ) {
+ return ! $snippet->is_trashed() && (bool) $snippet->active;
+ }
+
+ if ( 'inactive' === $status ) {
+ return ! $snippet->is_trashed() && ! $snippet->active;
+ }
+
+ return true;
}
);
}
From 1641d7b1a5d5468b7602ab9cbcbc3fcfad916f85 Mon Sep 17 00:00:00 2001
From: Imants
Date: Thu, 22 Jan 2026 14:06:09 +0200
Subject: [PATCH 26/28] fix: remove `require_once` to rely on composer
autoloader ref:
https://github.com/codesnippetspro/code-snippets/pull/328#discussion_r2711139828
---
src/php/class-plugin.php | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/php/class-plugin.php b/src/php/class-plugin.php
index eb8f9d96..05053e30 100644
--- a/src/php/class-plugin.php
+++ b/src/php/class-plugin.php
@@ -129,9 +129,7 @@ public function load_plugin() {
$this->evaluate_functions = new Evaluate_Functions( $this->db );
// Admin bar integration.
- require_once $includes_path . '/class-admin-bar.php';
$this->admin_bar = new Admin_Bar();
- $this->admin_bar->register_hooks();
// CodeMirror editor functions.
require_once $includes_path . '/editor.php';
From 87da1309cc16b976bf56c06e5b85250f7151704f Mon Sep 17 00:00:00 2001
From: Imants
Date: Thu, 22 Jan 2026 14:07:15 +0200
Subject: [PATCH 27/28] fix: update `register_hooks` to class constructor to
register WordPress hooks directly on load ref:
https://github.com/codesnippetspro/code-snippets/pull/328#discussion_r2711141243
---
src/php/class-admin-bar.php | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/src/php/class-admin-bar.php b/src/php/class-admin-bar.php
index 706a75e6..14792398 100644
--- a/src/php/class-admin-bar.php
+++ b/src/php/class-admin-bar.php
@@ -55,11 +55,9 @@ class Admin_Bar {
private const STYLE_HANDLE = 'code-snippets-admin-bar';
/**
- * Register WordPress hooks.
- *
- * @return void
+ * Class constructor.
*/
- public function register_hooks(): void {
+ public function __construct() {
add_action( 'admin_bar_menu', [ $this, 'register_nodes' ], 80 );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
From 4e333b4dfef97079fada96b8b1b1289c7361837f Mon Sep 17 00:00:00 2001
From: Imants
Date: Thu, 22 Jan 2026 19:40:12 +0200
Subject: [PATCH 28/28] fix: export types and interfaces, refactor
`getTypeFromScope` to switch and fix lint issues
---
src/js/admin-bar.ts | 130 ++++++++++++++++++++++++++++++--------------
1 file changed, 88 insertions(+), 42 deletions(-)
diff --git a/src/js/admin-bar.ts b/src/js/admin-bar.ts
index 29e9e309..21bcde53 100644
--- a/src/js/admin-bar.ts
+++ b/src/js/admin-bar.ts
@@ -1,13 +1,13 @@
-type PaginationStatus = 'active' | 'inactive'
-type PaginationAction = 'first' | 'prev' | 'next' | 'last'
+export type PaginationStatus = 'active' | 'inactive'
+export type PaginationAction = 'first' | 'prev' | 'next' | 'last'
-type SnippetResponseItem = {
+export interface SnippetResponseItem {
id: number
scope: string
name?: string
}
-type AdminBarConfig = {
+export interface AdminBarConfig {
restUrl: string
nonce: string
perPage: number
@@ -21,17 +21,22 @@ type AdminBarConfig = {
declare const CODE_SNIPPETS_ADMIN_BAR: AdminBarConfig | undefined
-const config = typeof CODE_SNIPPETS_ADMIN_BAR !== 'undefined' ? CODE_SNIPPETS_ADMIN_BAR : undefined
+const config = 'undefined' === typeof CODE_SNIPPETS_ADMIN_BAR ? undefined : CODE_SNIPPETS_ADMIN_BAR
const getMenuNode = (status: PaginationStatus): HTMLElement | null => {
- if (!config) return null
- const nodeId = status === 'active' ? config.activeNodeId : config.inactiveNodeId
+ if (!config) {
+ return null
+ }
+
+ const nodeId = 'active' === status ? config.activeNodeId : config.inactiveNodeId
return document.getElementById(nodeId)
}
const getPaginationControls = (status: PaginationStatus): HTMLElement | null => {
const menuNode = getMenuNode(status)
- if (!menuNode) return null
+ if (!menuNode) {
+ return null
+ }
return menuNode.querySelector(`.code-snippets-pagination-controls[data-status="${status}"]`)
}
@@ -41,8 +46,8 @@ const getPaginationState = (controls: HTMLElement): { page: number; totalPages:
const totalPages = Number.parseInt(controls.dataset.totalPages ?? '1', 10)
return {
- page: Number.isFinite(page) && page > 0 ? page : 1,
- totalPages: Number.isFinite(totalPages) && totalPages > 0 ? totalPages : 1
+ page: Number.isFinite(page) && 0 < page ? page : 1,
+ totalPages: Number.isFinite(totalPages) && 0 < totalPages ? totalPages : 1
}
}
@@ -51,7 +56,9 @@ const setLoading = (controls: HTMLElement, loading: boolean) => {
}
const buildRequestUrl = (status: PaginationStatus, page: number): string => {
- if (!config) return ''
+ if (!config) {
+ return ''
+ }
const url = new URL(config.restUrl)
url.searchParams.set('status', status)
@@ -64,7 +71,7 @@ const buildRequestUrl = (status: PaginationStatus, page: number): string => {
url.searchParams.set('network', '1')
}
- for (const excluded of config.excludeTypes ?? []) {
+ for (const excluded of config.excludeTypes) {
url.searchParams.append('exclude_types[]', excluded)
}
@@ -90,13 +97,15 @@ const fetchSnippetsPage = async (status: PaginationStatus, page: number) => {
const totalPagesHeader = response.headers.get('X-WP-TotalPages') ?? '1'
const totalPages = Number.parseInt(totalPagesHeader, 10) || 1
- const snippets = (await response.json()) as SnippetResponseItem[]
+ const snippets = await response.json()
return { snippets, totalPages }
}
const buildEditUrl = (snippetId: number): string => {
- if (!config) return '#'
+ if (!config) {
+ return '#'
+ }
try {
const url = new URL(config.editUrlBase, window.location.href)
@@ -108,23 +117,36 @@ const buildEditUrl = (snippetId: number): string => {
}
const buildSnippetPlaceholder = (snippetId: number): string => {
- if (!config?.snippetPlaceholder) return `Snippet #${snippetId}`
+ if (!config?.snippetPlaceholder) {
+ return `Snippet #${snippetId}`
+ }
- return config.snippetPlaceholder.replace(/%(\d+\$)?d/, String(snippetId))
+ return config.snippetPlaceholder.replace(/%(?:\d+\$)?d/, String(snippetId))
}
const getTypeFromScope = (scope: string): string => {
- if (scope.endsWith('-css')) return 'css'
- if (scope.endsWith('-js')) return 'js'
- if (scope.endsWith('content')) return 'html'
- if (scope === 'condition') return 'cond'
- return 'php'
+ switch (true) {
+ case scope.endsWith('-css'):
+ return 'css'
+
+ case scope.endsWith('-js'):
+ return 'js'
+
+ case scope.endsWith('content'):
+ return 'html'
+
+ case 'condition' === scope:
+ return 'cond'
+
+ default:
+ return 'php'
+ }
}
const formatSnippetTitle = (snippet: SnippetResponseItem): string => {
const typeLabel = getTypeFromScope(snippet.scope).toUpperCase()
const name = snippet.name?.trim()
- const title = name ? name : buildSnippetPlaceholder(snippet.id)
+ const title = ('' === name ? undefined : name) ?? buildSnippetPlaceholder(snippet.id)
return `(${typeLabel}) ${title}`
}
@@ -137,7 +159,7 @@ const updatePaginationControls = (controls: HTMLElement, page: number, totalPage
pageLabel.textContent = pageLabel.textContent?.replace(/\(\d+\/\d+\)/, `(${page}/${totalPages})`) ?? pageLabel.textContent
}
- const disableFirstPrev = page <= 1
+ const disableFirstPrev = 1 >= page
const disableNextLast = page >= totalPages
const setDisabled = (action: PaginationAction, disabled: boolean) => {
@@ -161,7 +183,7 @@ const updatePaginationControls = (controls: HTMLElement, page: number, totalPage
const buildHref = (targetPage: number) => {
const url = new URL(baseHref)
- if (targetPage <= 1) {
+ if (1 >= targetPage) {
url.searchParams.delete(queryArg)
} else {
url.searchParams.set(queryArg, String(targetPage))
@@ -174,30 +196,42 @@ const updatePaginationControls = (controls: HTMLElement, page: number, totalPage
controls.querySelector(`a[data-action="${action}"]`)
const first = getLink('first')
- if (first) first.href = buildHref(1)
+ if (first) {
+ first.href = buildHref(1)
+ }
const prev = getLink('prev')
- if (prev) prev.href = buildHref(Math.max(1, page - 1))
+ if (prev) {
+ prev.href = buildHref(Math.max(1, page - 1))
+ }
const next = getLink('next')
- if (next) next.href = buildHref(Math.min(totalPages, page + 1))
+ if (next) {
+ next.href = buildHref(Math.min(totalPages, page + 1))
+ }
const last = getLink('last')
- if (last) last.href = buildHref(totalPages)
+ if (last) {
+ last.href = buildHref(totalPages)
+ }
}
}
}
const replaceSnippetItems = (status: PaginationStatus, snippets: SnippetResponseItem[]) => {
const menuNode = getMenuNode(status)
- if (!menuNode) return
+ if (!menuNode) {
+ return
+ }
const subMenu = menuNode.querySelector('ul.ab-submenu')
- if (!subMenu) return
+ if (!subMenu) {
+ return
+ }
subMenu.querySelectorAll('li.code-snippets-snippet-item').forEach(node => node.remove())
- const insertAfterId = status === 'active'
+ const insertAfterId = 'active' === status
? 'wp-admin-bar-code-snippets-active-pagination'
: 'wp-admin-bar-code-snippets-inactive-pagination'
@@ -227,7 +261,9 @@ const replaceSnippetItems = (status: PaginationStatus, snippets: SnippetResponse
const navigateToPage = async (status: PaginationStatus, targetPage: number) => {
const controls = getPaginationControls(status)
- if (!controls) return
+ if (!controls) {
+ return
+ }
const { totalPages: currentTotalPages } = getPaginationState(controls)
const page = Math.max(1, Math.min(targetPage, currentTotalPages))
@@ -239,7 +275,6 @@ const navigateToPage = async (status: PaginationStatus, targetPage: number) => {
updatePaginationControls(controls, page, totalPages)
replaceSnippetItems(status, snippets)
} catch (error) {
- // eslint-disable-next-line no-console
console.error(error)
} finally {
setLoading(controls, false)
@@ -247,20 +282,31 @@ const navigateToPage = async (status: PaginationStatus, targetPage: number) => {
}
const handlePaginationClick = (event: MouseEvent) => {
- const target = event.target as Element | null
- if (!target) return
+ const target = event.target
+ if (!target) {
+ return
+ }
const link = target.closest('.code-snippets-pagination-controls a[data-action]')
- if (!link) return
+ if (!link) {
+ return
+ }
const controls = link.closest('.code-snippets-pagination-controls')
- if (!controls) return
- if (controls.dataset.loading === 'true') return
+ if (!controls) {
+ return
+ }
- const status = controls.dataset.status as PaginationStatus | undefined
- const action = link.dataset.action as PaginationAction | undefined
+ if ('true' === controls.dataset.loading) {
+ return
+ }
+
+ const status = controls.dataset.status
+ const action = link.dataset.action
- if (!status || !action) return
+ if (!status || !action) {
+ return
+ }
event.preventDefault()
event.stopPropagation()
@@ -284,7 +330,7 @@ const handlePaginationClick = (event: MouseEvent) => {
break
}
- if (targetPage === page || targetPage < 1 || targetPage > totalPages) {
+ if (targetPage === page || 1 > targetPage || targetPage > totalPages) {
return
}