| @@ -50,8 +50,13 @@ | ||
| 50 | 50 | add_action( 'pre_get_posts', [ $this, 'pre_get_posts' ], 1 ); |
| 51 | 51 | add_action( 'wp', function () { |
| 52 | 52 | new TemplateLoader( $this, self::$views ); |
| 53 | 53 | } ); |
| 54 | + // Unconditional (admin + front end): the editor's admin page bootstrap | |
| 55 | + // (post.php?action=elementor) never fires `wp`, so this can't be gated | |
| 56 | + // behind the TemplateLoader instantiation above. See TemplateLoader:: | |
| 57 | + // register_preview_product_hooks() for why two render pathways are covered. | |
| 58 | + TemplateLoader::register_preview_product_hooks(); | |
| 54 | 59 | |
| 55 | 60 | add_action( 'init', [ $this, 'source_register' ] ); |
| 56 | 61 | add_action( 'wp_ajax_templately_create_template', [ $this, 'create_template' ] ); |
| 57 | 62 | |
| @@ -56,8 +61,9 @@ | ||
| 56 | 61 | add_action( 'wp_ajax_templately_create_template', [ $this, 'create_template' ] ); |
| 57 | 62 | |
| 58 | 63 | add_filter( 'elementor/document/config', [$this, 'elementor_document_config'], 10, 2 ); |
| 59 | 64 | add_filter( 'elementor/documents/get/post_id', [$this, 'elementor_documents_get_post_id'] ); |
| 65 | + add_action( 'elementor/widgets/register', [ $this, 'register_elements' ] ); | |
| 60 | 66 | |
| 61 | 67 | add_filter( 'the_content', [$this, 'filter_content'], 10 ,1); |
| 62 | 68 | |
| 63 | 69 | self::$theme_compatibility = new ThemeCompatibility(); |
| @@ -85,13 +91,26 @@ | ||
| 85 | 91 | public function source_register() { |
| 86 | 92 | self::$templates_manager = new TemplateManager( $this ); |
| 87 | 93 | self::$conditions_manager = new ConditionManager( $this ); |
| 88 | 94 | self::$source = new Source( $this ); |
| 95 | + register_rest_field('templately_library','templately_type', [ | |
| 96 | + 'get_callback' => [ $this, 'get_rest_template_type' ], | |
| 97 | + ]); | |
| 89 | 98 | } |
| 90 | 99 | |
| 100 | + public function get_rest_template_type() { | |
| 101 | + return get_post_meta( get_the_ID(), '_templately_template_type', true ); | |
| 102 | + } | |
| 103 | + | |
| 91 | 104 | public function create_template() { |
| 92 | 105 | check_admin_referer( 'templately_create_template' ); |
| 93 | 106 | |
| 107 | + // Check user capability | |
| 108 | + if (!current_user_can('delete_posts')) { | |
| 109 | + wp_send_json_error(['message' => 'Insufficient permissions']); | |
| 110 | + wp_die(); | |
| 111 | + } | |
| 112 | + | |
| 94 | 113 | $_type = sanitize_text_field( wp_unslash( $_POST['template_type'] ) ); |
| 95 | 114 | |
| 96 | 115 | $_meta = []; |
| 97 | 116 | |
| @@ -185,9 +204,10 @@ | ||
| 185 | 204 | return $post_id; |
| 186 | 205 | } |
| 187 | 206 | |
| 188 | 207 | public function modify_template_type( $value, $object_id, $meta_key, $single ) { |
| 189 | - if ( Document::TYPE_META_KEY === $meta_key && Source::CPT === get_post_type( $object_id ) ) { | |
| 208 | + $_value = $value; | |
| 209 | + if ( empty($value) && Document::TYPE_META_KEY === $meta_key && Source::CPT === get_post_type( $object_id ) ) { | |
| 190 | 210 | remove_filter( 'get_post_metadata', [ $this, 'modify_template_type' ] ); |
| 191 | 211 | $value = get_post_meta( $object_id, Source::TYPE_META_KEY, $single ); |
| 192 | 212 | $arr = [ |
| 193 | 213 | 'post' => 'single-post', |
| @@ -199,11 +219,21 @@ | ||
| 199 | 219 | 'course_archive' => 'archive', |
| 200 | 220 | ]; |
| 201 | 221 | $key = $single ? $value : (isset($value[0]) ? $value[0] : ''); |
| 202 | 222 | $value = isset( $arr[ $key ] ) ? $arr[ $key ] : $value; |
| 223 | + if(in_array($value, ['header', 'footer'])){ | |
| 224 | + return $_value; | |
| 225 | + } | |
| 203 | 226 | } |
| 204 | 227 | |
| 205 | 228 | return $value; |
| 229 | + } | |
| 230 | + | |
| 231 | + public function register_elements( $widgets_manager ) { | |
| 232 | + $widgets_manager->register( new \Templately\Builder\Widgets\Post_Title() ); | |
| 233 | + $widgets_manager->register( new \Templately\Builder\Widgets\Post_Content() ); | |
| 234 | + $widgets_manager->register( new \Templately\Builder\Widgets\Featured_Image() ); | |
| 235 | + $widgets_manager->register( new \Templately\Builder\Widgets\Site_Logo() ); | |
| 206 | 236 | } |
| 207 | 237 | |
| 208 | 238 | public function filter_content( $content ) { |
| 209 | 239 | if(is_singular()){ |