Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
50.00% covered (danger)
50.00%
5 / 10
20.00% covered (danger)
20.00%
1 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
Product_Search_Template
50.00% covered (danger)
50.00%
4 / 8
20.00% covered (danger)
20.00%
1 / 5
8.12
0.00% covered (danger)
0.00%
0 / 1
 labels
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 post_title
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 read_seed_content
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 forbidden_message
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 create_failure_message
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Singleton CPT + lifecycle for the classic-theme product-search template editor.
4 *
5 * @package automattic/jetpack-search
6 */
7
8namespace Automattic\Jetpack\Search;
9
10if ( ! defined( 'ABSPATH' ) ) {
11    exit( 0 );
12}
13
14/**
15 * Theme-agnostic customization surface for the classic-theme product-search
16 * template via post.php — the WooCommerce-product counterpart of
17 * {@see Search_Template}. Lifecycle lives on {@see Singleton_Template_Cpt}.
18 * Seed mirrors what `Search_Blocks::get_classic_theme_product_search_body()`
19 * renders so the editor and the front end stay in lockstep.
20 */
21class Product_Search_Template extends Singleton_Template_Cpt {
22
23    const POST_TYPE          = 'jp_product_search';
24    const REST_BASE          = 'jetpack-product-search-template';
25    const OPTION_POST_ID     = 'jetpack_product_search_template_post_id';
26    const EDITOR_REQUEST_KEY = 'jetpack_search_open_product_template_editor';
27    const EDITOR_NONCE       = 'jetpack_search_product_template_editor';
28    const SEED_META_KEY      = '_jetpack_product_search_template_seeded_version';
29
30    /**
31     * Subclass hook — CPT labels.
32     *
33     * @return array{name:string,singular_name:string}
34     */
35    protected static function labels(): array {
36        return array(
37            'name'          => __( 'Product search template', 'jetpack-search-pkg' ),
38            'singular_name' => __( 'Product search template', 'jetpack-search-pkg' ),
39        );
40    }
41
42    /**
43     * Subclass hook — default post title.
44     *
45     * @return string
46     */
47    protected static function post_title(): string {
48        return __( 'Jetpack Search product template', 'jetpack-search-pkg' );
49    }
50
51    /**
52     * Subclass hook — seed `post_content`. `ensure_post_exists()` only runs
53     * when no customization exists, so the body source resolves to the
54     * bundled (template-part-stripped) markup.
55     *
56     * @return string
57     */
58    protected static function read_seed_content(): string {
59        return Search_Blocks::get_classic_theme_product_search_body();
60    }
61
62    /**
63     * Subclass hook — forbidden-response copy.
64     *
65     * @return string
66     */
67    protected static function forbidden_message(): string {
68        return __( 'You do not have permission to customize the product search template.', 'jetpack-search-pkg' );
69    }
70
71    /**
72     * Subclass hook — create-failure copy.
73     *
74     * @return string
75     */
76    protected static function create_failure_message(): string {
77        return __( 'Could not create the product search template.', 'jetpack-search-pkg' );
78    }
79}