Last active
October 16, 2023 21:02
-
-
Save MonteLogic/1efa3713736863663ff854797a56ca9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Starting update via different method. | |
| * | |
| * @param object $transient The update request for plugin. | |
| */ | |
| function myplugin_check_for_update( $transient ) { | |
| error_log( 'hello' ); | |
| if ( empty( $transient->checked ) ) { | |
| return $transient; | |
| } | |
| $plugin_slug = plugin_basename( __FILE__ ); | |
| $plugin_data = get_plugin_data( __FILE__ ); | |
| $plugin_version = $plugin_data['Version']; | |
| $api_url = 'https://ec.wp2mag.com/ec-plus-fundraiser/update.php'; | |
| $response = wp_remote_get( $api_url ); | |
| if ( is_wp_error( $response ) ) { | |
| return false; | |
| } | |
| $response_body = wp_remote_retrieve_body( $response ); | |
| $json = json_decode( $response_body ); | |
| if ( version_compare( $plugin_version, $json->new_version, '<' ) ) { | |
| $transient->response[ $plugin_slug ] = (object) array( | |
| 'slug' => $plugin_slug, | |
| 'new_version' => $json->new_version, | |
| 'url' => $json->package_url, | |
| 'package' => $json->package_url, | |
| ); | |
| } | |
| return $transient; | |
| } | |
| add_filter( 'pre_set_site_transient_update_plugins', 'myplugin_check_for_update' ); | |
| /** | |
| * Add the filter to run on init | |
| * | |
| * @return void | |
| */ | |
| function run_plugin_update_check() { | |
| wp_version_check(); // Manually trigger the pre_set_site_transient_update_plugins filter. | |
| error_log( 'Version check occurred' ); | |
| } | |
| add_action( 'init', 'run_plugin_update_check' ); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $plugin_slug = 'ec-plus-fundraiser'; // Replace with your actual plugin slug | |
| $plugin_zip_url = 'https://ec.wp2mag.com/ec-plus-fundraiser/zips/ec-plus-fundraiser.zip'; // Replace with the URL of your plugin ZIP file | |
| // Get the current version of the plugin | |
| $current_version = isset($_POST['version']) ? $_POST['version'] : ''; | |
| // Check if the current version is less than the latest version | |
| if (version_compare($current_version, '1.0.0', '<')) { // Replace '1.0.0' with your actual latest version number | |
| $update_info = array( | |
| 'slug' => $plugin_slug, | |
| 'new_version' => '1.0.0', // Replace with your actual latest version number | |
| 'url' => $plugin_zip_url, | |
| 'package' => $plugin_zip_url, | |
| ); | |
| echo json_encode($update_info); | |
| } else { | |
| echo 'No updates available'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment