Skip to content

Commit

Permalink
Merge pull request #1297 from Automattic/hotfix/attr
Browse files Browse the repository at this point in the history
fix: improved attribute handling
  • Loading branch information
claudiulodro authored Apr 23, 2024
2 parents a89bfe0 + b53415a commit d164af0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions includes/class-newspack-popups-inserter.php
Original file line number Diff line number Diff line change
Expand Up @@ -721,11 +721,18 @@ public static function enqueue_scripts() {
* @return HTML
*/
public static function popup_shortcode( $atts = array() ) {
$default_atts = [
'id' => 0,
'class' => '',
];
$atts = \shortcode_atts( $default_atts, $atts, 'newspack-popup' );

$found_popup = false;
if ( Newspack_Popups::preset_popup_id() ) {
$found_popup = Newspack_Popups_Presets::retrieve_preset_popup( Newspack_Popups::preset_popup_id() );
} elseif ( isset( $atts['id'] ) ) {
} elseif ( ! empty( $atts['id'] ) && is_numeric( $atts['id'] ) ) {
$include_unpublished = Newspack_Popups::is_preview_request();
$found_popup = Newspack_Popups_Model::retrieve_popup_by_id( $atts['id'], $include_unpublished );
$found_popup = Newspack_Popups_Model::retrieve_popup_by_id( (int) $atts['id'], $include_unpublished );
}
if ( ! $found_popup ) {
return;
Expand All @@ -742,7 +749,7 @@ public static function popup_shortcode( $atts = array() ) {

$class_names = '';
if ( ! empty( $atts['class'] ) ) {
$class_names .= ' class="' . $atts['class'] . '"';
$class_names = sprintf( ' class="%s"', \esc_attr( $atts['class'] ) );
}

// Wrapping the inline popup in an aside element prevents the markup from being mangled
Expand Down

0 comments on commit d164af0

Please sign in to comment.