From 521ce58de7b37927c204e758da8c4de8c1f5e7b6 Mon Sep 17 00:00:00 2001 From: Ian Dunn Date: Thu, 7 Nov 2019 15:37:01 -0800 Subject: [PATCH] Contributors: Return default array when posts empty to avoid notices. Previously there were `undefined index` notices on `wp-admin/edit.php?post_type=5ftf_pledge` when a pledge had `0` posts in either status. --- plugins/wporg-5ftf/includes/contributor.php | 14 +++++++++----- plugins/wporg-5ftf/includes/pledge-log.php | 4 ++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/plugins/wporg-5ftf/includes/contributor.php b/plugins/wporg-5ftf/includes/contributor.php index c8585e6..75c6df8 100644 --- a/plugins/wporg-5ftf/includes/contributor.php +++ b/plugins/wporg-5ftf/includes/contributor.php @@ -218,17 +218,21 @@ function get_pledge_contributors( $pledge_id, $status = 'publish', $contributor_ $posts = get_posts( $args ); - if ( 'all' === $status && ! empty( $posts ) ) { + if ( 'all' === $status ) { $initial = array( 'publish' => array(), 'pending' => array(), ); - $posts = array_reduce( $posts, function( $carry, WP_Post $item ) { - $carry[ $item->post_status ][] = $item; + if ( empty( $posts ) ) { + $posts = $initial; + } else { + $posts = array_reduce( $posts, function( $carry, WP_Post $item ) { + $carry[ $item->post_status ][] = $item; - return $carry; - }, $initial ); + return $carry; + }, $initial ); + } } return $posts; diff --git a/plugins/wporg-5ftf/includes/pledge-log.php b/plugins/wporg-5ftf/includes/pledge-log.php index ee0a3d3..ce94c98 100644 --- a/plugins/wporg-5ftf/includes/pledge-log.php +++ b/plugins/wporg-5ftf/includes/pledge-log.php @@ -119,6 +119,10 @@ function add_log_entry( $pledge_id, $type, $message, array $data = array(), $use $entry['user_id'] = $user_id; } elseif ( 'cli' === php_sapi_name() ) { + /* + * `wp_shell`, etc can only be run from w.org sandboxes, and the hostname is the best way to identify + * which sandbox was used. + */ $entry['user_id'] = gethostname(); }