| | 1 | <?php |
| | 2 | /** |
| | 3 | * Multisite plugin settings administration panel. |
| | 4 | * |
| | 5 | * @package WordPress |
| | 6 | * @subpackage Multisite |
| | 7 | * @since ------------- |
| | 8 | */ |
| | 9 | |
| | 10 | /** Load WordPress Administration Bootstrap */ |
| | 11 | require_once( dirname( __FILE__ ) . '/admin.php' ); |
| | 12 | |
| | 13 | if ( ! is_multisite() ) |
| | 14 | wp_die( __( 'Multisite support is not enabled.' ) ); |
| | 15 | |
| | 16 | if ( ! current_user_can( 'manage_network_plugins' ) ) |
| | 17 | wp_die( __( 'You do not have permission to access this page.' ) ); |
| | 18 | |
| | 19 | // Load parent class to create the class to display the sites |
| | 20 | _get_list_table( 'WP_MS_Sites_List_Table' ); |
| | 21 | |
| | 22 | /** |
| | 23 | * AD HOC class for displaying a sites list. The class take advantage of |
| | 24 | * the sites list table class and only redeclare some functions to adapt |
| | 25 | * the class. |
| | 26 | * |
| | 27 | */ |
| | 28 | class WP_MS_Plugin_Settings_List_Table extends WP_MS_Sites_List_Table { |
| | 29 | |
| | 30 | public function __construct( $args = array() ) { |
| | 31 | parent::__construct( array( |
| | 32 | 'plural' => 'Plugin Settings', |
| | 33 | 'screen' => isset( $args['screen'] ) ? $args['screen'] : null ) |
| | 34 | ); |
| | 35 | } |
| | 36 | |
| | 37 | public function ajax_user_can() { |
| | 38 | return current_user_can('manage_network_plugins'); |
| | 39 | } |
| | 40 | |
| | 41 | protected function get_bulk_actions() { |
| | 42 | $actions = array(); |
| | 43 | if ( current_user_can( 'manage_network_plugins' ) ) { |
| | 44 | $actions['enable'] = __( 'enable plugins' ); |
| | 45 | $actions['disable'] = __( 'disable plugins' ); |
| | 46 | } |
| | 47 | return $actions; |
| | 48 | } |
| | 49 | } |
| | 50 | |
| | 51 | |
| | 52 | // Hooks declared in WP_MS_Sites_List_Table |
| | 53 | add_filter('wpmu_blogs_columns', 'wp_network_plugin_settings_columns', 9999); // Create a custom column |
| | 54 | add_filter('manage_sites_action_links', 'wp_network_plugin_settings_actions', 9999, 3); // Define new actions in Sites column |
| | 55 | add_action('manage_sites_custom_column', 'wp_network_plugin_settings_row', 9999, 2); // Content of custom column |
| | 56 | |
| | 57 | // Create the list class |
| | 58 | $wp_list_table = new WP_MS_Plugin_Settings_List_Table(); |
| | 59 | $pagenum = $wp_list_table->get_pagenum(); |
| | 60 | |
| | 61 | $title = __( 'Plugin Settings' ); |
| | 62 | $parent_file = 'plugin-settings.php'; |
| | 63 | |
| | 64 | add_screen_option( 'per_page', array( 'label' => _x( 'Sites', 'sites per page (screen options)' ) ) ); |
| | 65 | |
| | 66 | get_current_screen()->add_help_tab( array( |
| | 67 | 'id' => 'overview', |
| | 68 | 'title' => __('Overview'), |
| | 69 | 'content' => |
| | 70 | '<p>' . __('This is the main table of all sites on this network.') . '</p>' . |
| | 71 | '<p>' . __('Hovering over each site reveals two options:') . '</p>' . |
| | 72 | '<ul><li>' . __('Enable the plugin in a site (the site admin can activate or deactivate.)') . '</li>' . |
| | 73 | '<li>' . __('Disable the plugin in a site (the plugin isn´t available in the selected site)') . '</li>' . |
| | 74 | '</ul>' . |
| | 75 | '<p>' . __('Clicking on bold headings can re-sort this table.') . '</p>' |
| | 76 | ) ); |
| | 77 | |
| | 78 | /* Not exist official page |
| | 79 | get_current_screen()->set_help_sidebar( |
| | 80 | '<p><strong>' . __('For more information:') . '</strong></p>' . |
| | 81 | '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Sites_Screen" target="_blank">Documentation on Site Management</a>') . '</p>' . |
| | 82 | '<p>' . __('<a href="https://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>' |
| | 83 | ); |
| | 84 | */ |
| | 85 | |
| | 86 | $plugin = isset( $_REQUEST['plugin'] ) ? $_REQUEST['plugin'] : ''; |
| | 87 | $id = isset( $_REQUEST['id'] ) ? $_REQUEST['id'] : ''; |
| | 88 | $ids = empty($id) ? array() : array($id); |
| | 89 | |
| | 90 | $reportnotupd = isset( $_REQUEST['reportnotupd'] ) ? $_REQUEST['reportnotupd'] : array(); // Report with the not updated ids |
| | 91 | $reportupd = isset( $_REQUEST['reportupd'] ) ? $_REQUEST['reportupd'] : array(); |
| | 92 | |
| | 93 | if ( isset( $_GET['action'] ) ) { |
| | 94 | |
| | 95 | if ( 'confirm' === $_GET['action'] ) { |
| | 96 | check_admin_referer( 'confirm' ); |
| | 97 | |
| | 98 | if ( ! headers_sent() ) { |
| | 99 | nocache_headers(); |
| | 100 | header( 'Content-Type: text/html; charset=utf-8' ); |
| | 101 | } |
| | 102 | |
| | 103 | require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
| | 104 | ?> |
| | 105 | <div class="wrap"> |
| | 106 | <h2><?php _e( 'Confirm your action' ); ?></h2> |
| | 107 | <?php $url = 'plugin-settings.php?action=' . esc_attr( $_GET['action2'] ); ?> |
| | 108 | <form action="<?php echo network_admin_url($url) ?>" method="post"> |
| | 109 | <input type="hidden" name="action" value="<?php echo esc_attr( $_GET['action2'] ) ?>" /> |
| | 110 | <input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" /> |
| | 111 | <input type="hidden" name="plugin" value="<?php echo esc_attr( $plugin ); ?>" /> |
| | 112 | <input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr( wp_get_referer() ); ?>" /> |
| | 113 | <?php wp_nonce_field( $_GET['action2'], '_wpnonce', false ); ?> |
| | 114 | <p><?php echo esc_html( wp_unslash( $_GET['msg'] ) ); ?></p> |
| | 115 | <?php submit_button( __( 'Confirm' ), 'button' ); ?> |
| | 116 | </form> |
| | 117 | </div> |
| | 118 | <?php |
| | 119 | require_once( ABSPATH . 'wp-admin/admin-footer.php' ); |
| | 120 | exit(); |
| | 121 | } |
| | 122 | |
| | 123 | $manage_actions = array( 'disable', 'enable' ); |
| | 124 | if ( in_array( $_GET['action'], $manage_actions ) ) { |
| | 125 | $action = $_GET['action']; |
| | 126 | if ( 'allblogs' === $action ) |
| | 127 | $action = 'bulk-sites'; |
| | 128 | |
| | 129 | check_admin_referer( $action ); |
| | 130 | } |
| | 131 | |
| | 132 | |
| | 133 | $doaction = $_GET['action']; |
| | 134 | |
| | 135 | if ( 'allblogs' === $doaction ) { |
| | 136 | if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allblogs'] ) ) |
| | 137 | $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2']; |
| | 138 | |
| | 139 | if ( ! current_user_can( 'manage_network_plugins' ) ) |
| | 140 | wp_die( __( 'You are not allowed to enable or disable plugins' ) ); |
| | 141 | |
| | 142 | $ids = (array) $_POST['allblogs']; |
| | 143 | } |
| | 144 | |
| | 145 | switch ( $doaction ) { |
| | 146 | |
| | 147 | case 'disable': |
| | 148 | if ( ! current_user_can( 'manage_network_plugins' ) ) |
| | 149 | wp_die( __( 'You do not have permission to access this page.' ) ); |
| | 150 | |
| | 151 | if ( empty($plugin) || ! is_array($ids) ) |
| | 152 | break; |
| | 153 | |
| | 154 | foreach ( $ids as $id ) { |
| | 155 | |
| | 156 | $disable_plugins = get_blog_option($id, 'disable_plugins'); |
| | 157 | if(empty($disable_plugins)) |
| | 158 | $disable_plugins = array(); |
| | 159 | |
| | 160 | // Check duplicate plugin |
| | 161 | if ( ! in_array( $plugin , $disable_plugins) ){ |
| | 162 | $disable_plugins[] = $plugin; |
| | 163 | } |
| | 164 | |
| | 165 | // Check if it is active. If true, report it and not updated |
| | 166 | if ( wp_network_is_plugin_active($id, $plugin) ){ |
| | 167 | $reportnotupd[] = $id; |
| | 168 | continue; |
| | 169 | } |
| | 170 | |
| | 171 | $updated_option = update_blog_option( $id, 'disable_plugins', $disable_plugins ); |
| | 172 | if ( ! $updated_option ) |
| | 173 | add_blog_option( $id, 'disable_plugins', $disable_plugins ); |
| | 174 | else |
| | 175 | $reportupd[] = $id; |
| | 176 | } |
| | 177 | |
| | 178 | $updated_action = 'disable'; |
| | 179 | break; |
| | 180 | |
| | 181 | case 'enable': |
| | 182 | if ( ! current_user_can( 'manage_network_plugins' ) ) |
| | 183 | wp_die( __( 'You do not have permission to access this page.' ) ); |
| | 184 | |
| | 185 | if ( empty($plugin) || ! is_array($ids) ) |
| | 186 | break; |
| | 187 | |
| | 188 | foreach ( $ids as $id ) { |
| | 189 | $disable_plugins = get_blog_option($id, 'disable_plugins'); |
| | 190 | if ( in_array( $plugin , $disable_plugins) ){ |
| | 191 | |
| | 192 | $disable_plugins_updated = array(); |
| | 193 | foreach($disable_plugins as $pl){ |
| | 194 | if ( $pl != $plugin) |
| | 195 | $disable_plugins_updated[] = $pl; |
| | 196 | } |
| | 197 | $disable_plugins = $disable_plugins_updated; |
| | 198 | } |
| | 199 | |
| | 200 | $updated_option = update_blog_option($id, 'disable_plugins', $disable_plugins); |
| | 201 | if ( ! $updated_option ) |
| | 202 | add_blog_option( $id, 'disable_plugins', $disable_plugins ); |
| | 203 | else |
| | 204 | $reportupd[] = $id; |
| | 205 | } |
| | 206 | |
| | 207 | $updated_action = 'enable'; |
| | 208 | break; |
| | 209 | } |
| | 210 | |
| | 211 | if ( empty( $updated_action ) && in_array( $_GET['action'], $manage_actions ) ) |
| | 212 | $updated_action = $_GET['action']; |
| | 213 | |
| | 214 | if ( ! empty( $updated_action ) ) { |
| | 215 | wp_safe_redirect( add_query_arg( array( 'updated' => $updated_action, 'reportupd' => $reportupd, 'reportnotupd' => $reportnotupd ), wp_get_referer() ) ); |
| | 216 | exit(); |
| | 217 | } |
| | 218 | } |
| | 219 | |
| | 220 | $msg = ''; |
| | 221 | if ( isset( $_GET['updated'] ) ) { |
| | 222 | |
| | 223 | if ( !empty($reportupd) ){ |
| | 224 | $msg .= '<div class="updated"><ul>'; |
| | 225 | foreach ($reportupd as $id){ |
| | 226 | switch_to_blog( $id ); |
| | 227 | $msg .= '<li>' . sprintf( __ ('Settings saved in: <strong> %1$s </strong>' ), get_option( 'blogname' ) ) . '</li>'; |
| | 228 | restore_current_blog(); |
| | 229 | } |
| | 230 | $msg .= '</ul></div>'; |
| | 231 | } |
| | 232 | |
| | 233 | if ( !empty($reportnotupd) ){ |
| | 234 | $msg .= '<div class="error"><ul>'; |
| | 235 | foreach ($reportnotupd as $id){ |
| | 236 | switch_to_blog( $id ); |
| | 237 | $msg .= '<li>' . sprintf( __ ('Not updated in <strong> %1$s </strong> because the plugin is <strong>Active</strong>' ), get_option( 'blogname' ) ) . '</li>'; |
| | 238 | restore_current_blog(); |
| | 239 | } |
| | 240 | $msg .= '</ul></div>'; |
| | 241 | } |
| | 242 | |
| | 243 | } |
| | 244 | |
| | 245 | $wp_list_table->prepare_items(); |
| | 246 | |
| | 247 | require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
| | 248 | ?> |
| | 249 | |
| | 250 | <div class="wrap"> |
| | 251 | <h2><?php printf(__( 'Plugin settings: %s' ), $plugin ) ?> |
| | 252 | |
| | 253 | <?php if ( isset( $_REQUEST['s'] ) && $_REQUEST['s'] ) { |
| | 254 | printf( '<span class="subtitle">' . __( 'Search results for “%s”' ) . '</span>', esc_html( $s ) ); |
| | 255 | } ?> |
| | 256 | </h2> |
| | 257 | |
| | 258 | <?php echo $msg; ?> |
| | 259 | |
| | 260 | <form action="" method="get" id="ms-search"> |
| | 261 | <?php $wp_list_table->search_box( __( 'Search Sites' ), 'site' ); ?> |
| | 262 | <input type="hidden" name="action" value="blogs" /> |
| | 263 | </form> |
| | 264 | |
| | 265 | <form id="form-site-list" action="plugin-settings.php?action=allblogs&plugin=<?php echo $plugin ?>" method="post"> |
| | 266 | <?php $wp_list_table->display(); ?> |
| | 267 | </form> |
| | 268 | </div> |
| | 269 | <?php |
| | 270 | |
| | 271 | require_once( ABSPATH . 'wp-admin/admin-footer.php' ); ?> |
| | 272 | No newline at end of file |