PluginProbe ʕ •ᴥ•ʔ
FrontBlocks for Gutenberg/GeneratePress / 1.5.0
FrontBlocks for Gutenberg/GeneratePress v1.5.0
1.5.2 1.5.1 1.4.0 1.5.0 trunk 0.2.0 0.2.1 0.2.2 0.2.3 0.2.4 0.2.5 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 ci-artifacts
frontblocks / includes / Frontend / ScrollTop.php
frontblocks / includes / Frontend Last commit date
Animations.php 3 months ago BackButton.php 9 months ago BeforeAfter.php 3 months ago BlockPatterns.php 6 months ago Carousel.php 2 months ago ColumnsSameHeight.php 2 months ago ContainerEdgeAlignment.php 1 week ago CookieNotice.php 1 week ago Counter.php 3 months ago DownloadButton.php 2 months ago Events.php 2 months ago FaqSchema.php 2 months ago FluidTypography.php 2 months ago Gallery.php 1 week ago GravityFormsInline.php 3 months ago Headline.php 2 months ago InsertPost.php 3 months ago Maintenance.php 1 week ago ProductCategories.php 2 months ago ReadingProgress.php 9 months ago ReadingTime.php 1 week ago ScrollTop.php 1 week ago ShapeAnimations.php 1 week ago StackedImages.php 6 months ago StickyColumn.php 2 months ago SvgUpload.php 2 months ago Testimonials.php 10 months ago TextAnimation.php 3 months ago UserText.php 2 months ago
ScrollTop.php
104 lines
1 <?php
2 /**
3 * Scroll to Top module for FrontBlocks.
4 *
5 * @package FrontBlocks
6 * @author Closemarketing
7 * @copyright 2025 Closemarketing
8 * @version 1.0
9 */
10
11 namespace FrontBlocks\Frontend;
12
13 defined( 'ABSPATH' ) || exit;
14
15 /**
16 * ScrollTop class.
17 *
18 * @since 1.0.0
19 */
20 class ScrollTop {
21
22 /**
23 * Constructor.
24 */
25 public function __construct() {
26 if ( ! is_admin() && $this->is_enabled() ) {
27 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) );
28 add_action( 'wp_footer', array( $this, 'render_button' ) );
29 }
30 }
31
32 /**
33 * Check if scroll to top is enabled.
34 *
35 * @return bool
36 */
37 private function is_enabled() {
38 $options = get_option( 'frontblocks_settings', array() );
39 return (bool) ( $options['enable_scroll_top'] ?? false );
40 }
41
42 /**
43 * Enqueue frontend assets.
44 *
45 * @return void
46 */
47 public function enqueue_assets() {
48 $options = get_option( 'frontblocks_settings', array() );
49 $position = sanitize_text_field( $options['scroll_top_position'] ?? 'bottom-right' );
50
51 wp_enqueue_style(
52 'frontblocks-scroll-top',
53 FRBL_PLUGIN_URL . 'assets/scroll-top/frontblocks-scroll-top.css',
54 array(),
55 FRBL_VERSION
56 );
57
58 wp_enqueue_script(
59 'frontblocks-scroll-top',
60 FRBL_PLUGIN_URL . 'assets/scroll-top/frontblocks-scroll-top.js',
61 array(),
62 FRBL_VERSION,
63 true
64 );
65
66 wp_localize_script(
67 'frontblocks-scroll-top',
68 'frblScrollTop',
69 array(
70 'position' => $position,
71 )
72 );
73 }
74
75 /**
76 * Render the scroll to top button HTML.
77 *
78 * @return void
79 */
80 public function render_button() {
81 $options = get_option( 'frontblocks_settings', array() );
82 $icon_url = esc_url( $options['scroll_top_icon_url'] ?? '' );
83 $position = sanitize_text_field( $options['scroll_top_position'] ?? 'bottom-right' );
84 $position_class = 'bottom-left' === $position ? 'frbl-scroll-top--left' : 'frbl-scroll-top--right';
85 ?>
86 <button
87 id="frbl-scroll-top"
88 class="frbl-scroll-top <?php echo esc_attr( $position_class ); ?>"
89 aria-label="<?php echo esc_attr__( 'Scroll to top', 'frontblocks' ); ?>"
90 title="<?php echo esc_attr__( 'Scroll to top', 'frontblocks' ); ?>"
91 >
92 <?php if ( $icon_url ) : ?>
93 <img src="<?php echo esc_url( $icon_url ); ?>" alt="" aria-hidden="true" />
94 <?php else : ?>
95 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
96 <line x1="12" y1="19" x2="12" y2="5"></line>
97 <polyline points="5 12 12 5 19 12"></polyline>
98 </svg>
99 <?php endif; ?>
100 </button>
101 <?php
102 }
103 }
104