Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
36.36% |
4 / 11 |
|
20.00% |
1 / 5 |
CRAP | |
0.00% |
0 / 1 |
| Overlay_Template | |
36.36% |
4 / 11 |
|
20.00% |
1 / 5 |
15.28 | |
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 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| 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 experimental block-template overlay. |
| 4 | * |
| 5 | * @package automattic/jetpack-search |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Search; |
| 9 | |
| 10 | /** |
| 11 | * Theme-agnostic customization surface for the Search overlay template via |
| 12 | * post.php. Falls back to `templates/jetpack-search-overlay.html` when the |
| 13 | * singleton doesn't exist. Lifecycle lives on {@see Singleton_Template_Cpt}. |
| 14 | * |
| 15 | * Gated behind both `jetpack_search_blocks_enabled` AND |
| 16 | * `jetpack_search_overlay_block_template_enabled`. |
| 17 | */ |
| 18 | class Overlay_Template extends Singleton_Template_Cpt { |
| 19 | |
| 20 | const POST_TYPE = 'jp_search_overlay'; |
| 21 | const REST_BASE = 'jetpack-search-overlay'; |
| 22 | const OPTION_POST_ID = 'jetpack_search_overlay_template_post_id'; |
| 23 | const EDITOR_REQUEST_KEY = 'jetpack_search_open_overlay_editor'; |
| 24 | const EDITOR_NONCE = 'jetpack_search_overlay_editor'; |
| 25 | const SEED_META_KEY = '_jetpack_search_overlay_seeded_version'; |
| 26 | |
| 27 | /** |
| 28 | * Subclass hook — CPT labels. |
| 29 | * |
| 30 | * @return array{name:string,singular_name:string} |
| 31 | */ |
| 32 | protected static function labels(): array { |
| 33 | return array( |
| 34 | 'name' => __( 'Search overlay template', 'jetpack-search-pkg' ), |
| 35 | 'singular_name' => __( 'Search overlay template', 'jetpack-search-pkg' ), |
| 36 | ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Subclass hook — default post title. |
| 41 | * |
| 42 | * @return string |
| 43 | */ |
| 44 | protected static function post_title(): string { |
| 45 | return __( 'Jetpack Search overlay', 'jetpack-search-pkg' ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Subclass hook — seed `post_content`. Reads the bundled file directly, |
| 50 | * not via `Search_Blocks::get_overlay_template_content()` (that would |
| 51 | * loop back through this class's customization check). |
| 52 | * |
| 53 | * @return string |
| 54 | */ |
| 55 | protected static function read_seed_content(): string { |
| 56 | $path = __DIR__ . '/templates/jetpack-search-overlay.html'; |
| 57 | if ( ! is_readable( $path ) ) { |
| 58 | return ''; |
| 59 | } |
| 60 | // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- local, bundled template. |
| 61 | return (string) file_get_contents( $path ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Subclass hook — forbidden-response copy. |
| 66 | * |
| 67 | * @return string |
| 68 | */ |
| 69 | protected static function forbidden_message(): string { |
| 70 | return __( 'You do not have permission to customize the Search overlay.', 'jetpack-search-pkg' ); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Subclass hook — create-failure copy. |
| 75 | * |
| 76 | * @return string |
| 77 | */ |
| 78 | protected static function create_failure_message(): string { |
| 79 | return __( 'Could not create the Search overlay template.', 'jetpack-search-pkg' ); |
| 80 | } |
| 81 | } |