From: Chuck Scott Date: Mon, 7 Oct 2019 20:09:30 +0000 (-0400) Subject: Added WordPress_Notes.txt X-Git-Tag: v1.0.0~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=3e2d9bdb92d0801a46df4000279641f192c44019;p=prog%2Fglm-documentation.git Added WordPress_Notes.txt --- diff --git a/WordPress_Notes.txt b/WordPress_Notes.txt new file mode 100644 index 0000000..7a47766 --- /dev/null +++ b/WordPress_Notes.txt @@ -0,0 +1,114 @@ +WordPress Notes: + +* Programatically Install/Upgrade Plugins + + + + + +Programatically Install/Upgrade Plugins +--------------------------------------- + +From site... +https://wpreset.com/programmatically-automatically-download-install-activate-wordpress-plugins/ + + +// pseudo code only! +// DO NOT copy & paste + +var $old_plugin; +var $new_plugin; + +if ( is_plugin_installed( $new_plugin ) ) { + // new plugin is already installed + // make sure we have the last version + upgrade_plugin( $new_plugin ); +} else { + install_plugin( $new_plugin ); +} + +if ( !is_plugin_active( $new_plugin ) ) { + // new plugin is not active - activate it + activate_plugin( $new_plugin ); +} + +// deactivate old plugin +deactivate_plugin( $old_plugin ); + +// if needed delete old plugin +delete_plugin( $old_plugin ); + +// pseudo code only! +// DO NOT copy & paste + + +// Support Functions + +function replace_plugin() { + // modify these variables with your new/old plugin values + $plugin_slug = 'wp-reset/wp-reset.php'; + $plugin_zip = 'https://downloads.wordpress.org/plugin/wp-reset.latest-stable.zip'; + $old_plugin_slug = 'reset-wp/reset-wp.php'; + + echo 'If things are not done in a minute click here to return to Plugins page

'; + echo 'Starting ...

'; + + echo 'Check if new plugin is already installed - '; + if ( is_plugin_installed( $plugin_slug ) ) { + echo 'it\'s installed! Making sure it\'s the latest version.'; + upgrade_plugin( $plugin_slug ); + $installed = true; + } else { + echo 'it\'s not installed. Installing.'; + $installed = install_plugin( $plugin_zip ); + } + + if ( !is_wp_error( $installed ) && $installed ) { + echo 'Activating new plugin.'; + $activate = activate_plugin( $plugin_slug ); + + if ( is_null($activate) ) { + echo '
Deactivating old plugin.
'; + deactivate_plugins( array( $old_plugin_slug ) ); + + echo '
Done! Everything went smooth.'; + } + } else { + echo 'Could not install the new plugin.'; + } +} + +function is_plugin_installed( $slug ) { + if ( ! function_exists( 'get_plugins' ) ) { + require_once ABSPATH . 'wp-admin/includes/plugin.php'; + } + $all_plugins = get_plugins(); + + if ( !empty( $all_plugins[$slug] ) ) { + return true; + } else { + return false; + } +} + +function install_plugin( $plugin_zip ) { + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; + wp_cache_flush(); + + $upgrader = new Plugin_Upgrader(); + $installed = $upgrader->install( $plugin_zip ); + + return $installed; +} + +function upgrade_plugin( $plugin_slug ) { + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; + wp_cache_flush(); + + $upgrader = new Plugin_Upgrader(); + $upgraded = $upgrader->upgrade( $plugin_slug ); + + return $upgraded; +} + +