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