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 Dec 16 #1380

Merged
merged 5 commits into from
Dec 16, 2024
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
8 changes: 6 additions & 2 deletions includes/class-newspack-popups-model.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static function retrieve_active_popups() {
* Set terms for a Popup.
*
* @param integer $id ID of Popup.
* @param array $terms Array of terms to be set.
* @param array $terms Array of term objects or IDs to be set.
* @param string $taxonomy Taxonomy slug.
*/
public static function set_popup_terms( $id, $terms, $taxonomy ) {
Expand All @@ -117,7 +117,11 @@ public static function set_popup_terms( $id, $terms, $taxonomy ) {
);
}
$term_ids = array_map(
function( $term ) {
function( $term ) use ( $taxonomy ) {
if ( is_int( $term ) ) {
$term = get_term_by( 'id', $term, $taxonomy, ARRAY_A );
$term['id'] = $term['term_id'];
}
return $term['id'];
},
$terms
Expand Down
11 changes: 11 additions & 0 deletions includes/class-newspack-popups.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ public static function register_meta() {
'single' => true,
'auth_callback' => '__return_true',
'sanitize_callback' => function( $input ) {
if ( empty( $input ) ) {
return '';
}
return preg_replace( '~[^-\w0-9_\s]+~', '', $input );
},
]
Expand Down Expand Up @@ -1252,6 +1255,14 @@ public static function duplicate_popup( $id, $title = '' ) {
);
wp_set_post_terms( $new_popup_id, $old_campaigns, self::NEWSPACK_POPUPS_TAXONOMY );

// Apply segment terms.
$old_segments = wp_get_post_terms(
$id,
Newspack_Segments_Model::TAX_SLUG,
[ 'fields' => 'ids' ]
);
wp_set_post_terms( $new_popup_id, $old_segments, Newspack_Segments_Model::TAX_SLUG );

// Set prompt options to match old prompt.
$old_popup_options = Newspack_Popups_Model::get_popup_options( $id );
foreach ( $old_popup_options as $key => $value ) {
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: 3.1.5
* Version: 3.1.6-alpha.1
*
* @package Newspack_Popups
*/
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"devDependencies": {
"@rushstack/eslint-patch": "^1.10.4",
"@wordpress/browserslist-config": "^6.12.0",
"@wordpress/browserslist-config": "^6.13.0",
"eslint": "^8.57.0",
"lint-staged": "^15.2.10",
"newspack-scripts": "^5.5.2",
Expand Down
20 changes: 17 additions & 3 deletions tests/test-e2e.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,17 @@ public function test_e2e_duplicate_prompt() {
'slug' => 'everyday',
]
);
wp_set_post_terms( $original_popup_id, [ $category_id ], 'category' );
wp_set_post_terms( $original_popup_id, [ $tag_id ], 'post_tag' );
wp_set_post_terms( $original_popup_id, [ $campaign_id ], Newspack_Popups::NEWSPACK_POPUPS_TAXONOMY );
$segment_id = self::factory()->term->create(
[
'name' => 'Loyal Readers',
'taxonomy' => Newspack_Segments_Model::TAX_SLUG,
'slug' => 'loyal-readers',
]
);
Newspack_Popups_Model::set_popup_terms( $original_popup_id, [ $category_id ], 'category' );
Newspack_Popups_Model::set_popup_terms( $original_popup_id, [ $tag_id ], 'post_tag' );
Newspack_Popups_Model::set_popup_terms( $original_popup_id, [ $campaign_id ], Newspack_Popups::NEWSPACK_POPUPS_TAXONOMY );
Newspack_Popups_Model::set_popup_terms( $original_popup_id, [ $segment_id ], Newspack_Segments_Model::TAX_SLUG );

$duplicate_popup_id = Newspack_Popups::duplicate_popup( $original_popup_id );
$second_duplicate_id = Newspack_Popups::duplicate_popup( $duplicate_popup_id );
Expand Down Expand Up @@ -94,5 +102,11 @@ public function test_e2e_duplicate_prompt() {
Newspack_Popups_Model::get_popup_options( $duplicate_popup_id ),
'Duplicated prompt has the same prompt options as the original prompt.'
);

self::assertEquals(
Newspack_Popups_Model::get_popup_segments( $original_popup_id ),
Newspack_Popups_Model::get_popup_segments( $duplicate_popup_id ),
'Duplicate prompt has the same segments as the original prompt.'
);
}
}
Loading