PHP code example of varunsridharan / wp-plugin-version-management

1. Go to this page and download the library: Download varunsridharan/wp-plugin-version-management library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

varunsridharan / wp-plugin-version-management example snippets


array(
	'1.0' => array(
		'user_id' => 1, // Stores Current User ID who install / upgrades the plugin
		'time'    => 2999391, // Stores Upgrade As Timestamp using `current_time('timestamp')`
		'from'    => false, // Which Version is upgraded from | false means its a fresh install
	),
	'1.1' => array(
		'user_id' => 1, // Stores Current User ID who install / upgrades the plugin
		'time'    => 3949391, // Stores Upgrade As Timestamp using `current_time('timestamp')`
		'from'    => '1.0', // Which Version is upgraded from | false means its a fresh install
	),
);

array(
	'your-plugin-slug'    => array(
		'version' => '',
		'logs'    => '',
	),
	'another-plugin-slug' => array(
		'version' => '',
		'logs'    => array(),
	),
);



register_activation_hook( __FILE__, 'your_plugin_activation' );

if ( ! function_exists( 'your_plugin_install_v1' ) ) {
	function your_plugin_install_v1( $from_version = false, $to_version = false ) {
		// do your stuff.
		return true; // should return something | return true if update is sucess / return false
	}
}

if ( ! function_exists( 'your_plugin_install_v1_1' ) ) {
	function your_plugin_install_v1_1( $from_version = false, $to_version = false ) {
		// do your stuff.
		return true; // should return something | return true if update is sucess / return false
	}
}

if ( ! function_exists( 'your_plugin_activation' ) ) {
	function your_plugin_activation() {
		$upgrader = new Varunsridharan\WordPress\Plugin_Version_Management( array(
			'slug'    => 'your-plugin-slug', // Uniquq Slug For Your Plugin.
			'logs'    => true, // Set True to save upgrade logs.
			'version' => '1.2', // Your Plugins New Version
		), array(
			'1.0' => 'your_plugin_install_v1',
			'1.1' => 'your_plugin_install_v1_1',
		) );

		$upgrader->run(); // Run Function Should Be Called.
	}
}


$upgrader = new Varunsridharan\WordPress\Plugin_Version_Management( array(
    'slug'    => 'your-plugin-slug', // Uniquq Slug For Your Plugin.
    'option_name'=> true,// use the same value which is used in register_plugin_activation if not set it to true
));


// Returns Current Version
$upgrader->version();

// Returns Logs
$upgrader->logs();