Skip to content

Commit

Permalink
refactor: use static function on array_map callback to pass the id as…
Browse files Browse the repository at this point in the history
… reference for _give_redirect_form_id to prevent warnings on PHP 8.0.1 or plus
  • Loading branch information
glaubersilva committed Oct 25, 2023
1 parent a44abaa commit c08d659
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ public function register_block() {

/**
* Block render callback
*
* @unreleased Use static function on array_map callback to pass the id as reference for _give_redirect_form_id to prevent warnings on PHP 8.0.1 or plus
*
* @param array $attributes Block parameters.
*
Expand All @@ -208,7 +210,14 @@ public function render_block( $attributes ) {
$parameters = array(
'forms_per_page' => absint( $attributes['formsPerPage'] ),
'ids' => implode(',',
array_map('_give_redirect_form_id', $this->getAsArray($attributes['formIDs']))
array_map(
static function ($id) {
_give_redirect_form_id($id);

return $id;
},
$this->getAsArray($attributes['formIDs'])
)
),
'exclude' => implode(',', $this->getAsArray($attributes['excludedFormIDs'] ) ),
'orderby' => $attributes['orderBy'],
Expand Down
11 changes: 10 additions & 1 deletion blocks/donor-wall/class-give-donor-wall.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ public function register_block() {

/**
* Block render callback
*
* @unreleased Use static function on array_map callback to pass the id as reference for _give_redirect_form_id to prevent warnings on PHP 8.0.1 or plus
*
* @param array $attributes Block parameters.
*
Expand All @@ -210,7 +212,14 @@ public function render_block( $attributes ) {
$parameters = [
'donors_per_page' => absint( $attributes['donorsPerPage'] ),
'form_id' => implode(',',
array_map('_give_redirect_form_id', $this->getAsArray($attributes['formID']))
array_map(
static function ($id) {
_give_redirect_form_id($id);

return $id;
},
$this->getAsArray($attributes['formID'])
)
),
'ids' => implode(',', $this->getAsArray($attributes['ids'] ) ),
'cats' => implode(',', $this->getAsArray($attributes['categories'] ) ),
Expand Down
31 changes: 19 additions & 12 deletions includes/shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,17 @@ function give_totals_shortcode( $atts ) {
*
* @since 2.1.0
*
* @unreleased Use static function on array_map callback to pass the id as reference for _give_redirect_form_id to prevent warnings on PHP 8.0.1 or plus
* @since 2.23.1 Updated the default text color for the donate button, see #6591.
* @since 2.21.2 change tag_background_color, progress_bar_color to official green color #69b868.
* change tag_text_color color to #333333.
* @since 2.20.0 $show_donate_button Option to show donate button
* @since 2.20.0 $donate_button_text Default Donate
* @since 2.20.0 $donate_button_background_color Default #66bb6a
* @since 2.20.0 $donate_button_text_color Default #fff
* @since 2.20.0 $show_bar Default false
* @since 2.22.2 remove $show_bar attribute in favor of show_goal
*
* @param array $atts {
* Optional. Attributes of the form grid shortcode.
*
Expand All @@ -800,22 +811,12 @@ function give_totals_shortcode( $atts ) {
* @type bool $show_goal Whether to display form goal. Default 'true'.
* @type bool $show_excerpt Whether to display form excerpt. Default 'true'.
* @type bool $show_featured_image Whether to display featured image. Default 'true'.
* @type string $image_size Featured image size. Default 'medium'. Accepts WordPress image sizes.
* @type string $image_size Featured image size. Default 'medium'. Accepts WordPress image sizes.
* @type string $image_height Featured image height. Default 'auto'. Accepts valid CSS heights.
* @type int $excerpt_length Number of words before excerpt is truncated. Default '16'.
* @type string $display_style How the form is displayed, either in new page or modal popup.
* Default 'redirect'. Accepts 'redirect', 'modal'.
*
* @since 2.23.1 Updated the default text color for the donate button, see #6591.
* @since 2.21.2 change tag_background_color, progress_bar_color to official green color #69b868.
* change tag_text_color color to #333333.
* @since 2.20.0 $show_donate_button Option to show donate button
* @since 2.20.0 $donate_button_text Default Donate
* @since 2.20.0 $donate_button_background_color Default #66bb6a
* @since 2.20.0 $donate_button_text_color Default #fff
* @since 2.20.0 $show_bar Default false
* @since 2.22.2 remove $show_bar attribute in favor of show_goal
*
* @return string|bool The markup of the form grid or false.
*/
function give_form_grid_shortcode( $atts ) {
Expand Down Expand Up @@ -901,7 +902,13 @@ function give_form_grid_shortcode( $atts ) {

// Maybe filter forms by IDs.
if ( ! empty( $atts['ids'] ) ) {
$form_args['post__in'] = array_map('_give_redirect_form_id', array_filter( array_map( 'trim', explode( ',', $atts['ids'] ) ) ) );
$form_args['post__in'] = array_map(
static function ($id) {
_give_redirect_form_id($id);

return $id;
}, array_filter(array_map('trim', explode(',', $atts['ids'])))
);
}

// Convert comma-separated form IDs into array.
Expand Down

0 comments on commit c08d659

Please sign in to comment.