first commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace Elementor\Modules\FloatingButtons\AdminMenuItems;
|
||||
|
||||
use Elementor\Core\Admin\Menu\Interfaces\Admin_Menu_Item_With_Page;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Floating_Buttons_Empty_View_Menu_Item extends Floating_Buttons_Menu_Item implements Admin_Menu_Item_With_Page {
|
||||
|
||||
private $render_callback;
|
||||
|
||||
public function __construct( callable $render_callback ) {
|
||||
$this->render_callback = $render_callback;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
( $this->render_callback )();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace Elementor\Modules\FloatingButtons\AdminMenuItems;
|
||||
|
||||
use Elementor\Core\Admin\Menu\Interfaces\Admin_Menu_Item;
|
||||
use Elementor\TemplateLibrary\Source_Local;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Floating_Buttons_Menu_Item implements Admin_Menu_Item {
|
||||
|
||||
public function is_visible() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function get_parent_slug() {
|
||||
return Source_Local::ADMIN_MENU_SLUG;
|
||||
}
|
||||
|
||||
public function get_label() {
|
||||
return esc_html__( 'Floating Elements', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_page_title() {
|
||||
return esc_html__( 'Floating Elements', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_capability() {
|
||||
return 'manage_options';
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\FloatingButtons\Classes\Action;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
use Elementor\Modules\FloatingButtons\Classes\Conditions\Conditions_Cache;
|
||||
use Elementor\Modules\FloatingButtons\Documents\Floating_Buttons;
|
||||
use Elementor\Modules\FloatingButtons\Module;
|
||||
|
||||
class Action_Handler {
|
||||
|
||||
protected string $action;
|
||||
protected array $menu_args;
|
||||
protected Conditions_Cache $conditions_cache;
|
||||
|
||||
public function __construct( string $action, array $menu_args ) {
|
||||
$this->action = $action;
|
||||
$this->menu_args = $menu_args;
|
||||
$this->conditions_cache = new Conditions_Cache();
|
||||
}
|
||||
|
||||
public function process_action() {
|
||||
if ( ! current_user_can( 'edit_posts' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ( $this->action ) {
|
||||
case 'remove_from_entire_site':
|
||||
$this->handle_remove_from_entire_site();
|
||||
break;
|
||||
case 'set_as_entire_site':
|
||||
$this->handle_set_as_entire_site();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private function handle_remove_from_entire_site(): void {
|
||||
$post_id = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT );
|
||||
check_admin_referer( 'remove_from_entire_site_' . $post_id );
|
||||
delete_post_meta( $post_id, '_elementor_conditions' );
|
||||
$this->conditions_cache->remove_from_cache( $post_id );
|
||||
|
||||
wp_redirect( $this->menu_args['menu_slug'] );
|
||||
exit;
|
||||
}
|
||||
|
||||
private function handle_set_as_entire_site(): void {
|
||||
$post_id = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT );
|
||||
check_admin_referer( 'set_as_entire_site_' . $post_id );
|
||||
|
||||
$posts = $this->get_published_floating_elements( $post_id );
|
||||
|
||||
foreach ( $posts as $post_id_to_delete ) {
|
||||
delete_post_meta( $post_id_to_delete, '_elementor_conditions' );
|
||||
$this->conditions_cache->remove_from_cache( $post_id_to_delete );
|
||||
}
|
||||
|
||||
update_post_meta( $post_id, '_elementor_conditions', [ 'include/general' ] );
|
||||
$this->conditions_cache->add_to_cache( $post_id );
|
||||
|
||||
wp_redirect( $this->menu_args['menu_slug'] );
|
||||
exit;
|
||||
}
|
||||
|
||||
private function get_published_floating_elements( int $post_id ): array {
|
||||
return get_posts( [
|
||||
'post_type' => Module::CPT_FLOATING_BUTTONS,
|
||||
'posts_per_page' => -1,
|
||||
'post_status' => 'publish',
|
||||
'fields' => 'ids',
|
||||
'no_found_rows' => true,
|
||||
'update_post_term_cache' => false,
|
||||
'update_post_meta_cache' => false,
|
||||
'meta_query' => Floating_Buttons::get_meta_query_for_floating_buttons(
|
||||
Floating_Buttons::get_floating_element_type( $post_id )
|
||||
),
|
||||
] );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\FloatingButtons\Classes\Conditions;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Conditions_Cache {
|
||||
|
||||
const CONDITIONS_CACHE_META_KEY = 'elementor_pro_theme_builder_conditions';
|
||||
|
||||
const CONDITION_TYPE = 'floating_buttons';
|
||||
|
||||
public function remove_from_cache( int $post_id ): void {
|
||||
$conditions = $this->get_conditions();
|
||||
|
||||
if ( isset( $conditions[ self::CONDITION_TYPE ][ $post_id ] ) ) {
|
||||
unset( $conditions[ self::CONDITION_TYPE ][ $post_id ] );
|
||||
|
||||
if ( empty( $conditions[ self::CONDITION_TYPE ] ) ) {
|
||||
unset( $conditions[ self::CONDITION_TYPE ] );
|
||||
}
|
||||
|
||||
$this->update_conditions( $conditions );
|
||||
}
|
||||
}
|
||||
|
||||
public function add_to_cache( int $post_id, array $condition_rules = [ 'include/general' ] ): void {
|
||||
$conditions = $this->get_conditions();
|
||||
|
||||
if ( ! isset( $conditions[ self::CONDITION_TYPE ] ) ) {
|
||||
$conditions[ self::CONDITION_TYPE ] = [];
|
||||
}
|
||||
|
||||
$conditions[ self::CONDITION_TYPE ][ $post_id ] = $condition_rules;
|
||||
|
||||
$this->update_conditions( $conditions );
|
||||
}
|
||||
|
||||
private function get_conditions(): array {
|
||||
return get_option( self::CONDITIONS_CACHE_META_KEY, [] );
|
||||
}
|
||||
|
||||
private function update_conditions( array $conditions ): void {
|
||||
update_option( self::CONDITIONS_CACHE_META_KEY, $conditions );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\FloatingButtons\Classes\Render;
|
||||
|
||||
/**
|
||||
* Class Contact_Buttons_Core_Render.
|
||||
*
|
||||
* This class handles the rendering of the Contact Buttons widget for the core version.
|
||||
*
|
||||
* @since 3.23.0
|
||||
*/
|
||||
class Contact_Buttons_Core_Render extends Contact_Buttons_Render_Base {
|
||||
|
||||
public function render(): void {
|
||||
$this->build_layout_render_attribute();
|
||||
$this->add_content_wrapper_render_attribute();
|
||||
|
||||
$content_classnames = 'e-contact-buttons__content';
|
||||
$animation_duration = $this->settings['style_chat_box_animation_duration'];
|
||||
|
||||
if ( ! empty( $animation_duration ) ) {
|
||||
$content_classnames .= ' has-animation-duration-' . $animation_duration;
|
||||
}
|
||||
|
||||
$this->widget->add_render_attribute( 'content', [
|
||||
'class' => $content_classnames,
|
||||
] );
|
||||
?>
|
||||
<div <?php echo $this->widget->get_render_attribute_string( 'layout' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
|
||||
<div <?php echo $this->widget->get_render_attribute_string( 'content-wrapper' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
|
||||
<div <?php echo $this->widget->get_render_attribute_string( 'content' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
|
||||
<?php
|
||||
$this->render_top_bar();
|
||||
$this->render_message_bubble();
|
||||
$this->render_send_button();
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
$this->render_chat_button();
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
protected function add_layout_render_attribute( $layout_classnames ) {
|
||||
$this->widget->add_render_attribute( 'layout', [
|
||||
'class' => $layout_classnames,
|
||||
'id' => $this->settings['advanced_custom_css_id'],
|
||||
'data-document-id' => get_the_ID(),
|
||||
'aria-role' => 'dialog',
|
||||
] );
|
||||
}
|
||||
|
||||
protected function add_content_wrapper_render_attribute() {
|
||||
$this->widget->add_render_attribute( 'content-wrapper', [
|
||||
'aria-hidden' => 'true',
|
||||
'aria-label' => __( 'Links window', 'elementor' ),
|
||||
'class' => 'e-contact-buttons__content-wrapper hidden',
|
||||
'id' => 'e-contact-buttons__content-wrapper',
|
||||
] );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,487 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\FloatingButtons\Classes\Render;
|
||||
|
||||
use Elementor\Core\Base\Providers\Social_Network_Provider;
|
||||
use Elementor\Icons_Manager;
|
||||
use Elementor\Modules\FloatingButtons\Base\Widget_Contact_Button_Base;
|
||||
use Elementor\Utils;
|
||||
|
||||
/**
|
||||
* Class Contact_Buttons_Render_Base.
|
||||
*
|
||||
* This is the base class that will hold shared functionality that will be needed by all the various widget versions.
|
||||
*
|
||||
* @since 3.23.0
|
||||
*/
|
||||
abstract class Contact_Buttons_Render_Base {
|
||||
|
||||
protected Widget_Contact_Button_Base $widget;
|
||||
|
||||
protected array $settings;
|
||||
|
||||
|
||||
abstract public function render(): void;
|
||||
|
||||
public function __construct( Widget_Contact_Button_Base $widget ) {
|
||||
$this->widget = $widget;
|
||||
$this->settings = $widget->get_settings_for_display();
|
||||
}
|
||||
|
||||
protected function render_chat_button_icon(): void {
|
||||
$platform = $this->settings['chat_button_platform'] ?? '';
|
||||
|
||||
$mapping = Social_Network_Provider::get_icon_mapping( $platform );
|
||||
$icon_lib = explode( ' ', $mapping )[0];
|
||||
$library = 'fab' === $icon_lib ? 'fa-brands' : 'fa-solid';
|
||||
Icons_Manager::render_icon(
|
||||
[
|
||||
'library' => $library,
|
||||
'value' => $mapping,
|
||||
],
|
||||
[ 'aria-hidden' => 'true' ]
|
||||
);
|
||||
}
|
||||
|
||||
protected function render_chat_button(): void {
|
||||
$platform = $this->settings['chat_button_platform'] ?? '';
|
||||
$display_dot = $this->settings['chat_button_show_dot'] ?? '';
|
||||
$button_size = $this->settings['style_chat_button_size'];
|
||||
$hover_animation = $this->settings['style_button_color_hover_animation'];
|
||||
$entrance_animation = $this->settings['style_chat_button_animation'];
|
||||
$entrance_animation_duration = $this->settings['style_chat_button_animation_duration'];
|
||||
$entrance_animation_delay = $this->settings['style_chat_button_animation_delay'];
|
||||
$accessible_name = $this->settings['chat_aria_label'];
|
||||
|
||||
$button_classnames = 'e-contact-buttons__chat-button e-contact-buttons__chat-button-shadow';
|
||||
|
||||
if ( ! empty( $button_size ) ) {
|
||||
$button_classnames .= ' has-size-' . $button_size;
|
||||
}
|
||||
|
||||
if ( ! empty( $hover_animation ) ) {
|
||||
$button_classnames .= ' elementor-animation-' . $hover_animation;
|
||||
}
|
||||
|
||||
if ( ! empty( $entrance_animation ) && 'none' != $entrance_animation ) {
|
||||
$button_classnames .= ' has-entrance-animation';
|
||||
}
|
||||
|
||||
if ( ! empty( $entrance_animation_delay ) ) {
|
||||
$button_classnames .= ' has-entrance-animation-delay';
|
||||
}
|
||||
|
||||
if ( ! empty( $entrance_animation_duration ) ) {
|
||||
$button_classnames .= ' has-entrance-animation-duration-' . $entrance_animation_duration;
|
||||
}
|
||||
|
||||
if ( 'yes' === $display_dot ) {
|
||||
$button_classnames .= ' has-dot';
|
||||
}
|
||||
|
||||
$this->widget->add_render_attribute( 'button', [
|
||||
'class' => $button_classnames,
|
||||
'aria-controls' => 'e-contact-buttons__content-wrapper',
|
||||
'aria-label' => sprintf(
|
||||
/* translators: %s: Accessible name. */
|
||||
esc_html__( 'Toggle %s', 'elementor' ),
|
||||
$accessible_name,
|
||||
),
|
||||
'type' => 'button',
|
||||
] );
|
||||
|
||||
?>
|
||||
<div class="e-contact-buttons__chat-button-container">
|
||||
<button <?php echo $this->widget->get_render_attribute_string( 'button' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
|
||||
<?php
|
||||
$this->render_chat_button_icon();
|
||||
?>
|
||||
</button>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
protected function render_close_button(): void {
|
||||
$accessible_name = $this->settings['chat_aria_label'];
|
||||
|
||||
$this->widget->add_render_attribute( 'close-button', [
|
||||
'class' => 'e-contact-buttons__close-button',
|
||||
'aria-controls' => 'e-contact-buttons__content-wrapper',
|
||||
'aria-label' => sprintf(
|
||||
/* translators: %s: Accessible name. */
|
||||
esc_html__( 'Close %s', 'elementor' ),
|
||||
$accessible_name,
|
||||
),
|
||||
'type' => 'button',
|
||||
] );
|
||||
|
||||
?>
|
||||
<button <?php echo $this->widget->get_render_attribute_string( 'close-button' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
|
||||
<i class="eicon-close"></i>
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
|
||||
protected function render_top_bar(): void {
|
||||
$profile_image_value = $this->settings['top_bar_image'] ?? [];
|
||||
$has_profile_image = ! empty( $profile_image_value ) && ( ! empty( $profile_image_value['url'] || ! empty( $profile_image_value['id'] ) ) );
|
||||
$profile_image_size = $this->settings['style_top_bar_image_size'];
|
||||
$display_profile_dot = $this->settings['top_bar_show_dot'];
|
||||
|
||||
$profile_image_classnames = 'e-contact-buttons__profile-image';
|
||||
|
||||
if ( ! empty( $profile_image_size ) ) {
|
||||
$profile_image_classnames .= ' has-size-' . $profile_image_size;
|
||||
}
|
||||
|
||||
if ( 'yes' === $display_profile_dot ) {
|
||||
$profile_image_classnames .= ' has-dot';
|
||||
}
|
||||
|
||||
$top_bar_title = $this->settings['top_bar_title'] ?? '';
|
||||
$top_bar_subtitle = $this->settings['top_bar_subtitle'] ?? '';
|
||||
|
||||
$has_top_bar_title = ! empty( $top_bar_title );
|
||||
$has_top_bar_subtitle = ! empty( $top_bar_subtitle );
|
||||
|
||||
$this->widget->add_render_attribute( 'profile-image', [
|
||||
'class' => $profile_image_classnames,
|
||||
] );
|
||||
?>
|
||||
<div class="e-contact-buttons__top-bar">
|
||||
<?php $this->render_close_button(); ?>
|
||||
<div <?php echo $this->widget->get_render_attribute_string( 'profile-image' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
|
||||
<?php if ( ! empty( $profile_image_value['id'] ) ) {
|
||||
echo wp_get_attachment_image( $profile_image_value['id'], 'medium', false, [
|
||||
'class' => 'e-contact-buttons__profile-image-el',
|
||||
] );
|
||||
} else {
|
||||
$this->widget->add_render_attribute( 'profile-image-src', [
|
||||
'alt' => '',
|
||||
'class' => 'e-contact-buttons__profile-image-el',
|
||||
'src' => esc_url( $profile_image_value['url'] ),
|
||||
] );
|
||||
?>
|
||||
<img <?php echo $this->widget->get_render_attribute_string( 'profile-image-src' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> />
|
||||
<?php }; ?>
|
||||
</div>
|
||||
|
||||
<div class="e-contact-buttons__top-bar-details">
|
||||
<?php if ( $has_top_bar_title ) { ?>
|
||||
<p class="e-contact-buttons__top-bar-title"><?php echo esc_html( $top_bar_title ); ?></p>
|
||||
<?php } ?>
|
||||
<?php if ( $has_top_bar_subtitle ) { ?>
|
||||
<p class="e-contact-buttons__top-bar-subtitle"><?php echo esc_html( $top_bar_subtitle ); ?></p>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
protected function render_message_bubble_typing_animation(): void {
|
||||
$has_typing_animation = 'yes' === $this->settings['chat_button_show_animation'];
|
||||
?>
|
||||
<?php if ( $has_typing_animation ) { ?>
|
||||
<div class="e-contact-buttons__dots-container">
|
||||
<span class="e-contact-buttons__dot e-contact-buttons__dot-1"></span>
|
||||
<span class="e-contact-buttons__dot e-contact-buttons__dot-2"></span>
|
||||
<span class="e-contact-buttons__dot e-contact-buttons__dot-3"></span>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php
|
||||
}
|
||||
|
||||
protected function render_message_bubble_container(): void {
|
||||
$message_bubble_name = $this->settings['message_bubble_name'] ?? '';
|
||||
$message_bubble_body = $this->settings['message_bubble_body'] ?? '';
|
||||
$has_message_bubble_name = ! empty( $message_bubble_name );
|
||||
$has_message_bubble_body = ! empty( $message_bubble_body );
|
||||
$time_format = $this->settings['chat_button_time_format'];
|
||||
?>
|
||||
<div class="e-contact-buttons__bubble-container">
|
||||
<div class="e-contact-buttons__bubble">
|
||||
<?php if ( $has_message_bubble_name ) { ?>
|
||||
<p class="e-contact-buttons__message-bubble-name"><?php echo esc_html( $message_bubble_name ); ?></p>
|
||||
<?php } ?>
|
||||
<?php if ( $has_message_bubble_body ) { ?>
|
||||
<p class="e-contact-buttons__message-bubble-body"><?php echo esc_html( $message_bubble_body ); ?></p>
|
||||
<?php } ?>
|
||||
<p class="e-contact-buttons__message-bubble-time" data-time-format="<?php echo esc_attr( $time_format ); ?>"></p>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
protected function render_message_bubble_powered_by(): void {
|
||||
if ( Utils::has_pro() ) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<div class="e-contact-buttons__powered-container">
|
||||
<p class="e-contact-buttons__powered-text">
|
||||
<?php echo esc_attr__( 'Powered by Elementor', 'elementor' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
protected function render_message_bubble(): void {
|
||||
$message_bubble_classnames = 'e-contact-buttons__message-bubble';
|
||||
$show_animation = $this->settings['chat_button_show_animation'] ?? false;
|
||||
$has_typing_animation = $show_animation && 'yes' === $show_animation;
|
||||
|
||||
if ( $has_typing_animation ) {
|
||||
$message_bubble_classnames .= ' has-typing-animation';
|
||||
}
|
||||
|
||||
$this->widget->add_render_attribute( 'message-bubble', [
|
||||
'class' => $message_bubble_classnames,
|
||||
] );
|
||||
?>
|
||||
<div <?php echo $this->widget->get_render_attribute_string( 'message-bubble' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
|
||||
<?php
|
||||
$this->render_message_bubble_typing_animation();
|
||||
$this->render_message_bubble_container();
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
protected function render_contact_text(): void {
|
||||
$contact_cta_text = $this->settings['contact_cta_text'] ?? '';
|
||||
?>
|
||||
<?php if ( ! empty( $contact_cta_text ) ) { ?>
|
||||
<p class="e-contact-buttons__contact-text"><?php echo esc_html( $contact_cta_text ); ?></p>
|
||||
<?php } ?>
|
||||
<?php
|
||||
}
|
||||
|
||||
protected function render_contact_links(): void {
|
||||
$contact_icons = $this->settings['contact_repeater'] ?? [];
|
||||
$icons_size = $this->settings['style_contact_button_size'] ?? 'small';
|
||||
$hover_animation = $this->settings['style_contact_button_hover_animation'];
|
||||
?>
|
||||
<div class="e-contact-buttons__contact-links">
|
||||
<?php
|
||||
foreach ( $contact_icons as $key => $icon ) {
|
||||
$icon_text_mapping = Social_Network_Provider::get_text_mapping( $icon['contact_icon_platform'] );
|
||||
$aria_label = sprintf(
|
||||
/* translators: %s: Platform name. */
|
||||
esc_html__( 'Open %s', 'elementor' ),
|
||||
$icon_text_mapping,
|
||||
);
|
||||
|
||||
$link = [
|
||||
'platform' => $icon['contact_icon_platform'],
|
||||
'number' => $icon['contact_icon_number'] ?? '',
|
||||
'username' => $icon['contact_icon_username'] ?? '',
|
||||
'email_data' => [
|
||||
'contact_icon_mail' => $icon['contact_icon_mail'] ?? '',
|
||||
'contact_icon_mail_subject' => $icon['contact_icon_mail_subject'] ?? '',
|
||||
'contact_icon_mail_body' => $icon['contact_icon_mail_body'] ?? '',
|
||||
],
|
||||
'viber_action' => $icon['contact_icon_viber_action'] ?? '',
|
||||
];
|
||||
|
||||
$formatted_link = $this->get_formatted_link( $link, 'contact_icon' );
|
||||
|
||||
$icon_classnames = 'e-contact-buttons__contact-icon-link has-size-' . $icons_size;
|
||||
|
||||
if ( ! empty( $hover_animation ) ) {
|
||||
$icon_classnames .= ' elementor-animation-' . $hover_animation;
|
||||
}
|
||||
|
||||
$this->widget->add_render_attribute( 'icon-link-' . $key, [
|
||||
'aria-label' => $aria_label,
|
||||
'class' => $icon_classnames,
|
||||
'href' => $formatted_link,
|
||||
'rel' => 'noopener noreferrer',
|
||||
'target' => '_blank',
|
||||
] );
|
||||
|
||||
?>
|
||||
|
||||
<a <?php echo $this->widget->get_render_attribute_string( 'icon-link-' . $key ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
|
||||
<?php
|
||||
$mapping = Social_Network_Provider::get_icon_mapping( $icon['contact_icon_platform'] );
|
||||
$icon_lib = explode( ' ', $mapping )[0];
|
||||
$library = 'fab' === $icon_lib ? 'fa-brands' : 'fa-solid';
|
||||
Icons_Manager::render_icon(
|
||||
[
|
||||
'library' => $library,
|
||||
'value' => $mapping,
|
||||
],
|
||||
[ 'aria-hidden' => 'true' ]
|
||||
);
|
||||
?>
|
||||
</a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
protected function render_contact_section(): void {
|
||||
?>
|
||||
<div class="e-contact-buttons__contact">
|
||||
<?php
|
||||
$this->render_contact_text();
|
||||
$this->render_contact_links();
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
protected function render_send_button(): void {
|
||||
$platform = $this->settings['chat_button_platform'] ?? '';
|
||||
$send_button_text = $this->settings['send_button_text'];
|
||||
$hover_animation = $this->settings['style_send_hover_animation'];
|
||||
$cta_classnames = 'e-contact-buttons__send-cta';
|
||||
|
||||
$link = [
|
||||
'platform' => $platform,
|
||||
'number' => $this->settings['chat_button_number'] ?? '',
|
||||
'username' => $this->settings['chat_button_username'] ?? '',
|
||||
'email_data' => [
|
||||
'chat_button_mail' => $this->settings['chat_button_mail'],
|
||||
'chat_button_mail_subject' => $this->settings['chat_button_mail_subject'] ?? '',
|
||||
'chat_button_mail_body' => $this->settings['chat_button_mail_body'] ?? '',
|
||||
],
|
||||
'viber_action' => $this->settings['chat_button_viber_action'],
|
||||
];
|
||||
|
||||
$formatted_link = $this->get_formatted_link( $link, 'chat_button' );
|
||||
|
||||
if ( ! empty( $hover_animation ) ) {
|
||||
$cta_classnames .= ' elementor-animation-' . $hover_animation;
|
||||
}
|
||||
|
||||
$this->widget->add_render_attribute( 'formatted-cta', [
|
||||
'class' => $cta_classnames,
|
||||
'href' => $formatted_link,
|
||||
'rel' => 'noopener noreferrer',
|
||||
'target' => '_blank',
|
||||
] );
|
||||
|
||||
?>
|
||||
<div class="e-contact-buttons__send-button">
|
||||
<?php $this->render_message_bubble_powered_by(); ?>
|
||||
<div class="e-contact-buttons__send-button-container">
|
||||
<?php if ( $send_button_text ) { ?>
|
||||
<a <?php echo $this->widget->get_render_attribute_string( 'formatted-cta' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
|
||||
<?php
|
||||
$mapping = Social_Network_Provider::get_icon_mapping( $platform );
|
||||
$icon_lib = explode( ' ', $mapping )[0];
|
||||
$library = 'fab' === $icon_lib ? 'fa-brands' : 'fa-solid';
|
||||
Icons_Manager::render_icon(
|
||||
[
|
||||
'library' => $library,
|
||||
'value' => $mapping,
|
||||
],
|
||||
[ 'aria-hidden' => 'true' ]
|
||||
);
|
||||
?>
|
||||
<?php echo esc_html( $send_button_text ); ?>
|
||||
</a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
protected function get_formatted_link( array $link, string $prefix ): string {
|
||||
|
||||
// Ensure we clear the default link value if the matching type value is empty
|
||||
switch ( $link['platform'] ) {
|
||||
case Social_Network_Provider::EMAIL:
|
||||
$formatted_link = Social_Network_Provider::build_email_link( $link['email_data'], $prefix );
|
||||
break;
|
||||
case Social_Network_Provider::SMS:
|
||||
$formatted_link = ! empty( $link['number'] ) ? 'sms:' . $link['number'] : '';
|
||||
break;
|
||||
case Social_Network_Provider::MESSENGER:
|
||||
$formatted_link = ! empty( $link['username'] ) ?
|
||||
Social_Network_Provider::build_messenger_link( $link['username'] ) :
|
||||
'';
|
||||
break;
|
||||
case Social_Network_Provider::WHATSAPP:
|
||||
$formatted_link = ! empty( $link['number'] ) ? 'https://wa.me/' . $link['number'] : '';
|
||||
break;
|
||||
case Social_Network_Provider::VIBER:
|
||||
$formatted_link = Social_Network_Provider::build_viber_link( $link['viber_action'], $link['number'] );
|
||||
break;
|
||||
case Social_Network_Provider::SKYPE:
|
||||
$formatted_link = ! empty( $link['username'] ) ? 'skype:' . $link['username'] . '?chat' : '';
|
||||
break;
|
||||
case Social_Network_Provider::TELEPHONE:
|
||||
$formatted_link = ! empty( $link['number'] ) ? 'tel:' . $link['number'] : '';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return esc_html( $formatted_link );
|
||||
}
|
||||
|
||||
protected function is_url_link( string $platform ): bool {
|
||||
return Social_Network_Provider::URL === $platform || Social_Network_Provider::WAZE === $platform;
|
||||
}
|
||||
|
||||
protected function render_link_attributes( array $link, string $key ) {
|
||||
switch ( $link['platform'] ) {
|
||||
case Social_Network_Provider::WAZE:
|
||||
if ( empty( $link['location']['url'] ) ) {
|
||||
$link['location']['url'] = '#';
|
||||
}
|
||||
|
||||
$this->widget->add_link_attributes( $key, $link['location'] );
|
||||
break;
|
||||
case Social_Network_Provider::URL:
|
||||
if ( empty( $link['url']['url'] ) ) {
|
||||
$link['url']['url'] = '#';
|
||||
}
|
||||
|
||||
$this->widget->add_link_attributes( $key, $link['url'] );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected function build_layout_render_attribute(): void {
|
||||
$layout_classnames = 'e-contact-buttons e-' . $this->widget->get_name();
|
||||
$platform = $this->settings['chat_button_platform'] ?? '';
|
||||
$border_radius = $this->settings['style_chat_box_corners'];
|
||||
$alignment_position_horizontal = $this->settings['advanced_horizontal_position'];
|
||||
$alignment_position_vertical = $this->settings['advanced_vertical_position'];
|
||||
$has_animations = ! empty( $this->settings['style_chat_box_exit_animation'] ) || ! empty( $this->settings['style_chat_box_entrance_animation'] );
|
||||
$custom_classes = $this->settings['advanced_custom_css_classes'] ?? '';
|
||||
|
||||
$icon_name_mapping = Social_Network_Provider::get_name_mapping( $platform );
|
||||
|
||||
if ( ! empty( $platform ) ) {
|
||||
$layout_classnames .= ' has-platform-' . $icon_name_mapping;
|
||||
}
|
||||
|
||||
if ( ! empty( $border_radius ) ) {
|
||||
$layout_classnames .= ' has-corners-' . $border_radius;
|
||||
}
|
||||
|
||||
if ( ! empty( $alignment_position_horizontal ) ) {
|
||||
$layout_classnames .= ' has-h-alignment-' . $alignment_position_horizontal;
|
||||
}
|
||||
|
||||
if ( ! empty( $alignment_position_vertical ) ) {
|
||||
$layout_classnames .= ' has-v-alignment-' . $alignment_position_vertical;
|
||||
}
|
||||
|
||||
if ( $has_animations ) {
|
||||
$layout_classnames .= ' has-animations';
|
||||
}
|
||||
|
||||
if ( $custom_classes ) {
|
||||
$layout_classnames .= ' ' . $custom_classes;
|
||||
}
|
||||
|
||||
$this->add_layout_render_attribute( $layout_classnames );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\FloatingButtons\Classes\Render;
|
||||
|
||||
use Elementor\Icons_Manager;
|
||||
|
||||
/**
|
||||
* Class Floating_Bars_Core_Render.
|
||||
*
|
||||
* This class handles the rendering of the Floating Bars widget for the core version.
|
||||
*
|
||||
* @since 3.23.0
|
||||
*/
|
||||
class Floating_Bars_Core_Render extends Floating_Bars_Render_Base {
|
||||
|
||||
protected function render_announcement_icon(): void {
|
||||
$icon = $this->settings['announcement_icon'] ?? '';
|
||||
|
||||
if ( '' !== $icon['value'] ) : ?>
|
||||
<span class="e-floating-bars__announcement-icon"><?php Icons_Manager::render_icon( $icon, [ 'aria-hidden' => 'true' ] ); ?></span>
|
||||
<?php endif;
|
||||
}
|
||||
|
||||
protected function render_announcement_text(): void {
|
||||
$text = $this->settings['announcement_text'] ?? '';
|
||||
|
||||
$this->widget->add_render_attribute( 'announcement_text', [
|
||||
'class' => 'e-floating-bars__announcement-text',
|
||||
] );
|
||||
|
||||
if ( '' !== $text ) : ?>
|
||||
<p <?php $this->widget->print_render_attribute_string( 'announcement_text' ); ?>>
|
||||
<?php echo esc_html( $text ); ?>
|
||||
</p>
|
||||
<?php endif;
|
||||
}
|
||||
|
||||
protected function render_cta_icon(): void {
|
||||
$icon = $this->settings['cta_icon'] ?? '';
|
||||
$icon_classnames = 'e-floating-bars__cta-icon';
|
||||
|
||||
$this->widget->add_render_attribute( 'cta-icon', [
|
||||
'class' => $icon_classnames,
|
||||
] );
|
||||
|
||||
if ( '' !== $icon['value'] ) : ?>
|
||||
<span <?php echo $this->widget->get_render_attribute_string( 'cta-icon' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>><?php Icons_Manager::render_icon( $icon, [ 'aria-hidden' => 'true' ] ); ?></span>
|
||||
<?php endif;
|
||||
}
|
||||
|
||||
protected function render_cta_button(): void {
|
||||
$link = $this->settings['cta_link'] ?? '';
|
||||
$text = $this->settings['cta_text'] ?? '';
|
||||
|
||||
$hover_animation = $this->settings['style_cta_button_hover_animation'];
|
||||
$corners = $this->settings['style_cta_button_corners'];
|
||||
$link_type = $this->settings['style_cta_type'];
|
||||
$entrance_animation = $this->settings['style_cta_button_animation'];
|
||||
$has_border = $this->settings['style_cta_button_show_border'];
|
||||
|
||||
$cta_classnames = 'e-floating-bars__cta-button';
|
||||
|
||||
if ( ! empty( $hover_animation ) ) {
|
||||
$cta_classnames .= ' elementor-animation-' . $hover_animation;
|
||||
}
|
||||
|
||||
if ( ! empty( $corners ) ) {
|
||||
$cta_classnames .= ' has-corners-' . $corners;
|
||||
}
|
||||
|
||||
if ( ! empty( $link_type ) ) {
|
||||
$cta_classnames .= ' is-type-' . $link_type;
|
||||
}
|
||||
|
||||
if ( ! empty( $entrance_animation ) && 'none' != $entrance_animation ) {
|
||||
$cta_classnames .= ' has-entrance-animation';
|
||||
}
|
||||
|
||||
if ( 'yes' == $has_border ) {
|
||||
$cta_classnames .= ' has-border';
|
||||
}
|
||||
|
||||
$this->widget->add_render_attribute( 'cta-button', [
|
||||
'class' => $cta_classnames,
|
||||
] );
|
||||
|
||||
$this->widget->add_render_attribute( 'cta_text', [
|
||||
'class' => 'e-floating-bars__cta-text',
|
||||
] );
|
||||
|
||||
if ( ! empty( $text ) ) {
|
||||
$this->widget->add_link_attributes( 'cta-button', $link );
|
||||
?>
|
||||
<div class="e-floating-bars__cta-button-container">
|
||||
<a <?php echo $this->widget->get_render_attribute_string( 'cta-button' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
|
||||
<?php $this->render_cta_icon(); ?>
|
||||
<span <?php $this->widget->print_render_attribute_string( 'cta_text' ); ?>><?php echo esc_html( $text ); ?></span>
|
||||
</a>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
protected function render_close_button(): void {
|
||||
$accessible_name = $this->settings['accessible_name'];
|
||||
$close_button_classnames = 'e-floating-bars__close-button';
|
||||
|
||||
$this->widget->add_render_attribute( 'close-button', [
|
||||
'class' => $close_button_classnames,
|
||||
'aria-label' => sprintf(
|
||||
/* translators: %s: Accessible name. */
|
||||
esc_html__( 'Close %s', 'elementor' ),
|
||||
$accessible_name,
|
||||
),
|
||||
'type' => 'button',
|
||||
'aria-controls' => 'e-floating-bars',
|
||||
] );
|
||||
|
||||
?>
|
||||
<button <?php echo $this->widget->get_render_attribute_string( 'close-button' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
|
||||
<i class="eicon-close"></i>
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function render(): void {
|
||||
$this->build_layout_render_attribute();
|
||||
$has_close_button = $this->settings['floating_bar_close_switch'];
|
||||
|
||||
?>
|
||||
<div <?php echo $this->widget->get_render_attribute_string( 'layout' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
|
||||
<?php
|
||||
$this->render_announcement_text();
|
||||
|
||||
$this->render_announcement_icon();
|
||||
|
||||
$this->render_cta_button();
|
||||
|
||||
if ( 'yes' === $has_close_button ) {
|
||||
$this->render_close_button();
|
||||
}
|
||||
?>
|
||||
<div class="e-floating-bars__overlay"></div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\FloatingButtons\Classes\Render;
|
||||
|
||||
use Elementor\Modules\FloatingButtons\Base\Widget_Floating_Bars_Base;
|
||||
|
||||
/**
|
||||
* Class Floating_Bars_Render_Base.
|
||||
*
|
||||
* This is the base class that will hold shared functionality that will be needed by all the various widget versions.
|
||||
*
|
||||
* @since 3.23.0
|
||||
*/
|
||||
abstract class Floating_Bars_Render_Base {
|
||||
|
||||
protected Widget_Floating_Bars_Base $widget;
|
||||
|
||||
protected array $settings;
|
||||
|
||||
abstract public function render(): void;
|
||||
|
||||
public function __construct( Widget_Floating_Bars_Base $widget ) {
|
||||
$this->widget = $widget;
|
||||
$this->settings = $widget->get_settings_for_display();
|
||||
}
|
||||
|
||||
protected function add_layout_render_attribute( $layout_classnames ) {
|
||||
$this->widget->add_render_attribute( 'layout', [
|
||||
'class' => $layout_classnames,
|
||||
'id' => $this->settings['advanced_custom_css_id'],
|
||||
'data-document-id' => get_the_ID(),
|
||||
'role' => 'alertdialog',
|
||||
] );
|
||||
}
|
||||
|
||||
public static function get_layout_classnames( Widget_Floating_Bars_Base $widget, array $settings ): string {
|
||||
$layout_classnames = 'e-floating-bars e-' . $widget->get_name();
|
||||
$vertical_position = $settings['advanced_vertical_position'];
|
||||
$is_sticky = $settings['advanced_toggle_sticky'];
|
||||
$has_close_button = $settings['floating_bar_close_switch'];
|
||||
|
||||
$layout_classnames .= ' has-vertical-position-' . $vertical_position;
|
||||
|
||||
if ( 'yes' === $has_close_button ) {
|
||||
$layout_classnames .= ' has-close-button';
|
||||
}
|
||||
|
||||
if ( 'yes' === $is_sticky ) {
|
||||
$layout_classnames .= ' is-sticky';
|
||||
}
|
||||
|
||||
return $layout_classnames;
|
||||
}
|
||||
|
||||
protected function build_layout_render_attribute(): void {
|
||||
$layout_classnames = static::get_layout_classnames( $this->widget, $this->settings );
|
||||
|
||||
$this->add_layout_render_attribute( $layout_classnames );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\FloatingButtons\Control;
|
||||
|
||||
use Elementor\Control_Hover_Animation;
|
||||
|
||||
class Hover_Animation_Floating_Buttons extends Control_Hover_Animation {
|
||||
|
||||
const TYPE = 'hover_animation_contact_buttons';
|
||||
|
||||
public function get_type() {
|
||||
return static::TYPE;
|
||||
}
|
||||
|
||||
public static function get_animations() {
|
||||
return [
|
||||
'grow' => 'Grow',
|
||||
'pulse' => 'Pulse',
|
||||
'push' => 'Push',
|
||||
'float' => 'Float',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\FloatingButtons\Documents;
|
||||
|
||||
use Elementor\Core\Base\Document;
|
||||
use Elementor\Core\DocumentTypes\PageBase;
|
||||
use Elementor\Modules\FloatingButtons\Module;
|
||||
use Elementor\Modules\Library\Traits\Library as Library_Trait;
|
||||
use Elementor\Modules\FloatingButtons\Module as Floating_Buttons_Module;
|
||||
use Elementor\Modules\PageTemplates\Module as Page_Templates_Module;
|
||||
use Elementor\Plugin;
|
||||
use Elementor\TemplateLibrary\Source_Local;
|
||||
use Elementor\Utils as ElementorUtils;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Floating_Buttons extends PageBase {
|
||||
use Library_Trait;
|
||||
|
||||
public static function get_properties() {
|
||||
$properties = parent::get_properties();
|
||||
|
||||
$properties['support_kit'] = true;
|
||||
$properties['support_site_editor'] = false;
|
||||
$properties['cpt'] = [ Floating_Buttons_Module::CPT_FLOATING_BUTTONS ];
|
||||
$properties['show_navigator'] = false;
|
||||
$properties['allow_adding_widgets'] = false;
|
||||
$properties['support_page_layout'] = false;
|
||||
$properties['library_close_title'] = esc_html__( 'Go To Dashboard', 'elementor' );
|
||||
$properties['publish_button_title'] = esc_html__( 'After publishing this widget, you will be able to set it as visible on the entire site in the Admin Table.', 'elementor' );
|
||||
$properties['allow_closing_remote_library'] = false;
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
||||
public static function get_floating_element_type( $post_id ) {
|
||||
$meta = get_post_meta( $post_id, Floating_Buttons_Module::FLOATING_ELEMENTS_TYPE_META_KEY, true );
|
||||
return $meta ? $meta : 'floating-buttons';
|
||||
}
|
||||
|
||||
public static function is_editing_existing_floating_buttons_page() {
|
||||
$action = ElementorUtils::get_super_global_value( $_GET, 'action' );
|
||||
$post_id = ElementorUtils::get_super_global_value( $_GET, 'post' );
|
||||
|
||||
return 'elementor' === $action && static::is_floating_buttons_type_meta_key( $post_id );
|
||||
}
|
||||
|
||||
public static function is_creating_floating_buttons_page() {
|
||||
$action = ElementorUtils::get_super_global_value( $_POST, 'action' ); //phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$post_id = ElementorUtils::get_super_global_value( $_POST, 'editor_post_id' ); //phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
|
||||
return 'elementor_ajax' === $action && static::is_floating_buttons_type_meta_key( $post_id );
|
||||
}
|
||||
|
||||
public static function is_floating_buttons_type_meta_key( $post_id ) {
|
||||
return Module::FLOATING_BUTTONS_DOCUMENT_TYPE === get_post_meta( $post_id, Document::TYPE_META_KEY, true );
|
||||
}
|
||||
|
||||
public function print_content() {
|
||||
$plugin = \Elementor\Plugin::$instance;
|
||||
|
||||
if ( $plugin->preview->is_preview_mode( $this->get_main_id() ) ) {
|
||||
// PHPCS - the method builder_wrapper is safe.
|
||||
echo $plugin->preview->builder_wrapper( '' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
} else {
|
||||
// PHPCS - the method get_content is safe.
|
||||
echo $this->get_content(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
}
|
||||
|
||||
public function get_location() {
|
||||
return self::get_property( 'location' );
|
||||
}
|
||||
|
||||
public static function get_type() {
|
||||
return Floating_Buttons_Module::FLOATING_BUTTONS_DOCUMENT_TYPE;
|
||||
}
|
||||
|
||||
public static function register_post_fields_control( $document ) {}
|
||||
|
||||
public static function register_hide_title_control( $document ) {}
|
||||
|
||||
public function get_name() {
|
||||
return Floating_Buttons_Module::FLOATING_BUTTONS_DOCUMENT_TYPE;
|
||||
}
|
||||
|
||||
public function filter_admin_row_actions( $actions ) {
|
||||
unset( $actions['edit'] );
|
||||
unset( $actions['inline hide-if-no-js'] );
|
||||
$built_with_elementor = parent::filter_admin_row_actions( [] );
|
||||
|
||||
if ( isset( $actions['trash'] ) ) {
|
||||
$delete = $actions['trash'];
|
||||
unset( $actions['trash'] );
|
||||
$actions['trash'] = $delete;
|
||||
}
|
||||
|
||||
if ( 'publish' === $this->get_post()->post_status ) {
|
||||
$actions = $this->set_as_entire_site( $actions );
|
||||
}
|
||||
|
||||
return $built_with_elementor + $actions;
|
||||
}
|
||||
|
||||
public static function get_meta_query_for_floating_buttons( string $floating_element_type ): array {
|
||||
$meta_query = [
|
||||
'relation' => 'AND',
|
||||
[
|
||||
'key' => '_elementor_conditions',
|
||||
'compare' => 'EXISTS',
|
||||
],
|
||||
];
|
||||
|
||||
if ( 'floating-buttons' === $floating_element_type ) {
|
||||
$meta_query[] = [
|
||||
'relation' => 'OR',
|
||||
[
|
||||
'key' => Module::FLOATING_ELEMENTS_TYPE_META_KEY,
|
||||
'compare' => 'NOT EXISTS',
|
||||
],
|
||||
[
|
||||
'key' => Module::FLOATING_ELEMENTS_TYPE_META_KEY,
|
||||
'value' => 'floating-buttons',
|
||||
],
|
||||
];
|
||||
} else {
|
||||
$meta_query[] = [
|
||||
'key' => Module::FLOATING_ELEMENTS_TYPE_META_KEY,
|
||||
'value' => $floating_element_type,
|
||||
];
|
||||
}
|
||||
|
||||
return $meta_query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to find the post id of the floating element that is set as entire site.
|
||||
* If found, returns the post id, otherwise returns 0.
|
||||
*
|
||||
* @param string $floating_element_type
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function get_set_as_entire_site_post_id( string $floating_element_type ): int {
|
||||
static $types = [];
|
||||
|
||||
if ( isset( $types[ $floating_element_type ] ) ) {
|
||||
return $types[ $floating_element_type ];
|
||||
}
|
||||
|
||||
$query = new \WP_Query( [
|
||||
'post_type' => Floating_Buttons_Module::CPT_FLOATING_BUTTONS,
|
||||
'posts_per_page' => -1,
|
||||
'post_status' => 'publish',
|
||||
'fields' => 'ids',
|
||||
'no_found_rows' => true,
|
||||
'update_post_term_cache' => false,
|
||||
'meta_query' => static::get_meta_query_for_floating_buttons( $floating_element_type ),
|
||||
] );
|
||||
|
||||
foreach ( $query->get_posts() as $post_id ) {
|
||||
$conditions = get_post_meta( $post_id, '_elementor_conditions', true );
|
||||
|
||||
if ( ! $conditions ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( in_array( 'include/general', $conditions ) ) {
|
||||
$types[ $floating_element_type ] = $post_id;
|
||||
return $post_id;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function set_as_entire_site( $actions ) {
|
||||
$floating_element_type = static::get_floating_element_type( $this->get_main_id() );
|
||||
$current_set_as_entire_site_post_id = static::get_set_as_entire_site_post_id( $floating_element_type );
|
||||
|
||||
if ( $current_set_as_entire_site_post_id === $this->get_main_id() ) {
|
||||
$actions['set_as_entire_site'] = sprintf(
|
||||
'<a style="color:red;" href="?post=%s&action=remove_from_entire_site&_wpnonce=%s">%s</a>',
|
||||
$this->get_post()->ID,
|
||||
wp_create_nonce( 'remove_from_entire_site_' . $this->get_post()->ID ),
|
||||
esc_html__( 'Remove From Entire Site', 'elementor' )
|
||||
);
|
||||
} else {
|
||||
$actions['set_as_entire_site'] = sprintf(
|
||||
'<a href="?post=%s&action=set_as_entire_site&_wpnonce=%s">%s</a>',
|
||||
$this->get_post()->ID,
|
||||
wp_create_nonce( 'set_as_entire_site_' . $this->get_post()->ID ),
|
||||
esc_html__( 'Set as Entire Site', 'elementor' )
|
||||
);
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
public static function get_title() {
|
||||
return esc_html__( 'Floating Element', 'elementor' );
|
||||
}
|
||||
|
||||
public static function get_plural_title() {
|
||||
return esc_html__( 'Floating Elements', 'elementor' );
|
||||
}
|
||||
|
||||
public static function get_create_url() {
|
||||
return parent::get_create_url() . '#library';
|
||||
}
|
||||
|
||||
public function save( $data ) {
|
||||
if ( empty( $data['settings']['template'] ) ) {
|
||||
$data['settings']['template'] = Page_Templates_Module::TEMPLATE_CANVAS;
|
||||
}
|
||||
|
||||
return parent::save( $data );
|
||||
}
|
||||
|
||||
public function admin_columns_content( $column_name ) {
|
||||
if ( 'elementor_library_type' === $column_name ) {
|
||||
$admin_filter_url = admin_url( Source_Local::ADMIN_MENU_SLUG . '&elementor_library_type=' . $this->get_name() );
|
||||
$meta = static::get_floating_element_type( $this->get_main_id() );
|
||||
printf( '<a href="%s">%s</a>', $admin_filter_url, Module::get_floating_elements_types()[ $meta ] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
}
|
||||
|
||||
public function get_edit_url() {
|
||||
return add_query_arg(
|
||||
[
|
||||
'post' => $this->get_main_id(),
|
||||
'action' => 'elementor',
|
||||
'floating_element' => get_post_meta(
|
||||
$this->get_main_id(),
|
||||
Module::FLOATING_ELEMENTS_TYPE_META_KEY,
|
||||
true
|
||||
),
|
||||
],
|
||||
admin_url( 'post.php' )
|
||||
);
|
||||
}
|
||||
|
||||
protected function get_remote_library_config() {
|
||||
$config = [
|
||||
'type' => 'floating_button',
|
||||
'default_route' => 'templates/floating-buttons',
|
||||
'autoImportSettings' => true,
|
||||
];
|
||||
|
||||
return array_replace_recursive( parent::get_remote_library_config(), $config );
|
||||
}
|
||||
}
|
||||
560
wp-content/plugins/elementor/modules/floating-buttons/module.php
Normal file
560
wp-content/plugins/elementor/modules/floating-buttons/module.php
Normal file
@@ -0,0 +1,560 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\FloatingButtons;
|
||||
|
||||
use Elementor\Controls_Manager;
|
||||
use Elementor\Core\Admin\Menu\Admin_Menu_Manager;
|
||||
use Elementor\Core\Base\Document;
|
||||
use Elementor\Core\Base\Module as BaseModule;
|
||||
use Elementor\Core\Documents_Manager;
|
||||
use Elementor\Core\Experiments\Manager;
|
||||
use Elementor\Modules\FloatingButtons\Base\Widget_Floating_Bars_Base;
|
||||
use Elementor\Modules\FloatingButtons\AdminMenuItems\Floating_Buttons_Empty_View_Menu_Item;
|
||||
use Elementor\Modules\FloatingButtons\AdminMenuItems\Floating_Buttons_Menu_Item;
|
||||
use Elementor\Modules\FloatingButtons\Base\Widget_Contact_Button_Base;
|
||||
use Elementor\Modules\FloatingButtons\Classes\Action\Action_Handler;
|
||||
use Elementor\Modules\FloatingButtons\Control\Hover_Animation_Floating_Buttons;
|
||||
use Elementor\Modules\FloatingButtons\Documents\Floating_Buttons;
|
||||
use Elementor\Plugin;
|
||||
use Elementor\TemplateLibrary\Source_Local;
|
||||
use Elementor\Utils as ElementorUtils;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Module extends BaseModule {
|
||||
|
||||
const FLOATING_ELEMENTS_TYPE_META_KEY = '_elementor_floating_elements_type';
|
||||
const ROUTER_OPTION_KEY = 'elementor_floating_buttons_router_version';
|
||||
const META_CLICK_TRACKING = '_elementor_click_tracking';
|
||||
const CLICK_TRACKING_NONCE = 'elementor-conversion-center-click';
|
||||
const FLOATING_BUTTONS_DOCUMENT_TYPE = 'floating-buttons';
|
||||
const CPT_FLOATING_BUTTONS = 'e-floating-buttons';
|
||||
const ADMIN_PAGE_SLUG_CONTACT = 'edit.php?post_type=e-floating-buttons';
|
||||
const WIDGET_HAS_CUSTOM_BREAKPOINTS = true;
|
||||
|
||||
private $has_contact_pages = null;
|
||||
private $trashed_contact_pages;
|
||||
|
||||
public static function is_active(): bool {
|
||||
return Plugin::$instance->experiments->is_feature_active( 'container' );
|
||||
}
|
||||
|
||||
public static function get_floating_elements_types() {
|
||||
return [
|
||||
'floating-buttons' => esc_html__( 'Floating Buttons', 'elementor' ),
|
||||
'floating-bars' => esc_html__( 'Floating Bars', 'elementor' ),
|
||||
];
|
||||
}
|
||||
|
||||
public function get_name(): string {
|
||||
return 'floating-buttons';
|
||||
}
|
||||
|
||||
public function get_widgets(): array {
|
||||
|
||||
return [
|
||||
'Contact_Buttons',
|
||||
'Floating_Bars_Var_1',
|
||||
];
|
||||
}
|
||||
|
||||
private function register_admin_menu_legacy( Admin_Menu_Manager $admin_menu ) {
|
||||
$menu_args = $this->get_contact_menu_args();
|
||||
$function = $menu_args['function'];
|
||||
if ( is_callable( $function ) ) {
|
||||
$admin_menu->register( $menu_args['menu_slug'], new Floating_Buttons_Empty_View_Menu_Item( $function ) );
|
||||
} else {
|
||||
$admin_menu->register( $menu_args['menu_slug'], new Floating_Buttons_Menu_Item() );
|
||||
};
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
if ( Floating_Buttons::is_creating_floating_buttons_page() || Floating_Buttons::is_editing_existing_floating_buttons_page() ) {
|
||||
Controls_Manager::add_tab(
|
||||
Widget_Contact_Button_Base::TAB_ADVANCED,
|
||||
esc_html__( 'Advanced', 'elementor' )
|
||||
);
|
||||
|
||||
Controls_Manager::add_tab(
|
||||
Widget_Floating_Bars_Base::TAB_ADVANCED,
|
||||
esc_html__( 'Advanced', 'elementor' )
|
||||
);
|
||||
}
|
||||
|
||||
$this->register_contact_pages_cpt();
|
||||
|
||||
add_action( 'elementor/documents/register', function ( Documents_Manager $documents_manager ) {
|
||||
$documents_manager->register_document_type(
|
||||
static::FLOATING_BUTTONS_DOCUMENT_TYPE,
|
||||
Floating_Buttons::get_class_full_name()
|
||||
);
|
||||
} );
|
||||
|
||||
add_action( 'current_screen', function() {
|
||||
$screen = get_current_screen();
|
||||
if ( $screen && 'edit-e-floating-buttons' === $screen->id ) {
|
||||
$this->flush_permalinks_on_elementor_version_change();
|
||||
}
|
||||
});
|
||||
|
||||
add_action( 'wp_ajax_elementor_send_clicks', [ $this, 'handle_click_tracking' ] );
|
||||
add_action( 'wp_ajax_nopriv_elementor_send_clicks', [ $this, 'handle_click_tracking' ] );
|
||||
|
||||
add_action( 'elementor/frontend/after_register_styles', [ $this, 'register_styles' ] );
|
||||
|
||||
add_action( 'elementor/controls/register', function ( Controls_Manager $controls_manager ) {
|
||||
$controls_manager->register( new Hover_Animation_Floating_Buttons() );
|
||||
});
|
||||
|
||||
add_filter( 'elementor/widget/common/register_css_attributes_control', function ( $common_controls ) {
|
||||
if ( Floating_Buttons::is_creating_floating_buttons_page() || Floating_Buttons::is_editing_existing_floating_buttons_page() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $common_controls;
|
||||
} );
|
||||
|
||||
add_filter( 'elementor/settings/controls/checkbox_list_cpt/post_type_objects', function ( $post_types ) {
|
||||
unset( $post_types[ static::CPT_FLOATING_BUTTONS ] );
|
||||
|
||||
return $post_types;
|
||||
} );
|
||||
|
||||
add_filter(
|
||||
'elementor/template_library/sources/local/is_valid_template_type',
|
||||
function ( $is_valid_template_type, $cpt ) {
|
||||
|
||||
if ( in_array( static::CPT_FLOATING_BUTTONS, $cpt, true ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $is_valid_template_type;
|
||||
},
|
||||
10,
|
||||
2
|
||||
);
|
||||
|
||||
if ( ! ElementorUtils::has_pro() ) {
|
||||
add_action( 'wp_footer', function () {
|
||||
$this->render_floating_buttons();
|
||||
} );
|
||||
}
|
||||
|
||||
add_action( 'elementor/admin-top-bar/is-active', function ( $is_top_bar_active, $current_screen ) {
|
||||
|
||||
if ( strpos( $current_screen->id ?? '', static::CPT_FLOATING_BUTTONS ) !== false ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $is_top_bar_active;
|
||||
}, 10, 2 );
|
||||
|
||||
add_action( 'elementor/admin/menu/register', function( Admin_Menu_Manager $admin_menu ) {
|
||||
$this->register_admin_menu_legacy( $admin_menu );
|
||||
}, Source_Local::ADMIN_MENU_PRIORITY + 20 );
|
||||
|
||||
add_action( 'elementor/admin/localize_settings', function ( array $settings ) {
|
||||
return $this->admin_localize_settings( $settings );
|
||||
} );
|
||||
|
||||
add_action( 'elementor/editor/localize_settings', function ( $data ) {
|
||||
return $this->editor_localize_settings( $data );
|
||||
} );
|
||||
|
||||
add_filter( 'elementor/template_library/sources/local/register_taxonomy_cpts', function ( array $cpts ) {
|
||||
$cpts[] = static::CPT_FLOATING_BUTTONS;
|
||||
|
||||
return $cpts;
|
||||
} );
|
||||
|
||||
add_action( 'admin_init', function () {
|
||||
$action = sanitize_text_field( filter_input( INPUT_GET, 'action' ) );
|
||||
|
||||
if ( $action ) {
|
||||
$menu_args = $this->get_contact_menu_args();
|
||||
$action_handler = new Action_Handler( $action, $menu_args );
|
||||
$action_handler->process_action();
|
||||
}
|
||||
} );
|
||||
|
||||
add_action( 'manage_' . static::CPT_FLOATING_BUTTONS . '_posts_columns', function( $posts_columns ) {
|
||||
$source_local = Plugin::$instance->templates_manager->get_source( 'local' );
|
||||
unset( $posts_columns['date'] );
|
||||
unset( $posts_columns['comments'] );
|
||||
$posts_columns['click_tracking'] = esc_html__( 'Click Tracking', 'elementor' );
|
||||
|
||||
if ( ! ElementorUtils::has_pro() ) {
|
||||
$posts_columns['instances'] = esc_html__( 'Instances', 'elementor' );
|
||||
}
|
||||
|
||||
return $source_local->admin_columns_headers( $posts_columns );
|
||||
} );
|
||||
|
||||
add_action(
|
||||
'manage_' . static::CPT_FLOATING_BUTTONS . '_posts_custom_column',
|
||||
[ $this, 'set_admin_columns_content' ],
|
||||
10,
|
||||
2
|
||||
);
|
||||
|
||||
add_action( 'admin_bar_menu', function ( $admin_bar ) {
|
||||
|
||||
$this->override_admin_bar_add_contact( $admin_bar );
|
||||
}, 100 );
|
||||
}
|
||||
|
||||
public function is_preview_for_document( $post_id ) {
|
||||
$preview_id = ElementorUtils::get_super_global_value( $_GET, 'preview_id' );
|
||||
$preview = ElementorUtils::get_super_global_value( $_GET, 'preview' );
|
||||
|
||||
return 'true' === $preview && (int) $post_id === (int) $preview_id;
|
||||
}
|
||||
|
||||
public function handle_click_tracking() {
|
||||
$data = filter_input_array( INPUT_POST, [
|
||||
'clicks' => [
|
||||
'filter' => FILTER_VALIDATE_INT,
|
||||
'flags' => FILTER_REQUIRE_ARRAY,
|
||||
],
|
||||
'_nonce' => FILTER_UNSAFE_RAW,
|
||||
] );
|
||||
|
||||
if ( ! wp_verify_nonce( $data['_nonce'], static::CLICK_TRACKING_NONCE ) ) {
|
||||
wp_send_json_error( [ 'message' => 'Invalid nonce' ] );
|
||||
}
|
||||
|
||||
if ( ! check_ajax_referer( static::CLICK_TRACKING_NONCE, '_nonce', false ) ) {
|
||||
wp_send_json_error( [ 'message' => 'Invalid referrer' ] );
|
||||
}
|
||||
|
||||
$posts_to_update = [];
|
||||
|
||||
foreach ( $data['clicks'] as $post_id ) {
|
||||
if ( ! isset( $posts_to_update[ $post_id ] ) ) {
|
||||
$starting_clicks = (int) get_post_meta( $post_id, static::META_CLICK_TRACKING, true );
|
||||
$posts_to_update[ $post_id ] = $starting_clicks ? $starting_clicks : 0;
|
||||
}
|
||||
$posts_to_update[ $post_id ]++;
|
||||
}
|
||||
|
||||
foreach ( $posts_to_update as $post_id => $clicks ) {
|
||||
if ( self::CPT_FLOATING_BUTTONS !== get_post_type( $post_id ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( 'publish' !== get_post_status( $post_id ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
update_post_meta( $post_id, static::META_CLICK_TRACKING, $clicks );
|
||||
}
|
||||
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
public function set_admin_columns_content( $column_name, $post_id ) {
|
||||
$document = Plugin::$instance->documents->get( $post_id );
|
||||
|
||||
if ( method_exists( $document, 'admin_columns_content' ) ) {
|
||||
$document->admin_columns_content( $column_name );
|
||||
}
|
||||
|
||||
switch ( $column_name ) {
|
||||
case 'click_tracking':
|
||||
$click_tracking = get_post_meta( $post_id, static::META_CLICK_TRACKING, true );
|
||||
echo esc_html( $click_tracking );
|
||||
break;
|
||||
case 'instances':
|
||||
if ( ElementorUtils::has_pro() ) {
|
||||
break;
|
||||
}
|
||||
$instances = get_post_meta( $post_id, '_elementor_conditions', true );
|
||||
if ( $instances ) {
|
||||
echo esc_html__( 'Entire Site', 'elementor' );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function flush_permalinks_on_elementor_version_change() {
|
||||
if ( get_option( static::ROUTER_OPTION_KEY ) !== ELEMENTOR_VERSION ) {
|
||||
flush_rewrite_rules();
|
||||
update_option( static::ROUTER_OPTION_KEY, ELEMENTOR_VERSION );
|
||||
}
|
||||
}
|
||||
|
||||
private function get_trashed_contact_posts(): array {
|
||||
if ( $this->trashed_contact_pages ) {
|
||||
return $this->trashed_contact_pages;
|
||||
}
|
||||
|
||||
$this->trashed_contact_pages = $this->get_trashed_posts(
|
||||
static::CPT_FLOATING_BUTTONS,
|
||||
static::FLOATING_BUTTONS_DOCUMENT_TYPE
|
||||
);
|
||||
|
||||
return $this->trashed_contact_pages;
|
||||
}
|
||||
|
||||
private function get_trashed_posts( string $cpt, string $document_type ) {
|
||||
$query = new \WP_Query( [
|
||||
'no_found_rows' => true,
|
||||
'post_type' => $cpt,
|
||||
'post_status' => 'trash',
|
||||
'posts_per_page' => 1,
|
||||
'meta_key' => '_elementor_template_type',
|
||||
'meta_value' => $document_type,
|
||||
] );
|
||||
|
||||
return $query->posts;
|
||||
}
|
||||
|
||||
private function get_add_new_contact_page_url() {
|
||||
if ( ElementorUtils::has_pro() ) {
|
||||
return Plugin::$instance->documents->get_create_new_post_url(
|
||||
static::CPT_FLOATING_BUTTONS,
|
||||
static::FLOATING_BUTTONS_DOCUMENT_TYPE
|
||||
);
|
||||
}
|
||||
|
||||
return Plugin::$instance->documents->get_create_new_post_url(
|
||||
static::CPT_FLOATING_BUTTONS,
|
||||
static::FLOATING_BUTTONS_DOCUMENT_TYPE
|
||||
) . '#library';
|
||||
}
|
||||
|
||||
public function print_empty_contact_pages_page() {
|
||||
$template_sources = Plugin::$instance->templates_manager->get_registered_sources();
|
||||
$source_local = $template_sources['local'];
|
||||
$trashed_posts = $this->get_trashed_contact_posts();
|
||||
|
||||
?>
|
||||
<div class="e-landing-pages-empty">
|
||||
<?php
|
||||
/** @var Source_Local $source_local */
|
||||
$source_local->print_blank_state_template(
|
||||
esc_html__( 'Floating Element', 'elementor' ),
|
||||
$this->get_add_new_contact_page_url(),
|
||||
nl2br( esc_html__( 'Add a Floating element so your users can easily get in touch!', 'elementor' ) )
|
||||
);
|
||||
|
||||
if ( ! empty( $trashed_posts ) ) : ?>
|
||||
<div class="e-trashed-items">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %1$s Link open tag, %2$s: Link close tag. */
|
||||
esc_html__( 'Or view %1$sTrashed Items%2$s', 'elementor' ),
|
||||
'<a href="' . esc_url( admin_url( 'edit.php?post_status=trash&post_type=' . self::CPT_FLOATING_BUTTONS ) ) . '">',
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
private function admin_localize_settings( $settings ) {
|
||||
$contact_menu_slug = $this->get_contact_menu_args()['menu_slug'];
|
||||
|
||||
if ( static::CPT_FLOATING_BUTTONS === $contact_menu_slug ) {
|
||||
$contact_menu_slug = 'admin.php?page=' . $contact_menu_slug;
|
||||
}
|
||||
|
||||
$additional_settings = [
|
||||
'urls' => [
|
||||
'addNewLinkUrlContact' => $this->get_add_new_contact_page_url(),
|
||||
'viewContactPageUrl' => $contact_menu_slug,
|
||||
],
|
||||
'contactPages' => [
|
||||
'hasPages' => $this->has_contact_pages(),
|
||||
],
|
||||
];
|
||||
|
||||
return array_replace_recursive( $settings, $additional_settings );
|
||||
}
|
||||
|
||||
private function register_contact_pages_cpt() {
|
||||
$this->register_post_type(
|
||||
Floating_Buttons::get_labels(),
|
||||
static::CPT_FLOATING_BUTTONS
|
||||
);
|
||||
}
|
||||
|
||||
private function register_post_type( array $labels, string $cpt ) {
|
||||
$args = [
|
||||
'labels' => $labels,
|
||||
'public' => true,
|
||||
'show_in_menu' => 'edit.php?post_type=elementor_library&tabs_group=library',
|
||||
'show_in_nav_menus' => false,
|
||||
'capability_type' => 'post',
|
||||
'taxonomies' => [ Source_Local::TAXONOMY_TYPE_SLUG ],
|
||||
'show_in_rest' => true,
|
||||
'supports' => [
|
||||
'title',
|
||||
'editor',
|
||||
'comments',
|
||||
'revisions',
|
||||
'trackbacks',
|
||||
'author',
|
||||
'excerpt',
|
||||
'page-attributes',
|
||||
'thumbnail',
|
||||
'custom-fields',
|
||||
'post-formats',
|
||||
'elementor',
|
||||
],
|
||||
];
|
||||
|
||||
register_post_type( $cpt, $args );
|
||||
}
|
||||
|
||||
private function has_contact_pages(): bool {
|
||||
if ( null !== $this->has_contact_pages ) {
|
||||
return $this->has_contact_pages;
|
||||
}
|
||||
|
||||
$this->has_contact_pages = $this->has_pages(
|
||||
static::CPT_FLOATING_BUTTONS,
|
||||
static::FLOATING_BUTTONS_DOCUMENT_TYPE
|
||||
);
|
||||
|
||||
return $this->has_contact_pages;
|
||||
}
|
||||
|
||||
private function has_pages( string $cpt, string $document_type ): bool {
|
||||
$posts_query = new \WP_Query( [
|
||||
'no_found_rows' => true,
|
||||
'post_type' => $cpt,
|
||||
'post_status' => 'any',
|
||||
'posts_per_page' => 1,
|
||||
'meta_key' => '_elementor_template_type',
|
||||
'meta_value' => $document_type,
|
||||
] );
|
||||
|
||||
return $posts_query->post_count > 0;
|
||||
}
|
||||
|
||||
private function get_contact_menu_args(): array {
|
||||
if ( $this->has_contact_pages() ) {
|
||||
$menu_slug = static::ADMIN_PAGE_SLUG_CONTACT;
|
||||
$function = null;
|
||||
} else {
|
||||
$menu_slug = static::CPT_FLOATING_BUTTONS;
|
||||
$function = [ $this, 'print_empty_contact_pages_page' ];
|
||||
}
|
||||
|
||||
return [
|
||||
'menu_slug' => $menu_slug,
|
||||
'function' => $function,
|
||||
];
|
||||
}
|
||||
|
||||
public function override_admin_bar_add_contact( $admin_bar ): void {
|
||||
$new_contact_page_node = $admin_bar->get_node( 'new-e-floating-buttons' );
|
||||
|
||||
if ( $new_contact_page_node ) {
|
||||
$new_contact_page_node->href = $this->get_add_new_contact_page_url();
|
||||
|
||||
$admin_bar->add_node( $new_contact_page_node );
|
||||
}
|
||||
}
|
||||
|
||||
private function editor_localize_settings( $data ) {
|
||||
$data['admin_floating_button_admin_url'] = admin_url( $this->get_contact_menu_args()['menu_slug'] );
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function render_floating_buttons(): void {
|
||||
if ( Plugin::$instance->preview->is_preview_mode() ) {
|
||||
$post_id = ElementorUtils::get_super_global_value( $_GET, 'elementor-preview' );
|
||||
$document = Plugin::$instance->documents->get( $post_id );
|
||||
|
||||
if (
|
||||
$document instanceof Document &&
|
||||
$document->get_name() === static::FLOATING_BUTTONS_DOCUMENT_TYPE
|
||||
) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$query = new \WP_Query( [
|
||||
'post_type' => static::CPT_FLOATING_BUTTONS,
|
||||
'posts_per_page' => - 1,
|
||||
'post_status' => 'publish',
|
||||
'fields' => 'ids',
|
||||
'meta_key' => '_elementor_conditions',
|
||||
'meta_compare' => 'EXISTS',
|
||||
] );
|
||||
|
||||
if ( ! $query->have_posts() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $query->posts as $post_id ) {
|
||||
$conditions = get_post_meta( $post_id, '_elementor_conditions', true );
|
||||
|
||||
if ( ! $conditions ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
in_array( 'include/general', $conditions ) &&
|
||||
! $this->is_preview_for_document( $post_id ) &&
|
||||
get_the_ID() !== $post_id
|
||||
) {
|
||||
$document = Plugin::$instance->documents->get( $post_id );
|
||||
$document->print_content();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register styles.
|
||||
*
|
||||
* At build time, Elementor compiles `/modules/floating-buttons/assets/scss/widgets/*.scss`
|
||||
* to `/assets/css/widget-*.min.css`.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_styles() {
|
||||
$direction_suffix = is_rtl() ? '-rtl' : '';
|
||||
$widget_styles = $this->get_widgets_style_list();
|
||||
$has_custom_breakpoints = Plugin::$instance->breakpoints->has_custom_breakpoints();
|
||||
|
||||
foreach ( $widget_styles as $widget_style_name => $widget_has_responsive_style ) {
|
||||
$should_load_responsive_css = $widget_has_responsive_style ? $has_custom_breakpoints : false;
|
||||
|
||||
wp_register_style(
|
||||
$widget_style_name,
|
||||
$this->get_frontend_file_url( "{$widget_style_name}{$direction_suffix}.min.css", $should_load_responsive_css ),
|
||||
[ 'elementor-frontend', 'elementor-icons' ],
|
||||
$should_load_responsive_css ? null : ELEMENTOR_VERSION
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function get_widgets_style_list(): array {
|
||||
return [
|
||||
'widget-floating-buttons' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, // TODO: Remove in v3.27.0 [ED-15717]
|
||||
'widget-floating-bars-base' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS,
|
||||
'widget-floating-bars-var-2' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS,
|
||||
'widget-floating-bars-var-3' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS,
|
||||
'widget-contact-buttons-base' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS,
|
||||
'widget-contact-buttons-var-1' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS,
|
||||
'widget-contact-buttons-var-3' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS,
|
||||
'widget-contact-buttons-var-4' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS,
|
||||
'widget-contact-buttons-var-6' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS,
|
||||
'widget-contact-buttons-var-7' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS,
|
||||
'widget-contact-buttons-var-8' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS,
|
||||
'widget-contact-buttons-var-9' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS,
|
||||
'widget-contact-buttons-var-10' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\FloatingButtons\Widgets;
|
||||
|
||||
use Elementor\Modules\FloatingButtons\Base\Widget_Contact_Button_Base;
|
||||
use Elementor\Plugin;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* Elementor Contact Buttons widget.
|
||||
*
|
||||
* Elementor widget that displays contact buttons and a chat-like prompt message.
|
||||
*
|
||||
* @since 3.23.0
|
||||
*/
|
||||
class Contact_Buttons extends Widget_Contact_Button_Base {
|
||||
|
||||
public function get_name(): string {
|
||||
return 'contact-buttons';
|
||||
}
|
||||
|
||||
public function get_title(): string {
|
||||
return esc_html__( 'Single Chat', 'elementor' );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\FloatingButtons\Widgets;
|
||||
|
||||
use Elementor\Modules\FloatingButtons\Base\Widget_Floating_Bars_Base;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* Elementor Floating Bars Var 1 widget.
|
||||
*
|
||||
* Elementor widget that displays a banner with icon and link
|
||||
*
|
||||
* @since 3.23.0
|
||||
*/
|
||||
class Floating_Bars_Var_1 extends Widget_Floating_Bars_Base {
|
||||
|
||||
public function get_name(): string {
|
||||
return 'floating-bars-var-1';
|
||||
}
|
||||
|
||||
public function get_title(): string {
|
||||
return esc_html__( 'Floating Bar CTA', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_group_name(): string {
|
||||
return 'floating-bars';
|
||||
}
|
||||
|
||||
public function render(): void {
|
||||
$this->add_inline_editing_attributes( 'announcement_text', 'none' );
|
||||
$this->add_inline_editing_attributes( 'cta_text', 'none' );
|
||||
|
||||
parent::render();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user