Files
display-featured-image-genesis/includes/widgets/displayfeaturedimagegenesis-author-widget.php
T

199 lines
5.3 KiB
PHP
Raw Normal View History

2015-06-07 17:03:09 -04:00
<?php
2016-04-01 20:18:20 -04:00
/**
* Class Display_Featured_Image_Genesis_Author_Widget
* @package DisplayFeaturedImageGenesis
* @author Robin Cornett <hello@robincornett.com>
* @license GPL-2.0+
2016-07-03 07:42:41 -04:00
* @link https://robincornett.com
2017-02-17 09:43:46 -05:00
* @copyright 2014-2017 Robin Cornett Creative, LLC
2016-04-01 20:18:20 -04:00
*/
2015-06-07 17:03:09 -04:00
class Display_Featured_Image_Genesis_Author_Widget extends WP_Widget {
/**
* Constructor. Set the default widget options and create widget.
*/
2017-08-09 08:05:09 -04:00
public function __construct() {
2015-06-07 17:03:09 -04:00
$widget_ops = array(
'classname' => 'author-profile',
'description' => __( 'Displays user profile block with Gravatar', 'display-featured-image-genesis' ),
'customize_selective_refresh' => true,
2015-06-07 17:03:09 -04:00
);
$control_ops = array(
'id_base' => 'featured-author',
'width' => 200,
'height' => 250,
);
parent::__construct( 'featured-author', __( 'Display Featured Author Profile', 'display-featured-image-genesis' ), $widget_ops, $control_ops );
}
2017-08-09 08:05:09 -04:00
/**
* Get the widget defaults.
*
* @return array
*/
public function defaults() {
2019-06-24 09:52:48 -04:00
return include 'fields/author-defaults.php';
2017-08-09 08:05:09 -04:00
}
2015-06-07 17:03:09 -04:00
/**
* Echo the widget content.
*
2017-08-09 08:05:09 -04:00
* @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
2015-06-07 17:03:09 -04:00
* @param array $instance The settings for the particular instance of the widget
*/
2017-08-09 08:05:09 -04:00
public function widget( $args, $instance ) {
2015-06-07 17:03:09 -04:00
// Merge with defaults
2017-08-09 08:05:09 -04:00
$instance = wp_parse_args( (array) $instance, $this->defaults() );
2015-06-07 17:03:09 -04:00
echo $args['before_widget'];
2019-06-08 15:58:15 -04:00
include plugin_dir_path( dirname( __FILE__ ) ) . 'output/class-displayfeaturedimagegenesis-output-author.php';
new DisplayFeaturedImageGenesisOutputAuthor( $instance, $args, $this->id_base );
2017-11-06 12:21:27 -05:00
echo $args['after_widget'];
}
2015-06-07 17:03:09 -04:00
/**
* Update a particular instance.
*
* This function should check that $new_instance is set correctly.
* The newly calculated value of $instance should be returned.
* If "false" is returned, the instance won't be saved/updated.
*
* @param array $new_instance New settings for this instance as input by the user via form()
* @param array $old_instance Old settings for this instance
2017-08-09 08:05:09 -04:00
*
2015-06-07 17:03:09 -04:00
* @return array Settings to save or bool false to cancel saving
*/
2017-08-09 08:05:09 -04:00
public function update( $new_instance, $old_instance ) {
2017-10-24 10:36:33 -04:00
$new_instance['user'] = (int) $new_instance['user'];
$updater = new DisplayFeaturedImageGenesisWidgetsUpdate();
2017-11-06 13:17:42 -05:00
return $updater->update( $new_instance, $old_instance, $this->get_fields( $new_instance ) );
2017-10-24 10:36:33 -04:00
}
/**
* Get all widget fields.
2017-11-06 13:17:42 -05:00
*
* @param $new_instance
*
2017-10-24 10:36:33 -04:00
* @return array
*/
2017-11-06 13:17:42 -05:00
public function get_fields( $new_instance ) {
2018-02-05 14:11:12 -05:00
$form = new DisplayFeaturedImageGenesisWidgetsForm( $this, $new_instance );
2017-10-24 10:36:33 -04:00
return array_merge(
2018-03-29 16:28:46 -04:00
include 'fields/author-image.php',
include 'fields/author-gravatar.php',
include 'fields/author-description.php',
include 'fields/author-archive.php'
2017-08-09 08:05:09 -04:00
);
2015-06-07 17:03:09 -04:00
}
/**
* Echo the settings update form.
*
* @param array $instance Current settings
*/
2017-08-09 08:05:09 -04:00
public function form( $instance ) {
2015-06-07 17:03:09 -04:00
// Merge with defaults
2017-08-09 08:05:09 -04:00
$instance = wp_parse_args( (array) $instance, $this->defaults() );
2018-02-05 14:11:12 -05:00
$form = new DisplayFeaturedImageGenesisWidgetsForm( $this, $instance );
2017-05-18 22:01:20 -04:00
$form->do_text( $instance, array(
'id' => 'title',
'label' => __( 'Title:', 'display-featured-image-genesis' ),
'class' => 'widefat',
) );
$form->do_select( $instance, array(
'id' => 'user',
'label' => __( 'Select a user. The email address for this account will be used to pull the Gravatar image.', 'display-featured-image-genesis' ),
'flex' => true,
'choices' => $this->get_users(),
) );
$form->do_boxes( array(
2018-03-29 16:28:46 -04:00
'author' => include 'fields/author-image.php',
2017-08-09 08:05:09 -04:00
), 'genesis-widget-column-box-top' );
$form->do_boxes( array(
2018-03-29 16:28:46 -04:00
'gravatar' => include 'fields/author-gravatar.php',
2017-08-09 08:05:09 -04:00
) );
$form->do_boxes( array(
2018-03-29 16:28:46 -04:00
'description' => include 'fields/author-description.php',
2017-08-09 08:05:09 -04:00
) );
$form->do_boxes( array(
2018-03-29 16:28:46 -04:00
'archive' => include 'fields/author-archive.php',
2017-08-09 08:05:09 -04:00
) );
}
2017-05-18 22:01:20 -04:00
/**
2017-08-09 08:05:09 -04:00
* Get the authors on the site.
*
2017-05-18 22:01:20 -04:00
* @return array
*/
protected function get_users() {
$users = get_users( array(
'who' => 'authors',
) );
$options = array();
foreach ( $users as $user ) {
$options[ $user->ID ] = $user->data->display_name;
}
return $options;
}
2015-06-07 17:03:09 -04:00
2017-05-18 22:01:20 -04:00
/**
2017-08-09 08:05:09 -04:00
* Get gravatar sizes.
*
2017-05-18 22:01:20 -04:00
* @return array
*/
protected function get_gravatar_sizes() {
$sizes = apply_filters( 'genesis_gravatar_sizes', array(
__( 'Small', 'display-featured-image-genesis' ) => 45,
__( 'Medium', 'display-featured-image-genesis' ) => 65,
__( 'Large', 'display-featured-image-genesis' ) => 85,
__( 'Extra Large', 'display-featured-image-genesis' ) => 125,
) );
$options = array();
foreach ( (array) $sizes as $label => $size ) {
$options[ $size ] = $label;
}
return $options;
2015-06-07 17:03:09 -04:00
}
2017-05-18 22:01:20 -04:00
/**
2017-08-09 08:05:09 -04:00
* Get the pages on the site.
*
2017-05-18 22:01:20 -04:00
* @return array
*/
protected function get_pages() {
$page_ids = get_pages( array(
'post_type' => 'page',
) );
$pages = array();
if ( $page_ids ) {
$pages[] = __( 'None', 'display-featured-image-genesis' );
foreach ( $page_ids as $id ) {
$title = empty( $id->post_title ) ? '#' . $id->ID . __( ' (no title)', 'sixtenpress-featured-content' ) : $id->post_title;
$pages[ $id->ID ] = $title;
}
}
return $pages;
}
2015-06-07 17:03:09 -04:00
}