-
Notifications
You must be signed in to change notification settings - Fork 146
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
enhance: support for additional CPT's #1483
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -66,17 +66,26 @@ public function third_party_cpt_options( $additional_options ) { | |||||||||||||||||||||
|
||||||||||||||||||||||
if ( $post_type_object ) { | ||||||||||||||||||||||
$additional_options['additional'][ $key ] = [ | ||||||||||||||||||||||
'id' => $key, | ||||||||||||||||||||||
'name' => $key, | ||||||||||||||||||||||
'db_key' => $key, | ||||||||||||||||||||||
'db_type' => 'meta', | ||||||||||||||||||||||
'type' => 'input-number', | ||||||||||||||||||||||
'label' => sprintf( 'Number of %s', esc_html( $post_type_object->label ) ), | ||||||||||||||||||||||
'tooltip' => sprintf( | ||||||||||||||||||||||
'Set the maximum number of %s users can create within their subscription period. Enter -1 for unlimited', | ||||||||||||||||||||||
'id' => $key, | ||||||||||||||||||||||
'name' => $key, | ||||||||||||||||||||||
'db_key' => 'additional_cpt_options', | ||||||||||||||||||||||
'db_type' => 'meta_serialized', | ||||||||||||||||||||||
'serialize_key' => $key, | ||||||||||||||||||||||
Comment on lines
+69
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improper Use of Meta Keys and Serialization The array keys Consider refactoring to ensure that each custom post type option has a unique and coherent meta key. For example: - 'db_key' => 'additional_cpt_options',
- 'db_type' => 'meta_serialized',
- 'serialize_key' => $key,
+ 'db_key' => 'additional_cpt_options_' . $key,
+ 'db_type' => 'meta',
+ 'serialize_key' => null, This change assigns a unique meta key for each post type option and avoids complex serialization. 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
'type' => 'input-number', | ||||||||||||||||||||||
'label' => sprintf( | ||||||||||||||||||||||
// translators: %s: post type label | ||||||||||||||||||||||
__( 'Number of %s', 'wp-user-frontend' ), | ||||||||||||||||||||||
esc_html( $post_type_object->label ) | ||||||||||||||||||||||
), | ||||||||||||||||||||||
'tooltip' => sprintf( | ||||||||||||||||||||||
// translators: %s: post type label | ||||||||||||||||||||||
__( | ||||||||||||||||||||||
'Set the maximum number of %s users can create within their subscription period. Enter -1 for unlimited', | ||||||||||||||||||||||
'wp-user-frontend' | ||||||||||||||||||||||
), | ||||||||||||||||||||||
esc_html( $key ) | ||||||||||||||||||||||
), | ||||||||||||||||||||||
'default' => '-1', | ||||||||||||||||||||||
'default' => '-1', | ||||||||||||||||||||||
]; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
@@ -809,9 +818,6 @@ public function profile_subscription_details( $profileuser ) { | |||||||||||||||||||||
$_post_expiration_time = explode( ' ', isset( $user_sub['_post_expiration_time'] ) ? $user_sub['_post_expiration_time'] : '' ); | ||||||||||||||||||||||
$time_value = isset( $_post_expiration_time[0] ) && ! empty( $_post_expiration_time[0] ) ? $_post_expiration_time[0] : '1'; | ||||||||||||||||||||||
$time_type = isset( $_post_expiration_time[1] ) && ! empty( $_post_expiration_time[1] ) ? $_post_expiration_time[1] : 'day'; | ||||||||||||||||||||||
|
||||||||||||||||||||||
error_log( print_r( $_post_expiration_time, true ) ); | ||||||||||||||||||||||
error_log( print_r( $time_type, true ) ); | ||||||||||||||||||||||
?> | ||||||||||||||||||||||
<tr> | ||||||||||||||||||||||
<th><label><?php esc_html_e( 'Post Expiration Enabled', 'wp-user-frontend' ); ?></label></th> | ||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -304,6 +304,7 @@ public static function get_subscription_meta( $subscription_id, $pack_post = nul | |||||||||||
$meta['_trial_duration_type'] = $meta['trial_duration_type']; | ||||||||||||
$meta['post_type_name'] = get_post_meta( $subscription_id, '_post_type_name', true ); | ||||||||||||
$meta['_post_type_name'] = $meta['post_type_name']; | ||||||||||||
$meta['additional_cpt_options'] = get_post_meta( $subscription_id, 'additional_cpt_options', true ); | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Use consistent meta key naming with underscore prefix In the existing code, meta keys are stored with an underscore prefix (e.g., Apply this diff to adjust the meta key: -$meta['additional_cpt_options'] = get_post_meta( $subscription_id, 'additional_cpt_options', true );
+$meta['_additional_cpt_options'] = get_post_meta( $subscription_id, '_additional_cpt_options', true );
+$meta['additional_cpt_options'] = $meta['_additional_cpt_options']; 📝 Committable suggestion
Suggested change
|
||||||||||||
$meta['_enable_post_expiration'] = get_post_meta( $subscription_id, '_enable_post_expiration', true ); | ||||||||||||
$meta['_post_expiration_time'] = get_post_meta( $subscription_id, '_post_expiration_time', true ); | ||||||||||||
$meta['_post_expiration_number'] = get_post_meta( $subscription_id, '_post_expiration_number', true ); | ||||||||||||
|
@@ -431,6 +432,7 @@ public function save_form_meta( $subscription_id, $post ) { | |||||||||||
update_post_meta( $subscription_id, '_trial_duration', $trial_duration ); | ||||||||||||
update_post_meta( $subscription_id, '_trial_duration_type', $trial_duration_type ); | ||||||||||||
update_post_meta( $subscription_id, '_post_type_name', array_map( 'sanitize_text_field', $post_data['post_type_name'] ) ); | ||||||||||||
update_post_meta( $subscription_id, 'additional_cpt_options', array_map( 'sanitize_text_field', $post_data['additional_cpt_options'] ) ); | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add check for 'additional_cpt_options' existence before updating meta To prevent undefined index notices, ensure that Apply this diff to add the necessary check and adjust the meta key: +if ( ! empty( $post_data['additional_cpt_options'] ) && is_array( $post_data['additional_cpt_options'] ) ) {
+ $sanitized_options = array_map( 'sanitize_text_field', $post_data['additional_cpt_options'] );
+ update_post_meta( $subscription_id, '_additional_cpt_options', $sanitized_options );
+} 📝 Committable suggestion
Suggested change
|
||||||||||||
update_post_meta( $subscription_id, '_enable_post_expiration', $enable_post_expir ); | ||||||||||||
update_post_meta( $subscription_id, '_post_expiration_time', $expiration_time ); | ||||||||||||
update_post_meta( $subscription_id, '_expired_post_status', $expire_post_status ); | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure
'additional_cpt_options'
exists in$post_data
before accessing itTo prevent potential undefined index notices, please check if
'additional_cpt_options'
exists in$post_data
before accessing it.Apply this diff to add the necessary check:
📝 Committable suggestion