Skip to content

Commit

Permalink
Fix PHPCS errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ryelle committed Sep 25, 2019
1 parent 1ee468c commit 3279813
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions public_html/wp-content/mu-plugins/4-helpers-wcpt.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

defined( 'WPINC' ) or die();
defined( 'WPINC' ) || die();

/*
* Helper functions related to the `wordcamp` post type.
Expand All @@ -15,13 +15,16 @@
* @return array
*/
function get_wordcamps( $args = array() ) {
$args = wp_parse_args( $args, array(
'post_type' => WCPT_POST_TYPE_ID,
'post_status' => 'any',
'orderby' => 'ID',
'numberposts' => -1,
'perm' => 'readable',
) );
$args = wp_parse_args(
$args,
array(
'post_type' => WCPT_POST_TYPE_ID,
'post_status' => 'any',
'orderby' => 'ID',
'numberposts' => -1,
'perm' => 'readable',
)
);

$wordcamps = get_posts( $args );

Expand All @@ -47,7 +50,8 @@ function get_wordcamp_post() {
$current_site_id = get_current_blog_id();
$current_site_url = site_url();

switch_to_blog( BLOG_ID_CURRENT_SITE ); // central.wordcamp.org
// Switch to central.wordcamp.org to get posts.
switch_to_blog( BLOG_ID_CURRENT_SITE );

$wordcamp = get_posts( array(
'post_type' => 'wordcamp',
Expand Down Expand Up @@ -88,13 +92,16 @@ function get_wordcamp_post() {
* @return mixed An integer if successful, or boolean false if failed
*/
function get_wordcamp_site_id( $wordcamp_post ) {
switch_to_blog( BLOG_ID_CURRENT_SITE ); // central.wordcamp.org
// Switch to central.wordcamp.org to get post meta.
switch_to_blog( BLOG_ID_CURRENT_SITE );

if ( ! $site_id = get_post_meta( $wordcamp_post->ID, '_site_id', true ) ) {
$site_id = get_post_meta( $wordcamp_post->ID, '_site_id', true );
if ( ! $site_id ) {
$url = parse_url( get_post_meta( $wordcamp_post->ID, 'URL', true ) );

if ( isset( $url['host'] ) && isset( $url['path'] ) ) {
if ( $site = get_site_by_path( $url['host'], $url['path'] ) ) {
$site = get_site_by_path( $url['host'], $url['path'] );
if ( $site ) {
$site_id = $site->blog_id;
}
}
Expand All @@ -121,7 +128,8 @@ function get_wordcamp_name( $site_id = 0 ) {

switch_to_blog( $site_id );

if ( $wordcamp = get_wordcamp_post() ) {
$wordcamp = get_wordcamp_post();
if ( $wordcamp ) {
if ( ! empty( $wordcamp->meta['Start Date (YYYY-mm-dd)'][0] ) ) {
$name = $wordcamp->post_title . ' ' . date( 'Y', $wordcamp->meta['Start Date (YYYY-mm-dd)'][0] );
}
Expand All @@ -143,15 +151,15 @@ function get_wordcamp_name( $site_id = 0 ) {
* @todo find other code that's doing this same task in an ad-hoc manner, and convert it to use this instead
*
* @param string $url
* @param string $part 'city', 'city-domain' (without the year, e.g. seattle.wordcamp.org), 'year'
* @param string $part 'city', 'city-domain' (without the year, e.g. seattle.wordcamp.org), 'year'.
*
* @return false|string|int False on errors; an integer for years; a string for city and city-domain
*/
function wcorg_get_url_part( $url, $part ) {
$url_parts = explode( '.', parse_url( $url, PHP_URL_HOST ) );
$result = false;

// Make sure it matches the typical year.city.wordcamp.org structure
// Make sure it matches the typical year.city.wordcamp.org structure.
if ( 4 !== count( $url_parts ) ) {
return $result;
}
Expand Down Expand Up @@ -187,14 +195,14 @@ function wcorg_get_wordcamp_duration( WP_Post $wordcamp ) {
$start = get_post_meta( $wordcamp->ID, 'Start Date (YYYY-mm-dd)', true );
$end = get_post_meta( $wordcamp->ID, 'End Date (YYYY-mm-dd)', true );

// Assume 1 day duration if there is no end date
// Assume 1 day duration if there is no end date.
if ( ! $end ) {
return 1;
}

$duration_raw = $end - $start;

// Add one second and round up to ensure the end date counts as a day as well
// Add one second and round up to ensure the end date counts as a day as well.
$duration_days = ceil( ( $duration_raw + 1 ) / DAY_IN_SECONDS );

return absint( $duration_days );
Expand Down Expand Up @@ -222,7 +230,7 @@ function get_wordcamp_dropdown( $name = 'wordcamp_id', $query_options = array(),
?>

<select name="<?php echo esc_attr( $name ); ?>" class="select2">
<option value=""><?php _e( 'Select a WordCamp', 'wordcamporg' ); ?></option>
<option value=""><?php esc_html_e( 'Select a WordCamp', 'wordcamporg' ); ?></option>
<option value=""></option>

<?php foreach ( $wordcamps as $wordcamp ) : ?>
Expand Down

0 comments on commit 3279813

Please sign in to comment.