Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updated dev

  • Loading branch information...
commit 4ab2fd1412b69c2c2372d9e2b826dc0acd00db1a 1 parent 44646b1
@thomasgriffin thomasgriffin authored
View
0  tgm-plugin-activation/admin-css.css 100644 → 100755
File mode changed
View
214 tgm-plugin-activation/auto-install.php 100644 → 100755
@@ -2,19 +2,19 @@
/**
* Plugin installation and activation for WordPress themes.
*
- * @package TGM Plugin Activation
- * @version 1.1.0
- * @author Thomas Griffin <thomas@thomasgriffinmedia.com>
- * @copyright Copyright (c) 2011, Thomas Griffin
- * @license http://opensource.org/licenses/gpl-3.0.php GPL v3
- * @link https://github.com/thomasgriffin/TGM-Plugin-Activation
+ * @package TGM-Plugin-Activation
+ * @version 1.1.0
+ * @author Thomas Griffin <thomas@thomasgriffinmedia.com>
+ * @copyright Copyright (c) 2011, Thomas Griffin
+ * @license http://opensource.org/licenses/gpl-3.0.php GPL v3
+ * @link https://github.com/thomasgriffin/TGM-Plugin-Activation
*/
-
-
-/* Copyright 2011 Thomas Griffin (email : thomas@thomasgriffinmedia.com)
+
+/*
+ Copyright 2011 Thomas Griffin (email : thomas@thomasgriffinmedia.com)
This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License, version 3, as
+ it under the terms of the GNU General Public License, version 3, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
@@ -25,102 +25,104 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
*/
-
/**
- * Auto installation and activation class.
+ * Automatic plugin installation and activation class.
+ *
+ * Creates a way to automatically install and activate plugins from within themes.
+ * The plugins can be either pre-packaged or downloaded from the WordPress
+ * Plugin Repository.
*
- * Creates a new way to automatically install and activate plugins from within themes.
- * The plugins can be either pre-packaged or downloaded from the WordPress Plugin Repository.
+ * @since 1.0.0
*
+ * @package TGM-Plugin-Activation
* @author Thomas Griffin <thomas@thomasgriffinmedia.com>
*/
class TGM_Plugin_Activation {
-
+
var $instance; // DO NOT MODIFY THIS
-
+
var $domain = 'tgmpa'; // Sets the textdomain for localization support
-
- // All of the variables below can be modified to suit your specific plugin.
-
+
+ // All of the variables below can be modified to suit your specific plugin.
+
var $args = array(
- array(
- 'plugin' => 'tgm-example-plugin/tgm-example-plugin.php', // The main plugin file (including the plugin folder)
- 'plugin_name' => 'TGM Example Plugin', // The name of your plugin
+ array(
+ 'plugin' => 'tgm-example-plugin/tgm-example-plugin.php', // The main plugin file (including the plugin folder)
+ 'plugin_name' => 'TGM Example Plugin', // The name of your plugin
'zip_file' => 'tgm-example-plugin.zip', // The name of your zip file (if no zip file, leave empty - see below)
'repo_file' => '', // The zip file to get from the repo (if no repo file, leave empty - see below for example if in use)
'input_name' => 'tgm_tpe' // The form submit input name (used for checks and security
),
- array(
- 'plugin' => 'edit-howdy/edithowdy.php',
- 'plugin_name' => 'Edit Howdy',
- 'zip_file' => '',
- 'repo_file' => 'http://downloads.wordpress.org/plugin/edit-howdy.zip',
- 'input_name' => 'tgm_eh'
+ array(
+ 'plugin' => 'edit-howdy/edithowdy.php',
+ 'plugin_name' => 'Edit Howdy',
+ 'zip_file' => '',
+ 'repo_file' => 'http://downloads.wordpress.org/plugin/edit-howdy.zip',
+ 'input_name' => 'tgm_eh'
)
);
-
+
var $menu = 'install-required-plugins';
-
-
+
+
/**
* Adds actions for class methods.
*
- * Adds three new methods for the class: admin_menu, admin_notices and admin_print_styles.
+ * Adds three new methods for the class: admin_menu, admin_notices and admin_print_styles.
* admin_notices handles the nag, admin_menu handles the bulk, and admin_print_styles prints the CSS.
- *
+ *
* @since 1.0.0
*
* @author Thomas Griffin <thomas@thomasgriffinmedia.com>
*/
public function __construct() {
-
+
$this->instance =& $this;
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
add_action( 'admin_print_styles', array( $this, 'admin_print_styles' ) );
-
+
}
-
-
+
+
/**
* Adds submenu page under 'Appearance' tab.
*
- * This method adds the submenu page letting users know that a required plugin needs to be installed.
+ * This method adds the submenu page letting users know that a required plugin needs to be installed.
* This page disappears once the plugin has been installed and activated.
- *
+ *
* @since 1.0.0
*
* @author Thomas Griffin <thomas@thomasgriffinmedia.com>
*/
public function admin_menu() {
-
+
if ( ! current_user_can( 'install_plugins' ) ) // Make sure privileges are correct to see the page
return;
-
+
foreach ( $this->args as $args ) {
-
+
if ( ! is_plugin_active( $args['plugin'] ) ) {
-
+
add_theme_page( __( 'Install Required Plugins', $this->domain ), __( 'Install Plugins', $this->domain ), 'edit_theme_options', $this->menu, array( $this, 'install_plugins_page' ) );
break;
-
+
}
-
+
}
-
+
}
-
-
+
+
/**
* Outputs plugin installation form.
*
- * This method is the callback for the admin_menu method function.
+ * This method is the callback for the admin_menu method function.
* This displays the admin page and form area where the user can select to install and activate the plugin.
- *
+ *
* @since 1.0.0
*
* @author Thomas Griffin <thomas@thomasgriffinmedia.com>
@@ -129,47 +131,47 @@ public function install_plugins_page() {
if ( $this->do_plugin_install() )
return;
-
+
echo '<div id="tgmpa-form" class="wrap">';
_e( '<h2>Install Required Plugins</h2>', $this->domain );
-
+
$plugins = get_plugins();
-
+
foreach ( $this->args as $form ) {
-
+
if ( is_plugin_active( $form['plugin'] ) ) // If the plugin is active, no need to display the form
continue;
-
+
if ( ! isset( $plugins[$form['plugin']] ) ) { // Plugin is not installed
-
+
_e( '<div class="instructions"><p>The <strong>' . $form['plugin_name'] . '</strong> plugin is required for this theme. Click on the big blue button below to install and activate <strong>' . $form['plugin_name'] . '</strong>!</p>', $this->domain );
-
+
} elseif ( is_plugin_inactive( $form['plugin'] ) ) { // The plugin is installed but not active
-
+
_e( '<div class="instructions"><p>The <strong>' . $form['plugin_name'] . '</strong> is installed but currently inactive. Please go to the <a href="' . admin_url( 'plugins.php' ) . '">plugin administration page</a> page to activate it.</p></div>', $this->domain );
continue; // No need to display a form because it is already installed, just needs to be activated
-
+
} ?>
-
+
<form id="tgmpa-go" action="" method="post">
<?php wp_nonce_field( 'tgm_pa', 'tgm_pa_nonce' );
echo "<input name='{$form['input_name']}' class='button-primary' type='submit' value='Install {$form['plugin_name']} Now!' />"; ?>
</form>
</div><!-- closing div if plugin is not installed -->
-
+
<?php } ?>
</div>
<?php
-
+
}
-
-
+
+
/**
* Installs and activates the plugin.
*
* This method function actually installs the plugin. It instantiates the WP_Filesystem Abstraction class to do the heavy lifting.
* Any errors are displayed using the WP_Error class.
- *
+ *
* @since 1.0.0
*
* @author Thomas Griffin <thomas@thomasgriffinmedia.com>
@@ -181,40 +183,40 @@ public function install_plugins_page() {
* @return boolean, true on success, false on failure
*/
public function do_plugin_install() {
-
+
foreach ( $this->args as $instance ) { // Iterate and perform the action for each plugin in the array
-
+
if ( empty( $_POST ) ) // Bail out if the global $_POST is empty
return false;
-
+
check_admin_referer( 'tgm_pa', 'tgm_pa_nonce' ); // Security check
-
+
$fields = array( $instance['input_name'] );
$method = ''; // Leave blank so WP_Filesystem can populate it as necessary
-
+
if ( isset( $_POST[$instance['input_name']] ) ) { // Don't do anything if the form has not been submitted
-
+
$url = wp_nonce_url( 'themes.php?page=' . $this->menu . '', 'tgm_pa' ); // Make sure we are coming from the right page
if ( false === ( $creds = request_filesystem_credentials( $url, $method, false, false, $fields ) ) )
return true;
-
+
if ( ! WP_Filesystem( $creds ) ) {
-
+
request_filesystem_credentials( $url, $method, false, false, $fields ); // Setup WP_Filesystem
return true;
-
+
}
-
+
global $wp_filesystem; // Introduce global $wp_filesystem to use WP_Filesystem class methods
-
+
// This section is specifically for plugins pre-packaged with the theme
- if ( isset( $instance['zip_file'] ) && '' !== $instance['zip_file'] ) {
-
+ if ( isset( $instance['zip_file'] ) && '' !== $instance['zip_file'] ) {
+
$source = get_stylesheet_directory() . '/lib/tgm-plugin-activation/plugins/' . $instance['zip_file']; // The source zip file
-
+
include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // Need for plugins_api
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; // Need for upgrade classes
-
+
$api = plugins_api( 'plugin_information', array( 'slug' => $instance['plugin'], 'fields' => array( 'sections' => false ) ) );
if ( is_wp_error( $api ) )
@@ -230,28 +232,28 @@ public function do_plugin_install() {
$type = 'upload'; // Important distinction
$upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact( 'title', 'url', 'nonce', 'plugin', 'api' ) ) ); // Create a new instance of Plugin_Upgrader
-
+
$upgrader->install( $source ); // Perform the action and install the plugin from the $source URL
-
+
if ( is_wp_error( $upgrader ) ) { // Spit out an error if any exists
$upgrader_error = $upgrader->get_error_message();
echo '<div id="message" class="installation error"><p>' . $upgrader_error . '</p></div>';
return false;
}
-
+
}
-
+
// This section is specifically for plugins automatically downloaded from the WordPress Plugin Repository
else {
-
+
include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // Need for plugins_api
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; // Need for upgrade classes
-
+
$api = plugins_api( 'plugin_information', array( 'slug' => $instance['plugin'], 'fields' => array( 'sections' => false ) ) );
if ( is_wp_error( $api ) )
wp_die( $api );
-
+
// Prep variables for Plugin_Installer_Skin class
$title = sprintf( __( 'Installing Plugin: %s'), $instance['plugin_name'], $this->domain );
$nonce = 'install-plugin_' . $instance['plugin'];
@@ -262,26 +264,26 @@ public function do_plugin_install() {
$type = 'web'; // Set this to web for tailored output messages
$upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact( 'title', 'url', 'nonce', 'plugin', 'api' ) ) ); // Create a new instance of Plugin_Upgrader
-
+
$upgrader->install( $instance['repo_file'] ); // Perform the action and install the plugin from the Repository
-
+
if ( is_wp_error( $upgrader ) ) { // Spit out an error if any exists
$upgrader_error = $upgrader->get_error_message();
echo '<div id="message" class="installation error"><p>' . $upgrader_error . '</p></div>';
return false;
}
-
+
}
-
+
}
-
+
}
-
+
return true;
-
+
}
-
+
/**
* Display required notice nag.
*
@@ -299,7 +301,7 @@ public function do_plugin_install() {
public function admin_notices( $output ) {
global $current_screen;
-
+
if ( 'appearance_page_install-required-plugins' == $current_screen->id ) // Remove nag on the install pages
return;
@@ -315,10 +317,10 @@ public function admin_notices( $output ) {
$output = printf( '<div id="tgm-plugin-activation" class="updated"><p>%1$s</p></div>', $message );
} else { // Need higher privileges to install the plugin
-
+
$message = sprintf( __( 'Sorry, but you do not have the correct permissions to install the <strong>' . $args['plugin_name'] . '</strong> plugin. Contact the administrator of this site for help on getting the plugin installed.', $this->domain ) );
$output = printf( '<div id="tgm-plugin-activation" class="updated"><p>%1$s</p></div>', $message );
-
+
}
@@ -330,10 +332,10 @@ public function admin_notices( $output ) {
$output = printf( '<div id="tgm-plugin-inactive" class="updated"><p>%1$s</p></div>', $message );
} else { // Need higher privileges to activate the plugin
-
+
$message = sprintf( __( 'Sorry, but you do not have the correct permissions to activate the <strong>' . $args['plugin_name'] . '</strong> plugin. Contact the administrator of this site for help on getting the plugin activated.', $this->domain ) );
$output = printf( '<div id="tgm-plugin-inactive" class="updated"><p>%1$s</p></div>', $message );
-
+
}
}
@@ -341,8 +343,8 @@ public function admin_notices( $output ) {
}
}
-
-
+
+
/**
* Print admin stylesheet.
*
@@ -356,12 +358,12 @@ public function admin_notices( $output ) {
* @return string HTML markup
*/
public function admin_print_styles() {
-
+
global $current_screen;
-
+
if ( 'appearance_page_install-required-plugins' == $current_screen->id ) // Only load the CSS file on our page
wp_enqueue_style( 'tgmpa-admin', get_stylesheet_directory_uri() . '/lib/tgm-plugin-activation/admin-css.css' );
-
+
}
}
View
0  tgm-plugin-activation/plugins/tgm-example-plugin.zip 100644 → 100755
File mode changed
Please sign in to comment.
Something went wrong with that request. Please try again.