mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-04-21 10:33:44 +03:00
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.
This commit is contained in:
parent
93d2bafd34
commit
521ce58de7
|
@ -218,18 +218,22 @@ function get_pledge_contributors( $pledge_id, $status = 'publish', $contributor_
|
||||||
|
|
||||||
$posts = get_posts( $args );
|
$posts = get_posts( $args );
|
||||||
|
|
||||||
if ( 'all' === $status && ! empty( $posts ) ) {
|
if ( 'all' === $status ) {
|
||||||
$initial = array(
|
$initial = array(
|
||||||
'publish' => array(),
|
'publish' => array(),
|
||||||
'pending' => array(),
|
'pending' => array(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ( empty( $posts ) ) {
|
||||||
|
$posts = $initial;
|
||||||
|
} else {
|
||||||
$posts = array_reduce( $posts, function( $carry, WP_Post $item ) {
|
$posts = array_reduce( $posts, function( $carry, WP_Post $item ) {
|
||||||
$carry[ $item->post_status ][] = $item;
|
$carry[ $item->post_status ][] = $item;
|
||||||
|
|
||||||
return $carry;
|
return $carry;
|
||||||
}, $initial );
|
}, $initial );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $posts;
|
return $posts;
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,6 +119,10 @@ function add_log_entry( $pledge_id, $type, $message, array $data = array(), $use
|
||||||
$entry['user_id'] = $user_id;
|
$entry['user_id'] = $user_id;
|
||||||
|
|
||||||
} elseif ( 'cli' === php_sapi_name() ) {
|
} 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();
|
$entry['user_id'] = gethostname();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue