Animations.php
1 month ago
BackButton.php
7 months ago
BeforeAfter.php
1 month ago
BlockPatterns.php
4 months ago
Carousel.php
1 week ago
ColumnsSameHeight.php
1 week ago
ContainerEdgeAlignment.php
4 weeks ago
Counter.php
1 month ago
DownloadButton.php
1 week ago
Events.php
4 weeks ago
FaqSchema.php
1 week ago
FluidTypography.php
4 weeks ago
Gallery.php
8 months ago
GravityFormsInline.php
1 month ago
Headline.php
4 weeks ago
InsertPost.php
1 month ago
ProductCategories.php
4 weeks ago
ReadingProgress.php
7 months ago
ReadingTime.php
8 months ago
ShapeAnimations.php
4 weeks ago
StackedImages.php
4 months ago
StickyColumn.php
4 weeks ago
SvgUpload.php
4 weeks ago
Testimonials.php
8 months ago
TextAnimation.php
1 month ago
UserText.php
4 weeks ago
BackButton.php
89 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Back Button 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 | * BackButton class. |
| 17 | * |
| 18 | * @since 1.0.0 |
| 19 | */ |
| 20 | class BackButton { |
| 21 | |
| 22 | /** |
| 23 | * Constructor. |
| 24 | */ |
| 25 | public function __construct() { |
| 26 | // Only load on frontend if enabled. |
| 27 | if ( ! is_admin() && $this->is_enabled() ) { |
| 28 | add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) ); |
| 29 | add_action( 'wp_footer', array( $this, 'render_button' ) ); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Check if back button is enabled. |
| 35 | * |
| 36 | * @return bool |
| 37 | */ |
| 38 | private function is_enabled() { |
| 39 | $options = get_option( 'frontblocks_settings', array() ); |
| 40 | return (bool) ( $options['enable_back_button'] ?? false ); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Enqueue frontend assets. |
| 45 | * |
| 46 | * @return void |
| 47 | */ |
| 48 | public function enqueue_assets() { |
| 49 | wp_enqueue_style( |
| 50 | 'frontblocks-back-button', |
| 51 | FRBL_PLUGIN_URL . 'assets/back-button/frontblocks-back-button.css', |
| 52 | array(), |
| 53 | FRBL_VERSION |
| 54 | ); |
| 55 | |
| 56 | wp_enqueue_script( |
| 57 | 'frontblocks-back-button', |
| 58 | FRBL_PLUGIN_URL . 'assets/back-button/frontblocks-back-button.js', |
| 59 | array(), |
| 60 | FRBL_VERSION, |
| 61 | true |
| 62 | ); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Render the back button HTML. |
| 67 | * |
| 68 | * @return void |
| 69 | */ |
| 70 | public function render_button() { |
| 71 | ?> |
| 72 | <button |
| 73 | id="frbl-back-button" |
| 74 | class="frbl-back-button" |
| 75 | aria-label="<?php echo esc_attr__( 'Go back to previous page', 'frontblocks' ); ?>" |
| 76 | title="<?php echo esc_attr__( 'Go back', 'frontblocks' ); ?>" |
| 77 | > |
| 78 | <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"> |
| 79 | <line x1="19" y1="12" x2="5" y2="12"></line> |
| 80 | <polyline points="12 19 5 12 12 5"></polyline> |
| 81 | </svg> |
| 82 | </button> |
| 83 | <?php |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | new BackButton(); |
| 88 | |
| 89 |