Add link upload image when URL is empty
-
Hi,
yours is a great plugin. But I wanted to tell you that it does not give the possibility to upload the image, if the variable $ thumb_url is empty despite WP signals true with has_post_thumbnail. This happens when, for example, you import a post with attachments and cannot find the attachment.
There is a way to add the button:Nel file featured-image-admin-thumb-fiat/admin/class-featured-image-admin-thumb-admin.php si potrebbe fare la seguente modifica:
public function fiat_custom_columns( $column, $post_id ) { switch ( $column ) { case 'thumb': if ( has_post_thumbnail( $post_id ) ) { // Determine if our image size has been created and use // that size/attribute combination // else get the post-thumbnail image and apply custom sizing to // size it to fit in the admin dashboard $sizes = ''; $thumbnail_id = get_post_thumbnail_id( $post_id ); $tpm = wp_get_attachment_metadata( $thumbnail_id ); if ( false !== $tpm && ! empty( $tpm ) ) { $sizes = $tpm['sizes']; } // Default to thumbnail size (as this will be sized down reducing the bandwidth until the image thumbnail is regenerated) $fiat_image_size = 'thumbnail'; // Review the sizes this particular image has been set to if ( is_array( $sizes ) ) { foreach ( $sizes as $s => $k ) { if ( $this->fiat_image_size === $s ) { // our size is present, set it and break out $fiat_image_size = $this->fiat_image_size; break; } } } /** * Check if WooCommerce is active * If so, only return anchor link markup to inline edit thumbnail * WooCommerce will supply the image markup **/ if ( $this->fiat_on_woocommerce_products_list() ) { $thumb_url = ''; } else { if ( 'thumbnail' === $fiat_image_size ) { // size down this time $thumb_url = wp_get_attachment_image( $thumbnail_id, array( 60, 60 ) ); } else { // use native sized image $thumb_url = get_image_tag( $thumbnail_id, '', '', '', $fiat_image_size ); } } // Here it is! $this->fiat_nonce = wp_create_nonce( 'set_post_thumbnail-' . $post_id ); if( $thumb_url === '' ) { $this->fiat_nonce = wp_create_nonce( 'set_post_thumbnail-' . $post_id ); $set_featured_image = sprintf( __( 'Set %s featured image', 'featured-image-admin-thumb-fiat' ), '<br/>' ); $set_edit_markup = $this->fiat_on_woocommerce_products_list() ? '' : $set_featured_image; $html = sprintf( $this->template_html, admin_url( 'media-upload.php?post_id=' . $post_id . '&type=image&TB_iframe=1&_wpnonce=' . $this->fiat_nonce ), $set_edit_markup, $post_id ); // Click me! echo wp_kses( $html, $this->fiat_kses ); } else { $html = sprintf( $this->template_html, admin_url( 'media-upload.php?post_id=' . $post_id . '&type=image&TB_iframe=1&_wpnonce=' . $this->fiat_nonce ), $thumb_url, $thumbnail_id ); // Click me to change! echo wp_kses( $html, $this->fiat_kses ); } } else { $this->fiat_nonce = wp_create_nonce( 'set_post_thumbnail-' . $post_id ); $set_featured_image = sprintf( __( 'Set %s featured image', 'featured-image-admin-thumb-fiat' ), '<br/>' ); $set_edit_markup = $this->fiat_on_woocommerce_products_list() ? '' : $set_featured_image; $html = sprintf( $this->template_html, admin_url( 'media-upload.php?post_id=' . $post_id . '&type=image&TB_iframe=1&_wpnonce=' . $this->fiat_nonce ), $set_edit_markup, $post_id ); // Click me! echo wp_kses( $html, $this->fiat_kses ); } break; } }
I extended the class to make the change.
But it would clearly be appropriate to make the change natively. 🙂
- The topic ‘Add link upload image when URL is empty’ is closed to new replies.