Skip to content

disallow 0x0 unit size - #72

Open
jakewrfoster wants to merge 3 commits into
mainfrom
patch/ad-server-settings/sizes/group_is_empty
Open

disallow 0x0 unit size#72
jakewrfoster wants to merge 3 commits into
mainfrom
patch/ad-server-settings/sizes/group_is_empty

Conversation

@jakewrfoster

@jakewrfoster jakewrfoster commented Oct 31, 2019

Copy link
Copy Markdown
Member

The current lack of group_is_empty allows for cases where ad-layers will save an ad unit size as 0x0. This size group then becomes impossible to remove. This PR ensures that any sizes groups that have a 0x0 ad unit will not be saved.

Screen Shot 568

@mboynes / @bcampeau: For backwards-compat reasons, is there any use-case for an ad unit being 0x0?

@kjbenk kjbenk left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be simplified

'add_more_label' => __( 'Add Size', 'ad-layers' ),
'description' => __( 'Size cannot be 0x0.', 'ad-layers' ),
'group_is_empty' => function( $values ) {
if ( isset( $values['width'], $values['height'] ) ) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should just be able to do

return empty( $values['width'] ) && empty( $values['height'] );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if you really need all of these checks, then it might be easier to read stacked in a single if statement

Comment thread php/ad-servers/class-ad-layers-dfp.php Outdated
// Valid size, save the group.
return false;
} else {
return true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if the values are set but one of them is not numeric, the group should be considered empty?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the numeric checks can be removed since these fields are being sanitized by absint anyway.

@kjbenk kjbenk left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛳️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants