customers
2 months ago
orders
4 months ago
subscriptions
3 months ago
add-edit-coupon.php
2 years ago
add-edit-plan-group.php
1 year ago
add-edit-plan.php
1 month ago
checkout-field-item.php
3 years ago
checkout-fields.php
3 years ago
coupons-page-sidebar.php
3 years ago
groups-page-sidebar.php
3 years ago
index.php
3 years ago
payment-method-list.php
3 years ago
plans-page-sidebar.php
3 years ago
tax-rates-setup.php
3 years ago
add-edit-plan.php
359 lines
| 1 | <?php |
| 2 | |
| 3 | use ProfilePress\Core\Admin\SettingsPages\Membership\PlanIntegrationsMetabox; |
| 4 | use ProfilePress\Core\Admin\SettingsPages\Membership\SettingsFieldsParser; |
| 5 | use ProfilePress\Core\Classes\ExtensionManager; |
| 6 | use ProfilePress\Core\Membership\Models\Subscription\SubscriptionBillingFrequency; |
| 7 | use ProfilePress\Core\Membership\Models\Subscription\SubscriptionTrialPeriod; |
| 8 | |
| 9 | $plan_data = ppress_get_plan(absint(ppressGET_var('id'))); |
| 10 | $plan_extras = $plan_data->get_meta($plan_data::PLAN_EXTRAS); |
| 11 | |
| 12 | if (ppressGET_var('ppress_subp_action') == 'edit' && ! $plan_data->exists()) { |
| 13 | ppress_content_http_redirect(PPRESS_MEMBERSHIP_PLANS_SETTINGS_SLUG); |
| 14 | |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | $append = ['create_new' => esc_html__('Create user role for this membership plan', 'wp-user-avatar')]; |
| 19 | |
| 20 | if ( ! is_null(get_role('ppress_plan_' . $plan_data->id))) { |
| 21 | $append = []; |
| 22 | } |
| 23 | |
| 24 | $user_roles = $append + (function () { |
| 25 | $core_roles = ppress_wp_roles_key_value(); |
| 26 | unset($core_roles['administrator']); |
| 27 | unset($core_roles['editor']); |
| 28 | unset($core_roles['author']); |
| 29 | unset($core_roles['contributor']); |
| 30 | unset($core_roles['subscriber']); |
| 31 | |
| 32 | return $core_roles; |
| 33 | })(); |
| 34 | |
| 35 | $plan_details = [ |
| 36 | [ |
| 37 | 'id' => 'name', |
| 38 | 'type' => 'text', |
| 39 | 'label' => esc_html__('Plan Name', 'wp-user-avatar') |
| 40 | ], |
| 41 | [ |
| 42 | 'id' => 'description', |
| 43 | 'type' => 'wp_editor', |
| 44 | 'label' => esc_html__('Plan Description', 'wp-user-avatar'), |
| 45 | 'description' => esc_html__('A description of this plan. This will be displayed on the checkout page.', 'wp-user-avatar') |
| 46 | ], |
| 47 | [ |
| 48 | 'id' => 'order_note', |
| 49 | 'type' => 'textarea', |
| 50 | 'label' => esc_html__('Purchase Note', 'wp-user-avatar'), |
| 51 | 'description' => esc_html__('Enter an optional note or special instructions to send the customer after purchase. These will be added to the order receipt.', 'wp-user-avatar') |
| 52 | ], |
| 53 | [ |
| 54 | 'id' => 'user_role', |
| 55 | 'type' => 'select', |
| 56 | 'options' => $user_roles, |
| 57 | 'label' => esc_html__('User Role', 'wp-user-avatar'), |
| 58 | 'description' => esc_html__('Select the user role to associate with this membership plan. Users that subscribe to this plan will be assigned this user role.', 'wp-user-avatar') |
| 59 | ], |
| 60 | [ |
| 61 | 'id' => 'price', |
| 62 | 'type' => 'price', |
| 63 | 'label' => esc_html__('Price', 'wp-user-avatar') . sprintf(' (%s)', ppress_get_currency_symbol()), |
| 64 | 'description' => esc_html__('The price of this membership plan. Enter 0.00 to make this plan free.', 'wp-user-avatar') |
| 65 | ] |
| 66 | ]; |
| 67 | |
| 68 | $subscription_settings = apply_filters('ppress_admin_membership_plan_subscription_settings', [ |
| 69 | [ |
| 70 | 'id' => 'billing_frequency', |
| 71 | 'type' => 'select', |
| 72 | 'label' => esc_html__('Billing Frequency', 'wp-user-avatar'), |
| 73 | 'options' => SubscriptionBillingFrequency::get_all(), |
| 74 | 'description' => ! ExtensionManager::is_premium() ? |
| 75 | '<p class="notice notice-info inline">'.sprintf( |
| 76 | esc_html__('Users who subscribe to a one-time payment plan get lifetime subscriptions. If you want their subscription to expire after a particular duration or at a specific date, %1$supgrade to premium%2$s to get the %3$sFixed Subscription Expiration addon%2$s.', 'wp-user-avatar'), |
| 77 | '<a target="_blank" href="https://profilepress.com/pricing/?utm_source=wp_dashboard&utm_medium=upgrade&utm_campaign=edit_plan_page_subscription_settings_metabox">', |
| 78 | '</a>', |
| 79 | '<a target="_blank" href="https://profilepress.com/addons/fixed-subscription-expiration/?utm_source=wp_dashboard&utm_medium=upgrade&utm_campaign=edit_plan_page_subscription_settings_metabox">', |
| 80 | ) . '</p>' : |
| 81 | '' |
| 82 | ], |
| 83 | [ |
| 84 | 'id' => 'subscription_length', |
| 85 | 'type' => 'select', |
| 86 | 'label' => esc_html__('Subscription Length', 'wp-user-avatar'), |
| 87 | 'options' => [ |
| 88 | 'renew_indefinitely' => esc_html__('Renew indefinitely until member cancels', 'wp-user-avatar'), |
| 89 | 'fixed' => esc_html__('Fixed number of payments', 'wp-user-avatar') |
| 90 | ] |
| 91 | ], |
| 92 | [ |
| 93 | 'id' => 'total_payments', |
| 94 | 'type' => 'number', |
| 95 | 'label' => esc_html__('Total Payments', 'wp-user-avatar'), |
| 96 | 'description' => esc_html__('The total number of recurring billing cycles including the trial period (if applicable). Keep in mind that once a member has completed the last payment, the subscription will not expire — essentially giving them lifetime access.', 'wp-user-avatar') |
| 97 | ], |
| 98 | [ |
| 99 | 'id' => 'signup_fee', |
| 100 | 'type' => 'price', |
| 101 | 'label' => esc_html__('Signup Fee', 'wp-user-avatar') . sprintf(' (%s)', ppress_get_currency_symbol()), |
| 102 | 'description' => esc_html__('Optional signup fee to charge subscribers for the first billing cycle.', 'wp-user-avatar') |
| 103 | ], |
| 104 | [ |
| 105 | 'id' => 'free_trial', |
| 106 | 'type' => 'select', |
| 107 | 'options' => SubscriptionTrialPeriod::get_all(), |
| 108 | 'label' => esc_html__('Free Trial', 'wp-user-avatar'), |
| 109 | 'description' => esc_html__('Allow members free access for a specified duration of time before charging them.', 'wp-user-avatar') |
| 110 | ] |
| 111 | ]); |
| 112 | |
| 113 | $file_downloads_setting_url = add_query_arg(['view' => 'payments', 'section' => 'file-downloads'], PPRESS_SETTINGS_SETTING_PAGE); |
| 114 | |
| 115 | $meta_box_settings = apply_filters('ppress_admin_membership_plan_metabox_settings', [ |
| 116 | 'digital_products' => [ |
| 117 | 'tab_title' => esc_html__('Digital Products', 'wp-user-avatar'), |
| 118 | [ |
| 119 | 'id' => 'df', |
| 120 | 'type' => 'digital_files', |
| 121 | 'label' => esc_html__('Product Files', 'wp-user-avatar'), |
| 122 | 'description' => esc_html__('Upload eBooks, music, videos, software or anything else digital.', 'wp-user-avatar'), |
| 123 | 'priority' => 5 |
| 124 | ], |
| 125 | [ |
| 126 | 'id' => 'df_download_limit', |
| 127 | 'type' => 'number', |
| 128 | 'label' => esc_html__('Download Limit', 'wp-user-avatar'), |
| 129 | 'description' => sprintf( |
| 130 | esc_html__('Set to 0 for unlimited re-downloads. Leave blank to use %sglobal setting%s', 'wp-user-avatar'), |
| 131 | '<a target="_blank" href="' . $file_downloads_setting_url . '">', '</a>' |
| 132 | ), |
| 133 | 'priority' => 10 |
| 134 | ], |
| 135 | [ |
| 136 | 'id' => 'df_download_expiry', |
| 137 | 'type' => 'number', |
| 138 | 'label' => esc_html__('Download Expiry', 'wp-user-avatar'), |
| 139 | 'description' => sprintf( |
| 140 | esc_html__('Enter the number of days before a download link expires. Set to 0 for no expiration. Leave blank to use %sglobal setting%s.', 'wp-user-avatar'), |
| 141 | '<a target="_blank" href="' . $file_downloads_setting_url . '">', '</a>' |
| 142 | ), |
| 143 | 'priority' => 15 |
| 144 | ] |
| 145 | ] |
| 146 | ]); |
| 147 | |
| 148 | if ( ! ExtensionManager::is_premium()) { |
| 149 | $pro_features = [ |
| 150 | 'LearnDash' => [ |
| 151 | esc_html__("Sell access to LearnDash courses, and enroll users after registration to specific courses.", 'wp-user-avatar') |
| 152 | ], |
| 153 | 'Mailchimp, Brevo, MailerLite, Campaign Monitor' => [ |
| 154 | esc_html__("Subscribe members to your email marketing lists when they register and on your website, subscribe to a membership and sync profile changes.", 'wp-user-avatar') |
| 155 | ], |
| 156 | 'WooCommerce' => [ |
| 157 | esc_html__("Sell paid memberships via WooCommerce, and create members-only discounts.", 'wp-user-avatar') |
| 158 | ] |
| 159 | ]; |
| 160 | ob_start(); |
| 161 | ?> |
| 162 | <div class="ppress-pro-features-wrap"> |
| 163 | <?php foreach ($pro_features as $label => $feature): ?> |
| 164 | <div class="ppress-pro-features"> |
| 165 | <strong><?php echo esc_html($label) ?>:</strong> <?php echo esc_html(implode(', ', $feature)) ?> |
| 166 | </div> |
| 167 | <?php endforeach; ?> |
| 168 | <div> |
| 169 | <a href="https://profilepress.com/pricing/?utm_source=wp_dashboard&utm_medium=upgrade&utm_campaign=edit_plan_page_integration_metabox" target="__blank" class="button-primary"> |
| 170 | <?php esc_html_e('Get ProfilePress Premium →', 'wp-user-avatar') ?> |
| 171 | </a> |
| 172 | </div> |
| 173 | </div> |
| 174 | <?php |
| 175 | |
| 176 | $content = ob_get_clean(); |
| 177 | |
| 178 | $meta_box_settings['pro_upsell'] = [ |
| 179 | 'tab_title' => esc_html__('Pro Integrations', 'wp-user-avatar'), |
| 180 | [ |
| 181 | 'label' => esc_html__('Pro Features', 'wp-user-avatar'), |
| 182 | 'type' => 'custom', |
| 183 | 'content' => $content |
| 184 | ] |
| 185 | ]; |
| 186 | } |
| 187 | |
| 188 | add_action('add_meta_boxes', function () use ($subscription_settings, $plan_details, $plan_data, $plan_extras, $meta_box_settings) { |
| 189 | add_meta_box( |
| 190 | 'ppress-membership-plan-content', |
| 191 | esc_html__('Plan Details', 'wp-user-avatar'), |
| 192 | function () use ($plan_details, $plan_data) { |
| 193 | echo '<div class="ppress-membership-plan-details">'; |
| 194 | (new SettingsFieldsParser($plan_details, $plan_data))->build(); |
| 195 | echo '</div>'; |
| 196 | }, |
| 197 | 'ppmembershipplan' |
| 198 | ); |
| 199 | |
| 200 | add_meta_box( |
| 201 | 'ppress-subscription-plan-settings', |
| 202 | esc_html__('Subscription Settings', 'wp-user-avatar'), |
| 203 | function () use ($subscription_settings, $plan_data) { |
| 204 | echo '<div class="ppress-subscription-plan-settings">'; |
| 205 | (new SettingsFieldsParser($subscription_settings, $plan_data))->build(); |
| 206 | echo '</div>'; |
| 207 | }, |
| 208 | 'ppmembershipplan' |
| 209 | ); |
| 210 | |
| 211 | add_meta_box( |
| 212 | 'pp-form-builder-metabox', |
| 213 | esc_html__('Downloads & Integrations', 'wp-user-avatar'), |
| 214 | function () use ($meta_box_settings, $plan_extras) { |
| 215 | echo '<div class="ppress-plan-integrations">'; |
| 216 | (new PlanIntegrationsMetabox($meta_box_settings, $plan_extras))->build(); |
| 217 | echo '</div>'; |
| 218 | }, |
| 219 | 'ppmembershipplan' |
| 220 | ); |
| 221 | |
| 222 | add_meta_box( |
| 223 | 'submitdiv', |
| 224 | __('Publish', 'wp-user-avatar'), |
| 225 | function () { |
| 226 | require dirname(__FILE__) . '/plans-page-sidebar.php'; |
| 227 | }, |
| 228 | 'ppmembershipplan', |
| 229 | 'sidebar' |
| 230 | ); |
| 231 | |
| 232 | add_meta_box( |
| 233 | 'ppress-subscription-plan-summary', |
| 234 | __('Summary', 'wp-user-avatar'), |
| 235 | function () { |
| 236 | ?> |
| 237 | <div class="ppress-subscription-plan-summary-content"> |
| 238 | </div> |
| 239 | <?php |
| 240 | }, |
| 241 | 'ppmembershipplan', |
| 242 | 'sidebar' |
| 243 | ); |
| 244 | |
| 245 | if ($plan_data->exists()) { |
| 246 | add_meta_box( |
| 247 | 'ppress-subscription-plan-links', |
| 248 | __('Checkout URL', 'wp-user-avatar'), |
| 249 | function () use ($plan_data) { |
| 250 | $checkout_url = $plan_data->get_checkout_url(); |
| 251 | ?> |
| 252 | <div class="ppress-subscription-plan-payment-links"> |
| 253 | <p> |
| 254 | <input |
| 255 | type="text" |
| 256 | id="ppress-checkout-url" |
| 257 | onfocus="this.select();" |
| 258 | readonly="readonly" |
| 259 | value="<?php echo esc_url($checkout_url); ?>" |
| 260 | style="width: 100%;" |
| 261 | /> |
| 262 | </p> |
| 263 | <p style="display: flex; align-items: center; gap: 10px;"> |
| 264 | <button type="button" class="button" id="ppress-copy-url-btn"> |
| 265 | <?php esc_html_e('Copy URL', 'wp-user-avatar'); ?> |
| 266 | </button> |
| 267 | <span id="ppress-copy-msg" style="color: green; display: none;"></span> |
| 268 | </p> |
| 269 | </div> |
| 270 | <?php |
| 271 | }, |
| 272 | 'ppmembershipplan', |
| 273 | 'sidebar' |
| 274 | ); |
| 275 | } |
| 276 | }); |
| 277 | |
| 278 | do_action('add_meta_boxes', 'ppmembershipplan', new WP_Post(new stdClass())); |
| 279 | ?> |
| 280 | <div id="poststuff"> |
| 281 | <div id="post-body" class="metabox-holder columns-2"> |
| 282 | <div id="postbox-container-1" class="postbox-container"> |
| 283 | <?php do_meta_boxes('ppmembershipplan', 'sidebar', ''); ?> |
| 284 | </div> |
| 285 | <div id="postbox-container-2" class="postbox-container"> |
| 286 | <?php do_meta_boxes('ppmembershipplan', 'advanced', ''); ?> |
| 287 | </div> |
| 288 | </div> |
| 289 | <br class="clear"> |
| 290 | </div> |
| 291 | |
| 292 | <?php add_action('admin_footer', function () { ?> |
| 293 | <script type="text/javascript"> |
| 294 | (function ($) { |
| 295 | |
| 296 | $('#billing_frequency').on('change', function () { |
| 297 | |
| 298 | if ($(this).val() !== 'lifetime') { |
| 299 | |
| 300 | $('#field-role-signup_fee').show(); |
| 301 | $('#field-role-free_trial').show(); |
| 302 | |
| 303 | $('#field-role-subscription_length').show() |
| 304 | .find('.ppress-plan-control').trigger('change'); |
| 305 | } else { |
| 306 | $('#field-role-subscription_length').hide(); |
| 307 | $('#field-role-total_payments').hide(); |
| 308 | $('#field-role-signup_fee').hide(); |
| 309 | $('#field-role-free_trial').hide(); |
| 310 | } |
| 311 | }); |
| 312 | |
| 313 | $('#subscription_length').on('change', function () { |
| 314 | $('#field-role-total_payments').toggle($(this).val() === 'fixed'); |
| 315 | }); |
| 316 | |
| 317 | $('#billing_frequency').trigger('change'); |
| 318 | |
| 319 | $(window).on('load', function () { |
| 320 | var tmpl = wp.template('ppress-plan-summary'); |
| 321 | |
| 322 | $('.ppress-plan-control').on('change', function () { |
| 323 | $('#ppress-subscription-plan-summary .ppress-subscription-plan-summary-content').html( |
| 324 | tmpl({ |
| 325 | 'price': $('.form-field #price').val(), |
| 326 | 'billing_frequency': $('.form-field #billing_frequency').val(), |
| 327 | 'total_payments': $('.form-field #total_payments').val(), |
| 328 | 'signup_fee': $('.form-field #signup_fee').val(), |
| 329 | 'subscription_length': $('.form-field #subscription_length').val(), |
| 330 | 'free_trial': $('.form-field #free_trial').val(), |
| 331 | 'subscription_expiration_type': $('.form-field #subscription_expiration').val(), |
| 332 | 'subscription_expiration_value': $('.form-field #plan-expire-value').val(), |
| 333 | 'subscription_expiration_unit': $('.form-field #plan-expire-unit').val(), |
| 334 | 'subscription_expiration_date': $('.form-field #subscription_expiration_date').val(), |
| 335 | }) |
| 336 | ); |
| 337 | }).trigger('change'); |
| 338 | |
| 339 | }); |
| 340 | |
| 341 | $('#ppress-copy-url-btn').on('click', function () { |
| 342 | |
| 343 | var input = $('#ppress-checkout-url')[0]; |
| 344 | var msg = $('#ppress-copy-msg'); |
| 345 | |
| 346 | input.select(); |
| 347 | input.setSelectionRange(0, 99999); // For mobile |
| 348 | |
| 349 | document.execCommand('copy'); |
| 350 | msg.text('<?php esc_html_e("Copied!", "wp-user-avatar"); ?>') |
| 351 | .css('color', 'green') |
| 352 | .show() |
| 353 | .fadeOut(3000); |
| 354 | }); |
| 355 | |
| 356 | })(jQuery); |
| 357 | </script> |
| 358 | <?php |
| 359 | }); |