Changeset 3435421
- Timestamp:
- 01/08/2026 06:32:27 PM (4 months ago)
- Location:
- xv-random-quotes/trunk
- Files:
-
- 6 edited
-
changelog.txt (modified) (1 diff)
-
readme.txt (modified) (1 diff)
-
src/Admin/MetaBoxes.php (modified) (4 diffs)
-
src/Migration/SettingsMigrator.php (modified) (4 diffs)
-
vendor/composer/installed.php (modified) (2 diffs)
-
xv-random-quotes.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
xv-random-quotes/trunk/changelog.txt
r3435038 r3435421 1 1 == XV Random Quotes == 2 3 = 2.6.0 = 4 Improvement: Default category migration from legacy settings 5 Improvement: Decouple settings migration steps 2 6 3 7 = 2.5.0 = -
xv-random-quotes/trunk/readme.txt
r3435038 r3435421 6 6 Tested up to: 6.9 7 7 Requires PHP: 7.4 8 Stable tag: 2. 5.08 Stable tag: 2.6.0 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html -
xv-random-quotes/trunk/src/Admin/MetaBoxes.php
r3430809 r3435421 31 31 add_action( 'add_meta_boxes', array( $this, 'register_meta_boxes' ) ); 32 32 add_action( 'save_post_xv_quote', array( $this, 'save_all_meta_boxes' ), 10, 2 ); 33 add_action( 'save_post_xv_quote', array( $this, 'apply_default_category' ), 20, 1 ); 33 34 } 34 35 … … 74 75 return $this->get_editor_settings( array( 75 76 'teeny' => false, 76 ' rows' => 8,77 'textarea_rows' => 10, 77 78 'media_buttons' => true, 78 79 'quicktags' => true, … … 86 87 * 87 88 * @since 2.0.0 88 * @param array $options Number of textarea rows. Default 8.89 * @param array $options Editor options to override defaults. 89 90 * @return array Editor settings 90 91 */ 91 92 private function get_editor_settings( $options = array() ) { 92 return array_merge( 93 array( 94 'media_buttons' => false, // No "Add Media" button 95 'quicktags' => false, // No HTML/Text tab 96 'teeny' => true, // Minimal editor 97 'textarea_rows' => 1, // Single line textarea 98 'tinymce' => array( 99 'toolbar1' => 'bold,italic,link,unlink', // Only these buttons 100 'toolbar2' => '', // No second toolbar 101 'toolbar3' => '', // No third toolbar 102 ), 93 $defaults = array( 94 'media_buttons' => false, // No "Add Media" button 95 'quicktags' => false, // No HTML/Text tab 96 'teeny' => true, // Minimal editor 97 'textarea_rows' => 1, // Single line textarea 98 'tinymce' => array( 99 'toolbar1' => 'bold,italic,link,unlink', // Only these buttons 100 'toolbar2' => '', // No second toolbar 101 'toolbar3' => '', // No third toolbar 103 102 ), 104 $options 105 ); 103 ); 104 105 return array_merge( $defaults, $options ); 106 106 } 107 107 … … 230 230 } 231 231 } 232 233 /** 234 * Apply default category to quotes without any category assigned 235 * 236 * Automatically assigns the default category term (from v1.x migration) 237 * to quotes that don't have any quote_category term assigned. 238 * 239 * @since 2.0.0 240 * @param int $post_id The post ID. 241 */ 242 public function apply_default_category( $post_id ) { 243 // Only apply to xv_quote post type 244 if ( get_post_type( $post_id ) !== 'xv_quote' ) { 245 return; 246 } 247 248 // Check if post has any quote_category terms assigned 249 $terms = wp_get_post_terms( $post_id, 'quote_category', array( 'fields' => 'ids' ) ); 250 251 // If no terms assigned, try to assign the default 252 if ( empty( $terms ) ) { 253 $default_term_id = (int) get_option( 'xv_quotes_default_category_id', 0 ); 254 255 if ( $default_term_id > 0 ) { 256 // Verify the term exists 257 if ( get_term( $default_term_id, 'quote_category' ) ) { 258 wp_set_post_terms( $post_id, array( $default_term_id ), 'quote_category', false ); 259 } 260 } 261 } 262 } 232 263 } 264 -
xv-random-quotes/trunk/src/Migration/SettingsMigrator.php
r3429335 r3435421 15 15 * Handles migration of settings from legacy stray_quotes_options 16 16 * to individual xv_quotes_* options. 17 * 18 * Uses version numbers for the _xv_quotes_migrated option: 19 * - 0 or false: Not migrated 20 * - 1: Settings migrated (v1 - initial migration) 21 * - 2: Default category setup (v2 - added later) 22 * - etc. 17 23 */ 18 24 class SettingsMigrator { 19 25 20 26 /** 27 * Current migration version 28 * 29 * @var int 30 */ 31 const MIGRATION_VERSION = 2; 32 33 /** 21 34 * Run the migration 22 35 */ 23 36 public static function migrate() { 24 // Check if migration has already been run 25 if ( get_option( '_xv_quotes_migrated', false ) ) { 26 return; 27 } 28 37 // Get current migration version (0 if never migrated, or false for backward compat) 38 $current_version = (int) get_option( '_xv_quotes_migrated', 0 ); 39 40 // Run v1 migration if not yet done 41 if ( $current_version < 1 ) { 42 self::migrate_v200(); 43 } 44 45 // Run v2 migration if not yet done 46 if ( $current_version < 2 ) { 47 self::migrate_v260(); 48 } 49 50 // Update version to current 51 update_option( '_xv_quotes_migrated', self::MIGRATION_VERSION ); 52 } 53 54 /** 55 * V2.0.0 Migration: Settings migration from legacy format 56 */ 57 private static function migrate_v200() { 29 58 // Get old settings 30 59 $old_settings = get_option( 'stray_quotes_options', array() ); … … 40 69 self::migrate_from_legacy_settings( $old_settings ); 41 70 } 42 43 // Mark migration as complete 44 update_option( '_xv_quotes_migrated', true ); 71 } 72 73 /** 74 * V2.6.0 Migration: Default category setup 75 */ 76 private static function migrate_v260() { 77 // Check if there's a default category to migrate 78 $old_settings = get_option( 'stray_quotes_options', array() ); 79 80 if ( isset( $old_settings['stray_default_category'] ) && ! empty( $old_settings['stray_default_category'] ) ) { 81 self::create_default_category_term( $old_settings['stray_default_category'] ); 82 } 45 83 } 46 84 … … 109 147 'stray_after_loader' => Settings::OPTION_AFTER_LOADER, 110 148 'stray_loading' => Settings::OPTION_LOADING, 149 150 // Default category (for applying to migrated quotes without a category) 151 'stray_default_category' => 'xv_quotes_default_category', 111 152 ); 112 153 … … 146 187 } 147 188 } 189 190 /** 191 * Create the default category term in the quote_category taxonomy 192 * 193 * @param string $category_name The name of the default category. 194 */ 195 private static function create_default_category_term( $category_name ) { 196 $taxonomy = 'quote_category'; 197 198 // Check if term already exists 199 $term = term_exists( $category_name, $taxonomy ); 200 201 if ( ! $term ) { 202 // Create the term 203 $term = wp_insert_term( $category_name, $taxonomy ); 204 205 if ( is_wp_error( $term ) ) { 206 return; 207 } 208 } 209 210 // Get the term ID (term_exists returns int, wp_insert_term returns array) 211 $term_id = is_array( $term ) ? $term['term_id'] : $term; 212 213 // Store the term ID for use as default when creating new quotes 214 update_option( 'xv_quotes_default_category_id', (int) $term_id ); 215 } 148 216 } -
xv-random-quotes/trunk/vendor/composer/installed.php
r3434614 r3435421 4 4 'pretty_version' => 'dev-main', 5 5 'version' => 'dev-main', 6 'reference' => ' fbcdfb5200202cd5c3c489ec669901a9e8531432',6 'reference' => 'c5c63fb91808ddbfdfb9ab496437bfe15ad21871', 7 7 'type' => 'wordpress-plugin', 8 8 'install_path' => __DIR__ . '/../../', … … 14 14 'pretty_version' => 'dev-main', 15 15 'version' => 'dev-main', 16 'reference' => ' fbcdfb5200202cd5c3c489ec669901a9e8531432',16 'reference' => 'c5c63fb91808ddbfdfb9ab496437bfe15ad21871', 17 17 'type' => 'wordpress-plugin', 18 18 'install_path' => __DIR__ . '/../../', -
xv-random-quotes/trunk/xv-random-quotes.php
r3435038 r3435421 5 5 Author: Xavi Ivars 6 6 Author URI: https://xavi.ivars.me/ 7 Version: 2. 5.07 Version: 2.6.0 8 8 Requires at least: 6.0 9 9 Requires PHP: 7.4 … … 90 90 */ 91 91 function xv_quotes_check_migration() { 92 // If the 'migrated' option doesn't exist (returns false), run the migration 93 // Also check that migration hasn't already been triggered or isn't pending 94 if ( ! get_option( 'xv_quotes_migrated_v2' ) 95 && ! get_option( 'xv_quotes_needs_migration' ) 96 && ! get_option( 'xv_migration_pending' ) ) { 97 xv_quotes_activation_migration(); 98 } 92 // Run settings migration (if not yet done) 93 // This handles both v1 settings migration and v2 default category setup 94 if ( class_exists( '\XVRandomQuotes\Migration\SettingsMigrator' ) ) { 95 $current_version = (int) get_option( '_xv_quotes_migrated', 0 ); 96 if ( $current_version < \XVRandomQuotes\Migration\SettingsMigrator::MIGRATION_VERSION ) { 97 \XVRandomQuotes\Migration\SettingsMigrator::migrate(); 98 } 99 } 100 101 // Check if quote migration is needed 102 // If the 'migrated' option doesn't exist (returns false), run the migration 103 // Also check that migration hasn't already been triggered or isn't pending 104 if ( ! get_option( 'xv_quotes_migrated_v2' ) 105 && ! get_option( 'xv_quotes_needs_migration' ) 106 && ! get_option( 'xv_migration_pending' ) ) { 107 xv_quotes_activation_migration(); 108 } 99 109 } 100 110 add_action( 'admin_init', 'xv_quotes_check_migration' );
Note: See TracChangeset
for help on using the changeset viewer.