Carsten Windler, HolidayPirates GmbH
if ( is_array($fields ) ) {
if ( isset($fields['blog_id']) ) {
$blog_id = $fields['blog_id'];
} elseif ( isset($fields['domain']) && isset($fields['path']) ) {
$key = md5( $fields['domain'] . $fields['path'] );
$blog = wp_cache_get($key, 'blog-lookup');
if ( false !== $blog )
return $blog;
if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) {
$nowww = substr( $fields['domain'], 4 );
$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'], $fields['path'] ) );
} else {
$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'] ) );
}
if ( $blog ) {
wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details');
$blog_id = $blog->blog_id;
} else {
return false;
}
} elseif ( isset($fields['domain']) && is_subdomain_install() ) {
$key = md5( $fields['domain'] );
$blog = wp_cache_get($key, 'blog-lookup');
if ( false !== $blog )
return $blog;
if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) {
$nowww = substr( $fields['domain'], 4 );
$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'] ) );
} else {
$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $fields['domain'] ) );
}
if ( $blog ) {
wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details');
$blog_id = $blog->blog_id;
} else {
return false;
}
} else {
return false;
}
} else {
if ( ! $fields )
$blog_id = get_current_blog_id();
elseif ( ! is_numeric( $fields ) )
$blog_id = get_id_from_blogname( $fields );
else
$blog_id = $fields;
}
$blog_id = (int) $blog_id;
$all = $get_all == true ? '' : 'short';
$details = wp_cache_get( $blog_id . $all, 'blog-details' );
if ( $details ) {
if ( ! is_object( $details ) ) {
if ( $details == -1 ) {
return false;
} else {
// Clear old pre-serialized objects. Cache clients do better with that.
wp_cache_delete( $blog_id . $all, 'blog-details' );
unset($details);
}
} else {
return $details;
}
}
// Try the other cache.
if ( $get_all ) {
$details = wp_cache_get( $blog_id . 'short', 'blog-details' );
} else {
$details = wp_cache_get( $blog_id, 'blog-details' );
// If short was requested and full cache is set, we can return.
if ( $details ) {
if ( ! is_object( $details ) ) {
if ( $details == -1 ) {
return false;
} else {
// Clear old pre-serialized objects. Cache clients do better with that.
wp_cache_delete( $blog_id, 'blog-details' );
unset($details);
}
} else {
return $details;
}
}
}
if ( empty($details) ) {
$details = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE blog_id = %d /* get_blog_details */", $blog_id ) );
if ( ! $details ) {
// Set the full cache.
wp_cache_set( $blog_id, -1, 'blog-details' );
return false;
}
}
if ( ! $get_all ) {
wp_cache_set( $blog_id . $all, $details, 'blog-details' );
return $details;
}
switch_to_blog( $blog_id );
$details->blogname = get_option( 'blogname' );
$details->siteurl = get_option( 'siteurl' );
$details->post_count = get_option( 'post_count' );
restore_current_blog();
/**
* Filter a blog's details.
*
* @since MU
*
* @param object $details The blog details.
*/
$details = apply_filters( 'blog_details', $details );
wp_cache_set( $blog_id . $all, $details, 'blog-details' );
$key = md5( $details->domain . $details->path );
wp_cache_set( $key, $details, 'blog-lookup' );
return $details;
not really surprisingly
... but how?
Sorry...
Management
Customer
Co-Worker
Other departments
The Business likes charts.
Let's give them some charts.
Life
*simplification; not necessarily related to any real project
your former lead dev
(yes, under the truck)
Sloppiness Short Term
Boost (SSTB)
Clean Code Long Term Benefit (CCLTB)
t 0
t1
t2
Startup
Phase
Consolidation Phase
Credit
Interest
fewer backlog items are left when doing sloppy programming instead of clean code in the startup phase
t 0
t 1
more backlog items left when doing sloppy programming instead of Clean Code over project lifetime
t 0
t 2
StartupMan
Wait, wait, wait... it's for the
Management, so keep it simple!
Quality is an investment
Developer scalability
Lower per-bug-costs
Customer satisfaction
...ouch...
Leave it up to the Management, if you can!
Quality is an investment
End-Customer satisfaction
Develop agile
*you probably don't want to tell that though
Yes, once again!
Happy refactoring
Saves development time
Ego
Lesser stress during deploys
Developer scalability
Hey Bob, how is your project going?
Awesome! During last the Refactoring Sprint we managed to drop the overall cyclomatic complexity by ~5 points (which is great). However we still have a maintenability index of 64.32 on the Middleware which we will change ASAP.
Nice
REFACTORING TIME!!
*assuming you use Version Control Systems
Tests are not optional, they are mandatory.
Period.
We mean it.
Seriously.
Write / Refactor
Automated Tests
Write / Refactor
Bugs
Manual Tests
E2E
Unit Tests
not (yet) available
not an option
- slow
- a bit fragile
- require test mode
your way to go before you start with refactoring
+ require no refactoring
+ require no deep code knowledge
+ can be done in a sane amount of time
(although you have to be pretty good)
Office work business
https://stocksnap.io/photo/HZCASACP3N
Top view of phone, earphones pen and diary
https://www.pexels.com/photo/top-view-of-phone-earphones-pen-and-diary-6662/
Guy working man
https://stocksnap.io/photo/GDAGX2JKI4
Red fire truck
https://stocksnap.io/photo/I2W591P4EV
Man wearing black and red checkered long sleeve...
https://www.pexels.com/photo/man-wearing-black-and-red-checkered-long-sleeve-shirt-wearing-black-wayfarer-sunglasses-sitting-on-white-wooden-chair-69212/
Man in white shirt using Macbook
https://www.pexels.com/photo/man-in-white-shirt-using-macbook-pro-52608/
Bow tie fashion man person
https://www.pexels.com/photo/bow-tie-fashion-man-person-5198/
All above images are licensed under CC0. Thank you very much for making this great work available freely!