Community Forums › Forums › Archived Forums › General Discussion › Suggestion to change Genesis source code
- This topic has 1 reply, 2 voices, and was last updated 9 years, 4 months ago by Davinder Singh Kainth.
-
AuthorPosts
-
December 13, 2014 at 2:22 am #134449CarloMember
This concerns Genesis 2.1.2
The function I don't like is
genesis_get_image
ingenesis/functions/image.php
.I want to set a default fallback image to display if there is no post thumbnail. As it is, the way the function allows me to do that is with the
genesis_get_image_default_args
filter. See lines 78–83 ofgenesis/functions/image.php
:/** * A filter on the default parameters used by <code>genesis_get_image()</code>. * * @since unknown */ $defaults = apply_filters( 'genesis_get_image_default_args', $defaults, $args );
The default arg I need to filter is
fallback
, which must be an array containing the complete HTML for the image, as well as its URL. See lines 104–109 ofgenesis/functions/image.php
://* Else if fallback array exists elseif ( is_array( $args['fallback'] ) ) { $id = 0; $html = $args['fallback']['html']; $url = $args['fallback']['url']; }
Then my filter will look like this:
//* Set default post thumbnail add_filter( 'genesis_get_image_default_args', function( $defaults, $args ) { $defaults[ 'fallback' ] = array(); $defaults[ 'fallback' ][ 'html' ] = wp_get_attachment_image( DEFAULT_IMAGE_ID, $args[ 'size' ], false, $args[ 'attr' ] ); list( $defaults[ 'fallback' ][ 'url' ] ) = wp_get_attachment_image_src( DEFAULT_IMAGE_ID, $args[ 'size' ], false, $args[ 'attr' ] ); return $defaults; }, 10, 2 );
My gripe about supplying an array with HTML and URL is that I have to hard-code the calls to
wp_get_attachment_image
andwp_get_attachment_image_src
. I would rather supply an attachment id for the default post image, and have Genesis handle the calls towp_get_attachment_image
andwp_get_attachment_image_src
in case things change in a future version.So the filter I would like to be able to write is as follows:
//* Set default post thumbnail add_filter( 'genesis_get_image_default_args', function( $defaults ) { $defaults[ 'fallback' ] = DEFAULT_IMAGE_ID; return $defaults; } );
And below is my proposed change to the function
genesis_get_image
. It basically allows the fallback arg to be the id of an attachment, while still retaining backward compatibility for the array format. This replaces lines 92–113 ofgenesis/functions/image.php
://* If post thumbnail (native WP) exists, use its id if ( has_post_thumbnail( $args['post_id'] ) && ( 0 === $args['num'] ) ) { $id = get_post_thumbnail_id( $args['post_id'] ); } //* Else if the first (default) image attachment is the fallback, use its id elseif ( 'first-attached' === $args['fallback'] ) { $id = genesis_get_image_id( $args['num'], $args['post_id'] ); } //* Else if fallback id is supplied, use it elseif ( is_int( $args['fallback'] ) ) { $id = $args['fallback']; } //* If we have an id, get the html and url if ( isset( $id ) ) { $html = wp_get_attachment_image( $id, $args['size'], false, $args['attr'] ); list( $url ) = wp_get_attachment_image_src( $id, $args['size'], false, $args['attr'] ); } //* Else if fallback html and url exist, use them elseif ( is_array( $args['fallback'] ) ) { $html = $args['fallback']['html']; $url = $args['fallback']['url']; } //* Else, return false (no image) else { return false; }
As far as I know, Genesis does not actively encourage developers to submit suggested source code changes like WordPress does, but I think the above change makes a lot of sense and I would like to have it considered for inclusion.
December 14, 2014 at 8:51 am #134505Davinder Singh KainthMemberBest would be contact studiopress team - http://www.studiopress.com/contact
Or reach Brian Gardner directly here - http://www.studiopress.com/contact or on his Twitter profile.
Sunshine PRO genesis theme
Need Genesis help? Davinder @ iGuiding Media | My Blog | Fresh Genesis Themes -
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.