diff --git a/includes/corrections/README.md b/includes/corrections/README.md index 4330e58ab0..d30919f303 100644 --- a/includes/corrections/README.md +++ b/includes/corrections/README.md @@ -18,12 +18,13 @@ define( 'NEWSPACK_CORRECTIONS_ENABLED', true ); Corrections are stored as `newspack_correction` custom post type. A correction consists of the following fields: -| Name | Type | Stored As | Description | -| ----------------------------- | -------- | -------------- | --------------------------------------------------------------- | -| `title` | `string` | `post_title` | The correction title. Defaults to 'Correction for [post title]' | -| `content` | `string` | `post_content` | The correction text. | -| `date` | `string` | `post_date` | The date assigned to the correction. | -| `newspack_correction-post-id` | `int` | `post_meta` | The ID of the post to which the correction is associated. | +| Name | Type | Stored As | Description | +| ----------------------------- | -------- | -------------- | ------------------------------------------------------------------------------ | +| `title` | `string` | `post_title` | The correction title. Defaults to 'Correction for [post title]' | +| `content` | `string` | `post_content` | The correction text. | +| `date` | `string` | `post_date` | The date assigned to the correction. | +| `newspack_correction-post-id` | `int` | `post_meta` | The ID of the post to which the correction is associated. | +| `newspack_corrections_type` | `string` | `post_meta` | Whether it's a correction or a clarification (`correction` or `clarification`) | In addition, some correction data is stored in the associated post as post meta: diff --git a/includes/corrections/class-corrections.php b/includes/corrections/class-corrections.php index 0131f2c28d..c899f4ca30 100644 --- a/includes/corrections/class-corrections.php +++ b/includes/corrections/class-corrections.php @@ -31,6 +31,16 @@ class Corrections { */ const CORRECTIONS_LOCATION_META = 'newspack_corrections_location'; + /** + * Meta key for post corrections type meta. + */ + const CORRECTIONS_TYPE_META = 'newspack_corrections_type'; + + /** + * Supported post types. + */ + const SUPPORTED_POST_TYPES = [ 'article_legacy', 'content_type_blog', 'post', 'press_release' ]; + /** * Initializes the class. */ @@ -134,7 +144,7 @@ public static function register_post_type() { 'public' => true, 'public_queryable' => true, 'query_var' => true, - 'rewrite' => [ 'slug' => 'correction' ], + 'rewrite' => [ 'slug' => 'corrections' ], 'show_ui' => false, 'show_in_rest' => true, 'supports' => $supports, @@ -142,6 +152,12 @@ public static function register_post_type() { 'menu_icon' => 'dashicons-edit', ); \register_post_type( self::POST_TYPE, $args ); + + $rewrite_rules_updated_option_name = 'newspack_corrections_rewrite_rules_updated'; + if ( get_option( $rewrite_rules_updated_option_name ) !== true ) { + flush_rewrite_rules(); //phpcs:ignore + update_option( $rewrite_rules_updated_option_name, true ); + } } /** @@ -161,6 +177,7 @@ public static function add_corrections( $post_id, $corrections ) { 'post_status' => 'publish', 'meta_input' => [ self::CORRECTION_POST_ID_META => $post_id, + self::CORRECTIONS_TYPE_META => $correction['type'], ], ] ); @@ -202,6 +219,9 @@ public static function update_correction( $correction_id, $correction ) { 'ID' => $correction_id, 'post_content' => sanitize_textarea_field( $correction['content'] ), 'post_date' => sanitize_text_field( $correction['date'] ), + 'meta_input' => [ + self::CORRECTIONS_TYPE_META => $correction['type'], + ], ] ); } @@ -225,6 +245,32 @@ public static function add_corrections_shortcode() { add_shortcode( 'corrections', [ __CLASS__, 'handle_corrections_shortcode' ] ); } + /** + * Gets the Correction type label for a given post. Defaults to the current global post if none is provided. + * + * @param int $post_id The correction id. + * @return string The correction type label. + */ + public static function get_correction_type( $post_id = null ) { + if ( ! $post_id ) { + $post_id = get_the_ID(); + } + return self::get_correction_type_label( get_post_meta( $post_id, self::CORRECTIONS_TYPE_META, true ) ); + } + + /** + * Gets the correction type label. + * + * @param string $type the correction type. + * @return string the correction type label. + */ + private static function get_correction_type_label( $type ) { + if ( 'clarification' === $type ) { + return __( 'Clarification', 'newspack-plugin' ); + } + return __( 'Correction', 'newspack-plugin' ); + } + /** * Handles the corrections shortcode. * @@ -288,8 +334,7 @@ public static function handle_corrections_shortcode() { * @param string $post_type the post type. */ public static function add_corrections_metabox( $post_type ) { - $valid_post_types = [ 'article_legacy', 'content_type_blog', 'post', 'press_release' ]; - if ( in_array( $post_type, $valid_post_types, true ) ) { + if ( in_array( $post_type, self::SUPPORTED_POST_TYPES, true ) ) { add_meta_box( 'corrections', 'Corrections', @@ -330,6 +375,7 @@ public static function render_corrections_metabox( $post ) { foreach ( $corrections as $correction ) : $correction_content = $correction->post_content; $correction_date = \get_the_date( 'Y-m-d', $correction->ID ); + $correction_type = get_post_meta( $correction->ID, self::CORRECTIONS_TYPE_META, true ); ?>

@@ -339,6 +385,13 @@ public static function render_corrections_metabox( $post ) {

+

+ + +

@@ -357,8 +410,8 @@ public static function render_corrections_metabox( $post ) { * @param int $post_id the post id. */ public static function save_corrections_metabox( $post_id ) { - // return early if we are saving a correction. - if ( self::POST_TYPE === get_post_type( $post_id ) ) { + // return early if we are saving an unsupported post type. + if ( ! in_array( get_post_type( $post_id ), self::SUPPORTED_POST_TYPES, true ) ) { return; } @@ -414,6 +467,7 @@ public static function save_corrections_metabox( $post_id ) { $corrections[] = [ 'content' => sanitize_textarea_field( $correction['content'] ), 'date' => ! empty( $correction['date'] ) ? sanitize_text_field( $correction['date'] ) : gmdate( 'Y-m-d' ), + 'type' => sanitize_text_field( $correction['type'] ), ]; } self::add_corrections( $post_id, $corrections ); @@ -454,11 +508,13 @@ public static function output_corrections_on_post( $content ) { post_content; - $correction_date = \get_the_date( 'M j, Y', $correction->ID ); + $correction_date = \get_the_date( get_option( 'date_format' ), $correction->ID ); + $correction_time = \get_the_time( get_option( 'time_format' ), $correction->ID ); $correction_heading = sprintf( - // translators: %s: correction date. - __( 'Correction on %s', 'newspack-plugin' ), - $correction_date + '%s, %s %s', + self::get_correction_type_label( get_post_meta( $correction->ID, self::CORRECTIONS_TYPE_META, true ) ), + $correction_date, + $correction_time ); ?> diff --git a/includes/plugins/class-woocommerce.php b/includes/plugins/class-woocommerce.php index 68142f54bc..a7fa110c5d 100644 --- a/includes/plugins/class-woocommerce.php +++ b/includes/plugins/class-woocommerce.php @@ -20,6 +20,7 @@ class WooCommerce { public static function init() { add_action( 'wp_loaded', [ __CLASS__, 'disable_wc_author_archive_override' ] ); add_filter( 'woocommerce_rest_prepare_shop_order_object', [ __CLASS__, 'modify_shop_order_wc_rest_api_payload' ] ); + add_filter( 'woocommerce_create_pages', [ __CLASS__, 'use_shortcodes_for_cart_checkout' ] ); } /** @@ -52,5 +53,18 @@ public static function modify_shop_order_wc_rest_api_payload( $response ) { $response->set_data( $data ); return $response; } + + /** + * Override the default page contents when creating the WooCommerce Cart and Checkout pages. + * + * @param array $woocommerce_pages Defaults for WooCommerce pages created on install. + * @return array + */ + public static function use_shortcodes_for_cart_checkout( $woocommerce_pages ) { + $woocommerce_pages['cart']['content'] = '[woocommerce_cart]'; + $woocommerce_pages['checkout']['content'] = '[woocommerce_checkout]'; + + return $woocommerce_pages; + } } WooCommerce::init(); diff --git a/includes/plugins/wc-memberships/class-memberships.php b/includes/plugins/wc-memberships/class-memberships.php index b87cb2df5c..cc576e64fc 100644 --- a/includes/plugins/wc-memberships/class-memberships.php +++ b/includes/plugins/wc-memberships/class-memberships.php @@ -774,7 +774,7 @@ public static function render_js() { if ( ev.detail.authenticated && ! window?.newspackReaderActivation?.getPendingCheckout() ) { if ( ras.overlays.get().length ) { ras.on( 'overlay', function( ev ) { - if ( ! ev.detail.overlays.length ) { + if ( ! ev.detail.overlays.length && ! window?.newspackReaderActivation?.openNewslettersSignupModal ) { window.location.reload(); } } ); diff --git a/includes/plugins/woocommerce-subscriptions/class-woocommerce-subscriptions.php b/includes/plugins/woocommerce-subscriptions/class-woocommerce-subscriptions.php index 013b4dcc4b..f9e528e5c1 100644 --- a/includes/plugins/woocommerce-subscriptions/class-woocommerce-subscriptions.php +++ b/includes/plugins/woocommerce-subscriptions/class-woocommerce-subscriptions.php @@ -40,7 +40,7 @@ public static function woocommerce_subscriptions_integration_init() { * @return bool */ public static function is_active() { - return class_exists( 'WC_Subscriptions' ); + return function_exists( 'WC' ) && class_exists( 'WC_Subscriptions' ); } /** diff --git a/package-lock.json b/package-lock.json index e5fb0681bc..16cf724f59 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,7 +25,7 @@ "@testing-library/react": "^12.1.4", "@types/qs": "^6.9.17", "@types/react": "^17.0.75", - "@wordpress/browserslist-config": "^6.15.0", + "@wordpress/browserslist-config": "^6.17.0", "eslint": "^8.57.0", "lint-staged": "^15.4.1", "newspack-scripts": "^5.5.2", @@ -6163,10 +6163,11 @@ } }, "node_modules/@wordpress/browserslist-config": { - "version": "6.15.0", - "resolved": "https://registry.npmjs.org/@wordpress/browserslist-config/-/browserslist-config-6.15.0.tgz", - "integrity": "sha512-JmpThXSvE/ZsihJ/GOBmZZUEgVN78xWIPDacRzEXCPp9FA4UuJpXgx1JY3nWe4L3FyB6XIz+Klk0TfEwfL8S2w==", + "version": "6.17.0", + "resolved": "https://registry.npmjs.org/@wordpress/browserslist-config/-/browserslist-config-6.17.0.tgz", + "integrity": "sha512-cjMclWLwfam5O03gOHWjD8veeLVnfmC93V9LX1aPt/ZT9aE0cmEZUxBa3VzkDM7NvuZFj7SjSvJr+vuar9Np1A==", "dev": true, + "license": "GPL-2.0-or-later", "engines": { "node": ">=18.12.0", "npm": ">=8.19.2" diff --git a/package.json b/package.json index fb5b9a17a2..dae6a052e1 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "@testing-library/react": "^12.1.4", "@types/qs": "^6.9.17", "@types/react": "^17.0.75", - "@wordpress/browserslist-config": "^6.15.0", + "@wordpress/browserslist-config": "^6.17.0", "eslint": "^8.57.0", "lint-staged": "^15.4.1", "newspack-scripts": "^5.5.2", diff --git a/src/other-scripts/corrections/index.js b/src/other-scripts/corrections/index.js index f721c2da3a..b9f53fe0ca 100644 --- a/src/other-scripts/corrections/index.js +++ b/src/other-scripts/corrections/index.js @@ -52,11 +52,23 @@ domReady( () => { const newCorrection = document.createElement( 'div' ); newCorrection.classList.add( 'correction' ); newCorrection.innerHTML = ` -
+

${ __( 'Article Correction', 'newspack-plugin' ) }

- +
-

${ __( 'Date:', 'newspack-plugin' ) }

+

${ __( + 'Date:', + 'newspack-plugin' + ) }

+

${ __( 'Type:', 'newspack-plugin' ) } + +

`; diff --git a/src/reader-activation/index.js b/src/reader-activation/index.js index 9bb8f2831e..d8d0b888e1 100644 --- a/src/reader-activation/index.js +++ b/src/reader-activation/index.js @@ -193,7 +193,7 @@ export function openNewslettersSignupModal( config = {} ) { config = { ...{ onSuccess: null, - onDissmiss: null, + onDismiss: null, onError: null, initialState: null, skipSuccess: false, diff --git a/tests/unit-tests/plugins/woocommerce-subscriptions/class-woocommerce-subscriptions.php b/tests/unit-tests/plugins/woocommerce-subscriptions/class-woocommerce-subscriptions.php index b55aceb2a0..1d5304b4d1 100644 --- a/tests/unit-tests/plugins/woocommerce-subscriptions/class-woocommerce-subscriptions.php +++ b/tests/unit-tests/plugins/woocommerce-subscriptions/class-woocommerce-subscriptions.php @@ -19,7 +19,7 @@ class Newspack_Test_WooCommerce_Subscriptions extends WP_UnitTestCase { */ public function test_is_active() { $is_active = WooCommerce_Subscriptions::is_active(); - $this->assertTrue( $is_active, 'WooCommerce Subscriptions integration should be active when WC_Subscriptions class exists.' ); + $this->assertFalse( $is_active, 'WooCommerce Subscriptions integration should not be active if the main WooCommerce plugin is not available.' ); } /** @@ -27,6 +27,6 @@ public function test_is_active() { */ public function test_is_enabled() { $is_enabled = WooCommerce_Subscriptions::is_enabled(); - $this->assertTrue( $is_enabled, 'WooCommerce Subscriptions integration should be enabled when RAS is enabled.' ); + $this->assertFalse( $is_enabled, 'WooCommerce Subscriptions integration should not be active if the main WooCommerce plugin is not available.' ); } }