Ticket #8177: 8177.4.diff
File 8177.4.diff, 7.7 KB (added by , 12 years ago) |
---|
-
wp-includes/comment.php
2072 2072 // 2073 2073 2074 2074 /** 2075 * Close comments on old posts on the fly, without any extra DB queries. Hooked to the_posts. 2075 * Close comments on old posts on the fly, without any extra DB queries. 2076 * Hooked to the_posts. 2076 2077 * 2077 2078 * @access private 2078 2079 * @since 2.7.0 2079 2080 * 2080 2081 * @param object $posts Post data object. 2081 * @param object $query Query object.2082 2082 * @return object 2083 2083 */ 2084 function _close_comments_for_old_posts( $posts , $query) {2085 if ( empty( $posts ) || ! $query->is_singular() || !get_option( 'close_comments_for_old_posts' ) )2084 function _close_comments_for_old_posts( $posts ) { 2085 if ( empty( $posts ) || ! get_option( 'close_comments_for_old_posts' ) ) 2086 2086 return $posts; 2087 2087 2088 2088 $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) ); … … 2093 2093 if ( ! $days_old ) 2094 2094 return $posts; 2095 2095 2096 if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) { 2097 $posts[0]->comment_status = 'closed'; 2098 $posts[0]->ping_status = 'closed'; 2099 } 2096 for ( $i = 0; $i < count( $posts ); $i++ ) { 2097 if ( time() - strtotime( $posts[ $i ]->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) { 2098 $posts[ $i ]->comment_status = 'closed'; 2099 $posts[ $i ]->ping_status = 'closed'; 2100 } 2101 } 2100 2102 2101 2103 return $posts; 2102 2104 } … … 2115 2117 if ( ! $open ) 2116 2118 return $open; 2117 2119 2118 if ( ! get_option('close_comments_for_old_posts') )2120 if ( ! get_option( 'close_comments_for_old_posts' ) ) 2119 2121 return $open; 2120 2122 2121 $days_old = (int) get_option( 'close_comments_days_old');2122 if ( ! $days_old )2123 $days_old = (int) get_option( 'close_comments_days_old' ); 2124 if ( ! $days_old ) 2123 2125 return $open; 2124 2126 2125 $post = get_post( $post_id);2127 $post = get_post( $post_id ); 2126 2128 2127 2129 $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) ); 2128 2130 if ( ! in_array( $post->post_type, $post_types ) ) … … 2133 2135 2134 2136 return $open; 2135 2137 } 2138 2139 /** 2140 * Close comments/pings on attachments if the parent's comments are closed. 2141 * Hooked to the_posts. 2142 * 2143 * @access private 2144 * @since 3.6.0 2145 * 2146 * @param object $posts Post data object. 2147 * @return object 2148 */ 2149 function _close_comments_for_attachments( $posts ) { 2150 2151 foreach ( (array) $posts as $key => $post ) { 2152 if ( 'attachment' != $post->post_type || 0 == $post->post_parent || $post->post_parent == $post->ID ) 2153 continue; 2154 2155 $parent = get_post( $post->post_parent ); 2156 $posts[ $key ]->comment_status = $parent->comment_status; 2157 $posts[ $key ]->ping_status = $parent->ping_status; 2158 } 2159 2160 return $posts; 2161 } 2162 2163 /** 2164 * Close comments/pings on attachment if parents comments/pings are closed. 2165 * Hooked to comments_open and pings_open. 2166 * 2167 * @access private 2168 * @since 3.6.0 2169 * 2170 * @param bool $open Comments open or closed 2171 * @param int $post_id Post ID 2172 * @return bool $open 2173 */ 2174 function _close_comments_for_attachment( $open, $post_id ) { 2175 if ( ! $open ) 2176 return $open; 2177 2178 $post = get_post( $post_id ); 2179 2180 if ( 'attachment' != $post->post_type || 0 == $post->post_parent ) 2181 return $open; 2182 2183 $parent = get_post( $post->post_parent ); 2184 2185 if ( ! $parent ) 2186 return $open; 2187 2188 if ( 'comments_open' == current_filter() ) 2189 $open = ( 'open' == $parent->comment_status ); 2190 else //pings 2191 $open = ( 'open' == $parent->ping_status ); 2192 2193 return $open; 2194 } 2195 No newline at end of file -
wp-includes/default-filters.php
174 174 add_filter( 'the_author', 'ent2ncr', 8 ); 175 175 176 176 // Misc filters 177 add_filter( 'option_ping_sites', 'privacy_ping_filter' ); 178 add_filter( 'option_blog_charset', '_wp_specialchars' ); // IMPORTANT: This must not be wp_specialchars() or esc_html() or it'll cause an infinite loop 179 add_filter( 'option_home', '_config_wp_home' ); 180 add_filter( 'option_siteurl', '_config_wp_siteurl' ); 181 add_filter( 'tiny_mce_before_init', '_mce_set_direction' ); 182 add_filter( 'pre_kses', 'wp_pre_kses_less_than' ); 183 add_filter( 'sanitize_title', 'sanitize_title_with_dashes', 10, 3 ); 184 add_action( 'check_comment_flood', 'check_comment_flood_db', 10, 3 ); 185 add_filter( 'comment_flood_filter', 'wp_throttle_comment_flood', 10, 3 ); 186 add_filter( 'pre_comment_content', 'wp_rel_nofollow', 15 ); 187 add_filter( 'comment_email', 'antispambot' ); 188 add_filter( 'option_tag_base', '_wp_filter_taxonomy_base' ); 189 add_filter( 'option_category_base', '_wp_filter_taxonomy_base' ); 190 add_filter( 'the_posts', '_close_comments_for_old_posts', 10, 2); 191 add_filter( 'comments_open', '_close_comments_for_old_post', 10, 2 ); 192 add_filter( 'pings_open', '_close_comments_for_old_post', 10, 2 ); 193 add_filter( 'editable_slug', 'urldecode' ); 194 add_filter( 'editable_slug', 'esc_textarea' ); 195 add_filter( 'nav_menu_meta_box_object', '_wp_nav_menu_meta_box_object' ); 196 add_filter( 'pingback_ping_source_uri', 'pingback_ping_source_uri' ); 197 add_filter( 'xmlrpc_pingback_error', 'xmlrpc_pingback_error' ); 177 add_filter( 'option_ping_sites', 'privacy_ping_filter' ); 178 add_filter( 'option_blog_charset', '_wp_specialchars' ); // IMPORTANT: This must not be wp_specialchars() or esc_html() or it'll cause an infinite loop 179 add_filter( 'option_home', '_config_wp_home' ); 180 add_filter( 'option_siteurl', '_config_wp_siteurl' ); 181 add_filter( 'tiny_mce_before_init', '_mce_set_direction' ); 182 add_filter( 'pre_kses', 'wp_pre_kses_less_than' ); 183 add_filter( 'sanitize_title', 'sanitize_title_with_dashes', 10, 3 ); 184 add_action( 'check_comment_flood', 'check_comment_flood_db', 10, 3 ); 185 add_filter( 'comment_flood_filter', 'wp_throttle_comment_flood', 10, 3 ); 186 add_filter( 'pre_comment_content', 'wp_rel_nofollow', 15 ); 187 add_filter( 'comment_email', 'antispambot' ); 188 add_filter( 'option_tag_base', '_wp_filter_taxonomy_base' ); 189 add_filter( 'option_category_base', '_wp_filter_taxonomy_base' ); 190 add_filter( 'the_posts', '_close_comments_for_old_posts' ); 191 add_filter( 'comments_open', '_close_comments_for_old_post', 10, 2 ); 192 add_filter( 'pings_open', '_close_comments_for_old_post', 10, 2 ); 193 add_filter( 'the_posts', '_close_comments_for_attachments' ); 194 add_filter( 'comments_open', '_close_comments_for_attachment', 10, 2 ); 195 add_filter( 'pings_open', '_close_comments_for_attachment', 10, 2 ); 196 add_filter( 'editable_slug', 'urldecode' ); 197 add_filter( 'editable_slug', 'esc_textarea' ); 198 add_filter( 'nav_menu_meta_box_object', '_wp_nav_menu_meta_box_object' ); 199 add_filter( 'pingback_ping_source_uri', 'pingback_ping_source_uri' ); 200 add_filter( 'xmlrpc_pingback_error', 'xmlrpc_pingback_error' ); 198 201 199 202 // Actions 200 203 add_action( 'wp_head', 'wp_enqueue_scripts', 1 );