['name' => __('Finders', 'facetcore'), 'singular_name' => __('Finder', 'facetcore'), 'menu_name' => __('FacetCore', 'facetcore'), 'add_new' => __('Add New', 'facetcore'), 'add_new_item' => __('Add Finder', 'facetcore'), 'edit_item' => __('Edit Finder', 'facetcore'), 'all_items' => __('Finders', 'facetcore'), 'search_items' => __('Search Finders', 'facetcore'), 'not_found' => __('No finders yet. Add your first Finder.', 'facetcore')],
'public' => false, 'show_ui' => true, 'show_in_menu' => true, 'show_in_rest' => false,
'supports' => ['title'], 'menu_icon' => 'dashicons-filter', 'map_meta_cap' => false,
'capabilities' => array_fill_keys(['edit_post', 'read_post', 'delete_post', 'edit_posts', 'edit_others_posts', 'publish_posts', 'read_private_posts', 'delete_posts', 'delete_private_posts', 'delete_published_posts', 'delete_others_posts', 'edit_private_posts', 'edit_published_posts', 'create_posts'], 'manage_woocommerce'),
]);
}
public function assets(): void
{
if (!get_current_screen() || get_current_screen()->post_type !== TableConfiguration::TYPE) { return; }
wp_enqueue_script('facetcore-admin', plugins_url('assets/admin.js', FACETCORE_FILE), [], FACETCORE_VERSION, true);
wp_localize_script('facetcore-admin', 'facetcoreAdminL10n', [
'noColumns' => __('No columns selected', 'facetcore'),
'gridDefault' => __('Title, Image & Price (default)', 'facetcore'),
'sku' => __('SKU', 'facetcore'),
/* translators: %1$s: new position number in the list. */
'moved' => __('Moved to position %1$s.', 'facetcore'),
'copied' => __('Copied!', 'facetcore'),
'copiedStatus' => __('Copied to clipboard.', 'facetcore'),
'copyManually' => __('Press Ctrl+C / Cmd+C to copy.', 'facetcore'),
/* translators: %1$s: maximum number of attributes. */
'limitStatus' => __('Choose up to %1$s attributes.', 'facetcore'),
/* translators: %1$s: maximum number of attributes. */
'limitAlert' => __('Choose up to %1$s attributes for this section.', 'facetcore'),
]);
wp_enqueue_style('facetcore-admin', plugins_url('assets/admin.css', FACETCORE_FILE), [], FACETCORE_VERSION);
do_action('facetcore_admin_assets');
}
public function boxes(): void
{
add_meta_box('facetcore-config', __('Finder configuration', 'facetcore'), [$this, 'render'], TableConfiguration::TYPE, 'normal', 'high');
add_meta_box('facetcore-shortcode', __('Shortcode', 'facetcore'), [$this, 'shortcode'], TableConfiguration::TYPE, 'side', 'high');
}
public function shortcode(\WP_Post $post): void
{
if ($post->post_status !== 'publish') {
echo '
' . esc_html__('Publish this finder to use its shortcode on a page.', 'facetcore') . '
';
return;
}
echo '
';
echo '
' . esc_html__('Paste this shortcode into any WordPress page or post.', 'facetcore') . '
';
$this->copyControl($post->ID);
echo '
';
}
private function copyControl(int $id): void
{
echo '';
echo ' ';
echo '';
echo '';
echo '';
}
public function columns(array $columns): array
{
return ['cb' => $columns['cb'], 'title' => __('Name', 'facetcore'), 'facetcore_shortcode' => __('Shortcode', 'facetcore'), 'facetcore_status' => __('Status', 'facetcore'), 'date' => __('Date', 'facetcore')];
}
public function column(string $column, int $id): void
{
if ($column === 'facetcore_shortcode' && get_post_status($id) === 'publish') { $this->copyControl($id); }
if ($column === 'facetcore_status') { echo esc_html(get_post_status_object(get_post_status($id))->label); }
}
public function render(\WP_Post $post): void
{
$config = TableConfiguration::get($post->ID, false) ?? TableConfiguration::defaults();
do_action('facetcore_admin_finder', $post);
wp_nonce_field('facetcore_config_' . $post->ID, 'facetcore_config_nonce');
echo '
';
if (TableConfiguration::missing($config)) {
echo '
' . esc_html__('Some selected attributes no longer exist. They are marked below and safely skipped on the frontend. Uncheck them to remove them.', 'facetcore') . '
' . esc_html__('Displays product counts next to each filter value (e.g. "DDR4 (16)").', 'facetcore') . '
';
echo '
';
echo '
';
echo '
';
echo '
';
echo '';
echo '
' . esc_html__('Hides filter options that have zero matching products. When unchecked, zero-count options remain visible but disabled.', 'facetcore') . '