VariationSwatches
1 week ago
Wishlist
1 week ago
AdminMessage.php
1 week ago
AjaxSearch.php
1 week ago
Backorder.php
1 week ago
CatalogMode.php
1 year ago
Compare.php
1 week ago
DefaultTemplates.php
2 years ago
FlashSalesCountdown.php
1 year ago
MenuCart.php
4 months ago
MobilePanel.php
1 week ago
MultiStep.php
1 year ago
Notifications.php
1 week ago
QuickView.php
1 week ago
RecentlyViewedProducts.php
1 year ago
RenameLabel.php
4 months ago
Shopify.php
1 year ago
SingleAjaxAddToCart.php
1 week ago
SizeChart.php
1 week ago
StickyAddToCart.php
1 week ago
DefaultTemplates.php
55 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Import default templates. |
| 4 | * |
| 5 | * @package ShopPress |
| 6 | */ |
| 7 | |
| 8 | namespace ShopPress\Modules; |
| 9 | |
| 10 | defined( 'ABSPATH' ) || exit; |
| 11 | |
| 12 | class DefaultTemplates { |
| 13 | /** |
| 14 | * Templates URL. |
| 15 | * |
| 16 | * @var string |
| 17 | */ |
| 18 | private static $templates_url = ''; |
| 19 | |
| 20 | /** |
| 21 | * Local Templates URL. |
| 22 | * |
| 23 | * @var string |
| 24 | */ |
| 25 | private static $local_templates_url = SHOPPRESS_URL . 'public/sample-data/'; |
| 26 | |
| 27 | /** |
| 28 | * Get template content. |
| 29 | * |
| 30 | * @since 1.0.0 |
| 31 | */ |
| 32 | public static function get_template_content( $page_id, $custom_type, $template = '' ) { |
| 33 | |
| 34 | if ( ! $page_id ) { |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | $args = array( |
| 39 | 'user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36', |
| 40 | ); |
| 41 | |
| 42 | $url = $template ? self::$templates_url . $custom_type . '/' . $template . '.json' : self::$local_templates_url . $custom_type . '.json'; |
| 43 | |
| 44 | $response = wp_remote_get( $url, $args ); |
| 45 | |
| 46 | if ( ! is_wp_error( $response ) ) { |
| 47 | $data = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 48 | |
| 49 | if ( isset( $data['content'] ) ) { |
| 50 | update_post_meta( $page_id, '_elementor_data', $data['content'] ); |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 |