theme-template-library
3 weeks ago
class-advanced-import-activator.php
4 years ago
class-advanced-import-cron.php
4 years ago
class-advanced-import-deactivator.php
3 weeks ago
class-advanced-import-i18n.php
3 weeks ago
class-advanced-import-loader.php
5 years ago
class-advanced-import.php
3 months ago
class-theme-template-library-base.php
3 weeks ago
functions-advanced-import.php
3 weeks ago
index.php
5 years ago
class-theme-template-library-base.php
121 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; |
| 4 | } |
| 5 | |
| 6 | if ( ! class_exists( 'Advanced_Import_Theme_Template_Library_Base' ) ) { |
| 7 | |
| 8 | /** |
| 9 | * Base Class For CosmosWP for common functions |
| 10 | * |
| 11 | * @package Advanced Import |
| 12 | * @subpackage Advanced Import Template Library |
| 13 | * @since 1.0.0 |
| 14 | */ |
| 15 | class Advanced_Import_Theme_Template_Library_Base { |
| 16 | |
| 17 | /** |
| 18 | * Theme author |
| 19 | * This class is created for acmethemes theme |
| 20 | * Check for author |
| 21 | * |
| 22 | * @since 1.4.6 |
| 23 | * @access protected |
| 24 | */ |
| 25 | protected $theme_author; |
| 26 | |
| 27 | |
| 28 | /** |
| 29 | * Theme author |
| 30 | * This class is created for acmethemes theme |
| 31 | * Check for author |
| 32 | * |
| 33 | * @since 1.4.6 |
| 34 | * @access protected |
| 35 | */ |
| 36 | protected $api_url = 'https://demo.patternswp.com/wp-json/patternswp-demo-setup/v1/acmeit-demos'; |
| 37 | |
| 38 | /** |
| 39 | * Run Block |
| 40 | * |
| 41 | * @access public |
| 42 | * @since 1.0.0 |
| 43 | * @return void |
| 44 | */ |
| 45 | public function run() { |
| 46 | add_filter( 'advanced_import_demo_lists', array( $this, 'add_template_library' ) ); |
| 47 | add_filter( 'advanced_import_template_api_args', array( $this, 'add_args' ) ); |
| 48 | add_filter( 'advanced_import_theme_api_args', array( $this, 'add_args' ) ); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Load template library |
| 53 | * |
| 54 | * @since 1.0.5 |
| 55 | * @package Acmethemes |
| 56 | * @author Acmethemes <info@acmethemes.com> |
| 57 | * |
| 58 | * @param array $current_demo_list Current demo list. |
| 59 | * @return array |
| 60 | */ |
| 61 | public function add_template_library( $current_demo_list ) { |
| 62 | /* Common check */ |
| 63 | if ( advanced_import_get_current_theme_author() !== $this->theme_author ) { |
| 64 | return $current_demo_list; |
| 65 | } |
| 66 | |
| 67 | /* Prepare API arguments */ |
| 68 | $args = array( |
| 69 | 'theme-slug' => esc_attr( advanced_import_get_current_theme_slug() ), |
| 70 | ); |
| 71 | $args = apply_filters( 'advanced_import_theme_api_args', $args ); |
| 72 | $url = add_query_arg( $args, $this->api_url ); |
| 73 | /* Fetch cached or fresh API data */ |
| 74 | $templates_list = advanced_import_get_api_data( $url ); |
| 75 | |
| 76 | if ( is_array( $templates_list ) ) { |
| 77 | return array_merge( $current_demo_list, $templates_list ); |
| 78 | } |
| 79 | |
| 80 | return $current_demo_list; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Load template library |
| 85 | * |
| 86 | * @since 1.4.6 |
| 87 | * @package Acmethemes |
| 88 | * @author Acmethemes <info@acmethemes.com> |
| 89 | * |
| 90 | * @param array $args Existing args. |
| 91 | * @return array |
| 92 | */ |
| 93 | public function add_args( $args ) { |
| 94 | /* Common check */ |
| 95 | if ( advanced_import_get_current_theme_author() !== $this->theme_author ) { |
| 96 | return $args; |
| 97 | } |
| 98 | |
| 99 | $current_theme_slug = advanced_import_get_current_theme_slug(); |
| 100 | $license = trim( get_option( $current_theme_slug . '_license_key' ) ); |
| 101 | if ( $license ) { |
| 102 | $args['license-info'][ $current_theme_slug ] = array( |
| 103 | 'author' => $this->theme_author, |
| 104 | /* |
| 105 | * Send both plaintext 'license' and hashed 'license-hash'. |
| 106 | * The remote API is still being updated to accept 'license-hash' |
| 107 | * (the new, secure format). Sending both fields keeps the |
| 108 | * plugin working with both old and new API versions. Once the |
| 109 | * remote side is fully migrated, the 'license' field can be removed. |
| 110 | */ |
| 111 | 'license' => $license, |
| 112 | 'url' => home_url(), |
| 113 | 'environment' => function_exists( 'wp_get_environment_type' ) ? wp_get_environment_type() : 'production', |
| 114 | ); |
| 115 | } |
| 116 | |
| 117 | return $args; |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 |