mirror of
https://github.com/10h30/display-featured-image-genesis.git
synced 2026-07-11 18:46:03 +09:00
Add featured image column for authors
Also refactored for a reusable image function.
This commit is contained in:
@@ -19,6 +19,7 @@ class Display_Featured_Image_Genesis_Admin {
|
||||
$this->common = new Display_Featured_Image_Genesis_Common();
|
||||
$this->set_up_taxonomy_columns();
|
||||
$this->set_up_post_type_columns();
|
||||
$this->set_up_author_columns();
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'featured_image_column_width' ) );
|
||||
}
|
||||
@@ -63,6 +64,16 @@ class Display_Featured_Image_Genesis_Admin {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up featured image column for users
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
protected function set_up_author_columns() {
|
||||
add_filter( 'manage_users_columns', array( $this, 'add_column' ) );
|
||||
add_action( 'manage_users_custom_column', array( $this, 'manage_user_column' ), 10, 3 );
|
||||
}
|
||||
|
||||
/**
|
||||
* add featured image column
|
||||
* @param column $columns set up new column to show featured image for taxonomies/posts/etc.
|
||||
@@ -103,19 +114,14 @@ class Display_Featured_Image_Genesis_Admin {
|
||||
|
||||
$taxonomy = filter_input( INPUT_POST, 'taxonomy', FILTER_SANITIZE_STRING );
|
||||
$taxonomy = ! is_null( $taxonomy ) ? $taxonomy : get_current_screen()->taxonomy;
|
||||
$alt = get_term( $term_id, $taxonomy )->name;
|
||||
$id = is_numeric( $term_meta['term_image'] ) ? $term_meta['term_image'] : Display_Featured_Image_Genesis_Common::get_image_id( $term_meta['term_image'] );
|
||||
|
||||
$preview = apply_filters(
|
||||
'display_featured_image_genesis_admin_term_thumbnail',
|
||||
wp_get_attachment_image_src( $id, 'thumbnail' ),
|
||||
$id
|
||||
$args = array(
|
||||
'image_id' => is_numeric( $term_meta['term_image'] ) ? $term_meta['term_image'] : Display_Featured_Image_Genesis_Common::get_image_id( $term_meta['term_image'] ),
|
||||
'context' => 'term',
|
||||
'alt' => get_term( $term_id, $taxonomy )->name,
|
||||
);
|
||||
|
||||
printf( '<img src="%1$s" alt="%2$s" />',
|
||||
esc_url( $preview[0] ),
|
||||
esc_attr( $alt )
|
||||
);
|
||||
echo wp_kses_post( $this->admin_featured_image( $args ) );
|
||||
|
||||
}
|
||||
|
||||
@@ -132,22 +138,19 @@ class Display_Featured_Image_Genesis_Admin {
|
||||
if ( 'featured_image' !== $column ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$id = get_post_thumbnail_id( $post_id );
|
||||
if ( ! $id ) {
|
||||
$image_id = get_post_thumbnail_id( $post_id );
|
||||
if ( ! $image_id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$preview = apply_filters(
|
||||
'display_featured_image_genesis_admin_post_thumbnail',
|
||||
wp_get_attachment_image_src( $id, 'thumbnail' ),
|
||||
$id
|
||||
);
|
||||
printf( '<img src="%1$s" alt="%2$s" />',
|
||||
esc_url( $preview[0] ),
|
||||
esc_attr( the_title_attribute( 'echo=0' ) )
|
||||
$args = array(
|
||||
'image_id' => $image_id,
|
||||
'context' => 'post',
|
||||
'alt' => the_title_attribute( 'echo=0' ),
|
||||
);
|
||||
|
||||
echo wp_kses_post( $this->admin_featured_image( $args ) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,7 +159,7 @@ class Display_Featured_Image_Genesis_Admin {
|
||||
*/
|
||||
public function featured_image_column_width() {
|
||||
$screen = get_current_screen();
|
||||
if ( in_array( $screen->base, array( 'edit', 'edit-tags' ) ) ) { ?>
|
||||
if ( in_array( $screen->base, array( 'edit', 'edit-tags', 'users' ) ) ) { ?>
|
||||
<style type="text/css">
|
||||
.column-featured_image { width: 105px; }
|
||||
.column-featured_image img { margin: 0 auto; display: block; height: auto; width: auto; max-width: 60px; max-height: 80px; }
|
||||
@@ -165,4 +168,49 @@ class Display_Featured_Image_Genesis_Admin {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* User column output
|
||||
* @param string $value image to be output to column
|
||||
* @param string $column_name column name (featured_image)
|
||||
* @param int $user_id user id
|
||||
* @return string image
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public function manage_user_column( $value, $column_name, $user_id ) {
|
||||
if ( 'featured_image' !== $column_name ) {
|
||||
return;
|
||||
}
|
||||
$image_id = get_the_author_meta( 'displayfeaturedimagegenesis', (int) $user_id );
|
||||
if ( ! $image_id ) {
|
||||
return;
|
||||
}
|
||||
$args = array(
|
||||
'image_id' => $image_id,
|
||||
'context' => 'author',
|
||||
'alt' => get_the_author_meta( 'user_nicename', (int) $user_id ),
|
||||
);
|
||||
|
||||
return $this->admin_featured_image( $args );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic function to return featured image
|
||||
* @param array $args array of values to pass to function ( image_id, context, alt_tag )
|
||||
* @return string image html
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
protected function admin_featured_image( $args ) {
|
||||
if ( ! $args['image_id'] ) {
|
||||
return;
|
||||
}
|
||||
apply_filters( "display_featured_image_genesis_admin_{$args['context']}_thumbnail", $args );
|
||||
|
||||
$preview = wp_get_attachment_image_src( $args['image_id'], 'thumbnail' );
|
||||
return sprintf( '<img src="%1$s" alt="%2$s" />', esc_url( $preview[0] ), esc_attr( $args['alt'] ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user