最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How can I add "last updated" in plugin descripton?

programmeradmin0浏览0评论

I'm trying to add Last updated option in to the plugin description section. I've tried to use a code of one old plugin which still works, but I don't like the date format of last update.

function range_plu_plugin_meta( $plugin_meta, $plugin_file ) {
    list( $slug ) = explode( '/', $plugin_file );


    $slug_hash = md5( $slug );
    $last_updated = get_transient( "range_plu_{$slug_hash}" );
    if ( false === $last_updated ) {
        $last_updated = range_plu_get_last_updated( $slug );
        set_transient( "range_plu_{$slug_hash}", $last_updated, 86400 );
    }

    if ( $last_updated )
        $plugin_meta['last_updated'] = 'Last Updated: ' . esc_html( $last_updated );

    return $plugin_meta;
}

It would be nice to have different format like on the Wordpress page saying: Last updated: 3 months ago

That way user will be aware if plugin is still maintained - or in the future there will be a warning if plugin hasn't been updated more that 6 months (that's just an example).

I'm trying to add Last updated option in to the plugin description section. I've tried to use a code of one old plugin which still works, but I don't like the date format of last update.

function range_plu_plugin_meta( $plugin_meta, $plugin_file ) {
    list( $slug ) = explode( '/', $plugin_file );


    $slug_hash = md5( $slug );
    $last_updated = get_transient( "range_plu_{$slug_hash}" );
    if ( false === $last_updated ) {
        $last_updated = range_plu_get_last_updated( $slug );
        set_transient( "range_plu_{$slug_hash}", $last_updated, 86400 );
    }

    if ( $last_updated )
        $plugin_meta['last_updated'] = 'Last Updated: ' . esc_html( $last_updated );

    return $plugin_meta;
}

It would be nice to have different format like on the Wordpress page saying: Last updated: 3 months ago

That way user will be aware if plugin is still maintained - or in the future there will be a warning if plugin hasn't been updated more that 6 months (that's just an example).

Share Improve this question asked Feb 20, 2020 at 7:11 mirsadmirsad 5571 gold badge4 silver badges8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Use this code instead:

function range_plu_plugin_meta( $plugin_meta, $plugin_file ) {
    list( $slug ) = explode( '/', $plugin_file );


    $slug_hash = md5( $slug );
    $last_updated = get_transient( "range_plu_{$slug_hash}" );
    if ( false === $last_updated ) {
        $last_updated = range_plu_get_last_updated( $slug );
        set_transient( "range_plu_{$slug_hash}", $last_updated, 86400 );
    }

    if ( $last_updated ) {
        $last_updated = strtotime( $last_updated );
        $last_updated = human_time_diff( $last_updated, current_time( 'timestamp' ) ) . ' ' . __( 'ago' );
        $plugin_meta['last_updated'] = 'Last Updated: ' . esc_html( $last_updated );
    }

    return $plugin_meta;
}
发布评论

评论列表(0)

  1. 暂无评论