From d349c0a3e2c40ae3a393a451434e1129d8922b2d Mon Sep 17 00:00:00 2001 From: MILLER/F Date: Thu, 12 Dec 2024 11:12:21 +0000 Subject: [PATCH] Allow coupons Memberships gifts and coupons CPT types and metas (#40541) * whitelist coupons and gifts cpt types and metas * Changelogs * Gift and coupons CPT setup * Update class-jetpack-memberships.php --- .../add-allow-coupons-gifts-cpt-types | 4 + projects/packages/sync/src/class-defaults.php | 2 - .../add-allow-coupons-gifts-cpt-types | 4 + .../memberships/class-jetpack-memberships.php | 89 ++++++++++++++++++- 4 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 projects/packages/sync/changelog/add-allow-coupons-gifts-cpt-types create mode 100644 projects/plugins/jetpack/changelog/add-allow-coupons-gifts-cpt-types diff --git a/projects/packages/sync/changelog/add-allow-coupons-gifts-cpt-types b/projects/packages/sync/changelog/add-allow-coupons-gifts-cpt-types new file mode 100644 index 0000000000000..dbda2687742d8 --- /dev/null +++ b/projects/packages/sync/changelog/add-allow-coupons-gifts-cpt-types @@ -0,0 +1,4 @@ +Significance: patch +Type: added + + diff --git a/projects/packages/sync/src/class-defaults.php b/projects/packages/sync/src/class-defaults.php index a60fde0e52aa8..0d05b206c97b4 100644 --- a/projects/packages/sync/src/class-defaults.php +++ b/projects/packages/sync/src/class-defaults.php @@ -461,8 +461,6 @@ public static function get_callable_whitelist() { 'wp_log', // WP Logging Plugin. 'wpephpcompat_jobs', 'wprss_feed_item', - 'memberships_coupon', - 'memberships_gift', 'tribe-ea-record', // The Events Calendar Plugin - Store Event Aggregator record information. 'wphb_minify_group', // Hummingbird Plugin - Used internally to keep data about assets minification. 'bigcommerce_task', // BigCommerce Plugin - Store import queue. diff --git a/projects/plugins/jetpack/changelog/add-allow-coupons-gifts-cpt-types b/projects/plugins/jetpack/changelog/add-allow-coupons-gifts-cpt-types new file mode 100644 index 0000000000000..1ef8afea050a2 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-allow-coupons-gifts-cpt-types @@ -0,0 +1,4 @@ +Significance: patch +Type: other + + diff --git a/projects/plugins/jetpack/modules/memberships/class-jetpack-memberships.php b/projects/plugins/jetpack/modules/memberships/class-jetpack-memberships.php index c7e6b39fd8836..75f4e627f88f5 100644 --- a/projects/plugins/jetpack/modules/memberships/class-jetpack-memberships.php +++ b/projects/plugins/jetpack/modules/memberships/class-jetpack-memberships.php @@ -33,6 +33,20 @@ class Jetpack_Memberships { */ public static $post_type_plan = 'jp_mem_plan'; + /** + * Our CPT type for the product (plan). + * + * @var string + */ + public static $post_type_coupon = 'memberships_coupon'; + + /** + * Our CPT type for the product (plan). + * + * @var string + */ + public static $post_type_gift = 'memberships_gift'; + /** * Tier type for plans * @@ -282,6 +296,44 @@ private function setup_cpts() { 'show_in_rest' => false, ); register_post_type( self::$post_type_plan, $order_args ); + $coupon_args = array( + 'label' => esc_html__( 'Coupon', 'jetpack' ), + 'description' => esc_html__( 'Memberships coupons', 'jetpack' ), + 'supports' => array( 'title', 'custom-fields', 'content' ), + 'hierarchical' => false, + 'public' => false, + 'show_ui' => false, + 'show_in_menu' => false, + 'show_in_admin_bar' => false, + 'show_in_nav_menus' => false, + 'can_export' => true, + 'has_archive' => false, + 'exclude_from_search' => true, + 'publicly_queryable' => false, + 'rewrite' => false, + 'capabilities' => $capabilities, + 'show_in_rest' => false, + ); + register_post_type( self::$post_type_coupon, $coupon_args ); + $gift_args = array( + 'label' => esc_html__( 'Gift', 'jetpack' ), + 'description' => esc_html__( 'Memberships gifts', 'jetpack' ), + 'supports' => array( 'title', 'custom-fields', 'content' ), + 'hierarchical' => false, + 'public' => false, + 'show_ui' => false, + 'show_in_menu' => false, + 'show_in_admin_bar' => false, + 'show_in_nav_menus' => false, + 'can_export' => true, + 'has_archive' => false, + 'exclude_from_search' => true, + 'publicly_queryable' => false, + 'rewrite' => false, + 'capabilities' => $capabilities, + 'show_in_rest' => false, + ); + register_post_type( self::$post_type_gift, $gift_args ); } /** @@ -294,6 +346,8 @@ private function setup_cpts() { */ public function allow_rest_api_types( $post_types ) { $post_types[] = self::$post_type_plan; + $post_types[] = self::$post_type_coupon; + $post_types[] = self::$post_type_gift; return $post_types; } @@ -306,11 +360,42 @@ public function allow_rest_api_types( $post_types ) { * @return array */ public function allow_sync_post_meta( $post_meta ) { - $meta_keys = array_map( + $meta_keys_plans = array_map( array( $this, 'return_meta' ), self::get_plan_property_mapping() ); - return array_merge( $post_meta, array_values( $meta_keys ) ); + + $meta_coupons_prefix = self::$post_type_coupon . '_'; + $meta_keys_coupons = array( + $meta_coupons_prefix . 'coupon_code', + $meta_coupons_prefix . 'can_be_combined', + $meta_coupons_prefix . 'first_time_purchase_only', + $meta_coupons_prefix . 'limit_per_user', + $meta_coupons_prefix . 'discount_type', + $meta_coupons_prefix . 'discount_value', + $meta_coupons_prefix . 'discount_percentage', + $meta_coupons_prefix . 'discount_currency', + $meta_coupons_prefix . 'start_date', + $meta_coupons_prefix . 'end_date', + $meta_coupons_prefix . 'plan_ids_allow_list', + $meta_coupons_prefix . 'duration', + $meta_coupons_prefix . 'email_allow_list', + $meta_coupons_prefix . 'is_deleted', + $meta_coupons_prefix . 'is_sandboxed', + ); + + $meta_gifts_prefix = self::$post_type_gift . '_'; + $meta_keys_gifts = array( + $meta_gifts_prefix . 'user_id', + $meta_gifts_prefix . 'plan_id', + $meta_gifts_prefix . 'is_deleted', + ); + return array_merge( + $post_meta, + array_values( $meta_keys_plans ), + $meta_keys_coupons, + $meta_keys_gifts + ); } /**