WordPress.org

Make WordPress Core

Ticket #12139: 12139.2.diff

File 12139.2.diff, 5.0 KB (added by nacin, 8 years ago)

Uses API for Network: true and Site Wide Only: true headers

  • wp-admin/css/wp-admin.dev.css

     
    851851
    852852.row-actions-visible {
    853853        padding: 2px 0 0;
    854         cursor: pointer;
    855854}
    856855
    857856/* Admin Header */
  • wp-admin/includes/plugin.php

     
    2929 *              located in the locale folder then Domain Path will be "/locale/" and
    3030 *              must have the first slash. Defaults to the base folder the plugin is
    3131 *              located in.
     32 * Network: Optional. Specify "Network: true" to require that a plugin is activated
     33 *              across all sites in an installation. This will prevent a plugin from being
     34 *              activated on a single site when Multisite is enabled.
    3235 *  * / # Remove the space to close comment
    3336 * </code>
    3437 *
     
    4346 *              'PluginURI' - Plugin web site address.
    4447 *              'TextDomain' - Plugin's text domain for localization.
    4548 *              'DomainPath' - Plugin's relative directory path to .mo files.
     49 *              'Network' - Boolean. Whether the plugin can only be activated network wide.
    4650 *
    4751 * Some users have issues with opening large files and manipulating the contents
    4852 * for want is usually the first 1kiB or 2kiB. This function stops pulling in
     
    7579                'Author' => 'Author',
    7680                'AuthorURI' => 'Author URI',
    7781                'TextDomain' => 'Text Domain',
    78                 'DomainPath' => 'Domain Path'
    79                 );
     82                'DomainPath' => 'Domain Path',
     83                'Network' => 'Network',
     84                '_sitewide' => 'Site Wide Only',
     85        );
    8086
    8187        $plugin_data = get_file_data( $plugin_file, $default_headers, 'plugin' );
    8288
     89        // Site Wide Only is the old header for Network
     90        if ( empty( $plugin_data['Network'] ) && ! empty( $plugin_data['_sitewide'] ) )
     91                $plugin_data['Network'] = $plugin_data['_sitewide'];
     92        $plugin_data['Network'] = ( 'true' == strtolower( $plugin_data['Network'] ) ) ? true : false;
     93        unset( $plugin_data['_sitewide'] );
     94
    8395        //For backward compatibility by default Title is the same as Name.
    8496        $plugin_data['Title'] = $plugin_data['Name'];
    8597
     
    282294}
    283295
    284296/**
    285  * Checks for "Site Wide Only: true" in the plugin header to see if this should
    286  * be activated as a network wide MU plugin.
     297 * Checks for "Network: true" in the plugin header to see if this should
     298 * be activated only as a network wide plugin. The plugin would also work
     299 * when Multisite is not enabled.
    287300 *
     301 * Checks for "Site Wide Only: true" for backwards compatibility.
     302 *
    288303 * @since 3.0.0
    289304 *
    290  * @todo Use API for getting arbitrary plugin headers.
    291  *
    292305 * @param $file Plugin to check
    293306 * $return bool True if plugin is network only, false otherwise.
    294307 */
    295 function is_network_only_plugin( $file ) {
    296         /* Open the plugin file for reading to check if this is a ms-plugin. */
    297         $fp = @fopen( WP_PLUGIN_DIR . '/' . $file, 'r' );
    298 
    299         /* Pull only the first 8kiB of the file in. */
    300         $plugin_data = @fread( $fp, 8192 );
    301 
    302         /* PHP will close file handle, but we are good citizens. */
    303         @fclose($fp);
    304 
    305         if ( preg_match( '/(Network|Site Wide Only):(.*)true$/mi', $plugin_data ) )
    306                 return true;
    307 
     308function is_network_only_plugin( $plugin ) {
     309        $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
     310        if ( $plugin_data )
     311                return $plugin_data['Network'];
    308312        return false;
    309313}
    310314
  • wp-admin/plugins.php

     
    491491                                $actions[] = '<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>';
    492492                        }
    493493                } else {
    494                         $actions[] = '<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>';
     494                        if ( is_network_only_plugin( $plugin_file ) )
     495                                $actions[] = '<span title="' . __('This plugin can only be activated for all sites in a network') . '">' . __('Network Only') . '</span>';
     496                        else
     497                                $actions[] = '<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>';
    495498                        if ( is_multisite() && is_super_admin() )
    496499                                $actions[] = '<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>';
    497500                }