Skip to content

Commit fdf0ecb

Browse files
committed
refactor: Replace hardcoded 'FreemKit' references with dynamic prefix in Tom Select and remove unused taxonomy suggest functionality
- Use dynamic prefix for Tom Select localization object name and data attributes - Remove taxonomy-suggest.js and related registration/enqueue code - Delete unused tags_search AJAX method from Options_API - Remove taxonomy search defaults from Settings_API enqueue method
1 parent e0c3e69 commit fdf0ecb

6 files changed

Lines changed: 5 additions & 189 deletions

File tree

includes/admin/class-settings-wizard.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,9 @@ public function enqueue_wizard_tom_select_data( string $hook ): void {
403403

404404
wp_localize_script(
405405
'wz-' . $this->prefix . '-tom-select-init',
406-
'FreemKitTomSelectSettings',
406+
"{$this->prefix}TomSelectSettings",
407407
array(
408-
'prefix' => 'FreemKit',
408+
'prefix' => $this->prefix,
409409
'nonce' => wp_create_nonce( $this->prefix . '_kit_search' ),
410410
'action' => $this->prefix . '_kit_search',
411411
'endpoint' => '',

includes/admin/class-settings.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ public static function settings_subscribers(): array {
514514
*/
515515
public static function get_kit_search_field_attributes( string $endpoint, array $ts_config = array() ): array {
516516
$attributes = array(
517-
'data-wp-prefix' => 'FreemKit',
517+
'data-wp-prefix' => self::$prefix,
518518
'data-wp-action' => self::$prefix . '_kit_search',
519519
'data-wp-nonce' => wp_create_nonce( self::$prefix . '_kit_search' ),
520520
'data-wp-endpoint' => $endpoint,
@@ -691,9 +691,9 @@ public function admin_enqueue_scripts( $hook ) {
691691
// Tom Select variables.
692692
wp_localize_script(
693693
'wz-' . self::$prefix . '-tom-select-init',
694-
'FreemKitTomSelectSettings',
694+
self::$prefix . 'TomSelectSettings',
695695
array(
696-
'prefix' => 'FreemKit',
696+
'prefix' => self::$prefix,
697697
'nonce' => wp_create_nonce( self::$prefix . '_kit_search' ),
698698
'action' => self::$prefix . '_kit_search',
699699
'endpoint' => '',

includes/admin/settings/class-settings-api.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -494,13 +494,6 @@ public function admin_enqueue_scripts( $hook ) {
494494
self::VERSION,
495495
true
496496
);
497-
wp_register_script(
498-
'wz-' . $this->prefix . '-taxonomy-suggest',
499-
plugins_url( 'js/taxonomy-suggest' . $minimize . '.js', __FILE__ ),
500-
array( 'jquery' ),
501-
self::VERSION,
502-
true
503-
);
504497
wp_register_script(
505498
'wz-' . $this->prefix . '-media-selector',
506499
plugins_url( 'js/media-selector' . $minimize . '.js', __FILE__ ),
@@ -583,16 +576,13 @@ public static function enqueue_scripts_styles( $prefix, $args = array() ) {
583576

584577
wp_enqueue_script( "wz-{$prefix}-admin" );
585578
wp_enqueue_script( "wz-{$prefix}-codemirror" );
586-
wp_enqueue_script( "wz-{$prefix}-taxonomy-suggest" );
587579
wp_enqueue_script( "wz-{$prefix}-media-selector" );
588580

589581
// Enqueue Tom Select.
590582
wp_enqueue_style( "wz-{$prefix}-tom-select" );
591583
wp_enqueue_script( "wz-{$prefix}-tom-select" );
592584

593585
$defaults = array(
594-
'action' => $prefix . '_taxonomy_search_tom_select',
595-
'nonce' => wp_create_nonce( $prefix . '_taxonomy_search_tom_select' ),
596586
'endpoint' => 'category',
597587
'strings' => array(
598588
'no_results' => 'No results found for "%s"',

includes/admin/settings/js/taxonomy-suggest.js

Lines changed: 0 additions & 108 deletions
This file was deleted.

includes/admin/settings/js/taxonomy-suggest.min.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

includes/class-options-api.php

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -328,69 +328,4 @@ public static function decrypt_api_key( $encrypted_key ) {
328328

329329
return $encrypted_key;
330330
}
331-
332-
333-
/**
334-
* Function to add an action to search for tags using Ajax.
335-
*
336-
* @since 1.0.0
337-
*
338-
* @return void
339-
*/
340-
public static function tags_search() {
341-
if ( ! isset( $_REQUEST['tax'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
342-
wp_die();
343-
}
344-
345-
$taxonomy = sanitize_key( $_REQUEST['tax'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
346-
$tax = get_taxonomy( $taxonomy );
347-
if ( ! empty( $taxonomy ) ) {
348-
$tax = get_taxonomy( $taxonomy );
349-
if ( ! $tax ) {
350-
wp_die();
351-
}
352-
353-
if ( ! current_user_can( $tax->cap->assign_terms ) ) {
354-
wp_die();
355-
}
356-
}
357-
358-
$s = isset( $_REQUEST['q'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['q'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
359-
360-
$comma = _x( ',', 'tag delimiter' );
361-
if ( ',' !== $comma ) {
362-
$s = str_replace( $comma, ',', $s );
363-
}
364-
if ( false !== strpos( $s, ',' ) ) {
365-
$s = explode( ',', $s );
366-
$s = $s[ count( $s ) - 1 ];
367-
}
368-
$s = trim( $s );
369-
370-
/** This filter has been defined in /wp-admin/includes/ajax-actions.php */
371-
$term_search_min_chars = (int) apply_filters( 'term_search_min_chars', 2, $tax, $s );
372-
373-
/*
374-
* Require $term_search_min_chars chars for matching (default: 2)
375-
* ensure it's a non-negative, non-zero integer.
376-
*/
377-
if ( ( 0 === $term_search_min_chars ) || ( strlen( $s ) < $term_search_min_chars ) ) {
378-
wp_die();
379-
}
380-
381-
$results = get_terms(
382-
array(
383-
'taxonomy' => $taxonomy,
384-
'name__like' => $s,
385-
'fields' => 'names',
386-
'hide_empty' => false,
387-
)
388-
);
389-
390-
echo wp_json_encode( $results );
391-
wp_die();
392-
}
393331
}
394-
395-
// Add the tags search AJAX action.
396-
add_action( 'wp_ajax_' . Options_API::FILTER_PREFIX . '_tags_search', array( Options_API::class, 'tags_search' ) );

0 commit comments

Comments
 (0)