2017-10-24 10:36:33 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class DisplayFeaturedImageGenesisWidgetsShortcodes
|
|
|
|
|
*/
|
|
|
|
|
class DisplayFeaturedImageGenesisWidgetsShortcodes {
|
|
|
|
|
|
|
|
|
|
/**
|
2017-10-24 18:04:55 -04:00
|
|
|
* Build the featured author widget shortcode.
|
|
|
|
|
*
|
2017-10-24 10:36:33 -04:00
|
|
|
* @param $atts
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function shortcode_author( $atts ) {
|
2019-06-26 13:17:51 -04:00
|
|
|
return $this->build_shortcode( $atts, 'displayfeaturedimagegenesis_author', 'Display_Featured_Image_Genesis_Author_Widget', 'author' );
|
2017-10-24 10:36:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-10-24 18:04:55 -04:00
|
|
|
* Build the featured post type widget shortcode.
|
|
|
|
|
*
|
2017-10-24 10:36:33 -04:00
|
|
|
* @param $atts
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function shortcode_post_type( $atts ) {
|
2019-06-26 13:17:51 -04:00
|
|
|
return $this->build_shortcode( $atts, 'displayfeaturedimagegenesis_post_type', 'Display_Featured_Image_Genesis_Widget_CPT', 'cpt' );
|
2017-10-24 10:36:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-10-24 18:04:55 -04:00
|
|
|
* Build the featured term widget shortcode.
|
|
|
|
|
*
|
2017-10-24 10:36:33 -04:00
|
|
|
* @param $atts
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function shortcode_term( $atts ) {
|
2019-06-26 13:17:51 -04:00
|
|
|
return $this->build_shortcode( $atts, 'displayfeaturedimagegenesis_term', 'Display_Featured_Image_Genesis_Widget_Taxonomy', 'term' );
|
2017-10-24 10:36:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-03-28 20:00:26 -04:00
|
|
|
* Helper function to build and return the shortcode.
|
2017-11-02 09:20:02 -04:00
|
|
|
*
|
2018-03-28 20:00:26 -04:00
|
|
|
* @param $atts
|
2017-10-24 18:04:55 -04:00
|
|
|
* @param $shortcode
|
2018-03-28 20:00:26 -04:00
|
|
|
* @param $class
|
2017-10-24 18:04:55 -04:00
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2019-06-26 13:17:51 -04:00
|
|
|
protected function build_shortcode( $atts, $shortcode, $class, $id ) {
|
|
|
|
|
$defaults = $this->get_defaults( $id );
|
2018-03-28 20:00:26 -04:00
|
|
|
$atts = shortcode_atts( $defaults, $atts, $shortcode );
|
|
|
|
|
$atts = $this->validate_shortcode( $atts, $class );
|
2017-11-06 12:20:58 -05:00
|
|
|
|
2018-03-28 20:00:26 -04:00
|
|
|
return $this->do_shortcode( $atts, $class );
|
2017-10-24 18:04:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the widget defaults.
|
|
|
|
|
*
|
2017-10-24 10:36:33 -04:00
|
|
|
* @param $class
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2019-06-26 13:17:51 -04:00
|
|
|
protected function get_defaults( $id ) {
|
|
|
|
|
return include "fields/{$id}-defaults.php";
|
2017-10-24 10:36:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-10-24 18:04:55 -04:00
|
|
|
* Return the shortcode output.
|
2017-11-02 09:20:02 -04:00
|
|
|
*
|
2017-10-24 10:36:33 -04:00
|
|
|
* @param $atts
|
|
|
|
|
* @param $class
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
protected function do_shortcode( $atts, $class ) {
|
|
|
|
|
$args = array(
|
|
|
|
|
'id' => 'displayfeaturedimagegenesis-shortcode',
|
|
|
|
|
);
|
|
|
|
|
ob_start();
|
|
|
|
|
the_widget( $class, $atts, $args );
|
|
|
|
|
$output = ob_get_clean();
|
|
|
|
|
|
|
|
|
|
return do_shortcode( trim( $output ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-10-24 18:04:55 -04:00
|
|
|
* Validate the shortcode.
|
|
|
|
|
*
|
2017-10-24 10:36:33 -04:00
|
|
|
* @param $atts
|
|
|
|
|
* @param $class
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
protected function validate_shortcode( $atts, $class ) {
|
|
|
|
|
$fields = new $class();
|
2019-06-26 13:18:04 -04:00
|
|
|
$update = new DisplayFeaturedImageGenesisWidgetsUpdate();
|
2017-10-24 10:36:33 -04:00
|
|
|
|
2019-06-26 13:18:04 -04:00
|
|
|
return $update->update( $atts, array(), $fields->get_fields( $atts ) );
|
2017-10-24 10:36:33 -04:00
|
|
|
}
|
|
|
|
|
}
|