| 1 |
<?php |
| 2 |
namespace HelloPlus\Modules\TemplateParts\Classes\Sources; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; // Exit if accessed directly |
| 6 |
} |
| 7 |
|
| 8 |
class Source_Remote_Ehp extends \Elementor\TemplateLibrary\Source_Remote { |
| 9 |
const API_TEMPLATES_URL = 'https://my.elementor.com/api/connect/v1/library/templates/'; |
| 10 |
const TEMPLATES_DATA_TRANSIENT_KEY_PREFIX = 'elementor_remote_templates_ehp_data_'; |
| 11 |
|
| 12 |
public function get_id(): string { |
| 13 |
return 'remote-ehp'; |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* @inheritDoc |
| 18 |
*/ |
| 19 |
public function get_title() { |
| 20 |
return esc_html__( 'Remote-Ehp', 'hello-plus' ); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* @inheritDoc |
| 25 |
*/ |
| 26 |
protected function get_templates_remotely( string $editor_layout_type ) { |
| 27 |
$query_args = $this->get_url_params( $editor_layout_type ); |
| 28 |
$url = add_query_arg( $query_args, static::API_TEMPLATES_URL ); |
| 29 |
|
| 30 |
$response = wp_remote_get( $url, [ |
| 31 |
'headers' => apply_filters( 'stg-cf-headers', [] ), |
| 32 |
] ); |
| 33 |
|
| 34 |
if ( is_wp_error( $response ) || 200 !== (int) wp_remote_retrieve_response_code( $response ) ) { |
| 35 |
return false; |
| 36 |
} |
| 37 |
|
| 38 |
$templates_data = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 39 |
|
| 40 |
if ( empty( $templates_data ) || ! is_array( $templates_data ) ) { |
| 41 |
return []; |
| 42 |
} |
| 43 |
|
| 44 |
return $templates_data; |
| 45 |
} |
| 46 |
|
| 47 |
protected function get_url_params( string $editor_layout_type ): array { |
| 48 |
return [ |
| 49 |
'products' => 'ehp', |
| 50 |
'editor_layout_type' => $editor_layout_type, |
| 51 |
]; |
| 52 |
} |
| 53 |
} |
| 54 |
|