Syntax highlighter

/wp-content/themes/your-theme/
├── functions.php
└── blocks/
    ├── testimonial/
    │   ├── block.json
	│   ├── editor.css
	│   ├── frontend.css
    │   └── render.php
    └── pricing/
        ├── block.json
	    ├── editor.css
	    ├── frontend.css
        └── render.php
...
/wp-content/plugins/mu-plugins/
├── acf-to-gutenberg.php
└── blocks/
    ├── testimonial/
    │   ├── block.json
	│   ├── editor.css
	│   ├── frontend.css
    │   └── render.php
    └── pricing/
        ├── block.json
	    ├── editor.css
	    ├── frontend.css
        └── render.php
...
{
    "$schema": "https://schemas.wp.org/trunk/block.json",
    "apiVersion": 3,
    "name": "eac-blocks/testimonial",
    "title": "EAC Testimonial",
    "category": "widgets",
    "icon": "awards",
    "description": "Display a customer testimonial with rating",
    "keywords": ["acf", "testimonial", "review", "quote"],
	"textdomain": "eac-components",
	"editorStyle": "file:./editor.css",
	"style": "file:./frontend.css",
	"render": "file:./render.php",
    "supports": {
        "html": false,
		"visibility": true,
		"align": false,
		"className": false,
		"customClassName": false,
		"color": {
			"background": true,
			"text": true,
			"link": true
		},
		"spacing": {
			"margin": true,
			"padding": true,
			"blockGap": true
		},
		"typography": {
			"fontSize": true,
			"textAlign": true
		},
		"shadow": true,
		"__experimentalBorder": {
			"color": true,
			"radius": true,
			"style": true,
			"width": true
		},
		"border": {
			"color": true,
			"radius": true,
			"style": true,
			"width": true
		}
}
<?php
/**
 * Render callback for Testimonial Block
 */

defined( 'ABSPATH' ) || exit;

$tite = isset( $attributes['le_texte'] ) ? trim( $attributes['le_texte'] ) : '';
$show_avatar = isset( $attributes['show_avatar'] ) ? boolval( $attributes['show_avatar'] ) : false;
$text_area = isset( $attributes['le_text_area'] ) ? trim( $attributes['le_text_area'] ) : '';
$la_note = isset( $attributes['la_note'] ) ? absint( $attributes['la_note'] ) : '';
$la_note = '' !== $la_note ? max( 0, min( 5, $la_note ) ) : '';
$page_link = isset( $attributes['internal_publication'] ) ? $attributes['internal_publication'] : '';
$has_image = isset( $attributes['une_image'] ) && is_array( $attributes['une_image'] ) ? $attributes['une_image'] : array();
$has_url = isset( $attributes['lurl'] ) ? trim( $attributes['lurl'] ) : '';
$date_time = isset( $attributes['un_date_time_picker'] ) ? $attributes['un_date_time_picker'] : '';
$reviews = isset( $attributes['the_pricing_card'] ) ? absint( $attributes['the_pricing_card'] ) : 19;
$link_label = isset( $attributes['continue_reading'] ) ? trim( $attributes['continue_reading'] ) : '';

$wrapper_attributes = get_block_wrapper_attributes( array(
	'class' => 'eac-testimonial__block-wrapper',
) );
?>
<article <?php echo wp_kses_data( $wrapper_attributes ); ?>>
	<div class='eac-testimonial__wrapper-image'>
			<?php if ( ! empty( $page_link ) ) : ?>
				<a href='<?php echo esc_url( $page_link ); ?>'>
			<?php endif; ?>

			<?php if ( $show_avatar ) : ?>
				<div class='eac-testimonial__image-avatar'>
					<img src='<?php echo esc_url( get_avatar_url( (int) get_the_author_meta( 'ID' ), array( 'size' => 80 ) ) ); ?>' style='border-radius: 50%; width: 80px; height: 80px;'>
				</div>
			<?php elseif ( ! empty( $has_image ) ) :
				$src        = ! empty( $has_image['src'] ) ? $has_image['src'] : '';
				$src_set    = $has_image['srcset'];
				$src_sizes  = $has_image['sizes'];
				$src_width  = $has_image['width'];
				$src_height = $has_image['height'];
				printf( '<img class="eac-testimonial__image-img" src="%s" srcset="%s" sizes="%s" width="%s" height="%s" />', esc_url( $src ), esc_attr( $src_set ), esc_attr( $src_sizes ), esc_attr( $src_width ), esc_attr( $src_height ) );
			endif;

			if ( ! empty( $page_link ) ) : ?>
				</a>
			<?php endif; ?>
	</div>
	<div class='eac-testimonial__wrapper-content'>
		<?php if ( $titre ) : ?>
			<h2 class='eac-testimonial__content-text'><?php echo esc_html( $titre ); ?></h2>
		<?php endif; ?>

		<?php if ( $text_area ) : ?>
			<p class='eac-testimonial__content-area'><?php echo nl2br( esc_html( $text_area ) ); ?></p>
		<?php endif; ?>

		<?php if ( $date_time ) :
			$timestamp = strtotime( $date_time ); ?>
			<p class='eac-testimonial__content-date'><?php echo esc_html( $date_time ); ?> (raw date)</p>
			<p class='eac-testimonial__content-date'><?php echo wp_date( get_option( 'date_format' ), esc_attr( $timestamp ) ); // phpcs:ignore ?> (formated date)</p>
		<?php endif; ?>

		<?php if ( $la_note ) : ?>
			<p class='eac-testimonial__content-rating' style='color: gold;'>
				<?php echo esc_html( str_repeat( '★', $la_note ) . str_repeat( '☆', 5 - $la_note ) ); ?>
				<?php printf( ' / %d Customer reviews', esc_attr( $reviews ) ); ?>
			</p>
		<?php endif; ?>

		<?php if ( $has_url ) : ?>
			<a href='<?php echo esc_url( $has_url ); ?>'>
				<p class='eac-testimonial__content-reading'><?php echo esc_html( $link_label ); ?></p>
			</a>
		<?php endif; ?>
	</div>
</article>
<?php
<?php
...

add_action( 'init', function() {
    // Check function exists.
    if ( function_exists( 'register_eac_block') ) {
        // Register a block testimonial.
        register_eac_block( array(
			'path' => get_stylesheet_directory() . '/blocks/testimonial',
			'name' => 'eac-blocks/testimonial'
        ));

		// Register a block pricing.
        register_eac_block( array(
			'path' => get_stylesheet_directory() . '/blocks/pricing',
			'name' => 'tutorial/smart-pricing'
        ));
    } else {
			error_log( 'The "register_eac_block" function does not exist.' );
	}
}, 100 );
<?php
/**
 * Plugin Name: ACF fields to Gutenberg block
 * Description: Create a Gutenberg block using fields from an ACF group.
 * Plugin URI: https://elementor-addon-components.com/
 * Version: 1.0.0
 * Author: EAC Team
 */

add_action( 'init', function() {
    // Check function exists.
    if ( function_exists( 'register_eac_block') ) {
        // Register a block testimonial.
        register_eac_block( array(
			'path' => __DIR__ . '/blocks/testimonial',
			'name' => 'eac-blocks/testimonial'
        ));

		// Register a block pricing.
        register_eac_block( array(
			'path' => __DIR__ . '/blocks/pricing',
			'name' => 'tutorial/smart-pricing'
        ));
    } else {
			error_log( 'The "register_eac_block" function does not exist.' );
	}
}, 100 );
ACF
Field type
Block
Attribute type
Block
Control type
Colonne 4 Section
text string TextControl Donnée 4 Donnée 5
textarea string TextareaControl Donnée 4 Donnée 5
number number NumberControl Donnée 4 Donnée 5
range number RangeControl Donnée 4 Donnée 5
select string SelectControl Donnée 4 Donnée 5
true_false boolean ToggleControl Donnée 4 Donnée 5
image object MediaUpload Donnée 4 Donnée 5
url string TextControl Donnée 4 Donnée 5
date_time_picker string DateTimePicker Donnée 4 Donnée 5
page_link string SelectControl Donnée 4 Donnée 5
button_group string ToggleGroupControl Donnée 4 Donnée 5
About Achille Talon

Administrator

Achille Talon, prototype de l'antihéros (un « gros bourgeois bavard » d'après Goscinny) : quadragénaire ventripotent (93 kg2) au nez énorme et à la calvitie généreuse, bourgeois suffisant et vaniteux, célibataire (malgré ses projets de mariage avec Virgule de Guillemets, marquise de son état).

Leave a Comment