'post', 'post_status' => 'publish', 'posts_per_page' => $limit, 'orderby' => 'date', 'order' => 'ASC', // oldest first ] ); $results = []; foreach ( $posts as $post ) { $score = self::decay_score( $post ); if ( $score['risk'] !== 'low' ) { $results[] = array_merge( [ 'post' => $post ], $score ); } } usort( $results, fn( $a, $b ) => $b['score'] <=> $a['score'] ); return $results; } public static function decay_score( $post ) { $score = 0; $reasons = []; $now = time(); $created = strtotime( $post->post_date ); $modified = strtotime( $post->post_modified ); $age_days = ( $now - $created ) / DAY_IN_SECONDS; $modified_days = ( $now - $modified ) / DAY_IN_SECONDS; // Post is older than 12 months. if ( $age_days > 365 ) { $score += 20; $reasons[] = 'Post is over 1 year old (' . round( $age_days / 365, 1 ) . ' years).'; } // Not updated in 6+ months. if ( $modified_days > 180 ) { $score += 25; $reasons[] = 'Not updated in ' . round( $modified_days / 30 ) . ' months.'; } elseif ( $modified_days > 90 ) { $score += 10; $reasons[] = 'Not updated in ' . round( $modified_days / 30 ) . ' months.'; } // Time-sensitive keywords in title. $time_keywords = [ 'best', 'top', 'review', 'vs', 'versus', 'comparison', 'guide', 'how to', 'tutorial', 'checklist', 'list', 'tips', 'tricks', 'tools', 'plugins', 'apps' ]; $title_lower = mb_strtolower( $post->post_title ); foreach ( $time_keywords as $kw ) { if ( false !== mb_strpos( $title_lower, $kw ) ) { $score += 10; $reasons[] = "Title contains '{$kw}' - time-sensitive topic."; break; } } // Year in title (e.g., "Best Plugins 2022"). if ( preg_match( '/20(1\d|2[0-3])/', $post->post_title, $m ) ) { $score += 30; $reasons[] = "Title contains year {$m[0]} - almost certainly outdated."; } // Short content = thin/low-effort = higher decay risk. $word_count = str_word_count( wp_strip_all_tags( $post->post_content ) ); if ( $word_count < 500 ) { $score += 15; $reasons[] = "Content is only {$word_count} words - thin posts decay faster."; } // No focus keyword = not optimised = higher risk. if ( ! AWBSEO_Meta_Manager::get( $post->ID, 'focus_keyword' ) ) { $score += 5; $reasons[] = 'No focus keyword set.'; } $risk = 'low'; if ( $score >= 50 ) $risk = 'high'; elseif ( $score >= 25 ) $risk = 'medium'; return [ 'score' => $score, 'risk' => $risk, 'reasons' => $reasons, 'age_days' => round( $age_days ), 'modified_days' => round( $modified_days ), 'word_count' => $word_count, ]; } /** * Returns suggested refresh actions for a post. */ public static function refresh_suggestions( $post_id ) { $post = get_post( $post_id ); $score = self::decay_score( $post ); $suggestions = []; if ( $score['modified_days'] > 90 ) { $suggestions[] = 'Review and update all statistics, prices, and data.'; $suggestions[] = 'Check all outbound links - broken links hurt rankings.'; } if ( preg_match( '/20(1\d|2[0-3])/', $post->post_title ) ) { $suggestions[] = 'Update the year in the post title to ' . date_i18n( 'Y' ) . '.'; } $suggestions[] = 'Add or refresh internal links to newer related content.'; $suggestions[] = 'Expand thin sections with new examples or updated information.'; $suggestions[] = 'Update the meta description to reflect fresh content.'; $suggestions[] = 'Set the dateModified schema field to today\'s date after editing.'; return $suggestions; } }