~canonical-sysadmins/wordpress/4.7

« back to all changes in this revision

Viewing changes to wp-admin/includes/ms.php

  • Committer: Nick Moffitt
  • Date: 2015-01-15 11:04:26 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: nick.moffitt@canonical.com-20150115110426-5stm1p14cfnxrtme
New Upstream Version 4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
        if ( upload_is_user_over_quota( false ) ) {
36
36
                $file['error'] = __( 'You have used your space quota. Please delete files before uploading.' );
37
37
        }
38
 
        if ( $file['error'] != '0' && !isset($_POST['html-upload']) )
 
38
        if ( $file['error'] != '0' && ! isset( $_POST['html-upload'] ) && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
39
39
                wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' );
 
40
        }
40
41
 
41
42
        return $file;
42
43
}
43
44
add_filter( 'wp_handle_upload_prefilter', 'check_upload_size' );
44
45
 
45
46
/**
46
 
 * Delete a blog
 
47
 * Delete a blog.
47
48
 *
48
49
 * @since 3.0.0
49
50
 *
50
 
 * @param int $blog_id Blog ID
51
 
 * @param bool $drop True if blog's table should be dropped. Default is false.
52
 
 * @return void
 
51
 * @param int  $blog_id Blog ID.
 
52
 * @param bool $drop    True if blog's table should be dropped. Default is false.
53
53
 */
54
54
function wpmu_delete_blog( $blog_id, $drop = false ) {
55
55
        global $wpdb;
84
84
 
85
85
        $current_site = get_current_site();
86
86
 
 
87
        // If a full blog object is not available, do not destroy anything.
 
88
        if ( $drop && ! $blog ) {
 
89
                $drop = false;
 
90
        }
 
91
 
87
92
        // Don't destroy the initial, main, or root blog.
88
 
        if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) )
89
 
                $drop = false;
 
93
        if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) ) {
 
94
                $drop = false;
 
95
        }
 
96
 
 
97
        $upload_path = trim( get_option( 'upload_path' ) );
 
98
 
 
99
        // If ms_files_rewriting is enabled and upload_path is empty, wp_upload_dir is not reliable.
 
100
        if ( $drop && get_site_option( 'ms_files_rewriting' ) && empty( $upload_path ) ) {
 
101
                $drop = false;
 
102
        }
90
103
 
91
104
        if ( $drop ) {
 
105
                $uploads = wp_upload_dir();
 
106
 
92
107
                $tables = $wpdb->tables( 'blog' );
93
108
                /**
94
109
                 * Filter the tables to drop when the blog is deleted.
106
121
 
107
122
                $wpdb->delete( $wpdb->blogs, array( 'blog_id' => $blog_id ) );
108
123
 
109
 
                $uploads = wp_upload_dir();
110
124
                /**
111
125
                 * Filter the upload base directory to delete when the blog is deleted.
112
126
                 *
154
168
                restore_current_blog();
155
169
}
156
170
 
157
 
// @todo Merge with wp_delete_user() ?
 
171
/**
 
172
 * Delete a user from the network and remove from all sites.
 
173
 *
 
174
 * @since 3.0.0
 
175
 *
 
176
 * @todo Merge with wp_delete_user() ?
 
177
 *
 
178
 * @param int $id The user ID.
 
179
 * @return bool True if the user was deleted, otherwise false.
 
180
 */
158
181
function wpmu_delete_user( $id ) {
159
182
        global $wpdb;
160
183
 
210
233
        return true;
211
234
}
212
235
 
 
236
/**
 
237
 * Sends an email when a site administrator email address is changed.
 
238
 *
 
239
 * @since 3.0.0
 
240
 *
 
241
 * @param string $old_value The old email address. Not currently used.
 
242
 * @param string $value     The new email address.
 
243
 */
213
244
function update_option_new_admin_email( $old_value, $value ) {
214
245
        if ( $value == get_option( 'admin_email' ) || !is_email( $value ) )
215
246
                return;
263
294
add_action( 'update_option_new_admin_email', 'update_option_new_admin_email', 10, 2 );
264
295
add_action( 'add_option_new_admin_email', 'update_option_new_admin_email', 10, 2 );
265
296
 
 
297
/**
 
298
 * Sends an email when an email address change is requested.
 
299
 *
 
300
 * @since 3.0.0
 
301
 *
 
302
 * @global object $errors WP_Error object.
 
303
 * @global object $wpdb   WordPress database object.
 
304
 */
266
305
function send_confirmation_on_profile_email() {
267
306
        global $errors, $wpdb;
268
307
        $current_user = wp_get_current_user();
333
372
}
334
373
add_action( 'personal_options_update', 'send_confirmation_on_profile_email' );
335
374
 
 
375
/**
 
376
 * Adds an admin notice alerting the user to check for confirmation email
 
377
 * after email address change.
 
378
 *
 
379
 * @since 3.0.0
 
380
 */
336
381
function new_user_email_admin_notice() {
337
382
        if ( strpos( $_SERVER['PHP_SELF'], 'profile.php' ) && isset( $_GET['updated'] ) && $email = get_option( get_current_user_id() . '_new_email' ) )
338
383
                echo "<div class='update-nag'>" . sprintf( __( "Your email address has not been updated yet. Please check your inbox at %s for a confirmation email." ), $email['newemail'] ) . "</div>";
345
390
 * @since MU
346
391
 *
347
392
 * @param bool $echo Optional. If $echo is set and the quota is exceeded, a warning message is echoed. Default is true.
348
 
 * @return int
 
393
 * @return bool True if user is over upload space quota, otherwise false.
349
394
 */
350
395
function upload_is_user_over_quota( $echo = true ) {
351
396
        if ( get_site_option( 'upload_space_check_disabled' ) )
395
440
 * Get the remaining upload space for this blog.
396
441
 *
397
442
 * @since MU
398
 
 * @uses upload_is_user_over_quota()
399
 
 * @uses get_space_allowed()
400
 
 * @uses get_upload_space_available()
401
443
 *
402
444
 * @param int $size Current max size in bytes
403
445
 * @return int Max size in bytes
410
452
        return min( $size, $available );
411
453
}
412
454
 
413
 
// Edit blog upload space setting on Edit Blog page
 
455
/**
 
456
 * Displays the edit blog upload space setting form on the Edit Blog screen.
 
457
 *
 
458
 * @since 3.0.0
 
459
 *
 
460
 * @param int $id The ID of the blog to display the setting for.
 
461
 */
414
462
function upload_space_setting( $id ) {
415
463
        switch_to_blog( $id );
416
464
        $quota = get_option( 'blog_upload_space' );
428
476
}
429
477
add_action( 'wpmueditblogaction', 'upload_space_setting' );
430
478
 
 
479
/**
 
480
 * Update the status of a user in the database.
 
481
 *
 
482
 * Used in core to mark a user as spam or "ham" (not spam) in Multisite.
 
483
 *
 
484
 * @since 3.0.0
 
485
 *
 
486
 * @param int    $id         The user ID.
 
487
 * @param string $pref       The column in the wp_users table to update the user's status
 
488
 *                           in (presumably user_status, spam, or deleted).
 
489
 * @param int    $value      The new status for the user.
 
490
 * @param null   $deprecated Deprecated as of 3.0.2 and should not be used.
 
491
 * @return int   The initially passed $value.
 
492
 */
431
493
function update_user_status( $id, $pref, $value, $deprecated = null ) {
432
494
        global $wpdb;
433
495
 
464
526
        return $value;
465
527
}
466
528
 
 
529
/**
 
530
 * Cleans the user cache for a specific user.
 
531
 *
 
532
 * @since 3.0.0
 
533
 *
 
534
 * @param int $id The user ID.
 
535
 * @return bool|int The ID of the refreshed user or false if the user does not exist.
 
536
 */
467
537
function refresh_user_details( $id ) {
468
538
        $id = (int) $id;
469
539
 
475
545
        return $id;
476
546
}
477
547
 
 
548
/**
 
549
 * Returns the language for a language code.
 
550
 *
 
551
 * @since 3.0.0
 
552
 *
 
553
 * @param string $code Optional. The two-letter language code. Default empty.
 
554
 * @return string The language corresponding to $code if it exists. If it does not exist,
 
555
 *                then the first two letters of $code is returned.
 
556
 */
478
557
function format_code_lang( $code = '' ) {
479
558
        $code = strtolower( substr( $code, 0, 2 ) );
480
559
        $lang_codes = array(
502
581
        return strtr( $code, $lang_codes );
503
582
}
504
583
 
 
584
/**
 
585
 * Synchronize category and post tag slugs when global terms are enabled.
 
586
 *
 
587
 * @since 3.0.0
 
588
 *
 
589
 * @param $term     The term.
 
590
 * @param $taxonomy The taxonomy for $term. Should be 'category' or 'post_tag', as these are
 
591
 *                  the only taxonomies which are processed by this function; anything else
 
592
 *                  will be returned untouched.
 
593
 * @return object|array Returns `$term`, after filtering the 'slug' field with {@see sanitize_title()}
 
594
 *                      if $taxonomy is 'category' or 'post_tag'.
 
595
 */
505
596
function sync_category_tag_slugs( $term, $taxonomy ) {
506
597
        if ( global_terms_enabled() && ( $taxonomy == 'category' || $taxonomy == 'post_tag' ) ) {
507
598
                if ( is_object( $term ) ) {
514
605
}
515
606
add_filter( 'get_term', 'sync_category_tag_slugs', 10, 2 );
516
607
 
 
608
/**
 
609
 * Displays an access denied message when a user tries to view a site's dashboard they
 
610
 * do not have access to.
 
611
 *
 
612
 * @since 3.2.0
 
613
 * @access private
 
614
 */
517
615
function _access_denied_splash() {
518
616
        if ( ! is_user_logged_in() || is_network_admin() )
519
617
                return;
548
646
}
549
647
add_action( 'admin_page_access_denied', '_access_denied_splash', 99 );
550
648
 
 
649
/**
 
650
 * Checks if the current user has permissions to import new users.
 
651
 *
 
652
 * @since 3.0.0
 
653
 *
 
654
 * @param string $permission A permission to be checked. Currently not used.
 
655
 * @return bool True if the user has proper permissions, false if they do not.
 
656
 */
551
657
function check_import_new_users( $permission ) {
552
658
        if ( !is_super_admin() )
553
659
                return false;
556
662
add_filter( 'import_allow_create_users', 'check_import_new_users' );
557
663
// See "import_allow_fetch_attachments" and "import_attachment_size_limit" filters too.
558
664
 
 
665
/**
 
666
 * Generates and displays a drop-down of available languages.
 
667
 *
 
668
 * @since 3.0.0
 
669
 *
 
670
 * @param array  $lang_files Optional. An array of the language files. Default empty array.
 
671
 * @param string $current    Optional. The current language code. Default empty.
 
672
 */
559
673
function mu_dropdown_languages( $lang_files = array(), $current = '' ) {
560
674
        $flag = false;
561
675
        $output = array();
583
697
 
584
698
        // Order by name
585
699
        uksort( $output, 'strnatcasecmp' );
 
700
 
586
701
        /**
587
702
         * Filter the languages available in the dropdown.
588
703
         *
593
708
         * @param string $current   The current language code.
594
709
         */
595
710
        $output = apply_filters( 'mu_dropdown_languages', $output, $lang_files, $current );
 
711
 
596
712
        echo implode( "\n\t", $output );
597
713
}
598
714
 
 
715
/**
 
716
 * Displays an admin notice to upgrade all sites after a core upgrade.
 
717
 *
 
718
 * @since 3.0.0
 
719
 *
 
720
 * @global int $wp_db_version The version number of the database.
 
721
 */
599
722
function site_admin_notice() {
600
723
        global $wp_db_version;
601
724
        if ( !is_super_admin() )
606
729
add_action( 'admin_notices', 'site_admin_notice' );
607
730
add_action( 'network_admin_notices', 'site_admin_notice' );
608
731
 
 
732
/**
 
733
 * Avoids a collision between a site slug and a permalink slug.
 
734
 *
 
735
 * In a subdirectory install this will make sure that a site and a post do not use the
 
736
 * same subdirectory by checking for a site with the same name as a new post.
 
737
 *
 
738
 * @since 3.0.0
 
739
 *
 
740
 * @param array $data    An array of post data.
 
741
 * @param array $postarr An array of posts. Not currently used.
 
742
 * @return array The new array of post data after checking for collisions.
 
743
 */
609
744
function avoid_blog_page_permalink_collision( $data, $postarr ) {
610
745
        if ( is_subdomain_install() )
611
746
                return $data;
629
764
}
630
765
add_filter( 'wp_insert_post_data', 'avoid_blog_page_permalink_collision', 10, 2 );
631
766
 
 
767
/**
 
768
 * Handles the display of choosing a user's primary site.
 
769
 *
 
770
 * This displays the user's primary site and allows the user to choose
 
771
 * which site is primary.
 
772
 *
 
773
 * @since 3.0.0
 
774
 */
632
775
function choose_primary_blog() {
633
776
        ?>
634
777
        <table class="form-table">
684
827
 * Grants Super Admin privileges.
685
828
 *
686
829
 * @since 3.0.0
 
830
 *
687
831
 * @param int $user_id ID of the user to be granted Super Admin privileges.
688
832
 * @return bool True on success, false on failure. This can fail when the user is
689
 
 *              already a super admin or when the $super_admins global is defined.
 
833
 *              already a super admin or when the `$super_admins` global is defined.
690
834
 */
691
835
function grant_super_admin( $user_id ) {
692
836
        // If global super_admins override is defined, there is nothing to do here.
728
872
 * Revokes Super Admin privileges.
729
873
 *
730
874
 * @since 3.0.0
 
875
 *
731
876
 * @param int $user_id ID of the user Super Admin privileges to be revoked from.
732
877
 * @return bool True on success, false on failure. This can fail when the user's email
733
 
 *              is the network admin email or when the $super_admins global is defined.
 
878
 *              is the network admin email or when the `$super_admins` global is defined.
734
879
 */
735
880
function revoke_super_admin( $user_id ) {
736
881
        // If global super_admins override is defined, there is nothing to do here.
771
916
}
772
917
 
773
918
/**
774
 
 * Whether or not we can edit this network from this page
 
919
 * Whether or not we can edit this network from this page.
775
920
 *
776
 
 * By default editing of network is restricted to the Network Admin for that site_id this allows for this to be overridden
 
921
 * By default editing of network is restricted to the Network Admin for that `$site_id`
 
922
 * this allows for this to be overridden.
777
923
 *
778
924
 * @since 3.1.0
779
 
 * @param integer $site_id The network/site ID to check.
 
925
 *
 
926
 * @param int $site_id The network/site ID to check.
 
927
 * @return bool True if network can be edited, otherwise false.
780
928
 */
781
929
function can_edit_network( $site_id ) {
782
930
        global $wpdb;
801
949
 * Thickbox image paths for Network Admin.
802
950
 *
803
951
 * @since 3.1.0
 
952
 *
804
953
 * @access private
805
954
 */
806
955
function _thickbox_path_admin_subfolder() {
807
956
?>
808
957
<script type="text/javascript">
809
958
//<![CDATA[
810
 
var tb_pathToImage = "../../wp-includes/js/thickbox/loadingAnimation.gif";
 
959
var tb_pathToImage = "<?php echo includes_url( 'js/thickbox/loadingAnimation.gif', 'relative' ); ?>";
811
960
//]]>
812
961
</script>
813
962
<?php