prefix. $old_table = $wpdb->prefix . self::OLD . '_history'; $new_table = Repository::table(); if ( $old_table === $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $old_table ) ) ) ) { $has_new = $new_table === $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $new_table ) ) ); if ( $has_new && 0 === (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$new_table}" ) ) { $wpdb->query( "DROP TABLE {$new_table}" ); $has_new = false; } if ( ! $has_new ) { $wpdb->query( "RENAME TABLE {$old_table} TO {$new_table}" ); } } // Cached values are rebuilt under the new names. $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\\_transient\\_%priceproof\\_%' OR option_name LIKE '\\_site\\_transient\\_%priceproof\\_%'" ); // Settings that already exist under the new name are kept. $wpdb->query( "UPDATE IGNORE {$wpdb->options} SET option_name = CONCAT( 'strikewise_', SUBSTRING( option_name, 12 ) ) WHERE option_name LIKE 'priceproof\\_%'" ); $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'priceproof\\_%'" ); $wpdb->query( "UPDATE {$wpdb->options} SET option_value = REPLACE( option_value, 'wp:priceproof/', 'wp:strikewise/' ) WHERE option_name = 'widget_block' AND option_value LIKE '%wp:priceproof/%'" ); $wpdb->query( "UPDATE {$wpdb->postmeta} SET meta_key = CONCAT( '_strikewise_', SUBSTRING( meta_key, 13 ) ) WHERE meta_key LIKE '\\_priceproof\\_%'" ); $wpdb->query( "UPDATE {$wpdb->posts} SET post_content = REPLACE( post_content, 'wp:priceproof/', 'wp:strikewise/' ) WHERE post_content LIKE '%wp:priceproof/%'" ); $wpdb->query( "UPDATE {$wpdb->usermeta} SET meta_key = CONCAT( 'strikewise_', SUBSTRING( meta_key, 12 ) ) WHERE meta_key LIKE 'priceproof\\_%'" ); // Position, folding and visibility of the dashboard widget and the product box. $wpdb->query( "UPDATE {$wpdb->usermeta} SET meta_value = REPLACE( meta_value, 'priceproof', 'strikewise' ) WHERE ( meta_key LIKE 'meta-box-order\\_%' OR meta_key LIKE 'metaboxhidden\\_%' OR meta_key LIKE 'closedpostboxes\\_%' ) AND meta_value LIKE '%priceproof%'" ); // phpcs:enable wp_cache_flush(); // The old actions have no callbacks any more; the new ones are scheduled on the next admin request. if ( did_action( 'action_scheduler_init' ) ) { self::cancel_actions(); } else { add_action( 'action_scheduler_init', array( self::class, 'cancel_actions' ) ); } } public static function cancel_actions(): void { if ( function_exists( 'as_unschedule_all_actions' ) ) { as_unschedule_all_actions( '', array(), self::OLD ); } } }