Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




_close_comments_for_old_posts [ WordPress Function ]

_close_comments_for_old_posts ( $posts, $query )
Access:
  • private
Parameters:
  • (object) $posts Post data object.
  • (object) $query Query object.
Returns:
  • (object)
Defined at:



Close comments on old posts on the fly, without any extra DB queries. Hooked to the_posts.

Source


<?php
function _close_comments_for_old_posts$posts$query ) {
    if ( empty( 
$posts ) || ! $query->is_singular() || ! get_option'close_comments_for_old_posts' ) )
        return 
$posts;

    
$post_types apply_filters'close_comments_for_post_types', array( 'post' ) );
    if ( ! 
in_array$posts[0]->post_type$post_types ) )
        return 
$posts;

    
$days_old = (int) get_option'close_comments_days_old' );
    if ( ! 
$days_old )
        return 
$posts;

    if ( 
time() - strtotime$posts[0]->post_date_gmt ) > ( $days_old 24 60 60 ) ) {
        
$posts[0]->comment_status 'closed';
        
$posts[0]->ping_status 'closed';
    }

    return 
$posts;
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

Gebruikersdiscussies [ wordpress.org ]

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics