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

Alpha release Oct 16 #1231

Merged
merged 5 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
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
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
28 changes: 14 additions & 14 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
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