n Name: Freeze Posts After Date (WP-CLI) * Description: Congela (bozza) i post pubblicati dopo una certa data e permette il ripristino con la data originale. * Author: Marco * Version: 1.0.0 */ if ( ! defined('WP_CLI') || ! WP_CLI ) { return; } class Freeze_Posts_Command { const META_FLAG = '_freeze_flag'; const META_ORIG_DATE = '_freeze_original_post_date'; const META_ORIG_DATE_GMT = '_freeze_original_post_date_gmt'; const META_ORIG_STATUS = '_freeze_original_post_status'; /** * Congela i post pubblicati dopo una data (default: 2024-09-01 00:00:00). * * ## OPTIONS * * [--after=] * : Data (inclusiva) dopo cui congelare i post. Default: 2024-09-01 * * [--post_type=] * : Post type da considerare. Default: post * * [--dry-run] * : Non applica cambiamenti, mostra solo cosa farebbe. * * ## EXAMPLES * wp freeze-posts run --after=2024-09-01 * wp freeze-posts run --post_type=news */ public function run( $args, $assoc_args ) { $after = isset($assoc_args['after']) ? $assoc_args['after'] : '2024-09-01'; $post_type = isset($assoc_args['post_type']) ? $assoc_args['post_type'] : 'post'; $dry_run = isset($assoc_args['dry-run']); $after_dt = date('Y-m-d 00:00:00', strtotime($after)); $q = new WP_Query([ 'post_type' => $post_type, 'post_status' => 'publish', 'date_query' => [ [ 'after' => $after_dt, 'inclusive' => true, 'column' => 'post_date', ], ], 'posts_per_page' => -1, 'fields' => 'ids', 'no_found_rows' => true, ]); $count = 0; if ( $q->have_posts() ) { foreach ( $q->posts as $post_id ) { $already = get_post_meta($post_id, self::META_FLAG, true); if ( $already ) { WP_CLI::log("Skip #$post_id (già congelato)"); continue; } $post = get_post($post_id); $orig_status = $post->post_status; $orig_date = $post->post_date; $orig_date_gmt = $post->post_date_gmt; if ( ! $dry_run ) { // salva meta per ripristino update_post_meta($post_id, self::META_FLAG, 1); update_post_meta($post_id, self::META_ORIG_STATUS, $orig_status); update_post_meta($post_id, self::META_ORIG_DATE, $orig_date); update_post_meta($post_id, self::META_ORIG_DATE_GMT, $orig_date_gmt); // porta offline: draft wp_update_post([ 'ID' => $post_id, 'post_status' => 'draft', ]); } $count++; WP_CLI::log(($dry_run ? '[DRY RUN] ' : '') . "Congelato #$post_id ($post_type) – era publish del $orig_date"); } } WP_CLI::success(($dry_run ? '[DRY RUN] ' : '') . "Totale post congelati: $count"); } /** * Ripristina tutti i post congelati (flag presenti), rimettendo online con la data originale. * * ## OPTIONS * * [--post_type=] * : Post type da considerare. Default: post * * [--dry-run] * : Non applica cambiamenti, mostra solo cosa farebbe. * * ## EXAMPLES * wp freeze-posts restore */ public function restore( $args, $assoc_args ) { $post_type = isset($assoc_args['post_type']) ? $assoc_args['post_type'] : 'post'; $dry_run = isset($assoc_args['dry-run']); $q = new WP_Query([ 'post_type' => $post_type, 'post_status' => ['draft','pending','private','publish','future'], 'meta_query' => [ [ 'key' => self::META_FLAG, 'value' => 1, ], ], 'posts_per_page' => -1, 'fields' => 'ids', 'no_found_rows' => true, ]); $count = 0; if ( $q->have_posts() ) { foreach ( $q->posts as $post_id ) { $orig_status = get_post_meta($post_id, self::META_ORIG_STATUS, true) ?: 'publish'; $orig_date = get_post_meta($post_id, self::META_ORIG_DATE, true); $orig_date_gmt = get_post_meta($post_id, self::META_ORIG_DATE_GMT, true); if ( ! $orig_date || ! $orig_date_gmt ) { WP_CLI::warning("Post #$post_id: mancano date originali, skip."); continue; } if ( ! $dry_run ) { // ripristina status e date wp_update_post([ 'ID' => $post_id, 'post_status' => $orig_status, 'post_date' => $orig_date, 'post_date_gmt' => $orig_date_gmt, ]); // pulizia meta delete_post_meta($post_id, self::META_FLAG); delete_post_meta($post_id, self::META_ORIG_STATUS); delete_post_meta($post_id, self::META_ORIG_DATE); delete_post_meta($post_id, self::META_ORIG_DATE_GMT); } $count++; WP_CLI::log(($dry_run ? '[DRY RUN] ' : '') . "Ripristinato #$post_id → {$orig_status} ({$orig_date})"); } } WP_CLI::success(($dry_run ? '[DRY RUN] ' : '') . "Totale post ripristinati: $count"); } } WP_CLI::add_command('freeze-posts', 'Freeze_Posts_Command'); Villaggi per bambini Puglia, Salento | Viaggiamo

Villaggi per bambini in Puglia: le migliori strutture del Salento

Resort La Brunese

Situato in posizione tranquilla, a 2 km dal centro di Torre dell’Orso, il Resort La Brunese è un villaggio vacanze dotato di piscina all’aperto, camere funzionali, ristorante e connessione Wi-Fi.

Resort La Brunese

Continua la lettura