first commit

This commit is contained in:
2024-07-15 11:28:08 +02:00
commit f52d538ea5
21891 changed files with 6161164 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
<?php
/**
* Is front page condition
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Theme_Core_Conditions_Archive_All' ) ) {
/**
* Define Jet_Theme_Core_Conditions_Archive_All class
*/
class Jet_Theme_Core_Conditions_Archive_All extends Jet_Theme_Core_Conditions_Base {
/**
* Condition slug
*
* @return string
*/
public function get_id() {
return 'archive-all';
}
/**
* Condition label
*
* @return string
*/
public function get_label() {
return __( 'All Archives', 'jet-theme-core' );
}
/**
* Condition group
*
* @return string
*/
public function get_group() {
return 'archive';
}
/**
* Condition check callback
*
* @return bool
*/
public function check( $args ) {
return is_archive();
}
}
}

View File

@@ -0,0 +1,122 @@
<?php
/**
* Is front page condition
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Theme_Core_Conditions_Archive_Category' ) ) {
/**
* Define Jet_Theme_Core_Conditions_Archive_Category class
*/
class Jet_Theme_Core_Conditions_Archive_Category extends Jet_Theme_Core_Conditions_Base {
/**
* Condition slug
*
* @return string
*/
public function get_id() {
return 'archive-category';
}
/**
* Condition label
*
* @return string
*/
public function get_label() {
return __( 'Category Archives', 'jet-theme-core' );
}
/**
* Condition group
*
* @return string
*/
public function get_group() {
return 'archive';
}
public function get_controls() {
return array(
'cats' => array(
'label' => __( 'Select Categories', 'jet-theme-core' ),
'type' => 'jet_search',
'action' => 'jet_theme_search_cats',
'label_block' => true,
'multiple' => true,
'description' => __( 'Leave empty to apply for all categories', 'jet-theme-core' ),
'saved' => $this->get_saved_cats(),
),
);
}
public function get_saved_cats() {
$template_id = get_the_ID();
$saved = get_post_meta( $template_id, '_elementor_page_settings', true );
if ( ! empty( $saved['conditions_archive-category_cats'] ) ) {
$terms = get_terms( array(
'include' => $saved['conditions_archive-category_cats'],
'taxonomy' => 'category',
'hide_empty' => false,
) );
if ( empty( $terms ) ) {
return array();
} else {
return wp_list_pluck( $terms, 'name', 'term_id' );
}
} else {
return array();
}
}
public function verbose_args( $args ) {
if ( empty( $args['cats'] ) ) {
return __( 'All', 'jet-theme-core' );
}
$result = '';
$sep = '';
$terms = get_terms( array(
'include' => $args['cats'],
'taxonomy' => 'category',
'hide_empty' => false,
) );
foreach ( $terms as $term ) {
$result .= $sep . $term->name;
$sep = ', ';
}
return $result;
}
/**
* Condition check callback
*
* @return bool
*/
public function check( $args ) {
if ( empty( $args['cats'] ) ) {
return is_category();
}
return is_category( $args['cats'] );
}
}
}

View File

@@ -0,0 +1,98 @@
<?php
/**
* Is front page condition
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Theme_Core_Conditions_Archive_Post_Type' ) ) {
/**
* Define Jet_Theme_Core_Conditions_Archive_Post_Type class
*/
class Jet_Theme_Core_Conditions_Archive_Post_Type extends Jet_Theme_Core_Conditions_Base {
/**
* Condition slug
*
* @return string
*/
public function get_id() {
return 'archive-post-type';
}
/**
* Condition label
*
* @return string
*/
public function get_label() {
return __( 'Post Type Archives', 'jet-theme-core' );
}
/**
* Condition group
*
* @return string
*/
public function get_group() {
return 'archive';
}
public function get_controls() {
return array(
'types' => array(
'label' => esc_html__( 'Post Type', 'jet-theme-core' ),
'type' => Elementor\Controls_Manager::SELECT2,
'default' => 'post',
'options' => Jet_Theme_Core_Utils::get_post_types(),
'multiple' => true,
),
);
}
public function verbose_args( $args ) {
if ( empty( $args['types'] ) ) {
return __( 'All', 'jet-theme-core' );
}
$result = '';
$sep = '';
foreach ( $args['types'] as $post_type ) {
$obj = get_post_type_object( $post_type );
$label = ! empty( $obj ) ? $obj->labels->singular_name : $post_type;
$result .= $sep . $label;
$sep = ', ';
}
return $result;
}
/**
* Condition check callback
*
* @return bool
*/
public function check( $args ) {
if ( empty( $args['types'] ) ) {
return is_post_type_archive();
}
$types = $args['types'];
if ( in_array( 'post', $types ) && 'post' === get_post_type() ) {
return is_archive() || is_home();
}
return is_post_type_archive( $types ) || ( is_tax() && in_array( get_post_type(), $types ) );
}
}
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* Is front page condition
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Theme_Core_Conditions_Archive_Search' ) ) {
/**
* Define Jet_Theme_Core_Conditions_Archive_Search class
*/
class Jet_Theme_Core_Conditions_Archive_Search extends Jet_Theme_Core_Conditions_Base {
/**
* Condition slug
*
* @return string
*/
public function get_id() {
return 'archive-search';
}
/**
* Condition label
*
* @return string
*/
public function get_label() {
return __( 'Search Results', 'jet-theme-core' );
}
/**
* Condition group
*
* @return string
*/
public function get_group() {
return 'archive';
}
public function get_controls() {
return array();
}
public function verbose_args( $args ) {
return '';
}
/**
* Condition check callback
*
* @return bool
*/
public function check( $args ) {
return is_search();
}
}
}

View File

@@ -0,0 +1,123 @@
<?php
/**
* Is front page condition
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Theme_Core_Conditions_Archive_Tag' ) ) {
/**
* Define Jet_Theme_Core_Conditions_Archive_Tag class
*/
class Jet_Theme_Core_Conditions_Archive_Tag extends Jet_Theme_Core_Conditions_Base {
/**
* Condition slug
*
* @return string
*/
public function get_id() {
return 'archive-tag';
}
/**
* Condition label
*
* @return string
*/
public function get_label() {
return __( 'Tag Archives', 'jet-theme-core' );
}
/**
* Condition group
*
* @return string
*/
public function get_group() {
return 'archive';
}
public function get_controls() {
return array(
'tags' => array(
'label' => __( 'Select Tags', 'jet-theme-core' ),
'type' => 'jet_search',
'action' => 'jet_theme_search_tags',
'label_block' => true,
'multiple' => true,
'description' => __( 'Leave empty to apply for all tags', 'jet-theme-core' ),
'saved' => $this->get_saved_tags(),
),
);
}
public function get_saved_tags() {
$template_id = get_the_ID();
$saved = get_post_meta( $template_id, '_elementor_page_settings', true );
if ( ! empty( $saved['conditions_archive-tag_tags'] ) ) {
$terms = get_terms( array(
'include' => $saved['conditions_archive-tag_tags'],
'taxonomy' => 'post_tag',
'hide_empty' => false,
) );
if ( empty( $terms ) ) {
return array();
} else {
return wp_list_pluck( $terms, 'name', 'term_id' );
}
} else {
return array();
}
}
public function verbose_args( $args ) {
if ( empty( $args['tags'] ) ) {
return __( 'All', 'jet-theme-core' );
}
$result = '';
$sep = '';
$terms = get_terms( array(
'include' => $args['tags'],
'taxonomy' => 'post_tag',
'hide_empty' => false,
) );
foreach ( $terms as $term ) {
$result .= $sep . $term->name;
$sep = ', ';
}
return $result;
}
/**
* Condition check callback
*
* @return bool
*/
public function check( $args ) {
if ( empty( $args['tags'] ) ) {
return is_tag();
}
return is_tag( $args['tags'] );
}
}
}

View File

@@ -0,0 +1,144 @@
<?php
/**
* Is front page condition
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Theme_Core_Conditions_Archive_Tax' ) ) {
/**
* Define Jet_Theme_Core_Conditions_Archive_Tax class
*/
class Jet_Theme_Core_Conditions_Archive_Tax extends Jet_Theme_Core_Conditions_Base {
/**
* Condition slug
*
* @return string
*/
public function get_id() {
return 'archive-tax';
}
/**
* Condition label
*
* @return string
*/
public function get_label() {
return __( 'Custom Taxonomy Archives', 'jet-theme-core' );
}
/**
* Condition group
*
* @return string
*/
public function get_group() {
return 'archive';
}
public function get_controls() {
return array(
'tax' => array(
'label' => esc_html__( 'Taxonomy', 'jet-theme-core' ),
'type' => Elementor\Controls_Manager::SELECT2,
'default' => '',
'options' => Jet_Theme_Core_Utils::get_taxonomies(),
'multiple' => true,
),
'terms' => array(
'label' => __( 'Select Terms', 'jet-theme-core' ),
'type' => 'jet_search',
'action' => 'jet_theme_search_terms',
'query_params' => array( 'conditions_archive-tax_tax' ),
'label_block' => true,
'multiple' => true,
'description' => __( 'Leave empty to apply for all terms', 'jet-theme-core' ),
'saved' => $this->get_saved_tags(),
),
);
}
public function get_saved_tags() {
$template_id = get_the_ID();
$saved = get_post_meta( $template_id, '_elementor_page_settings', true );
if ( empty( $saved['conditions_archive-tax_tax'] ) ) {
return array();
}
$tax = $saved['conditions_archive-tax_tax'];
if ( ! empty( $saved['conditions_archive-tax_terms'] ) ) {
$terms = get_terms( array(
'include' => $saved['conditions_archive-tax_terms'],
'taxonomy' => $tax,
'hide_empty' => false,
) );
if ( empty( $terms ) ) {
return array();
} else {
return wp_list_pluck( $terms, 'name', 'term_id' );
}
} else {
return array();
}
}
public function verbose_args( $args ) {
if ( empty( $args['tax'] ) ) {
return __( 'All', 'jet-theme-core' );
}
$result = '';
$sep = '';
$terms = get_terms( array(
'include' => $args['tax'],
'taxonomy' => 'post_tag',
'hide_empty' => false,
) );
foreach ( $terms as $term ) {
$result .= $sep . $term->name;
$sep = ', ';
}
return $result;
}
/**
* Condition check callback
*
* @return bool
*/
public function check( $args ) {
if ( empty( $args['tax'] ) ) {
return is_tax();
}
if ( ! empty( $args['tax'] ) && empty( $args['terms'] ) ) {
return is_tax( $args['tax'] );
}
if ( ! empty( $args['terms'] ) ) {
return is_tax( $args['tax'], $args['terms'] );
}
}
}
}

View File

@@ -0,0 +1,80 @@
<?php
/**
* Class description
*
* @package package_name
* @author Cherry Team
* @license GPL-2.0+
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Theme_Core_Conditions_Base' ) ) {
/**
* Define Jet_Theme_Core_Conditions_Base class
*/
abstract class Jet_Theme_Core_Conditions_Base {
/**
* Condition slug
*
* @return string
*/
abstract public function get_id();
/**
* Condition label
*
* @return string
*/
abstract public function get_label();
/**
* Condition group
*
* @return string
*/
abstract public function get_group();
/**
* Condition check callback
*
* @return bool
*/
abstract public function check( $args );
/**
* Returns parent codition ID for current condition
*
* @return array
*/
public function get_childs() {
return array();
}
/**
* Returns parent codition ID for current condition
*
* @return array
*/
public function get_controls() {
return array();
}
/**
* Returns human-reading information about active arguments for condition
*
* @param arrayu $args
* @return string
*/
public function verbose_args( $args ) {
return '';
}
}
}

View File

@@ -0,0 +1,557 @@
<?php
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Theme_Core_Conditions_Manager' ) ) {
/**
* Define Jet_Theme_Core_Conditions_Manager class
*/
class Jet_Theme_Core_Conditions_Manager {
private $_conditions = array();
private $_matched_conditions = array();
private $_processed_childs = array();
public $conditions_key = 'jet_site_conditions';
public function __construct() {
$this->register_conditions();
add_action( 'elementor/editor/after_save', array( $this, 'update_site_conditions' ) );
add_action( 'wp_trash_post', array( $this, 'remove_post_from_site_conditions' ) );
}
public function update_site_conditions( $post_id ) {
$post = get_post( $post_id );
if ( jet_theme_core()->templates->slug() !== $post->post_type ) {
return;
}
$type = get_post_meta( $post_id, '_elementor_template_type', true );
$sanitized = $this->get_post_conditions( $post_id );
$saved = get_option( $this->conditions_key, array() );
$saved = $this->remove_post_from_conditions_array( $post_id, $saved );
if ( ! isset( $saved[ $type ] ) ) {
$saved[ $type ] = array();
}
$saved[ $type ][ $post_id ] = $sanitized;
update_option( $this->conditions_key, $saved, true );
}
public function get_site_conditions() {
return get_option( $this->conditions_key, array() );
}
public function get_post_conditions( $post_id ) {
$group = '';
$conditions = get_post_meta( $post_id, '_elementor_page_settings', true );
$sanitized = array();
if ( ! $conditions ) {
$conditions = array();
}
foreach ( $conditions as $condition => $value ) {
if ( false === strpos( $condition, 'conditions_' ) ) {
continue;
}
if ( 'conditions_top' === $condition ) {
$group = $value;
$sanitized['main'] = $group;
continue;
}
if ( 'conditions_sub_' . $group === $condition ) {
$sanitized[ $value ] = $this->get_condition_args( $value, $conditions );
continue;
}
}
return $sanitized;
}
/**
* Check if post currently presented in conditions array and remove it if yes.
*
* @param integer $post_id [description]
* @param array $conditions [description]
* @return [type] [description]
*/
public function remove_post_from_conditions_array( $post_id = 0, $conditions = array() ) {
foreach ( $conditions as $type => $type_conditions ) {
if ( array_key_exists( $post_id, $type_conditions ) ) {
unset( $conditions[ $type ][ $post_id ] );
}
}
return $conditions;
}
public function remove_post_from_site_conditions( $post_id = 0 ) {
$conditions = get_option( $this->conditions_key, array() );
$conditions = $this->remove_post_from_conditions_array( $post_id, $conditions );
update_option( $this->conditions_key, $conditions, true );
}
/**
* Find condition arguments in saved data
*
* @param [type] $cid [description]
* @param [type] $conditions [description]
* @return [type] [description]
*/
public function get_condition_args( $cid, $conditions ) {
$args = array();
$prefix = 'conditions_' . $cid . '_';
foreach ( $conditions as $condition => $value ) {
if ( false === strpos( $condition, $prefix ) ) {
continue;
}
$args[ str_replace( $prefix, '', $condition ) ] = $value;
}
return $args;
}
public function register_conditions() {
$base_path = jet_theme_core()->plugin_path( 'includes/conditions/' );
require $base_path . 'base.php';
$default = array(
// Singular conditions
'Jet_Theme_Core_Conditions_Front' => $base_path . 'singular-front-page.php',
'Jet_Theme_Core_Conditions_Singular_Post_Type' => $base_path . 'singular-post-type.php',
'Jet_Theme_Core_Conditions_Singular_Post' => $base_path . 'singular-post.php',
'Jet_Theme_Core_Conditions_Singular_Post_From_Category' => $base_path . 'singular-post-from-cat.php',
'Jet_Theme_Core_Conditions_Singular_Post_From_Tag' => $base_path . 'singular-post-from-tag.php',
'Jet_Theme_Core_Conditions_Singular_Page' => $base_path . 'singular-page.php',
'Jet_Theme_Core_Conditions_Singular_Page_Child' => $base_path . 'singular-page-child.php',
'Jet_Theme_Core_Conditions_Singular_Page_Template' => $base_path . 'singular-page-template.php',
'Jet_Theme_Core_Conditions_Singular_404' => $base_path . 'singular-404.php',
// Archive conditions
'Jet_Theme_Core_Conditions_Archive_All' => $base_path . 'archive-all.php',
'Jet_Theme_Core_Conditions_Archive_Post_Type' => $base_path . 'archive-post-type.php',
'Jet_Theme_Core_Conditions_Archive_Category' => $base_path . 'archive-category.php',
'Jet_Theme_Core_Conditions_Archive_Tag' => $base_path . 'archive-tag.php',
'Jet_Theme_Core_Conditions_Archive_Tax' => $base_path . 'archive-tax.php',
'Jet_Theme_Core_Conditions_Archive_Search' => $base_path . 'archive-search.php',
);
foreach ( $default as $class => $file ) {
require $file;
$this->register_condition( $class );
}
/**
* You could register custom conditions on this hook.
* Note - each condition should be presented like instance of class 'Jet_Theme_Core_Conditions_Base'
*/
do_action( 'jet-theme-core/conditions/register', $this );
}
public function register_condition( $class ) {
$instance = new $class;
$this->_conditions[ $instance->get_id() ] = $instance;
}
public function get_condition( $condition_id ) {
return isset( $this->_conditions[ $condition_id ] ) ? $this->_conditions[ $condition_id ] : false;
}
/**
* Returns conditions groups
*
* @return void
*/
public function get_groups() {
return array(
'entire' => __( 'Entire Site', 'jet-theme-core' ),
'singular' => __( 'Singular', 'jet-theme-core' ),
'archive' => __( 'Archive', 'jet-theme-core' ),
);
}
/**
* Regsiter apropriate condition controls
*
* @return [type] [description]
*/
public function register_condition_controls( $controls_manager ) {
if ( ! $controls_manager ) {
return;
}
$prepared_data = $this->prepare_conditions_for_controls();
$default = array( '' => esc_html__( 'Select...', 'jet-theme-core' ) );
$general = $default + $this->get_groups();
$controls_manager->add_control(
'conditions_top',
array(
'label' => esc_html__( 'General', 'jet-theme-core' ),
'type' => Elementor\Controls_Manager::SELECT,
'default' => '',
'options' => $general,
)
);
foreach ( $prepared_data as $group => $options ) {
if ( empty( $options ) ) {
continue;
}
$condition = array(
'conditions_top' => $group,
);
$control_name = 'conditions_sub_' . $group;
$controls_manager->add_control(
$control_name,
array(
'label' => $general[ $group ],
'type' => Elementor\Controls_Manager::SELECT,
'default' => '',
'options' => $this->esc_options( $options ),
'condition' => $condition,
)
);
$this->register_child_options_group( $options, $controls_manager, $control_name, $condition );
}
}
/**
* Get options list from options data
*
* @param [type] $data [description]
* @return [type] [description]
*/
public function esc_options( $data ) {
$result = array();
foreach ( $data as $id => $item ) {
$result[ $id ] = $item['label'];
}
return $result;
}
public function esc_child_options( $childs ) {
$result = array();
foreach ( $childs as $child ) {
$instance = $this->get_condition( $child );
$result[ $child ] = $instance->get_label();
}
return $result;
}
public function register_child_options_group( $options, $controls_manager, $parent_id, $parent_condition ) {
foreach ( $options as $cid => $data ) {
$this->register_child_controls( $cid, $controls_manager, $parent_id, $parent_condition );
if ( empty( $data['childs'] ) ) {
continue;
}
$condition = array_merge(
$parent_condition,
array(
$parent_id => $cid
)
);
$instance = $this->get_condition( $cid );
$control_name = 'conditions_sub_' . $cid;
$controls_manager->add_control(
$control_name,
array(
'label' => $instance->get_label(),
'type' => Elementor\Controls_Manager::SELECT,
'default' => '',
'options' => $this->esc_child_options( $data['childs'] ),
'condition' => $condition,
)
);
$this->register_child_options_item( $data['childs'], $controls_manager, $control_name, $condition );
}
}
public function register_child_options_item( $items, $controls_manager, $parent_id, $parent_condition ) {
foreach ( $items as $cid ) {
$instance = $this->get_condition( $cid );
$childs = $instance->get_childs();
$this->register_child_controls( $cid, $controls_manager, $parent_id, $parent_condition );
if ( empty( $childs ) ) {
continue;
}
$condition = array_merge(
$parent_condition,
array(
$parent_id => $cid
)
);
$control_name = 'conditions_sub_' . $cid;
$controls_manager->add_control(
$control_name,
array(
'label' => $instance->get_label(),
'type' => Elementor\Controls_Manager::SELECT,
'default' => '',
'options' => $this->esc_child_options( $childs ),
'condition' => $condition,
)
);
$this->register_child_options_item( $childs, $controls_manager, $control_name, $condition );
}
}
public function register_child_controls( $condition_id, $controls_manager, $parent_id, $parent_condition ) {
$instance = $this->get_condition( $condition_id );
$controls = $instance->get_controls();
if ( empty( $controls ) ) {
return;
}
foreach ( $controls as $control_id => $control_options ) {
$id = 'conditions_' . $condition_id . '_' . $control_id;
$child_cond = ! empty( $control_options['condition'] ) ? $control_options['condition'] : array();
$control_options['condition'] = array_merge(
$child_cond,
array( $parent_id => $condition_id ),
$parent_condition
);
$controls_manager->add_control( $id, $control_options );
}
}
/**
* Prepare registerred conditions for controls
*
* @return array
*/
public function prepare_conditions_for_controls() {
$sorted_conditions = array();
foreach ( $this->_conditions as $cid => $instance ) {
if ( in_array( $cid, $this->_processed_childs ) ) {
continue;
}
$group = $instance->get_group();
$childs = $instance->get_childs();
if ( ! isset( $sorted_conditions[ $group ] ) ) {
$sorted_conditions[ $group ] = array();
}
$current = array(
'label' => $instance->get_label(),
);
if ( ! empty( $childs ) ) {
$current['childs'] = $this->add_condition_childs( $childs );
}
$sorted_conditions[ $group ][ $cid ] = $current;
}
return $sorted_conditions;
}
/**
* Add child conditions to stack
*/
public function add_condition_childs( $childs ) {
$result = array();
foreach ( $childs as $cid ) {
$instance = $this->get_condition( $cid );
$childs = $instance->get_childs();
$current = array(
'label' => $instance->get_label(),
);
if ( ! empty( $childs ) ) {
$current['childs'] = $this->add_condition_childs( $childs );
}
$result[ $cid ] = $current;
if ( ! in_array( $cid, $this->_processed_childs ) ) {
$this->_processed_childs[] = $cid;
}
}
return $result;
}
/**
* Run condtions check for passed type. Return {template_id} on firs condition match.
* If not matched - return false
*
* @return int|bool
*/
public function find_matched_conditions( $type ) {
if ( isset( $this->_matched_conditions[ $type ] ) ) {
return $this->_matched_conditions[ $type ];
}
$conditions = get_option( $this->conditions_key, array() );
if ( empty( $conditions[ $type ] ) ) {
$this->_matched_conditions[ $type ] = false;
return false;
}
$entire = false;
foreach ( $conditions[ $type ] as $template_id => $template_conditions ) {
if ( empty( $template_conditions['main'] ) ) {
continue;
}
if ( 'entire' === $template_conditions['main'] ) {
$this->_matched_conditions[ $type ] = $template_id;
$entire = $template_id;
continue;
}
foreach ( $template_conditions as $cid => $args ) {
$instance = $this->get_condition( $cid );
if ( ! $instance ) {
continue;
}
$check = call_user_func( array( $instance, 'check' ), $args );
if ( true === $check ) {
$this->_matched_conditions[ $type ] = $template_id;
return $template_id;
}
}
}
if ( $entire ) {
return $entire;
}
$this->_matched_conditions[ $type ] = false;
return false;
}
/**
* Get active conditions for passed post
*
* @param [type] $post_id [description]
* @return [type] [description]
*/
public function post_conditions_verbose( $post_id = null ) {
$conditions = $this->get_post_conditions( $post_id );
if ( empty( $conditions['main'] ) ) {
return;
}
if ( 'entire' === $conditions['main'] ) {
return __( 'Entire Site', 'jet-theme-core' );
}
unset( $conditions['main'] );
$condition_keys = array_keys( $conditions );
$verbose = '';
foreach ( $condition_keys as $key ) {
$instance = $this->get_condition( $key );
$verbose_args = $instance->verbose_args( $conditions[ $key ] );
if ( ! empty( $verbose_args ) ) {
$verbose_args = ': ' . $verbose_args;
}
$verbose .= sprintf( '<div>%1$s%2$s</div>', $instance->get_label(), $verbose_args );
}
return $verbose;
}
}
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* Is front page condition
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Theme_Core_Conditions_Singular_404' ) ) {
/**
* Define Jet_Theme_Core_Conditions_Singular_404 class
*/
class Jet_Theme_Core_Conditions_Singular_404 extends Jet_Theme_Core_Conditions_Base {
/**
* Condition slug
*
* @return string
*/
public function get_id() {
return 'singular-404';
}
/**
* Condition label
*
* @return string
*/
public function get_label() {
return __( '404 Page', 'jet-theme-core' );
}
/**
* Condition group
*
* @return string
*/
public function get_group() {
return 'singular';
}
/**
* Condition check callback
*
* @return bool
*/
public function check( $args ) {
return is_404();
}
}
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* Is front page condition
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Theme_Core_Conditions_Front' ) ) {
/**
* Define Jet_Theme_Core_Conditions_Front class
*/
class Jet_Theme_Core_Conditions_Front extends Jet_Theme_Core_Conditions_Base {
/**
* Condition slug
*
* @return string
*/
public function get_id() {
return 'singular-front-page';
}
/**
* Condition label
*
* @return string
*/
public function get_label() {
return __( 'Front Page', 'jet-theme-core' );
}
/**
* Condition group
*
* @return string
*/
public function get_group() {
return 'singular';
}
/**
* Condition check callback
*
* @return bool
*/
public function check( $args ) {
return is_front_page();
}
}
}

View File

@@ -0,0 +1,139 @@
<?php
/**
* Is front page condition
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Theme_Core_Conditions_Singular_Page_Child' ) ) {
/**
* Define Jet_Theme_Core_Conditions_Singular_Page_Child class
*/
class Jet_Theme_Core_Conditions_Singular_Page_Child extends Jet_Theme_Core_Conditions_Base {
/**
* Condition slug
*
* @return string
*/
public function get_id() {
return 'singular-page-child';
}
/**
* Condition label
*
* @return string
*/
public function get_label() {
return __( 'Page, Child of', 'jet-theme-core' );
}
/**
* Condition group
*
* @return string
*/
public function get_group() {
return 'singular';
}
public function get_controls() {
return array(
'pages' => array(
'label' => __( 'Select Parent', 'jet-theme-core' ),
'type' => 'jet_search',
'action' => 'jet_theme_search_pages',
'label_block' => true,
'multiple' => false,
'saved' => $this->get_saved_pages(),
),
);
}
public function get_saved_pages() {
$template_id = get_the_ID();
$saved = get_post_meta( $template_id, '_elementor_page_settings', true );
if ( ! empty( $saved['conditions_singular-page-child_pages'] ) ) {
if ( ! is_array( $saved['conditions_singular-page-child_pages'] ) ) {
$pages = array( $saved['conditions_singular-page-child_pages'] );
} else {
$pages = $saved['conditions_singular-page-child_pages'];
}
$posts = get_posts( array(
'post_type' => 'page',
'post__in' => $pages,
'ignore_sticky_posts' => true,
) );
if ( empty( $posts ) ) {
return array();
} else {
return wp_list_pluck( $posts, 'post_title', 'ID' );
}
} else {
return array();
}
}
public function verbose_args( $args ) {
if ( empty( $args['pages'] ) ) {
return __( 'Not Selected', 'jet-theme-core' );
}
$result = '';
$sep = '';
if ( ! is_array( $args['pages'] ) ) {
$parents = array( $args['pages'] );
} else {
$parents = $args['pages'];
}
foreach ( $parents as $page ) {
$result .= $sep . get_the_title( $page );
$sep = ', ';
}
return $result;
}
/**
* Condition check callback
*
* @return bool
*/
public function check( $args ) {
if ( empty( $args['pages'] ) ) {
return false;
}
if ( ! is_page() ) {
return false;
}
if ( ! is_array( $args['pages'] ) ) {
$parents = array( $args['pages'] );
} else {
$parents = $args['pages'];
}
global $post;
return in_array( $post->post_parent, $parents );
}
}
}

View File

@@ -0,0 +1,93 @@
<?php
/**
* Is front page condition
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Theme_Core_Conditions_Singular_Page_Template' ) ) {
/**
* Define Jet_Theme_Core_Conditions_Singular_Page_Template class
*/
class Jet_Theme_Core_Conditions_Singular_Page_Template extends Jet_Theme_Core_Conditions_Base {
/**
* Condition slug
*
* @return string
*/
public function get_id() {
return 'singular-page-template';
}
/**
* Condition label
*
* @return string
*/
public function get_label() {
return __( 'Page Template', 'jet-theme-core' );
}
/**
* Condition group
*
* @return string
*/
public function get_group() {
return 'singular';
}
public function get_controls() {
$templates = wp_get_theme()->get_page_templates();
$templates = array( '' => __( 'Select...', 'jet-theme-core' ) ) + $templates;
return array(
'template' => array(
'label' => __( 'Select Template', 'jet-theme-core' ),
'type' => Elementor\Controls_Manager::SELECT,
'default' => '',
'options' => $templates,
),
);
}
public function verbose_args( $args ) {
if ( empty( $args['template'] ) ) {
return __( 'Not Selected', 'jet-theme-core' );
}
return $args['template'];
}
/**
* Condition check callback
*
* @return bool
*/
public function check( $args ) {
if ( empty( $args['template'] ) ) {
return false;
}
if ( ! is_page() ) {
return false;
}
global $post;
$page_template_slug = get_page_template_slug( $post->ID );
return $page_template_slug === $args['template'];
}
}
}

View File

@@ -0,0 +1,116 @@
<?php
/**
* Is front page condition
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Theme_Core_Conditions_Singular_Page' ) ) {
/**
* Define Jet_Theme_Core_Conditions_Singular_Page class
*/
class Jet_Theme_Core_Conditions_Singular_Page extends Jet_Theme_Core_Conditions_Base {
/**
* Condition slug
*
* @return string
*/
public function get_id() {
return 'singular-page';
}
/**
* Condition label
*
* @return string
*/
public function get_label() {
return __( 'Page', 'jet-theme-core' );
}
/**
* Condition group
*
* @return string
*/
public function get_group() {
return 'singular';
}
public function get_controls() {
return array(
'pages' => array(
'label' => __( 'Select Pages', 'jet-theme-core' ),
'type' => 'jet_search',
'action' => 'jet_theme_search_pages',
'label_block' => true,
'multiple' => true,
'description' => __( 'Leave empty to apply for all pages', 'jet-theme-core' ),
'saved' => $this->get_saved_pages(),
),
);
}
public function get_saved_pages() {
$template_id = get_the_ID();
$saved = get_post_meta( $template_id, '_elementor_page_settings', true );
if ( ! empty( $saved['conditions_singular-page_pages'] ) ) {
$posts = get_posts( array(
'post_type' => 'page',
'post__in' => $saved['conditions_singular-page_pages'],
'ignore_sticky_posts' => true,
) );
if ( empty( $posts ) ) {
return array();
} else {
return wp_list_pluck( $posts, 'post_title', 'ID' );
}
} else {
return array();
}
}
public function verbose_args( $args ) {
if ( empty( $args['pages'] ) ) {
return __( 'All', 'jet-theme-core' );
}
$result = '';
$sep = '';
foreach ( $args['pages'] as $page ) {
$result .= $sep . get_the_title( $page );
$sep = ', ';
}
return $result;
}
/**
* Condition check callback
*
* @return bool
*/
public function check( $args ) {
if ( empty( $args['pages'] ) ) {
return is_page();
}
return is_page( $args['pages'] );
}
}
}

View File

@@ -0,0 +1,127 @@
<?php
/**
* Is front page condition
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Theme_Core_Conditions_Singular_Post_From_Category' ) ) {
/**
* Define Jet_Theme_Core_Conditions_Singular_Post_From_Category class
*/
class Jet_Theme_Core_Conditions_Singular_Post_From_Category extends Jet_Theme_Core_Conditions_Base {
/**
* Condition slug
*
* @return string
*/
public function get_id() {
return 'singular-post-from-cat';
}
/**
* Condition label
*
* @return string
*/
public function get_label() {
return __( 'Posts from Category', 'jet-theme-core' );
}
/**
* Condition group
*
* @return string
*/
public function get_group() {
return 'singular';
}
public function get_controls() {
return array(
'cats' => array(
'label' => __( 'Select Categories', 'jet-theme-core' ),
'type' => 'jet_search',
'action' => 'jet_theme_search_cats',
'label_block' => true,
'multiple' => true,
'saved' => $this->get_saved_cats(),
),
);
}
public function get_saved_cats() {
$template_id = get_the_ID();
$saved = get_post_meta( $template_id, '_elementor_page_settings', true );
if ( ! empty( $saved['conditions_singular-post-from-cat_cats'] ) ) {
$terms = get_terms( array(
'include' => $saved['conditions_singular-post-from-cat_cats'],
'taxonomy' => 'category',
'hide_empty' => false,
) );
if ( empty( $terms ) ) {
return array();
} else {
return wp_list_pluck( $terms, 'name', 'term_id' );
}
} else {
return array();
}
}
public function verbose_args( $args ) {
if ( empty( $args['cats'] ) ) {
return __( 'All', 'jet-theme-core' );
}
$result = '';
$sep = '';
$terms = get_terms( array(
'include' => $args['cats'],
'taxonomy' => 'category',
'hide_empty' => false,
) );
foreach ( $terms as $term ) {
$result .= $sep . $term->name;
$sep = ', ';
}
return $result;
}
/**
* Condition check callback
*
* @return bool
*/
public function check( $args ) {
if ( empty( $args['cats'] ) ) {
return false;
}
if ( ! is_single() ) {
return false;
}
global $post;
return in_category( $args['cats'], $post );
}
}
}

View File

@@ -0,0 +1,127 @@
<?php
/**
* Is front page condition
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Theme_Core_Conditions_Singular_Post_From_Tag' ) ) {
/**
* Define Jet_Theme_Core_Conditions_Singular_Post_From_Tag class
*/
class Jet_Theme_Core_Conditions_Singular_Post_From_Tag extends Jet_Theme_Core_Conditions_Base {
/**
* Condition slug
*
* @return string
*/
public function get_id() {
return 'singular-post-from-tag';
}
/**
* Condition label
*
* @return string
*/
public function get_label() {
return __( 'Posts from Tag', 'jet-theme-core' );
}
/**
* Condition group
*
* @return string
*/
public function get_group() {
return 'singular';
}
public function get_controls() {
return array(
'tags' => array(
'label' => __( 'Select Tags', 'jet-theme-core' ),
'type' => 'jet_search',
'action' => 'jet_theme_search_tags',
'label_block' => true,
'multiple' => true,
'saved' => $this->get_saved_tags(),
),
);
}
public function get_saved_tags() {
$template_id = get_the_ID();
$saved = get_post_meta( $template_id, '_elementor_page_settings', true );
if ( ! empty( $saved['conditions_singular-post-from-tag_tags'] ) ) {
$terms = get_terms( array(
'include' => $saved['conditions_singular-post-from-tag_tags'],
'taxonomy' => 'post_tag',
'hide_empty' => false,
) );
if ( empty( $terms ) ) {
return array();
} else {
return wp_list_pluck( $terms, 'name', 'term_id' );
}
} else {
return array();
}
}
public function verbose_args( $args ) {
if ( empty( $args['tags'] ) ) {
return __( 'All', 'jet-theme-core' );
}
$result = '';
$sep = '';
$terms = get_terms( array(
'include' => $args['tags'],
'taxonomy' => 'post_tag',
'hide_empty' => false,
) );
foreach ( $terms as $term ) {
$result .= $sep . $term->name;
$sep = ', ';
}
return $result;
}
/**
* Condition check callback
*
* @return bool
*/
public function check( $args ) {
if ( empty( $args['tags'] ) ) {
return false;
}
if ( ! is_single() ) {
return false;
}
global $post;
return has_tag( $args['tags'], $post );
}
}
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* Is front page condition
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Theme_Core_Conditions_Singular_Post_Type' ) ) {
/**
* Define Jet_Theme_Core_Conditions_Singular_Post_Type class
*/
class Jet_Theme_Core_Conditions_Singular_Post_Type extends Jet_Theme_Core_Conditions_Base {
/**
* Condition slug
*
* @return string
*/
public function get_id() {
return 'singular-post-type';
}
/**
* Condition label
*
* @return string
*/
public function get_label() {
return __( 'Post Type', 'jet-theme-core' );
}
/**
* Condition group
*
* @return string
*/
public function get_group() {
return 'singular';
}
public function get_controls() {
return array(
'types' => array(
'label' => esc_html__( 'Post Type', 'jet-theme-core' ),
'type' => Elementor\Controls_Manager::SELECT2,
'default' => 'post',
'options' => Jet_Theme_Core_Utils::get_post_types(),
'multiple' => true,
),
);
}
public function verbose_args( $args ) {
if ( empty( $args['types'] ) ) {
return __( 'All', 'jet-theme-core' );
}
$result = '';
$sep = '';
foreach ( $args['types'] as $post_type ) {
$obj = get_post_type_object( $post_type );
$result .= $sep . $obj->labels->singular_name;
$sep = ', ';
}
return $result;
}
/**
* Condition check callback
*
* @return bool
*/
public function check( $args ) {
if ( empty( $args['types'] ) ) {
return is_singular();
}
return is_singular( $args['types'] );
}
}
}

View File

@@ -0,0 +1,116 @@
<?php
/**
* Is front page condition
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Theme_Core_Conditions_Singular_Post' ) ) {
/**
* Define Jet_Theme_Core_Conditions_Singular_Post class
*/
class Jet_Theme_Core_Conditions_Singular_Post extends Jet_Theme_Core_Conditions_Base {
/**
* Condition slug
*
* @return string
*/
public function get_id() {
return 'singular-post';
}
/**
* Condition label
*
* @return string
*/
public function get_label() {
return __( 'Post', 'jet-theme-core' );
}
/**
* Condition group
*
* @return string
*/
public function get_group() {
return 'singular';
}
public function get_controls() {
return array(
'posts' => array(
'label' => __( 'Select Posts', 'jet-theme-core' ),
'type' => 'jet_search',
'action' => 'jet_theme_search_posts',
'label_block' => true,
'multiple' => true,
'description' => __( 'Leave empty to apply for all posts', 'jet-theme-core' ),
'saved' => $this->get_saved_posts(),
),
);
}
public function get_saved_posts() {
$template_id = get_the_ID();
$saved = get_post_meta( $template_id, '_elementor_page_settings', true );
if ( ! empty( $saved['conditions_singular-post_posts'] ) ) {
$posts = get_posts( array(
'post_type' => 'post',
'post__in' => $saved['conditions_singular-post_posts'],
'ignore_sticky_posts' => true,
) );
if ( empty( $posts ) ) {
return array();
} else {
return wp_list_pluck( $posts, 'post_title', 'ID' );
}
} else {
return array();
}
}
public function verbose_args( $args ) {
if ( empty( $args['posts'] ) ) {
return __( 'All', 'jet-theme-core' );
}
$result = '';
$sep = '';
foreach ( $args['posts'] as $post ) {
$result .= $sep . get_the_title( $post );
$sep = ', ';
}
return $result;
}
/**
* Condition check callback
*
* @return bool
*/
public function check( $args ) {
if ( empty( $args['posts'] ) ) {
return is_single();
}
return is_single( $args['posts'] );
}
}
}