| @@ -20,13 +20,8 @@ | ||
| 20 | 20 | class TemplateSource extends Source_Base { |
| 21 | 21 | protected $template_prefix = 'betterdocs_'; |
| 22 | 22 | protected $cloud_url = 'https://betterdocs.co/wp-json/bd_cloud/v1/'; |
| 23 | 23 | |
| 24 | - /** | |
| 25 | - * Local template IDs (templates bundled with the plugin) | |
| 26 | - */ | |
| 27 | - const LOCAL_TAG_ARCHIVE_ID = 'betterdocs_local_tag_archive_1'; | |
| 28 | - | |
| 29 | 24 | public function get_prefix() { |
| 30 | 25 | return $this->template_prefix; |
| 31 | 26 | } |
| 32 | 27 | |
| @@ -40,34 +35,21 @@ | ||
| 40 | 35 | |
| 41 | 36 | public function register_data() {} |
| 42 | 37 | |
| 43 | 38 | public function get_items( $args = [] ) { |
| 44 | - $_cache_key = 'betterdocs_remote_templates_v1'; | |
| 45 | - $templates = get_transient( $_cache_key ); | |
| 39 | + $url = $this->cloud_url . 'templates'; | |
| 40 | + $response = wp_remote_get( $url, [ 'timeout' => 60 ] ); | |
| 41 | + $body = wp_remote_retrieve_body( $response ); | |
| 42 | + $body = json_decode( $body, true ); | |
| 43 | + $templates_data = ! empty( $body['data'] ) ? $body['data'] : []; | |
| 44 | + $templates = []; | |
| 46 | 45 | |
| 47 | - if ( false === $templates ) { | |
| 48 | - $templates = []; | |
| 49 | - | |
| 50 | - // Fetch remote templates | |
| 51 | - $url = $this->cloud_url . 'templates'; | |
| 52 | - $response = wp_remote_get( $url, [ 'timeout' => 60 ] ); | |
| 53 | - $body = wp_remote_retrieve_body( $response ); | |
| 54 | - $body = json_decode( $body, true ); | |
| 55 | - $templates_data = ! empty( $body['data'] ) ? $body['data'] : []; | |
| 56 | - | |
| 57 | - if ( ! empty( $templates_data ) ) { | |
| 58 | - foreach ( $templates_data as $template_data ) { | |
| 59 | - $templates[] = $this->prepare_template( $template_data ); | |
| 60 | - } | |
| 46 | + if ( ! empty( $templates_data ) ) { | |
| 47 | + foreach ( $templates_data as $template_data ) { | |
| 48 | + $templates[] = $this->prepare_template( $template_data ); | |
| 61 | 49 | } |
| 62 | - | |
| 63 | - set_transient( $_cache_key, $templates, DAY_IN_SECONDS ); | |
| 64 | 50 | } |
| 65 | 51 | |
| 66 | - // Note: local bundled templates are NOT included here. | |
| 67 | - // They are injected exclusively via Elementor.php::get_templates() → http_response filter | |
| 68 | - // to avoid duplicates (Elementor calls get_items() on registered sources separately). | |
| 69 | - | |
| 70 | 52 | if ( ! empty( $args ) ) { |
| 71 | 53 | $templates = wp_list_filter( $templates, $args ); |
| 72 | 54 | } |
| 73 | 55 | |
| @@ -73,36 +55,8 @@ | ||
| 73 | 55 | |
| 74 | 56 | return $templates; |
| 75 | 57 | } |
| 76 | 58 | |
| 77 | - /** | |
| 78 | - * Returns locally bundled premade templates (no remote fetch required). | |
| 79 | - * | |
| 80 | - * @return array | |
| 81 | - */ | |
| 82 | - public function get_local_templates() { | |
| 83 | - return [ | |
| 84 | - [ | |
| 85 | - 'accessLevel' => 0, | |
| 86 | - 'template_id' => self::LOCAL_TAG_ARCHIVE_ID, | |
| 87 | - 'source' => 'remote', | |
| 88 | - 'type' => 'block', | |
| 89 | - 'subtype' => 'Docs Archive', | |
| 90 | - 'title' => __( 'BetterDocs Tag Archive', 'betterdocs' ), | |
| 91 | - 'thumbnail' => plugins_url( '/assets/static/admin/images/templates/tag-archive-thumb.png', BETTERDOCS_PLUGIN_FILE ), | |
| 92 | - 'date' => '2024-01-01', | |
| 93 | - 'author' => 'WPDeveloper', | |
| 94 | - 'tags' => [ 'Docs Archive' ], | |
| 95 | - 'isPro' => false, | |
| 96 | - 'popularityIndex' => 0, | |
| 97 | - 'trendIndex' => 0, | |
| 98 | - 'hasPageSettings' => false, | |
| 99 | - 'url' => plugins_url( '/assets/static/admin/images/templates/tag-archive-thumb.png', BETTERDOCS_PLUGIN_FILE ), | |
| 100 | - 'favorite' => false, | |
| 101 | - ], | |
| 102 | - ]; | |
| 103 | - } | |
| 104 | - | |
| 105 | 59 | public function prepare_template( $template_data ) { |
| 106 | 60 | return [ |
| 107 | 61 | 'accessLevel' => 0, |
| 108 | 62 | 'template_id' => $template_data['template_id'], |
| @@ -157,13 +111,8 @@ | ||
| 157 | 111 | return false; |
| 158 | 112 | } |
| 159 | 113 | |
| 160 | 114 | public function get_data( array $args, $context = 'display' ) { |
| 161 | - // Serve local bundled templates without a remote HTTP request | |
| 162 | - if ( isset( $args['template_id'] ) && $args['template_id'] === self::LOCAL_TAG_ARCHIVE_ID ) { | |
| 163 | - return $this->get_local_tag_archive_data(); | |
| 164 | - } | |
| 165 | - | |
| 166 | 115 | $file_url = $this->cloud_url . 'template/' . $args['template_id']; |
| 167 | 116 | $request = wp_remote_get( $file_url ); |
| 168 | 117 | $response = wp_remote_retrieve_body( $request ); |
| 169 | 118 | $body = json_decode( $response, true ); |
| @@ -171,153 +120,8 @@ | ||
| 171 | 120 | |
| 172 | 121 | $result = []; |
| 173 | 122 | |
| 174 | 123 | $result['content'] = $this->replace_elements_ids( $data ); |
| 175 | - $result['content'] = $this->process_export_import_content( $result['content'], 'on_import' ); | |
| 176 | - $result['page_settings'] = []; | |
| 177 | - | |
| 178 | - return $result; | |
| 179 | - } | |
| 180 | - | |
| 181 | - /** | |
| 182 | - * Returns the Elementor template content for the Tag Archive premade template. | |
| 183 | - * Layout (mirrors the screenshot): Search bar (full-width) + Sidebar / Content two-column area. | |
| 184 | - * | |
| 185 | - * @return array | |
| 186 | - */ | |
| 187 | - protected function get_local_tag_archive_data() { | |
| 188 | - $content = [ | |
| 189 | - // ── Row 1: Search bar (full-width container) ────────────────────── | |
| 190 | - [ | |
| 191 | - 'id' => 'bdta0001', | |
| 192 | - 'elType' => 'container', | |
| 193 | - 'settings' => [ | |
| 194 | - 'flex_direction' => 'row', | |
| 195 | - 'content_width' => 'full', | |
| 196 | - 'padding' => [ | |
| 197 | - 'unit' => 'px', | |
| 198 | - 'top' => '20', | |
| 199 | - 'right' => '20', | |
| 200 | - 'bottom' => '20', | |
| 201 | - 'left' => '20', | |
| 202 | - 'isLinked' => false, | |
| 203 | - ], | |
| 204 | - ], | |
| 205 | - 'elements' => [ | |
| 206 | - [ | |
| 207 | - 'id' => 'bdta0003', | |
| 208 | - 'elType' => 'widget', | |
| 209 | - 'widgetType' => 'betterdocs-search-form', | |
| 210 | - 'settings' => [], | |
| 211 | - 'elements' => [], | |
| 212 | - ], | |
| 213 | - ], | |
| 214 | - ], | |
| 215 | - | |
| 216 | - // ── Row 2: Sidebar (33 %) + Content (67 %) ─────────────────────── | |
| 217 | - [ | |
| 218 | - 'id' => 'bdta0010', | |
| 219 | - 'elType' => 'container', | |
| 220 | - 'settings' => [ | |
| 221 | - 'flex_direction' => 'row', | |
| 222 | - 'content_width' => 'full', | |
| 223 | - 'gap' => [ | |
| 224 | - 'unit' => 'px', | |
| 225 | - 'size' => 0, | |
| 226 | - ], | |
| 227 | - 'padding' => [ | |
| 228 | - 'unit' => 'px', | |
| 229 | - 'top' => '30', | |
| 230 | - 'right' => '20', | |
| 231 | - 'bottom' => '40', | |
| 232 | - 'left' => '20', | |
| 233 | - 'isLinked' => false, | |
| 234 | - ], | |
| 235 | - ], | |
| 236 | - 'elements' => [ | |
| 237 | - | |
| 238 | - // Left container – BetterDocs Sidebar | |
| 239 | - [ | |
| 240 | - 'id' => 'bdta0011', | |
| 241 | - 'elType' => 'container', | |
| 242 | - 'settings' => [ | |
| 243 | - 'flex_direction' => 'column', | |
| 244 | - 'content_width' => 'full', | |
| 245 | - 'width' => [ | |
| 246 | - 'unit' => '%', | |
| 247 | - 'size' => 33, | |
| 248 | - ], | |
| 249 | - ], | |
| 250 | - 'elements' => [ | |
| 251 | - [ | |
| 252 | - 'id' => 'bdta0012', | |
| 253 | - 'elType' => 'widget', | |
| 254 | - 'widgetType' => 'betterdocs-sidebar', | |
| 255 | - 'settings' => [], | |
| 256 | - 'elements' => [], | |
| 257 | - ], | |
| 258 | - ], | |
| 259 | - ], | |
| 260 | - | |
| 261 | - // Right container – Breadcrumbs + Tag title + Doc list | |
| 262 | - [ | |
| 263 | - 'id' => 'bdta0020', | |
| 264 | - 'elType' => 'container', | |
| 265 | - 'settings' => [ | |
| 266 | - 'flex_direction' => 'column', | |
| 267 | - 'content_width' => 'full', | |
| 268 | - 'width' => [ | |
| 269 | - 'unit' => '%', | |
| 270 | - 'size' => 67, | |
| 271 | - ], | |
| 272 | - 'padding' => [ | |
| 273 | - 'unit' => 'px', | |
| 274 | - 'top' => '0', | |
| 275 | - 'right' => '0', | |
| 276 | - 'bottom' => '0', | |
| 277 | - 'left' => '30', | |
| 278 | - 'isLinked' => false, | |
| 279 | - ], | |
| 280 | - ], | |
| 281 | - 'elements' => [ | |
| 282 | - // Breadcrumbs | |
| 283 | - [ | |
| 284 | - 'id' => 'bdta0021', | |
| 285 | - 'elType' => 'widget', | |
| 286 | - 'widgetType' => 'betterdocs-breadcrumb', | |
| 287 | - 'settings' => [], | |
| 288 | - 'elements' => [], | |
| 289 | - ], | |
| 290 | - | |
| 291 | - // Archive title – shows "Docs Tag: <tag-name>" dynamically | |
| 292 | - [ | |
| 293 | - 'id' => 'bdta0022', | |
| 294 | - 'elType' => 'widget', | |
| 295 | - 'widgetType' => 'theme-archive-title', | |
| 296 | - 'settings' => [ | |
| 297 | - 'title_size' => 'h2', | |
| 298 | - ], | |
| 299 | - 'elements' => [], | |
| 300 | - ], | |
| 301 | - | |
| 302 | - // Docs list for the current tag | |
| 303 | - [ | |
| 304 | - 'id' => 'bdta0023', | |
| 305 | - 'elType' => 'widget', | |
| 306 | - 'widgetType' => 'betterdocs-category-archive-list', | |
| 307 | - 'settings' => [ | |
| 308 | - 'section_betterdocs_archive_list_layout' => 'layout-1', | |
| 309 | - ], | |
| 310 | - 'elements' => [], | |
| 311 | - ], | |
| 312 | - ], | |
| 313 | - ], | |
| 314 | - ], | |
| 315 | - ], | |
| 316 | - ]; | |
| 317 | - | |
| 318 | - $result = []; | |
| 319 | - $result['content'] = $this->replace_elements_ids( $content ); | |
| 320 | 124 | $result['content'] = $this->process_export_import_content( $result['content'], 'on_import' ); |
| 321 | 125 | $result['page_settings'] = []; |
| 322 | 126 | |
| 323 | 127 | return $result; |