acmethemes.php
109 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; |
| 4 | } |
| 5 | |
| 6 | if ( ! class_exists( 'Advanced_Import_Theme_Acmethemes' ) ) { |
| 7 | |
| 8 | /** |
| 9 | * Functions related to About Block |
| 10 | * |
| 11 | * @package Advanced Import |
| 12 | * @subpackage Advanced_Import_Theme_Acmethemes |
| 13 | * @since 1.0.5 |
| 14 | */ |
| 15 | |
| 16 | class Advanced_Import_Theme_Acmethemes extends Advanced_Import_Theme_Template_Library_Base { |
| 17 | |
| 18 | |
| 19 | /** |
| 20 | * Theme author |
| 21 | * This class is created for acmethemes theme |
| 22 | * Check for author |
| 23 | * |
| 24 | * @since 1.0.5 |
| 25 | * @access private |
| 26 | */ |
| 27 | private $theme_author = 'acmethemes'; |
| 28 | |
| 29 | /** |
| 30 | * Gets an instance of this object. |
| 31 | * Prevents duplicate instances which avoid artefacts and improves performance. |
| 32 | * |
| 33 | * @static |
| 34 | * @access public |
| 35 | * @since 1.0.5 |
| 36 | * @return object |
| 37 | */ |
| 38 | public static function get_instance() { |
| 39 | |
| 40 | // Store the instance locally to avoid private static replication |
| 41 | static $instance = null; |
| 42 | |
| 43 | // Only run these methods if they haven't been ran previously |
| 44 | if ( null === $instance ) { |
| 45 | $instance = new self(); |
| 46 | } |
| 47 | |
| 48 | // Always return the instance |
| 49 | return $instance; |
| 50 | |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Load block library |
| 55 | * Used for blog template loading |
| 56 | * |
| 57 | * @since 1.0.5 |
| 58 | * @package Acmethemes |
| 59 | * @author Acmethemes <info@acmethemes.com> |
| 60 | * |
| 61 | * @param$current_demo_list array |
| 62 | * @return array |
| 63 | */ |
| 64 | public function add_template_library( $current_demo_list ) { |
| 65 | /*common check*/ |
| 66 | if ( advanced_import_get_current_theme_author() != $this->theme_author ) { |
| 67 | return $current_demo_list; |
| 68 | } |
| 69 | |
| 70 | /* |
| 71 | for acmethemes only |
| 72 | check if acmethemes template library function exist*/ |
| 73 | if ( function_exists( 'run_acme_demo_setup' ) ) { |
| 74 | return $current_demo_list; |
| 75 | } |
| 76 | |
| 77 | /*finally fetch template library data from live*/ |
| 78 | $templates_list = array(); |
| 79 | |
| 80 | $url = 'https://www.acmeit.org/wp-json/acmethemes-demo-api/v1/fetch_templates/?theme-slug=' . esc_attr( advanced_import_get_current_theme_slug() ); |
| 81 | $body_args = array( |
| 82 | /*API version*/ |
| 83 | 'api_version' => wp_get_theme()['Version'], |
| 84 | /*lang*/ |
| 85 | 'site_lang' => get_bloginfo( 'language' ), |
| 86 | ); |
| 87 | $raw_json = wp_safe_remote_get( |
| 88 | $url, |
| 89 | array( |
| 90 | 'timeout' => 100, |
| 91 | 'body' => $body_args, |
| 92 | ) |
| 93 | ); |
| 94 | |
| 95 | if ( ! is_wp_error( $raw_json ) ) { |
| 96 | $demo_server = json_decode( wp_remote_retrieve_body( $raw_json ), true ); |
| 97 | if ( json_last_error() === JSON_ERROR_NONE ) { |
| 98 | if ( is_array( $demo_server ) ) { |
| 99 | $templates_list = $demo_server; |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | return array_merge( $current_demo_list, $templates_list ); |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | Advanced_Import_Theme_Acmethemes::get_instance()->run(); |
| 109 |