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 Buttons', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_page_title() {
|
||||
return esc_html__( 'Floating Buttons', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_capability() {
|
||||
return 'manage_options';
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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(),
|
||||
] );
|
||||
}
|
||||
|
||||
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,461 @@
|
||||
<?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'];
|
||||
|
||||
$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',
|
||||
] );
|
||||
|
||||
?>
|
||||
<div class="e-contact-buttons__chat-button-container">
|
||||
<button <?php echo $this->widget->get_render_attribute_string( 'button' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> type="button" aria-label="<?php echo esc_attr__( 'Toggle Links Popup', 'elementor' ); ?>">
|
||||
<?php
|
||||
$this->render_chat_button_icon();
|
||||
?>
|
||||
</button>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
protected function render_close_button(): void {
|
||||
?>
|
||||
<button type="button" class="e-contact-buttons__close-button" aria-label="<?php echo esc_attr__( 'Close Links Popup', 'elementor' ); ?>" aria-controls="e-contact-buttons__content-wrapper">
|
||||
<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 ) {
|
||||
|
||||
$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' => esc_attr( $icon['contact_icon_platform'] ),
|
||||
'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,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,144 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\FloatingButtons\Documents;
|
||||
|
||||
use Elementor\Core\DocumentTypes\PageBase;
|
||||
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;
|
||||
|
||||
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 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 function set_as_entire_site( $actions ) {
|
||||
if ( get_post_meta( $this->get_post()->ID, '_elementor_conditions', true ) ) {
|
||||
$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 Button', 'elementor' );
|
||||
}
|
||||
|
||||
public static function get_plural_title() {
|
||||
return esc_html__( 'Floating Buttons', '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 ) {
|
||||
$this->print_admin_column_type();
|
||||
}
|
||||
}
|
||||
|
||||
public function get_edit_url() {
|
||||
$url = parent::get_edit_url();
|
||||
|
||||
if ( ! $this->get_post()->post_content ) {
|
||||
$url .= '#library';
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
540
wp-content/plugins/elementor/modules/floating-buttons/module.php
Normal file
540
wp-content/plugins/elementor/modules/floating-buttons/module.php
Normal file
@@ -0,0 +1,540 @@
|
||||
<?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\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\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 EXPERIMENT_NAME = 'floating-buttons';
|
||||
|
||||
const ROUTER_VERSION = '1.0.0';
|
||||
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';
|
||||
|
||||
private $has_contact_pages = null;
|
||||
private $trashed_contact_pages;
|
||||
|
||||
public static function is_active(): bool {
|
||||
return Plugin::$instance->experiments->is_feature_active( static::EXPERIMENT_NAME );
|
||||
}
|
||||
|
||||
public function get_name(): string {
|
||||
return static::EXPERIMENT_NAME;
|
||||
}
|
||||
|
||||
public function get_widgets(): array {
|
||||
return [
|
||||
'Contact_Buttons',
|
||||
];
|
||||
}
|
||||
|
||||
public static function get_experimental_data(): array {
|
||||
return [
|
||||
'name' => static::EXPERIMENT_NAME,
|
||||
'title' => esc_html__( 'Floating Buttons', 'elementor' ),
|
||||
'description' => esc_html__( 'Boost visitor engagement with Floating Buttons. The Floating Button template library offers a variety of interactive one-click contact options, highlighted links, and calls to action to increase your website conversions.', 'elementor' ),
|
||||
'default' => Manager::STATE_INACTIVE,
|
||||
'release_status' => Manager::RELEASE_STATUS_BETA,
|
||||
'dependencies' => [
|
||||
'container',
|
||||
],
|
||||
'new_site' => [
|
||||
'default_active' => true,
|
||||
'minimum_installation_version' => '3.23.0',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
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 ( $this->is_editing_existing_floating_buttons_page() || $this->is_creating_floating_buttons_page() ) {
|
||||
Controls_Manager::add_tab(
|
||||
Widget_Contact_Button_Base::TAB_ADVANCED,
|
||||
esc_html__( 'Advanced', 'elementor' )
|
||||
);
|
||||
}
|
||||
|
||||
$this->register_contact_pages_cpt();
|
||||
|
||||
if ( ! ElementorUtils::has_pro() ) {
|
||||
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( 'save_post_' . static::CPT_FLOATING_BUTTONS, [ $this, 'flush_permalinks_on_save' ] );
|
||||
|
||||
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/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 ( $this->is_creating_floating_buttons_page() || $this->is_editing_existing_floating_buttons_page() ) {
|
||||
return false;
|
||||
}
|
||||
return $common_controls;
|
||||
} );
|
||||
|
||||
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 = filter_input( INPUT_GET, 'action' );
|
||||
$menu_args = $this->get_contact_menu_args();
|
||||
|
||||
switch ( $action ) {
|
||||
case 'remove_from_entire_site':
|
||||
$post = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT );
|
||||
check_admin_referer( 'remove_from_entire_site_' . $post );
|
||||
delete_post_meta( $post, '_elementor_conditions' );
|
||||
wp_redirect( $menu_args['menu_slug'] );
|
||||
exit;
|
||||
case 'set_as_entire_site':
|
||||
$post = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT );
|
||||
check_admin_referer( 'set_as_entire_site_' . $post );
|
||||
|
||||
$posts = get_posts( [
|
||||
'post_type' => static::CPT_FLOATING_BUTTONS,
|
||||
'posts_per_page' => -1,
|
||||
'post_status' => 'publish',
|
||||
'fields' => 'ids',
|
||||
'meta_key' => '_elementor_conditions',
|
||||
'meta_compare' => 'EXISTS',
|
||||
] );
|
||||
|
||||
foreach ( $posts as $post_id ) {
|
||||
delete_post_meta( $post_id, '_elementor_conditions' );
|
||||
}
|
||||
|
||||
update_post_meta( $post, '_elementor_conditions', [ 'include/general' ] );
|
||||
|
||||
wp_redirect( $menu_args['menu_slug'] );
|
||||
exit;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} );
|
||||
|
||||
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 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 ) {
|
||||
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_save() {
|
||||
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( get_option( static::ROUTER_OPTION_KEY ) !== static::ROUTER_VERSION ) {
|
||||
flush_rewrite_rules();
|
||||
update_option( static::ROUTER_OPTION_KEY, static::ROUTER_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 Button', 'elementor' ),
|
||||
$this->get_add_new_contact_page_url(),
|
||||
nl2br( esc_html__( 'Add a Floating button 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%1$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 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 && $this->is_floating_buttons_type_meta_key( $post_id );
|
||||
}
|
||||
|
||||
private 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 && $this->is_floating_buttons_type_meta_key( $post_id );
|
||||
}
|
||||
|
||||
private function is_floating_buttons_type_meta_key( $post_id ) {
|
||||
return static::FLOATING_BUTTONS_DOCUMENT_TYPE === get_post_meta( $post_id, Document::TYPE_META_KEY, true );
|
||||
}
|
||||
|
||||
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',
|
||||
'capability_type' => 'page',
|
||||
'taxonomies' => [ Source_Local::TAXONOMY_TYPE_SLUG ],
|
||||
'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 ) ) {
|
||||
$document = Plugin::$instance->documents->get( $post_id );
|
||||
$document->print_content();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\FloatingButtons\Widgets;
|
||||
|
||||
use Elementor\Modules\FloatingButtons\Base\Widget_Contact_Button_Base;
|
||||
|
||||
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' );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user