WP init
This commit is contained in:
@@ -0,0 +1,214 @@
|
||||
<?php
|
||||
namespace WprAddons\Admin\Includes;
|
||||
|
||||
use WprAddons\Classes\Utilities;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* WPR_Conditions_Manager setup
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class WPR_Conditions_Manager {
|
||||
|
||||
/**
|
||||
** Header & Footer Conditions
|
||||
*/
|
||||
public static function header_footer_display_conditions( $conditions ) {
|
||||
$template = NULL;
|
||||
|
||||
// Custom
|
||||
if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->can_use_premium_code() ) {
|
||||
if ( !empty($conditions) ) {
|
||||
$conditions['caller-header-footer'] = ['true'];
|
||||
|
||||
// Archive Pages (includes search)
|
||||
if ( !is_null( \WprAddonsPro\Classes\Pro_Modules::archive_templates_conditions( $conditions ) ) ) {
|
||||
$template = \WprAddonsPro\Classes\Pro_Modules::archive_templates_conditions( $conditions );
|
||||
}
|
||||
|
||||
// Single Pages
|
||||
if ( !is_null( \WprAddonsPro\Classes\Pro_Modules::single_templates_conditions( $conditions ) ) ) {
|
||||
$template = \WprAddonsPro\Classes\Pro_Modules::single_templates_conditions( $conditions );
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
$template = Utilities::get_template_slug( $conditions, 'global' );
|
||||
}
|
||||
|
||||
if ( \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
|
||||
$template_type = Utilities::get_wpr_template_type(get_the_ID());
|
||||
|
||||
if ( 'header' === $template_type || 'footer' === $template_type || is_singular('wpr_mega_menu') ) {
|
||||
$template = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if ( 'on' === get_option('wpr_hide_head_foot_on_maintenenace', 'on') ) {
|
||||
if ( !current_user_can('administrator') && ('maintenance' == get_option('elementor_maintenance_mode_mode') || 'coming_soon' == get_option('elementor_maintenance_mode_mode')) ) {
|
||||
$template = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
/**
|
||||
** Canvas Content Conditions
|
||||
*/
|
||||
public static function canvas_page_content_display_conditions() {
|
||||
$template = NULL;
|
||||
|
||||
// Get Conditions
|
||||
if ( class_exists( 'WooCommerce' ) && is_woocommerce() ) {
|
||||
$archives = json_decode( get_option( 'wpr_product_archive_conditions' ), true );
|
||||
$singles = json_decode( get_option( 'wpr_product_single_conditions' ), true );
|
||||
} else {
|
||||
$archives = json_decode( get_option( 'wpr_archive_conditions' ), true );
|
||||
$singles = json_decode( get_option( 'wpr_single_conditions' ), true );
|
||||
}
|
||||
|
||||
if ( empty($archives) && empty($singles) ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Custom
|
||||
if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->can_use_premium_code() ) {
|
||||
|
||||
// Archive Pages (includes search)
|
||||
if ( !is_null( \WprAddonsPro\Classes\Pro_Modules::archive_templates_conditions( $archives ) ) ) {
|
||||
$template = \WprAddonsPro\Classes\Pro_Modules::archive_templates_conditions( $archives );
|
||||
}
|
||||
|
||||
// Single Pages
|
||||
if ( !is_null( \WprAddonsPro\Classes\Pro_Modules::single_templates_conditions( $singles ) ) ) {
|
||||
$template = \WprAddonsPro\Classes\Pro_Modules::single_templates_conditions( $singles );
|
||||
}
|
||||
} else {
|
||||
// Archive Pages (includes search)
|
||||
if ( !is_null( WPR_Conditions_Manager::archive_templates_conditions_free($archives) ) ) {
|
||||
$template = WPR_Conditions_Manager::archive_templates_conditions_free($archives);
|
||||
}
|
||||
|
||||
// Single Pages
|
||||
if ( !is_null( WPR_Conditions_Manager::single_templates_conditions_free($singles) ) ) {
|
||||
$template = WPR_Conditions_Manager::single_templates_conditions_free($singles);
|
||||
}
|
||||
}
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
** Archive Pages Templates Conditions Free
|
||||
*/
|
||||
public static function archive_templates_conditions_free( $conditions ) {
|
||||
$term_id = '';
|
||||
$term_name = '';
|
||||
$queried_object = get_queried_object();
|
||||
|
||||
// Get Terms
|
||||
if ( ! is_null( $queried_object ) ) {
|
||||
if ( isset( $queried_object->term_id ) && isset( $queried_object->taxonomy ) ) {
|
||||
$term_id = $queried_object->term_id;
|
||||
$term_name = $queried_object->taxonomy;
|
||||
}
|
||||
}
|
||||
|
||||
// Reset
|
||||
$template = NULL;
|
||||
|
||||
// Archive Pages (includes search)
|
||||
if ( is_archive() || is_search() ) {
|
||||
if ( ! is_search() ) {
|
||||
// Author
|
||||
if ( is_author() ) {
|
||||
$template = Utilities::get_template_slug( $conditions, 'archive/author' );
|
||||
// Date
|
||||
} elseif ( is_date() ) {
|
||||
$template = Utilities::get_template_slug( $conditions, 'archive/date' );
|
||||
// Category
|
||||
} elseif ( is_category() ) {
|
||||
$template = Utilities::get_template_slug( $conditions, 'archive/categories', $term_id );
|
||||
// Tag
|
||||
} elseif ( is_tag() ) {
|
||||
$template = Utilities::get_template_slug( $conditions, 'archive/tags', $term_id );
|
||||
// Products
|
||||
} elseif ( class_exists( 'WooCommerce' ) && is_woocommerce() ) {
|
||||
$template = Utilities::get_template_slug( $conditions, 'product_archive/products' );
|
||||
}
|
||||
|
||||
// Search Page
|
||||
} else {
|
||||
$template = Utilities::get_template_slug( $conditions, 'archive/search' );
|
||||
}
|
||||
|
||||
// Posts Page
|
||||
} elseif ( Utilities::is_blog_archive() ) {
|
||||
$template = Utilities::get_template_slug( $conditions, 'archive/posts' );
|
||||
}
|
||||
|
||||
// Global - For All Archives
|
||||
if ( is_null($template) ) {
|
||||
$all_archives = Utilities::get_template_slug( $conditions, 'archive/all_archives' );
|
||||
|
||||
if ( ! is_null($all_archives) ) {
|
||||
if ( class_exists( 'WooCommerce' ) && is_shop() ) {
|
||||
$template = null;
|
||||
} else {
|
||||
if ( is_archive() || is_search() || Utilities::is_blog_archive() ) {
|
||||
$template = $all_archives;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
/**
|
||||
** Single Pages Templates Conditions - Free
|
||||
*/
|
||||
public static function single_templates_conditions_free( $conditions ) {
|
||||
global $post;
|
||||
|
||||
// Get Posts
|
||||
$post_id = is_null($post) ? '' : $post->ID;
|
||||
$post_type = is_null($post) ? '' : $post->post_type;
|
||||
|
||||
// Reset
|
||||
$template = NULL;
|
||||
|
||||
// Single Pages
|
||||
if ( is_single() || is_front_page() || is_page() || is_404() ) {
|
||||
|
||||
if ( is_single() ) {
|
||||
// Blog Posts
|
||||
if ( 'post' == $post_type ) {
|
||||
$template = Utilities::get_template_slug( $conditions, 'single/posts', $post_id );
|
||||
} elseif ( 'product' == $post_type ) {
|
||||
$template = Utilities::get_template_slug( $conditions, 'product_single/product', $post_id );
|
||||
}
|
||||
} else {
|
||||
// Front page
|
||||
if ( is_front_page() && ! Utilities::is_blog_archive() ) {//TODO: is it a good check? - is_blog_archive()
|
||||
$template = Utilities::get_template_slug( $conditions, 'single/front_page' );
|
||||
// Error 404 Page
|
||||
} elseif ( is_404() ) {
|
||||
$template = Utilities::get_template_slug( $conditions, 'single/page_404' );
|
||||
// Single Page
|
||||
} elseif ( is_page() ) {
|
||||
$template = Utilities::get_template_slug( $conditions, 'single/pages', $post_id );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $template;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
namespace WprAddons\Admin\Includes;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* WPR_Editor_Hooks
|
||||
*
|
||||
* Handles Elementor editor hooks and modifications
|
||||
* Including removal of Elementor Pro promotion widgets
|
||||
*/
|
||||
class WPR_Editor_Hooks {
|
||||
|
||||
/**
|
||||
* Instance of this class
|
||||
*
|
||||
* @var WPR_Editor_Hooks
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* Get instance
|
||||
*
|
||||
* @return WPR_Editor_Hooks
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
private function __construct() {
|
||||
$this->add_hooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register all hooks
|
||||
*/
|
||||
private function add_hooks() {
|
||||
// Remove Elementor Pro Promotion Widgets - Only in editor (not during import)
|
||||
if ( current_user_can('administrator') ) {
|
||||
add_action('elementor/editor/before_enqueue_scripts', [$this, 'conditional_remove_elementor_pro_promotions'], 1);
|
||||
// Detect widgets when page is saved
|
||||
add_action('elementor/editor/after_save', [$this, 'detect_widgets_on_save'], 10, 2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove pro widgets from Elementor transient
|
||||
*
|
||||
* @param mixed $transient Transient data
|
||||
* @return mixed Modified transient data
|
||||
*/
|
||||
public function remove_pro_widgets_from_transient($transient) {
|
||||
// Remove pro_widgets from the Elementor API data
|
||||
if ($transient && isset($transient['pro_widgets'])) {
|
||||
$transient['pro_widgets'] = [];
|
||||
}
|
||||
return $transient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Conditionally remove Elementor Pro promotions
|
||||
* Uses persistent flag for performance - once Royal widgets are used, always hide promotions
|
||||
*/
|
||||
public function conditional_remove_elementor_pro_promotions() {
|
||||
// Check persistent flag first (most efficient) - works everywhere
|
||||
$flag = get_option('wpr_has_used_royal_widgets');
|
||||
|
||||
if ($flag) {
|
||||
$this->remove_elementor_promotions();
|
||||
return;
|
||||
}
|
||||
|
||||
// Only continue for first-time detection in actual Elementor editor (not during imports)
|
||||
$is_editor = isset(\Elementor\Plugin::$instance->editor);
|
||||
$is_edit_mode = $is_editor && \Elementor\Plugin::$instance->editor->is_edit_mode();
|
||||
|
||||
if (!$is_editor || !$is_edit_mode) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback: Check current page for first-time detection
|
||||
$post_id = get_the_ID();
|
||||
|
||||
if (!$post_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if this page uses Royal widgets
|
||||
$has_widgets = $this->page_has_royal_widgets($post_id);
|
||||
|
||||
if ($has_widgets) {
|
||||
// Set persistent flag for future use
|
||||
update_option('wpr_has_used_royal_widgets', time());
|
||||
|
||||
// Remove promotions
|
||||
$this->remove_elementor_promotions();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect Royal widgets when page is saved and set persistent flag
|
||||
*
|
||||
* @param int $post_id Post ID that was saved
|
||||
* @param array $data Elementor data being saved
|
||||
*/
|
||||
public function detect_widgets_on_save($post_id, $data) {
|
||||
// Skip if flag already set
|
||||
if (get_option('wpr_has_used_royal_widgets')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear cache to force fresh detection
|
||||
delete_transient('wpr_has_widgets_' . $post_id);
|
||||
|
||||
// Check if this page has Royal widgets
|
||||
if ($this->page_has_royal_widgets($post_id)) {
|
||||
update_option('wpr_has_used_royal_widgets', time());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply filters to remove Elementor promotions
|
||||
*/
|
||||
private function remove_elementor_promotions() {
|
||||
add_filter('pre_transient_elementor_remote_info_api_data_' . ELEMENTOR_VERSION,
|
||||
[$this, 'remove_pro_widgets_from_transient'], 999);
|
||||
add_filter('transient_elementor_remote_info_api_data_' . ELEMENTOR_VERSION,
|
||||
[$this, 'remove_pro_widgets_from_transient'], 999);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a page has Royal Addons widgets
|
||||
*
|
||||
* @param int $post_id Post ID to check
|
||||
* @return bool True if Royal widgets found
|
||||
*/
|
||||
private function page_has_royal_widgets($post_id) {
|
||||
// Check cache first
|
||||
$cache_key = 'wpr_has_widgets_' . $post_id;
|
||||
$cached = get_transient($cache_key);
|
||||
if (false !== $cached) {
|
||||
return $cached === 'yes';
|
||||
}
|
||||
|
||||
$has_widgets = false;
|
||||
|
||||
// Method 1: Check _elementor_controls_usage (fastest and most reliable)
|
||||
$controls_usage = get_post_meta($post_id, '_elementor_controls_usage', true);
|
||||
|
||||
if (is_array($controls_usage)) {
|
||||
foreach ($controls_usage as $widget_type => $data) {
|
||||
if (is_string($widget_type) && strpos($widget_type, 'wpr-') === 0) {
|
||||
$has_widgets = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Method 2: Fallback to _elementor_data for unsaved pages
|
||||
if (!$has_widgets) {
|
||||
$elementor_data = get_post_meta($post_id, '_elementor_data', true);
|
||||
|
||||
if (!empty($elementor_data)) {
|
||||
// Handle both array (during import) and string (normal) cases
|
||||
if (is_array($elementor_data)) {
|
||||
$elementor_data = wp_json_encode($elementor_data);
|
||||
}
|
||||
|
||||
if (is_string($elementor_data)) {
|
||||
if (strpos($elementor_data, '"widgetType":"wpr-') !== false) {
|
||||
$has_widgets = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cache result for 1 hour
|
||||
$cache_value = $has_widgets ? 'yes' : 'no';
|
||||
set_transient($cache_key, $cache_value, HOUR_IN_SECONDS);
|
||||
|
||||
return $has_widgets;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Initialize
|
||||
WPR_Editor_Hooks::instance();
|
||||
@@ -0,0 +1,306 @@
|
||||
<?php
|
||||
namespace WprAddons\Admin\Includes;
|
||||
|
||||
use WprAddons\Classes\Utilities;
|
||||
use Elementor\Core\Base\Elements_Iteration_Actions\Assets;
|
||||
use Elementor\Core\Files\CSS\Post as Post_CSS;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* WPR_Render_Templates setup
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class WPR_Render_Templates {
|
||||
|
||||
/**
|
||||
** Instance of Elemenntor Frontend class.
|
||||
*
|
||||
** @var \Elementor\Frontend()
|
||||
*/
|
||||
private static $elementor_instance;
|
||||
|
||||
/**
|
||||
** Get Current Theme.
|
||||
*/
|
||||
public $current_theme;
|
||||
|
||||
/**
|
||||
** Royal Themes Array.
|
||||
*/
|
||||
public $royal_themes;
|
||||
|
||||
|
||||
/**
|
||||
** Constructor
|
||||
*/
|
||||
public function __construct( $only_hf = false ) {
|
||||
|
||||
// Elementor Frontend
|
||||
self::$elementor_instance = \Elementor\Plugin::instance();
|
||||
|
||||
// Ative Theme
|
||||
$this->current_theme = get_template();
|
||||
|
||||
// Royal Themes
|
||||
$this->royal_themes = ['ashe', 'ashe-pro', 'ashe-pro-premium', 'bard', 'bard-pro', 'bard-pro-premium'];
|
||||
|
||||
// Popular Themes
|
||||
if ( 'astra' === $this->current_theme ) {
|
||||
require_once(__DIR__ . '/../templates/views/astra/class-astra-compat.php');
|
||||
|
||||
} elseif ( 'generatepress' === $this->current_theme ) {
|
||||
require_once(__DIR__ . '/../templates/views/generatepress/class-generatepress-compat.php');
|
||||
|
||||
} elseif ( 'oceanwp' === $this->current_theme ) {
|
||||
require_once(__DIR__ . '/../templates/views/oceanwp/class-oceanwp-compat.php');
|
||||
|
||||
} elseif ( 'storefront' === $this->current_theme ) {
|
||||
require_once(__DIR__ . '/../templates/views/storefront/class-storefront-compat.php');
|
||||
|
||||
// Other Themes
|
||||
} else {
|
||||
add_action( 'wp', [ $this, 'global_compatibility' ] );
|
||||
}
|
||||
|
||||
// Scripts and Styles
|
||||
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
|
||||
|
||||
// Theme Builder
|
||||
if ( !$only_hf ) { // Prevent Loading in Header or Footer Templates
|
||||
add_filter( 'template_include', [ $this, 'convert_to_canvas' ], 12 ); // 12 after WP Pages and WooCommerce.
|
||||
add_action( 'elementor/page_templates/canvas/wpr_print_content', [ $this, 'canvas_page_content_display' ] );
|
||||
}
|
||||
}
|
||||
|
||||
public function global_compatibility() {
|
||||
add_action( 'get_header', [ $this, 'replace_header' ] );
|
||||
add_action( 'elementor/page_templates/canvas/before_content', [ $this, 'add_canvas_header' ] );
|
||||
|
||||
add_action( 'get_footer', [ $this, 'replace_footer' ] );
|
||||
add_action( 'elementor/page_templates/canvas/after_content', [ $this, 'add_canvas_footer' ], 9 );
|
||||
}
|
||||
|
||||
/**
|
||||
** Check if a Template has Conditions
|
||||
*/
|
||||
public function is_template_available( $type ) {
|
||||
if ( 'content' === $type ) {
|
||||
return !is_null(WPR_Conditions_Manager::canvas_page_content_display_conditions()) ? true : false;
|
||||
} else {
|
||||
$conditions = json_decode( get_option('wpr_'. $type .'_conditions', '[]'), true );
|
||||
$template = WPR_Conditions_Manager::header_footer_display_conditions( $conditions );
|
||||
|
||||
return (!empty( $conditions ) && !is_null($template)) ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Header
|
||||
*/
|
||||
public function replace_header() {
|
||||
if ( $this->is_template_available('header') ) {
|
||||
if ( ! in_array($this->current_theme, $this->royal_themes) ) {
|
||||
require __DIR__ . '/../templates/views/theme-header.php';
|
||||
} else {
|
||||
require __DIR__ . '/../templates/views/royal/theme-header-royal.php';
|
||||
}
|
||||
|
||||
$templates = [];
|
||||
$templates[] = 'header.php';
|
||||
|
||||
remove_all_actions( 'wp_head' ); // Avoid running wp_head hooks again.
|
||||
|
||||
ob_start();
|
||||
locate_template( $templates, true );
|
||||
ob_get_clean();
|
||||
}
|
||||
}
|
||||
|
||||
public function add_canvas_header() {
|
||||
if ( $this->is_template_available('header') ) {
|
||||
$conditions = json_decode( get_option('wpr_header_conditions', '[]'), true );
|
||||
$template_slug = WPR_Conditions_Manager::header_footer_display_conditions($conditions);
|
||||
$template_id = Utilities::get_template_id($template_slug);
|
||||
|
||||
if ( defined('ICL_LANGUAGE_CODE') ) {
|
||||
$default_language_code = apply_filters('wpml_default_language', null);
|
||||
$current_language_code = apply_filters( 'wpml_current_language', NULL );
|
||||
|
||||
IF ( ICL_LANGUAGE_CODE !== $default_language_code ) {
|
||||
$template_id = apply_filters('wpml_object_id', $template_id, 'wpr_templates', true, $default_language_code);
|
||||
}
|
||||
}
|
||||
|
||||
$show_on_canvas = get_post_meta($template_id, 'wpr_header_show_on_canvas', true);
|
||||
|
||||
// if ( !empty($show_on_canvas) && 'true' === $show_on_canvas && 0 === strpos($template_slug, 'user-header-') ) {
|
||||
if ( !empty($show_on_canvas) && 'true' === $show_on_canvas && !is_null($template_slug) ) {
|
||||
Utilities::render_elementor_template($template_slug);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Footer
|
||||
*/
|
||||
public function replace_footer() {
|
||||
if ( $this->is_template_available('footer') ) {
|
||||
if ( ! in_array($this->current_theme, $this->royal_themes) ) {
|
||||
require __DIR__ . '/../templates/views/theme-footer.php';
|
||||
} else {
|
||||
require __DIR__ . '/../templates/views/royal/theme-footer-royal.php';
|
||||
}
|
||||
|
||||
$templates = [];
|
||||
$templates[] = 'footer.php';
|
||||
|
||||
remove_all_actions( 'wp_footer' ); // Avoid running wp_footer hooks again.
|
||||
|
||||
ob_start();
|
||||
locate_template( $templates, true );
|
||||
ob_get_clean();
|
||||
}
|
||||
}
|
||||
|
||||
public function add_canvas_footer() {
|
||||
if ( $this->is_template_available('footer') ) {
|
||||
$conditions = json_decode( get_option('wpr_footer_conditions', '[]'), true );
|
||||
$template_slug = WPR_Conditions_Manager::header_footer_display_conditions($conditions);
|
||||
$template_id = Utilities::get_template_id($template_slug);
|
||||
|
||||
if ( defined('ICL_LANGUAGE_CODE') ) {
|
||||
$default_language_code = apply_filters('wpml_default_language', null);
|
||||
$current_language_code = apply_filters( 'wpml_current_language', NULL );
|
||||
|
||||
IF ( ICL_LANGUAGE_CODE !== $default_language_code ) {
|
||||
$template_id = apply_filters('wpml_object_id', $template_id, 'wpr_templates', true, $default_language_code);
|
||||
}
|
||||
}
|
||||
|
||||
$show_on_canvas = get_post_meta($template_id, 'wpr_footer_show_on_canvas', true);
|
||||
|
||||
// if ( !empty($show_on_canvas) && 'true' === $show_on_canvas && 0 === strpos($template_slug, 'user-footer-') ) {
|
||||
if ( !empty($show_on_canvas) && 'true' === $show_on_canvas && !is_null($template_slug) ) {
|
||||
Utilities::render_elementor_template($template_slug);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function convert_to_canvas( $template ) {
|
||||
$is_theme_builder_edit = \Elementor\Plugin::$instance->preview->is_preview_mode() && Utilities::is_theme_builder_template() ? true : false;
|
||||
$_wp_page_template = get_post_meta(get_the_ID(), '_wp_page_template', true);
|
||||
|
||||
if ( $this->is_template_available('content') || $is_theme_builder_edit ) {
|
||||
if ( (is_page() || is_single()) && 'elementor_canvas' === $_wp_page_template && !$is_theme_builder_edit ) {
|
||||
return $template;
|
||||
} else {
|
||||
return WPR_ADDONS_PATH . 'admin/templates/wpr-canvas.php';
|
||||
}
|
||||
} else {
|
||||
return $template;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Theme Builder Content Display
|
||||
*/
|
||||
public function canvas_page_content_display() {
|
||||
// Get Template
|
||||
$template = WPR_Conditions_Manager::canvas_page_content_display_conditions();
|
||||
|
||||
// Display Template
|
||||
Utilities::render_elementor_template( $template );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue styles and scripts.
|
||||
*/
|
||||
public function enqueue_scripts() {
|
||||
|
||||
if ( !class_exists( '\Elementor\Plugin' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Elementor Frontend // Maybe we dont need this (should be extra, because we have everything below)
|
||||
// self::$elementor_instance->frontend->enqueue_styles();
|
||||
|
||||
// if ( class_exists( '\ElementorPro\Plugin' ) ) {
|
||||
// $elementor_pro = \ElementorPro\Plugin::instance();
|
||||
// $elementor_pro->enqueue_frontend_scripts();
|
||||
// }
|
||||
|
||||
// Load Header Template CSS File
|
||||
$heder_conditions = json_decode( get_option('wpr_header_conditions', '[]'), true );
|
||||
$heder_template = WPR_Conditions_Manager::header_footer_display_conditions($heder_conditions);
|
||||
$header_template_id = !is_null($heder_template) ? Utilities::get_template_id($heder_template) : false;
|
||||
|
||||
if ( false !== $header_template_id ) {
|
||||
|
||||
// Load Header Template Assets (Elementor Widget)
|
||||
if ( ! self::$elementor_instance->preview->is_preview_mode() ) {
|
||||
$page_assets = get_post_meta( $header_template_id, Assets::ASSETS_META_KEY, true );
|
||||
if ( ! empty( $page_assets ) ) {
|
||||
self::$elementor_instance->assets_loader->enable_assets( $page_assets );
|
||||
}
|
||||
|
||||
$css_file = Post_CSS::create( get_the_ID() );
|
||||
$css_file->enqueue();
|
||||
}
|
||||
|
||||
// Header Template CSS File
|
||||
if ( class_exists( '\Elementor\Core\Files\CSS\Post' ) ) {
|
||||
$header_css_file = new \Elementor\Core\Files\CSS\Post( $header_template_id );
|
||||
} elseif ( class_exists( '\Elementor\Post_CSS_File' ) ) {
|
||||
$header_css_file = new \Elementor\Post_CSS_File( $header_template_id );
|
||||
}
|
||||
|
||||
$header_css_file->enqueue();
|
||||
}
|
||||
|
||||
// Load Footer Template CSS File
|
||||
$footer_conditions = json_decode( get_option('wpr_footer_conditions', '[]'), true );
|
||||
$footer_template = WPR_Conditions_Manager::header_footer_display_conditions($footer_conditions);
|
||||
$footer_template_id = !is_null($footer_template) ? Utilities::get_template_id($footer_template) : false;
|
||||
|
||||
if ( false !== $footer_template_id ) {
|
||||
// Load Footer Template Assets (Elementor Widget)
|
||||
if ( ! self::$elementor_instance->preview->is_preview_mode() ) {
|
||||
$page_assets = get_post_meta( $footer_template_id, Assets::ASSETS_META_KEY, true );
|
||||
if ( ! empty( $page_assets ) ) {
|
||||
self::$elementor_instance->assets_loader->enable_assets( $page_assets );
|
||||
}
|
||||
|
||||
$css_file = Post_CSS::create( get_the_ID() );
|
||||
$css_file->enqueue();
|
||||
}
|
||||
|
||||
// Footer Template CSS File
|
||||
if ( class_exists( '\Elementor\Core\Files\CSS\Post' ) ) {
|
||||
$footer_css_file = new \Elementor\Core\Files\CSS\Post( $footer_template_id );
|
||||
} elseif ( class_exists( '\Elementor\Post_CSS_File' ) ) {
|
||||
$footer_css_file = new \Elementor\Post_CSS_File( $footer_template_id );
|
||||
}
|
||||
|
||||
$footer_css_file->enqueue();
|
||||
}
|
||||
|
||||
// Load Canvas Content Template CSS File
|
||||
$canvas_conditions = WPR_Conditions_Manager::canvas_page_content_display_conditions();
|
||||
$canvas_template_id = !empty($canvas_conditions) ? Utilities::get_template_id($canvas_conditions) : false;
|
||||
|
||||
if ( false !== $canvas_template_id ) {
|
||||
if ( class_exists( '\Elementor\Core\Files\CSS\Post' ) ) {
|
||||
$footer_css_file = new \Elementor\Core\Files\CSS\Post( $canvas_template_id );
|
||||
} elseif ( class_exists( '\Elementor\Post_CSS_File' ) ) {
|
||||
$footer_css_file = new \Elementor\Post_CSS_File( $canvas_template_id );
|
||||
}
|
||||
|
||||
$footer_css_file->enqueue();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,569 @@
|
||||
<?php
|
||||
namespace WprAddons\Admin\Includes;
|
||||
|
||||
use WprAddons\Plugin;
|
||||
use Elementor\TemplateLibrary\Source_Base;
|
||||
use Elementor\Core\Common\Modules\Ajax\Module as Ajax;
|
||||
use WprAddons\Classes\Utilities;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* WPR_Templates_Actions setup
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class WPR_Templates_Actions {
|
||||
|
||||
/**
|
||||
** Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
// Save Conditions
|
||||
add_action( 'wp_ajax_wpr_save_template_conditions', [ $this, 'wpr_save_template_conditions' ] );
|
||||
|
||||
// Create Template
|
||||
add_action( 'wp_ajax_wpr_create_template', [ $this, 'wpr_create_template' ] );
|
||||
|
||||
// Import Library Template
|
||||
add_action( 'wp_ajax_wpr_import_library_template', [ $this, 'wpr_import_library_template' ] );
|
||||
|
||||
// Reset Template
|
||||
add_action( 'wp_ajax_wpr_delete_template', [ $this, 'wpr_delete_template' ] );
|
||||
|
||||
// Register Elementor AJAX Actions
|
||||
add_action( 'elementor/ajax/register_actions', [ $this, 'register_elementor_ajax_actions' ] );
|
||||
|
||||
// Enqueue Scripts
|
||||
add_action( 'admin_enqueue_scripts', [ $this, 'templates_library_scripts' ] );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
** Save Template Conditions
|
||||
*/
|
||||
public function wpr_save_template_conditions() {
|
||||
|
||||
$nonce = $_POST['nonce'];
|
||||
|
||||
if ( !wp_verify_nonce( $nonce, 'wpr-plugin-options-js') || !current_user_can( 'manage_options' ) ) {
|
||||
exit; // Get out of here, the nonce is rotten!
|
||||
}
|
||||
|
||||
$template = isset($_POST['template']) ? sanitize_text_field(wp_unslash($_POST['template'])): false;
|
||||
|
||||
// Header
|
||||
if ( isset($_POST['wpr_header_conditions']) ) {
|
||||
update_option( 'wpr_header_conditions', $this->sanitize_conditions($_POST['wpr_header_conditions']) ); // phpcs:ignore
|
||||
|
||||
$wpr_header_show_on_canvas = isset($_POST['wpr_header_show_on_canvas']) ? sanitize_text_field(wp_unslash($_POST['wpr_header_show_on_canvas'])): false;
|
||||
if ( $wpr_header_show_on_canvas && $template ) {
|
||||
update_post_meta( Utilities::get_template_id($template), 'wpr_header_show_on_canvas', $wpr_header_show_on_canvas );
|
||||
}
|
||||
}
|
||||
|
||||
// Footer
|
||||
if ( isset($_POST['wpr_footer_conditions']) ) {
|
||||
update_option( 'wpr_footer_conditions', $this->sanitize_conditions($_POST['wpr_footer_conditions']) ); // phpcs:ignore
|
||||
|
||||
$wpr_footer_show_on_canvas = isset($_POST['wpr_footer_show_on_canvas']) ? sanitize_text_field(wp_unslash($_POST['wpr_footer_show_on_canvas'])): false;
|
||||
if ( $wpr_footer_show_on_canvas && $template ) {
|
||||
update_post_meta( Utilities::get_template_id($template), 'wpr_footer_show_on_canvas', $wpr_footer_show_on_canvas );
|
||||
}
|
||||
}
|
||||
|
||||
// Archive
|
||||
if ( isset($_POST['wpr_archive_conditions']) ) {
|
||||
update_option( 'wpr_archive_conditions', $this->sanitize_conditions($_POST['wpr_archive_conditions']) ); // phpcs:ignore
|
||||
}
|
||||
|
||||
// Single
|
||||
if ( isset($_POST['wpr_single_conditions']) ) {
|
||||
update_option( 'wpr_single_conditions', $this->sanitize_conditions($_POST['wpr_single_conditions']) ); // phpcs:ignore
|
||||
}
|
||||
|
||||
// Product Archive
|
||||
if ( isset($_POST['wpr_product_archive_conditions']) ) {
|
||||
update_option( 'wpr_product_archive_conditions', $this->sanitize_conditions($_POST['wpr_product_archive_conditions']) ); // phpcs:ignore
|
||||
}
|
||||
|
||||
// Product Single
|
||||
if ( isset($_POST['wpr_product_single_conditions']) ) {
|
||||
update_option( 'wpr_product_single_conditions', $this->sanitize_conditions($_POST['wpr_product_single_conditions']) ); // phpcs:ignore
|
||||
}
|
||||
|
||||
// Popup
|
||||
if ( isset($_POST['wpr_popup_conditions']) ) {
|
||||
update_option( 'wpr_popup_conditions', $this->sanitize_conditions($_POST['wpr_popup_conditions']) ); // phpcs:ignore
|
||||
}
|
||||
}
|
||||
|
||||
public function sanitize_conditions( $data ) {
|
||||
return wp_unslash( json_encode( array_filter( json_decode(stripcslashes($data), true) ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
** Create Template
|
||||
*/
|
||||
public function wpr_create_template() {
|
||||
|
||||
$nonce = $_POST['nonce'];
|
||||
|
||||
if ( !wp_verify_nonce( $nonce, 'wpr-plugin-options-js') || !current_user_can( 'manage_options' ) ) {
|
||||
exit; // Get out of here, the nonce is rotten!
|
||||
}
|
||||
|
||||
$user_template_type = isset($_POST['user_template_type']) ? sanitize_text_field(wp_unslash($_POST['user_template_type'])): false;
|
||||
$user_template_library = isset($_POST['user_template_library']) ? sanitize_text_field(wp_unslash($_POST['user_template_library'])): false;
|
||||
$user_template_title = isset($_POST['user_template_title']) ? sanitize_text_field(wp_unslash($_POST['user_template_title'])): false;
|
||||
$user_template_slug = isset($_POST['user_template_slug']) ? sanitize_text_field(wp_unslash($_POST['user_template_slug'])): false;
|
||||
|
||||
$check_post_type =( $user_template_library == 'wpr_templates' || $user_template_library == 'elementor_library' );
|
||||
|
||||
if ( $user_template_title && $check_post_type ) {
|
||||
// Create
|
||||
$template_id = wp_insert_post(array (
|
||||
'post_type' => $user_template_library,
|
||||
'post_title' => $user_template_title,
|
||||
'post_name' => $user_template_slug,
|
||||
'post_content' => '',
|
||||
'post_status' => 'publish'
|
||||
));
|
||||
|
||||
// Set Types
|
||||
if ( 'wpr_templates' === $_POST['user_template_library'] ) {
|
||||
|
||||
wp_set_object_terms( $template_id, [$user_template_type, 'user'], 'wpr_template_type' );
|
||||
|
||||
if ( 'popup' === $_POST['user_template_type'] ) {
|
||||
update_post_meta( $template_id, '_elementor_template_type', 'wpr-popups' );
|
||||
} else {
|
||||
if ( 'header' === $_POST['user_template_type'] ) {
|
||||
update_post_meta( $template_id, '_elementor_template_type', 'wpr-theme-builder-header' );
|
||||
} elseif ( 'footer' === $_POST['user_template_type'] ) {
|
||||
update_post_meta( $template_id, '_elementor_template_type', 'wpr-theme-builder-footer' );
|
||||
} else {
|
||||
update_post_meta( $template_id, '_elementor_template_type', 'wpr-theme-builder' );
|
||||
}
|
||||
|
||||
update_post_meta( $template_id, '_wpr_template_type', $user_template_type );
|
||||
}
|
||||
} else {
|
||||
update_post_meta( $template_id, '_elementor_template_type', 'page' );
|
||||
}
|
||||
|
||||
// Set Canvas Template
|
||||
update_post_meta( $template_id, '_wp_page_template', 'elementor_canvas' ); //tmp - maybe set for wpr_templates only
|
||||
|
||||
// Send ID to JS
|
||||
echo esc_html($template_id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Import Library Template
|
||||
*/
|
||||
public function wpr_import_library_template() {
|
||||
|
||||
$nonce = $_POST['nonce'];
|
||||
|
||||
if ( !wp_verify_nonce( $nonce, 'wpr-addons-library-frontend-js') || !current_user_can( 'manage_options' ) ) {
|
||||
exit; // Get out of here, the nonce is rotten!
|
||||
}
|
||||
|
||||
$source = new WPR_Library_Source();
|
||||
$slug = isset($_POST['slug']) ? sanitize_text_field(wp_unslash($_POST['slug'])) : '';
|
||||
$kit = isset($_POST['kit']) ? sanitize_text_field(wp_unslash($_POST['kit'])) : '';
|
||||
$section = isset($_POST['section']) ? sanitize_text_field(wp_unslash($_POST['section'])) : '';
|
||||
|
||||
$data = $source->get_data([
|
||||
'template_id' => $slug,
|
||||
'kit_id' => $kit,
|
||||
'section_id' => $section
|
||||
]);
|
||||
|
||||
$template = '' !== $kit ? $kit : $slug;
|
||||
if ( $this->vts($slug) ) {
|
||||
echo json_encode($data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Validate Template
|
||||
*/
|
||||
public function vts( $template ) {
|
||||
// Avoid Cache
|
||||
$randomNum = substr(str_shuffle("0123456789abcdefghijklmnopqrstvwxyzABCDEFGHIJKLMNOPQRSTVWXYZ"), 0, 7);
|
||||
|
||||
$remote_file_url = 'https://royal-elementor-addons.com/library/vts.json?='. $randomNum;
|
||||
|
||||
$tmp_file = download_url( $remote_file_url );
|
||||
|
||||
$file_args = [
|
||||
'name' => 'vts.json',
|
||||
'tmp_name' => $tmp_file,
|
||||
'error' => 0,
|
||||
'size' => filesize( $tmp_file ),
|
||||
];
|
||||
|
||||
$defaults = array(
|
||||
'test_form' => false,
|
||||
'test_size' => true,
|
||||
'test_upload' => true,
|
||||
'mimes' => [
|
||||
'xml' => 'text/xml',
|
||||
'json' => 'text/plain',
|
||||
],
|
||||
'wp_handle_sideload' => 'upload',
|
||||
);
|
||||
|
||||
$local_file = wp_handle_sideload( $file_args, $defaults );
|
||||
|
||||
if ( isset( $local_file['error'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$tmps = json_decode(file_get_contents($local_file['file']));
|
||||
|
||||
// Delete Import File
|
||||
unlink( $local_file['file'] );
|
||||
|
||||
return in_array($template, $tmps) && (!defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->can_use_premium_code()) ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
** Reset Template
|
||||
*/
|
||||
public function wpr_delete_template() {
|
||||
|
||||
$nonce = $_POST['nonce'];
|
||||
|
||||
if ( !wp_verify_nonce( $nonce, 'delete_post-' . $_POST['template_slug'] ) || !current_user_can( 'manage_options' ) ) {
|
||||
exit; // Get out of here, the nonce is rotten!
|
||||
}
|
||||
|
||||
$template_slug = isset($_POST['template_slug']) ? sanitize_text_field(wp_unslash($_POST['template_slug'])): '';
|
||||
$template_library = isset($_POST['template_library']) ? sanitize_text_field(wp_unslash($_POST['template_library'])): '';
|
||||
|
||||
$post = get_page_by_path( $template_slug, OBJECT, $template_library );
|
||||
|
||||
if ( get_post_type($post->ID) == 'wpr_templates' || get_post_type($post->ID) == 'elementor_library' ) {
|
||||
wp_delete_post( $post->ID, true );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Enqueue Scripts and Styles
|
||||
*/
|
||||
public function templates_library_scripts( $hook ) {
|
||||
|
||||
// Get Plugin Version
|
||||
$version = Plugin::instance()->get_version();
|
||||
|
||||
$screen = get_current_screen();
|
||||
|
||||
|
||||
if ( $screen->id === 'edit-wpr_templates' ) {
|
||||
$custom_css = '
|
||||
.wpr-templates-cat-select,
|
||||
.wpr-templates-cat-select option,
|
||||
.wpr-templates-cat-select option:checked {
|
||||
text-transform: capitalize !important;
|
||||
}
|
||||
';
|
||||
|
||||
wp_add_inline_style( 'wp-admin', $custom_css );
|
||||
}
|
||||
|
||||
// Deny if NOT Plugin Page
|
||||
if ( 'toplevel_page_wpr-addons' == $hook || strpos($hook, 'wpr-theme-builder') || strpos($hook, 'wpr-popups') ) {
|
||||
|
||||
// Color Picker
|
||||
wp_enqueue_style( 'wp-color-picker' );
|
||||
wp_enqueue_script( 'wp-color-picker-alpha', WPR_ADDONS_URL .'assets/js/admin/lib/wp-color-picker-alpha.min.js', ['jquery', 'wp-color-picker'], $version, true );
|
||||
|
||||
// Media Upload
|
||||
if ( ! did_action( 'wp_enqueue_media' ) ) {
|
||||
wp_enqueue_media();
|
||||
}
|
||||
|
||||
// enqueue CSS
|
||||
wp_enqueue_style( 'wpr-plugin-options-css', WPR_ADDONS_URL .'assets/css/admin/plugin-options.css', [], $version );
|
||||
|
||||
// enqueue JS
|
||||
wp_enqueue_script( 'wpr-plugin-options-js', WPR_ADDONS_URL .'assets/js/admin/plugin-options.js', ['jquery'], $version );
|
||||
|
||||
wp_localize_script(
|
||||
'wpr-plugin-options-js',
|
||||
'WprPluginOptions', // This is used in the js file to group all of your scripts together
|
||||
[
|
||||
'nonce' => wp_create_nonce( 'wpr-plugin-options-js' ),
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if ( strpos($hook, 'wpr-templates-kit') ) {
|
||||
wp_enqueue_style( 'wpr-templates-kit-css', WPR_ADDONS_URL .'assets/css/admin/templates-kit.css', [], $version );
|
||||
wp_enqueue_script( 'wpr-templates-kit-js', WPR_ADDONS_URL .'assets/js/admin/templates-kit.js', ['jquery', 'updates'], $version );
|
||||
|
||||
wp_localize_script(
|
||||
'wpr-templates-kit-js',
|
||||
'WprTemplatesKitLoc', // This is used in the js file to group all of your scripts together
|
||||
[
|
||||
'ajaxurl' => admin_url( 'admin-ajax.php' ),
|
||||
'resturl' => get_rest_url() . 'wpraddons/v1',
|
||||
'nonce' => wp_create_nonce( 'wpr-templates-kit-js' ),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if ( strpos($hook, 'wpr-premade-blocks') ) {
|
||||
wp_enqueue_style( 'wpr-premade-blocks-css', WPR_ADDONS_URL .'assets/css/admin/premade-blocks.css', [], $version );
|
||||
|
||||
wp_enqueue_script( 'wpr-macy-js', WPR_ADDONS_URL .'assets/js/lib/macy/macy.js', ['jquery'], $version );
|
||||
wp_enqueue_script( 'wpr-premade-blocks-js', WPR_ADDONS_URL .'assets/js/admin/premade-blocks.js', ['jquery'], $version );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Register Elementor AJAX Actions
|
||||
*/
|
||||
public function register_elementor_ajax_actions( Ajax $ajax ) {
|
||||
|
||||
// Elementor Search Data
|
||||
$ajax->register_ajax_action( 'wpr_elementor_search_data', function( $data ) {
|
||||
// Freemius OptIn
|
||||
if ( ! (wpr_fs()->is_registered() && wpr_fs()->is_tracking_allowed() || wpr_fs()->is_pending_activation() )) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( strlen($data['search_query']) > 25 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Send Search Query
|
||||
wp_remote_post( 'https://reastats.kinsta.cloud/wp-json/elementor-search/data', [
|
||||
'body' => [
|
||||
'search_query' => $data['search_query']
|
||||
]
|
||||
] );
|
||||
} );
|
||||
|
||||
// Templates Library Pages Search Data
|
||||
$ajax->register_ajax_action( 'wpr_templates_library_search_data', function( $data ) {
|
||||
// Freemius OptIn
|
||||
if ( ! (wpr_fs()->is_registered() && wpr_fs()->is_tracking_allowed() || wpr_fs()->is_pending_activation() )) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( strlen($data['search_query']) > 25 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Send Search Query
|
||||
wp_remote_post( 'https://reastats.kinsta.cloud/wp-json/templates-library-search/data', [
|
||||
'body' => [
|
||||
'search_query' => $data['search_query']
|
||||
]
|
||||
] );
|
||||
} );
|
||||
|
||||
// Templates Library Blocks Search Data
|
||||
$ajax->register_ajax_action( 'wpr_templates_library_blocks_search_data', function( $data ) {
|
||||
// Freemius OptIn
|
||||
if ( ! (wpr_fs()->is_registered() && wpr_fs()->is_tracking_allowed() || wpr_fs()->is_pending_activation() )) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( strlen($data['search_query']) > 25 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Send Search Query
|
||||
wp_remote_post( 'https://reastats.kinsta.cloud/wp-json/templates-library-blocks-search/data', [
|
||||
'body' => [
|
||||
'search_query' => $data['search_query']
|
||||
]
|
||||
] );
|
||||
} );
|
||||
|
||||
// Templates Library Sections Search Data
|
||||
$ajax->register_ajax_action( 'wpr_templates_library_sections_search_data', function( $data ) {
|
||||
// Freemius OptIn
|
||||
if ( ! (wpr_fs()->is_registered() && wpr_fs()->is_tracking_allowed() || wpr_fs()->is_pending_activation() )) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( strlen($data['search_query']) > 25 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Send Search Query
|
||||
wp_remote_post( 'https://reastats.kinsta.cloud/wp-json/templates-library-sections-search/data', [
|
||||
'body' => [
|
||||
'search_query' => $data['search_query']
|
||||
]
|
||||
] );
|
||||
} );
|
||||
|
||||
// Library Template Import Finished
|
||||
$ajax->register_ajax_action( 'wpr_library_template_import_finished', function( $data ) {
|
||||
Utilities::regenerate_extra_image_sizes();
|
||||
|
||||
// Freemius OptIn
|
||||
if ( ! (wpr_fs()->is_registered() && wpr_fs()->is_tracking_allowed() || wpr_fs()->is_pending_activation() )) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Templates Library Import Block
|
||||
if ( isset($data['block'])) {
|
||||
wp_remote_post( 'https://reastats.kinsta.cloud/wp-json/templates-library-blocks-import/data', [
|
||||
'body' => [
|
||||
'imported_block' => $data['block']
|
||||
]
|
||||
] );
|
||||
}
|
||||
|
||||
// Templates Library Import Section
|
||||
if ( isset($data['section'])) {
|
||||
wp_remote_post( 'https://reastats.kinsta.cloud/wp-json/templates-library-sections-import/data', [
|
||||
'body' => [
|
||||
'imported_section' => $data['section']
|
||||
]
|
||||
] );
|
||||
}
|
||||
|
||||
if ( ! isset($data['kit']) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Templates Library Import Template
|
||||
wp_remote_post( 'https://reastats.kinsta.cloud/wp-json/templates-library-import/data', [
|
||||
'body' => [
|
||||
'imported_template' => $data['kit'] .'-'. $data['template'] . ' *'. WPR_ADDONS_VERSION .'*'
|
||||
]
|
||||
] );
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* WPR_Templates_Actions setup
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class WPR_Library_Source extends \Elementor\TemplateLibrary\Source_Base {
|
||||
|
||||
public function get_id() {
|
||||
return 'wpr-layout-manager';
|
||||
}
|
||||
|
||||
public function get_title() {
|
||||
return 'WPR Layout Manager';
|
||||
}
|
||||
|
||||
public function register_data() {}
|
||||
|
||||
public function save_item( $template_data ) {
|
||||
return new \WP_Error( 'invalid_request', 'Cannot save template to a WPR layout manager' );
|
||||
}
|
||||
|
||||
public function update_item( $new_data ) {
|
||||
return new \WP_Error( 'invalid_request', 'Cannot update template to a WPR layout manager' );
|
||||
}
|
||||
|
||||
public function delete_template( $template_id ) {
|
||||
return new \WP_Error( 'invalid_request', 'Cannot delete template from a WPR layout manager' );
|
||||
}
|
||||
|
||||
public function export_template( $template_id ) {
|
||||
return new \WP_Error( 'invalid_request', 'Cannot export template from a WPR layout manager' );
|
||||
}
|
||||
|
||||
public function get_items( $args = [] ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function get_item( $template_id ) {
|
||||
$templates = $this->get_items();
|
||||
|
||||
return $templates[ $template_id ];
|
||||
}
|
||||
|
||||
public function request_template_data( $template_id, $kit_id, $section_id ) {
|
||||
if ( empty( $template_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( '' !== $kit_id ) {
|
||||
$url = 'https://royal-elementor-addons.com/library/templates-kit/'. $kit_id .'/';
|
||||
} elseif ( '' !== $section_id ) {
|
||||
$url = 'https://royal-elementor-addons.com/library/premade-sections/';
|
||||
// $url = 'https://royal-elementor-addons.com/library/premade-sections/'. $kit_id .'/';
|
||||
} else {
|
||||
$url = 'https://royal-elementor-addons.com/library/premade-styles/';
|
||||
}
|
||||
|
||||
// Avoid Cache
|
||||
$randomNum = substr(str_shuffle("0123456789abcdefghijklmnopqrstvwxyzABCDEFGHIJKLMNOPQRSTVWXYZ"), 0, 7);
|
||||
|
||||
$response = wp_remote_get($url . $template_id .'.json?='. $randomNum, [
|
||||
'timeout' => 60,
|
||||
'sslverify' => false
|
||||
] );
|
||||
|
||||
return wp_remote_retrieve_body( $response );
|
||||
}
|
||||
|
||||
public function get_data( array $args ) {
|
||||
$data = $this->request_template_data( $args['template_id'], $args['kit_id'], $args['section_id'] );
|
||||
|
||||
$data = json_decode( $data, true );
|
||||
|
||||
if ( empty( $data ) || empty( $data['content'] ) ) {
|
||||
throw new \Exception( 'Template does not have any content' );
|
||||
}
|
||||
|
||||
add_filter( 'intermediate_image_sizes_advanced', [new Utilities, 'disable_extra_image_sizes'], 10, 3 );
|
||||
|
||||
// Remove Parallax Images from Import File
|
||||
foreach( $data['content'] as $key => $content ) {
|
||||
if ( isset($data['content'][$key]['settings']['bg_image']) ) {
|
||||
unset($data['content'][$key]['settings']['bg_image']);
|
||||
}
|
||||
if ( isset($data['content'][$key]['settings']['hover_parallax']) ) {
|
||||
unset($data['content'][$key]['settings']['hover_parallax']);
|
||||
}
|
||||
}
|
||||
|
||||
$parallax_bg = get_option('wpr-parallax-background', 'on');
|
||||
$parallax_multi = get_option('wpr-parallax-multi-layer', 'on');
|
||||
|
||||
// Disable Extensions during Import
|
||||
if ( 'on' === $parallax_bg ) {
|
||||
update_option('wpr-parallax-background', '');
|
||||
}
|
||||
if ( 'on' === $parallax_multi ) {
|
||||
update_option('wpr-parallax-multi-layer', '');
|
||||
}
|
||||
|
||||
$data['content'] = $this->replace_elements_ids( $data['content'] );
|
||||
$data['content'] = $this->process_export_import_content( $data['content'], 'on_import' );
|
||||
|
||||
// Enable Back
|
||||
if ( 'on' === $parallax_bg ) {
|
||||
update_option('wpr-parallax-background', 'on');
|
||||
}
|
||||
if ( 'on' === $parallax_multi ) {
|
||||
update_option('wpr-parallax-multi-layer', 'on');
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
namespace WprAddons\Admin\Includes;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* WPR_Templates_Category_Filter setup
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class WPR_Templates_Category_Filter {
|
||||
|
||||
/**
|
||||
** Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
// $which (the position of the filters form) is either 'top' or 'bottom'
|
||||
add_action( 'restrict_manage_posts', function ( $post_type, $which ) {
|
||||
if ( 'top' === $which && 'wpr_templates' === $post_type ) {
|
||||
$taxonomy = 'wpr_template_type';
|
||||
$tax = get_taxonomy( $taxonomy ); // get the taxonomy object/data
|
||||
$cat = filter_input( INPUT_GET, $taxonomy ); // get the selected category slug
|
||||
|
||||
echo '<label class="screen-reader-text" for="wpr_template_type">Filter by ' .
|
||||
esc_html( $tax->labels->singular_name ) . '</label>';
|
||||
|
||||
wp_dropdown_categories( [
|
||||
'walker' => new WPR_Custom_Walker_CategoryDropdown(),
|
||||
'class' => 'wpr-templates-cat-select',
|
||||
'show_option_all' => $tax->labels->all_items,
|
||||
'hide_empty' => 0, // include categories that have no posts
|
||||
'hierarchical' => $tax->hierarchical,
|
||||
'show_count' => 0, // don't show the category's posts count
|
||||
'orderby' => 'name',
|
||||
'selected' => $cat,
|
||||
'taxonomy' => $taxonomy,
|
||||
'name' => $taxonomy,
|
||||
'value_field' => 'slug',
|
||||
] );
|
||||
}
|
||||
}, 10, 2 );
|
||||
}
|
||||
}
|
||||
|
||||
new WPR_Templates_Category_Filter();
|
||||
|
||||
class WPR_Custom_Walker_CategoryDropdown extends \Walker_CategoryDropdown {
|
||||
function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
|
||||
$pad = str_repeat(' ', $depth * 3);
|
||||
|
||||
// Here you can modify the category name
|
||||
$cat_name = apply_filters('list_cats', $category->name, $category);
|
||||
|
||||
// Customization example: append count
|
||||
if( $args['show_count'] ) {
|
||||
$cat_name .= ' ('. $category->count .')';
|
||||
}
|
||||
|
||||
$output .= "\t<option class=\"level-$depth\" value=\"".$category->slug."\"";
|
||||
if ( $category->slug == $args['selected'] ) {
|
||||
$output .= ' selected="selected"';
|
||||
}
|
||||
$output .= '>';
|
||||
$output .= str_replace('_', ' ', $pad.$cat_name);
|
||||
if ( $args['show_count'] ) {
|
||||
$output .= ' ('. $category->count .')';
|
||||
}
|
||||
$output .= "</option>\n";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
use WprAddons\Admin\Includes\WPR_Render_Templates;
|
||||
use WprAddons\Admin\Includes\WPR_Templates_Shortcode;
|
||||
use WprAddons\Admin\Includes\WPR_Templates_Modal_Popups;
|
||||
use WprAddons\Admin\Includes\WPR_Templates_Actions;
|
||||
use WprAddons\Admin\Templates\Library\WPR_Templates_Library_Blocks;
|
||||
use WprAddons\Admin\Templates\Library\WPR_Templates_Library_Sections;
|
||||
use WprAddons\Admin\Templates\Library\WPR_Templates_Library_Pages;
|
||||
use WprAddons\Admin\Templates\Library\WPR_Templates_Library_Popups;
|
||||
use WprAddons\Classes\Utilities;
|
||||
|
||||
/**
|
||||
* WPR_Templates_Library setup
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class WPR_Templates_Library {
|
||||
|
||||
/**
|
||||
** Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
// Register CPTs
|
||||
add_action( 'init', [ $this, 'register_templates_library_cpt' ] );
|
||||
add_action( 'template_redirect', [ $this, 'block_template_frontend' ] );
|
||||
add_action( 'current_screen', [ $this, 'redirect_to_options_page' ] );
|
||||
|
||||
// Templates Shortcode
|
||||
new WPR_Templates_Shortcode();
|
||||
|
||||
// Init Popups
|
||||
new WPR_Templates_Modal_Popups();
|
||||
|
||||
// Init Theme Builder
|
||||
new WPR_Render_Templates();
|
||||
|
||||
// Template Actions
|
||||
new WPR_Templates_Actions();
|
||||
|
||||
// Add Blocks to Library
|
||||
new WPR_Templates_Library_Blocks();
|
||||
|
||||
// Add Sections to Library
|
||||
new WPR_Templates_Library_Sections();
|
||||
|
||||
// Add Pages to Library
|
||||
new WPR_Templates_Library_Pages();
|
||||
|
||||
// Add Popups to Library
|
||||
new WPR_Templates_Library_Popups();
|
||||
|
||||
// Enable Elementor for 'wpr_templates'
|
||||
$this->add_elementor_cpt_support();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
** Register Templates Library
|
||||
*/
|
||||
public function redirect_to_options_page() {
|
||||
if ( get_current_screen()->post_type == 'wpr_templates' && isset($_GET['action']) && $_GET['action'] == 'edit' ) {
|
||||
$elementor_template_type = isset($_GET['post']) ? sanitize_text_field(wp_unslash($_GET['post'])) : '';
|
||||
|
||||
if ( 'wpr-popups' === Utilities::get_elementor_template_type( $elementor_template_type ) ) {
|
||||
wp_redirect('admin.php?page=wpr-popups');
|
||||
} else {
|
||||
wp_redirect('admin.php?page=wpr-theme-builder');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function register_templates_library_cpt() {
|
||||
|
||||
$args = array(
|
||||
'label' => esc_html__( 'Royal Templates', 'wpr-addons' ),
|
||||
'public' => true,
|
||||
'rewrite' => false,
|
||||
'show_ui' => true,
|
||||
'show_in_menu' => false,
|
||||
'show_in_nav_menus' => false,
|
||||
'exclude_from_search' => true,
|
||||
'capability_type' => 'post',
|
||||
'hierarchical' => false,
|
||||
);
|
||||
|
||||
register_post_type( 'wpr_templates', $args );
|
||||
|
||||
$tax_args = [
|
||||
'hierarchical' => true,
|
||||
'show_ui' => true,
|
||||
'show_in_nav_menus' => false,
|
||||
'show_admin_column' => true,
|
||||
'query_var' => is_admin(),
|
||||
'rewrite' => false,
|
||||
'public' => false,
|
||||
];
|
||||
|
||||
register_taxonomy( 'wpr_template_type', 'wpr_templates', $tax_args );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
** Don't display on the frontend for non edit_posts capable users
|
||||
*/
|
||||
public function block_template_frontend() {
|
||||
if ( is_singular( 'wpr_templates' ) && ! current_user_can( 'edit_posts' ) ) {
|
||||
wp_redirect( site_url(), 301 );
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*** Add elementor support for wpr_templates.
|
||||
**/
|
||||
function add_elementor_cpt_support() {
|
||||
if ( ! is_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$cpt_support = get_option( 'elementor_cpt_support' );
|
||||
|
||||
if ( ! $cpt_support ) {
|
||||
update_option( 'elementor_cpt_support', ['post', 'page', 'wpr_templates'] );
|
||||
} elseif ( ! in_array( 'wpr_templates', $cpt_support ) ) {
|
||||
$cpt_support[] = 'wpr_templates';
|
||||
update_option( 'elementor_cpt_support', $cpt_support );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
new WPR_Templates_Library();
|
||||
@@ -0,0 +1,524 @@
|
||||
<?php
|
||||
|
||||
namespace WprAddons\Admin\Includes;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
use WprAddons\Classes\Utilities;
|
||||
|
||||
/**
|
||||
** WPR_Templates_Loop setup
|
||||
*/
|
||||
class WPR_Templates_Loop {
|
||||
|
||||
/**
|
||||
** Loop Through Custom Templates
|
||||
*/
|
||||
public static function render_theme_builder_templates( $template ) {
|
||||
// WP_Query arguments
|
||||
$args = array (
|
||||
'post_type' => array( 'wpr_templates' ),
|
||||
'post_status' => array( 'publish' ),
|
||||
'posts_per_page' => -1,
|
||||
'tax_query' => array(
|
||||
array(
|
||||
'taxonomy' => 'wpr_template_type',
|
||||
'field' => 'slug',
|
||||
'terms' => [ $template, 'user' ],
|
||||
'operator' => 'AND'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// The Query
|
||||
$user_templates = get_posts( $args );
|
||||
|
||||
// The Loop
|
||||
echo '<ul class="wpr-'. esc_attr($template) .'-templates-list wpr-my-templates-list" data-pro="'. esc_attr(defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->can_use_premium_code()) .'">';
|
||||
|
||||
if ( ! empty( $user_templates ) ) {
|
||||
foreach ( $user_templates as $user_template ) {
|
||||
$slug = $user_template->post_name;
|
||||
|
||||
if ( !str_contains( $slug, 'user-' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$edit_url = str_replace( 'edit', 'elementor', get_edit_post_link( $user_template->ID ) );
|
||||
$show_on_canvas = get_post_meta(Utilities::get_template_id($slug), 'wpr_'. $template .'_show_on_canvas', true);
|
||||
|
||||
echo '<li>';
|
||||
echo '<h3 class="wpr-title">'. esc_html($user_template->post_title) .'</h3>';
|
||||
|
||||
echo '<div class="wpr-action-buttons">';
|
||||
// Activate
|
||||
echo '<span class="wpr-template-conditions button button-primary" data-slug="'. esc_attr($slug) .'" data-show-on-canvas="'. esc_attr($show_on_canvas) .'">'. esc_html__( 'Manage Conditions', 'wpr-addons' ) .'</span>';
|
||||
// Edit
|
||||
echo '<a href="'. esc_url($edit_url) .'" class="wpr-edit-template button button-primary">'. esc_html__( 'Edit Template', 'wpr-addons' ) .'</a>';
|
||||
|
||||
// Delete
|
||||
$one_time_nonce = wp_create_nonce( 'delete_post-' . $slug );
|
||||
|
||||
echo '<span class="wpr-delete-template button button-primary" data-nonce="'. esc_attr($one_time_nonce) .'" data-slug="'. esc_attr($slug) .'" data-warning="'. esc_html__( 'Are you sure you want to delete this template?', 'wpr-addons' ) .'"><span class="dashicons dashicons-no-alt"></span></span>';
|
||||
|
||||
|
||||
echo '</div>';
|
||||
echo '</li>';
|
||||
}
|
||||
} else {
|
||||
echo '<li class="wpr-no-templates">You don\'t have any templates yet!</li>';
|
||||
}
|
||||
|
||||
echo '</ul>';
|
||||
|
||||
// Restore original Post Data
|
||||
wp_reset_postdata();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
** Loop Through My Templates
|
||||
*/
|
||||
public static function render_elementor_saved_templates() {
|
||||
|
||||
// WP_Query arguments
|
||||
$args = array (
|
||||
'post_type' => array( 'elementor_library' ),
|
||||
'post_status' => array( 'publish' ),
|
||||
'meta_key' => '_elementor_template_type',
|
||||
'meta_value' => ['page', 'section'],
|
||||
'numberposts' => -1
|
||||
);
|
||||
|
||||
// The Query
|
||||
$user_templates = get_posts( $args );
|
||||
|
||||
// My Templates List
|
||||
echo '<ul class="wpr-my-templates-list striped">';
|
||||
|
||||
// The Loop
|
||||
if ( ! empty( $user_templates ) ) {
|
||||
foreach ( $user_templates as $user_template ) {
|
||||
// Edit URL
|
||||
$edit_url = str_replace( 'edit', 'elementor', get_edit_post_link( $user_template->ID ) );
|
||||
|
||||
// List
|
||||
echo '<li>';
|
||||
echo '<h3 class="wpr-title">'. esc_html($user_template->post_title) .'</h3>';
|
||||
|
||||
echo '<span class="wpr-action-buttons">';
|
||||
echo '<a href="'. esc_url($edit_url) .'" class="wpr-edit-template button button-primary">'. esc_html__( 'Edit', 'wpr-addons' ) .'</a>';
|
||||
echo '<span class="wpr-delete-template button button-primary" data-slug="'. esc_attr($user_template->post_name) .'" data-warning="'. esc_html__( 'Are you sure you want to delete this template?', 'wpr-addons' ) .'"><span class="dashicons dashicons-no-alt"></span></span>';
|
||||
echo '</span>';
|
||||
echo '</li>';
|
||||
}
|
||||
} else {
|
||||
echo '<li class="wpr-no-templates">You don\'t have any templates yet!</li>';
|
||||
}
|
||||
|
||||
echo '</ul>';
|
||||
|
||||
// Restore original Post Data
|
||||
wp_reset_postdata();
|
||||
}
|
||||
|
||||
/**
|
||||
** Render Conditions Popup
|
||||
*/
|
||||
public static function render_conditions_popup( $canvas = false ) {
|
||||
|
||||
// Active Tab
|
||||
$active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : 'wpr_tab_header';
|
||||
|
||||
?>
|
||||
|
||||
<div class="wpr-condition-popup-wrap wpr-admin-popup-wrap">
|
||||
<div class="wpr-condition-popup wpr-admin-popup">
|
||||
<header>
|
||||
<h2><?php esc_html_e( 'Where Do You Want to Display Your Template?', 'wpr-addons' ); ?></h2>
|
||||
<p>
|
||||
<?php esc_html_e( 'Set the conditions that determine where your Template is used throughout your site.', 'wpr-addons' ); ?><br>
|
||||
<?php esc_html_e( 'For example, choose \'Entire Site\' to display the template across your site.', 'wpr-addons' ); ?>
|
||||
</p>
|
||||
</header>
|
||||
<span class="close-popup dashicons dashicons-no-alt"></span>
|
||||
|
||||
<!-- Conditions -->
|
||||
<div class="wpr-conditions-wrap">
|
||||
<div class="wpr-conditions-sample">
|
||||
<?php if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->can_use_premium_code() ) : ?>
|
||||
<!-- Global -->
|
||||
<select name="global_condition_select" class="global-condition-select">
|
||||
<option value="global"><?php esc_html_e( 'Entire Site', 'wpr-addons' ); ?></option>
|
||||
<option value="archive"><?php esc_html_e( 'Archives', 'wpr-addons' ); ?></option>
|
||||
<option value="single"><?php esc_html_e( 'Singular', 'wpr-addons' ); ?></option>
|
||||
</select>
|
||||
|
||||
<!-- Archive -->
|
||||
<select name="archives_condition_select" class="archives-condition-select">
|
||||
<?php if ( 'wpr_tab_header' === $active_tab || 'wpr_tab_footer' === $active_tab ) : ?>
|
||||
<optgroup label="<?php esc_html_e( 'Archives', 'wpr-addons' ); ?>">
|
||||
<option value="all_archives"><?php esc_html_e( 'All Archives', 'wpr-addons' ); ?></option>
|
||||
<option value="posts"><?php esc_html_e( 'Posts Archive', 'wpr-addons' ); ?></option>
|
||||
<?php // Custom Post Types
|
||||
$custom_post_types = Utilities::get_custom_types_of( 'post', true );
|
||||
foreach ($custom_post_types as $key => $value) {
|
||||
if ( 'e-landing-page' === $key ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->is_plan( 'expert' ) || 'product' === $key ) {
|
||||
echo '<option value="'. esc_attr($key) .'">'. $value .' '. esc_html__( 'Archive', 'wpr-addons' ) .'</option>';
|
||||
} else {
|
||||
echo '<option value="pro-'. esc_attr(substr($key, 0, 3)) .'">'. $value .' '. esc_html__( 'Archive (Expert)', 'wpr-addons' ) .'</option>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
<option value="author"><?php esc_html_e( 'Author Archive', 'wpr-addons' ); ?></option>
|
||||
<option value="date"><?php esc_html_e( 'Date Archive', 'wpr-addons' ); ?></option>
|
||||
<option value="search"><?php esc_html_e( 'Search Results', 'wpr-addons' ); ?></option>
|
||||
</optgroup>
|
||||
|
||||
<optgroup label="<?php esc_html_e( 'Taxonomy Archives', 'wpr-addons' ); ?>">
|
||||
<option value="categories" class="custom-ids"><?php esc_html_e( 'Post Categories', 'wpr-addons' ); ?></option>
|
||||
<option value="tags" class="custom-ids"><?php esc_html_e( 'Post Tags', 'wpr-addons' ); ?></option>
|
||||
<?php // Custom Taxonomies
|
||||
$custom_taxonomies = Utilities::get_custom_types_of( 'tax', true );
|
||||
foreach ($custom_taxonomies as $key => $value) {
|
||||
if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->is_plan( 'expert' ) || 'product_cat' === $key || 'product_tag' === $key ) {
|
||||
echo '<option value="'. esc_attr($key) .'" class="custom-type-ids">'. esc_html($value) .'</option>';
|
||||
} else {
|
||||
echo '<option value="pro-'. esc_attr(substr($key, 0, 3)) .'" class="custom-type-ids">'. esc_html($value) .' (Expert)</option>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</optgroup>
|
||||
<?php else: ?>
|
||||
<?php if ( 'wpr_tab_archive' === $active_tab ) : ?>
|
||||
<optgroup label="<?php esc_html_e( 'Archives', 'wpr-addons' ); ?>">
|
||||
<option value="all_archives"><?php esc_html_e( 'All Archives', 'wpr-addons' ); ?></option>
|
||||
<option value="posts"><?php esc_html_e( 'Posts Archive', 'wpr-addons' ); ?></option>
|
||||
|
||||
<?php // Custom Post Types
|
||||
$custom_post_types = Utilities::get_custom_types_of( 'post', true );
|
||||
foreach ($custom_post_types as $key => $value) {
|
||||
if ( 'product' === $key || 'e-landing-page' === $key ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->is_plan( 'expert' ) ) {
|
||||
echo '<option value="'. esc_attr($key) .'">'. $value .' '. esc_html__( 'Archive', 'wpr-addons' ) .'</option>';
|
||||
} else {
|
||||
echo '<option value="pro-'. esc_attr(substr($key, 0, 3)) .'">'. $value .' '. esc_html__( 'Archive (Expert)', 'wpr-addons' ) .'</option>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<option value="author"><?php esc_html_e( 'Author Archive', 'wpr-addons' ); ?></option>
|
||||
<option value="date"><?php esc_html_e( 'Date Archive', 'wpr-addons' ); ?></option>
|
||||
<option value="search"><?php esc_html_e( 'Search Results', 'wpr-addons' ); ?></option>
|
||||
</optgroup>
|
||||
|
||||
<optgroup label="<?php esc_html_e( 'Taxonomy Archives', 'wpr-addons' ); ?>">
|
||||
<option value="categories" class="custom-ids"><?php esc_html_e( 'Post Categories', 'wpr-addons' ); ?></option>
|
||||
<option value="tags" class="custom-ids"><?php esc_html_e( 'Post Tags', 'wpr-addons' ); ?></option>
|
||||
<?php // Custom Taxonomies
|
||||
$custom_taxonomies = Utilities::get_custom_types_of( 'tax', true );
|
||||
foreach ($custom_taxonomies as $key => $value) {
|
||||
if ( 'product_cat' === $key || 'product_tag' === $key ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->is_plan( 'expert' ) ) {
|
||||
echo '<option value="'. esc_attr($key) .'" class="custom-type-ids">'. esc_html($value) .'</option>';
|
||||
} else {
|
||||
echo '<option value="pro-'. esc_attr(substr($key, 0, 3)) .'" class="custom-type-ids">'. esc_html($value) .' (Expert)</option>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</optgroup>
|
||||
<?php elseif ( 'wpr_tab_product_archive' === $active_tab ): ?>
|
||||
<option value="products"><?php esc_html_e( 'Products Archive', 'wpr-addons' ); ?></option>
|
||||
<option value="product_cat" class="custom-type-ids"><?php esc_html_e( 'Products Categories', 'wpr-addons' ); ?></option>
|
||||
<option value="product_tag" class="custom-type-ids"><?php esc_html_e( 'Products Tags', 'wpr-addons' ); ?></option>
|
||||
<option value="product_search"><?php esc_html_e( 'Products Search', 'wpr-addons' ); ?></option>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</select>
|
||||
|
||||
<!-- Single -->
|
||||
<select name="singles_condition_select" class="singles-condition-select">
|
||||
<?php if ( 'wpr_tab_header' === $active_tab || 'wpr_tab_footer' === $active_tab ) : ?>
|
||||
<option value="front_page"><?php esc_html_e( 'Front Page', 'wpr-addons' ); ?></option>
|
||||
<option value="page_404"><?php esc_html_e( '404 Page', 'wpr-addons' ); ?></option>
|
||||
<option value="pages" class="custom-ids"><?php esc_html_e( 'Pages', 'wpr-addons' ); ?></option>
|
||||
<option value="posts" class="custom-ids"><?php esc_html_e( 'Posts', 'wpr-addons' ); ?></option>
|
||||
<?php // Custom Post Types
|
||||
$custom_post_types = Utilities::get_custom_types_of( 'post', true );
|
||||
foreach ($custom_post_types as $key => $value) {
|
||||
if ( 'e-landing-page' === $key ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->is_plan( 'expert' ) || 'product' === $key ) {
|
||||
echo '<option value="'. esc_attr($key) .'" class="custom-type-ids">'. esc_html($value) .'</option>';
|
||||
} else {
|
||||
echo '<option value="pro-'. esc_attr(substr($key, 0, 3)) .'" class="custom-type-ids">'. esc_html($value) .' (Expert)</option>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php else: ?>
|
||||
<?php if ( 'wpr_tab_single' === $active_tab ) : ?>
|
||||
<option value="front_page"><?php esc_html_e( 'Front Page', 'wpr-addons' ); ?></option>
|
||||
<option value="page_404"><?php esc_html_e( '404 Page', 'wpr-addons' ); ?></option>
|
||||
<option value="pages" class="custom-ids"><?php esc_html_e( 'Pages', 'wpr-addons' ); ?></option>
|
||||
<option value="posts" class="custom-ids"><?php esc_html_e( 'Posts', 'wpr-addons' ); ?></option>
|
||||
|
||||
<?php // Custom Post Types
|
||||
$custom_post_types = Utilities::get_custom_types_of( 'post', true );
|
||||
foreach ($custom_post_types as $key => $value) {
|
||||
if ( 'product' === $key || 'e-landing-page' === $key ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->is_plan( 'expert' ) ) {
|
||||
echo '<option value="'. esc_attr($key) .'" class="custom-type-ids">'. esc_html($value) .'</option>';
|
||||
} else {
|
||||
echo '<option value="pro-'. esc_attr(substr($key, 0, 3)) .'" class="custom-type-ids">'. esc_html($value) .' (Expert)</option>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php elseif ( 'wpr_tab_product_single' === $active_tab ): ?>
|
||||
<option value="product" class="custom-product-ids custom-type-ids"><?php esc_html_e( 'Products', 'wpr-addons' ); ?></option>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</select>
|
||||
|
||||
<input type="text" placeholder="<?php esc_html_e( 'Enter comma separated IDs', 'wpr-addons' ); ?>" name="condition_input_ids" class="wpr-condition-input-ids">
|
||||
<span class="wpr-delete-template-conditions dashicons dashicons-no-alt"></span>
|
||||
|
||||
<?php else: // Free user conditions ?>
|
||||
|
||||
<!-- Global -->
|
||||
<select name="global_condition_select" class="global-condition-select">
|
||||
<option value="global"><?php esc_html_e( 'Entire Site', 'wpr-addons' ); ?></option>
|
||||
<option value="archive"><?php esc_html_e( 'Archives (Pro)', 'wpr-addons' ); ?></option>
|
||||
<option value="single"><?php esc_html_e( 'Singular (Pro)', 'wpr-addons' ); ?></option>
|
||||
</select>
|
||||
|
||||
<!-- Archive -->
|
||||
<select name="archives_condition_select" class="archives-condition-select">
|
||||
<?php if ( 'wpr_tab_header' === $active_tab || 'wpr_tab_footer' === $active_tab ) : ?>
|
||||
<optgroup label="<?php esc_html_e( 'Archives', 'wpr-addons' ); ?>">
|
||||
<option value="all_archives"><?php esc_html_e( 'All Archives (Pro)', 'wpr-addons' ); ?></option>
|
||||
<option value="posts"><?php esc_html_e( 'Posts Archive (Pro)', 'wpr-addons' ); ?></option>
|
||||
<option value="author"><?php esc_html_e( 'Author Archive (Pro)', 'wpr-addons' ); ?></option>
|
||||
<option value="date"><?php esc_html_e( 'Date Archive (Pro)', 'wpr-addons' ); ?></option>
|
||||
<option value="search"><?php esc_html_e( 'Search Results (Pro)', 'wpr-addons' ); ?></option>
|
||||
<option value="categories" class="custom-ids"><?php esc_html_e( 'Post Categories (Pro)', 'wpr-addons' ); ?></option>
|
||||
<option value="tags" class="custom-ids"><?php esc_html_e( 'Post Tags (Pro)', 'wpr-addons' ); ?></option>
|
||||
</optgroup>
|
||||
<optgroup label="<?php esc_html_e( 'WooCommerce Archives', 'wpr-addons' ); ?>">
|
||||
<option value="products" class="custom-ids"><?php esc_html_e( 'Products Archive (Pro)', 'wpr-addons' ); ?></option>
|
||||
<option value="products_cats" class="custom-ids"><?php esc_html_e( 'Product Categories (Pro)', 'wpr-addons' ); ?></option>
|
||||
<option value="product_tags" class="custom-ids"><?php esc_html_e( 'Product Tags (Pro)', 'wpr-addons' ); ?></option>
|
||||
</optgroup>
|
||||
<optgroup label="<?php esc_html_e( 'Custom Post Type Archives', 'wpr-addons' ); ?>">
|
||||
<?php // Custom Post Types
|
||||
$custom_post_types = Utilities::get_custom_types_of( 'post', true );
|
||||
foreach ($custom_post_types as $key => $value) {
|
||||
if ( 'product' === $key || 'e-landing-page' === $key ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
echo '<option value="'. esc_attr(substr($key, 0, 3)) .'" class="custom-type-ids">'. esc_html($value) .' (Expert)</option>';
|
||||
}
|
||||
?>
|
||||
<?php // Custom Taxonomies
|
||||
$custom_taxonomies = Utilities::get_custom_types_of( 'tax', true );
|
||||
foreach ($custom_taxonomies as $key => $value) {
|
||||
if ( 'product_cat' === $key || 'product_tag' === $key ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// List Taxonomies
|
||||
echo '<option value="'. esc_attr($key) .'" class="custom-type-ids">'. esc_html($value) .' (Expert)</option>';
|
||||
}
|
||||
?>
|
||||
</optgroup>
|
||||
<?php else: ?>
|
||||
<?php if ( 'wpr_tab_archive' === $active_tab ) : ?>
|
||||
<optgroup label="<?php esc_html_e( 'Archives', 'wpr-addons' ); ?>">
|
||||
<option value="all_archives"><?php esc_html_e( 'All Archives', 'wpr-addons' ); ?></option>
|
||||
<option value="posts"><?php esc_html_e( 'Posts Archive', 'wpr-addons' ); ?></option>
|
||||
<option value="author"><?php esc_html_e( 'Author Archive', 'wpr-addons' ); ?></option>
|
||||
<option value="date"><?php esc_html_e( 'Date Archive', 'wpr-addons' ); ?></option>
|
||||
<option value="search"><?php esc_html_e( 'Search Results', 'wpr-addons' ); ?></option>
|
||||
<option value="categories" class="custom-ids"><?php esc_html_e( 'Post Categories', 'wpr-addons' ); ?></option>
|
||||
<option value="tags" class="custom-ids"><?php esc_html_e( 'Post Tags', 'wpr-addons' ); ?></option>
|
||||
</optgroup>
|
||||
<optgroup label="<?php esc_html_e( 'Custom Post Type Archives', 'wpr-addons' ); ?>">
|
||||
<?php // Custom Post Types
|
||||
$custom_post_types = Utilities::get_custom_types_of( 'post', true );
|
||||
foreach ($custom_post_types as $key => $value) {
|
||||
if ( 'product' === $key || 'e-landing-page' === $key ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
echo '<option value="'. esc_attr(substr($key, 0, 3)) .'" class="custom-type-ids">'. esc_html($value) .' (Expert)</option>';
|
||||
}
|
||||
?>
|
||||
<?php // Custom Taxonomies
|
||||
$custom_taxonomies = Utilities::get_custom_types_of( 'tax', true );
|
||||
foreach ($custom_taxonomies as $key => $value) {
|
||||
if ( 'product_cat' === $key || 'product_tag' === $key ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// List Taxonomies
|
||||
echo '<option value="'. esc_attr($key) .'" class="custom-type-ids">'. esc_html($value) .' (Expert)</option>';
|
||||
}
|
||||
?>
|
||||
</optgroup>
|
||||
<?php elseif ( 'wpr_tab_product_archive' === $active_tab ): ?>
|
||||
<option value="products"><?php esc_html_e( 'Products Archive', 'wpr-addons' ); ?></option>
|
||||
<option value="product_cat" class="custom-type-ids"><?php esc_html_e( 'Products Categories (Pro)', 'wpr-addons' ); ?></option>
|
||||
<option value="product_tag" class="custom-type-ids"><?php esc_html_e( 'Products Tags (Pro)', 'wpr-addons' ); ?></option>
|
||||
<option value="product_search"><?php esc_html_e( 'Products Search (Pro)', 'wpr-addons' ); ?></option>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</select>
|
||||
|
||||
<!-- Single -->
|
||||
<select name="singles_condition_select" class="singles-condition-select">
|
||||
<?php if ( 'wpr_tab_header' === $active_tab || 'wpr_tab_footer' === $active_tab ) : ?>
|
||||
<option value="front_page"><?php esc_html_e( 'Front Page (Pro)', 'wpr-addons' ); ?></option>
|
||||
<option value="page_404"><?php esc_html_e( '404 Page (Pro)', 'wpr-addons' ); ?></option>
|
||||
<option value="pages" class="custom-ids"><?php esc_html_e( 'Pages (Pro)', 'wpr-addons' ); ?></option>
|
||||
<option value="posts" class="custom-ids"><?php esc_html_e( 'Posts (Pro)', 'wpr-addons' ); ?></option>
|
||||
<option value="product" class="custom-ids"><?php esc_html_e( 'Product (Pro)', 'wpr-addons' ); ?></option>
|
||||
<?php // Custom Post Types
|
||||
$custom_post_types = Utilities::get_custom_types_of( 'post', true );
|
||||
foreach ($custom_post_types as $key => $value) {
|
||||
if ( 'product' === $key || 'e-landing-page' === $key ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
echo '<option value="'. esc_attr($key) .'" class="custom-type-ids">'. esc_html($value) .' (Expert)</option>';
|
||||
}
|
||||
?>
|
||||
<?php else: ?>
|
||||
<?php if ( 'wpr_tab_single' === $active_tab ) : ?>
|
||||
<option value="front_page"><?php esc_html_e( 'Front Page', 'wpr-addons' ); ?></option>
|
||||
<option value="page_404"><?php esc_html_e( '404 Page', 'wpr-addons' ); ?></option>
|
||||
<option value="pages" class="custom-ids"><?php esc_html_e( 'Pages', 'wpr-addons' ); ?></option>
|
||||
<option value="posts" class="custom-ids"><?php esc_html_e( 'Posts', 'wpr-addons' ); ?></option>
|
||||
|
||||
<?php // Custom Post Types
|
||||
$custom_post_types = Utilities::get_custom_types_of( 'post', true );
|
||||
foreach ($custom_post_types as $key => $value) {
|
||||
if ( 'product' === $key || 'e-landing-page' === $key ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
echo '<option value="'. esc_attr($key) .'" class="custom-type-ids">'. esc_html($value) .' (Expert)</option>';
|
||||
}
|
||||
?>
|
||||
<?php elseif ( 'wpr_tab_product_single' === $active_tab ): ?>
|
||||
<option value="product" class="custom-type-ids"><?php esc_html_e( 'Products', 'wpr-addons' ); ?></option>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</select>
|
||||
|
||||
<input type="text" placeholder="<?php esc_html_e( 'Enter comma separated IDs (Pro)', 'wpr-addons' ); ?>" name="condition_input_ids" class="wpr-condition-input-ids">
|
||||
<span class="wpr-delete-template-conditions dashicons dashicons-no-alt"></span>
|
||||
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php // Expert Notice
|
||||
|
||||
if ( !defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->is_plan( 'expert' ) ) {
|
||||
echo '<span class="wpr-expert-notice" style="display:none;text-align:center;"><br>
|
||||
<span style="color:#f44;font-size:18px;" class="dashicons dashicons-warning"></span>
|
||||
<strong style="color:#f44;">Please Note:</strong>
|
||||
<strong>Custom Post Types</strong>, <strong>Custom Taxonomies</strong> and <strong>Custom Fields</strong><br>
|
||||
are only supported in the <strong style="color:#f44;"><a href="https://royal-elementor-addons.com/?ref=rea-plugin-backend-conditions-upgrade-expert#purchasepro" target="_blank" style="text-decoration:none">Expert Version.</a></strong>
|
||||
</span>';
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<?php if ( $canvas ) : ?>
|
||||
<div class="wpr-canvas-condition wpr-setting-custom-ckbox">
|
||||
<span><?php esc_html_e( 'Show this template on Elementor Canvas pages', 'wpr-addons' ); ?></span>
|
||||
<input type="checkbox" name="wpr-show-on-canvas" id="wpr-show-on-canvas">
|
||||
<label for="wpr-show-on-canvas"></label>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
// Pro Notice
|
||||
if ( !defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->can_use_premium_code() ) {
|
||||
echo '<span style="color: #7f8b96;"><br>Conditions are fully supported in the <strong><a href="https://royal-elementor-addons.com/?ref=rea-plugin-backend-conditions-upgrade-pro#purchasepro" target="_blank">Pro and Expert versions.</a></strong></span>';
|
||||
// echo '<span style="color: #7f8b96;"><br>Conditions are fully supported in the <strong><a href="'. admin_url('admin.php?page=wpr-addons-pricing') .'" target="_blank">Pro version</a></strong></span>';
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<!-- Action Buttons -->
|
||||
<span class="wpr-add-conditions"><?php esc_html_e( 'Add Conditions', 'wpr-addons' ); ?></span>
|
||||
<span class="wpr-save-conditions"><?php esc_html_e( 'Save Conditions', 'wpr-addons' ); ?></span>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
** Render Create Template Popup
|
||||
*/
|
||||
public static function render_create_template_popup() {
|
||||
?>
|
||||
|
||||
<!-- Custom Template Popup -->
|
||||
<div class="wpr-user-template-popup-wrap wpr-admin-popup-wrap">
|
||||
<div class="wpr-user-template-popup wpr-admin-popup">
|
||||
<header>
|
||||
<h2><?php esc_html_e( 'Templates Help You Work Efficiently!', 'wpr-addons' ); ?></h2>
|
||||
<p><?php esc_html_e( 'Use templates to create the different pieces of your site, and reuse them with one click whenever needed.', 'wpr-addons' ); ?></p>
|
||||
</header>
|
||||
|
||||
<input type="text" name="user_template_title" class="wpr-user-template-title" placeholder="<?php esc_html_e( 'Enter Template Title', 'wpr-addons' ); ?>">
|
||||
<input type="hidden" name="user_template_type" class="user-template-type">
|
||||
<span class="wpr-create-template"><?php esc_html_e( 'Create Template', 'wpr-addons' ); ?></span>
|
||||
<span class="close-popup dashicons dashicons-no-alt"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
** Check if Library Template Exists
|
||||
*/
|
||||
public static function template_exists( $slug ) {
|
||||
$result = false;
|
||||
$wpr_templates = get_posts( ['post_type' => 'wpr_templates', 'posts_per_page' => '-1'] );
|
||||
|
||||
foreach ( $wpr_templates as $post ) {
|
||||
|
||||
if ( $slug === $post->post_name ) {
|
||||
$result = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
+249
@@ -0,0 +1,249 @@
|
||||
<?php
|
||||
namespace WprAddons\Admin\Includes;
|
||||
|
||||
use WprAddons\Plugin;
|
||||
use WprAddons\Classes\Utilities;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* WPR_Templates_Modal_Popups setup
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class WPR_Templates_Modal_Popups {
|
||||
|
||||
/**
|
||||
** Instance of Elemenntor Frontend class.
|
||||
*
|
||||
** @var \Elementor\Frontend()
|
||||
*/
|
||||
private static $elementor_instance;
|
||||
|
||||
/**
|
||||
** Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
// Elementor Frontend
|
||||
self::$elementor_instance = \Elementor\Plugin::instance();
|
||||
|
||||
add_action( 'template_include', [ $this, 'set_post_type_template' ], 9999 );
|
||||
|
||||
add_action( 'wp_footer', [ $this, 'render_popups' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set blank template for editor
|
||||
*/
|
||||
public function set_post_type_template( $template ) {
|
||||
|
||||
if ( is_singular( 'wpr_templates' ) ) {
|
||||
if ( 'wpr-popups' === Utilities::get_elementor_template_type(get_the_ID()) && self::$elementor_instance->preview->is_preview_mode() ) {
|
||||
$template = WPR_ADDONS_PATH . 'modules/popup/editor.php';
|
||||
}
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
/**
|
||||
** Popups
|
||||
*/
|
||||
public function render_popups() {
|
||||
$conditions = json_decode( get_option('wpr_popup_conditions'), true );
|
||||
|
||||
if ( ! empty( $conditions ) ) {
|
||||
$conditions = $this->reverse_template_conditions( $conditions );
|
||||
|
||||
// Global
|
||||
if ( isset( $conditions['global'] ) ) {
|
||||
WPR_Templates_Modal_Popups::display_popups_by_location( $conditions, 'global' );
|
||||
}
|
||||
|
||||
// Custom
|
||||
if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->can_use_premium_code() ) {
|
||||
// Archive
|
||||
\WprAddonsPro\Classes\Pro_Modules::archive_pages_popup_conditions( $conditions );
|
||||
|
||||
// Single
|
||||
\WprAddonsPro\Classes\Pro_Modules::single_pages_popup_conditions( $conditions );
|
||||
}
|
||||
|
||||
|
||||
// Enqueue ScrolBar JS //TODO - check if displayed multiple times
|
||||
wp_enqueue_script( 'wpr-popup-scroll-js', WPR_ADDONS_URL .'assets/js/lib/perfect-scrollbar/perfect-scrollbar.min.js', [ 'jquery' ], '0.4.9' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Reverse Template Conditions
|
||||
*/
|
||||
public function reverse_template_conditions( $conditions ) {
|
||||
$reverse = [];
|
||||
|
||||
foreach ( $conditions as $key => $condition ) {
|
||||
foreach( $condition as $location ) {
|
||||
if ( ! isset( $reverse[$location] ) ) {
|
||||
$reverse[$location] = [ $key ];
|
||||
} else {
|
||||
array_push( $reverse[$location], $key );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $reverse;
|
||||
}
|
||||
|
||||
/**
|
||||
** Display Popups by Location
|
||||
*/
|
||||
public static function display_popups_by_location( $conditions, $page ) {
|
||||
foreach ( $conditions[$page] as $key => $popup ) {
|
||||
WPR_Templates_Modal_Popups::render_popup_content( $popup );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Display Elementor Content
|
||||
*/
|
||||
public static function render_popup_content( $slug ) {
|
||||
$template_name = '';
|
||||
|
||||
$template_id = Utilities::get_template_id( $slug );
|
||||
|
||||
if ( defined('ICL_LANGUAGE_CODE') ) {
|
||||
$default_language_code = apply_filters('wpml_default_language', null);
|
||||
$current_language_code = apply_filters( 'wpml_current_language', NULL );
|
||||
|
||||
|
||||
IF ( ICL_LANGUAGE_CODE !== $default_language_code ) {
|
||||
$template_id = apply_filters('wpml_object_id', $template_id, 'wpr_templates', true, $current_language_code);
|
||||
}
|
||||
}
|
||||
|
||||
$get_settings = WPR_Templates_Modal_Popups::get_template_settings( $slug );
|
||||
$get_elementor_content = self::$elementor_instance->frontend->get_builder_content( $template_id, false );
|
||||
|
||||
if ( '' === $get_elementor_content ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Encode Settings
|
||||
$get_encoded_settings = ! empty( $get_settings ) ? wp_json_encode( $get_settings ) : '[]';
|
||||
|
||||
// Template Settings Attribute
|
||||
$template_settings_attr = "data-settings='". esc_attr($get_encoded_settings) ."'";
|
||||
|
||||
// Return if NOT available for current user
|
||||
if ( ! WPR_Templates_Modal_Popups::check_available_user_roles( $get_settings['popup_show_for_roles'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! self::$elementor_instance->preview->is_preview_mode() ) {
|
||||
echo '<div id="wpr-popup-id-'. esc_attr($template_id) .'" class="wpr-template-popup" '. $template_settings_attr .'>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo '<div class="wpr-template-popup-inner">';
|
||||
|
||||
// Popup Overlay & Close Button
|
||||
echo '<div class="wpr-popup-overlay"></div>';
|
||||
|
||||
// Template Container
|
||||
echo '<div class="wpr-popup-container">';
|
||||
|
||||
// Close Button
|
||||
if ( \Elementor\Plugin::$instance->experiments->is_feature_active( 'e_font_icon_svg' ) ) { // GOGA: why not included
|
||||
echo '<div class="wpr-popup-close-btn"><i class="fa fa-times"></i></div>';
|
||||
} else {
|
||||
echo '<div class="wpr-popup-close-btn"><i class="eicon-close"></i></div>';
|
||||
}
|
||||
|
||||
// Elementor Template Content
|
||||
echo '<div class="wpr-popup-container-inner">';
|
||||
echo ''. $get_elementor_content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo '</div>';
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Get Template Settings
|
||||
*/
|
||||
public static function get_template_settings( $slug ) {
|
||||
$settings = [];
|
||||
$defaults = [];
|
||||
|
||||
$template_id = Utilities::get_template_id( $slug );
|
||||
$meta_settings = get_post_meta( $template_id, '_elementor_page_settings', true );
|
||||
|
||||
$popup_defaults = [
|
||||
'popup_trigger' => 'load',
|
||||
'popup_load_delay' => 1,
|
||||
'popup_scroll_progress' => 10,
|
||||
'popup_inactivity_time' => 15,
|
||||
'popup_element_scroll' => '',
|
||||
'popup_custom_trigger' => '',
|
||||
'popup_specific_date' => date( 'Y-m-d H:i', strtotime( '+1 month' ) + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ),
|
||||
'popup_stop_after_date' => false,
|
||||
'popup_stop_after_date_select' => date( 'Y-m-d H:i', strtotime( '+1 day' ) + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ),
|
||||
'popup_show_again_delay' => 1,
|
||||
'popup_disable_esc_key' => false,
|
||||
'popup_automatic_close_switch' => false,
|
||||
'popup_automatic_close_delay' => 10,
|
||||
'popup_animation' => 'fade',
|
||||
'popup_animation_duration' => 1,
|
||||
'popup_show_for_roles' => '',
|
||||
'popup_show_via_referral' => false,
|
||||
'popup_referral_keyword' => '',
|
||||
'popup_display_as' => 'modal',
|
||||
'popup_show_on_device' => true,
|
||||
'popup_show_on_device_mobile' => true,
|
||||
'popup_show_on_device_tablet' => true,
|
||||
'popup_disable_page_scroll' => true,
|
||||
'popup_overlay_disable_close' => false,
|
||||
'popup_close_button_display_delay' => 0,
|
||||
];
|
||||
|
||||
// Determine Template
|
||||
if ( strpos( $slug, 'popup') ) {
|
||||
$defaults = $popup_defaults;
|
||||
}
|
||||
|
||||
foreach( $defaults as $option => $value ) {
|
||||
if ( isset($meta_settings[$option]) ) {
|
||||
$settings[$option] = $meta_settings[$option];
|
||||
}
|
||||
}
|
||||
|
||||
return array_merge( $defaults, $settings );
|
||||
}
|
||||
|
||||
/**
|
||||
** Check Available User Rols
|
||||
*/
|
||||
public static function check_available_user_roles( $selected_roles ) {
|
||||
if ( empty( $selected_roles ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$current_user = wp_get_current_user();
|
||||
|
||||
if ( ! empty( $current_user->roles ) ) {
|
||||
$role = $current_user->roles[0];
|
||||
} else {
|
||||
$role = 'guest';
|
||||
}
|
||||
|
||||
if ( in_array( $role, $selected_roles ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace WprAddons\Admin\Includes;
|
||||
|
||||
use Elementor;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* WPR_Templates_Shortcode setup
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class WPR_Templates_Shortcode {
|
||||
|
||||
public function __construct() {
|
||||
add_shortcode( 'wpr-template', [ $this, 'shortcode' ] );
|
||||
|
||||
add_action('elementor/element/after_section_start', [ $this, 'extend_shortcode' ], 10, 3 );
|
||||
}
|
||||
|
||||
public function shortcode( $attributes = [] ) {
|
||||
if ( empty( $attributes['id'] ) ) {
|
||||
return '';
|
||||
} else {
|
||||
$id = intval($attributes['id']);
|
||||
}
|
||||
|
||||
// Ensure only publicly published posts can be accessed
|
||||
$post = get_post($id);
|
||||
|
||||
if (!$post || $post->post_status !== 'publish' || in_array($post->post_status, ['draft', 'private', 'future'])) {
|
||||
return 'You do not have permission to view this post.';
|
||||
}
|
||||
|
||||
// Optionally check if the post is password protected
|
||||
if (post_password_required($post)) {
|
||||
return 'This post is password protected.';
|
||||
}
|
||||
|
||||
// WPML language handling
|
||||
if (defined('ICL_LANGUAGE_CODE')) {
|
||||
$default_language_code = apply_filters('wpml_default_language', null);
|
||||
|
||||
if ( ICL_LANGUAGE_CODE !== $default_language_code ) {
|
||||
$id = icl_object_id($id, 'elementor_library', false, ICL_LANGUAGE_CODE);
|
||||
}
|
||||
}
|
||||
|
||||
$edit_link = '<span class="wpr-template-edit-btn" data-permalink="'. esc_url(get_permalink($id)) .'">Edit Template</span>';
|
||||
|
||||
$type = get_post_meta(get_the_ID(), '_wpr_template_type', true) || get_post_meta($id, '_elementor_template_type', true);
|
||||
$has_css = 'internal' === get_option( 'elementor_css_print_method' ) || '' !== $type;
|
||||
|
||||
return Elementor\Plugin::instance()->frontend->get_builder_content_for_display( $id, $has_css ) . $edit_link;
|
||||
}
|
||||
|
||||
public function extend_shortcode( $section, $section_id, $args ) {
|
||||
if ( $section->get_name() == 'shortcode' && $section_id == 'section_shortcode' ) {
|
||||
$section->add_control(
|
||||
'select_template' ,
|
||||
[
|
||||
'label' => esc_html__( 'Select Template', 'wpr-addons' ),
|
||||
'type' => 'wpr-ajax-select2',
|
||||
'options' => 'ajaxselect2/get_elementor_templates',
|
||||
'label_block' => true,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user