protected function activate()
 {
     foreach ($this->plugins as $plugin) {
         if (!$this->network_wide && Jetpack::is_plugin_active($plugin) || is_plugin_active_for_network($plugin)) {
             $this->log[$plugin]['error'] = __('The Plugin is already active.', 'jetpack');
             $has_errors = true;
             continue;
         }
         if (!$this->network_wide && is_network_only_plugin($plugin) && is_multisite()) {
             $this->log[$plugin]['error'] = __('Plugin can only be Network Activated', 'jetpack');
             $has_errors = true;
             continue;
         }
         $result = activate_plugin($plugin, '', $this->network_wide);
         if (is_wp_error($result)) {
             $this->log[$plugin]['error'] = $result->get_error_messages();
             $has_errors = true;
             continue;
         }
         $success = Jetpack::is_plugin_active($plugin);
         if ($success && $this->network_wide) {
             $success &= is_plugin_active_for_network($plugin);
         }
         if (!$success) {
             $this->log[$plugin]['error'] = $result->get_error_messages;
             $has_errors = true;
             continue;
         }
         $this->log[$plugin][] = __('Plugin activated.', 'jetpack');
     }
     if (!$this->bulk && isset($has_errors)) {
         $plugin = $this->plugins[0];
         return new WP_Error('activation_error', $this->log[$plugin]['error']);
     }
 }
 function prepare_items()
 {
     global $status, $plugins, $totals, $page, $orderby, $order, $s;
     wp_reset_vars(array('orderby', 'order', 's'));
     $plugins = array('all' => apply_filters('all_plugins', get_plugins()), 'search' => array(), 'active' => array(), 'inactive' => array(), 'recently_activated' => array(), 'upgrade' => array(), 'mustuse' => array(), 'dropins' => array());
     $screen = get_current_screen();
     if (!is_multisite() || $screen->is_network && current_user_can('manage_network_plugins')) {
         if (apply_filters('show_advanced_plugins', true, 'mustuse')) {
             $plugins['mustuse'] = get_mu_plugins();
         }
         if (apply_filters('show_advanced_plugins', true, 'dropins')) {
             $plugins['dropins'] = get_dropins();
         }
         $current = get_site_transient('update_plugins');
         foreach ((array) $plugins['all'] as $plugin_file => $plugin_data) {
             if (isset($current->response[$plugin_file])) {
                 $plugins['upgrade'][$plugin_file] = $plugin_data;
             }
         }
     }
     set_transient('plugin_slugs', array_keys($plugins['all']), 86400);
     $recently_activated = get_option('recently_activated', array());
     $one_week = 7 * 24 * 60 * 60;
     foreach ($recently_activated as $key => $time) {
         if ($time + $one_week < time()) {
             unset($recently_activated[$key]);
         }
     }
     update_option('recently_activated', $recently_activated);
     foreach ((array) $plugins['all'] as $plugin_file => $plugin_data) {
         // Filter into individual sections
         if (is_multisite() && is_network_only_plugin($plugin_file) && !$screen->is_network) {
             unset($plugins['all'][$plugin_file]);
         } elseif (is_plugin_active_for_network($plugin_file) && !$screen->is_network) {
             unset($plugins['all'][$plugin_file]);
         } elseif (is_multisite() && is_network_only_plugin($plugin_file) && !current_user_can('manage_network_plugins')) {
             $plugins['network'][$plugin_file] = $plugin_data;
         } elseif (!$screen->is_network && is_plugin_active($plugin_file) || $screen->is_network && is_plugin_active_for_network($plugin_file)) {
             $plugins['active'][$plugin_file] = $plugin_data;
         } else {
             if (!$screen->is_network && isset($recently_activated[$plugin_file])) {
                 // Was the plugin recently activated?
                 $plugins['recently_activated'][$plugin_file] = $plugin_data;
             }
             $plugins['inactive'][$plugin_file] = $plugin_data;
         }
     }
     if (!current_user_can('update_plugins')) {
         $plugins['upgrade'] = array();
     }
     if ($s) {
         $status = 'search';
         $plugins['search'] = array_filter($plugins['all'], array(&$this, '_search_callback'));
     }
     $totals = array();
     foreach ($plugins as $type => $list) {
         $totals[$type] = count($list);
     }
     if (empty($plugins[$status]) && !in_array($status, array('all', 'search'))) {
         $status = 'all';
     }
     $this->items = array();
     foreach ($plugins[$status] as $plugin_file => $plugin_data) {
         // Translate, Don't Apply Markup, Sanitize HTML
         $this->items[$plugin_file] = _get_plugin_data_markup_translate($plugin_file, $plugin_data, false, true);
     }
     $total_this_page = $totals[$status];
     if ($orderby) {
         $orderby = ucfirst($orderby);
         $order = strtoupper($order);
         uasort($this->items, array(&$this, '_order_callback'));
     }
     $plugins_per_page = $this->get_items_per_page(str_replace('-', '_', $screen->id . '_per_page'));
     $start = ($page - 1) * $plugins_per_page;
     if ($total_this_page > $plugins_per_page) {
         $this->items = array_slice($this->items, $start, $plugins_per_page);
     }
     $this->set_pagination_args(array('total_items' => $total_this_page, 'per_page' => $plugins_per_page));
 }
Exemple #3
0
/**
 * Attempts activation of plugin in a "sandbox" and redirects on success.
 *
 * A plugin that is already activated will not attempt to be activated again.
 *
 * The way it works is by setting the redirection to the error before trying to
 * include the plugin file. If the plugin fails, then the redirection will not
 * be overwritten with the success message. Also, the options will not be
 * updated and the activation hook will not be called on plugin error.
 *
 * It should be noted that in no way the below code will actually prevent errors
 * within the file. The code should not be used elsewhere to replicate the
 * "sandbox", which uses redirection to work.
 * {@source 13 1}
 *
 * If any errors are found or text is outputted, then it will be captured to
 * ensure that the success redirection will update the error redirection.
 *
 * @since 2.5.0
 *
 * @param string $plugin Plugin path to main plugin file with plugin data.
 * @param string $redirect Optional. URL to redirect to.
 * @param bool $network_wide Whether to enable the plugin for all sites in the
 *   network or just the current site. Multisite only. Default is false.
 * @param bool $silent Prevent calling activation hooks. Optional, default is false.
 * @return WP_Error|null WP_Error on invalid file or null on success.
 */
function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) {
	$plugin = plugin_basename( trim( $plugin ) );

	if ( is_multisite() && ( $network_wide || is_network_only_plugin($plugin) ) ) {
		$network_wide = true;
		$current = get_site_option( 'active_sitewide_plugins', array() );
		$_GET['networkwide'] = 1; // Back compat for plugins looking for this value.
	} else {
		$current = get_option( 'active_plugins', array() );
	}

	$valid = validate_plugin($plugin);
	if ( is_wp_error($valid) )
		return $valid;

	if ( ( $network_wide && ! isset( $current[ $plugin ] ) ) || ( ! $network_wide && ! in_array( $plugin, $current ) ) ) {
		if ( !empty($redirect) )
			wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); // we'll override this later if the plugin can be included without fatal error
		ob_start();
		wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
		$_wp_plugin_file = $plugin;
		include_once( WP_PLUGIN_DIR . '/' . $plugin );
		$plugin = $_wp_plugin_file; // Avoid stomping of the $plugin variable in a plugin.

		if ( ! $silent ) {
			/**
			 * Fires before a plugin is activated.
			 *
			 * If a plugin is silently activated (such as during an update),
			 * this hook does not fire.
			 *
			 * @since 2.9.0
			 *
			 * @param string $plugin       Plugin path to main plugin file with plugin data.
			 * @param bool   $network_wide Whether to enable the plugin for all sites in the network
			 *                             or just the current site. Multisite only. Default is false.
			 */
			do_action( 'activate_plugin', $plugin, $network_wide );

			/**
			 * Fires as a specific plugin is being activated.
			 *
			 * This hook is the "activation" hook used internally by
			 * {@see register_activation_hook()}. The dynamic portion of the
			 * hook name, `$plugin`, refers to the plugin basename.
			 *
			 * If a plugin is silently activated (such as during an update),
			 * this hook does not fire.
			 *
			 * @since 2.0.0
			 *
			 * @param bool $network_wide Whether to enable the plugin for all sites in the network
			 *                           or just the current site. Multisite only. Default is false.
			 */
			do_action( 'activate_' . $plugin, $network_wide );
		}

		if ( $network_wide ) {
			$current = get_site_option( 'active_sitewide_plugins', array() );
			$current[$plugin] = time();
			update_site_option( 'active_sitewide_plugins', $current );
		} else {
			$current = get_option( 'active_plugins', array() );
			$current[] = $plugin;
			sort($current);
			update_option('active_plugins', $current);
		}

		if ( ! $silent ) {
			/**
			 * Fires after a plugin has been activated.
			 *
			 * If a plugin is silently activated (such as during an update),
			 * this hook does not fire.
			 *
			 * @since 2.9.0
			 *
			 * @param string $plugin       Plugin path to main plugin file with plugin data.
			 * @param bool   $network_wide Whether to enable the plugin for all sites in the network
			 *                             or just the current site. Multisite only. Default is false.
			 */
			do_action( 'activated_plugin', $plugin, $network_wide );
		}

		if ( ob_get_length() > 0 ) {
			$output = ob_get_clean();
			return new WP_Error('unexpected_output', __('The plugin generated unexpected output.'), $output);
		}
		ob_end_clean();
	}

	return null;
}
function exclude_plugins_no_network()
{
    $plugins = get_plugins();
    $network_plugins = array();
    foreach ((array) $plugins as $plugin => $plugin_data) {
        if (is_network_only_plugin($plugin)) {
            $network_plugins[$plugin] = $plugin_data;
        }
    }
    return array_diff_assoc($plugins, $network_plugins);
}
Exemple #5
0
/**
 * @deprecated 3.0.0
 * @see is_network_only_plugin()
 */
function is_wpmu_sitewide_plugin($file)
{
    _deprecated_function(__FUNCTION__, '3.0', 'is_network_only_plugin()');
    return is_network_only_plugin($file);
}
 public function prepare_items()
 {
     global $status, $plugins, $totals, $page, $orderby, $order, $s;
     wp_reset_vars(array('orderby', 'order', 's'));
     /**
      * Filter the full array of plugins to list in the Plugins list table.
      *
      * @since 3.0.0
      *
      * @see get_plugins()
      *
      * @param array $plugins An array of plugins to display in the list table.
      */
     $plugins = array('all' => apply_filters('all_plugins', get_plugins()), 'search' => array(), 'active' => array(), 'inactive' => array(), 'recently_activated' => array(), 'upgrade' => array(), 'mustuse' => array(), 'dropins' => array());
     $screen = $this->screen;
     if (!is_multisite() || $screen->in_admin('network') && current_user_can('manage_network_plugins')) {
         /**
          * Filter whether to display the advanced plugins list table.
          *
          * There are two types of advanced plugins - must-use and drop-ins -
          * which can be used in a single site or Multisite network.
          *
          * The $type parameter allows you to differentiate between the type of advanced
          * plugins to filter the display of. Contexts include 'mustuse' and 'dropins'.
          *
          * @since 3.0.0
          *
          * @param bool   $show Whether to show the advanced plugins for the specified
          *                     plugin type. Default true.
          * @param string $type The plugin type. Accepts 'mustuse', 'dropins'.
          */
         if (apply_filters('show_advanced_plugins', true, 'mustuse')) {
             $plugins['mustuse'] = get_mu_plugins();
         }
         /** This action is documented in wp-admin/includes/class-wp-plugins-list-table.php */
         if (apply_filters('show_advanced_plugins', true, 'dropins')) {
             $plugins['dropins'] = get_dropins();
         }
         if (current_user_can('update_plugins')) {
             $current = get_site_transient('update_plugins');
             foreach ((array) $plugins['all'] as $plugin_file => $plugin_data) {
                 if (isset($current->response[$plugin_file])) {
                     $plugins['all'][$plugin_file]['update'] = true;
                     $plugins['upgrade'][$plugin_file] = $plugins['all'][$plugin_file];
                 }
             }
         }
     }
     set_transient('plugin_slugs', array_keys($plugins['all']), DAY_IN_SECONDS);
     if (!$screen->in_admin('network')) {
         $recently_activated = get_option('recently_activated', array());
         foreach ($recently_activated as $key => $time) {
             if ($time + WEEK_IN_SECONDS < time()) {
                 unset($recently_activated[$key]);
             }
         }
         update_option('recently_activated', $recently_activated);
     }
     $plugin_info = get_site_transient('update_plugins');
     foreach ((array) $plugins['all'] as $plugin_file => $plugin_data) {
         // Extra info if known. array_merge() ensures $plugin_data has precedence if keys collide.
         if (isset($plugin_info->response[$plugin_file])) {
             $plugins['all'][$plugin_file] = $plugin_data = array_merge((array) $plugin_info->response[$plugin_file], $plugin_data);
         } elseif (isset($plugin_info->no_update[$plugin_file])) {
             $plugins['all'][$plugin_file] = $plugin_data = array_merge((array) $plugin_info->no_update[$plugin_file], $plugin_data);
         }
         // Filter into individual sections
         if (is_multisite() && !$screen->in_admin('network') && is_network_only_plugin($plugin_file) && !is_plugin_active($plugin_file)) {
             // On the non-network screen, filter out network-only plugins as long as they're not individually activated
             unset($plugins['all'][$plugin_file]);
         } elseif (!$screen->in_admin('network') && is_plugin_active_for_network($plugin_file)) {
             // On the non-network screen, filter out network activated plugins
             unset($plugins['all'][$plugin_file]);
         } elseif (!$screen->in_admin('network') && is_plugin_active($plugin_file) || $screen->in_admin('network') && is_plugin_active_for_network($plugin_file)) {
             // On the non-network screen, populate the active list with plugins that are individually activated
             // On the network-admin screen, populate the active list with plugins that are network activated
             $plugins['active'][$plugin_file] = $plugin_data;
         } else {
             if (!$screen->in_admin('network') && isset($recently_activated[$plugin_file])) {
                 // On the non-network screen, populate the recently activated list with plugins that have been recently activated
                 $plugins['recently_activated'][$plugin_file] = $plugin_data;
             }
             // Populate the inactive list with plugins that aren't activated
             $plugins['inactive'][$plugin_file] = $plugin_data;
         }
     }
     if ($s) {
         $status = 'search';
         $plugins['search'] = array_filter($plugins['all'], array($this, '_search_callback'));
     }
     $totals = array();
     foreach ($plugins as $type => $list) {
         $totals[$type] = count($list);
     }
     if (empty($plugins[$status]) && !in_array($status, array('all', 'search'))) {
         $status = 'all';
     }
     $this->items = array();
     foreach ($plugins[$status] as $plugin_file => $plugin_data) {
         // Translate, Don't Apply Markup, Sanitize HTML
         $this->items[$plugin_file] = _get_plugin_data_markup_translate($plugin_file, $plugin_data, false, true);
     }
     $total_this_page = $totals[$status];
     if ($orderby) {
         $orderby = ucfirst($orderby);
         $order = strtoupper($order);
         uasort($this->items, array($this, '_order_callback'));
     }
     $plugins_per_page = $this->get_items_per_page(str_replace('-', '_', $screen->id . '_per_page'), 999);
     $start = ($page - 1) * $plugins_per_page;
     if ($total_this_page > $plugins_per_page) {
         $this->items = array_slice($this->items, $start, $plugins_per_page);
     }
     $this->set_pagination_args(array('total_items' => $total_this_page, 'per_page' => $plugins_per_page));
 }
Exemple #7
0
 /**
  * Gets VC is activated as network plugin.
  *
  * @since  4.2
  * @access public
  *
  * @return bool
  */
 public function isNetworkPlugin()
 {
     if (is_null($this->is_network_plugin)) {
         // Check is VC as network plugin
         if (is_multisite() && (is_plugin_active_for_network($this->pluginName()) || is_network_only_plugin($this->pluginName()))) {
             $this->setAsNetworkPlugin(true);
         }
     }
     return $this->is_network_plugin ? true : false;
 }
Exemple #8
0
    function admin_page()
    {
        global $psts;
        if (isset($_POST['supporter_plugins'])) {
            $psts_plugins = array();
            if (is_array($_POST['plugins'])) {
                foreach ($_POST['plugins'] as $plugin => $value) {
                    $value['auto'] = $value['level'] == 'none' ? 0 : intval(@$value['auto']);
                    $psts_plugins[$plugin] = $value;
                }
                $psts->update_setting('pp_plugins', $psts_plugins);
                echo '<div id="message" class="updated fade"><p>' . __('Settings Saved!', 'psts') . '</p></div>';
            }
        }
        ?>
	  <div class="wrap">
    <div class="icon32" id="icon-plugins"></div>
    <h2><?php 
        _e('Premium Plugins', 'psts');
        ?>
</h2>
  	<p><?php 
        _e('Select the minimum Pro Site level for premium plugins that you want to enable for sites of that level or above. Checking Auto Activate will activate the plugin when they upgrade to that level. Network only and network activated plugins will not show in this list. Note you can also override plugin permissions on a per-site basis on the <a href="sites.php">edit sites</a> page.', 'psts');
        ?>
</p>

		<form method="post" action="">
		<table class="widefat">
  			<thead>
  				<tr>
  					<th style="width:25%;"><?php 
        _e('Minimum Level', 'psts');
        ?>
</th>
            <th style="width:20%;"><?php 
        _e('Plugin', 'psts');
        ?>
</th>
  					<th style="width:10%;"><?php 
        _e('Version', 'psts');
        ?>
</th>
  					<th><?php 
        _e('Description', 'psts');
        ?>
</th>
  				</tr>
  			</thead>
  			<tbody id="plugins">
  		  <?php 
        $plugins = get_plugins();
        $psts_plugins = (array) $psts->get_setting('pp_plugins');
        $levels = (array) get_site_option('psts_levels');
        foreach ($plugins as $file => $p) {
            //skip network only plugins
            if (is_network_only_plugin($file) || is_plugin_active_for_network($file)) {
                continue;
            }
            ?>
        	<tr>
        		<td>
        		<select name="plugins[<?php 
            echo $file;
            ?>
][level]">
             <option value="none"<?php 
            selected(@$psts_plugins[$file]['level'], 'none');
            ?>
><?php 
            _e('None', 'psts');
            ?>
</option>
             <option value="0"<?php 
            selected(@$psts_plugins[$file]['level'], 0);
            ?>
><?php 
            _e('Anyone', 'psts');
            ?>
</option>
             <?php 
            foreach ($levels as $level => $value) {
                ?>
<option value="<?php 
                echo $level;
                ?>
"<?php 
                selected(@$psts_plugins[$file]['level'], $level);
                ?>
><?php 
                echo $level . ': ' . esc_attr($value['name']);
                ?>
</option><?php 
            }
            ?>
            </select>
            <label><input type="checkbox" name="plugins[<?php 
            echo $file;
            ?>
][auto]" value="1"<?php 
            checked(@$psts_plugins[$file]['auto']);
            ?>
 /> <?php 
            _e('Auto Activate', 'psts');
            ?>
</label>
        		</td>
        		<th scope="row"><?php 
            echo $p['Name'];
            ?>
</th>
        		<th scope="row"><?php 
            echo $p['Version'];
            ?>
</th>
        		<td><?php 
            echo $p['Description'];
            ?>
</td>
          </tr>
        <?php 
        }
        ?>
  			</tbody>
  		</table>
  		
  		<p class="submit"><input type="submit" name="supporter_plugins" class="button-primary" value="<?php 
        _e('Save Changes', 'psts');
        ?>
" /></p>
  	</form>
		</div>
	  <?php 
    }
 /**
  * @covers ::is_network_only_plugin
  */
 public function test_is_network_only_plugin()
 {
     $p = $this->_create_plugin("<?php\n/*\nPlugin Name: test\nNetwork: true");
     $this->assertTrue(is_network_only_plugin($p[0]));
     unlink($p[1]);
 }
Exemple #10
0
 private function active_output($name, $file, $network_wide, $action)
 {
     $network_wide = $network_wide || is_multisite() && is_network_only_plugin($file);
     $check = $this->check_active($file, $network_wide);
     if ($action == "activate" ? $check : !$check) {
         if ($network_wide) {
             WP_CLI::success("Plugin '{$name}' network {$action}d.");
         } else {
             WP_CLI::success("Plugin '{$name}' {$action}d.");
         }
     } else {
         WP_CLI::warning("Could not {$action} the '{$name}' plugin.");
     }
 }
Exemple #11
0
 case 'activate-selected':
     if (!current_user_can('activate_plugins')) {
         wp_die(__('You do not have sufficient permissions to activate plugins for this site.'));
     }
     check_admin_referer('bulk-plugins');
     $plugins = isset($_POST['checked']) ? (array) $_POST['checked'] : array();
     // Only activate plugins which are not already active.
     if (is_network_admin()) {
         foreach ($plugins as $i => $plugin) {
             if (is_plugin_active_for_network($plugin)) {
                 unset($plugins[$i]);
             }
         }
     } else {
         foreach ($plugins as $i => $plugin) {
             if (is_plugin_active($plugin) || is_network_only_plugin($plugin)) {
                 unset($plugins[$i]);
             }
         }
     }
     if (empty($plugins)) {
         wp_redirect(self_admin_url("plugins.php?plugin_status={$status}&paged={$page}&s={$s}"));
         exit;
     }
     activate_plugins($plugins, self_admin_url('plugins.php?error=true'), is_network_admin());
     if (!is_network_admin()) {
         $recent = (array) get_option('recently_activated');
         foreach ($plugins as $plugin) {
             unset($recent[$plugin]);
         }
         update_option('recently_activated', $recent);
 /**
  * @global string $status
  * @global int $page
  * @global string $s
  * @global array $totals
  *
  * @param array $item
  */
 public function single_row($item)
 {
     global $status, $page, $s, $totals;
     list($plugin_file, $plugin_data) = $item;
     $context = $status;
     $screen = $this->screen;
     // Pre-order.
     $actions = array('deactivate' => '', 'activate' => '', 'details' => '', 'edit' => '', 'delete' => '');
     // Do not restrict by default
     $restrict_network_active = false;
     $restrict_network_only = false;
     if ('mustuse' === $context) {
         $is_active = true;
     } elseif ('dropins' === $context) {
         $dropins = _get_dropins();
         $plugin_name = $plugin_file;
         if ($plugin_file != $plugin_data['Name']) {
             $plugin_name .= '<br/>' . $plugin_data['Name'];
         }
         if (true === $dropins[$plugin_file][1]) {
             // Doesn't require a constant
             $is_active = true;
             $description = '<p><strong>' . $dropins[$plugin_file][0] . '</strong></p>';
         } elseif (defined($dropins[$plugin_file][1]) && constant($dropins[$plugin_file][1])) {
             // Constant is true
             $is_active = true;
             $description = '<p><strong>' . $dropins[$plugin_file][0] . '</strong></p>';
         } else {
             $is_active = false;
             $description = '<p><strong>' . $dropins[$plugin_file][0] . ' <span class="error-message">' . __('Inactive:') . '</span></strong> ' . sprintf(__('Requires %1$s in %2$s file.'), "<code>define('" . $dropins[$plugin_file][1] . "', true);</code>", '<code>wp-config.php</code>') . '</p>';
         }
         if ($plugin_data['Description']) {
             $description .= '<p>' . $plugin_data['Description'] . '</p>';
         }
     } else {
         if ($screen->in_admin('network')) {
             $is_active = is_plugin_active_for_network($plugin_file);
         } else {
             $is_active = is_plugin_active($plugin_file);
             $restrict_network_active = is_multisite() && is_plugin_active_for_network($plugin_file);
             $restrict_network_only = is_multisite() && is_network_only_plugin($plugin_file) && !$is_active;
         }
         if ($screen->in_admin('network')) {
             if ($is_active) {
                 if (current_user_can('manage_network_plugins')) {
                     /* translators: %s: plugin name */
                     $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" aria-label="' . esc_attr(sprintf(__('Network deactivate %s'), $plugin_data['Name'])) . '">' . __('Network Deactivate') . '</a>';
                 }
             } else {
                 if (current_user_can('manage_network_plugins')) {
                     /* translators: %s: plugin name */
                     $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file) . '" class="edit" aria-label="' . esc_attr(sprintf(__('Network Activate %s'), $plugin_data['Name'])) . '">' . __('Network Activate') . '</a>';
                 }
                 if (current_user_can('delete_plugins') && !is_plugin_active($plugin_file)) {
                     /* translators: %s: plugin name */
                     $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins') . '" class="delete" aria-label="' . esc_attr(sprintf(__('Delete %s'), $plugin_data['Name'])) . '">' . __('Delete') . '</a>';
                 }
             }
         } else {
             if ($restrict_network_active) {
                 $actions = array('network_active' => __('Network Active'));
             } elseif ($restrict_network_only) {
                 $actions = array('network_only' => __('Network Only'));
             } elseif ($is_active) {
                 /* translators: %s: plugin name */
                 $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" aria-label="' . esc_attr(sprintf(__('Deactivate %s'), $plugin_data['Name'])) . '">' . __('Deactivate') . '</a>';
             } else {
                 /* translators: %s: plugin name */
                 $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file) . '" class="edit" aria-label="' . esc_attr(sprintf(__('Activate %s'), $plugin_data['Name'])) . '">' . __('Activate') . '</a>';
                 if (!is_multisite() && current_user_can('delete_plugins')) {
                     /* translators: %s: plugin name */
                     $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins') . '" class="delete" aria-label="' . esc_attr(sprintf(__('Delete %s'), $plugin_data['Name'])) . '">' . __('Delete') . '</a>';
                 }
             }
             // end if $is_active
         }
         // end if $screen->in_admin( 'network' )
         if ((!is_multisite() || $screen->in_admin('network')) && current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file)) {
             /* translators: %s: plugin name */
             $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" class="edit" aria-label="' . esc_attr(sprintf(__('Edit %s'), $plugin_data['Name'])) . '">' . __('Edit') . '</a>';
         }
     }
     // end if $context
     $actions = array_filter($actions);
     if ($screen->in_admin('network')) {
         /**
          * Filter the action links displayed for each plugin in the Network Admin Plugins list table.
          *
          * The default action links for the Network plugins list table include
          * 'Network Activate', 'Network Deactivate', 'Edit', and 'Delete'.
          *
          * @since 3.1.0 As `{$prefix}_plugin_action_links`
          * @since 4.4.0
          *
          * @param array  $actions     An array of plugin action links.
          * @param string $plugin_file Path to the plugin file relative to the plugins directory.
          * @param array  $plugin_data An array of plugin data.
          * @param string $context     The plugin context. Defaults are 'All', 'Active',
          *                            'Inactive', 'Recently Activated', 'Upgrade',
          *                            'Must-Use', 'Drop-ins', 'Search'.
          */
         $actions = apply_filters('network_admin_plugin_action_links', $actions, $plugin_file, $plugin_data, $context);
         /**
          * Filter the list of action links displayed for a specific plugin in the Network Admin Plugins list table.
          *
          * The dynamic portion of the hook name, $plugin_file, refers to the path
          * to the plugin file, relative to the plugins directory.
          *
          * @since 3.1.0 As `{$prefix}_plugin_action_links_{$plugin_file}`
          * @since 4.4.0
          *
          * @param array  $actions     An array of plugin action links.
          * @param string $plugin_file Path to the plugin file relative to the plugins directory.
          * @param array  $plugin_data An array of plugin data.
          * @param string $context     The plugin context. Defaults are 'All', 'Active',
          *                            'Inactive', 'Recently Activated', 'Upgrade',
          *                            'Must-Use', 'Drop-ins', 'Search'.
          */
         $actions = apply_filters("network_admin_plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context);
     } else {
         /**
          * Filter the action links displayed for each plugin in the Plugins list table.
          *
          * The default action links for the site plugins list table include
          * 'Activate', 'Deactivate', and 'Edit', for a network site, and
          * 'Activate', 'Deactivate', 'Edit', and 'Delete' for a single site.
          *
          * @since 2.5.0 As `{$prefix}_plugin_action_links`
          * @since 4.4.0
          *
          * @param array  $actions     An array of plugin action links.
          * @param string $plugin_file Path to the plugin file relative to the plugins directory.
          * @param array  $plugin_data An array of plugin data.
          * @param string $context     The plugin context. Defaults are 'All', 'Active',
          *                            'Inactive', 'Recently Activated', 'Upgrade',
          *                            'Must-Use', 'Drop-ins', 'Search'.
          */
         $actions = apply_filters('plugin_action_links', $actions, $plugin_file, $plugin_data, $context);
         /**
          * Filter the list of action links displayed for a specific plugin in the Plugins list table.
          *
          * The dynamic portion of the hook name, $plugin_file, refers to the path
          * to the plugin file, relative to the plugins directory.
          *
          * @since 2.7.0 As `{$prefix}_plugin_action_links_{$plugin_file}`
          * @since 4.4.0
          *
          * @param array  $actions     An array of plugin action links.
          * @param string $plugin_file Path to the plugin file relative to the plugins directory.
          * @param array  $plugin_data An array of plugin data.
          * @param string $context     The plugin context. Defaults are 'All', 'Active',
          *                            'Inactive', 'Recently Activated', 'Upgrade',
          *                            'Must-Use', 'Drop-ins', 'Search'.
          */
         $actions = apply_filters("plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context);
     }
     $class = $is_active ? 'active' : 'inactive';
     $checkbox_id = "checkbox_" . md5($plugin_data['Name']);
     if ($restrict_network_active || $restrict_network_only || in_array($status, array('mustuse', 'dropins'))) {
         $checkbox = '';
     } else {
         $checkbox = "<label class='screen-reader-text' for='" . $checkbox_id . "' >" . sprintf(__('Select %s'), $plugin_data['Name']) . "</label>" . "<input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' id='" . $checkbox_id . "' />";
     }
     if ('dropins' != $context) {
         $description = '<p>' . ($plugin_data['Description'] ? $plugin_data['Description'] : '&nbsp;') . '</p>';
         $plugin_name = $plugin_data['Name'];
     }
     if (!empty($totals['upgrade']) && !empty($plugin_data['update'])) {
         $class .= ' update';
     }
     $plugin_slug = isset($plugin_data['slug']) ? $plugin_data['slug'] : sanitize_title($plugin_name);
     printf('<tr class="%s" data-slug="%s" data-plugin="%s">', esc_attr($class), esc_attr($plugin_slug), esc_attr($plugin_file));
     list($columns, $hidden, $sortable, $primary) = $this->get_column_info();
     foreach ($columns as $column_name => $column_display_name) {
         $extra_classes = '';
         if (in_array($column_name, $hidden)) {
             $extra_classes = ' hidden';
         }
         switch ($column_name) {
             case 'cb':
                 echo "<th scope='row' class='check-column'>{$checkbox}</th>";
                 break;
             case 'name':
                 echo "<td class='plugin-title column-primary'><strong>{$plugin_name}</strong>";
                 echo $this->row_actions($actions, true);
                 echo "</td>";
                 break;
             case 'description':
                 $classes = 'column-description desc';
                 echo "<td class='{$classes}{$extra_classes}'>\n\t\t\t\t\t\t<div class='plugin-description'>{$description}</div>\n\t\t\t\t\t\t<div class='{$class} second plugin-version-author-uri'>";
                 $plugin_meta = array();
                 if (!empty($plugin_data['Version'])) {
                     $plugin_meta[] = sprintf(__('Version %s'), $plugin_data['Version']);
                 }
                 if (!empty($plugin_data['Author'])) {
                     $author = $plugin_data['Author'];
                     if (!empty($plugin_data['AuthorURI'])) {
                         $author = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>';
                     }
                     $plugin_meta[] = sprintf(__('By %s'), $author);
                 }
                 // Details link using API info, if available
                 if (isset($plugin_data['slug']) && current_user_can('install_plugins')) {
                     $plugin_meta[] = sprintf('<a href="%s" class="thickbox" aria-label="%s" data-title="%s">%s</a>', esc_url(network_admin_url('plugin-install.php?tab=plugin-information&plugin=' . $plugin_data['slug'] . '&TB_iframe=true&width=600&height=550')), esc_attr(sprintf(__('More information about %s'), $plugin_name)), esc_attr($plugin_name), __('View details'));
                 } elseif (!empty($plugin_data['PluginURI'])) {
                     $plugin_meta[] = sprintf('<a href="%s">%s</a>', esc_url($plugin_data['PluginURI']), __('Visit plugin site'));
                 }
                 /**
                  * Filter the array of row meta for each plugin in the Plugins list table.
                  *
                  * @since 2.8.0
                  *
                  * @param array  $plugin_meta An array of the plugin's metadata,
                  *                            including the version, author,
                  *                            author URI, and plugin URI.
                  * @param string $plugin_file Path to the plugin file, relative to the plugins directory.
                  * @param array  $plugin_data An array of plugin data.
                  * @param string $status      Status of the plugin. Defaults are 'All', 'Active',
                  *                            'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',
                  *                            'Drop-ins', 'Search'.
                  */
                 $plugin_meta = apply_filters('plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status);
                 echo implode(' | ', $plugin_meta);
                 echo "</div></td>";
                 break;
             default:
                 $classes = "{$column_name} column-{$column_name}{$class}";
                 echo "<td class='{$classes}{$extra_classes}'>";
                 /**
                  * Fires inside each custom column of the Plugins list table.
                  *
                  * @since 3.1.0
                  *
                  * @param string $column_name Name of the column.
                  * @param string $plugin_file Path to the plugin file.
                  * @param array  $plugin_data An array of plugin data.
                  */
                 do_action('manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data);
                 echo "</td>";
         }
     }
     echo "</tr>";
     /**
      * Fires after each row in the Plugins list table.
      *
      * @since 2.3.0
      *
      * @param string $plugin_file Path to the plugin file, relative to the plugins directory.
      * @param array  $plugin_data An array of plugin data.
      * @param string $status      Status of the plugin. Defaults are 'All', 'Active',
      *                            'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',
      *                            'Drop-ins', 'Search'.
      */
     do_action('after_plugin_row', $plugin_file, $plugin_data, $status);
     /**
      * Fires after each specific row in the Plugins list table.
      *
      * The dynamic portion of the hook name, `$plugin_file`, refers to the path
      * to the plugin file, relative to the plugins directory.
      *
      * @since 2.7.0
      *
      * @param string $plugin_file Path to the plugin file, relative to the plugins directory.
      * @param array  $plugin_data An array of plugin data.
      * @param string $status      Status of the plugin. Defaults are 'All', 'Active',
      *                            'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',
      *                            'Drop-ins', 'Search'.
      */
     do_action("after_plugin_row_{$plugin_file}", $plugin_file, $plugin_data, $status);
 }
/**
 * @ignore
 *
 * @param array $plugins
 * @param string $context
 */
function print_plugins_table($plugins, $context = '')
{
    global $page;
    $checkbox = !in_array($context, array('mustuse', 'dropins')) ? '<input type="checkbox" />' : '';
    ?>
<table class="widefat" cellspacing="0" id="<?php 
    echo $context;
    ?>
-plugins-table">
	<thead>
	<tr>
		<th scope="col" class="manage-column check-column"><?php 
    echo $checkbox;
    ?>
</th>
		<th scope="col" class="manage-column"><?php 
    _e('Plugin');
    ?>
</th>
		<th scope="col" class="manage-column"><?php 
    _e('Description');
    ?>
</th>
	</tr>
	</thead>

	<tfoot>
	<tr>
		<th scope="col" class="manage-column check-column"><?php 
    echo $checkbox;
    ?>
</th>
		<th scope="col" class="manage-column"><?php 
    _e('Plugin');
    ?>
</th>
		<th scope="col" class="manage-column"><?php 
    _e('Description');
    ?>
</th>
	</tr>
	</tfoot>

	<tbody class="plugins">
<?php 
    if (empty($plugins)) {
        echo '<tr>
			<td colspan="3">' . __('No plugins to show') . '</td>
		</tr>';
    }
    foreach ((array) $plugins as $plugin_file => $plugin_data) {
        // preorder
        $actions = array('network_deactivate' => '', 'deactivate' => '', 'network_only' => '', 'activate' => '', 'network_activate' => '', 'edit' => '', 'delete' => '');
        if ('mustuse' == $context) {
            $is_active = true;
        } elseif ('dropins' == $context) {
            $dropins = _get_dropins();
            $plugin_name = $plugin_file;
            if ($plugin_file != $plugin_data['Name']) {
                $plugin_name .= '<br/>' . $plugin_data['Name'];
            }
            if (true === $dropins[$plugin_file][1]) {
                // Doesn't require a constant
                $is_active = true;
                $description = '<p><strong>' . $dropins[$plugin_file][0] . '</strong></p>';
            } elseif (constant($dropins[$plugin_file][1])) {
                // Constant is true
                $is_active = true;
                $description = '<p><strong>' . $dropins[$plugin_file][0] . '</strong></p>';
            } else {
                $is_active = false;
                $description = '<p><strong>' . $dropins[$plugin_file][0] . ' <span class="attention">' . __('Inactive:') . '</span></strong> ' . sprintf(__('Requires <code>%s</code> in <code>wp-config.php</code>.'), "define('" . $dropins[$plugin_file][1] . "', true);") . '</p>';
            }
            if ($plugin_data['Description']) {
                $description .= '<p>' . $plugin_data['Description'] . '</p>';
            }
        } else {
            $is_active_for_network = is_plugin_active_for_network($plugin_file);
            $is_active = $is_active_for_network || is_plugin_active($plugin_file);
            if ($is_active_for_network && !is_super_admin()) {
                continue;
            }
            if ($is_active) {
                if ($is_active_for_network) {
                    if (is_super_admin()) {
                        $actions['network_deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>';
                    }
                } else {
                    $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Deactivate') . '</a>';
                }
            } else {
                if (is_multisite() && is_network_only_plugin($plugin_file)) {
                    $actions['network_only'] = '<span title="' . __('This plugin can only be activated for all sites in a network') . '">' . __('Network Only') . '</span>';
                } else {
                    $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin') . '" class="edit">' . __('Activate') . '</a>';
                }
                if (is_multisite() && current_user_can('manage_network_plugins')) {
                    $actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>';
                }
                if (current_user_can('delete_plugins')) {
                    $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'bulk-manage-plugins') . '" title="' . __('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>';
                }
            }
            // end if $is_active
            if (current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file)) {
                $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . __('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
            }
        }
        // end if $context
        $actions = apply_filters('plugin_action_links', array_filter($actions), $plugin_file, $plugin_data, $context);
        $actions = apply_filters("plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context);
        $class = $is_active ? 'active' : 'inactive';
        $checkbox = in_array($context, array('mustuse', 'dropins')) ? '' : "<input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' />";
        if ('dropins' != $context) {
            $description = '<p>' . $plugin_data['Description'] . '</p>';
            $plugin_name = $plugin_data['Name'];
        }
        echo "\n\t<tr class='{$class}'>\n\t\t<th scope='row' class='check-column'>{$checkbox}</th>\n\t\t<td class='plugin-title'><strong>{$plugin_name}</strong></td>\n\t\t<td class='desc'>{$description}</td>\n\t</tr>\n\t<tr class='{$class} second'>\n\t\t<td></td>\n\t\t<td class='plugin-title'>";
        echo '<div class="row-actions-visible">';
        foreach ($actions as $action => $link) {
            $sep = end($actions) == $link ? '' : ' | ';
            echo "<span class='{$action}'>{$link}{$sep}</span>";
        }
        echo "</div></td>\n\t\t<td class='desc'>";
        $plugin_meta = array();
        if (!empty($plugin_data['Version'])) {
            $plugin_meta[] = sprintf(__('Version %s'), $plugin_data['Version']);
        }
        if (!empty($plugin_data['Author'])) {
            $author = $plugin_data['Author'];
            if (!empty($plugin_data['AuthorURI'])) {
                $author = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . __('Visit author homepage') . '">' . $plugin_data['Author'] . '</a>';
            }
            $plugin_meta[] = sprintf(__('By %s'), $author);
        }
        if (!empty($plugin_data['PluginURI'])) {
            $plugin_meta[] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . __('Visit plugin site') . '">' . __('Visit plugin site') . '</a>';
        }
        $plugin_meta = apply_filters('plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $context);
        echo implode(' | ', $plugin_meta);
        echo "</td>\n\t</tr>\n";
        do_action('after_plugin_row', $plugin_file, $plugin_data, $context);
        do_action("after_plugin_row_{$plugin_file}", $plugin_file, $plugin_data, $context);
    }
    ?>
	</tbody>
</table>
<?php 
}
Exemple #14
0
/**
 * Attempts activation of plugin in a "sandbox" and redirects on success.
 *
 * A plugin that is already activated will not attempt to be activated again.
 *
 * The way it works is by setting the redirection to the error before trying to
 * include the plugin file. If the plugin fails, then the redirection will not
 * be overwritten with the success message. Also, the options will not be
 * updated and the activation hook will not be called on plugin error.
 *
 * It should be noted that in no way the below code will actually prevent errors
 * within the file. The code should not be used elsewhere to replicate the
 * "sandbox", which uses redirection to work.
 * {@source 13 1}
 *
 * If any errors are found or text is outputted, then it will be captured to
 * ensure that the success redirection will update the error redirection.
 *
 * @since 2.5.0
 *
 * @param string $plugin Plugin path to main plugin file with plugin data.
 * @param string $redirect Optional. URL to redirect to.
 * @param bool $network_wide Whether to enable the plugin for all sites in the
 *   network or just the current site. Multisite only. Default is false.
 * @param bool $silent Prevent calling activation hooks. Optional, default is false.
 * @return WP_Error|null WP_Error on invalid file or null on success.
 */
function activate_plugin($plugin, $redirect = '', $network_wide = false, $silent = false)
{
    $plugin = plugin_basename(trim($plugin));
    if (is_multisite() && ($network_wide || is_network_only_plugin($plugin))) {
        $network_wide = true;
        $current = get_site_option('active_sitewide_plugins', array());
        $_GET['networkwide'] = 1;
        // Back compat for plugins looking for this value.
    } else {
        $current = get_option('active_plugins', array());
    }
    $valid = validate_plugin($plugin);
    if (is_wp_error($valid)) {
        return $valid;
    }
    if (!in_array($plugin, $current)) {
        if (!empty($redirect)) {
            wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect));
        }
        // we'll override this later if the plugin can be included without fatal error
        ob_start();
        include_once WP_PLUGIN_DIR . '/' . $plugin;
        if (!$silent) {
            /**
             * Fires before a plugin is activated in activate_plugin() when the $silent parameter is false.
             * 
             * @since 2.9.0
             *
             * @param string $plugin       Plugin path to main plugin file with plugin data.
             * @param bool   $network_wide Whether to enable the plugin for all sites in the network
             *                             or just the current site. Multisite only. Default is false.
             */
            do_action('activate_plugin', $plugin, $network_wide);
            /**
             * Fires before a plugin is activated in activate_plugin() when the $silent parameter is false.
             * 
             * The action concatenates the 'activate_' prefix with the $plugin value passed to
             * activate_plugin() to create a dynamically-named action.
             * 
             * @since 2.0.0
             *
             * @param bool $network_wide Whether to enable the plugin for all sites in the network
             *                           or just the current site. Multisite only. Default is false.
             */
            do_action('activate_' . $plugin, $network_wide);
        }
        if ($network_wide) {
            $current[$plugin] = time();
            update_site_option('active_sitewide_plugins', $current);
        } else {
            $current[] = $plugin;
            sort($current);
            update_option('active_plugins', $current);
        }
        if (!$silent) {
            /**
             * Fires after a plugin has been activated in activate_plugin() when the $silent parameter is false.
             * 
             * @since 2.9.0
             *
             * @param string $plugin       Plugin path to main plugin file with plugin data.
             * @param bool   $network_wide Whether to enable the plugin for all sites in the network
             *                             or just the current site. Multisite only. Default is false.
             */
            do_action('activated_plugin', $plugin, $network_wide);
        }
        if (ob_get_length() > 0) {
            $output = ob_get_clean();
            return new WP_Error('unexpected_output', __('The plugin generated unexpected output.'), $output);
        }
        ob_end_clean();
    }
    return null;
}
    function blog_options_form($blog_id)
    {
        $plugins = get_plugins();
        $override_plugins = (array) get_blog_option($blog_id, 'pm_plugin_override_list');
        ?>
	  </table>
	  <h3><?php 
        _e('Plugin Override Options', 'pm');
        ?>
</h3>
	  <p style="padding:5px 10px 0 10px;margin:0;">
	  <?php 
        _e('Checked plugins here will be accessible to this site, overriding the sitewide <a href="plugins.php?page=plugin-management">Plugin Management</a> settings. Uncheck to return to sitewide settings.', 'pm');
        ?>
	  </p>
	  <table class="widefat" style="margin:10px;width:95%;">
	  <thead>
		<tr>
			<th title="<?php 
        _e('Blog users may activate/deactivate', 'pm');
        ?>
"><?php 
        _e('User Control', 'pm');
        ?>
</th>
	    <th><?php 
        _e('Name', 'pm');
        ?>
</th>
			<th><?php 
        _e('Version', 'pm');
        ?>
</th>
			<th><?php 
        _e('Author', 'pm');
        ?>
</th>
		</tr>
		</thead>
	  <?php 
        foreach ($plugins as $file => $p) {
            //skip network plugins or network activated plugins
            if (is_network_only_plugin($file) || is_plugin_active_for_network($file)) {
                continue;
            }
            ?>
			<tr>
				<td>
				<?php 
            $checked = in_array($file, $override_plugins) ? 'checked="checked"' : '';
            echo '<label><input name="plugins[' . $file . ']" type="checkbox" value="1" ' . $checked . '/> ' . __('Enable', 'mp') . '</label>';
            ?>
				</td>
		 		<td><?php 
            echo $p['Name'];
            ?>
</td>
		 		<td><?php 
            echo $p['Version'];
            ?>
</td>
		 		<td><?php 
            echo $p['Author'];
            ?>
</td>
			</tr>
			<?php 
        }
        echo '</table>';
    }
Exemple #16
0
 public function setUpPlugin()
 {
     if (is_plugin_active_for_network('js_composer/js_composer.php') || is_network_only_plugin('js_composer/js_composer.php')) {
         $this->composer->setAsNetworkPlugin(true);
     }
     global $current_user;
     get_currentuserinfo();
     /** @var $settings - get use group access rules */
     $settings = WPBakeryVisualComposerSettings::get('groups_access_rules');
     parent::setUpPlugin();
     $show = true;
     foreach ($current_user->roles as $role) {
         if (isset($settings[$role]['show']) && $settings[$role]['show'] === 'no') {
             $show = false;
             break;
         }
     }
     if ($show) {
         $this->composer->addAction('edit_post', 'saveMetaBoxes');
         $this->composer->addAction('wp_ajax_wpb_get_element_backend_html', 'elementBackendHtmlJavascript_callback');
         $this->composer->addAction('wp_ajax_wpb_get_convert_elements_backend_html', 'Convert2NewVersionJavascript_callback');
         $this->composer->addAction('wp_ajax_wpb_get_row_element_backend_html', 'elementRowBackendHtmlJavascript_callback');
         $this->composer->addAction('wp_ajax_wpb_shortcodes_to_visualComposer', 'shortCodesVisualComposerJavascript_callback');
         $this->composer->addAction('wp_ajax_wpb_single_image_src', 'singleImageSrcJavascript_callback');
         $this->composer->addAction('wp_ajax_wpb_gallery_html', 'galleryHTMLJavascript_callback');
         $this->composer->addAction('wp_ajax_wpb_get_loop_suggestion', 'getLoopSuggestionJavascript_callback');
         $this->composer->addAction('wp_ajax_wpb_remove_settings_notification_element_css_class', 'removeSettingsNotificationJavascript_callback');
         $this->composer->addAction('wp_ajax_wpb_image_url', 'getImageUrlByIdJavascript_callback');
         /*
          * Create edit form html
          * @deprecated
          */
         $this->composer->addAction('wp_ajax_wpb_show_edit_form', 'showEditFormJavascript_callback');
         $this->composer->addAction('wp_ajax_wpb_get_edit_form', 'getEditFormJavascript_callback');
         $this->composer->addAction('wp_ajax_wpb_save_template', 'saveTemplateJavascript_callback');
         $this->composer->addAction('wp_ajax_wpb_load_template', 'loadTemplateJavascript_callback');
         $this->composer->addAction('wp_ajax_wpb_load_inline_template', 'loadInlineTemplateJavascript_callback');
         $this->composer->addAction('wp_ajax_wpb_load_template_shortcodes', 'loadTemplateShortcodesJavascript_callback');
         $this->composer->addAction('wp_ajax_wpb_delete_template', 'deleteTemplateJavascript_callback');
         $this->composer->addAction('wp_ajax_wpb_get_loop_settings', 'getLoopSettingsJavascript_callback');
         $this->composer->addAction('wp_ajax_wpb_activate_license', 'activateLicense');
         $this->composer->addAction('wp_ajax_wpb_deactivate_license', 'deactivateLicense');
         $this->composer->inlineEditor()->addAction('wp_ajax_vc_load_shortcode', 'loadShortcodes');
         $this->composer->inlineEditor()->addAction('wp_ajax_vc_show_edit_form', 'renderEditForm');
         $this->composer->inlineEditor()->addAction('wp_ajax_vc_update_content', 'savePost');
         $this->composer->inlineEditor()->addAction('wp_ajax_vc_inline_template', 'renderTemplate');
         $this->composer->inlineEditor()->addAction('wp_ajax_vc_show_inline_edit_form', 'buildInlineEditForm');
         $this->addAction('admin_init', 'jsComposerEditPage', 5);
         $this->composer->inlineEditor()->addFilter('page_row_actions', 'renderRowAction');
         $this->composer->inlineEditor()->addFilter('post_row_actions', 'renderRowAction');
     }
     vc_automapper()->addAction('wp_ajax_vc_automapper', 'goAction');
     if (vc_is_inline()) {
         $this->composer->inlineEditor()->addFilter('vc_single_param_edit', 'changeEditFormFieldParams');
         $this->composer->inlineEditor()->addFilter('vc_edit_form_class', 'changeEditFormParams');
     }
     $this->composer->addAction('admin_init', 'renderInlineEditor');
     // Add specific CSS class by filter
     $this->addFilter('body_class', 'jsComposerBodyClass');
     $this->addFilter('get_media_item_args', 'jsForceSend');
     $this->addAction('admin_init', 'composerRedirect');
     $this->addAction('admin_init', 'registerCss');
     $this->addAction('admin_init', 'registerJavascript');
     if ($this->composer->isNetworkPlugin() && is_network_admin()) {
         $this->addAction('network_admin_menu', 'composerSettings');
     }
     $this->addAction('admin_menu', 'composerSettings');
     $this->addAction('admin_print_scripts-post.php', 'editScreen_js');
     $this->addAction('admin_print_scripts-post-new.php', 'editScreen_js');
     // Upgrade message in plugins list.
     if ($this->composer->updaterDisabled()) {
         return $this;
     }
     $plugin_file_name = 'js_composer/js_composer.php';
     new WpbAutoUpdate(WPB_VC_VERSION, 'http://wpbakery.com/version/?' . time(), $plugin_file_name);
     $this->addAction('in_plugin_update_message-' . $plugin_file_name, 'addUpgradeMessageLink');
 }
/**
 * Helper function to get network plugins only
 *
 * @since 1.1
 */
function ray_get_network_plugins_only()
{
    $all_plugins = get_plugins();
    $network_plugins = array();
    foreach ((array) $all_plugins as $plugin_file => $plugin_data) {
        if (is_multisite() && is_network_only_plugin($plugin_file) && !current_user_can('manage_network_plugins')) {
            unset($all_plugins[$plugin_file]);
            continue;
        } elseif (is_plugin_active_for_network($plugin_file)) {
            $network_plugins[$plugin_file] = $plugin_data;
        }
    }
    return apply_filters('network_plugins_only', $network_plugins);
}
             $is_active_for_network = is_plugin_active_for_network($plugin_file);
             $is_active = $is_active_for_network || is_plugin_active($plugin_file);
             if ($is_active_for_network && !is_super_admin()) {
                 continue;
             }
             if ($is_active) {
                 $players[$slug] = $name;
                 if ($is_active_for_network) {
                     if (is_super_admin()) {
                         $action_links['network_deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>';
                     }
                 } else {
                     $action_links['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Deactivate') . '</a>';
                 }
             } else {
                 if (is_multisite() && is_network_only_plugin($plugin_file)) {
                     $action_links['network_only'] = '<span title="' . __('This plugin can only be activated for all sites in a network') . '">' . __('Network Only') . '</span>';
                 } else {
                     $action_links['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin') . '" class="edit">' . __('Activate') . '</a>';
                 }
                 if (is_multisite() && current_user_can('manage_network_plugins')) {
                     $action_links['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>';
                 }
                 if (current_user_can('delete_plugins')) {
                     $action_links['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'bulk-manage-plugins') . '" title="' . __('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>';
                 }
             }
             // end if $is_active
         }
     }
 }
Exemple #19
0
 if (!current_user_can('activate_plugins')) {
     wp_die(__('You do not have sufficient permissions to activate plugins for this site.'));
 }
 check_admin_referer('bulk-plugins');
 $plugins = isset($_POST['checked']) ? (array) $_POST['checked'] : array();
 if (is_network_admin()) {
     foreach ($plugins as $i => $plugin) {
         // Only activate plugins which are not already network activated.
         if (is_plugin_active_for_network($plugin)) {
             unset($plugins[$i]);
         }
     }
 } else {
     foreach ($plugins as $i => $plugin) {
         // Only activate plugins which are not already active and are not network-only when on Multisite.
         if (is_plugin_active($plugin) || is_multisite() && is_network_only_plugin($plugin)) {
             unset($plugins[$i]);
         }
     }
 }
 if (empty($plugins)) {
     wp_redirect(self_admin_url("plugins.php?plugin_status={$status}&paged={$page}&s={$s}"));
     exit;
 }
 activate_plugins($plugins, self_admin_url('plugins.php?error=true'), is_network_admin());
 if (!is_network_admin()) {
     $recent = (array) get_option('recently_activated');
     foreach ($plugins as $plugin) {
         unset($recent[$plugin]);
     }
     update_option('recently_activated', $recent);
Exemple #20
0
 /**
  * Gets VC is activated as network plugin.
  *
  * @since  4.2
  * @access public
  * @return bool
  */
 public function isNetworkPlugin()
 {
     if (is_null($this->is_network_plugin)) {
         // Check is VC as network plugin
         if (is_multisite() && (is_plugin_active_for_network('js_composer_salient/js_composer.php') || is_network_only_plugin('js_composer_salient/js_composer.php'))) {
             $this->setAsNetworkPlugin(true);
         }
     }
     return $this->is_network_plugin;
 }
Exemple #21
0
/**
 * Attempts activation of plugin in a "sandbox" and redirects on success.
 *
 * A plugin that is already activated will not attempt to be activated again.
 *
 * The way it works is by setting the redirection to the error before trying to
 * include the plugin file. If the plugin fails, then the redirection will not
 * be overwritten with the success message. Also, the options will not be
 * updated and the activation hook will not be called on plugin error.
 *
 * It should be noted that in no way the below code will actually prevent errors
 * within the file. The code should not be used elsewhere to replicate the
 * "sandbox", which uses redirection to work.
 * {@source 13 1}
 *
 * If any errors are found or text is outputted, then it will be captured to
 * ensure that the success redirection will update the error redirection.
 *
 * @since 2.5.0
 *
 * @param string $plugin Plugin path to main plugin file with plugin data.
 * @param string $redirect Optional. URL to redirect to.
 * @param bool $network_wide Whether to enable the plugin for all sites in the
 *   network or just the current site. Multisite only. Default is false.
 * @param bool $silent Prevent calling activation hooks. Optional, default is false.
 * @return WP_Error|null WP_Error on invalid file or null on success.
 */
function activate_plugin($plugin, $redirect = '', $network_wide = false, $silent = false)
{
    $plugin = plugin_basename(trim($plugin));
    if (is_multisite() && ($network_wide || is_network_only_plugin($plugin))) {
        $network_wide = true;
        $current = get_site_option('active_sitewide_plugins', array());
    } else {
        $current = get_option('active_plugins', array());
    }
    $valid = validate_plugin($plugin);
    if (is_wp_error($valid)) {
        return $valid;
    }
    if (!in_array($plugin, $current)) {
        if (!empty($redirect)) {
            wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect));
        }
        // we'll override this later if the plugin can be included without fatal error
        ob_start();
        include_once WP_PLUGIN_DIR . '/' . $plugin;
        if (!$silent) {
            do_action('activate_plugin', $plugin, $network_wide);
            do_action('activate_' . $plugin, $network_wide);
        }
        if ($network_wide) {
            $current[$plugin] = time();
            update_site_option('active_sitewide_plugins', $current);
        } else {
            $current[] = $plugin;
            sort($current);
            update_option('active_plugins', $current);
        }
        if (!$silent) {
            do_action('activated_plugin', $plugin, $network_wide);
        }
        if (ob_get_length() > 0) {
            $output = ob_get_clean();
            return new WP_Error('unexpected_output', __('The plugin generated unexpected output.'), $output);
        }
        ob_end_clean();
    }
    return null;
}
    /**
     *	options added to wpmu-blogs.php edit page. Overrides sitewide control settings for an individual blog.
     *
     *	@action wpmueditblogaction
     */
    function blog_options_form($blog_id)
    {
        switch_to_blog($blog_id);
        $plugins = get_plugins();
        $auto_activate = (array) get_site_option('pm_auto_activate_list');
        $user_control = (array) get_site_option('pm_user_control_list');
        $override_plugins = (array) get_option('pm_plugin_override_list');
        ?>
		</table>
		<h3><?php 
        _e('Plugin Override Options', 'pm');
        ?>
</h3>
		<p style="padding:5px 10px 0 10px;margin:0;">
			<?php 
        _e('Choose “Allow” if you want to allow plugin (de-)activation on this specific site. Choose “Deny” to always deny activation for blog users.', 'pm');
        ?>
		</p>
		<table class="widefat" style="margin:10px;width:95%;">
			<thead>
				<tr>
					<th><?php 
        _e('Name', 'pm');
        ?>
</th>
					<th><?php 
        _e('Author', 'pm');
        ?>
</th>
					<th><?php 
        _e('Version', 'pm');
        ?>
</th>
					<th><?php 
        _e('User-Control (Network Default)', 'pm');
        ?>
</th>
					<th title="<?php 
        _e('Blog users may activate/deactivate', 'pm');
        ?>
"><?php 
        _e('User Control', 'pm');
        ?>
</th>
					<th><?php 
        _e('Activation', 'pm');
        ?>
</th>
				</tr>
			</thead>
			<?php 
        $control_options = array('' => __('— Network default —', 'pm'), '1' => __('Allow', 'pm'), '0' => __('Deny', 'pm'));
        foreach ($plugins as $file => $p) {
            //skip network plugins or network activated plugins
            if (is_network_only_plugin($file) || is_plugin_active_for_network($file)) {
                continue;
            }
            ?>
			<tr>
				<td><?php 
            echo $p['Name'];
            ?>
</td>
				<td><?php 
            echo $p['Author'];
            ?>
</td>
				<td><?php 
            echo $p['Version'];
            ?>
</td>
				<td><?php 
            if (in_array($file, $auto_activate)) {
                ?>
<span style="color:#093"><?php 
                ?>
<span class="dashicons dashicons-yes"></span><?php 
                _e('Allow and Auto-Activate', 'pm');
                ?>
</span><?php 
            } else {
                if (in_array($file, $user_control)) {
                    ?>
<span style="color:#093"><?php 
                    ?>
<span class="dashicons dashicons-yes"></span><?php 
                    _e('Allow', 'pm');
                    ?>
</span><?php 
                } else {
                    ?>
<span style="color:#aaa"><?php 
                    ?>
<span class="dashicons dashicons-no-alt"></span><?php 
                    _e('Deny', 'pm');
                    ?>
</span><?php 
                }
            }
            ?>
</td>
				<td>
				<?php 
            printf('<select name="plugins[%s]">', $file);
            foreach ($control_options as $value => $label) {
                $plugin_status = in_array($file, $override_plugins) ? '1' : (isset($override_plugins[$file]) ? $override_plugins[$file] : '');
                printf('<option value="%s" %s>%s</option>', $value, selected($value, $plugin_status), $label);
            }
            echo '</select>';
            ?>
				</td>
				<td><?php 
            if (is_plugin_active($file)) {
                ?>
<button class="button" type="submit" name="deactivate-plugin" value="<?php 
                esc_attr_e($file);
                ?>
"><?php 
                _e('Deactivate plugin');
                ?>
</button><?php 
            } else {
                ?>
<button class="button-primary" type="submit" name="activate-plugin" value="<?php 
                esc_attr_e($file);
                ?>
"><?php 
                _e('Activate plugin');
                ?>
</button><?php 
            }
            ?>
</td>
			</tr>
			<?php 
        }
        echo '</table>';
        restore_current_blog();
    }