★★★★★ 5 Stars?'; $links[] = $rating_link; } return $links; } /** * Enqueue admin JS when on supported screens. * * @param string $hook Current admin page hook. * @return void */ public function enqueue_admin_assets( $hook ) { $supported = array( 'post.php', 'post-new.php', 'edit.php' ); if ( ! in_array( $hook, $supported, true ) ) { return; } wp_register_script( 'pcf-admin', APCF_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery' ), (string) APCF_VERSION, true ); $settings = $this->get_plugin_settings(); // Backward compatibility: old JS expects fc_plugin. wp_localize_script( 'pcf-admin', 'fc_plugin', array( 'placeholder' => isset( $settings['placeholderFinal'] ) ? $settings['placeholderFinal'] : 'Filter Categories', ) ); // New JS object (current). wp_localize_script( 'pcf-admin', 'pcfPlugin', $settings ); wp_enqueue_script( 'pcf-admin' ); } /** * Localize after screen is set to correctly detect base. * * @return void */ public function maybe_localize_screen() { // No-op, kept for backward compatibility with older hooks. } /** * Build localized settings. * * @return array */ public function get_plugin_settings() { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; $base = $screen ? (string) $screen->base : ''; // Provide both template and final string to avoid %s issues. $placeholder_template = __( 'Filter %s', 'admin-category-filter' ); // Default to "Categories" unless we can infer better. $taxonomy_label = __( 'Categories', 'admin-category-filter' ); // If we are on a post type screen, try to infer the taxonomy label. if ( $screen && ! empty( $screen->post_type ) ) { // WooCommerce products typically use "product_cat". $tax = ( 'product' === $screen->post_type ) ? 'product_cat' : 'category'; $taxonomy_obj = get_taxonomy( $tax ); if ( $taxonomy_obj && ! empty( $taxonomy_obj->labels->singular_name ) ) { $taxonomy_label = (string) $taxonomy_obj->labels->singular_name; } } $placeholder_final = sprintf( $placeholder_template, $taxonomy_label ); return array( 'placeholder' => $placeholder_template, 'placeholderFinal' => $placeholder_final, 'screenName' => $base, 'enableGutenberg' => (bool) apply_filters( 'pcf_enable_gutenberg_filter', true ), ); } } }