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-search-template.php

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

80 lines 2.2 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 classic-theme search template editor.
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 classic-theme search template
16 * via post.php — the equivalent of the Site Editor entry block themes get.
17 * Lifecycle lives on {@see Singleton_Template_Cpt}. Seed mirrors what
18 * `Search_Blocks::get_classic_theme_search_body()` renders so the editor and
19 * the front end stay in lockstep.
20 */
21 class Search_Template extends Singleton_Template_Cpt {
22
23 const POST_TYPE = 'jp_search_template';
24 const REST_BASE = 'jetpack-search-template';
25 const OPTION_POST_ID = 'jetpack_search_template_post_id';
26 const EDITOR_REQUEST_KEY = 'jetpack_search_open_template_editor';
27 const EDITOR_NONCE = 'jetpack_search_template_editor';
28 const SEED_META_KEY = '_jetpack_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' => __( 'Search template', 'jetpack-search-pkg' ),
38 'singular_name' => __( '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 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_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 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 Search template.', 'jetpack-search-pkg' );
78 }
79 }
80