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

Release Oct 31 #1238

Merged
merged 10 commits into from
Oct 31, 2023
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# [2.25.0-alpha.2](https://github.com/Automattic/newspack-popups/compare/v2.25.0-alpha.1...v2.25.0-alpha.2) (2023-10-20)


### Features

* implement ras overlays ([#1233](https://github.com/Automattic/newspack-popups/issues/1233)) ([6c86cd3](https://github.com/Automattic/newspack-popups/commit/6c86cd3c5689622160b7d118764b1c62a77b95e2))

# [2.25.0-alpha.1](https://github.com/Automattic/newspack-popups/compare/v2.24.0...v2.25.0-alpha.1) (2023-10-16)


### Bug Fixes

* deduplication strategy for Homepage Posts block ([#1228](https://github.com/Automattic/newspack-popups/issues/1228)) ([bbb952d](https://github.com/Automattic/newspack-popups/commit/bbb952d0f696bb72850607579574a2a0d19d82a3))


### Features

* remove is_non_interactive method ([adabea2](https://github.com/Automattic/newspack-popups/commit/adabea225a04df880f0b6e120ee8dcad82c3445d))

# [2.24.0](https://github.com/Automattic/newspack-popups/compare/v2.23.1...v2.24.0) (2023-10-09)


Expand Down
29 changes: 19 additions & 10 deletions includes/class-newspack-popups-model.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ final class Newspack_Popups_Model {
*/
protected static $form_hooks_popup_id;

/**
* The current popup.
*
* @var array|null
*/
protected static $current_popup = null;

/**
* Retrieve all Popups (first 100).
*
Expand Down Expand Up @@ -976,9 +983,19 @@ class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>"
<?php echo do_shortcode( $body ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</div>
<?php
self::$current_popup = null;
return ob_get_clean();
}

/**
* Return the current popup.
*
* @return array|null The current popup or null if it's not set.
*/
public static function get_current_popup() {
return self::$current_popup;
}

/**
* Generate markup and styles for an overlay popup.
*
Expand All @@ -997,10 +1014,7 @@ public static function generate_popup( $popup ) {
$popup = Newspack_Popups_Presets::retrieve_preset_popup( Newspack_Popups::preset_popup_id() );
}

if ( self::is_overlay( $popup ) && self::is_overlay( $popup ) && has_block( 'newspack-blocks/homepage-articles', $popup['content'] ) ) {
add_filter( 'newspack_blocks_homepage_enable_duplication', '__return_true' );
add_filter( 'newspack_blocks_homepage_shown_rendered_posts', '__return_true' );
}
self::$current_popup = $popup;

if ( ! self::is_overlay( $popup ) ) {
return self::generate_inline_popup( $popup );
Expand Down Expand Up @@ -1084,12 +1098,7 @@ class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>"
<div id="page-position-marker_<?php echo esc_attr( $element_id ); ?>" class="page-position-marker" style="position: absolute; top: <?php echo esc_attr( $popup['options']['trigger_scroll_progress'] ); ?>%"></div>
<?php endif; ?>
<?php
if ( self::is_overlay( $popup ) && has_block( 'newspack-blocks/homepage-articles', $popup['content'] ) ) {
add_filter( 'newspack_blocks_homepage_enable_duplication', '__return_false' );
add_filter( 'newspack_blocks_homepage_shown_rendered_posts', '__return_false' );
}
?>
<?php
self::$current_popup = null;
return ob_get_clean();
}

Expand Down
11 changes: 0 additions & 11 deletions includes/class-newspack-popups-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,17 +349,6 @@ function ( $carry, $item ) {
return $settings_list;
}

/**
* Is the non-interactive setting on?
*
* Deprecated: There is no longer a non interactive mode
*
* @deprecated
*/
public static function is_non_interactive() {
return false;
}

/**
* Donor landing page.
*/
Expand Down
17 changes: 17 additions & 0 deletions includes/class-newspack-popups.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public function __construct() {
add_action( 'transition_post_status', [ __CLASS__, 'prevent_default_category_on_publish' ], 10, 3 );
add_action( 'pre_delete_term', [ __CLASS__, 'prevent_default_category_on_term_delete' ], 10, 2 );
add_filter( 'show_admin_bar', [ __CLASS__, 'show_admin_bar' ], 10, 2 ); // phpcs:ignore WordPressVIPMinimum.UserExperience.AdminBarRemoval.RemovalDetected
add_filter( 'newspack_blocks_should_deduplicate', [ __CLASS__, 'newspack_blocks_should_deduplicate' ], 10, 2 );

include_once dirname( __FILE__ ) . '/class-newspack-popups-model.php';
include_once dirname( __FILE__ ) . '/class-newspack-segments-migration.php';
Expand All @@ -108,6 +109,22 @@ public function __construct() {
include_once dirname( __FILE__ ) . '/class-newspack-popups-criteria.php';
}

/**
* Handle deduplication of "Homepage Posts" block from Newspack Blocks.
*
* @param boolean $deduplicate Whether to deduplicate.
* @param array $attributes Block attributes.
*
* @return boolean
*/
public static function newspack_blocks_should_deduplicate( $deduplicate, $attributes ) {
$current_popup = Newspack_Popups_Model::get_current_popup();
if ( $current_popup && Newspack_Popups_Model::is_overlay( $current_popup ) ) {
$deduplicate = false;
}
return $deduplicate;
}

/**
* Register CLI commands.
*
Expand Down
2 changes: 1 addition & 1 deletion newspack-popups.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Author URI: https://newspack.com
* Text Domain: newspack-popups
* Domain Path: /languages
* Version: 2.24.0
* Version: 2.25.0-alpha.2
*
* @package Newspack_Popups
*/
Expand Down
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "newspack-popups",
"version": "2.24.0",
"version": "2.25.0-alpha.2",
"main": "Gruntfile.js",
"author": "Automattic",
"scripts": {
Expand Down Expand Up @@ -36,11 +36,11 @@
"qs": "^6.11.2"
},
"devDependencies": {
"@rushstack/eslint-patch": "^1.4.0",
"@rushstack/eslint-patch": "^1.5.1",
"eslint": "^7.32.0",
"lint-staged": "^13.2.3",
"newspack-scripts": "^5.1.0",
"postcss-scss": "^4.0.8",
"postcss-scss": "^4.0.9",
"prettier": "npm:wp-prettier@^2.2.1-beta-1",
"stylelint": "^15.10.3"
}
Expand Down
19 changes: 18 additions & 1 deletion src/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { useEffect } from '@wordpress/element';
/**
* Internal dependencies
*/
import { optionsFieldsSelector } from './utils';
import { optionsFieldsSelector, isOverlayPlacement } from './utils';
import Sidebar from './Sidebar';
import StylesSidebar from './StylesSidebar';
import FrequencySidebar from './FrequencySidebar';
Expand Down Expand Up @@ -145,6 +145,23 @@ registerPlugin( 'newspack-popups-editor', {
icon: null,
} );

// Hide Newspack's Homepage Posts block deduplication toggle when the popup is an overlay.
registerPlugin( 'newspack-popups-disable-newspack-blocks-deduplication', {
render: function HideDeduplicationToggle() {
const { placement } = useSelect( select => {
const { getEditedPostAttribute } = select( 'core/editor' );
return {
placement: getEditedPostAttribute( 'meta' )?.placement,
};
} );
if ( ! isOverlayPlacement( placement ) ) {
return null;
}
return <style>{ '.newspack-blocks-deduplication-toggle {display: none;}' }</style>;
},
icon: null,
} );

// Add a button in post status section
const PluginPostStatusInfoTest = () => (
<PluginPostStatusInfo className="newspack-popups__status-options">
Expand Down
5 changes: 5 additions & 0 deletions src/view/segmentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export const handleSegmentation = prompts => {
if ( ras ) {
handleSeen( prompt, ras );
}

// Register the overlay in RAS.
if ( isOverlay && ras?.overlays ) {
prompt.overlayId = ras.overlays.add();
}
};
if ( isOverlay ) {
const scroll = prompt.getAttribute( 'data-scroll' );
Expand Down
5 changes: 5 additions & 0 deletions src/view/utils/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export const closeOverlay = event => {
parent.style.display = 'none';
}

// Remove the overlay from RAS.
if ( parent.overlayId && window.newspackReaderActivation?.overlays ) {
window.newspackReaderActivation.overlays.remove( parent.overlayId );
}

event.preventDefault();
};

Expand Down