Files

135 lines
3.0 KiB
PHP
Raw Permalink Normal View History

2019-06-24 11:15:32 -04:00
<?php
2019-06-25 12:37:40 -04:00
/**
* Class DisplayFeaturedImageGenesisWidgetsBlocksOutput
*/
2019-06-24 11:15:32 -04:00
class DisplayFeaturedImageGenesisWidgetsBlocksOutput {
2019-06-25 12:37:40 -04:00
/**
* @var string
*/
2019-06-26 08:47:10 -04:00
private $block = 'displayfeaturedimagegenesis';
2019-06-24 11:15:32 -04:00
/**
* Render the widget in a container div.
*
* @param $atts
*
* @return string
*/
public function render_cpt( $atts ) {
2019-06-26 08:46:43 -04:00
$block_id = 'cpt';
$atts = $this->update_attributes( $atts, $block_id );
2019-06-24 11:15:32 -04:00
$post_type = get_post_type_object( $atts['post_type'] );
if ( ! $post_type ) {
return '';
}
2019-06-26 08:47:26 -04:00
$classes = $this->get_block_classes( $atts, $block_id );
2019-06-26 08:58:38 -04:00
$this->include_output_file( $block_id );
2019-06-24 11:15:32 -04:00
ob_start();
2019-06-26 08:47:26 -04:00
echo '<div class="' . esc_attr( $classes ) . '">';
2019-06-24 11:15:32 -04:00
new DisplayFeaturedImageGenesisOutputCPT( $atts, array(), $post_type );
2019-06-26 08:47:26 -04:00
echo '</div>';
$output = ob_get_contents();
2019-06-24 11:15:32 -04:00
ob_clean();
return $output;
}
/**
* @param $atts
*
* @return string
*/
public function render_author( $atts ) {
2019-06-26 08:46:43 -04:00
$block_id = 'author';
$atts = $this->update_attributes( $atts, $block_id );
2019-06-26 08:58:16 -04:00
if ( empty( $atts['user'] ) ) {
return '';
}
$classes = $this->get_block_classes( $atts, $block_id );
2019-06-26 08:58:38 -04:00
$this->include_output_file( $block_id );
2019-06-24 11:15:32 -04:00
ob_start();
2019-06-26 08:47:26 -04:00
echo '<div class="' . esc_attr( $classes ) . '">';
2019-06-24 11:15:32 -04:00
new DisplayFeaturedImageGenesisOutputAuthor( $atts, array() );
2019-06-26 08:47:26 -04:00
$output = ob_get_contents();
echo '</div>';
2019-06-24 11:15:32 -04:00
ob_clean();
return $output;
}
2019-06-25 12:37:40 -04:00
/**
* @param $atts
*
* @return string
*/
public function render_term( $atts ) {
2019-06-26 08:46:43 -04:00
$block_id = 'term';
$atts = $this->update_attributes( $atts, $block_id );
2019-06-26 08:47:26 -04:00
$term = get_term_by( 'id', $atts['term'], $atts['taxonomy'] );
2019-06-25 12:37:40 -04:00
if ( ! $term ) {
return '';
}
2019-06-26 08:47:26 -04:00
$classes = $this->get_block_classes( $atts, $block_id );
2019-06-26 08:58:38 -04:00
$this->include_output_file( $block_id );
2019-06-25 12:37:40 -04:00
ob_start();
2019-06-26 08:47:26 -04:00
echo '<div class="' . esc_attr( $classes ) . '">';
2019-06-25 12:37:40 -04:00
new DisplayFeaturedImageGenesisOutputTerm( $atts, array(), $term );
2019-06-26 08:47:26 -04:00
echo '</div>';
$output = ob_get_contents();
2019-06-25 12:37:40 -04:00
ob_clean();
return $output;
}
2019-06-26 08:46:43 -04:00
/**
* Update the block attributes by merging with defaults.
*
* @param $atts
* @param $block_id
*
* @return array
*/
private function update_attributes( $atts, $block_id ) {
return wp_parse_args( $atts, include "fields/{$block_id}-defaults.php" );
}
2019-06-24 11:15:32 -04:00
/**
* Get the CSS classes for the block.
*
* @param $atts
* @param $block_id
*
* @return string
*/
private function get_block_classes( $atts, $block_id ) {
$classes = array(
2019-06-26 08:47:10 -04:00
"wp-block-{$this->block}-{$block_id}",
2019-06-24 11:15:32 -04:00
);
if ( ! empty( $atts['className'] ) ) {
$classes[] = $atts['className'];
}
if ( ! empty( $atts['blockAlignment'] ) ) {
$classes[] = 'align' . $atts['blockAlignment'];
}
2019-10-24 17:07:15 -04:00
if ( ! empty( $atts['alignment'] ) ) {
$classes[] = 'has-text-align-' . $atts['alignment'];
}
2019-06-24 11:15:32 -04:00
return implode( ' ', $classes );
}
2019-06-26 08:58:38 -04:00
/**
* Load the block output file.
*
* @param $block_id
*/
private function include_output_file( $block_id ) {
include_once plugin_dir_path( dirname( __FILE__ ) ) . "output/class-displayfeaturedimagegenesis-output-{$block_id}.php";
}
2019-06-24 11:15:32 -04:00
}