Skip to content

Commit

Permalink
Remove action links completely, just for install via TGMPA.
Browse files Browse the repository at this point in the history
Returns false on the WP filter, if the current screen is the TGMPA page.
Otherwise returns existing action links.

Fixes #48.
  • Loading branch information
GaryJones committed Oct 17, 2011
1 parent f9e8f12 commit 521c502
Showing 1 changed file with 36 additions and 35 deletions.
71 changes: 36 additions & 35 deletions tgm-plugin-activation/class-tgm-plugin-activation.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function install_plugins_page() {
?>
<h2><?php echo esc_html( get_admin_page_title() ); ?></h2>
<?php

$installed_plugins = get_plugins();

foreach ( $this->plugins as $plugin ) {
Expand All @@ -248,7 +248,7 @@ public function install_plugins_page() {
continue;

if ( ! isset( $installed_plugins[$plugin['file_path']] ) ) { // Plugin is not installed

if ( $plugin['required'] )
echo '<div class="instructions"><p>' . sprintf( $this->strings['instructions_install'], '<strong>' . $plugin['name'] . '</strong>' ) . '</p>'; // Leave <div> tag open, close after the form has been printed
else // This plugin is only recommended
Expand Down Expand Up @@ -353,23 +353,23 @@ protected function do_plugin_install() {
$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 urldecode()

$plugin_activate = $upgrader->plugin_info(); // Grab the plugin info from the Plugin_Upgrader method

wp_cache_flush(); // Flush the cache to remove plugin header errors

$activate = activate_plugin( $plugin_activate ); // Activate the plugin

$this->populate_file_path(); // Re-populate the file path now that the plugin has been installed and activated

if ( is_wp_error( $activate ) ) {
echo '<div id="message" class="error"><p>' . $activate->get_error_message() . '</p></div>';
echo '<a href="' . add_query_arg( 'page', $this->menu, admin_url( 'themes.php' ) ) . '" title="' . esc_attr( $this->strings['return'] ) . '" target="_parent">' . __( 'Return to Required Plugins Installer', $this->domain ) . '</a>';
return true; // End it here if there is an error with automatic activation
}
else {
echo '<p>' . $this->strings['plugin_activated'] . '</p>';

foreach ( $this->plugins as $plugin ) {

if ( ! is_plugin_active( $plugin['file_path'] ) ) {
Expand All @@ -380,7 +380,7 @@ protected function do_plugin_install() {
}

}

}

}
Expand Down Expand Up @@ -447,27 +447,27 @@ public function notices() {
$message['notice_cannot_activate'][] = $plugin['name'];

}

}

if ( ! get_user_meta( get_current_user_id(), 'tgmpa_dismissed_notice', true ) ) {

krsort( $message );
if ( ! empty( $message ) ) {

if ( ! empty( $message ) ) {

$rendered = ''; // Display all nag messages as strings

foreach ( $message as $type => $plugin_groups ) { // Grab all plugin names

asort( $plugin_groups );
$name = array_pop( $plugin_groups ); // Pop off last name to prep for readability
$imploded = empty( $plugin_groups ) ? '<em>' . $name . '</em>' : '<em>' . ( implode( ', ', $plugin_groups ) . '</em> and <em>' . $name . '</em>' );

$rendered .= '<p>' . sprintf( $this->strings[$type], $imploded ) . '</p>'; // All messages now stored

}

/** Define all of the action links */
$action_links = apply_filters( 'tgmpa_notice_action_links', array(
'install' => '<a href="' . add_query_arg( 'page', $this->menu, admin_url( 'themes.php' ) ) . '">' . __( 'Begin installing plugins', $this->domain ) . '</a>',
Expand All @@ -477,14 +477,14 @@ public function notices() {

if ( $action_links )
$rendered .= '<p>' . implode( ' | ', $action_links ) . '</p>';

add_settings_error( 'tgmpa', 'tgmpa', $rendered, 'updated' );


}

}

settings_errors( 'tgmpa' );

}
Expand Down Expand Up @@ -526,7 +526,7 @@ public function styles() {
'</style>';

}

/**
* Add dismissable admin notices.
*
Expand All @@ -535,10 +535,10 @@ public function styles() {
* @since 2.1.0
*/
public function dismiss() {

if ( isset( $_GET[sanitize_key( 'tgmpa-dismiss' )] ) )
update_user_meta( get_current_user_id(), 'tgmpa_dismissed_notice', 1 );

}

/**
Expand Down Expand Up @@ -595,26 +595,27 @@ public function config( $config ) {
*/
public function actions( $install_actions ) {

unset( $install_actions['plugins_page'] );
unset( $install_actions['activate_plugin'] );
unset( $install_actions['importers_page'] );
unset( $install_actions['network_activate'] );

global $current_screen;

// Remove action links on the TGMPa install page
if ( 'appearance_page_' . $this->menu == $current_screen->id )
return false;

return $install_actions;

}

/**
* Set file_path key for each installed plugin.
*
* @since 2.1.0
*/
public function populate_file_path() {

// Add file_path key for all plugins
foreach( $this->plugins as $plugin => $values )
$this->plugins[$plugin]['file_path'] = $this->_get_plugin_basename_from_slug( $values['slug'] );

}

/**
Expand Down

0 comments on commit 521c502

Please sign in to comment.