WordPress.org

Ready to get started?Download WordPress

Forums

WP-Table Reloaded
Customize table info's last modified date via filter? (4 posts)

  1. scripty
    Member
    Posted 2 years ago #

    I'm trying to customize the last-modified date display - but I just don't understand how to use the filters. I'm assuming I'd use this one: wp_table_reloaded_shortcode_table_overwrite ( false, $atts ) (boolean|string)
    but after that I get stuck :)
    I tried this:

    add_filter('wp_table_reloaded_shortcode_table_info_overwrite', 'fix_table_date_display');
    function fix_table_date_display($atts) {
    	return print_r($atts,true);
    }

    (returning the $atts array just to see what I had to work with - but it has no affect)

    http://wordpress.org/extend/plugins/wp-table-reloaded/

  2. TobiasBg
    Member
    Plugin Author

    Posted 2 years ago #

    Hi,

    sorry for the late answer.

    Ok, I can see what you are trying to achieve. And after checking the code, I have to say that this is not easily possible at the moment...
    I should however be able to make a small change in the plugin to allow this.

    For that, can you maybe explain how exactly (e.g. to what format) you want to change the last modified date when it is displayed?

    Thanks!
    Tobias

  3. scripty
    Member
    Posted 2 years ago #

    Ideally - it would be great if it was flexible (ie. enter in a php date format like: 'n/j/y') - but for the specific use I wanted this for, a date format like this: 10/31/11

    Thanks for your reply! (And thank you for the wp-table-reloaded plugin! It's a great piece of work!!)

  4. TobiasBg
    Member
    Plugin Author

    Posted 2 years ago #

    Hi,

    ok, in that case, the following process should be the best.

    At first, you'll need to make a modification to WP-Table Reloaded. I will also add this to all future versions (as it is actually something that should already have been there, I just must have forgotten it), so that you won't have to do this again in the future, but only for WP-Table Reloaded 1.9.2.
    That is: Open the file "controller-frontend.php" in the "controllers" subfolder and in line 148, before the

    return $output;

    add the line

    $output = apply_filters( 'wp_table_reloaded_shortcode_table_info_output', $output, $atts );

    That will add the filter that you need, which however was not yet in place...

    After that, you can use the filter to modify the behavior of the Shortcode [table-info ... field="last-modified" /].
    At first, you will need to add the additional parameter format="raw", to make it easier to determine the date format later on. So, as the new Shortcode, use

    [table-info id=123 field="last-modified" format="raw" /]

    Now, to actually filter the date, paste the following code into the "functions.php" of your theme.

    add_filter( 'wp_table_reloaded_shortcode_table_info_output', 'wp_table_reloaded_change_last_modified_date', 10, 2 );
    function wp_table_reloaded_change_last_modified_date( $content, $atts ) {
    // only modify calls to the last modified date
    if ( 'last-modified' != $atts['field'] )
        return $content;
    
    // $content now contains the raw datetime string
    // manipulate as desired here, e.g. with PHP functions strtotime(), date(), etc.:
    // $content = ...;
    
    return $content;
    }

    At the position of the comment, you can use PHP to modify the date (in the $content variable) to whatever you want, using the appropriate PHP functions. The best way probably is to transform the string back to a timestamp and then apply a new date output format to that.

    Best wishes,
    Tobias

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic