From 538fcd13b1e5a9e41bf0a44994a087c790e41c22 Mon Sep 17 00:00:00 2001 From: EliteStarServices Date: Thu, 7 Mar 2024 15:40:21 -0500 Subject: [PATCH 01/30] Changes to be committed: modified: lib/admin-page.php modified: switch-to-classicpress.php --- lib/admin-page.php | 123 +++++++++++++++++++++++++------------ switch-to-classicpress.php | 103 ++++++++++++++++++++++++++++--- 2 files changed, 179 insertions(+), 47 deletions(-) diff --git a/lib/admin-page.php b/lib/admin-page.php index 1c986db..78a2bb2 100644 --- a/lib/admin-page.php +++ b/lib/admin-page.php @@ -212,11 +212,11 @@ classicpress_show_migration_blocked_info();
  • support forum or Slack group.', + 'For support, suggestions for improvement, or general discussion about how the plugin works, visit us in our support forum or Zulip chat.', 'switch-to-classicpress' ), 'https://forums.classicpress.net/c/support/migration-plugin', - 'https://www.classicpress.net/join-slack/' + 'https://classicpress.zulipchat.com/register/' ); ?>
  • - get_error_message(); ?> - get_error_data() ); ?> + get_error_message(); ?> + get_error_data() ); ?>

    %1$s to %2$s (and some newer development versions).', @@ -380,7 +380,7 @@ function classicpress_check_can_migrate() { version_compare( $wp_version, $wp_version_max, 'gt' ) ) && // ... and it doesn't match any other acceptable version patterns - empty( array_filter( $parameters['wordpress']['other'], function( $pattern ) { + empty( array_filter( $cp_api_parameters['wordpress']['other'], function( $pattern ) { global $wp_version; return preg_match( $pattern, $wp_version ); } ) ) @@ -452,8 +452,8 @@ function classicpress_check_can_migrate() { // Check: Conflicting Theme $theme = wp_get_theme(); if ( - in_array( $theme->stylesheet, (array) $parameters['themes'] ) || - ( is_child_theme() && in_array( $theme->parent()->stylesheet, (array) $parameters['themes'] ) ) + in_array( $theme->stylesheet, (array) $cp_api_parameters['themes'] ) || + ( is_child_theme() && in_array( $theme->parent()->stylesheet, (array) $cp_api_parameters['themes'] ) ) ) { $preflight_checks['theme'] = false; echo "\n$icon_preflight_fail\n\n

    \n"; @@ -507,13 +507,13 @@ function classicpress_check_can_migrate() { // Start by checking if plugins have declared they require WordPress 5.0 or higher foreach ( $plugins as $plugin ) { - if ( in_array( $plugin, $parameters['plugins'] ) ) { + if ( isset( $cp_api_parameters['plugins'] ) && in_array( $plugin, $cp_api_parameters['plugins'] ) ) { continue; } $plugin_data = get_file_data( WP_PLUGIN_DIR . '/' . $plugin, $plugin_headers ); $plugin_name = $plugin_data['Name']; - if ( version_compare( $plugin_data['RequiresWP'], '5.0' ) >= 0 ) { + if ( version_compare( $plugin_data['RequiresWP'], '7.0' ) >= 0 ) { $declared_incompatible_plugins[ $plugin ] = $plugin_name; } else { $plugin_files = get_plugin_files( $plugin ); @@ -525,7 +525,7 @@ function classicpress_check_can_migrate() { continue; } $readme_data = get_file_data( WP_PLUGIN_DIR . '/' . $readme, $plugin_headers ); - if ( version_compare( $readme_data['RequiresWP'], '5.0' ) >= 0 ) { + if ( version_compare( $readme_data['RequiresWP'], '7.0' ) >= 0 ) { $declared_incompatible_plugins[ $plugin ] = $plugin_name; continue; } @@ -542,12 +542,12 @@ function classicpress_check_can_migrate() { // Compare active plugins with API response of known conflicting plugins if ( - $plugins !== array_diff( $plugins, $parameters['plugins'] ) || + isset( $cp_api_parameters['plugins'] ) && $plugins !== array_diff( $plugins, $cp_api_parameters['plugins'] ) || ! empty( $declared_incompatible_plugins ) ) { $preflight_checks['plugins'] = false; - $conflicting_plugins = array_intersect( $parameters['plugins'], $plugins ); + $conflicting_plugins = array_intersect( $cp_api_parameters['plugins'], $plugins ); $conflicting_plugin_names = array(); foreach( $conflicting_plugins as $conflicting_plugin ) { $conflicting_plugin_data = get_plugin_data( WP_CONTENT_DIR . '/plugins/' . $conflicting_plugin ); @@ -608,8 +608,10 @@ function classicpress_check_can_migrate() { // Check: Supported PHP version if ( - version_compare( PHP_VERSION, $parameters['php']['min'], 'lt' ) || - version_compare( PHP_VERSION, $parameters['php']['max'], 'gt' ) + isset( $cp_api_parameters['php'] ) && ( + version_compare( PHP_VERSION, $cp_api_parameters['php']['min'], 'lt' ) || + version_compare( PHP_VERSION, $cp_api_parameters['php']['max'], 'gt' ) + ) ) { $preflight_checks['php_version'] = false; echo "\n$icon_preflight_fail\n\n"; @@ -618,11 +620,11 @@ function classicpress_check_can_migrate() { echo "\n$icon_preflight_pass\n\n"; } echo "

    \n"; - printf( __( + printf( __( /* translators: 1: minimum supported PHP version, 2: maximum supported PHP version */ - 'ClassicPress supports PHP versions %1$s to %2$s.', + 'ClassicPress supports PHP versions %1$s through %2$s.', 'switch-to-classicpress' - ), $parameters['php']['min'], $parameters['php']['max_display'] ); + ), $cp_api_parameters['php']['min'], $cp_api_parameters['php']['max_display'] ); echo "
    \n"; printf( __( /* translators: current PHP version */ @@ -678,7 +680,7 @@ function classicpress_check_can_migrate() { ); echo "
    \n"; _e( - 'If you are using composer.json to manage dependencies for this site, then you should back up this file before continuing, and restore it after the migration.', + 'If you are using composer.json to manage dependencies for this site, then you should back up this file now, and restore it after the migration.', 'switch-to-classicpress' ); echo "\n

    \n"; @@ -781,12 +783,14 @@ function classicpress_check_can_migrate() { * @since 0.1.0 */ function classicpress_show_migration_controls() { + $cp_api_parameters = classicpress_migration_parameters(); + $cp_cv = substr($cp_api_parameters['classicpress']['version'], 0, strpos($cp_api_parameters['classicpress']['version'], '+')); ?>

    - +

    - please make a backup of your site files and database.', 'switch-to-classicpress' ); ?> + Please make a Complete Backup of your Site Files and Database now!.', 'switch-to-classicpress' ); ?>

    @@ -875,6 +879,12 @@ function classicpress_show_migration_blocked_info() { * hide the "advanced controls" button if preflight checks failed. */ function classicpress_show_advanced_migration_controls( $ok = true ) { + $cp_api_parameters = classicpress_migration_parameters(); + // Get versions for drop down value names here + $cp_pv = substr($cp_api_parameters['classicpress']['version'], 0, strpos($cp_api_parameters['classicpress']['version'], '+')); + $cp_v1 = substr($cp_api_parameters['links']['ClassicPress v1'], 119, -23); + $wp_v6 = substr($cp_api_parameters['links']['WordPress 6.2.x'], 32, -4); + $wp_v4 = substr($cp_api_parameters['links']['WordPress 4.9.x'], 32, -4); $is_wp = ! function_exists( 'classicpress_version' ); if ( $ok ) { ?> @@ -883,7 +893,7 @@ function classicpress_show_advanced_migration_controls( $ok = true ) { class="button button-large hide-if-no-js" > @@ -902,6 +912,16 @@ class="hidden" 'switch-to-classicpress' ); ?> +

    +

    "; +$myversion = "1.7.1"; +$cp_url = get_migration_from_cp_version($myversion); +echo $cp_url; +*/ ?> +

    @@ -914,13 +934,13 @@ class="hidden" + + +

    migration builds!', + 'Use this tool to install another version of WordPress or ClassicPress Migration Builds!', 'switch-to-classicpress' ); ?>

    will not work.', + 'Official Release Builds of ClassicPress will not work for migration.', 'switch-to-classicpress' ); ?>

    @@ -928,7 +948,7 @@ class="hidden" on GitHub.', + 'You can find ClassicPress Migration Builds on GitHub.', 'switch-to-classicpress' ), 'https://github.com/ClassyBot/ClassicPress-nightly/releases' @@ -947,19 +967,45 @@ class="hidden"

    - However, that doesn't mean it will be successful in all cases!", 'switch-to-classicpress' ); ?>

    take a backup of your site before using this feature.', + 'Please, make a Complete Backup of your Site before using this feature with caution!', 'switch-to-classicpress' ); ?>

    + * MIGRATING TO WP v4.9 SHOULD BE A LAST RESORT AND IS DONE AT YOUR OWN RISK!

    ', + 'switch-to-classicpress' + ); + } + ?>
    + +
    - +
    + get_error_message(); @@ -191,17 +191,17 @@ function classicpress_migration_parameters() { } if ( $status === 200 ) { - $parameters = json_decode( wp_remote_retrieve_body( $response ), true ); - if ( is_array( $parameters ) ) { + $cp_api_parameters = json_decode( wp_remote_retrieve_body( $response ), true ); + if ( is_array( $cp_api_parameters ) ) { set_transient( 'classicpress_migration_parameters', - $parameters, + $cp_api_parameters, 1 * HOUR_IN_SECONDS ); } } - if ( ! is_array( $parameters ) ) { + if ( ! is_array( $cp_api_parameters ) ) { return new WP_Error( 'classicpress_server_error', __( @@ -213,5 +213,90 @@ function classicpress_migration_parameters() { } } - return $parameters; + return $cp_api_parameters; } + + +/** + * Get a list of ClassicPress released versions from api-v1.classicpress.net. + * + * @return array|false Array of CP versions or false on API failure. + */ +/* +function get_cp_versions() { + $cp_versions = get_transient( 'classicpress_release_versions' ); + +if ( ! $cp_versions ) { + $response = wp_remote_get('https://api-v1.classicpress.net/v1/upgrade/index.php', ['timeout'=>3]); + if ( is_wp_error( $response ) ) { + $status = $response->get_error_message(); + } else { + $status = wp_remote_retrieve_response_code( $response ); + } + + if ( $status === 200 ) { + $cp_versions = json_decode( wp_remote_retrieve_body( $response ), true ); + if ( is_array( $cp_versions ) ) { + set_transient( + 'classicpress_release_versions', + $cp_versions, + 1 * HOUR_IN_SECONDS + ); + } + } + + if ( ! is_array( $cp_versions ) ) { + return new WP_Error( + 'classicpress_server_error', + __( + 'Could not communicate with the ClassicPress API server', + 'switch-to-classicpress' + ), + array( 'status' => $status ) + ); + } +} +// $versions = json_decode(wp_remote_retrieve_body($response)); + + // Get only stable releases + foreach ($cp_versions as $key => $version) { + if(!str_contains($version, 'nightly') && !str_contains($version, 'rc') && !str_contains($version, 'alpha') && !str_contains($version, 'beta')) { + continue; + } + unset($cp_versions[$key]); + } + + // Strip .json from version + $cp_versions = array_map( + function($v) { + return substr($v, 0, -5); + }, + $cp_versions + ); + + // Sort using SemVer + usort($cp_versions, 'version_compare'); + + return array_values($cp_versions); + +} + +function get_migration_from_cp_version($version) { + $response = wp_remote_get('https://api.github.com/repos/ClassicPress/ClassicPress-release/releases/tags/'.$version, ['timeout'=>3]); + if (is_wp_error($response) || empty($response)) { + return false; + } + + $data = json_decode(wp_remote_retrieve_body($response), true); + if(isset($data['message']) && $data['message'] === 'Not Found') { + return ''; + } + + $created_at = new \DateTime($data['created_at']); + $day = $created_at->format('Ymd'); + $exploded = explode('.', $version); + $major = $exploded[0]; + $url = 'https://github.com/ClassyBot/ClassicPress-v'.$major.'-nightly/releases/download/'.$version.'%2Bmigration.'.$day.'/ClassicPress-nightly-'.$version.'-migration.'.$day.'.zip'; + return $url; +} +*/ \ No newline at end of file From 9f22f5faafbb17954b3c397567a78fd78d728ee1 Mon Sep 17 00:00:00 2001 From: EliteStarServices Date: Fri, 8 Mar 2024 16:00:33 -0500 Subject: [PATCH 02/30] On branch master Your branch is up to date with 'origin/master'. Changes to be committed: modified: lib/admin-page.php modified: switch-to-classicpress.php --- lib/admin-page.php | 127 +++++++++++++++++++++++++------------ switch-to-classicpress.php | 40 +++++++++++- 2 files changed, 124 insertions(+), 43 deletions(-) diff --git a/lib/admin-page.php b/lib/admin-page.php index 78a2bb2..4bebfe1 100644 --- a/lib/admin-page.php +++ b/lib/admin-page.php @@ -253,24 +253,42 @@ function classicpress_check_can_migrate() { // Check: Are we already on ClassicPress? if ( function_exists( 'classicpress_version' ) ) { + global $cp_version; if ( is_multisite() ) { $delete_plugin_url = network_admin_url( 'plugins.php' ); + $reinstall_url = network_admin_url( 'update-core.php' ); } else { $delete_plugin_url = admin_url( 'plugins.php' ); + $reinstall_url = admin_url( 'update-core.php' ); } ?>
    -

    +

    +

    +You must visit the Updates Page and Press the Re-Install Now button to complete the switch to ClassicPress!", + 'switch-to-classicpress' + ); +} +?> +

    + This Plugin is also an Advanced Version Control Tool for Development and Troubleshooting.", 'switch-to-classicpress' ); ?>

    delete this plugin now.', + 'If no longer needed. you can delete the plugin.', 'switch-to-classicpress' ), $delete_plugin_url @@ -507,7 +525,7 @@ function classicpress_check_can_migrate() { // Start by checking if plugins have declared they require WordPress 5.0 or higher foreach ( $plugins as $plugin ) { - if ( isset( $cp_api_parameters['plugins'] ) && in_array( $plugin, $cp_api_parameters['plugins'] ) ) { + if ( in_array( $plugin, $cp_api_parameters['plugins'] ) ) { continue; } @@ -542,7 +560,7 @@ function classicpress_check_can_migrate() { // Compare active plugins with API response of known conflicting plugins if ( - isset( $cp_api_parameters['plugins'] ) && $plugins !== array_diff( $plugins, $cp_api_parameters['plugins'] ) || + $plugins !== array_diff( $plugins, $cp_api_parameters['plugins'] ) || ! empty( $declared_incompatible_plugins ) ) { $preflight_checks['plugins'] = false; @@ -608,10 +626,8 @@ function classicpress_check_can_migrate() { // Check: Supported PHP version if ( - isset( $cp_api_parameters['php'] ) && ( - version_compare( PHP_VERSION, $cp_api_parameters['php']['min'], 'lt' ) || - version_compare( PHP_VERSION, $cp_api_parameters['php']['max'], 'gt' ) - ) + version_compare( PHP_VERSION, $cp_api_parameters['php']['min'], 'lt' ) || + version_compare( PHP_VERSION, $cp_api_parameters['php']['max'], 'gt' ) ) { $preflight_checks['php_version'] = false; echo "\n$icon_preflight_fail\n\n"; @@ -790,10 +806,13 @@ function classicpress_show_migration_controls() {

    - Please make a Complete Backup of your Site Files and Database now!.', 'switch-to-classicpress' ); ?> + Please make a Complete Backup of your Site Files and Database before you continue!.', 'switch-to-classicpress' ); ?> +

    +

    + After the Initial Migration, you must visit the Updates Page and Press the Re-Install Now button!
    This is needed to complete the switch to ClassicPress and to insure you get the latest updates.', 'switch-to-classicpress' ); ?>

    - +

    @@ -908,39 +949,29 @@ class="hidden" >

    -

    -

    "; -$myversion = "1.7.1"; -$cp_url = get_migration_from_cp_version($myversion); -echo $cp_url; -*/ ?> -

    + - - diff --git a/switch-to-classicpress.php b/switch-to-classicpress.php index 0cc1a0c..03292e2 100644 --- a/switch-to-classicpress.php +++ b/switch-to-classicpress.php @@ -222,7 +222,6 @@ function classicpress_migration_parameters() { * * @return array|false Array of CP versions or false on API failure. */ -/* function get_cp_versions() { $cp_versions = get_transient( 'classicpress_release_versions' ); @@ -299,4 +298,41 @@ function get_migration_from_cp_version($version) { $url = 'https://github.com/ClassyBot/ClassicPress-v'.$major.'-nightly/releases/download/'.$version.'%2Bmigration.'.$day.'/ClassicPress-nightly-'.$version.'-migration.'.$day.'.zip'; return $url; } -*/ \ No newline at end of file + +/** + * Get release URL. + * + * @param string $version Version to retrive migration URL. + * + * @return string URL for release. + */ +function getReleaseFromCPVersion($version) { + return 'https://github.com/ClassicPress/ClassicPress-release/archive/refs/tags/'.$version.'.zip'; +} + +/** + * Get previous release version. + * + * @param string $version Version to get previous release. + * @param array $versions Array of ClassicPress versions as + * returned by getCPVersions(). + * Used for caching. + * + * @return string|bool Previous version. False if not found. + */ +function get_previous_version($version, $versions = []) { + if (empty($versions)) { +// $versions = self::getCPVersions(); + $versions = get_cp_versions(); + } else { + usort($versions, 'version_compare'); + } + if(!in_array($version, $versions)) { + return false; + } + $pos = array_search($version, $versions, true); + if(!isset($versions[$pos - 1])) { + return false; + } + return $versions[$pos - 1];; +} \ No newline at end of file From 8183c95318a8d64096b47ac9ea852df1ab6ba001 Mon Sep 17 00:00:00 2001 From: EliteStarServices Date: Sun, 10 Mar 2024 21:36:38 -0400 Subject: [PATCH 03/30] On branch master Your branch is up to date with 'origin/master'. Changes to be committed: modified: lib/admin-page.php --- lib/admin-page.php | 94 ++++++++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 40 deletions(-) diff --git a/lib/admin-page.php b/lib/admin-page.php index 4bebfe1..2702b35 100644 --- a/lib/admin-page.php +++ b/lib/admin-page.php @@ -115,6 +115,10 @@ function classicpress_print_admin_styles() { width: 100%; max-width: 50em; } +#picker-label { + display: block; + margin-bottom: 0.75em; +}

    Migration Builds!', + 'You can use this tool to install another version of ClassicPress or WordPress.', 'switch-to-classicpress' ); ?>

    will not work for migration.', + 'Release Builds of ClassicPress do not work for migration from WordPress.', 'switch-to-classicpress' ); ?>

    @@ -956,25 +987,20 @@ class="hidden"

    - +

    However, that doesn't mean it will be successful in all cases!", + 'If all requirements for your custom version have been met, then migration should complete.

    That does not mean it will be successful in every case and Older Versions May Not be Secure!

    ', 'switch-to-classicpress' ); ?>

    Complete Backup of your Site before using this feature with caution!', + 'Please, make a Complete Backup of your Site before using this tool At Your Own Risk!', 'switch-to-classicpress' ); ?>

    @@ -993,16 +1019,35 @@ class="hidden"