posts.html
then open posts.html by going site.com/posts.html
*/
header( 'Content-type: text/html; charset=utf-8' );
header( 'X-Accel-Buffering: no' );
// In case this is run as a page.
set_time_limit(3600);
ob_implicit_flush(true);
@ini_set('zlib.output_compression',0);
@ini_set('implicit_flush',1);
$php_cli = php_sapi_name() == 'cli';
$browser_job = ! $php_cli;
$nl = "\n";
if ( $browser_job ) {
$nl .= "
";
// Put something so the webservers don't buffer
echo '' . "$nl";
}
// paths to wp-cli
$wp_paths = [
'wp',
'/usr/local/bin/wp',
'/usr/bin/wp',
__DIR__ . '/../bin/wp',
];
$found = 0;
$wp_test = '';
foreach ($wp_paths as $wp) {
$wp_test = trim(`$wp --info`);
if (stripos($wp_test, 'WP-CLI root') !== false) {
$found = 1;
break;
}
}
if (!$found) {
die("wp-cli is missing. Can't continue.");
}
// http://stackoverflow.com/questions/4870697/php-flush-that-works-even-in-nginx
echo "wp cli info$nl";
if ( $browser_job ) {
echo "
"; } echo $wp_test; if ( $browser_job ) { echo ""; } echo $nl . $nl; // will return a list all post IDs separated by spaces $ids_str = `$wp post list --post_type=post --format=ids`; // Cleanup $ids_arr = preg_split('#\s+#si', $ids_str); $ids_arr = array_unique($ids_arr); $ids_arr = array_filter($ids_arr); sort($ids_arr); $cnt = count($ids_arr); echo "Found " . $cnt . " posts.$nl"; foreach ($ids_arr as $idx => $id) { $id = (int) $id; echo "Checking ID: $id [" . ( $idx + 1 ) . " of $cnt]$nl"; // https://runcommand.io/to/assign-featured-image-generated-post/ $featured_img_id = `$wp post meta get $id _thumbnail_id`; $featured_img_id = trim($featured_img_id); $featured_img_id = (int) $featured_img_id; if (!empty($featured_img_id)) { // http://example.com/wp-content/uploads/2017/01/????-?????-e1483549644521.jpg $featured_img_url = `$wp post get $featured_img_id --field='guid'`; $featured_img_url = trim($featured_img_url); if (!empty($featured_img_url) && preg_match('#(/wp-content/uploads/.*)#si', $featured_img_url, $matches)) { if (!file_exists(__DIR__ . $matches[1])) { echo "