123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556 |
- <?php
- function get_sitestats() {
- $stats = array(
- 'blogs' => get_blog_count(),
- 'users' => get_user_count(),
- );
- return $stats;
- }
- function get_active_blog_for_user( $user_id ) {
- global $wpdb;
- $blogs = get_blogs_of_user( $user_id );
- if ( empty( $blogs ) )
- return;
- if ( !is_multisite() )
- return $blogs[$wpdb->blogid];
- $primary_blog = get_user_meta( $user_id, 'primary_blog', true );
- $first_blog = current($blogs);
- if ( false !== $primary_blog ) {
- if ( ! isset( $blogs[ $primary_blog ] ) ) {
- update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id );
- $primary = get_site( $first_blog->userblog_id );
- } else {
- $primary = get_site( $primary_blog );
- }
- } else {
-
- add_user_to_blog( $first_blog->userblog_id, $user_id, 'subscriber' );
- update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id );
- $primary = $first_blog;
- }
- if ( ( ! is_object( $primary ) ) || ( $primary->archived == 1 || $primary->spam == 1 || $primary->deleted == 1 ) ) {
- $blogs = get_blogs_of_user( $user_id, true );
- $ret = false;
- if ( is_array( $blogs ) && count( $blogs ) > 0 ) {
- foreach ( (array) $blogs as $blog_id => $blog ) {
- if ( $blog->site_id != $wpdb->siteid )
- continue;
- $details = get_site( $blog_id );
- if ( is_object( $details ) && $details->archived == 0 && $details->spam == 0 && $details->deleted == 0 ) {
- $ret = $blog;
- if ( get_user_meta( $user_id , 'primary_blog', true ) != $blog_id )
- update_user_meta( $user_id, 'primary_blog', $blog_id );
- if ( !get_user_meta($user_id , 'source_domain', true) )
- update_user_meta( $user_id, 'source_domain', $blog->domain );
- break;
- }
- }
- } else {
- return;
- }
- return $ret;
- } else {
- return $primary;
- }
- }
- function get_user_count( $network_id = null ) {
- return get_network_option( $network_id, 'user_count' );
- }
- function get_blog_count( $network_id = null ) {
- return get_network_option( $network_id, 'blog_count' );
- }
- function get_blog_post( $blog_id, $post_id ) {
- switch_to_blog( $blog_id );
- $post = get_post( $post_id );
- restore_current_blog();
- return $post;
- }
- function add_user_to_blog( $blog_id, $user_id, $role ) {
- switch_to_blog($blog_id);
- $user = get_userdata( $user_id );
- if ( ! $user ) {
- restore_current_blog();
- return new WP_Error( 'user_does_not_exist', __( 'The requested user does not exist.' ) );
- }
- if ( !get_user_meta($user_id, 'primary_blog', true) ) {
- update_user_meta($user_id, 'primary_blog', $blog_id);
- $site = get_site( $blog_id );
- update_user_meta( $user_id, 'source_domain', $site->domain );
- }
- $user->set_role($role);
-
- do_action( 'add_user_to_blog', $user_id, $role, $blog_id );
- wp_cache_delete( $user_id, 'users' );
- wp_cache_delete( $blog_id . '_user_count', 'blog-details' );
- restore_current_blog();
- return true;
- }
- function remove_user_from_blog($user_id, $blog_id = '', $reassign = '') {
- global $wpdb;
- switch_to_blog($blog_id);
- $user_id = (int) $user_id;
-
- do_action( 'remove_user_from_blog', $user_id, $blog_id );
-
-
- $primary_blog = get_user_meta($user_id, 'primary_blog', true);
- if ( $primary_blog == $blog_id ) {
- $new_id = '';
- $new_domain = '';
- $blogs = get_blogs_of_user($user_id);
- foreach ( (array) $blogs as $blog ) {
- if ( $blog->userblog_id == $blog_id )
- continue;
- $new_id = $blog->userblog_id;
- $new_domain = $blog->domain;
- break;
- }
- update_user_meta($user_id, 'primary_blog', $new_id);
- update_user_meta($user_id, 'source_domain', $new_domain);
- }
-
- $user = get_userdata( $user_id );
- if ( ! $user ) {
- restore_current_blog();
- return new WP_Error('user_does_not_exist', __('That user does not exist.'));
- }
- $user->remove_all_caps();
- $blogs = get_blogs_of_user($user_id);
- if ( count($blogs) == 0 ) {
- update_user_meta($user_id, 'primary_blog', '');
- update_user_meta($user_id, 'source_domain', '');
- }
- if ( $reassign != '' ) {
- $reassign = (int) $reassign;
- $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $user_id ) );
- $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $user_id ) );
- if ( ! empty( $post_ids ) ) {
- $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_author = %d WHERE post_author = %d", $reassign, $user_id ) );
- array_walk( $post_ids, 'clean_post_cache' );
- }
- if ( ! empty( $link_ids ) ) {
- $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->links SET link_owner = %d WHERE link_owner = %d", $reassign, $user_id ) );
- array_walk( $link_ids, 'clean_bookmark_cache' );
- }
- }
- restore_current_blog();
- return true;
- }
- function get_blog_permalink( $blog_id, $post_id ) {
- switch_to_blog( $blog_id );
- $link = get_permalink( $post_id );
- restore_current_blog();
- return $link;
- }
- function get_blog_id_from_url( $domain, $path = '/' ) {
- $domain = strtolower( $domain );
- $path = strtolower( $path );
- $id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' );
- if ( $id == -1 )
- return 0;
- elseif ( $id )
- return (int) $id;
- $args = array(
- 'domain' => $domain,
- 'path' => $path,
- 'fields' => 'ids',
- );
- $result = get_sites( $args );
- $id = array_shift( $result );
- if ( ! $id ) {
- wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' );
- return 0;
- }
- wp_cache_set( md5( $domain . $path ), $id, 'blog-id-cache' );
- return $id;
- }
- function is_email_address_unsafe( $user_email ) {
- $banned_names = get_site_option( 'banned_email_domains' );
- if ( $banned_names && ! is_array( $banned_names ) )
- $banned_names = explode( "\n", $banned_names );
- $is_email_address_unsafe = false;
- if ( $banned_names && is_array( $banned_names ) && false !== strpos( $user_email, '@', 1 ) ) {
- $banned_names = array_map( 'strtolower', $banned_names );
- $normalized_email = strtolower( $user_email );
- list( $email_local_part, $email_domain ) = explode( '@', $normalized_email );
- foreach ( $banned_names as $banned_domain ) {
- if ( ! $banned_domain )
- continue;
- if ( $email_domain == $banned_domain ) {
- $is_email_address_unsafe = true;
- break;
- }
- $dotted_domain = ".$banned_domain";
- if ( $dotted_domain === substr( $normalized_email, -strlen( $dotted_domain ) ) ) {
- $is_email_address_unsafe = true;
- break;
- }
- }
- }
-
- return apply_filters( 'is_email_address_unsafe', $is_email_address_unsafe, $user_email );
- }
- function wpmu_validate_user_signup($user_name, $user_email) {
- global $wpdb;
- $errors = new WP_Error();
- $orig_username = $user_name;
- $user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) );
- if ( $user_name != $orig_username || preg_match( '/[^a-z0-9]/', $user_name ) ) {
- $errors->add( 'user_name', __( 'Usernames can only contain lowercase letters (a-z) and numbers.' ) );
- $user_name = $orig_username;
- }
- $user_email = sanitize_email( $user_email );
- if ( empty( $user_name ) )
- $errors->add('user_name', __( 'Please enter a username.' ) );
- $illegal_names = get_site_option( 'illegal_names' );
- if ( ! is_array( $illegal_names ) ) {
- $illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' );
- add_site_option( 'illegal_names', $illegal_names );
- }
- if ( in_array( $user_name, $illegal_names ) ) {
- $errors->add( 'user_name', __( 'Sorry, that username is not allowed.' ) );
- }
-
- $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
- if ( in_array( strtolower( $user_name ), array_map( 'strtolower', $illegal_logins ) ) ) {
- $errors->add( 'user_name', __( 'Sorry, that username is not allowed.' ) );
- }
- if ( ! is_email( $user_email ) ) {
- $errors->add( 'user_email', __( 'Please enter a valid email address.' ) );
- } elseif ( is_email_address_unsafe( $user_email ) ) {
- $errors->add( 'user_email', __( 'You cannot use that email address to signup. We are having problems with them blocking some of our email. Please use another email provider.' ) );
- }
- if ( strlen( $user_name ) < 4 )
- $errors->add('user_name', __( 'Username must be at least 4 characters.' ) );
- if ( strlen( $user_name ) > 60 ) {
- $errors->add( 'user_name', __( 'Username may not be longer than 60 characters.' ) );
- }
-
- if ( preg_match( '/^[0-9]*$/', $user_name ) )
- $errors->add('user_name', __('Sorry, usernames must have letters too!'));
- $limited_email_domains = get_site_option( 'limited_email_domains' );
- if ( is_array( $limited_email_domains ) && ! empty( $limited_email_domains ) ) {
- $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
- if ( ! in_array( $emaildomain, $limited_email_domains ) ) {
- $errors->add('user_email', __('Sorry, that email address is not allowed!'));
- }
- }
-
- if ( username_exists($user_name) )
- $errors->add( 'user_name', __( 'Sorry, that username already exists!' ) );
-
- if ( email_exists($user_email) )
- $errors->add( 'user_email', __( 'Sorry, that email address is already used!' ) );
-
- $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name) );
- if ( $signup != null ) {
- $registered_at = mysql2date('U', $signup->registered);
- $now = current_time( 'timestamp', true );
- $diff = $now - $registered_at;
-
- if ( $diff > 2 * DAY_IN_SECONDS )
- $wpdb->delete( $wpdb->signups, array( 'user_login' => $user_name ) );
- else
- $errors->add('user_name', __('That username is currently reserved but may be available in a couple of days.'));
- }
- $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE user_email = %s", $user_email) );
- if ( $signup != null ) {
- $diff = current_time( 'timestamp', true ) - mysql2date('U', $signup->registered);
-
- if ( $diff > 2 * DAY_IN_SECONDS )
- $wpdb->delete( $wpdb->signups, array( 'user_email' => $user_email ) );
- else
- $errors->add('user_email', __('That email address has already been used. Please check your inbox for an activation email. It will become available in a couple of days if you do nothing.'));
- }
- $result = array('user_name' => $user_name, 'orig_username' => $orig_username, 'user_email' => $user_email, 'errors' => $errors);
-
- return apply_filters( 'wpmu_validate_user_signup', $result );
- }
- function wpmu_validate_blog_signup( $blogname, $blog_title, $user = '' ) {
- global $wpdb, $domain;
- $current_network = get_network();
- $base = $current_network->path;
- $blog_title = strip_tags( $blog_title );
- $errors = new WP_Error();
- $illegal_names = get_site_option( 'illegal_names' );
- if ( $illegal_names == false ) {
- $illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' );
- add_site_option( 'illegal_names', $illegal_names );
- }
-
- if ( ! is_subdomain_install() ) {
- $illegal_names = array_merge( $illegal_names, get_subdirectory_reserved_names() );
- }
- if ( empty( $blogname ) )
- $errors->add('blogname', __( 'Please enter a site name.' ) );
- if ( preg_match( '/[^a-z0-9]+/', $blogname ) ) {
- $errors->add( 'blogname', __( 'Site names can only contain lowercase letters (a-z) and numbers.' ) );
- }
- if ( in_array( $blogname, $illegal_names ) )
- $errors->add('blogname', __( 'That name is not allowed.' ) );
-
- $minimum_site_name_length = apply_filters( 'minimum_site_name_length', 4 );
- if ( strlen( $blogname ) < $minimum_site_name_length ) {
-
- $errors->add( 'blogname', sprintf( _n( 'Site name must be at least %s character.', 'Site name must be at least %s characters.', $minimum_site_name_length ), number_format_i18n( $minimum_site_name_length ) ) );
- }
-
- if ( !is_subdomain_install() && $wpdb->get_var( $wpdb->prepare( "SELECT post_name FROM " . $wpdb->get_blog_prefix( $current_network->site_id ) . "posts WHERE post_type = 'page' AND post_name = %s", $blogname ) ) )
- $errors->add( 'blogname', __( 'Sorry, you may not use that site name.' ) );
-
- if ( preg_match( '/^[0-9]*$/', $blogname ) )
- $errors->add('blogname', __('Sorry, site names must have letters too!'));
-
- $blogname = apply_filters( 'newblogname', $blogname );
- $blog_title = wp_unslash( $blog_title );
- if ( empty( $blog_title ) )
- $errors->add('blog_title', __( 'Please enter a site title.' ) );
-
- if ( is_subdomain_install() ) {
- $mydomain = $blogname . '.' . preg_replace( '|^www\.|', '', $domain );
- $path = $base;
- } else {
- $mydomain = "$domain";
- $path = $base.$blogname.'/';
- }
- if ( domain_exists($mydomain, $path, $current_network->id) )
- $errors->add( 'blogname', __( 'Sorry, that site already exists!' ) );
- if ( username_exists( $blogname ) ) {
- if ( ! is_object( $user ) || ( is_object($user) && ( $user->user_login != $blogname ) ) )
- $errors->add( 'blogname', __( 'Sorry, that site is reserved!' ) );
- }
-
- $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path) );
- if ( ! empty($signup) ) {
- $diff = current_time( 'timestamp', true ) - mysql2date('U', $signup->registered);
-
- if ( $diff > 2 * DAY_IN_SECONDS )
- $wpdb->delete( $wpdb->signups, array( 'domain' => $mydomain , 'path' => $path ) );
- else
- $errors->add('blogname', __('That site is currently reserved but may be available in a couple days.'));
- }
- $result = array('domain' => $mydomain, 'path' => $path, 'blogname' => $blogname, 'blog_title' => $blog_title, 'user' => $user, 'errors' => $errors);
-
- return apply_filters( 'wpmu_validate_blog_signup', $result );
- }
- function wpmu_signup_blog( $domain, $path, $title, $user, $user_email, $meta = array() ) {
- global $wpdb;
- $key = substr( md5( time() . wp_rand() . $domain ), 0, 16 );
-
- $meta = apply_filters( 'signup_site_meta', $meta, $domain, $path, $title, $user, $user_email, $key );
- $wpdb->insert( $wpdb->signups, array(
- 'domain' => $domain,
- 'path' => $path,
- 'title' => $title,
- 'user_login' => $user,
- 'user_email' => $user_email,
- 'registered' => current_time('mysql', true),
- 'activation_key' => $key,
- 'meta' => serialize( $meta )
- ) );
-
- do_action( 'after_signup_site', $domain, $path, $title, $user, $user_email, $key, $meta );
- }
- function wpmu_signup_user( $user, $user_email, $meta = array() ) {
- global $wpdb;
-
- $user = preg_replace( '/\s+/', '', sanitize_user( $user, true ) );
- $user_email = sanitize_email( $user_email );
- $key = substr( md5( time() . wp_rand() . $user_email ), 0, 16 );
-
- $meta = apply_filters( 'signup_user_meta', $meta, $user, $user_email, $key );
- $wpdb->insert( $wpdb->signups, array(
- 'domain' => '',
- 'path' => '',
- 'title' => '',
- 'user_login' => $user,
- 'user_email' => $user_email,
- 'registered' => current_time('mysql', true),
- 'activation_key' => $key,
- 'meta' => serialize( $meta )
- ) );
-
- do_action( 'after_signup_user', $user, $user_email, $key, $meta );
- }
- function wpmu_signup_blog_notification( $domain, $path, $title, $user_login, $user_email, $key, $meta = array() ) {
-
- if ( ! apply_filters( 'wpmu_signup_blog_notification', $domain, $path, $title, $user_login, $user_email, $key, $meta ) ) {
- return false;
- }
-
- if ( !is_subdomain_install() || get_current_network_id() != 1 )
- $activate_url = network_site_url("wp-activate.php?key=$key");
- else
- $activate_url = "http://{$domain}{$path}wp-activate.php?key=$key";
- $activate_url = esc_url($activate_url);
- $admin_email = get_site_option( 'admin_email' );
- if ( $admin_email == '' )
- $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
- $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );
- $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
- $user = get_user_by( 'login', $user_login );
- $switched_locale = switch_to_locale( get_user_locale( $user ) );
- $message = sprintf(
-
- apply_filters( 'wpmu_signup_blog_notification_email',
- __( "To activate your blog, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login.\n\nAfter you activate, you can visit your site here:\n\n%s" ),
- $domain, $path, $title, $user_login, $user_email, $key, $meta
- ),
- $activate_url,
- esc_url( "http://{$domain}{$path}" ),
- $key
- );
-
- $subject = sprintf(
-
- apply_filters( 'wpmu_signup_blog_notification_subject',
-
- _x( '[%1$s] Activate %2$s', 'New site notification email subject' ),
- $domain, $path, $title, $user_login, $user_email, $key, $meta
- ),
- $from_name,
- esc_url( 'http://' . $domain . $path )
- );
- wp_mail( $user_email, wp_specialchars_decode( $subject ), $message, $message_headers );
- if ( $switched_locale ) {
- restore_previous_locale();
- }
- return true;
- }
- function wpmu_signup_user_notification( $user_login, $user_email, $key, $meta = array() ) {
-
- if ( ! apply_filters( 'wpmu_signup_user_notification', $user_login, $user_email, $key, $meta ) )
- return false;
- $user = get_user_by( 'login', $user_login );
- $switched_locale = switch_to_locale( get_user_locale( $user ) );
-
- $admin_email = get_site_option( 'admin_email' );
- if ( $admin_email == '' )
- $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
- $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );
- $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
- $message = sprintf(
-
- apply_filters( 'wpmu_signup_user_notification_email',
- __( "To activate your user, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login." ),
- $user_login, $user_email, $key, $meta
- ),
- site_url( "wp-activate.php?key=$key" )
- );
-
- $subject = sprintf(
-
- apply_filters( 'wpmu_signup_user_notification_subject',
-
- _x( '[%1$s] Activate %2$s', 'New user notification email subject' ),
- $user_login, $user_email, $key, $meta
- ),
- $from_name,
- $user_login
- );
- wp_mail( $user_email, wp_specialchars_decode( $subject ), $message, $message_headers );
- if ( $switched_locale ) {
- restore_previous_locale();
- }
- return true;
- }
- function wpmu_activate_signup($key) {
- global $wpdb;
- $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE activation_key = %s", $key) );
- if ( empty( $signup ) )
- return new WP_Error( 'invalid_key', __( 'Invalid activation key.' ) );
- if ( $signup->active ) {
- if ( empty( $signup->domain ) )
- return new WP_Error( 'already_active', __( 'The user is already active.' ), $signup );
- else
- return new WP_Error( 'already_active', __( 'The site is already active.' ), $signup );
- }
- $meta = maybe_unserialize($signup->meta);
- $password = wp_generate_password( 12, false );
- $user_id = username_exists($signup->user_login);
- if ( ! $user_id )
- $user_id = wpmu_create_user($signup->user_login, $password, $signup->user_email);
- else
- $user_already_exists = true;
- if ( ! $user_id )
- return new WP_Error('create_user', __('Could not create user'), $signup);
- $now = current_time('mysql', true);
- if ( empty($signup->domain) ) {
- $wpdb->update( $wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key) );
- if ( isset( $user_already_exists ) )
- return new WP_Error( 'user_already_exists', __( 'That username is already activated.' ), $signup);
-
- do_action( 'wpmu_activate_user', $user_id, $password, $meta );
- return array( 'user_id' => $user_id, 'password' => $password, 'meta' => $meta );
- }
- $blog_id = wpmu_create_blog( $signup->domain, $signup->path, $signup->title, $user_id, $meta, $wpdb->siteid );
-
- if ( is_wp_error($blog_id) ) {
-
-
- if ( 'blog_taken' == $blog_id->get_error_code() ) {
- $blog_id->add_data( $signup );
- $wpdb->update( $wpdb->signups, array( 'active' => 1, 'activated' => $now ), array( 'activation_key' => $key ) );
- }
- return $blog_id;
- }
- $wpdb->update( $wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key) );
-
- do_action( 'wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta );
- return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta);
- }
- function wpmu_create_user( $user_name, $password, $email ) {
- $user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) );
- $user_id = wp_create_user( $user_name, $password, $email );
- if ( is_wp_error( $user_id ) )
- return false;
-
- delete_user_option( $user_id, 'capabilities' );
- delete_user_option( $user_id, 'user_level' );
-
- do_action( 'wpmu_new_user', $user_id );
- return $user_id;
- }
- function wpmu_create_blog( $domain, $path, $title, $user_id, $meta = array(), $site_id = 1 ) {
- $defaults = array(
- 'public' => 0,
- 'WPLANG' => get_site_option( 'WPLANG' ),
- );
- $meta = wp_parse_args( $meta, $defaults );
- $domain = preg_replace( '/\s+/', '', sanitize_user( $domain, true ) );
- if ( is_subdomain_install() )
- $domain = str_replace( '@', '', $domain );
- $title = strip_tags( $title );
- $user_id = (int) $user_id;
- if ( empty($path) )
- $path = '/';
-
- if ( domain_exists($domain, $path, $site_id) )
- return new WP_Error( 'blog_taken', __( 'Sorry, that site already exists!' ) );
- if ( ! wp_installing() ) {
- wp_installing( true );
- }
- if ( ! $blog_id = insert_blog($domain, $path, $site_id) )
- return new WP_Error('insert_blog', __('Could not create site.'));
- switch_to_blog($blog_id);
- install_blog($blog_id, $title);
- wp_install_defaults($user_id);
- add_user_to_blog($blog_id, $user_id, 'administrator');
- foreach ( $meta as $key => $value ) {
- if ( in_array( $key, array( 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' ) ) )
- update_blog_status( $blog_id, $key, $value );
- else
- update_option( $key, $value );
- }
- update_option( 'blog_public', (int) $meta['public'] );
- if ( ! is_super_admin( $user_id ) && ! get_user_meta( $user_id, 'primary_blog', true ) )
- update_user_meta( $user_id, 'primary_blog', $blog_id );
- restore_current_blog();
-
- do_action( 'wpmu_new_blog', $blog_id, $user_id, $domain, $path, $site_id, $meta );
- wp_cache_set( 'last_changed', microtime(), 'sites' );
- return $blog_id;
- }
- function newblog_notify_siteadmin( $blog_id, $deprecated = '' ) {
- if ( get_site_option( 'registrationnotification' ) != 'yes' )
- return false;
- $email = get_site_option( 'admin_email' );
- if ( is_email($email) == false )
- return false;
- $options_site_url = esc_url(network_admin_url('settings.php'));
- switch_to_blog( $blog_id );
- $blogname = get_option( 'blogname' );
- $siteurl = site_url();
- restore_current_blog();
-
- $msg = sprintf( __( 'New Site: %1$s
- URL: %2$s
- Remote IP: %3$s
- Disable these notifications: %4$s' ), $blogname, $siteurl, wp_unslash( $_SERVER['REMOTE_ADDR'] ), $options_site_url);
-
- $msg = apply_filters( 'newblog_notify_siteadmin', $msg );
- wp_mail( $email, sprintf( __( 'New Site Registration: %s' ), $siteurl ), $msg );
- return true;
- }
- function newuser_notify_siteadmin( $user_id ) {
- if ( get_site_option( 'registrationnotification' ) != 'yes' )
- return false;
- $email = get_site_option( 'admin_email' );
- if ( is_email($email) == false )
- return false;
- $user = get_userdata( $user_id );
- $options_site_url = esc_url(network_admin_url('settings.php'));
-
- $msg = sprintf(__('New User: %1$s
- Remote IP: %2$s
- Disable these notifications: %3$s'), $user->user_login, wp_unslash( $_SERVER['REMOTE_ADDR'] ), $options_site_url);
-
- $msg = apply_filters( 'newuser_notify_siteadmin', $msg, $user );
- wp_mail( $email, sprintf(__('New User Registration: %s'), $user->user_login), $msg );
- return true;
- }
- function domain_exists($domain, $path, $site_id = 1) {
- $path = trailingslashit( $path );
- $args = array(
- 'network_id' => $site_id,
- 'domain' => $domain,
- 'path' => $path,
- 'fields' => 'ids',
- );
- $result = get_sites( $args );
- $result = array_shift( $result );
-
- return apply_filters( 'domain_exists', $result, $domain, $path, $site_id );
- }
- function insert_blog($domain, $path, $site_id) {
- global $wpdb;
- $path = trailingslashit($path);
- $site_id = (int) $site_id;
- $result = $wpdb->insert( $wpdb->blogs, array('site_id' => $site_id, 'domain' => $domain, 'path' => $path, 'registered' => current_time('mysql')) );
- if ( ! $result )
- return false;
- $blog_id = $wpdb->insert_id;
- refresh_blog_details( $blog_id );
- wp_maybe_update_network_site_counts( $site_id );
- return $blog_id;
- }
- function install_blog( $blog_id, $blog_title = '' ) {
- global $wpdb, $wp_roles;
-
- $blog_id = (int) $blog_id;
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
- $suppress = $wpdb->suppress_errors();
- if ( $wpdb->get_results( "DESCRIBE {$wpdb->posts}" ) )
- die( '<h1>' . __( 'Already Installed' ) . '</h1><p>' . __( 'You appear to have already installed WordPress. To reinstall please clear your old database tables first.' ) . '</p></body></html>' );
- $wpdb->suppress_errors( $suppress );
- $url = get_blogaddress_by_id( $blog_id );
-
- make_db_current_silent( 'blog' );
- populate_options();
- populate_roles();
-
- $wp_roles = new WP_Roles();
- $siteurl = $home = untrailingslashit( $url );
- if ( ! is_subdomain_install() ) {
- if ( 'https' === parse_url( get_site_option( 'siteurl' ), PHP_URL_SCHEME ) ) {
- $siteurl = set_url_scheme( $siteurl, 'https' );
- }
- if ( 'https' === parse_url( get_home_url( get_network()->site_id ), PHP_URL_SCHEME ) ) {
- $home = set_url_scheme( $home, 'https' );
- }
- }
- update_option( 'siteurl', $siteurl );
- update_option( 'home', $home );
- if ( get_site_option( 'ms_files_rewriting' ) )
- update_option( 'upload_path', UPLOADBLOGSDIR . "/$blog_id/files" );
- else
- update_option( 'upload_path', get_blog_option( get_network()->site_id, 'upload_path' ) );
- update_option( 'blogname', wp_unslash( $blog_title ) );
- update_option( 'admin_email', '' );
-
- $table_prefix = $wpdb->get_blog_prefix();
- delete_metadata( 'user', 0, $table_prefix . 'user_level', null, true );
- delete_metadata( 'user', 0, $table_prefix . 'capabilities', null, true );
- }
- function install_blog_defaults($blog_id, $user_id) {
- global $wpdb;
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
- $suppress = $wpdb->suppress_errors();
- wp_install_defaults($user_id);
- $wpdb->suppress_errors( $suppress );
- }
- function wpmu_welcome_notification( $blog_id, $user_id, $password, $title, $meta = array() ) {
- $current_network = get_network();
-
- if ( ! apply_filters( 'wpmu_welcome_notification', $blog_id, $user_id, $password, $title, $meta ) )
- return false;
- $user = get_userdata( $user_id );
- $switched_locale = switch_to_locale( get_user_locale( $user ) );
- $welcome_email = get_site_option( 'welcome_email' );
- if ( $welcome_email == false ) {
-
- $welcome_email = __( 'Howdy USERNAME,
- Your new SITE_NAME site has been successfully set up at:
- BLOG_URL
- You can log in to the administrator account with the following information:
- Username: USERNAME
- Password: PASSWORD
- Log in here: BLOG_URLwp-login.php
- We hope you enjoy your new site. Thanks!
- --The Team @ SITE_NAME' );
- }
- $url = get_blogaddress_by_id($blog_id);
- $welcome_email = str_replace( 'SITE_NAME', $current_network->site_name, $welcome_email );
- $welcome_email = str_replace( 'BLOG_TITLE', $title, $welcome_email );
- $welcome_email = str_replace( 'BLOG_URL', $url, $welcome_email );
- $welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email );
- $welcome_email = str_replace( 'PASSWORD', $password, $welcome_email );
-
- $welcome_email = apply_filters( 'update_welcome_email', $welcome_email, $blog_id, $user_id, $password, $title, $meta );
- $admin_email = get_site_option( 'admin_email' );
- if ( $admin_email == '' )
- $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
- $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );
- $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
- $message = $welcome_email;
- if ( empty( $current_network->site_name ) )
- $current_network->site_name = 'WordPress';
-
- $subject = __( 'New %1$s Site: %2$s' );
-
- $subject = apply_filters( 'update_welcome_subject', sprintf( $subject, $current_network->site_name, wp_unslash( $title ) ) );
- wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers );
- if ( $switched_locale ) {
- restore_previous_locale();
- }
- return true;
- }
- function wpmu_welcome_user_notification( $user_id, $password, $meta = array() ) {
- $current_network = get_network();
-
- if ( ! apply_filters( 'wpmu_welcome_user_notification', $user_id, $password, $meta ) )
- return false;
- $welcome_email = get_site_option( 'welcome_user_email' );
- $user = get_userdata( $user_id );
- $switched_locale = switch_to_locale( get_user_locale( $user ) );
-
- $welcome_email = apply_filters( 'update_welcome_user_email', $welcome_email, $user_id, $password, $meta );
- $welcome_email = str_replace( 'SITE_NAME', $current_network->site_name, $welcome_email );
- $welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email );
- $welcome_email = str_replace( 'PASSWORD', $password, $welcome_email );
- $welcome_email = str_replace( 'LOGINLINK', wp_login_url(), $welcome_email );
- $admin_email = get_site_option( 'admin_email' );
- if ( $admin_email == '' )
- $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
- $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );
- $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
- $message = $welcome_email;
- if ( empty( $current_network->site_name ) )
- $current_network->site_name = 'WordPress';
-
- $subject = __( 'New %1$s User: %2$s' );
-
- $subject = apply_filters( 'update_welcome_user_subject', sprintf( $subject, $current_network->site_name, $user->user_login) );
- wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers );
- if ( $switched_locale ) {
- restore_previous_locale();
- }
- return true;
- }
- function get_current_site() {
- global $current_site;
- return $current_site;
- }
- function get_most_recent_post_of_user( $user_id ) {
- global $wpdb;
- $user_blogs = get_blogs_of_user( (int) $user_id );
- $most_recent_post = array();
-
-
- foreach ( (array) $user_blogs as $blog ) {
- $prefix = $wpdb->get_blog_prefix( $blog->userblog_id );
- $recent_post = $wpdb->get_row( $wpdb->prepare("SELECT ID, post_date_gmt FROM {$prefix}posts WHERE post_author = %d AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1", $user_id ), ARRAY_A);
-
- if ( isset($recent_post['ID']) ) {
- $post_gmt_ts = strtotime($recent_post['post_date_gmt']);
-
-
-
- if ( !isset($most_recent_post['post_gmt_ts']) || ( $post_gmt_ts > $most_recent_post['post_gmt_ts'] ) ) {
- $most_recent_post = array(
- 'blog_id' => $blog->userblog_id,
- 'post_id' => $recent_post['ID'],
- 'post_date_gmt' => $recent_post['post_date_gmt'],
- 'post_gmt_ts' => $post_gmt_ts
- );
- }
- }
- }
- return $most_recent_post;
- }
- function get_dirsize( $directory ) {
- $dirsize = get_transient( 'dirsize_cache' );
- if ( is_array( $dirsize ) && isset( $dirsize[ $directory ][ 'size' ] ) )
- return $dirsize[ $directory ][ 'size' ];
- if ( ! is_array( $dirsize ) )
- $dirsize = array();
-
-
- if ( is_main_site() ) {
- $dirsize[ $directory ][ 'size' ] = recurse_dirsize( $directory, $directory . '/sites' );
- } else {
- $dirsize[ $directory ][ 'size' ] = recurse_dirsize( $directory );
- }
- set_transient( 'dirsize_cache', $dirsize, HOUR_IN_SECONDS );
- return $dirsize[ $directory ][ 'size' ];
- }
- function recurse_dirsize( $directory, $exclude = null ) {
- $size = 0;
- $directory = untrailingslashit( $directory );
- if ( ! file_exists( $directory ) || ! is_dir( $directory ) || ! is_readable( $directory ) || $directory === $exclude ) {
- return false;
- }
- if ($handle = opendir($directory)) {
- while(($file = readdir($handle)) !== false) {
- $path = $directory.'/'.$file;
- if ($file != '.' && $file != '..') {
- if (is_file($path)) {
- $size += filesize($path);
- } elseif (is_dir($path)) {
- $handlesize = recurse_dirsize( $path, $exclude );
- if ($handlesize > 0)
- $size += $handlesize;
- }
- }
- }
- closedir($handle);
- }
- return $size;
- }
- function check_upload_mimes( $mimes ) {
- $site_exts = explode( ' ', get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ) );
- $site_mimes = array();
- foreach ( $site_exts as $ext ) {
- foreach ( $mimes as $ext_pattern => $mime ) {
- if ( $ext != '' && strpos( $ext_pattern, $ext ) !== false )
- $site_mimes[$ext_pattern] = $mime;
- }
- }
- return $site_mimes;
- }
- function update_posts_count( $deprecated = '' ) {
- global $wpdb;
- update_option( 'post_count', (int) $wpdb->get_var( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_status = 'publish' and post_type = 'post'" ) );
- }
- function wpmu_log_new_registrations( $blog_id, $user_id ) {
- global $wpdb;
- $user = get_userdata( (int) $user_id );
- if ( $user )
- $wpdb->insert( $wpdb->registration_log, array('email' => $user->user_email, 'IP' => preg_replace( '/[^0-9., ]/', '', wp_unslash( $_SERVER['REMOTE_ADDR'] ) ), 'blog_id' => $blog_id, 'date_registered' => current_time('mysql')) );
- }
- function global_terms( $term_id, $deprecated = '' ) {
- global $wpdb;
- static $global_terms_recurse = null;
- if ( !global_terms_enabled() )
- return $term_id;
-
- $recurse_start = false;
- if ( $global_terms_recurse === null ) {
- $recurse_start = true;
- $global_terms_recurse = 1;
- } elseif ( 10 < $global_terms_recurse++ ) {
- return $term_id;
- }
- $term_id = intval( $term_id );
- $c = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->terms WHERE term_id = %d", $term_id ) );
- $global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE category_nicename = %s", $c->slug ) );
- if ( $global_id == null ) {
- $used_global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE cat_ID = %d", $c->term_id ) );
- if ( null == $used_global_id ) {
- $wpdb->insert( $wpdb->sitecategories, array( 'cat_ID' => $term_id, 'cat_name' => $c->name, 'category_nicename' => $c->slug ) );
- $global_id = $wpdb->insert_id;
- if ( empty( $global_id ) )
- return $term_id;
- } else {
- $max_global_id = $wpdb->get_var( "SELECT MAX(cat_ID) FROM $wpdb->sitecategories" );
- $max_local_id = $wpdb->get_var( "SELECT MAX(term_id) FROM $wpdb->terms" );
- $new_global_id = max( $max_global_id, $max_local_id ) + mt_rand( 100, 400 );
- $wpdb->insert( $wpdb->sitecategories, array( 'cat_ID' => $new_global_id, 'cat_name' => $c->name, 'category_nicename' => $c->slug ) );
- $global_id = $wpdb->insert_id;
- }
- } elseif ( $global_id != $term_id ) {
- $local_id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE term_id = %d", $global_id ) );
- if ( null != $local_id ) {
- global_terms( $local_id );
- if ( 10 < $global_terms_recurse ) {
- $global_id = $term_id;
- }
- }
- }
- if ( $global_id != $term_id ) {
- if ( get_option( 'default_category' ) == $term_id )
- update_option( 'default_category', $global_id );
- $wpdb->update( $wpdb->terms, array('term_id' => $global_id), array('term_id' => $term_id) );
- $wpdb->update( $wpdb->term_taxonomy, array('term_id' => $global_id), array('term_id' => $term_id) );
- $wpdb->update( $wpdb->term_taxonomy, array('parent' => $global_id), array('parent' => $term_id) );
- clean_term_cache($term_id);
- }
- if ( $recurse_start )
- $global_terms_recurse = null;
- return $global_id;
- }
- function redirect_this_site( $deprecated = '' ) {
- return array( get_network()->domain );
- }
- function upload_is_file_too_big( $upload ) {
- if ( ! is_array( $upload ) || defined( 'WP_IMPORTING' ) || get_site_option( 'upload_space_check_disabled' ) )
- return $upload;
- if ( strlen( $upload['bits'] ) > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) {
- return sprintf( __( 'This file is too big. Files must be less than %d KB in size.' ) . '<br />', get_site_option( 'fileupload_maxk', 1500 ) );
- }
- return $upload;
- }
- function signup_nonce_fields() {
- $id = mt_rand();
- echo "<input type='hidden' name='signup_form_id' value='{$id}' />";
- wp_nonce_field('signup_form_' . $id, '_signup_form', false);
- }
- function signup_nonce_check( $result ) {
- if ( !strpos( $_SERVER[ 'PHP_SELF' ], 'wp-signup.php' ) )
- return $result;
- if ( wp_create_nonce('signup_form_' . $_POST[ 'signup_form_id' ]) != $_POST['_signup_form'] )
- wp_die( __( 'Please try again.' ) );
- return $result;
- }
- function maybe_redirect_404() {
-
- if ( is_main_site() && is_404() && defined( 'NOBLOGREDIRECT' ) && ( $destination = apply_filters( 'blog_redirect_404', NOBLOGREDIRECT ) ) ) {
- if ( $destination == '%siteurl%' )
- $destination = network_home_url();
- wp_redirect( $destination );
- exit();
- }
- }
- function maybe_add_existing_user_to_blog() {
- if ( false === strpos( $_SERVER[ 'REQUEST_URI' ], '/newbloguser/' ) )
- return;
- $parts = explode( '/', $_SERVER[ 'REQUEST_URI' ] );
- $key = array_pop( $parts );
- if ( $key == '' )
- $key = array_pop( $parts );
- $details = get_option( 'new_user_' . $key );
- if ( !empty( $details ) )
- delete_option( 'new_user_' . $key );
- if ( empty( $details ) || is_wp_error( add_existing_user_to_blog( $details ) ) )
- wp_die( sprintf(__('An error occurred adding you to this site. Back to the <a href="%s">homepage</a>.'), home_url() ) );
- wp_die( sprintf( __( 'You have been added to this site. Please visit the <a href="%s">homepage</a> or <a href="%s">log in</a> using your username and password.' ), home_url(), admin_url() ), __( 'WordPress › Success' ), array( 'response' => 200 ) );
- }
- function add_existing_user_to_blog( $details = false ) {
- if ( is_array( $details ) ) {
- $blog_id = get_current_blog_id();
- $result = add_user_to_blog( $blog_id, $details[ 'user_id' ], $details[ 'role' ] );
-
- do_action( 'added_existing_user', $details['user_id'], $result );
- return $result;
- }
- }
- function add_new_user_to_blog( $user_id, $password, $meta ) {
- if ( !empty( $meta[ 'add_to_blog' ] ) ) {
- $blog_id = $meta[ 'add_to_blog' ];
- $role = $meta[ 'new_role' ];
- remove_user_from_blog($user_id, get_network()->site_id);
- add_user_to_blog( $blog_id, $user_id, $role );
- update_user_meta( $user_id, 'primary_blog', $blog_id );
- }
- }
- function fix_phpmailer_messageid( $phpmailer ) {
- $phpmailer->Hostname = get_network()->domain;
- }
- function is_user_spammy( $user = null ) {
- if ( ! ( $user instanceof WP_User ) ) {
- if ( $user ) {
- $user = get_user_by( 'login', $user );
- } else {
- $user = wp_get_current_user();
- }
- }
- return $user && isset( $user->spam ) && 1 == $user->spam;
- }
- function update_blog_public( $old_value, $value ) {
- update_blog_status( get_current_blog_id(), 'public', (int) $value );
- }
- function is_user_option_local( $key, $user_id = 0, $blog_id = 0 ) {
- global $wpdb;
- $current_user = wp_get_current_user();
- if ( $blog_id == 0 ) {
- $blog_id = $wpdb->blogid;
- }
- $local_key = $wpdb->get_blog_prefix( $blog_id ) . $key;
- return isset( $current_user->$local_key );
- }
- function users_can_register_signup_filter() {
- $registration = get_site_option('registration');
- return ( $registration == 'all' || $registration == 'user' );
- }
- function welcome_user_msg_filter( $text ) {
- if ( !$text ) {
- remove_filter( 'site_option_welcome_user_email', 'welcome_user_msg_filter' );
-
- $text = __( 'Howdy USERNAME,
- Your new account is set up.
- You can log in with the following information:
- Username: USERNAME
- Password: PASSWORD
- LOGINLINK
- Thanks!
- --The Team @ SITE_NAME' );
- update_site_option( 'welcome_user_email', $text );
- }
- return $text;
- }
- function force_ssl_content( $force = '' ) {
- static $forced_content = false;
- if ( '' != $force ) {
- $old_forced = $forced_content;
- $forced_content = $force;
- return $old_forced;
- }
- return $forced_content;
- }
- function filter_SSL( $url ) {
- if ( ! is_string( $url ) )
- return get_bloginfo( 'url' );
- if ( force_ssl_content() && is_ssl() )
- $url = set_url_scheme( $url, 'https' );
- return $url;
- }
- function wp_schedule_update_network_counts() {
- if ( !is_main_site() )
- return;
- if ( ! wp_next_scheduled('update_network_counts') && ! wp_installing() )
- wp_schedule_event(time(), 'twicedaily', 'update_network_counts');
- }
- function wp_update_network_counts( $network_id = null ) {
- wp_update_network_user_counts( $network_id );
- wp_update_network_site_counts( $network_id );
- }
- function wp_maybe_update_network_site_counts( $network_id = null ) {
- $is_small_network = ! wp_is_large_network( 'sites', $network_id );
-
- if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'sites' ) )
- return;
- wp_update_network_site_counts( $network_id );
- }
- function wp_maybe_update_network_user_counts( $network_id = null ) {
- $is_small_network = ! wp_is_large_network( 'users', $network_id );
-
- if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'users' ) )
- return;
- wp_update_network_user_counts( $network_id );
- }
- function wp_update_network_site_counts( $network_id = null ) {
- $network_id = (int) $network_id;
- if ( ! $network_id ) {
- $network_id = get_current_network_id();
- }
- $count = get_sites( array(
- 'network_id' => $network_id,
- 'spam' => 0,
- 'deleted' => 0,
- 'archived' => 0,
- 'count' => true,
- ) );
- update_network_option( $network_id, 'blog_count', $count );
- }
- function wp_update_network_user_counts( $network_id = null ) {
- global $wpdb;
- $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" );
- update_network_option( $network_id, 'user_count', $count );
- }
- function get_space_used() {
-
- $space_used = apply_filters( 'pre_get_space_used', false );
- if ( false === $space_used ) {
- $upload_dir = wp_upload_dir();
- $space_used = get_dirsize( $upload_dir['basedir'] ) / MB_IN_BYTES;
- }
- return $space_used;
- }
- function get_space_allowed() {
- $space_allowed = get_option( 'blog_upload_space' );
- if ( ! is_numeric( $space_allowed ) )
- $space_allowed = get_site_option( 'blog_upload_space' );
- if ( ! is_numeric( $space_allowed ) )
- $space_allowed = 100;
-
- return apply_filters( 'get_space_allowed', $space_allowed );
- }
- function get_upload_space_available() {
- $allowed = get_space_allowed();
- if ( $allowed < 0 ) {
- $allowed = 0;
- }
- $space_allowed = $allowed * MB_IN_BYTES;
- if ( get_site_option( 'upload_space_check_disabled' ) )
- return $space_allowed;
- $space_used = get_space_used() * MB_IN_BYTES;
- if ( ( $space_allowed - $space_used ) <= 0 )
- return 0;
- return $space_allowed - $space_used;
- }
- function is_upload_space_available() {
- if ( get_site_option( 'upload_space_check_disabled' ) )
- return true;
- return (bool) get_upload_space_available();
- }
- function upload_size_limit_filter( $size ) {
- $fileupload_maxk = KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 );
- if ( get_site_option( 'upload_space_check_disabled' ) )
- return min( $size, $fileupload_maxk );
- return min( $size, $fileupload_maxk, get_upload_space_available() );
- }
- function wp_is_large_network( $using = 'sites', $network_id = null ) {
- $network_id = (int) $network_id;
- if ( ! $network_id ) {
- $network_id = get_current_network_id();
- }
- if ( 'users' == $using ) {
- $count = get_user_count( $network_id );
-
- return apply_filters( 'wp_is_large_network', $count > 10000, 'users', $count, $network_id );
- }
- $count = get_blog_count( $network_id );
-
- return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count, $network_id );
- }
- function get_subdirectory_reserved_names() {
- $names = array(
- 'page', 'comments', 'blog', 'files', 'feed', 'wp-admin',
- 'wp-content', 'wp-includes', 'wp-json', 'embed'
- );
-
- return apply_filters( 'subdirectory_reserved_names', $names );
- }
|