| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\FloatingButtons; |
| 4 |
|
| 5 |
use Elementor\Controls_Manager; |
| 6 |
use Elementor\Core\Admin\Menu\Admin_Menu_Manager; |
| 7 |
use Elementor\Core\Base\Document; |
| 8 |
use Elementor\Core\Base\Module as BaseModule; |
| 9 |
use Elementor\Core\Documents_Manager; |
| 10 |
use Elementor\Core\Experiments\Manager; |
| 11 |
use Elementor\Modules\FloatingButtons\Base\Widget_Floating_Bars_Base; |
| 12 |
use Elementor\Modules\FloatingButtons\AdminMenuItems\Floating_Buttons_Empty_View_Menu_Item; |
| 13 |
use Elementor\Modules\FloatingButtons\AdminMenuItems\Floating_Buttons_Menu_Item; |
| 14 |
use Elementor\Modules\FloatingButtons\Base\Widget_Contact_Button_Base; |
| 15 |
use Elementor\Modules\FloatingButtons\Control\Hover_Animation_Floating_Buttons; |
| 16 |
use Elementor\Modules\FloatingButtons\Documents\Floating_Buttons; |
| 17 |
use Elementor\Plugin; |
| 18 |
use Elementor\TemplateLibrary\Source_Local; |
| 19 |
use Elementor\Utils as ElementorUtils; |
| 20 |
|
| 21 |
if ( ! defined( 'ABSPATH' ) ) { |
| 22 |
exit; // Exit if accessed directly. |
| 23 |
} |
| 24 |
|
| 25 |
class Module extends BaseModule { |
| 26 |
|
| 27 |
const FLOATING_ELEMENTS_TYPE_META_KEY = '_elementor_floating_elements_type'; |
| 28 |
const ROUTER_OPTION_KEY = 'elementor_floating_buttons_router_version'; |
| 29 |
const META_CLICK_TRACKING = '_elementor_click_tracking'; |
| 30 |
const CLICK_TRACKING_NONCE = 'elementor-conversion-center-click'; |
| 31 |
const FLOATING_BUTTONS_DOCUMENT_TYPE = 'floating-buttons'; |
| 32 |
const CPT_FLOATING_BUTTONS = 'e-floating-buttons'; |
| 33 |
const ADMIN_PAGE_SLUG_CONTACT = 'edit.php?post_type=e-floating-buttons'; |
| 34 |
const WIDGET_HAS_CUSTOM_BREAKPOINTS = true; |
| 35 |
|
| 36 |
private $has_contact_pages = null; |
| 37 |
private $trashed_contact_pages; |
| 38 |
|
| 39 |
public static function is_active(): bool { |
| 40 |
return Plugin::$instance->experiments->is_feature_active( 'container' ); |
| 41 |
} |
| 42 |
|
| 43 |
public static function get_floating_elements_types() { |
| 44 |
return [ |
| 45 |
'floating-buttons' => esc_html__( 'Floating Buttons', 'elementor' ), |
| 46 |
'floating-bars' => esc_html__( 'Floating Bars', 'elementor' ), |
| 47 |
]; |
| 48 |
} |
| 49 |
|
| 50 |
public function get_name(): string { |
| 51 |
return 'floating-buttons'; |
| 52 |
} |
| 53 |
|
| 54 |
public function get_widgets(): array { |
| 55 |
|
| 56 |
return [ |
| 57 |
'Contact_Buttons', |
| 58 |
'Floating_Bars_Var_1', |
| 59 |
]; |
| 60 |
} |
| 61 |
|
| 62 |
private function register_admin_menu_legacy( Admin_Menu_Manager $admin_menu ) { |
| 63 |
$menu_args = $this->get_contact_menu_args(); |
| 64 |
$function = $menu_args['function']; |
| 65 |
if ( is_callable( $function ) ) { |
| 66 |
$admin_menu->register( $menu_args['menu_slug'], new Floating_Buttons_Empty_View_Menu_Item( $function ) ); |
| 67 |
} else { |
| 68 |
$admin_menu->register( $menu_args['menu_slug'], new Floating_Buttons_Menu_Item() ); |
| 69 |
}; |
| 70 |
} |
| 71 |
|
| 72 |
public function __construct() { |
| 73 |
parent::__construct(); |
| 74 |
|
| 75 |
if ( Floating_Buttons::is_creating_floating_buttons_page() || Floating_Buttons::is_editing_existing_floating_buttons_page() ) { |
| 76 |
Controls_Manager::add_tab( |
| 77 |
Widget_Contact_Button_Base::TAB_ADVANCED, |
| 78 |
esc_html__( 'Advanced', 'elementor' ) |
| 79 |
); |
| 80 |
|
| 81 |
Controls_Manager::add_tab( |
| 82 |
Widget_Floating_Bars_Base::TAB_ADVANCED, |
| 83 |
esc_html__( 'Advanced', 'elementor' ) |
| 84 |
); |
| 85 |
} |
| 86 |
|
| 87 |
$this->register_contact_pages_cpt(); |
| 88 |
|
| 89 |
add_action( 'elementor/documents/register', function ( Documents_Manager $documents_manager ) { |
| 90 |
$documents_manager->register_document_type( |
| 91 |
static::FLOATING_BUTTONS_DOCUMENT_TYPE, |
| 92 |
Floating_Buttons::get_class_full_name() |
| 93 |
); |
| 94 |
} ); |
| 95 |
|
| 96 |
add_action( 'current_screen', function() { |
| 97 |
$screen = get_current_screen(); |
| 98 |
if ( $screen && 'edit-e-floating-buttons' === $screen->id ) { |
| 99 |
$this->flush_permalinks_on_elementor_version_change(); |
| 100 |
} |
| 101 |
}); |
| 102 |
|
| 103 |
add_action( 'wp_ajax_elementor_send_clicks', [ $this, 'handle_click_tracking' ] ); |
| 104 |
add_action( 'wp_ajax_nopriv_elementor_send_clicks', [ $this, 'handle_click_tracking' ] ); |
| 105 |
|
| 106 |
add_action( 'elementor/frontend/after_register_styles', [ $this, 'register_styles' ] ); |
| 107 |
|
| 108 |
add_action( 'elementor/controls/register', function ( Controls_Manager $controls_manager ) { |
| 109 |
$controls_manager->register( new Hover_Animation_Floating_Buttons() ); |
| 110 |
}); |
| 111 |
|
| 112 |
add_filter( 'elementor/widget/common/register_css_attributes_control', function ( $common_controls ) { |
| 113 |
if ( Floating_Buttons::is_creating_floating_buttons_page() || Floating_Buttons::is_editing_existing_floating_buttons_page() ) { |
| 114 |
return false; |
| 115 |
} |
| 116 |
|
| 117 |
return $common_controls; |
| 118 |
} ); |
| 119 |
|
| 120 |
add_filter( 'elementor/settings/controls/checkbox_list_cpt/post_type_objects', function ( $post_types ) { |
| 121 |
unset( $post_types[ static::CPT_FLOATING_BUTTONS ] ); |
| 122 |
|
| 123 |
return $post_types; |
| 124 |
} ); |
| 125 |
|
| 126 |
add_filter( |
| 127 |
'elementor/template_library/sources/local/is_valid_template_type', |
| 128 |
function ( $is_valid_template_type, $cpt ) { |
| 129 |
|
| 130 |
if ( in_array( static::CPT_FLOATING_BUTTONS, $cpt, true ) ) { |
| 131 |
return true; |
| 132 |
} |
| 133 |
|
| 134 |
return $is_valid_template_type; |
| 135 |
}, |
| 136 |
10, |
| 137 |
2 |
| 138 |
); |
| 139 |
|
| 140 |
if ( ! ElementorUtils::has_pro() ) { |
| 141 |
add_action( 'wp_footer', function () { |
| 142 |
$this->render_floating_buttons(); |
| 143 |
} ); |
| 144 |
} |
| 145 |
|
| 146 |
add_action( 'elementor/admin-top-bar/is-active', function ( $is_top_bar_active, $current_screen ) { |
| 147 |
|
| 148 |
if ( strpos( $current_screen->id ?? '', static::CPT_FLOATING_BUTTONS ) !== false ) { |
| 149 |
return true; |
| 150 |
} |
| 151 |
|
| 152 |
return $is_top_bar_active; |
| 153 |
}, 10, 2 ); |
| 154 |
|
| 155 |
add_action( 'elementor/admin/menu/register', function( Admin_Menu_Manager $admin_menu ) { |
| 156 |
$this->register_admin_menu_legacy( $admin_menu ); |
| 157 |
}, Source_Local::ADMIN_MENU_PRIORITY + 20 ); |
| 158 |
|
| 159 |
add_action( 'elementor/admin/localize_settings', function ( array $settings ) { |
| 160 |
return $this->admin_localize_settings( $settings ); |
| 161 |
} ); |
| 162 |
|
| 163 |
add_action( 'elementor/editor/localize_settings', function ( $data ) { |
| 164 |
return $this->editor_localize_settings( $data ); |
| 165 |
} ); |
| 166 |
|
| 167 |
add_filter( 'elementor/template_library/sources/local/register_taxonomy_cpts', function ( array $cpts ) { |
| 168 |
$cpts[] = static::CPT_FLOATING_BUTTONS; |
| 169 |
|
| 170 |
return $cpts; |
| 171 |
} ); |
| 172 |
|
| 173 |
add_action( 'admin_init', function () { |
| 174 |
$action = filter_input( INPUT_GET, 'action' ); |
| 175 |
$menu_args = $this->get_contact_menu_args(); |
| 176 |
|
| 177 |
switch ( $action ) { |
| 178 |
case 'remove_from_entire_site': |
| 179 |
$post = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT ); |
| 180 |
check_admin_referer( 'remove_from_entire_site_' . $post ); |
| 181 |
delete_post_meta( $post, '_elementor_conditions' ); |
| 182 |
|
| 183 |
wp_redirect( $menu_args['menu_slug'] ); |
| 184 |
exit; |
| 185 |
case 'set_as_entire_site': |
| 186 |
$post = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT ); |
| 187 |
check_admin_referer( 'set_as_entire_site_' . $post ); |
| 188 |
|
| 189 |
$posts = get_posts( [ |
| 190 |
'post_type' => static::CPT_FLOATING_BUTTONS, |
| 191 |
'posts_per_page' => -1, |
| 192 |
'post_status' => 'publish', |
| 193 |
'fields' => 'ids', |
| 194 |
'no_found_rows' => true, |
| 195 |
'update_post_term_cache' => false, |
| 196 |
'update_post_meta_cache' => false, |
| 197 |
'meta_query' => Floating_Buttons::get_meta_query_for_floating_buttons( |
| 198 |
Floating_Buttons::get_floating_element_type( $post ) |
| 199 |
), |
| 200 |
] ); |
| 201 |
|
| 202 |
foreach ( $posts as $post_id ) { |
| 203 |
delete_post_meta( $post_id, '_elementor_conditions' ); |
| 204 |
} |
| 205 |
|
| 206 |
update_post_meta( $post, '_elementor_conditions', [ 'include/general' ] ); |
| 207 |
|
| 208 |
wp_redirect( $menu_args['menu_slug'] ); |
| 209 |
exit; |
| 210 |
default: |
| 211 |
break; |
| 212 |
} |
| 213 |
} ); |
| 214 |
|
| 215 |
add_action( 'manage_' . static::CPT_FLOATING_BUTTONS . '_posts_columns', function( $posts_columns ) { |
| 216 |
$source_local = Plugin::$instance->templates_manager->get_source( 'local' ); |
| 217 |
unset( $posts_columns['date'] ); |
| 218 |
unset( $posts_columns['comments'] ); |
| 219 |
$posts_columns['click_tracking'] = esc_html__( 'Click Tracking', 'elementor' ); |
| 220 |
|
| 221 |
if ( ! ElementorUtils::has_pro() ) { |
| 222 |
$posts_columns['instances'] = esc_html__( 'Instances', 'elementor' ); |
| 223 |
} |
| 224 |
|
| 225 |
return $source_local->admin_columns_headers( $posts_columns ); |
| 226 |
} ); |
| 227 |
|
| 228 |
add_action( |
| 229 |
'manage_' . static::CPT_FLOATING_BUTTONS . '_posts_custom_column', |
| 230 |
[ $this, 'set_admin_columns_content' ], |
| 231 |
10, |
| 232 |
2 |
| 233 |
); |
| 234 |
|
| 235 |
add_action( 'admin_bar_menu', function ( $admin_bar ) { |
| 236 |
|
| 237 |
$this->override_admin_bar_add_contact( $admin_bar ); |
| 238 |
}, 100 ); |
| 239 |
} |
| 240 |
|
| 241 |
public function is_preview_for_document( $post_id ) { |
| 242 |
$preview_id = ElementorUtils::get_super_global_value( $_GET, 'preview_id' ); |
| 243 |
$preview = ElementorUtils::get_super_global_value( $_GET, 'preview' ); |
| 244 |
|
| 245 |
return 'true' === $preview && (int) $post_id === (int) $preview_id; |
| 246 |
} |
| 247 |
|
| 248 |
public function handle_click_tracking() { |
| 249 |
$data = filter_input_array( INPUT_POST, [ |
| 250 |
'clicks' => [ |
| 251 |
'filter' => FILTER_VALIDATE_INT, |
| 252 |
'flags' => FILTER_REQUIRE_ARRAY, |
| 253 |
], |
| 254 |
'_nonce' => FILTER_UNSAFE_RAW, |
| 255 |
] ); |
| 256 |
|
| 257 |
if ( ! wp_verify_nonce( $data['_nonce'], static::CLICK_TRACKING_NONCE ) ) { |
| 258 |
wp_send_json_error( [ 'message' => 'Invalid nonce' ] ); |
| 259 |
} |
| 260 |
|
| 261 |
if ( ! check_ajax_referer( static::CLICK_TRACKING_NONCE, '_nonce', false ) ) { |
| 262 |
wp_send_json_error( [ 'message' => 'Invalid referrer' ] ); |
| 263 |
} |
| 264 |
|
| 265 |
$posts_to_update = []; |
| 266 |
|
| 267 |
foreach ( $data['clicks'] as $post_id ) { |
| 268 |
if ( ! isset( $posts_to_update[ $post_id ] ) ) { |
| 269 |
$starting_clicks = (int) get_post_meta( $post_id, static::META_CLICK_TRACKING, true ); |
| 270 |
$posts_to_update[ $post_id ] = $starting_clicks ? $starting_clicks : 0; |
| 271 |
} |
| 272 |
$posts_to_update[ $post_id ]++; |
| 273 |
} |
| 274 |
|
| 275 |
foreach ( $posts_to_update as $post_id => $clicks ) { |
| 276 |
if ( self::CPT_FLOATING_BUTTONS !== get_post_type( $post_id ) ) { |
| 277 |
continue; |
| 278 |
} |
| 279 |
|
| 280 |
if ( 'publish' !== get_post_status( $post_id ) ) { |
| 281 |
continue; |
| 282 |
} |
| 283 |
|
| 284 |
update_post_meta( $post_id, static::META_CLICK_TRACKING, $clicks ); |
| 285 |
} |
| 286 |
|
| 287 |
wp_send_json_success(); |
| 288 |
} |
| 289 |
|
| 290 |
public function set_admin_columns_content( $column_name, $post_id ) { |
| 291 |
$document = Plugin::$instance->documents->get( $post_id ); |
| 292 |
|
| 293 |
if ( method_exists( $document, 'admin_columns_content' ) ) { |
| 294 |
$document->admin_columns_content( $column_name ); |
| 295 |
} |
| 296 |
|
| 297 |
switch ( $column_name ) { |
| 298 |
case 'click_tracking': |
| 299 |
$click_tracking = get_post_meta( $post_id, static::META_CLICK_TRACKING, true ); |
| 300 |
echo esc_html( $click_tracking ); |
| 301 |
break; |
| 302 |
case 'instances': |
| 303 |
if ( ElementorUtils::has_pro() ) { |
| 304 |
break; |
| 305 |
} |
| 306 |
$instances = get_post_meta( $post_id, '_elementor_conditions', true ); |
| 307 |
if ( $instances ) { |
| 308 |
echo esc_html__( 'Entire Site', 'elementor' ); |
| 309 |
} |
| 310 |
break; |
| 311 |
default: |
| 312 |
break; |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
public function flush_permalinks_on_elementor_version_change() { |
| 317 |
if ( get_option( static::ROUTER_OPTION_KEY ) !== ELEMENTOR_VERSION ) { |
| 318 |
flush_rewrite_rules(); |
| 319 |
update_option( static::ROUTER_OPTION_KEY, ELEMENTOR_VERSION ); |
| 320 |
} |
| 321 |
} |
| 322 |
|
| 323 |
private function get_trashed_contact_posts(): array { |
| 324 |
if ( $this->trashed_contact_pages ) { |
| 325 |
return $this->trashed_contact_pages; |
| 326 |
} |
| 327 |
|
| 328 |
$this->trashed_contact_pages = $this->get_trashed_posts( |
| 329 |
static::CPT_FLOATING_BUTTONS, |
| 330 |
static::FLOATING_BUTTONS_DOCUMENT_TYPE |
| 331 |
); |
| 332 |
|
| 333 |
return $this->trashed_contact_pages; |
| 334 |
} |
| 335 |
|
| 336 |
private function get_trashed_posts( string $cpt, string $document_type ) { |
| 337 |
$query = new \WP_Query( [ |
| 338 |
'no_found_rows' => true, |
| 339 |
'post_type' => $cpt, |
| 340 |
'post_status' => 'trash', |
| 341 |
'posts_per_page' => 1, |
| 342 |
'meta_key' => '_elementor_template_type', |
| 343 |
'meta_value' => $document_type, |
| 344 |
] ); |
| 345 |
|
| 346 |
return $query->posts; |
| 347 |
} |
| 348 |
|
| 349 |
private function get_add_new_contact_page_url() { |
| 350 |
if ( ElementorUtils::has_pro() ) { |
| 351 |
return Plugin::$instance->documents->get_create_new_post_url( |
| 352 |
static::CPT_FLOATING_BUTTONS, |
| 353 |
static::FLOATING_BUTTONS_DOCUMENT_TYPE |
| 354 |
); |
| 355 |
} |
| 356 |
|
| 357 |
return Plugin::$instance->documents->get_create_new_post_url( |
| 358 |
static::CPT_FLOATING_BUTTONS, |
| 359 |
static::FLOATING_BUTTONS_DOCUMENT_TYPE |
| 360 |
) . '#library'; |
| 361 |
} |
| 362 |
|
| 363 |
public function print_empty_contact_pages_page() { |
| 364 |
$template_sources = Plugin::$instance->templates_manager->get_registered_sources(); |
| 365 |
$source_local = $template_sources['local']; |
| 366 |
$trashed_posts = $this->get_trashed_contact_posts(); |
| 367 |
|
| 368 |
?> |
| 369 |
<div class="e-landing-pages-empty"> |
| 370 |
<?php |
| 371 |
/** @var Source_Local $source_local */ |
| 372 |
$source_local->print_blank_state_template( |
| 373 |
esc_html__( 'Floating Element', 'elementor' ), |
| 374 |
$this->get_add_new_contact_page_url(), |
| 375 |
nl2br( esc_html__( 'Add a Floating element so your users can easily get in touch!', 'elementor' ) ) |
| 376 |
); |
| 377 |
|
| 378 |
if ( ! empty( $trashed_posts ) ) : ?> |
| 379 |
<div class="e-trashed-items"> |
| 380 |
<?php |
| 381 |
printf( |
| 382 |
/* translators: %1$s Link open tag, %2$s: Link close tag. */ |
| 383 |
esc_html__( 'Or view %1$sTrashed Items%1$s', 'elementor' ), |
| 384 |
'<a href="' . esc_url( admin_url( 'edit.php?post_status=trash&post_type=' . self::CPT_FLOATING_BUTTONS ) ) . '">', |
| 385 |
'</a>' |
| 386 |
); |
| 387 |
?> |
| 388 |
</div> |
| 389 |
<?php endif; ?> |
| 390 |
</div> |
| 391 |
<?php |
| 392 |
} |
| 393 |
|
| 394 |
private function admin_localize_settings( $settings ) { |
| 395 |
$contact_menu_slug = $this->get_contact_menu_args()['menu_slug']; |
| 396 |
|
| 397 |
if ( static::CPT_FLOATING_BUTTONS === $contact_menu_slug ) { |
| 398 |
$contact_menu_slug = 'admin.php?page=' . $contact_menu_slug; |
| 399 |
} |
| 400 |
|
| 401 |
$additional_settings = [ |
| 402 |
'urls' => [ |
| 403 |
'addNewLinkUrlContact' => $this->get_add_new_contact_page_url(), |
| 404 |
'viewContactPageUrl' => $contact_menu_slug, |
| 405 |
], |
| 406 |
'contactPages' => [ |
| 407 |
'hasPages' => $this->has_contact_pages(), |
| 408 |
], |
| 409 |
]; |
| 410 |
|
| 411 |
return array_replace_recursive( $settings, $additional_settings ); |
| 412 |
} |
| 413 |
|
| 414 |
private function register_contact_pages_cpt() { |
| 415 |
$this->register_post_type( |
| 416 |
Floating_Buttons::get_labels(), |
| 417 |
static::CPT_FLOATING_BUTTONS |
| 418 |
); |
| 419 |
} |
| 420 |
|
| 421 |
private function register_post_type( array $labels, string $cpt ) { |
| 422 |
$args = [ |
| 423 |
'labels' => $labels, |
| 424 |
'public' => true, |
| 425 |
'show_in_menu' => 'edit.php?post_type=elementor_library&tabs_group=library', |
| 426 |
'show_in_nav_menus' => false, |
| 427 |
'capability_type' => 'post', |
| 428 |
'taxonomies' => [ Source_Local::TAXONOMY_TYPE_SLUG ], |
| 429 |
'show_in_rest' => true, |
| 430 |
'supports' => [ |
| 431 |
'title', |
| 432 |
'editor', |
| 433 |
'comments', |
| 434 |
'revisions', |
| 435 |
'trackbacks', |
| 436 |
'author', |
| 437 |
'excerpt', |
| 438 |
'page-attributes', |
| 439 |
'thumbnail', |
| 440 |
'custom-fields', |
| 441 |
'post-formats', |
| 442 |
'elementor', |
| 443 |
], |
| 444 |
]; |
| 445 |
|
| 446 |
register_post_type( $cpt, $args ); |
| 447 |
} |
| 448 |
|
| 449 |
private function has_contact_pages(): bool { |
| 450 |
if ( null !== $this->has_contact_pages ) { |
| 451 |
return $this->has_contact_pages; |
| 452 |
} |
| 453 |
|
| 454 |
$this->has_contact_pages = $this->has_pages( |
| 455 |
static::CPT_FLOATING_BUTTONS, |
| 456 |
static::FLOATING_BUTTONS_DOCUMENT_TYPE |
| 457 |
); |
| 458 |
|
| 459 |
return $this->has_contact_pages; |
| 460 |
} |
| 461 |
|
| 462 |
private function has_pages( string $cpt, string $document_type ): bool { |
| 463 |
$posts_query = new \WP_Query( [ |
| 464 |
'no_found_rows' => true, |
| 465 |
'post_type' => $cpt, |
| 466 |
'post_status' => 'any', |
| 467 |
'posts_per_page' => 1, |
| 468 |
'meta_key' => '_elementor_template_type', |
| 469 |
'meta_value' => $document_type, |
| 470 |
] ); |
| 471 |
|
| 472 |
return $posts_query->post_count > 0; |
| 473 |
} |
| 474 |
|
| 475 |
private function get_contact_menu_args(): array { |
| 476 |
if ( $this->has_contact_pages() ) { |
| 477 |
$menu_slug = static::ADMIN_PAGE_SLUG_CONTACT; |
| 478 |
$function = null; |
| 479 |
} else { |
| 480 |
$menu_slug = static::CPT_FLOATING_BUTTONS; |
| 481 |
$function = [ $this, 'print_empty_contact_pages_page' ]; |
| 482 |
} |
| 483 |
|
| 484 |
return [ |
| 485 |
'menu_slug' => $menu_slug, |
| 486 |
'function' => $function, |
| 487 |
]; |
| 488 |
} |
| 489 |
|
| 490 |
public function override_admin_bar_add_contact( $admin_bar ): void { |
| 491 |
$new_contact_page_node = $admin_bar->get_node( 'new-e-floating-buttons' ); |
| 492 |
|
| 493 |
if ( $new_contact_page_node ) { |
| 494 |
$new_contact_page_node->href = $this->get_add_new_contact_page_url(); |
| 495 |
|
| 496 |
$admin_bar->add_node( $new_contact_page_node ); |
| 497 |
} |
| 498 |
} |
| 499 |
|
| 500 |
private function editor_localize_settings( $data ) { |
| 501 |
$data['admin_floating_button_admin_url'] = admin_url( $this->get_contact_menu_args()['menu_slug'] ); |
| 502 |
return $data; |
| 503 |
} |
| 504 |
|
| 505 |
private function render_floating_buttons(): void { |
| 506 |
if ( Plugin::$instance->preview->is_preview_mode() ) { |
| 507 |
$post_id = ElementorUtils::get_super_global_value( $_GET, 'elementor-preview' ); |
| 508 |
$document = Plugin::$instance->documents->get( $post_id ); |
| 509 |
|
| 510 |
if ( |
| 511 |
$document instanceof Document && |
| 512 |
$document->get_name() === static::FLOATING_BUTTONS_DOCUMENT_TYPE |
| 513 |
) { |
| 514 |
return; |
| 515 |
} |
| 516 |
} |
| 517 |
|
| 518 |
$query = new \WP_Query( [ |
| 519 |
'post_type' => static::CPT_FLOATING_BUTTONS, |
| 520 |
'posts_per_page' => - 1, |
| 521 |
'post_status' => 'publish', |
| 522 |
'fields' => 'ids', |
| 523 |
'meta_key' => '_elementor_conditions', |
| 524 |
'meta_compare' => 'EXISTS', |
| 525 |
] ); |
| 526 |
|
| 527 |
if ( ! $query->have_posts() ) { |
| 528 |
return; |
| 529 |
} |
| 530 |
|
| 531 |
foreach ( $query->posts as $post_id ) { |
| 532 |
$conditions = get_post_meta( $post_id, '_elementor_conditions', true ); |
| 533 |
|
| 534 |
if ( ! $conditions ) { |
| 535 |
continue; |
| 536 |
} |
| 537 |
|
| 538 |
if ( |
| 539 |
in_array( 'include/general', $conditions ) && |
| 540 |
! $this->is_preview_for_document( $post_id ) && |
| 541 |
get_the_ID() !== $post_id |
| 542 |
) { |
| 543 |
$document = Plugin::$instance->documents->get( $post_id ); |
| 544 |
$document->print_content(); |
| 545 |
} |
| 546 |
} |
| 547 |
} |
| 548 |
|
| 549 |
/** |
| 550 |
* Register styles. |
| 551 |
* |
| 552 |
* At build time, Elementor compiles `/modules/floating-buttons/assets/scss/widgets/*.scss` |
| 553 |
* to `/assets/css/widget-*.min.css`. |
| 554 |
* |
| 555 |
* @return void |
| 556 |
*/ |
| 557 |
public function register_styles() { |
| 558 |
$direction_suffix = is_rtl() ? '-rtl' : ''; |
| 559 |
$widget_styles = $this->get_widgets_style_list(); |
| 560 |
$has_custom_breakpoints = Plugin::$instance->breakpoints->has_custom_breakpoints(); |
| 561 |
|
| 562 |
foreach ( $widget_styles as $widget_style_name => $widget_has_responsive_style ) { |
| 563 |
$should_load_responsive_css = $widget_has_responsive_style ? $has_custom_breakpoints : false; |
| 564 |
|
| 565 |
wp_register_style( |
| 566 |
$widget_style_name, |
| 567 |
$this->get_frontend_file_url( "{$widget_style_name}{$direction_suffix}.min.css", $should_load_responsive_css ), |
| 568 |
[ 'elementor-frontend', 'elementor-icons' ], |
| 569 |
$should_load_responsive_css ? null : ELEMENTOR_VERSION |
| 570 |
); |
| 571 |
} |
| 572 |
} |
| 573 |
|
| 574 |
private function get_widgets_style_list(): array { |
| 575 |
return [ |
| 576 |
'widget-floating-buttons' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, // TODO: Remove in v3.27.0 [ED-15717] |
| 577 |
'widget-floating-bars-base' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, |
| 578 |
'widget-floating-bars-var-2' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS, |
| 579 |
'widget-floating-bars-var-3' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, |
| 580 |
'widget-contact-buttons-base' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, |
| 581 |
'widget-contact-buttons-var-1' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS, |
| 582 |
'widget-contact-buttons-var-3' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS, |
| 583 |
'widget-contact-buttons-var-4' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS, |
| 584 |
'widget-contact-buttons-var-6' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS, |
| 585 |
'widget-contact-buttons-var-7' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, |
| 586 |
'widget-contact-buttons-var-8' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS, |
| 587 |
'widget-contact-buttons-var-9' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, |
| 588 |
'widget-contact-buttons-var-10' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, |
| 589 |
]; |
| 590 |
} |
| 591 |
} |
| 592 |
|