File: /home/tvypkwena2lu/public_html/wp-content/plugins/custom-elementor-extension.php
<?php
/**
* Plugin Name: Theme Specific Elementor Extension
* Description: Theme Specific Elementor Extension. Elementor Blocks for customized theme specific requiements.
* Plugin URI: https://elementor.com/
* Version: 1.0.0
* Author: Elementor
* Author URI: https://elementor.com/
* Text Domain: custom-elementor-extension
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Main Custom Elementor Extension Class
*
* The main class that initiates and runs the plugin.
*
* @since 1.0.0
*/
final class Custom_Elementor_Extension {
/**
* Plugin Version
*
* @since 1.0.0
*
* @var string The plugin version.
*/
const VERSION = '1.0.0';
/**
* Minimum Elementor Version
*
* @since 1.0.0
*
* @var string Minimum Elementor version required to run the plugin.
*/
const MINIMUM_ELEMENTOR_VERSION = '2.0.0';
/**
* Minimum PHP Version
*
* @since 1.0.0
*
* @var string Minimum PHP version required to run the plugin.
*/
const MINIMUM_PHP_VERSION = '5.0';
/**
* Instance
*
* @since 1.0.0
*
* @access private
* @static
*
* @var Custom_Elementor_Extension The single instance of the class.
*/
private static $_instance = null;
/**
* Instance
*
* Ensures only one instance of the class is loaded or can be loaded.
*
* @since 1.0.0
*
* @access public
* @static
*
* @return Custom_Elementor_Extension An instance of the class.
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Constructor
*
* @since 1.0.0
*
* @access public
*/
public function __construct() {
add_action( 'init', [ $this, 'i18n' ] );
add_action( 'plugins_loaded', [ $this, 'init' ] );
}
/**
* Load Textdomain
*
* Load plugin localization files.
*
* Fired by `init` action hook.
*
* @since 1.0.0
*
* @access public
*/
public function i18n() {
load_plugin_textdomain( 'custom-elementor-extension' );
}
/**
* Initialize the plugin
*
* Load the plugin only after Elementor (and other plugins) are loaded.
* Checks for basic plugin requirements, if one check fail don't continue,
* if all check have passed load the files required to run the plugin.
*
* Fired by `plugins_loaded` action hook.
*
* @since 1.0.0
*
* @access public
*/
public function init() {
// Check if Elementor installed and activated
if ( ! did_action( 'elementor/loaded' ) ) {
add_action( 'admin_notices', [ $this, 'admin_notice_missing_main_plugin' ] );
return;
}
// Check for required Elementor version
if ( ! version_compare( ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=' ) ) {
add_action( 'admin_notices', [ $this, 'admin_notice_minimum_elementor_version' ] );
return;
}
// Check for required PHP version
if ( version_compare( PHP_VERSION, self::MINIMUM_PHP_VERSION, '<' ) ) {
add_action( 'admin_notices', [ $this, 'admin_notice_minimum_php_version' ] );
return;
}
// Add Plugin actions
add_action( 'elementor/widgets/widgets_registered', [ $this, 'init_widgets' ] );
add_action( 'elementor/controls/controls_registered', [ $this, 'init_controls' ] );
add_action( 'elementor/elements/categories_registered', [ $this, 'init_new_category' ] );
//add_action( 'elementor/elements/categories_registered', 'add_elementor_widget_categories' );
}
/**
* Admin notice
*
* Warning when the site doesn't have Elementor installed or activated.
*
* @since 1.0.0
*
* @access public
*/
public function admin_notice_missing_main_plugin() {
if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );
$message = sprintf(
/* translators: 1: Plugin name 2: Elementor */
esc_html__( '"%1$s" requires "%2$s" to be installed and activated.', 'custom-elementor-extension' ),
'<strong>' . esc_html__( 'Custom Elementor Extension', 'custom-elementor-extension' ) . '</strong>',
'<strong>' . esc_html__( 'Elementor', 'custom-elementor-extension' ) . '</strong>'
);
printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message );
}
/**
* Admin notice
*
* Warning when the site doesn't have a minimum required Elementor version.
*
* @since 1.0.0
*
* @access public
*/
public function admin_notice_minimum_elementor_version() {
if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );
$message = sprintf(
/* translators: 1: Plugin name 2: Elementor 3: Required Elementor version */
esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'custom-elementor-extension' ),
'<strong>' . esc_html__( 'Custom Elementor Extension', 'custom-elementor-extension' ) . '</strong>',
'<strong>' . esc_html__( 'Elementor', 'custom-elementor-extension' ) . '</strong>',
self::MINIMUM_ELEMENTOR_VERSION
);
printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message );
}
/**
* Admin notice
*
* Warning when the site doesn't have a minimum required PHP version.
*
* @since 1.0.0
*
* @access public
*/
public function admin_notice_minimum_php_version() {
if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );
$message = sprintf(
/* translators: 1: Plugin name 2: PHP 3: Required PHP version */
esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'custom-elementor-extension' ),
'<strong>' . esc_html__( 'Custom Elementor Extension', 'custom-elementor-extension' ) . '</strong>',
'<strong>' . esc_html__( 'PHP', 'custom-elementor-extension' ) . '</strong>',
self::MINIMUM_PHP_VERSION
);
printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message );
}
/**
* Init Widgets
*
* Include widgets files and register them
*
* @since 1.0.0
*
* @access public
*/
public function init_widgets() {
function lae_get_all_post_type_options() {
$post_types = get_post_types(array('public' => true), 'objects');
$options = ['' => ''];
foreach ($post_types as $post_type) {
$options[$post_type->name] = $post_type->label;
}
return apply_filters('lae_post_type_options', $options);
}
function lae_get_all_books_options() {
$args = array(
'post_type' => array( 'page' ),
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => '_wp_page_template',
'value' => 'page_books.php'
)
),
);
$loop = new WP_Query( $args );
$options = [];
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
global $post;
//echo $product->get_id();
$options['prd:'.$post->ID] = get_the_title();
endwhile;
} else {
}
wp_reset_postdata();
//var_dump($options);
return apply_filters('lae_post_type_options', $options);
}
/**
* Action to handle searching taxonomy terms.
*/
function lae_get_all_taxonomy_options() {
global $wpdb;
$results = array();
foreach ($wpdb->get_results("
SELECT terms.slug AS 'slug', terms.name AS 'label', termtaxonomy.taxonomy AS 'type'
FROM $wpdb->terms AS terms
JOIN $wpdb->term_taxonomy AS termtaxonomy ON terms.term_id = termtaxonomy.term_id
LIMIT 500
") as $result) {
$results[$result->type . ':' . $result->slug] = $result->type . ':' . $result->label;
}
return apply_filters('lae_taxonomy_options', $results);
}
// get all registered taxonomies
function lae_get_taxonomies_map()
{
$map = array();
$taxonomies = get_taxonomies();
foreach ( $taxonomies as $taxonomy ) {
$map[$taxonomy] = $taxonomy;
}
return apply_filters( 'lae_taxonomies_map', $map );
}
function lae_build_query_args($settings) {
$query_args = [
'orderby' => $settings['orderby'],
'order' => $settings['order'],
'ignore_sticky_posts' => 1,
'post_status' => 'publish',
];
if (!empty($settings['post_in'])) {
$query_args['post_type'] = 'any';
$query_args['post__in'] = explode(',', $settings['post_in']);
$query_args['post__in'] = array_map('intval', $query_args['post__in']);
}
else {
if (!empty($settings['post_types'])) {
$query_args['post_type'] = $settings['post_types'];
}
if (!empty($settings['tax_query'])) {
$tax_queries = $settings['tax_query'];
$query_args['tax_query'] = array();
$query_args['tax_query']['relation'] = 'OR';
foreach ($tax_queries as $tq) {
list($tax, $term) = explode(':', $tq);
if (empty($tax) || empty($term))
continue;
$query_args['tax_query'][] = array(
'taxonomy' => $tax,
'field' => 'slug',
'terms' => $term
);
}
}
}
$query_args['posts_per_page'] = $settings['posts_per_page'];
$query_args['paged'] = max(1, get_query_var('paged'), get_query_var('page'));
//return apply_filters('lae_posts_query_args', $query_args, $settings);
return $query_args;
}
// Include Widget files
require_once( __DIR__ . '/widgets/ele-theme-book.php' );
require_once( __DIR__ . '/widgets/my-widget.php' );
//require_once( __DIR__ . '/widgets/gvs-video-overview.php' );
//require_once( __DIR__ . '/widgets/gvs-testimonial.php' );
require_once( __DIR__ . '/widgets/gvs-new_event.php' );
require_once( __DIR__ . '/widgets/ele-theme-slider.php' );
//require_once( __DIR__ . '/widgets/ele-featured-video.php' );
//require_once( __DIR__ . '/widgets/theme-home-testimonial.php' );
//require_once( __DIR__ . '/widgets/ele-theme-service.php' );
//require_once( __DIR__ . '/widgets/ele-theme-buttons.php' );
//require_once( __DIR__ . '/widgets/ele-post-caurosel.php' );
// Register widget
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \Elementor_Book_Widget() );
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \Elementor_ThemeSlider_Widget() );
//\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \Elementor_GVSTestimonial_Widget() );
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \Elementor_oEmbed_Widget() );
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \Elementor_GVSNewsEvents_Widget() );
//\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \Elementor_FeaturedVideo_Widget() );
//\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \Elementor_HomeTestimonial_Widget() );
/*
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \Elementor_ThemeHeading_Widget() );
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \Elementor_ThemeService_Widget() );
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \Elementor_ThemeButtons_Widget() );
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \Elementor_Posts_Carousel_Widget() );
*/
}
/**
* Init Controls
*
* Include controls files and register them
*
* @since 1.0.0
*
* @access public
*/
public function init_controls() {
// Include Control files
//require_once( __DIR__ . '/controls/test-control.php' );
// Register control
//\Elementor\Plugin::$instance->controls_manager->register_control( 'control-type-', new \Test_Control() );
}
public function init_new_category( $elements_manager ) {
$new_cat_name = 'Theme Specific'; //get_bloginfo( 'name' );
$elements_manager->add_category(
'theme-specific-category',
[
'title' => __( $new_cat_name, 'plugin-name' ),
'icon' => 'fa fa-plug',
]
);
}
}
Custom_Elementor_Extension::instance();