PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 All 508 releases
jetpack / jetpack_vendor / automattic / jetpack-search / src / search-blocks / class-overlay-template.php

class-overlay-template.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3, at jetpack_vendor/automattic/jetpack-search/src/search-blocks/class-overlay-template.php

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