Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disallow 0x0 unit size #72

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions php/ad-servers/class-ad-layers-dfp.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,21 @@ public function get_settings_fields() {
'code' => new Fieldmanager_Textfield( __( 'Code', 'ad-layers' ) ),
'path_override' => new Fieldmanager_TextField( __( 'Custom Path Template', 'ad-layers' ) ),
'sizes' => new Fieldmanager_Group( array(
'limit' => 0,
'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

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

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

// Disallow 0px X 0px for an ad unit size. This sometimes leads to an "unremovable" field in the group.
return ( empty( $values['width'] ) && empty( $values['height'] ) );
}

// Default to saving the field.
return false;
},
'extra_elements' => 0,
'one_label_per_item' => false,
'limit' => 0,
'label' => __( 'Sizes', 'ad-layers' ),
'add_more_label' => __( 'Add Size', 'ad-layers' ),
'one_label_per_item' => false,
'children' => $this->get_size_options(),
) ),
),
Expand Down