PluginProbe ʕ •ᴥ•ʔ
Starter Sites & Templates by Neve / 1.4.1
Starter Sites & Templates by Neve v1.4.1
1.4.1 1.4.0 1.3.0 1.2.29 1.2.28 1.2.6 1.2.7 1.2.8 1.2.9 trunk 1.0.10 1.0.11 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.20 1.1.21 1.1.22 1.1.23 1.1.24 1.1.25 1.1.26 1.1.27 1.1.28 1.1.29 1.1.3 1.1.30 1.1.31 1.1.32 1.1.33 1.1.34 1.1.35 1.1.36 1.1.37 1.1.38 1.1.39 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.3 1.2.4 1.2.5
templates-patterns-collection / includes / Editor.php
templates-patterns-collection / includes Last commit date
Importers 2 months ago Admin.php 2 weeks ago Editor.php 1 year ago Elementor.php 1 year ago License.php 1 year ago Logger.php 2 years ago Main.php 1 day ago Rest_Server.php 3 weeks ago Sites_Listing.php 1 day ago Starter_Ranking.php 2 weeks ago TI_Beaver.php 1 year ago WP_Cli.php 3 months ago White_Label_Config.php 3 years ago
Editor.php
245 lines
1 <?php
2 /**
3 * Handles code for Block Editor.
4 *
5 * @package templates-patterns-collection
6 */
7
8 namespace TIOB;
9
10 use TIOB\Main;
11
12 /**
13 * Class Editor
14 *
15 * @package templates-patterns-collection
16 */
17 class Editor {
18 use White_Label_Config;
19
20 const ALLOWED_POST_TYPES = array( 'post', 'page', 'neve_custom_layouts' );
21
22 /**
23 * Assets Handle.
24 *
25 * @var string
26 */
27 private $handle = 'ti-tpc-block';
28
29 /**
30 * Get allowed post types.
31 *
32 * @return array
33 */
34 public static function get_allowed_post_types() {
35 return apply_filters( 'ti_tpc_allowed_post_types', self::ALLOWED_POST_TYPES );
36 }
37
38 /**
39 * Initialize the Admin.
40 */
41 public function init() {
42 $this->setup_white_label();
43
44 if ( $this->is_library_disabled() ) {
45 return;
46 }
47
48 if ( ! defined( 'TPC_TEMPLATES_CLOUD_ENDPOINT' ) ) {
49 define( 'TPC_TEMPLATES_CLOUD_ENDPOINT', Admin::get_templates_cloud_endpoint() );
50 }
51 add_action( 'enqueue_block_editor_assets', array( $this, 'register_block' ), 11 );
52 $this->tpc_register_settings();
53 $this->register_post_meta();
54 }
55
56 /**
57 * Register editor blocks.
58 */
59 public function register_block() {
60 $deps = require( TIOB_PATH . 'editor/build/index.asset.php' );
61
62 $screen = get_current_screen();
63 if ( ! isset( $screen->id ) ) {
64 return;
65 }
66
67 if ( $screen->id === 'widgets' ) {
68 return;
69 }
70
71 wp_register_script(
72 $this->handle,
73 TIOB_URL . 'editor/build/index.js',
74 array_merge( $deps['dependencies'], array( 'wp-api', 'regenerator-runtime' ) ),
75 $deps['version']
76 );
77
78 wp_localize_script(
79 $this->handle,
80 'tiTpc',
81 apply_filters(
82 'ti_tpc_editor_data',
83 array(
84 'endpoint' => TPC_TEMPLATES_CLOUD_ENDPOINT,
85 'params' => array(
86 'site_url' => get_site_url(),
87 'license_id' => apply_filters( 'tiob_license_key', 'free' ),
88 'type' => 'gutenberg',
89 'meta' => Main::get_meta_fields( $post_id = get_the_ID(), $type = 'gutenberg' ),
90 ),
91 'metaKeys' => apply_filters( 'ti_tpc_template_meta', array(), $post_id = get_the_ID(), $type = 'gutenberg' ),
92 'canPredefine' => apply_filters( 'ti_tpc_can_predefine', false ),
93 'allowed_post' => self::get_allowed_post_types(),
94 'isSiteEditor' => $screen->id === 'site-editor',
95 'isFSETheme' => Admin::is_fse_theme(),
96 )
97 )
98 );
99
100 wp_register_style(
101 $this->handle,
102 TIOB_URL . 'editor/build/index.css',
103 array(),
104 $deps['version']
105 );
106
107 wp_style_add_data( $this->handle, 'rtl', 'replace' );
108
109 register_block_type(
110 'ti-tpc/templates-cloud',
111 array(
112 'editor_script' => $this->handle,
113 'editor_style' => $this->handle,
114 )
115 );
116 }
117
118 /**
119 * Register global settings for FSE templates.
120 */
121 public function tpc_register_settings() {
122 $can_predefine = apply_filters( 'ti_tpc_can_predefine', false );
123 $properties = array(
124 '_ti_tpc_template_id' => array(
125 'type' => 'string',
126 ),
127 '_ti_tpc_template_sync' => array(
128 'type' => 'boolean',
129 ),
130 );
131 if ( $can_predefine ) {
132 $properties = array_merge(
133 $properties,
134 array(
135 '__ti_tpc_screenshot_url' => array(
136 'type' => 'string',
137 ),
138 '_ti_tpc_site_slug' => array(
139 'type' => 'string',
140 ),
141 '_ti_tpc_published' => array(
142 'type' => 'boolean',
143 ),
144 '_ti_tpc_previewer_url' => array(
145 'type' => 'string',
146 ),
147 )
148 );
149 }
150
151 register_setting(
152 '',
153 'templates_patterns_collection_fse_templates',
154 array(
155 'default' => '',
156 'show_in_rest' => array(
157 'schema' => array(
158 'type' => 'object',
159 'additionalProperties' => array(
160 'type' => 'object',
161 'properties' => $properties,
162 ),
163 'propertyNames' => array(
164 'type' => 'string', // Specify that the key is a string
165 ),
166 ),
167 ),
168 'type' => 'object',
169 )
170 );
171 }
172
173 /**
174 * Register post meta.
175 */
176 public function register_post_meta() {
177 register_post_meta(
178 '',
179 '_ti_tpc_template_sync',
180 array(
181 'show_in_rest' => true,
182 'single' => true,
183 'type' => 'boolean',
184 'auth_callback' => function() {
185 return current_user_can( 'edit_posts' );
186 },
187 )
188 );
189
190 register_post_meta(
191 '',
192 '_ti_tpc_template_id',
193 array(
194 'show_in_rest' => true,
195 'single' => true,
196 'type' => 'string',
197 'auth_callback' => function () {
198 return current_user_can( 'edit_posts' );
199 },
200 )
201 );
202
203 if ( apply_filters( 'ti_tpc_can_predefine', false ) === false ) {
204 return;
205 }
206
207 register_post_meta(
208 '',
209 '_ti_tpc_screenshot_url',
210 array(
211 'show_in_rest' => true,
212 'single' => true,
213 'type' => 'string',
214 'auth_callback' => function () {
215 return current_user_can( 'edit_posts' );
216 },
217 )
218 );
219 register_post_meta(
220 '',
221 '_ti_tpc_site_slug',
222 array(
223 'show_in_rest' => true,
224 'single' => true,
225 'type' => 'string',
226 'auth_callback' => function () {
227 return current_user_can( 'edit_posts' );
228 },
229 )
230 );
231 register_post_meta(
232 '',
233 '_ti_tpc_published',
234 array(
235 'show_in_rest' => true,
236 'single' => true,
237 'type' => 'boolean',
238 'auth_callback' => function () {
239 return current_user_can( 'edit_posts' );
240 },
241 )
242 );
243 }
244 }
245