page_value) === 0) { $rows[] = [ 'id' => (int) $row->id, 'time' => $row->time, 'menu_slug' => $row->menu_slug, 'page_value' => $row->page_value, 'plugin' => $row->plugin ?? Plugin::_NAME, ]; } } if (! $rows) { return false; } /** * How many days the backup of the pages from before the JSON storage is kept. * * @since 1.0.0 * * @param int $days Default 90. */ $days = max(1, (int) apply_filters('aop_backup_days', 90)); update_option(self::BACKUP, ['created' => time(), 'plugin_version' => Plugin::releaseVersion(), 'rows' => $rows], false); update_option(self::BACKUP_EXPIRES, time() + $days * DAY_IN_SECONDS, true); return true; } /** * Remove the backup when its time is up. Runs on every admin request; it reads one small option. */ public static function expireBackup(): void { $expires = (int) get_option(self::BACKUP_EXPIRES, 0); if ($expires > 0 && time() > $expires) { self::deleteBackup(); } } public static function deleteBackup(): void { delete_option(self::BACKUP); delete_option(self::BACKUP_EXPIRES); } /** * Put the pages back as they were before the upgrade, PHP-serialized, so that version 0.9.x can read them. * Replaces everything in the table: pages that were made or changed after the upgrade are lost. Not used by * the plugin itself; run it by hand, see `docs/schema.md`. * * @return int The number of pages that were put back, or 0 when there is no backup. */ public static function restoreBackup(): int { $backup = get_option(self::BACKUP, false); if (! is_array($backup) || empty($backup['rows'])) { return 0; } return PageRepository::replaceAllWithLegacyRows($backup['rows']); } }