* wp downup prepare-theme * * Rewrites the given plugin's or theme's version header to a lower "-dev" * value so WordPress's normal update flow reports an update is available. */ class FUFD_CLI { public static function prepare( $args, $assoc_args ) { if ( empty( $args[0] ) ) { WP_CLI::error( 'Usage: wp downup prepare ' ); } $plugin = $args[0]; if ( false === strpos( $plugin, '/' ) ) { $plugin = self::resolve_basename_from_slug( $plugin ); } if ( ! $plugin ) { WP_CLI::error( 'Could not resolve plugin basename.' ); } if ( ! FUFD_Admin::is_enabled( $plugin ) ) { WP_CLI::error( "{$plugin} is disabled in DownUp settings." ); } $result = FUFD_Version_Manager::prepare_fake_downgrade( $plugin ); if ( is_wp_error( $result ) ) { WP_CLI::error( $result->get_error_message() ); } WP_CLI::success( "Version header for {$plugin} rewritten. Run 'wp plugin update {$plugin}' or use the Plugins page to complete the update." ); } public static function prepare_theme( $args, $assoc_args ) { if ( empty( $args[0] ) ) { WP_CLI::error( 'Usage: wp downup prepare-theme ' ); } $theme = $args[0]; if ( ! FUFD_Admin::is_theme_enabled( $theme ) ) { WP_CLI::error( "{$theme} is disabled in DownUp settings." ); } $result = FUFD_Theme_Version_Manager::prepare_fake_downgrade( $theme ); if ( is_wp_error( $result ) ) { WP_CLI::error( $result->get_error_message() ); } WP_CLI::success( "Version header for theme {$theme} rewritten. Run 'wp theme update {$theme}' or use the Appearance > Themes page to complete the update." ); } private static function resolve_basename_from_slug( $slug ) { if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } foreach ( array_keys( get_plugins() ) as $file ) { if ( 0 === strpos( $file, $slug . '/' ) || $file === $slug . '.php' ) { return $file; } } return ''; } } WP_CLI::add_command( 'downup prepare', array( 'FUFD_CLI', 'prepare' ) ); WP_CLI::add_command( 'downup prepare-theme', array( 'FUFD_CLI', 'prepare_theme' ) );