-
-
Save billerickson/1ce9a2f0dd536c9247cf5dd64bdbe7fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Advanced Custom Fields | |
* | |
* @package KatieWorkman2020 | |
* @author Bill Erickson | |
* @since 1.0.0 | |
* @license GPL-2.0+ | |
**/ | |
class BE_ACF_Customizations { | |
public function __construct() { | |
// Register options page | |
add_action( 'init', array( $this, 'register_options_page' ) ); | |
// Register Blocks | |
add_action('acf/init', array( $this, 'register_blocks' ) ); | |
} | |
/** | |
* Register Options Page | |
* | |
*/ | |
function register_options_page() { | |
if ( function_exists( 'acf_add_options_page' ) ) { | |
acf_add_options_page( array( | |
'title' => __( 'Site Options', 'katieworkman2020' ), | |
'capability' => 'manage_options', | |
) ); | |
} | |
} | |
/** | |
* Register Blocks | |
* @link https://www.billerickson.net/building-gutenberg-block-acf/#register-block | |
* | |
* Categories: common, formatting, layout, widgets, embed | |
* Dashicons: https://developer.wordpress.org/resource/dashicons/ | |
* ACF Settings: https://www.advancedcustomfields.com/resources/acf_register_block/ | |
*/ | |
function register_blocks() { | |
if( ! function_exists('acf_register_block_type') ) | |
return; | |
acf_register_block_type( array( | |
'name' => 'testimonial', | |
'title' => __( 'Testimonial', 'katieworkman2020' ), | |
'description' => __( 'Displays one testimonial. Manage testimonials in Site Options', 'katieworkman2020' ), | |
'render_template' => 'partials/block-testimonial.php', | |
'category' => 'widgets', | |
'icon' => 'editor-quote', | |
'mode' => 'preview', | |
'keywords' => array( 'quote' ), | |
)); | |
} | |
} | |
new BE_ACF_Customizations(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Testimonial block | |
* | |
* @package KatieWorkman2020 | |
* @author Bill Erickson | |
* @since 1.0.0 | |
* @license GPL-2.0+ | |
**/ | |
$testimonials = get_field( 'ea_testimonials', 'option' ); | |
if( empty( $testimonials ) ) | |
return; | |
$testimonial = $testimonials[ array_rand( $testimonials ) ]; | |
echo '<blockquote class="is-style-testimonial">' . wpautop( $testimonial['quote'] ); | |
if( !empty( $testimonial['byline'] ) ) | |
echo ' <cite>' . $testimonial['byline']; | |
echo '</blockquote>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment