| 1 |
<?php |
| 2 |
namespace Easyel\EasyElements\Template_Library; |
| 3 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 4 |
|
| 5 |
class Easyel_Templates_Library { |
| 6 |
|
| 7 |
private $assets_url; |
| 8 |
private $rest_url; |
| 9 |
|
| 10 |
const SITE_URL = 'https://wpeasyelements.com/demotemplate/'; |
| 11 |
|
| 12 |
protected static $instance = null; |
| 13 |
|
| 14 |
public function __construct() { |
| 15 |
|
| 16 |
$this->assets_url = EASYELEMENTS_DIR_URL . 'includes/Template_Library/assets/'; |
| 17 |
|
| 18 |
$this->rest_url = self::SITE_URL . '/wp-json/rtTemplates/v1/templates'; |
| 19 |
|
| 20 |
add_action( 'elementor/editor/before_enqueue_scripts', array( $this, 'easy_editor_scripts' ), 1 ); |
| 21 |
|
| 22 |
add_action( 'elementor/editor/after_enqueue_styles', array( $this, 'easy_editor_styles' ) ); |
| 23 |
|
| 24 |
add_action( 'elementor/preview/enqueue_styles', array( $this, 'easy_preview_styles' ) ); |
| 25 |
|
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Get instance |
| 30 |
*/ |
| 31 |
public static function get_instance() { |
| 32 |
if ( null === self::$instance ) { |
| 33 |
self::$instance = new self(); |
| 34 |
} |
| 35 |
return self::$instance; |
| 36 |
} |
| 37 |
|
| 38 |
public function easy_editor_scripts() { |
| 39 |
wp_enqueue_script( 'easy-elements-template-library-script', $this->assets_url . 'js/easy-template-library.js', array( 'jquery', 'wp-element' ), EASYELEMENTS_VER, true ); |
| 40 |
|
| 41 |
wp_localize_script('easy-elements-template-library-script', 'rtElementsTemplatesajax', [ |
| 42 |
'previewBaseUrl' => "https://wpeasyelements.com/demotemplate/", |
| 43 |
'ajaxUrl' => admin_url('admin-ajax.php'), |
| 44 |
]); |
| 45 |
|
| 46 |
wp_enqueue_script( 'easy-elements-template-library-isotope-script', $this->assets_url . 'js/isotope.pkgd.min.js', array( 'jquery', 'wp-element' ), EASYELEMENTS_VER, true ); |
| 47 |
|
| 48 |
$config = array( |
| 49 |
'activeTab' => 'sections', |
| 50 |
'nonce' => wp_create_nonce( 'wp_rest' ), |
| 51 |
'buttonIcon' => $this->assets_url . 'img/easy-template-logo.png', |
| 52 |
'logoUrl' => $this->assets_url . 'img/easy-template-logo-sm2.webp', |
| 53 |
'headerLogoUrl' => $this->assets_url . 'img/easy-template-logo.png', |
| 54 |
'bannerAdUrl' => $this->assets_url . 'img/easy-templates-banner-ad2.webp', |
| 55 |
'apiUrl' => $this->rest_url, |
| 56 |
'thumbnailPlaceholderUrl' => $this->assets_url . 'img/about-img.jpg', |
| 57 |
'canInsertPro' => false, |
| 58 |
'proCta' => array( |
| 59 |
'title' => __( 'Premium template', 'easy-elements' ), |
| 60 |
'btnText' => __( 'Get Pro', 'easy-elements' ), |
| 61 |
'btnUrl' => 'https://wpeasyelements.com/pricing/', |
| 62 |
), |
| 63 |
); |
| 64 |
|
| 65 |
$config = (array) apply_filters( 'easyel_template_library_config', $config ); |
| 66 |
|
| 67 |
wp_add_inline_script( |
| 68 |
'easy-elements-template-library-script', |
| 69 |
'var rtElementsTemplatesManager = ' . wp_json_encode( $config ) . ';', |
| 70 |
'before' |
| 71 |
); |
| 72 |
} |
| 73 |
|
| 74 |
public function easy_editor_styles() { |
| 75 |
wp_enqueue_style( 'easy-elements-template-library-style', $this->assets_url . 'css/easy-elements-template-library.min.css', array(), EASYELEMENTS_VER ); |
| 76 |
} |
| 77 |
|
| 78 |
public function easy_preview_styles() { |
| 79 |
wp_enqueue_style( 'easy-elements-template-library-preview-style', $this->assets_url . 'css/preview.css', array(), EASYELEMENTS_VER ); |
| 80 |
} |
| 81 |
|
| 82 |
} |