PluginProbe
Ele Conditions for Elementor / trunk
Ele Conditions for Elementor vtrunk
2.0.0 trunk 1.0.6 1.0.7 1.0.8
ele-conditions / ele-conditions.php

ele-conditions.php in Ele Conditions for Elementor trunk, at ele-conditions.php

91 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Plugin Name: Ele Conditions for Elementor
4 * Version: 2.0.0
5 * Description: Conditional display logic for Elementor elements and widgets.
6 * Plugin URI: https://www.eletemplator.com
7 * Author: Liviu Duda
8 * Author URI: https://www.leadpro.ro
9 * Text Domain: ele-conditions
10 * Domain Path: /languages
11 * License: GPL-2.0-or-later
12 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
13 */
14 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
15 define( 'ELECONDITIONS_DIR', plugin_dir_path( __FILE__ ) );
16 require_once ELECONDITIONS_DIR . 'inc/controls.php';
17 require_once ELECONDITIONS_DIR . 'inc/controls-triggers.php';
18
19 add_action( 'wp_enqueue_scripts', function() {
20 wp_enqueue_script(
21 'elecond-triggers',
22 plugin_dir_url( __FILE__ ) . 'assets/js/triggers.js',
23 [],
24 '2.0.0',
25 true
26 );
27 } );
28
29 add_action( 'elementor/controls/register', function( $controls_manager ) {
30 require_once ELECONDITIONS_DIR . 'inc/control-datetime.php';
31 $controls_manager->register( new Elecond_Datetime_Control() );
32 } );
33
34 add_filter( 'eleconditions_vars', 'elecond_keywords' );
35 function elecond_keywords( $custom_vars ) {
36 global $post;
37
38 // Date/time in WordPress timezone
39 $tz = wp_timezone();
40 $now_dt = new DateTime( 'now', $tz );
41
42 $custom_vars['now'] = $now_dt->format( 'Y-m-d H:i:s' );
43 $custom_vars['current_date'] = $now_dt->format( 'Y-m-d' );
44 $custom_vars['current_hour'] = (int) $now_dt->format( 'G' ); // 0–23
45 $custom_vars['current_day'] = (int) $now_dt->format( 'N' ); // 1=Mon, 7=Sun
46 $custom_vars['current_month'] = (int) $now_dt->format( 'n' ); // 1–12
47 $custom_vars['current_year'] = (int) $now_dt->format( 'Y' );
48
49 // Post
50 if ( isset( $post->ID ) ) {
51 $custom_vars['comment_count'] = (int) get_comments_number( $post->ID );
52 $custom_vars['post_author'] = get_the_author_meta( 'login', $post->post_author );
53 $custom_vars['post_author_id'] = (int) $post->post_author;
54 $custom_vars['post_status'] = $post->post_status;
55 $custom_vars['post_type'] = $post->post_type;
56 $custom_vars['content_length'] = mb_strlen( wp_strip_all_tags( $post->post_content ) );
57 $custom_vars['excerpt_length'] = mb_strlen( wp_strip_all_tags( get_the_excerpt( $post->ID ) ) );
58 }
59
60 // Current user
61 $user = wp_get_current_user();
62 $custom_vars['user_id'] = $user->ID;
63 $custom_vars['user_role'] = ! empty( $user->roles ) ? $user->roles[0] : '';
64 $custom_vars['is_logged_in'] = is_user_logged_in() ? 'true' : 'false';
65
66 // WooCommerce
67 if ( function_exists( 'WC' ) && WC()->cart ) {
68 $custom_vars['cart_count'] = WC()->cart->get_cart_contents_count();
69 $custom_vars['cart_total'] = (float) WC()->cart->subtotal;
70 }
71
72 // UTM / Query string
73 // phpcs:disable WordPress.Security.NonceVerification.Recommended
74 $custom_vars['utm_source'] = sanitize_text_field( $_GET['utm_source'] ?? '' );
75 $custom_vars['utm_medium'] = sanitize_text_field( $_GET['utm_medium'] ?? '' );
76 $custom_vars['utm_campaign'] = sanitize_text_field( $_GET['utm_campaign'] ?? '' );
77 $custom_vars['utm_content'] = sanitize_text_field( $_GET['utm_content'] ?? '' );
78 $custom_vars['utm_term'] = sanitize_text_field( $_GET['utm_term'] ?? '' );
79 // phpcs:enable
80
81 // Post-relative
82 if ( isset( $post->ID ) ) {
83 $publish_time = get_post_time( 'U', true, $post->ID );
84 $custom_vars['post_age_days'] = (int) floor( ( time() - $publish_time ) / DAY_IN_SECONDS );
85 $custom_vars['post_has_thumbnail'] = has_post_thumbnail( $post->ID ) ? 'true' : 'false';
86 $custom_vars['post_word_count'] = str_word_count( wp_strip_all_tags( $post->post_content ) );
87 }
88
89 return $custom_vars;
90 }
91