Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    I don’t really think that this will be possible. TablePress is not making any assumptions about the content that someone puts into a table cell, i.e. it doesn’t actually know if there’s HTML or an image in a cell. It treats image HTML in the same way as WordPress does it in posts or pages, after they have been inserted.
    I do however have plans for a “Search and Replace” Extension which should make it easier in the future to e.g. search/replace URLs in tables.

    Regards,
    Tobias

    Thread Starter mayrrecordscan

    (@mayrrecordscan)

    if someone also likes clean id references, here we go. ??
    you can add an image with the known shortcode sheme:

    [image id="2167"]

    then add to your theme controller (e.g. functions.php):

    add_filter('tablepress_cell_content', 'tablepress_update_image_ids', 10, 4);
    
    function tablepress_update_image_ids( $cell_content, $tableID, $row_idx, $col_idx ) {
    
    	return preg_replace_callback('/\[image id=\"(.*?)".*\]/', '__tablepress_set_image_attachment', $cell_content);
    
    }
    
    function __tablepress_set_image_attachment( $matches ) {
    
    	$attachmentID = (int) $matches[1];
    	$image = wp_get_attachment_image( $attachmentID, 'thumbnail');
    
    	if( empty( $image ) )
    		return FALSE;
    
    	return $image;
    
    }
    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    that’s a nice solution, indeed! Thanks for sharing it!

    If you use the WordPress Shortcode API, you could make this a little bit more robust, and it would also work in regular posts and pages:

    add_shortcode( 'image', 'mayrrecordscan_image_shortcode' );
    function mayrrecordscan_image_shortcode( $atts ) {
      $attachmentID = (int) $atts['id'];
      $image = wp_get_attachment_image( $attachmentID, 'thumbnail' );
      if ( empty( $image ) ) {
        return '';
      }
      return $image;
    }

    Regards,
    Tobias

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hardcoded Image Urls’ is closed to new replies.