home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress2 / wp-admin / network / site-themes.php < prev    next >
Encoding:
PHP Script  |  2017-07-17  |  6.2 KB  |  208 lines

  1. <?php
  2. /**
  3.  * Edit Site Themes Administration Screen
  4.  *
  5.  * @package WordPress
  6.  * @subpackage Multisite
  7.  * @since 3.1.0
  8.  */
  9.  
  10. /** Load WordPress Administration Bootstrap */
  11. require_once( dirname( __FILE__ ) . '/admin.php' );
  12.  
  13. if ( ! current_user_can( 'manage_sites' ) )
  14.     wp_die( __( 'Sorry, you are not allowed to manage themes for this site.' ) );
  15.  
  16. get_current_screen()->add_help_tab( get_site_screen_help_tab_args() );
  17. get_current_screen()->set_help_sidebar( get_site_screen_help_sidebar_content() );
  18.  
  19. get_current_screen()->set_screen_reader_content( array(
  20.     'heading_views'      => __( 'Filter site themes list' ),
  21.     'heading_pagination' => __( 'Site themes list navigation' ),
  22.     'heading_list'       => __( 'Site themes list' ),
  23. ) );
  24.  
  25. $wp_list_table = _get_list_table('WP_MS_Themes_List_Table');
  26.  
  27. $action = $wp_list_table->current_action();
  28.  
  29. $s = isset($_REQUEST['s']) ? $_REQUEST['s'] : '';
  30.  
  31. // Clean up request URI from temporary args for screen options/paging uri's to work as expected.
  32. $temp_args = array( 'enabled', 'disabled', 'error' );
  33. $_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI'] );
  34. $referer = remove_query_arg( $temp_args, wp_get_referer() );
  35.  
  36. if ( ! empty( $_REQUEST['paged'] ) ) {
  37.     $referer = add_query_arg( 'paged', (int) $_REQUEST['paged'], $referer );
  38. }
  39.  
  40. $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
  41.  
  42. if ( ! $id )
  43.     wp_die( __('Invalid site ID.') );
  44.  
  45. $wp_list_table->prepare_items();
  46.  
  47. $details = get_site( $id );
  48. if ( ! $details ) {
  49.     wp_die( __( 'The requested site does not exist.' ) );
  50. }
  51.  
  52. if ( !can_edit_network( $details->site_id ) )
  53.     wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
  54.  
  55. $is_main_site = is_main_site( $id );
  56.  
  57. if ( $action ) {
  58.     switch_to_blog( $id );
  59.     $allowed_themes = get_option( 'allowedthemes' );
  60.  
  61.     switch ( $action ) {
  62.         case 'enable':
  63.             check_admin_referer( 'enable-theme_' . $_GET['theme'] );
  64.             $theme = $_GET['theme'];
  65.             $action = 'enabled';
  66.             $n = 1;
  67.             if ( !$allowed_themes )
  68.                 $allowed_themes = array( $theme => true );
  69.             else
  70.                 $allowed_themes[$theme] = true;
  71.             break;
  72.         case 'disable':
  73.             check_admin_referer( 'disable-theme_' . $_GET['theme'] );
  74.             $theme = $_GET['theme'];
  75.             $action = 'disabled';
  76.             $n = 1;
  77.             if ( !$allowed_themes )
  78.                 $allowed_themes = array();
  79.             else
  80.                 unset( $allowed_themes[$theme] );
  81.             break;
  82.         case 'enable-selected':
  83.             check_admin_referer( 'bulk-themes' );
  84.             if ( isset( $_POST['checked'] ) ) {
  85.                 $themes = (array) $_POST['checked'];
  86.                 $action = 'enabled';
  87.                 $n = count( $themes );
  88.                 foreach ( (array) $themes as $theme )
  89.                     $allowed_themes[ $theme ] = true;
  90.             } else {
  91.                 $action = 'error';
  92.                 $n = 'none';
  93.             }
  94.             break;
  95.         case 'disable-selected':
  96.             check_admin_referer( 'bulk-themes' );
  97.             if ( isset( $_POST['checked'] ) ) {
  98.                 $themes = (array) $_POST['checked'];
  99.                 $action = 'disabled';
  100.                 $n = count( $themes );
  101.                 foreach ( (array) $themes as $theme )
  102.                     unset( $allowed_themes[ $theme ] );
  103.             } else {
  104.                 $action = 'error';
  105.                 $n = 'none';
  106.             }
  107.             break;
  108.         default:
  109.             if ( isset( $_POST['checked'] ) ) {
  110.                 check_admin_referer( 'bulk-themes' );
  111.                 $themes = (array) $_POST['checked'];
  112.                 $n = count( $themes );
  113.                 $screen = get_current_screen()->id;
  114.  
  115.                 /**
  116.                  * Fires when a custom bulk action should be handled.
  117.                  *
  118.                  * The redirect link should be modified with success or failure feedback
  119.                  * from the action to be used to display feedback to the user.
  120.                  *
  121.                  * The dynamic portion of the hook name, `$screen`, refers to the current screen ID.
  122.                  *
  123.                  * @since 4.7.0
  124.                  *
  125.                  * @param string $redirect_url The redirect URL.
  126.                  * @param string $action       The action being taken.
  127.                  * @param array  $items        The items to take the action on.
  128.                  * @param int    $site_id      The site ID.
  129.                  */
  130.                 $referer = apply_filters( "handle_network_bulk_actions-{$screen}", $referer, $action, $themes, $id );
  131.             } else {
  132.                 $action = 'error';
  133.                 $n = 'none';
  134.             }
  135.     }
  136.  
  137.     update_option( 'allowedthemes', $allowed_themes );
  138.     restore_current_blog();
  139.  
  140.     wp_safe_redirect( add_query_arg( array( 'id' => $id, $action => $n ), $referer ) );
  141.     exit;
  142. }
  143.  
  144. if ( isset( $_GET['action'] ) && 'update-site' == $_GET['action'] ) {
  145.     wp_safe_redirect( $referer );
  146.     exit();
  147. }
  148.  
  149. add_thickbox();
  150. add_screen_option( 'per_page' );
  151.  
  152. /* translators: %s: site name */
  153. $title = sprintf( __( 'Edit Site: %s' ), esc_html( $details->blogname ) );
  154.  
  155. $parent_file = 'sites.php';
  156. $submenu_file = 'sites.php';
  157.  
  158. require( ABSPATH . 'wp-admin/admin-header.php' ); ?>
  159.  
  160. <div class="wrap">
  161. <h1 id="edit-site"><?php echo $title; ?></h1>
  162. <p class="edit-site-actions"><a href="<?php echo esc_url( get_home_url( $id, '/' ) ); ?>"><?php _e( 'Visit' ); ?></a> | <a href="<?php echo esc_url( get_admin_url( $id ) ); ?>"><?php _e( 'Dashboard' ); ?></a></p>
  163. <?php
  164.  
  165. network_edit_site_nav( array(
  166.     'blog_id'  => $id,
  167.     'selected' => 'site-themes'
  168. ) );
  169.  
  170. if ( isset( $_GET['enabled'] ) ) {
  171.     $enabled = absint( $_GET['enabled'] );
  172.     if ( 1 == $enabled ) {
  173.         $message = __( 'Theme enabled.' );
  174.     } else {
  175.         $message = _n( '%s theme enabled.', '%s themes enabled.', $enabled );
  176.     }
  177.     echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $enabled ) ) . '</p></div>';
  178. } elseif ( isset( $_GET['disabled'] ) ) {
  179.     $disabled = absint( $_GET['disabled'] );
  180.     if ( 1 == $disabled ) {
  181.         $message = __( 'Theme disabled.' );
  182.     } else {
  183.         $message = _n( '%s theme disabled.', '%s themes disabled.', $disabled );
  184.     }
  185.     echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $disabled ) ) . '</p></div>';
  186. } elseif ( isset( $_GET['error'] ) && 'none' == $_GET['error'] ) {
  187.     echo '<div id="message" class="error notice is-dismissible"><p>' . __( 'No theme selected.' ) . '</p></div>';
  188. } ?>
  189.  
  190. <p><?php _e( 'Network enabled themes are not shown on this screen.' ) ?></p>
  191.  
  192. <form method="get">
  193. <?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?>
  194. <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
  195. </form>
  196.  
  197. <?php $wp_list_table->views(); ?>
  198.  
  199. <form method="post" action="site-themes.php?action=update-site">
  200.     <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
  201.  
  202. <?php $wp_list_table->display(); ?>
  203.  
  204. </form>
  205.  
  206. </div>
  207. <?php include(ABSPATH . 'wp-admin/admin-footer.php'); ?>
  208.