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 ) ) : ?>
',
''
);
?>
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' => '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 ) &&
! $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/frontend.scss`
* to `/assets/css/widget-floating-buttons.min.css`.
*
* @return void
*/
public function register_styles() {
wp_register_style(
'widget-floating-buttons',
$this->get_css_assets_url( 'widget-floating-buttons', null, true, true ),
[ 'elementor-icons' ],
ELEMENTOR_VERSION
);
}
}