__( 'Author box widget for the sidebar', 'anissa' ),
)
);
}
private function showSocialIfSet( $instance, $authorId, $property )
{
return !empty( $instance['social_' . $property . '-' . $authorId] ) ? '
' : '';
}
/**
* Front-end display of widget.
*
* @see WP_Widget::widget()
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
public function widget( $args, $instance )
{
global $post;
if ( empty( $post ) ) return;
if ( is_single() || is_page() ) {
$authorId = $post->post_author;
} else {
$authorId = get_user_by( 'email', get_bloginfo( 'admin_email' ) )->ID;
}
echo '';
}
/**
* Sanitize widget form values as they are saved.
*
* @see WP_Widget::update()
*
* @param array $new_instance Values just sent to be saved.
* @param array $old_instance Previously saved values from database.
*
* @return array Updated safe values to be saved.
*/
public function update( $new_instance, $old_instance )
{
$userId = (int)$new_instance['author'];
$instance = array();
$fields = array(
'title' => 'sanitize_text_field',
'textbox' => 'strip_tags',
'image_url' => 'esc_url',
'social_twitter' => 'esc_url',
'social_facebook' => 'esc_url',
'social_dribbble' => 'esc_url',
'social_pinterest' => 'esc_url',
'social_linkedin' => 'esc_url',
'social_drupal' => 'esc_url',
'social_wordpress' => 'esc_url',
'social_y-combinator' => 'esc_url',
'social_google-plus' => 'esc_url',
'social_behance' => 'esc_url',
'social_flickr' => 'esc_url',
'social_500px' => 'esc_url',
'social_reddit' => 'esc_url',
'social_youtube' => 'esc_url',
'social_soundcloud' => 'esc_url',
'social_medium' => 'esc_url',
);
foreach ( $fields as $field => $sanitization ) {
$field .= '-' . $userId;
if ( $sanitization === 'strip_tags' ) {
$instance[$field] = $sanitization( $new_instance[$field], '
' );
} else {
$instance[$field] = $sanitization( $new_instance[$field] );
}
};
return array_merge( $new_instance, $instance );
}
/**
* Back-end widget form.
*
* @see WP_Widget::form()
*
* @param array $instance Previously saved values from database.
*/
public function form( $instance )
{
echo '';
}
}
// init the widget
function anissa_register_author_box_widget()
{
register_widget( 'anissa_Author_Box_Widget' );
}
add_action( 'widgets_init', 'anissa_register_author_box_widget' );
// queue up the necessary js
function anissa_author_box_widget_script_enqueue()
{
wp_enqueue_style( 'thickbox' );
wp_enqueue_script( 'media-upload' );
wp_enqueue_script( 'thickbox' );
wp_enqueue_script( 'anissa_author_box_widget_js', get_template_directory_uri() . '/js/widget-author-box.js', null, null, true );
}
add_action( 'admin_enqueue_scripts', 'anissa_author_box_widget_script_enqueue' );