Skip to content

Commit

Permalink
Allow coupons Memberships gifts and coupons CPT types and metas (#40541)
Browse files Browse the repository at this point in the history
* whitelist coupons and gifts cpt types and metas
* Changelogs
* Gift and coupons CPT setup
* Update class-jetpack-memberships.php
  • Loading branch information
millerf authored Dec 12, 2024
1 parent 709e37f commit d349c0a
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added


2 changes: 0 additions & 2 deletions projects/packages/sync/src/class-defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other


Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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 );
}

/**
Expand All @@ -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;
}
Expand All @@ -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
);
}

/**
Expand Down

0 comments on commit d349c0a

Please sign in to comment.