Animations.php
4 months ago
BackButton.php
7 months ago
BlockPatterns.php
4 months ago
Carousel.php
4 months ago
ContainerEdgeAlignment.php
7 months ago
Counter.php
4 months ago
Events.php
6 months ago
FluidTypography.php
4 months ago
Gallery.php
8 months ago
GravityFormsInline.php
7 months ago
Headline.php
4 months ago
InsertPost.php
8 months ago
ProductCategories.php
8 months ago
ReadingProgress.php
7 months ago
ReadingTime.php
8 months ago
ShapeAnimations.php
7 months ago
StackedImages.php
4 months ago
StickyColumn.php
8 months ago
Testimonials.php
8 months ago
ReadingProgress.php
85 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Reading Progress Bar 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 | * ReadingProgress class. |
| 17 | * |
| 18 | * @since 1.0.0 |
| 19 | */ |
| 20 | class ReadingProgress { |
| 21 | |
| 22 | /** |
| 23 | * Constructor. |
| 24 | */ |
| 25 | public function __construct() { |
| 26 | add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend_assets' ) ); |
| 27 | add_action( 'wp_footer', array( $this, 'render_reading_progress_bar' ) ); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Check if reading progress is enabled. |
| 32 | * |
| 33 | * @return bool |
| 34 | */ |
| 35 | private function is_enabled() { |
| 36 | $options = get_option( 'frontblocks_settings', array() ); |
| 37 | return (bool) ( $options['enable_reading_progress'] ?? false ); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Enqueue frontend styles and scripts. |
| 42 | * |
| 43 | * @return void |
| 44 | */ |
| 45 | public function enqueue_frontend_assets() { |
| 46 | // Only load on singular posts (blog entries). |
| 47 | if ( ! is_singular( 'post' ) || ! $this->is_enabled() ) { |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | wp_enqueue_style( |
| 52 | 'frontblocks-reading-progress', |
| 53 | FRBL_PLUGIN_URL . 'assets/reading-progress/frontblocks-reading-progress.css', |
| 54 | array(), |
| 55 | FRBL_VERSION |
| 56 | ); |
| 57 | |
| 58 | wp_enqueue_script( |
| 59 | 'frontblocks-reading-progress', |
| 60 | FRBL_PLUGIN_URL . 'assets/reading-progress/frontblocks-reading-progress.js', |
| 61 | array(), |
| 62 | FRBL_VERSION, |
| 63 | true |
| 64 | ); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Render the reading progress bar HTML. |
| 69 | * |
| 70 | * @return void |
| 71 | */ |
| 72 | public function render_reading_progress_bar() { |
| 73 | // Only render on singular posts (blog entries). |
| 74 | if ( ! is_singular( 'post' ) || ! $this->is_enabled() ) { |
| 75 | return; |
| 76 | } |
| 77 | ?> |
| 78 | <div class="frbl-reading-progress-bar" role="progressbar" aria-label="<?php echo esc_attr__( 'Reading progress', 'frontblocks' ); ?>" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"> |
| 79 | <div class="frbl-reading-progress-fill"></div> |
| 80 | </div> |
| 81 | <?php |
| 82 | } |
| 83 | } |
| 84 | |
| 85 |