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
UserText.php
134 lines
| 1 | <?php |
| 2 | /** |
| 3 | * User Text block for FrontBlocks. |
| 4 | * |
| 5 | * Renders a text pattern with logged-in user data substituted for placeholders. |
| 6 | * |
| 7 | * @package FrontBlocks |
| 8 | * @author Alex castellón <castellon@close.technology> |
| 9 | * @copyright 2025 Closemarketing |
| 10 | * @version 1.0.0 |
| 11 | */ |
| 12 | |
| 13 | namespace FrontBlocks\Frontend; |
| 14 | |
| 15 | defined( 'ABSPATH' ) || exit; |
| 16 | |
| 17 | /** |
| 18 | * UserText class. |
| 19 | * |
| 20 | * @since 1.4.0 |
| 21 | */ |
| 22 | class UserText { |
| 23 | |
| 24 | /** |
| 25 | * Constructor. |
| 26 | */ |
| 27 | public function __construct() { |
| 28 | add_action( 'init', array( $this, 'register_block' ) ); |
| 29 | add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_editor_assets' ) ); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Register the block type with a server-side render callback. |
| 34 | * |
| 35 | * @return void |
| 36 | */ |
| 37 | public function register_block() { |
| 38 | wp_register_script( |
| 39 | 'frontblocks-user-text-editor', |
| 40 | FRBL_PLUGIN_URL . 'assets/user-text/frontblocks-user-text.js', |
| 41 | array( |
| 42 | 'wp-blocks', |
| 43 | 'wp-element', |
| 44 | 'wp-block-editor', |
| 45 | 'wp-components', |
| 46 | 'wp-i18n', |
| 47 | ), |
| 48 | FRBL_VERSION, |
| 49 | true |
| 50 | ); |
| 51 | |
| 52 | wp_register_style( |
| 53 | 'frontblocks-user-text-editor', |
| 54 | FRBL_PLUGIN_URL . 'assets/user-text/frontblocks-user-text.css', |
| 55 | array(), |
| 56 | FRBL_VERSION |
| 57 | ); |
| 58 | |
| 59 | register_block_type( |
| 60 | 'frontblocks/user-text', |
| 61 | array( |
| 62 | 'editor_script' => 'frontblocks-user-text-editor', |
| 63 | 'editor_style' => 'frontblocks-user-text-editor', |
| 64 | 'render_callback' => array( $this, 'render_block' ), |
| 65 | 'attributes' => array( |
| 66 | 'textPattern' => array( |
| 67 | 'type' => 'string', |
| 68 | 'default' => '', |
| 69 | ), |
| 70 | 'htmlTag' => array( |
| 71 | 'type' => 'string', |
| 72 | 'default' => 'p', |
| 73 | ), |
| 74 | 'textColor' => array( |
| 75 | 'type' => 'string', |
| 76 | 'default' => '', |
| 77 | ), |
| 78 | 'hoverTextColor' => array( |
| 79 | 'type' => 'string', |
| 80 | 'default' => '', |
| 81 | ), |
| 82 | 'fontSize' => array( |
| 83 | 'type' => 'string', |
| 84 | 'default' => '', |
| 85 | ), |
| 86 | 'fontFamily' => array( |
| 87 | 'type' => 'string', |
| 88 | 'default' => '', |
| 89 | ), |
| 90 | 'fontWeight' => array( |
| 91 | 'type' => 'string', |
| 92 | 'default' => '', |
| 93 | ), |
| 94 | 'textAlign' => array( |
| 95 | 'type' => 'string', |
| 96 | 'default' => '', |
| 97 | ), |
| 98 | 'loggedOutText' => array( |
| 99 | 'type' => 'string', |
| 100 | 'default' => '', |
| 101 | ), |
| 102 | ), |
| 103 | ) |
| 104 | ); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Render the block on the frontend. |
| 109 | * |
| 110 | * Actual rendering is handled by FrontBlocks Pro via the frbl_user_text_render filter. |
| 111 | * |
| 112 | * @param array $attrs Block attributes. |
| 113 | * @return string |
| 114 | */ |
| 115 | public function render_block( $attrs ) { |
| 116 | return apply_filters( 'frbl_user_text_render', '', $attrs ); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Enqueue editor-only assets. |
| 121 | * |
| 122 | * @return void |
| 123 | */ |
| 124 | public function enqueue_editor_assets() { |
| 125 | wp_enqueue_script( 'frontblocks-user-text-editor' ); |
| 126 | wp_enqueue_style( 'frontblocks-user-text-editor' ); |
| 127 | |
| 128 | wp_set_script_translations( |
| 129 | 'frontblocks-user-text-editor', |
| 130 | 'frontblocks' |
| 131 | ); |
| 132 | } |
| 133 | } |
| 134 |