Skip to content

Commit

Permalink
Merge pull request #3176 from Automattic/alpha
Browse files Browse the repository at this point in the history
Release Jun 10
  • Loading branch information
dkoo authored Jun 12, 2024
2 parents b957374 + 8f58ce4 commit 9ea1e38
Show file tree
Hide file tree
Showing 23 changed files with 151 additions and 77 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module.exports = {
newspack_aux_data: 'readonly',
},
rules: {
'no-console': 'off',
'@typescript-eslint/ban-ts-comment': 'warn',
},
ignorePatterns: [ 'dist/', 'node_modules/', 'assets/components/node_modules' ],
Expand Down
23 changes: 22 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
# [4.2.0](https://github.com/Automattic/newspack-plugin/compare/v4.1.0...v4.2.0) (2024-06-11)
# [4.2.0-alpha.1](https://github.com/Automattic/newspack-plugin/compare/v4.1.0...v4.2.0-alpha.1) (2024-05-31)


### Bug Fixes

* **newsletters:** missing UTM params passing ([#3145](https://github.com/Automattic/newspack-plugin/issues/3145)) ([0688fa0](https://github.com/Automattic/newspack-plugin/commit/0688fa002700d479c69d56ee3325a74ba63cc39d))
* **ras-setup:** redirect to init screen after setup ([#3142](https://github.com/Automattic/newspack-plugin/issues/3142)) ([b86580b](https://github.com/Automattic/newspack-plugin/commit/b86580b6c0926cbddb5c621409d4cc448e1f5e1e))
* **ras:** handle RAS disabled in newsletters signup handling ([3d70a1d](https://github.com/Automattic/newspack-plugin/commit/3d70a1d3700f10b1e9aa9e37035bd6e8c5ebb6e3))
* **ras:** prevent email address exposure via user login ([#3139](https://github.com/Automattic/newspack-plugin/issues/3139)) ([9b534d3](https://github.com/Automattic/newspack-plugin/commit/9b534d3c51ac93f269e1baa3577e426b5b4be7a5))
* **reader-revenue:** prevent sending duplicate receipt emails ([aa91890](https://github.com/Automattic/newspack-plugin/commit/aa9189023bd03f0a117c5bd0c4d2db60d28c66d2))
* **tracking:** handling user role in pixel ([#3137](https://github.com/Automattic/newspack-plugin/issues/3137)) ([a041764](https://github.com/Automattic/newspack-plugin/commit/a0417642806ae7be499e9b1d2d571831d07d6331))


### Features

* **cli:** enable running the setup with a site import ([#3122](https://github.com/Automattic/newspack-plugin/issues/3122)) ([c6cc10e](https://github.com/Automattic/newspack-plugin/commit/c6cc10efd5e2ccfa2f0eba11fa11ac083d2213d4))
* expand memberships perf to archives ([#3148](https://github.com/Automattic/newspack-plugin/issues/3148)) ([bdbdf1d](https://github.com/Automattic/newspack-plugin/commit/bdbdf1db6b816f424053c9b6fdb86fd05b250150))
* **memberships:** remove content restriction handling on the homepage ([b63a3fa](https://github.com/Automattic/newspack-plugin/commit/b63a3fa8ad9317aa5bf92416a398e58808502f40))
* update donation landing page ([#3109](https://github.com/Automattic/newspack-plugin/issues/3109)) ([96218c1](https://github.com/Automattic/newspack-plugin/commit/96218c18f206c330e36c0472253b6c79b70c9791))

# [4.2.0](https://github.com/Automattic/newspack-plugin/compare/v4.1.0...v4.2.0) (2024-06-11)


### Bug Fixes

* **ga:** add custom parameters to FE-originating GA requests ([#3178](https://github.com/Automattic/newspack-plugin/issues/3178)) ([860791f](https://github.com/Automattic/newspack-plugin/commit/860791fe9e0f77aa34e85a9a155316868ad77844))


# [4.1.0](https://github.com/Automattic/newspack-plugin/compare/v4.0.1...v4.1.0) (2024-05-30)


Expand Down
1 change: 0 additions & 1 deletion assets/reader-activation/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,6 @@ window.newspackRAS.push( function ( readerActivation ) {
}
} )
.catch( error => {
console.log( error );
if ( googleLoginForm?.endLoginFlow ) {
googleLoginForm.endLoginFlow( error?.message, 400 );
}
Expand Down
2 changes: 1 addition & 1 deletion assets/reader-activation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ function handlePush( ...args ) {
} else if ( typeof arg === 'function' ) {
arg( readerActivation );
} else {
console.warn( 'Invalid newspackRAS.push argument', arg );
console.warn( 'Invalid newspackRAS.push argument', arg ); // eslint-disable-line no-console
}
} );
}
Expand Down
2 changes: 1 addition & 1 deletion assets/wizards/componentsDemo/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '../../shared/js/public-path';

/* eslint-disable jsx-a11y/anchor-is-valid */
/* eslint-disable jsx-a11y/anchor-is-valid, no-console */

/**
* Components Demo
Expand Down
30 changes: 15 additions & 15 deletions assets/wizards/engagement/views/reader-activation/complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ const listItems = [
},
];

const activationSteps = [
__( 'Setting up new segments…', 'newspack-plugin' ),
__( 'Activating reader registration…', 'newspack-plugin' ),
__( 'Activating Reader Activation Campaign…', 'newspack-plugin' ),
];

const activationStepsCount = activationSteps.length;
const DEFAULT_ACTIVATION_STEPS = {
campaignsSegments: __( 'Setting up new segments…', 'newspack-plugin' ),
readerRegistration: __( 'Activating reader registration…', 'newspack-plugin' ),
campaignsPrompts: __( 'Activating Reader Activation Campaign…', 'newspack-plugin' ),
};

/**
* Get a random number between min and max.
Expand All @@ -70,15 +68,17 @@ export default withWizardScreen( () => {
const [ progressLabel, setProgressLabel ] = useState( false );
const [ completed, setCompleted ] = useState( false );
const timer = useRef();
const [ activationSteps, setActivationSteps ] = useState(
Object.values( DEFAULT_ACTIVATION_STEPS )
);
const { reader_activation_url, is_skipped_campaign_setup = '' } = newspack_engagement_wizard;
const isSkippedCampaignSetup = is_skipped_campaign_setup === '1';

/**
* If skipped, remove first item.
*/
if ( isSkippedCampaignSetup && activationSteps.length !== activationStepsCount - 1 ) {
activationSteps.shift();
}
useEffect( () => {
if ( isSkippedCampaignSetup ) {
setActivationSteps( [ DEFAULT_ACTIVATION_STEPS.readerRegistration ] );
}
}, [ isSkippedCampaignSetup ] );

/**
* Generate step list strings
Expand Down Expand Up @@ -107,12 +107,12 @@ export default withWizardScreen( () => {
setProgress( _progress => _progress + 1 );
}, generateRandomNumber( 1000, 2000 ) );
}
if ( progress === activationSteps.length && completed ) {
if ( progress >= activationSteps.length && completed ) {
setProgress( activationSteps.length + 1 ); // Plus one to account for the "Done!" step.
setProgressLabel( __( 'Done!', 'newspack-plugin' ) );
setTimeout( () => {
setInFlight( false );
// window.location = reader_activation_url;
window.location.replace( reader_activation_url );
}, 3000 );
}
}, [ completed, progress ] );
Expand Down
2 changes: 0 additions & 2 deletions assets/wizards/popups/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ const getFavoriteCategoryNamesFn = async favoriteCategories => {
} );
return category.name;
} catch ( e ) {
console.warn( e );
return '';
}
} )
Expand Down Expand Up @@ -269,7 +268,6 @@ const getItems = memoize( async path => {
label: item.title || item.name,
} ) );
} catch ( e ) {
console.warn( e );
return [];
}
} );
Expand Down
6 changes: 2 additions & 4 deletions assets/wizards/popups/views/segments/segments-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,7 @@ const SegmentsList = ( { wizardApiFetch, segments, setSegments, isLoading } ) =>
setInFlight( false );
setSegments( _segments );
} )
.catch( e => {
console.error( e );
.catch( () => {
setInFlight( false );
} );
};
Expand All @@ -285,8 +284,7 @@ const SegmentsList = ( { wizardApiFetch, segments, setSegments, isLoading } ) =>
setInFlight( false );
setSegments( _segments );
} )
.catch( e => {
console.error( e );
.catch( () => {
setInFlight( false );
} );
};
Expand Down
1 change: 0 additions & 1 deletion assets/wizards/readerRevenue/views/stripe-setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ const StripeSetup = () => {
plugins={ [ 'woocommerce-gateway-stripe' ] }
onStatus={ ( { complete } ) => {
if ( complete ) {
console.log( complete );
updateWizardSettings( {
slug: 'newspack-reader-revenue-wizard',
path: [ 'stripe_data' ],
Expand Down
5 changes: 1 addition & 4 deletions assets/wizards/site-design/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ class SiteDesignWizard extends Component {
const { theme, theme_mods } = response;
this.setState( { theme, themeSettings: theme_mods } );
} )
.catch( error => {
console.log( '[Theme Update Error]', error );
setError( { error } );
} );
.catch( error => setError( { error } ) );
};

state = {};
Expand Down
56 changes: 41 additions & 15 deletions includes/class-donations.php
Original file line number Diff line number Diff line change
Expand Up @@ -801,35 +801,60 @@ public static function checkout_create_order_line_item( $item, $cart_item_key, $
public static function create_donation_page() {
$revenue_model = 'donations';

$intro = esc_html__( 'With the support of readers like you, we provide thoughtfully researched articles for a more informed and connected community. This is your chance to support credible, community-based, public-service journalism. Please join us!', 'newspack' );
$content_heading = esc_html__( 'Donation', 'newspack' );
$content = esc_html__( "Edit and add to this content to tell your publication's story and explain the benefits of becoming a member. This is a good place to mention any special member privileges, let people know that donations are tax-deductible, or provide any legal information.", 'newspack' );

$title = esc_html__( 'Support our publication', 'newspack' );
$intro = esc_html__( 'With the support of readers like you, we provide thoughtfully researched articles for a more informed and connected community. This is your chance to support credible, community-based, public-service journalism. Please join us!', 'newspack' );
$content = esc_html__( "Edit and add to this content to tell your publication's story and explain the benefits of becoming a member. This is a good place to mention any special member privileges, let people know that donations are tax-deductible, or provide any legal information.", 'newspack' );
$image = Newspack::plugin_url() . '/includes/images/placeholder-donation.jpg';

$container_block = '
<!-- wp:cover {"url":"' . $image . '","dimRatio":20,"overlayColor":"black","isUserOverlayColor":true,"minHeight":85,"minHeightUnit":"vh","align":"full","style":{"spacing":{"padding":{"top":"var:preset|spacing|80","bottom":"var:preset|spacing|80","left":"var:preset|spacing|80","right":"var:preset|spacing|80"}}},"layout":{"type":"constrained"}} -->
<div class="wp-block-cover alignfull" style="padding-top:var(--wp--preset--spacing--80);padding-right:var(--wp--preset--spacing--80);padding-bottom:var(--wp--preset--spacing--80);padding-left:var(--wp--preset--spacing--80);min-height:85vh">
<span aria-hidden="true" class="wp-block-cover__background has-black-background-color has-background-dim-20 has-background-dim"></span>
<img class="wp-block-cover__image-background" alt="" src="' . $image . '" data-object-fit="cover"/>
<div class="wp-block-cover__inner-container">
<!-- wp:columns {"verticalAlignment":"center","align":"wide"} -->
<div class="wp-block-columns alignwide are-vertically-aligned-center">
<!-- wp:column {"verticalAlignment":"center"} -->
<div class="wp-block-column is-vertically-aligned-center">
%1$s
</div>
<!-- /wp:column -->
<!-- wp:column {"verticalAlignment":"center"} -->
<div class="wp-block-column is-vertically-aligned-center">
%2$s
</div>
<!-- /wp:column -->
</div>
<!-- /wp:columns -->
</div>
</div>
<!-- /wp:cover -->';
$heading_block = '
<!-- wp:heading -->
<h2>%s</h2>
<!-- /wp:heading -->';
$intro_block = '
<!-- wp:paragraph -->
<p>%s</p>
<!-- /wp:paragraph -->';
$content_heading_block = '
<!-- wp:heading -->
<h2>%s</h2>
<!-- /wp:heading -->';
$content_block = '
<!-- wp:paragraph -->
<p>%s</p>
<!-- /wp:paragraph -->';

$page_content = sprintf( $intro_block, $intro );
$column_content = sprintf( $heading_block, $title );
$column_content .= sprintf( $intro_block, $intro );
$column_content .= sprintf( $content_block, $content );

if ( 'donations' === $revenue_model ) {
$page_content .= self::get_donations_block();
$page_content = sprintf( $container_block, $column_content, self::get_donations_block() );
} elseif ( 'subscriptions' === $revenue_model ) {
$page_content .= self::get_subscriptions_block();
$page_content = sprintf( $container_block, $column_content, self::get_subscriptions_block() );
}
$page_content .= sprintf( $content_heading_block, $content_heading );
$page_content .= sprintf( $content_block, $content );

$page_args = [
'post_type' => 'page',
'post_title' => __( 'Support our publication', 'newspack' ),
'post_title' => $title,
'post_content' => $page_content,
'post_excerpt' => __( 'Support quality journalism by joining us today!', 'newspack' ),
'post_status' => 'draft',
Expand All @@ -841,6 +866,7 @@ public static function create_donation_page() {
if ( is_numeric( $page_id ) ) {
self::set_donation_page( $page_id );
update_post_meta( $page_id, '_wp_page_template', 'single-feature.php' );
update_post_meta( $page_id, 'newspack_hide_page_title', true );
}

return $page_id;
Expand Down Expand Up @@ -882,7 +908,7 @@ protected static function get_subscriptions_block() {
* @return string Raw block content.
*/
protected static function get_donations_block() {
$block = '<!-- wp:newspack-blocks/donate /-->';
$block = '<!-- wp:newspack-blocks/donate {"className":"is-style-modern"} /-->';
return $block;
}

Expand Down
23 changes: 19 additions & 4 deletions includes/cli/class-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __invoke( $args, $assoc_args ) {

$this->plugins();

$this->initial_content();
$this->initial_content( $assoc_args );

WP_CLI::success( 'Done!' );
}
Expand Down Expand Up @@ -91,13 +91,28 @@ private function configure_plugin( $plugin ) {
/**
* Populates the site with initial content
*
* @return void
* @param array $assoc_args Assoc args passed to the CLI invocation.
* @return void|WP_Error Error on failure.
*/
private function initial_content() {
private function initial_content( $assoc_args ) {
WP_CLI::line( 'Creating Initial Content' );
$request = new WP_REST_Request( 'POST', '/' . NEWSPACK_API_NAMESPACE . '/wizard/newspack-setup-wizard/starter-content/init' );
$request->set_query_params( [ 'type' => 'generated' ] );
if ( isset( $assoc_args['site'] ) && ! empty( $assoc_args['site'] ) ) {
$assoc_args['type'] = 'import';
// Prepend HTTPS protocol if missing.
if ( ! preg_match( '/^https?:\/\//', $assoc_args['site'] ) ) {
$assoc_args['site'] = 'https://' . $assoc_args['site'];
}
}
$init_query_params = wp_parse_args(
$assoc_args,
[ 'type' => 'generated' ]
);
$request->set_query_params( $init_query_params );
$response = rest_do_request( $request );
if ( $response->status !== 200 ) {
return WP_CLI::error( $response->data['message'] );
}

WP_CLI::line( 'Creating Posts' );
for ( $i = 0; $i < 40; $i++ ) {
Expand Down
Binary file added includes/images/placeholder-donation.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion includes/plugins/class-newspack-newsletters.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public static function normalize_contact_data( $contact ) {
if ( 'utm' === substr( $param, 0, 3 ) ) {
$param = str_replace( 'utm_', '', $param );
$key = self::get_metadata_key( $utm_key_prefix ) . $param;
if ( ! isset( $contact['metadata'][ $key ] ) ) {
if ( ! isset( $contact['metadata'][ $key ] ) || empty( $contact['metadata'][ $key ] ) ) {
$contact['metadata'][ $key ] = $value;
}
}
Expand Down
16 changes: 16 additions & 0 deletions includes/plugins/wc-memberships/class-memberships.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public static function init() {
add_filter( 'newspack_popups_assess_has_disabled_popups', [ __CLASS__, 'disable_popups' ] );
add_filter( 'newspack_reader_activity_article_view', [ __CLASS__, 'suppress_article_view_activity' ], 100 );
add_filter( 'user_has_cap', [ __CLASS__, 'user_has_cap' ], 10, 3 );
add_action( 'wp', [ __CLASS__, 'remove_unnecessary_content_restriction' ], 11 );

/** Add gate content filters to mimic 'the_content'. See 'wp-includes/default-filters.php' for reference. */
add_filter( 'newspack_gate_content', 'capital_P_dangit', 11 );
Expand Down Expand Up @@ -982,5 +983,20 @@ public static function fix_expired_memberships_for_active_subscriptions() {
);
}
}

/**
* Remove content restriction on the front page and archives, to increase performance.
* The only thing Memberships would really do on these pages is add a "You need a membership"-type message in excerpts.
*/
public static function remove_unnecessary_content_restriction() {
if ( ( is_front_page() || is_archive() ) && function_exists( 'wc_memberships' ) ) {
$memberships = wc_memberships();
$restrictions_instance = $memberships->get_restrictions_instance();
$posts_restrictions_instance = $restrictions_instance->get_posts_restrictions_instance();
remove_action( 'the_post', [ $posts_restrictions_instance, 'restrict_post' ], 0 );
remove_filter( 'the_content', [ $posts_restrictions_instance, 'handle_restricted_post_content_filtering' ], 999 );
remove_action( 'loop_start', [ $posts_restrictions_instance, 'display_restricted_taxonomy_term_notice' ], 1 );
}
}
}
Memberships::init();
9 changes: 4 additions & 5 deletions includes/reader-activation/class-reader-activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -1727,9 +1727,7 @@ public static function canonize_user_data( $user_data = [] ) {
return $user_data;
}

$user_login = str_replace( '+', '_', \sanitize_user( $user_data['user_email'], true ) ); // Matches the email address, but replace + with _ to allow for Gmail aliases.
$random_password = \wp_generate_password();
$user_nicename = self::generate_user_nicename( ! empty( $user_data['display_name'] ) ? $user_data['display_name'] : $user_data['user_email'] );
$user_nicename = self::generate_user_nicename( ! empty( $user_data['display_name'] ) ? $user_data['display_name'] : $user_data['user_email'] );

// If we don't have a display name, make it match the nicename.
if ( empty( $user_data['display_name'] ) ) {
Expand All @@ -1739,9 +1737,10 @@ public static function canonize_user_data( $user_data = [] ) {
$user_data = array_merge(
$user_data,
[
'user_login' => $user_login,
'user_login' => $user_nicename,
'user_nicename' => $user_nicename,
'user_pass' => $random_password,
'display_name' => $user_nicename,
'user_pass' => \wp_generate_password(),
]
);

Expand Down
3 changes: 3 additions & 0 deletions includes/reader-activation/class-reader-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ public static function api_delete_item( $request ) {
* @param array $data Data.
*/
public static function update_newsletter_subscribed_lists( $timestamp, $data ) {
if ( ! isset( $data['user_id'] ) ) {
return;
}
if ( ! empty( $data['lists'] ) ) {
self::update_item( $data['user_id'], 'is_newsletter_subscriber', true );
self::update_item( $data['user_id'], 'newsletter_subscribed_lists', wp_json_encode( $data['lists'] ) );
Expand Down
Loading

0 comments on commit 9ea1e38

Please sign in to comment.