diff --git a/assets/js/admin/admin-pointers.js b/assets/js/admin/admin-pointers.js deleted file mode 100644 index d32fd3d..0000000 --- a/assets/js/admin/admin-pointers.js +++ /dev/null @@ -1,57 +0,0 @@ -jQuery(document).ready(function($){ - - if(arePointersEnabled()){ - setTimeout(showSubscriptionPointers, 800); // give TinyMCE a chance to finish loading - } - - $('select#product-type').change(function(){ - if(arePointersEnabled()){ - $('#product-type').pointer('close'); - } - }); - - $('#_subscription_price, #_subscription_period, #_subscription_length').change(function(){ - if(arePointersEnabled()){ - $('.options_group.subscription_pricing').pointer('close'); - $('#product-type').pointer('close'); - } - }); - - function arePointersEnabled(){ - if($.getParameterByName('subscription_pointers')=='true'){ - return true; - } else { - return false; - } - } - - function showSubscriptionPointers(){ - $('#product-type').pointer({ - content: WCSPointers.typePointerContent, - position: { - edge: 'left', - align: 'center' - }, - close: function() { - if ($('select#product-type').val()==WCSubscriptions.productType){ - $('.options_group.subscription_pricing:not(".subscription_sync")').pointer({ - content: WCSPointers.pricePointerContent, - position: 'bottom', - close: function() { - dismissSubscriptionPointer(); - } - }).pointer('open'); - } - dismissSubscriptionPointer(); - } - }).pointer('open'); - } - - function dismissSubscriptionPointer(){ - $.post( ajaxurl, { - pointer: 'wcs_pointer', - action: 'dismiss-wp-pointer' - }); - } - -}); \ No newline at end of file diff --git a/assets/js/admin/admin.js b/assets/js/admin/admin.js deleted file mode 100644 index 0de3752..0000000 --- a/assets/js/admin/admin.js +++ /dev/null @@ -1,831 +0,0 @@ -jQuery(document).ready(function($){ - - $.extend({ - getParameterByName: function(name) { - name = name.replace(/[\[]/, '\\\[').replace(/[\]]/, '\\\]'); - var regexS = '[\\?&]' + name + '=([^]*)'; - var regex = new RegExp(regexS); - var results = regex.exec(window.location.search); - if(results == null) { - return ''; - } else { - return decodeURIComponent(results[1].replace(/\+/g, ' ')); - } - }, - daysInMonth: function( month ) { - // Intentionally choose a non-leap year because we want february to have only 28 days. - return new Date(Date.UTC(2001, month, 0)).getUTCDate(); - }, - showHideSubscriptionMeta: function(){ - if ($('select#product-type').val()==WCSubscriptions.productType) { - $('.show_if_simple').show(); - $('.grouping_options').hide(); - $('.options_group.pricing ._regular_price_field').hide(); - $('#sale-price-period').show(); - $('.hide_if_subscription').hide(); - $( 'input#_manage_stock' ).change(); - - if('day' == $('#_subscription_period').val()) { - $('.subscription_sync').hide(); - } - } else { - $('.options_group.pricing ._regular_price_field').show(); - $('#sale-price-period').hide(); - } - }, - showHideVariableSubscriptionMeta: function(){ - // In order for WooCommerce not to show the stock_status_field on variable subscriptions, make sure it has the hide if variable subscription class. - $( 'p.stock_status_field' ).addClass( 'hide_if_variable-subscription' ); - - if ($('select#product-type').val()=='variable-subscription') { - - $( 'input#_downloadable' ).prop( 'checked', false ); - $( 'input#_virtual' ).removeAttr( 'checked' ); - - $('.show_if_variable').show(); - $('.hide_if_variable').hide(); - $('.show_if_variable-subscription').show(); - $('.hide_if_variable-subscription').hide(); - $.showOrHideStockFields(); - - // Make the sale price row full width - $('.sale_price_dates_fields').prev('.form-row').addClass('form-row-full').removeClass('form-row-last'); - - } else { - - if ( 'variable' === $('select#product-type').val() ) { - $( '.show_if_variable-subscription' ).hide(); - $( '.show_if_variable' ).show(); - $( '.hide_if_variable' ).hide(); - $.showOrHideStockFields(); - } - - // Restore the sale price row width to half - $('.sale_price_dates_fields').prev('.form-row').removeClass('form-row-full').addClass('form-row-last'); - } - }, - showOrHideStockFields : function(){ - if ( $( 'input#_manage_stock' ).is( ':checked' ) ) { - $( 'div.stock_fields' ).show(); - } else { - $( 'div.stock_fields' ).hide(); - } - }, - setSubscriptionLengths: function(){ - $('[name^="_subscription_length"], [name^="variable_subscription_length"]').each(function(){ - var $lengthElement = $(this), - selectedLength = $lengthElement.val(), - hasSelectedLength = false, - matches = $lengthElement.attr('name').match(/\[(.*?)\]/), - periodSelector, - interval; - - if (matches) { // Variation - periodSelector = '[name="variable_subscription_period['+matches[1]+']"]'; - billingInterval = parseInt($('[name="variable_subscription_period_interval['+matches[1]+']"]').val()); - } else { - periodSelector = '#_subscription_period'; - billingInterval = parseInt($('#_subscription_period_interval').val()); - } - - $lengthElement.empty(); - - $.each(WCSubscriptions.subscriptionLengths[ $(periodSelector).val() ], function(length,description) { - if(parseInt(length) == 0 || 0 == (parseInt(length) % billingInterval)) { - $lengthElement.append($('').attr('value',length).text(description)); - } - }); - - $lengthElement.children('option').each(function(){ - if (this.value == selectedLength) { - hasSelectedLength = true; - return false; - } - }); - - if(hasSelectedLength){ - $lengthElement.val(selectedLength); - } else { - $lengthElement.val(0); - } - - }); - }, - setTrialPeriods: function(){ - $('[name^="_subscription_trial_length"], [name^="variable_subscription_trial_length"]').each(function(){ - var $trialLengthElement = $(this), - trialLength = $trialLengthElement.val(), - matches = $trialLengthElement.attr('name').match(/\[(.*?)\]/), - periodStrings; - - if (matches) { // Variation - $trialPeriodElement = $('[name="variable_subscription_trial_period['+matches[1]+']"]'); - } else { - $trialPeriodElement = $('#_subscription_trial_period'); - } - - selectedTrialPeriod = $trialPeriodElement.val(); - - $trialPeriodElement.empty(); - - if( parseInt(trialLength) == 1 ) { - periodStrings = WCSubscriptions.trialPeriodSingular; - } else { - periodStrings = WCSubscriptions.trialPeriodPlurals; - } - - $.each(periodStrings, function(key,description) { - $trialPeriodElement.append($('').attr('value',key).text(description)); - }); - - $trialPeriodElement.val(selectedTrialPeriod); - }); - }, - setSalePeriod: function(){ - $('#sale-price-period').fadeOut(80,function(){ - $('#sale-price-period').text($('#_subscription_period_interval option:selected').text()+' '+$('#_subscription_period option:selected').text()); - $('#sale-price-period').fadeIn(180); - }); - }, - setSyncOptions: function(periodField) { - - if ( typeof periodField != 'undefined' ) { - - if ($('select#product-type').val()=='variable-subscription') { - var $container = periodField.closest('.woocommerce_variable_attributes').find('.variable_subscription_sync'); - } else { - $container = periodField.closest('#general_product_data').find('.subscription_sync'); - } - - var $syncWeekMonthContainer = $container.find('.subscription_sync_week_month'), - $syncWeekMonthSelect = $syncWeekMonthContainer.find('select'), - $syncAnnualContainer = $container.find('.subscription_sync_annual'), - $varSubField = $container.find('[name^="variable_subscription_payment_sync_date"]'), - billingPeriod; - - if ($varSubField.length > 0) { // Variation - var matches = $varSubField.attr('name').match(/\[(.*?)\]/); - $subscriptionPeriodElement = $('[name="variable_subscription_period['+matches[1]+']"]'); - } else { - $subscriptionPeriodElement = $('#_subscription_period'); - } - - billingPeriod = $subscriptionPeriodElement.val(); - - if('day'==billingPeriod) { - $syncWeekMonthSelect.val(0); - $syncAnnualContainer.find('input[type="number"]').val(0).trigger('change'); - } else { - if('year'==billingPeriod) { - // Make sure the year sync fields are reset - $syncAnnualContainer.find('input[type="number"]').val(0).trigger('change'); - // And the week/month field has no option selected - $syncWeekMonthSelect.val(0); - } else { - // Make sure the year sync value is 0 - $syncAnnualContainer.find('input[type="number"]').val(0).trigger('change'); - - // And the week/month field has the appropriate options - $syncWeekMonthSelect.empty(); - $.each(WCSubscriptions.syncOptions[billingPeriod], function(key,description) { - $syncWeekMonthSelect.append($('').attr('value',key).text(description)); - }); - } - } - } - }, - showHideSyncOptions: function(){ - if($('#_subscription_payment_sync_date').length > 0 || $('.wc_input_subscription_payment_sync').length > 0){ - $('.subscription_sync, .variable_subscription_sync').each(function(){ // loop through all sync field groups - var $syncWeekMonthContainer = $(this).find('.subscription_sync_week_month'), - $syncWeekMonthSelect = $syncWeekMonthContainer.find('select'), - $syncAnnualContainer = $(this).find('.subscription_sync_annual'), - $varSubField = $(this).find('[name^="variable_subscription_payment_sync_date"]'), - $slideSwitch = false, // stop the general sync field group sliding down if editing a variable subscription - billingPeriod; - - if ($varSubField.length > 0) { // Variation - var matches = $varSubField.attr('name').match(/\[(.*?)\]/); - $subscriptionPeriodElement = $('[name="variable_subscription_period['+matches[1]+']"]'); - - if ($('select#product-type').val()=='variable-subscription') { - $slideSwitch = true; - } - } else { - $subscriptionPeriodElement = $('#_subscription_period'); - if ($('select#product-type').val()==WCSubscriptions.productType) { - $slideSwitch = true; - } - } - - billingPeriod = $subscriptionPeriodElement.val(); - - if('day'==billingPeriod) { - $(this).slideUp(400); - } else { - if ( $slideSwitch ) { - $(this).slideDown(400); - if('year'==billingPeriod) { - // Make sure the year sync fields are visible - $syncAnnualContainer.slideDown(400); - // And the week/month field is hidden - $syncWeekMonthContainer.slideUp(400); - } else { - // Make sure the year sync fields are hidden - $syncAnnualContainer.slideUp(400); - // And the week/month field is visible - $syncWeekMonthContainer.slideDown(400); - } - } - } - }); - } - }, - moveSubscriptionVariationFields: function(){ - $('#variable_product_options .variable_subscription_pricing').not('wcs_moved').each(function(){ - var $regularPriceRow = $(this).siblings('.variable_pricing'), - $trialSignUpRow = $(this).siblings('.variable_subscription_trial_sign_up'), - $saleDatesRow; - - $saleDatesRow = $(this).siblings('.variable_pricing'); - - // Add the subscription price fields above the standard price fields - $(this).insertBefore($regularPriceRow); - - $trialSignUpRow.insertBefore($(this)); - - // Replace the regular price field with the trial period field - $regularPriceRow.children(':first').addClass('hide_if_variable-subscription'); - - $(this).addClass('wcs_moved'); - }); - }, - getVariationBulkEditValue: function(variation_action){ - var value; - - switch( variation_action ) { - case 'variable_subscription_period': - case 'variable_subscription_trial_period': - value = prompt( WCSubscriptions.bulkEditPeriodMessage ); - break; - case 'variable_subscription_period_interval': - value = prompt( WCSubscriptions.bulkEditIntervalhMessage ); - break; - case 'variable_subscription_trial_length': - case 'variable_subscription_length': - value = prompt( WCSubscriptions.bulkEditLengthMessage ); - break; - case 'variable_subscription_sign_up_fee': - value = prompt( woocommerce_admin_meta_boxes_variations.i18n_enter_a_value ); - value = accounting.unformat( value, woocommerce_admin.mon_decimal_point ); - break; - } - - return value; - }, - disableEnableOneTimeShipping: function() { - var is_synced_or_has_trial = false; - - if ( 'variable-subscription' == $( 'select#product-type' ).val() ) { - var variations = $( '.woocommerce_variations .woocommerce_variation' ), - variations_checked = {}, - number_of_pages = $( '.woocommerce_variations' ).attr( 'data-total_pages' ); - - $(variations).each(function() { - var period_field = $( this ).find( '.wc_input_subscription_period' ), - variation_index = $( period_field ).attr( 'name' ).match(/\[(.*?)\]/), - variation_id = $( '[name="variable_post_id['+variation_index[1]+']"]' ).val(), - period = period_field.val(), - trial = $( this ).find( '.wc_input_subscription_trial_length' ).val(), - sync_date = 0; - - if ( 0 != trial ) { - is_synced_or_has_trial = true; - - // break - return false; - } - - if ( $( this ).find( '.variable_subscription_sync' ).length ) { - if ( 'month' == period || 'week' == period ) { - sync_date = $( '[name="variable_subscription_payment_sync_date['+variation_index[1]+']"]' ).val(); - } else if ( 'year' == period ) { - sync_date = $( '[name="variable_subscription_payment_sync_date_day['+variation_index[1]+']"]' ).val(); - } - - if ( 0 != sync_date ) { - is_synced_or_has_trial = true; - - // break - return false; - } - } - - variations_checked[ variation_index[1] ] = variation_id; - }); - - // if we haven't found a variation synced or with a trial at this point check the backend for other product variations - if ( ( number_of_pages > 1 || 0 == variations.length ) && false == is_synced_or_has_trial ) { - - var data = { - action: 'wcs_product_has_trial_or_is_synced', - product_id: woocommerce_admin_meta_boxes_variations.post_id, - variations_checked: variations_checked, - nonce: WCSubscriptions.oneTimeShippingCheckNonce, - }; - - $.ajax({ - url: WCSubscriptions.ajaxUrl, - data: data, - type: 'POST', - success : function( response ) { - $( '#_subscription_one_time_shipping' ).prop( 'disabled', response.is_synced_or_has_trial ); - // trigger an event now we have determined the one time shipping availability, in case we need to update the backend - $( '#_subscription_one_time_shipping' ).trigger( 'subscription_one_time_shipping_updated', [ response.is_synced_or_has_trial ] ); - } - }); - } else { - // trigger an event now we have determined the one time shipping availability, in case we need to update the backend - $( '#_subscription_one_time_shipping' ).trigger( 'subscription_one_time_shipping_updated', [ is_synced_or_has_trial ] ); - } - } else { - var trial = $( '#general_product_data #_subscription_trial_length' ).val(); - - if ( 0 != trial ) { - is_synced_or_has_trial = true; - } - - if ( $( '.subscription_sync' ).length && false == is_synced_or_has_trial ) { - var period = $( '#_subscription_period' ).val(), - sync_date = 0; - - if ( 'month' == period || 'week' == period ) { - sync_date = $( '#_subscription_payment_sync_date' ).val(); - } else if ( 'year' == period ) { - sync_date = $( '#_subscription_payment_sync_date_day' ).val(); - } - - if ( 0 != sync_date ) { - is_synced_or_has_trial = true; - } - } - } - - $( '#_subscription_one_time_shipping' ).prop( 'disabled', is_synced_or_has_trial ); - }, - showHideSubscriptionsPanels: function() { - var tab = $( 'div.panel-wrap' ).find( 'ul.wc-tabs li' ).eq( 0 ).find( 'a' ); - var panel = tab.attr( 'href' ); - var visible = $( panel ).children( '.options_group' ).filter( function() { - return 'none' != $( this ).css( 'display' ); - }); - if ( 0 != visible.length ) { - tab.click().parent().show(); - } - }, - maybeDisableRemoveLinks: function() { - $( '#variable_product_options .woocommerce_variation' ).each( function() { - var $removeLink = $( this ).find( '.remove_variation' ); - var can_remove_variation = ( '1' === $( this ).find( 'input.wcs-can-remove-variation').val() ); - var $msg = $( this ).find( '.wcs-can-not-remove-variation-msg' ); - - if ( ! can_remove_variation ) { - $msg.text( $removeLink.text() ); - $removeLink.replaceWith( $msg ); - } - } ); - }, - }); - - $('.options_group.pricing ._sale_price_field .description').prepend(''); - - // Move the subscription pricing section to the same location as the normal pricing section - $('.options_group.subscription_pricing').not('.variable_subscription_pricing .options_group.subscription_pricing').insertBefore($('.options_group.pricing:first')); - $('.show_if_subscription.clear').insertAfter($('.options_group.subscription_pricing')); - - // Move the subscription variation pricing section to a better location in the DOM on load - if($('#variable_product_options .variable_subscription_pricing').length > 0) { - $.moveSubscriptionVariationFields(); - } - // When a variation is added - $('#woocommerce-product-data').on('woocommerce_variations_added woocommerce_variations_loaded',function(){ - $.moveSubscriptionVariationFields(); - $.showHideVariableSubscriptionMeta(); - $.showHideSyncOptions(); - $.setSubscriptionLengths(); - }); - - if($('.options_group.pricing').length > 0) { - $.setSalePeriod(); - $.showHideSubscriptionMeta(); - $.showHideVariableSubscriptionMeta(); - $.setSubscriptionLengths(); - $.setTrialPeriods(); - $.showHideSyncOptions(); - $.disableEnableOneTimeShipping(); - $.showHideSubscriptionsPanels(); - } - - // Update subscription ranges when subscription period or interval is changed - $('#woocommerce-product-data').on('change','[name^="_subscription_period"], [name^="_subscription_period_interval"], [name^="variable_subscription_period"], [name^="variable_subscription_period_interval"]',function(){ - $.setSubscriptionLengths(); - $.showHideSyncOptions(); - $.setSyncOptions( $(this) ); - $.setSalePeriod(); - $.disableEnableOneTimeShipping(); - }); - - $('#woocommerce-product-data').on('propertychange keyup input paste change','[name^="_subscription_trial_length"], [name^="variable_subscription_trial_length"]',function(){ - $.setTrialPeriods(); - }); - - // Handles changes to sync date select/input for yearly subscription products. - $('#woocommerce-product-data').on('change', '[name^="_subscription_payment_sync_date_day"], [name^="variable_subscription_payment_sync_date_day"]', function() { - if ( 0 == $(this).val() ) { - $(this).siblings('[name^="_subscription_payment_sync_date_month"], [name^="variable_subscription_payment_sync_date_month"]').val(0); - $(this).prop('disabled', true); - } - }).on('change', '[name^="_subscription_payment_sync_date_month"], [name^="variable_subscription_payment_sync_date_month"]', function() { - var $syncDayOfMonthInput = $(this).siblings('[name^="_subscription_payment_sync_date_day"], [name^="variable_subscription_payment_sync_date_day"]'); - - if ( 0 < $(this).val() ) { - $syncDayOfMonthInput.val(1).attr({step: "1", min: "1", max: $.daysInMonth($(this).val())}).prop('disabled', false); - } else { - $syncDayOfMonthInput.val(0).trigger('change'); - } - }); - - $('body').bind('woocommerce-product-type-change',function(){ - $.showHideSubscriptionMeta(); - $.showHideVariableSubscriptionMeta(); - $.showHideSyncOptions(); - $.showHideSubscriptionsPanels(); - }); - - $('input#_downloadable, input#_virtual').change(function(){ - $.showHideSubscriptionMeta(); - $.showHideVariableSubscriptionMeta(); - }); - - // Make sure the "Used for variations" checkbox is visible when adding attributes to a variable subscription - $('body').on('woocommerce_added_attribute', function(){ - $.showHideVariableSubscriptionMeta(); - }); - - if($.getParameterByName('select_subscription')=='true'){ - $('select#product-type option[value="'+WCSubscriptions.productType+'"]').attr('selected', 'selected'); - $('select#product-type').select().change(); - } - - // Before saving a subscription product, validate the trial period - $('#post').submit(function(e){ - if ( WCSubscriptions.subscriptionLengths !== undefined ){ - var trialLength = $('#_subscription_trial_length').val(), - selectedTrialPeriod = $('#_subscription_trial_period').val(); - - if ( parseInt(trialLength) >= WCSubscriptions.subscriptionLengths[selectedTrialPeriod].length ) { - alert(WCSubscriptions.trialTooLongMessages[selectedTrialPeriod]); - $('#ajax-loading').hide(); - $('#publish').removeClass('button-primary-disabled'); - e.preventDefault(); - } - } - }); - - // Notify store manager that deleting an order via the Orders screen also deletes subscriptions associated with the orders - $('#posts-filter').submit(function(){ - if($('[name="post_type"]').val()=='shop_order'&&($('[name="action"]').val()=='trash'||$('[name="action2"]').val()=='trash')){ - var containsSubscription = false; - $('[name="post[]"]:checked').each(function(){ - if(true===$('.contains_subscription',$('#post-'+$(this).val())).data('contains_subscription')){ - containsSubscription = true; - } - return (false === containsSubscription); - }); - if(containsSubscription){ - return confirm(WCSubscriptions.bulkTrashWarning); - } - } - }); - - $('.order_actions .submitdelete').click(function(){ - if($('[name="contains_subscription"]').val()=='true'){ - return confirm(WCSubscriptions.trashWarning); - } - }); - - $( '#variable_product_options' ).on( 'click', '.delete.wcs-can-not-remove-variation-msg', function( e ) { - e.preventDefault(); - e.stopPropagation(); - } ); - - // Notify the store manager that trashing an order via the admin orders table row action also deletes the associated subscription if it exists - $( '.row-actions .submitdelete' ).click( function() { - var order = $( this ).closest( '.type-shop_order' ).attr( 'id' ); - - if ( true === $( '.contains_subscription', $( '#' + order ) ).data( 'contains_subscription' ) ) { - return confirm( WCSubscriptions.trashWarning ); - } - }); - - // Editing a variable product - $('#variable_product_options').on('change','[name^="variable_regular_price"]',function(){ - var matches = $(this).attr('name').match(/\[(.*?)\]/); - - if (matches) { - var loopIndex = matches[1]; - $('[name="variable_subscription_price['+loopIndex+']"]').val($(this).val()); - } - }); - - // Editing a variable product - $('#variable_product_options').on('change','[name^="variable_subscription_price"]',function(){ - var matches = $(this).attr('name').match(/\[(.*?)\]/); - - if (matches) { - var loopIndex = matches[1]; - $('[name="variable_regular_price['+loopIndex+']"]').val($(this).val()); - } - }); - - // Update hidden regular price when subscription price is update on simple products - $('#general_product_data').on('change', '[name^="_subscription_price"]', function() { - $('[name="_regular_price"]').val($(this).val()); - }); - - // Notify store manager that deleting an user via the Users screen also removed them from any subscriptions. - $('.users-php .submitdelete').on('click',function(){ - return confirm(WCSubscriptions.deleteUserWarning); - }); - - // WC 2.4+ variation bulk edit handling - $('select.variation_actions').on('variable_subscription_sign_up_fee_ajax_data variable_subscription_period_interval_ajax_data variable_subscription_period_ajax_data variable_subscription_trial_period_ajax_data variable_subscription_trial_length_ajax_data variable_subscription_length_ajax_data', function(event, data) { - bulk_action = event.type.replace(/_ajax_data/g,''); - value = $.getVariationBulkEditValue( bulk_action ); - - if ( 'variable_subscription_trial_length' == bulk_action ) { - // After variations have their trial length bulk updated in the backend, flag the One Time Shipping field as needing to be updated - $( '#_subscription_one_time_shipping' ).addClass( 'wcs_ots_needs_update' ); - } - - if ( value != null ) { - data.value = value; - } - return data; - }); - - var $allowSwitching = $( document.getElementById( 'woocommerce_subscriptions_allow_switching' ) ), - $syncRenewals = $( document.getElementById( 'woocommerce_subscriptions_sync_payments' ) ); - - // We're on the Subscriptions settings page - if ( $allowSwitching.length > 0 ) { - var allowSwitchingEnabled = $allowSwitching.find( 'input:checked' ).length, - $switchSettingsRows = $allowSwitching.parents( 'tr' ).siblings( 'tr' ), - $prorateFirstRenewal = $( document.getElementById( 'woocommerce_subscriptions_prorate_synced_payments' ) ), - $syncRows = $syncRenewals.parents( 'tr' ).siblings( 'tr' ), - $daysNoFeeRow = $( document.getElementById( 'woocommerce_subscriptions_days_no_fee' ) ).parents( 'tr' ), - $suspensionExtensionRow = $( '#woocommerce_subscriptions_recoup_suspension' ).parents( 'tr' ); - - // No animation for initial hiding when switching is disabled. - if ( 0 === allowSwitchingEnabled ) { - $switchSettingsRows.hide(); - } - - $allowSwitching.find( 'input' ).on( 'change', function() { - - var isEnabled = $allowSwitching.find( 'input:checked' ).length; - - if ( 0 === isEnabled ) { - $switchSettingsRows.fadeOut(); - } else if ( 0 === allowSwitchingEnabled ) { // switching was previously disabled, so settings will be hidden - $switchSettingsRows.fadeIn(); - } - allowSwitchingEnabled = isEnabled; - } ); - - // Show/hide suspension extension setting - $( '#woocommerce_subscriptions_max_customer_suspensions' ).on( 'change', function() { - if ( $( this ).val() > 0 ) { - $suspensionExtensionRow.show(); - } else { - $suspensionExtensionRow.hide(); - } - } ).change(); - - // No animation when initially hiding prorated rows. - if ( ! $syncRenewals.is( ':checked' ) ) { - $syncRows.hide(); - } else if ( 'recurring' !== $prorateFirstRenewal.val() ) { - $daysNoFeeRow.hide(); - } - - // Animate showing and hiding the synchronization rows. - $syncRenewals.on( 'change', function(){ - if ( $( this ).is( ':checked' ) ) { - $syncRows.not( $daysNoFeeRow ).fadeIn(); - $prorateFirstRenewal.change(); - } else { - $syncRows.fadeOut(); - } - } ); - - // Watch the Prorate First Renewal field for changes. - $prorateFirstRenewal.on( 'change', function() { - if ( 'recurring' === $( this ).val() ) { - $daysNoFeeRow.fadeIn(); - } else { - $daysNoFeeRow.fadeOut(); - } - } ); - } - - // Don't display the variation notice for variable subscription products - $( 'body' ).on( 'woocommerce-display-product-type-alert', function(e, select_val) { - if (select_val=='variable-subscription') { - return false; - } - }); - - $('.wcs_payment_method_selector').on('change', function() { - - var payment_method = $(this).val(); - - $('.wcs_payment_method_meta_fields').hide(); - $('#wcs_' + payment_method + '_fields').show(); - }); - - // After variations have been saved/updated in the backend, flag the One Time Shipping field as needing to be updated - $( '#woocommerce-product-data' ).on( 'woocommerce_variations_saved', function() { - $( '#_subscription_one_time_shipping' ).addClass( 'wcs_ots_needs_update' ); - }); - - // After variations have been loaded and if the One Time Shipping field needs updating, check if One Time Shipping is still available - $( '#woocommerce-product-data' ).on( 'woocommerce_variations_loaded', function() { - if ( $( '.wcs_ots_needs_update' ).length ) { - $.disableEnableOneTimeShipping(); - } - }); - - // After variations have been loaded, check which ones are tied to subscriptions to prevent them from being deleted. - $( '#woocommerce-product-data' ).on( 'woocommerce_variations_loaded', function() { - $.maybeDisableRemoveLinks(); - } ); - - // Triggered by $.disableEnableOneTimeShipping() after One Time shipping has been enabled or disabled for variations. - // If the One Time Shipping field needs updating, send the ajax request to update the product setting in the backend - $( '#_subscription_one_time_shipping' ).on( 'subscription_one_time_shipping_updated', function( event, is_synced_or_has_trial ) { - - if ( $( '.wcs_ots_needs_update' ).length ) { - var data = { - action: 'wcs_update_one_time_shipping', - product_id: woocommerce_admin_meta_boxes_variations.post_id, - one_time_shipping_enabled: ! is_synced_or_has_trial, - one_time_shipping_selected: $( '#_subscription_one_time_shipping' ).prop( 'checked' ), - nonce: WCSubscriptions.oneTimeShippingCheckNonce, - }; - - $.ajax({ - url: WCSubscriptions.ajaxUrl, - data: data, - type: 'POST', - success : function( response ) { - // remove the flag requiring the one time shipping field to be updated - $( '#_subscription_one_time_shipping' ).removeClass( 'wcs_ots_needs_update' ); - $( '#_subscription_one_time_shipping' ).prop( 'checked', response.one_time_shipping == 'yes' ? true : false ); - } - }); - } - }); - - $( '#general_product_data, #variable_product_options' ).on( 'change', '[class^="wc_input_subscription_payment_sync"], [class^="wc_input_subscription_trial_length"]', function() { - $.disableEnableOneTimeShipping(); - }); - - /** - * Prevents removal of variations in use by a subscription. - */ - var wcs_prevent_variation_removal = { - init: function() { - if ( 0 === $( '#woocommerce-product-data' ).length ) { - return; - } - - $( 'body' ).on( 'woocommerce-product-type-change', this.product_type_change ); - $( '#variable_product_options' ).on( 'reload', this.product_type_change ); - $( 'select.variation_actions' ).on( 'delete_all_no_subscriptions_ajax_data', this.bulk_action_data ); - this.product_type_change(); - }, - - product_type_change: function() { - var product_type = $( '#product-type' ).val(); - var $variation_actions = $( 'select.variation_actions' ); - var $delete_all = $variation_actions.find( 'option[value="delete_all"], option[value="delete_all_no_subscriptions"]' ); - - if ( 'variable-subscription' === product_type && 'delete_all' === $delete_all.val() ) { - $delete_all.data( 'wcs_original_wc_label', $delete_all.text() ) - .attr( 'value', 'delete_all_no_subscriptions' ) - .text( WCSubscriptions.bulkDeleteOptionLabel ); - } else if ( 'variable-subscription' !== product_type && 'delete_all_no_subscriptions' === $delete_all.val() ) { - $delete_all.text( $delete_all.data( 'wcs_original_wc_label' ) ) - .attr( 'value', 'delete_all' ); - } - }, - - bulk_action_data: function( event, data ) { - if ( window.confirm( woocommerce_admin_meta_boxes_variations.i18n_delete_all_variations ) ) { - if ( window.confirm( woocommerce_admin_meta_boxes_variations.i18n_last_warning ) ) { - data.allowed = true; - - // do_variation_action() in woocommerce/assets/js/admin/meta-boxes-product-variation.js doesn't - // allow us to do anything after the AJAX request, so we need to listen to all AJAX requests for a - // little while to update the quantity and refresh the variation list. - $( document ).bind( 'ajaxComplete', wcs_prevent_variation_removal.update_qty_after_removal ); - } - } - - return data; - }, - - update_qty_after_removal: function( event, jqXHR, ajaxOptions ) { - var $variations = $( '#variable_product_options .woocommerce_variations' ); - var removed; - - // Not our bulk edit request. Ignore. - if ( -1 === ajaxOptions.data.indexOf( 'action=woocommerce_bulk_edit_variations' ) || -1 === ajaxOptions.data.indexOf( 'bulk_action=delete_all_no_subscriptions' ) ) { - return; - } - - // Unbind so this doesn't get called every time an AJAX request is performed. - $( document ).unbind( 'ajaxComplete', wcs_prevent_variation_removal.update_qty_after_removal ); - - // Update variation quantity. - removed = ( 'OK' === jqXHR.statusText ) ? parseInt( jqXHR.responseText, 10 ) : 0; - $variations.attr( 'data-total', Math.max( 0, parseInt( $variations.attr( 'data-total' ), 10 ) - removed ) ); - $( '#variable_product_options' ).trigger( 'reload' ); - }, - }; - wcs_prevent_variation_removal.init(); - - /* - * Prevents changing of the product type for subscription products in use by a subscription. - */ - var wcs_prevent_product_type_change = { - init: function() { - if ( 'yes' !== WCSubscriptions.productHasSubscriptions ) { - return; - } - - var $select = $( 'select#product-type' ); - var $options = $select.find( 'option' ); - var $selection = $options.filter( 'option:selected' ); - - if ( 'subscription' !== $selection.val() && 'variable-subscription' !== $selection.val() ) { - return; - } - - $options.not( $selection ).prop( 'disabled', true ); - $select.addClass( 'tips' ).attr( 'data-tip', WCSubscriptions.productTypeWarning ); - }, - }; - wcs_prevent_product_type_change.init(); - - /* - * Handles enabling and disabling PayPal Standard for Subscriptions. - */ - var wcs_paypal_standard_settings = { - - init: function() { - if ( 0 === $( '#woocommerce_paypal_enabled' ).length ) { - return; - } - - $( '#woocommerce_paypal_enabled' ).on( 'change', this.paypal_enabled_change ); - $( '#woocommerce_paypal_enabled_for_subscriptions' ).on( 'change', this.paypal_for_subscriptions_enabled ); - this.paypal_enabled_change(); - }, - - /** - * Show and hide the enable PayPal for Subscriptions checkbox when PayPal is enabled or disabled. - */ - paypal_enabled_change: function() { - var $enabled_for_subscriptions_element = $( '#woocommerce_paypal_enabled_for_subscriptions' ).closest( 'tr' ); - - if ( $( '#woocommerce_paypal_enabled' ).is( ':checked' ) ) { - $enabled_for_subscriptions_element.show(); - } else { - $enabled_for_subscriptions_element.hide(); - } - }, - - /** - * Display a confirm dialog when PayPal for Subscriptions is enabled (checked). - */ - paypal_for_subscriptions_enabled: function() { - if ( $( this ).is( ':checked' ) && ! confirm( WCSubscriptions.enablePayPalWarning ) ) { - $( this ).removeAttr( 'checked' ); - } - } - }; - wcs_paypal_standard_settings.init(); - -}); diff --git a/assets/js/admin/meta-boxes-subscription.js b/assets/js/admin/meta-boxes-subscription.js deleted file mode 100644 index 4e9d919..0000000 --- a/assets/js/admin/meta-boxes-subscription.js +++ /dev/null @@ -1,239 +0,0 @@ -jQuery(document).ready(function($){ - var timezone = jstz.determine(); - - // Display the timezone for date changes - $( '#wcs-timezone' ).text( timezone.name() ); - - // Display times in client's timezone (based on UTC) - $( '.woocommerce-subscriptions.date-picker' ).each(function(){ - var $date_input = $(this), - date_type = $date_input.attr( 'id' ), - $hour_input = $( '#'+date_type+'_hour' ), - $minute_input = $( '#'+date_type+'_minute' ), - time = $('#'+date_type+'_timestamp_utc').val(), - date = moment.unix(time); - - if ( time > 0 ) { - date.local(); - $date_input.val( date.year() + '-' + ( zeroise( date.months() + 1 ) ) + '-' + ( date.format( 'DD' ) ) ); - $hour_input.val( date.format( 'HH' ) ); - $minute_input.val( date.format( 'mm' ) ); - } - }); - - // Make sure start date picker is in the past - $( '.woocommerce-subscriptions.date-picker#start' ).datepicker( 'option','maxDate',moment().toDate()); - - // Make sure other date pickers are in the future - $( '.woocommerce-subscriptions.date-picker:not(#start)' ).datepicker( 'option','minDate',moment().add(1,'hours').toDate()); - - // Validate date when hour/minute inputs change - $( '[name$="_hour"], [name$="_minute"]' ).on( 'change', function() { - $( '#' + $(this).attr( 'name' ).replace( '_hour', '' ).replace( '_minute', '' ) ).change(); - }); - - // Validate entire date - $( '.woocommerce-subscriptions.date-picker' ).on( 'change',function(){ - - // The date was deleted, clear hour/minute inputs values and set the UTC timestamp to 0 - if( '' == $(this).val() ) { - $( '#' + $(this).attr( 'id' ) + '_hour' ).val(''); - $( '#' + $(this).attr( 'id' ) + '_minute' ).val(''); - $( '#' + $(this).attr( 'id' ) + '_timestamp_utc' ).val(0); - return; - } - - var time_now = moment(), - one_hour_from_now = moment().add(1,'hours' ), - $date_input = $(this), - date_type = $date_input.attr( 'id' ), - date_pieces = $date_input.val().split( '-' ), - $hour_input = $( '#'+date_type+'_hour' ), - $minute_input = $( '#'+date_type+'_minute' ), - chosen_hour = (0 == $hour_input.val().length) ? one_hour_from_now.format( 'HH' ) : $hour_input.val(), - chosen_minute = (0 == $minute_input.val().length) ? one_hour_from_now.format( 'mm' ) : $minute_input.val(), - chosen_date = moment({ - years: date_pieces[0], - months: (date_pieces[1] - 1), - date: (date_pieces[2]), - hours: chosen_hour, - minutes: chosen_minute, - seconds: one_hour_from_now.format( 'ss' ) - }); - - // Make sure start date is before now. - if ( 'start' == date_type ) { - - if ( false === chosen_date.isBefore( time_now ) ) { - alert( wcs_admin_meta_boxes.i18n_start_date_notice ); - $date_input.val( time_now.year() + '-' + ( zeroise( time_now.months() + 1 ) ) + '-' + ( time_now.format( 'DD' ) ) ); - $hour_input.val( time_now.format( 'HH' ) ); - $minute_input.val( time_now.format( 'mm' ) ); - } - - } - - // Make sure trial end and next payment are after start date - if ( ( 'trial_end' == date_type || 'next_payment' == date_type ) && '' != $( '#start_timestamp_utc' ).val() ) { - var change_date = false, - start = moment.unix( $('#start_timestamp_utc').val() ); - - // Make sure trial end is after start date - if ( 'trial_end' == date_type && chosen_date.isBefore( start, 'minute' ) ) { - - if ( 'trial_end' == date_type ) { - alert( wcs_admin_meta_boxes.i18n_trial_end_start_notice ); - } else if ( 'next_payment' == date_type ) { - alert( wcs_admin_meta_boxes.i18n_next_payment_start_notice ); - } - - // Change the date - $date_input.val( start.year() + '-' + ( zeroise( start.months() + 1 ) ) + '-' + ( start.format( 'DD' ) ) ); - $hour_input.val( start.format( 'HH' ) ); - $minute_input.val( start.format( 'mm' ) ); - } - } - - // Make sure next payment is after trial end - if ( 'next_payment' == date_type && '' != $( '#trial_end_timestamp_utc' ).val() ) { - var trial_end = moment.unix( $('#trial_end_timestamp_utc').val() ); - - if ( chosen_date.isBefore( trial_end, 'minute' ) ) { - alert( wcs_admin_meta_boxes.i18n_next_payment_trial_notice ); - $date_input.val( trial_end.year() + '-' + ( zeroise( trial_end.months() + 1 ) ) + '-' + ( trial_end.format( 'DD' ) ) ); - $hour_input.val( trial_end.format( 'HH' ) ); - $minute_input.val( trial_end.format( 'mm' ) ); - } - } - - // Make sure trial end is before next payment and expiration is after next payment date - else if ( ( 'trial_end' == date_type || 'end' == date_type ) && '' != $( '#next_payment' ).val() ) { - var change_date = false, - next_payment = moment.unix( $('#next_payment_timestamp_utc').val() ); - - // Make sure trial end is before or equal to next payment - if ( 'trial_end' == date_type && next_payment.isBefore( chosen_date, 'minute' ) ) { - alert( wcs_admin_meta_boxes.i18n_trial_end_next_notice ); - change_date = true; - } - // Make sure end date is after next payment date - else if ( 'end' == date_type && chosen_date.isBefore( next_payment, 'minute' ) ) { - alert( wcs_admin_meta_boxes.i18n_end_date_notice ); - change_date = true; - } - - if ( true === change_date ) { - $date_input.val( next_payment.year() + '-' + ( zeroise( next_payment.months() + 1 ) ) + '-' + ( next_payment.format( 'DD' ) ) ); - $hour_input.val( next_payment.format( 'HH' ) ); - $minute_input.val( next_payment.format( 'mm' ) ); - } - } - - // Make sure the date is more than an hour in the future - if ( 'trial_end' != date_type && 'start' != date_type && chosen_date.unix() < one_hour_from_now.unix() ) { - - alert( wcs_admin_meta_boxes.i18n_past_date_notice ); - - // Set date to current day - $date_input.val( one_hour_from_now.year() + '-' + ( zeroise( one_hour_from_now.months() + 1 ) ) + '-' + ( one_hour_from_now.format( 'DD' ) ) ); - - // Set time if current time is in the past - if ( chosen_date.hours() < one_hour_from_now.hours() || ( chosen_date.hours() == one_hour_from_now.hours() && chosen_date.minutes() < one_hour_from_now.minutes() ) ) { - $hour_input.val( one_hour_from_now.format( 'HH' ) ); - $minute_input.val( one_hour_from_now.format( 'mm' ) ); - } - } - - if( 0 == $hour_input.val().length ){ - $hour_input.val(one_hour_from_now.format( 'HH' )); - } - - if( 0 == $minute_input.val().length ){ - $minute_input.val(one_hour_from_now.format( 'mm' )); - } - - // Update the UTC timestamp sent to the server - date_pieces = $date_input.val().split( '-' ); - - $('#'+date_type+'_timestamp_utc').val(moment({ - years: date_pieces[0], - months: (date_pieces[1] - 1), - date: (date_pieces[2]), - hours: $hour_input.val(), - minutes: $minute_input.val(), - seconds: one_hour_from_now.format( 'ss' ) - }).utc().unix()); - - $( 'body' ).trigger( 'wcs-updated-date',date_type); - }); - - function zeroise( val ) { - return (val > 9 ) ? val : '0' + val; - } - - if( $( '#parent-order-id' ).is( 'select' ) ) { - wcs_update_parent_order_options(); - - $( '#customer_user' ).on( 'change', wcs_update_parent_order_options ); - } - - function wcs_update_parent_order_options() { - - // Get user ID to load orders for - var user_id = $( '#customer_user' ).val(); - - if ( ! user_id ) { - return false; - } - - var data = { - user_id: user_id, - action: 'wcs_get_customer_orders', - security: wcs_admin_meta_boxes.get_customer_orders_nonce - }; - - $( '#parent-order-id' ).siblings( '.select2-container' ).block({ - message: null, - overlayCSS: { - background: '#fff', - opacity: 0.6 - } - }); - - $.ajax({ - url: WCSubscriptions.ajaxUrl, - data: data, - type: 'POST', - success: function( response ) { - if ( response ) { - var $orderlist = $( '#parent-order-id' ); - - $( '#parent-order-id' ).select2( 'val', '' ); - - $orderlist.empty(); // remove old options - - $orderlist.append( $( '' ).attr( 'value', '' ).text( 'Select an order' ) ); - - $.each( response, function( order_id, order_number ) { - $orderlist.append( $( '' ).attr( 'value', order_id ).text( order_number ) ); - }); - - $( '#parent-order-id' ).siblings( '.select2-container' ).unblock(); - } - } - }); - return false; - }; - - $('body.post-type-shop_subscription #post').submit(function(){ - if('wcs_process_renewal' == $( "body.post-type-shop_subscription select[name='wc_order_action']" ).val()) { - return confirm(wcs_admin_meta_boxes.process_renewal_action_warning); - } - }); - - $('body.post-type-shop_subscription #post').submit(function(){ - if ( typeof wcs_admin_meta_boxes.change_payment_method_warning != 'undefined' && wcs_admin_meta_boxes.payment_method != $('#_payment_method').val() ) { - return confirm(wcs_admin_meta_boxes.change_payment_method_warning); - } - }); -}); diff --git a/assets/js/admin/reports.js b/assets/js/admin/reports.js index 418e592..5866702 100644 --- a/assets/js/admin/reports.js +++ b/assets/js/admin/reports.js @@ -1,4 +1,4 @@ -jQuery(function($) { +jQuery( function( $ ) { $.extend({ wcs_format_money: function(value,decimal_precision) { diff --git a/assets/js/admin/wcs-meta-boxes-order.js b/assets/js/admin/wcs-meta-boxes-order.js deleted file mode 100644 index c99b87b..0000000 --- a/assets/js/admin/wcs-meta-boxes-order.js +++ /dev/null @@ -1,8 +0,0 @@ -jQuery(document).ready(function($){ - - $('body.post-type-shop_order #post').submit(function(){ - if('wcs_retry_renewal_payment' == $( "body.post-type-shop_order select[name='wc_order_action']" ).val()) { - return confirm(wcs_admin_order_meta_boxes.retry_renewal_payment_action_warning); - } - }); -}); diff --git a/assets/js/wcs-upgrade.js b/assets/js/wcs-upgrade.js deleted file mode 100644 index 1ee2b8d..0000000 --- a/assets/js/wcs-upgrade.js +++ /dev/null @@ -1,206 +0,0 @@ -jQuery(document).ready(function($){ - var upgrade_start_time = null, - total_subscriptions = wcs_update_script_data.subscription_count; - - $('#update-messages').slideUp(); - $('#upgrade-step-3').slideUp(); - - $('form#subscriptions-upgrade').on('submit',function(e){ - $('#update-welcome').slideUp(600); - $('#update-messages').slideDown(600); - if('true'==wcs_update_script_data.really_old_version){ - wcs_ajax_update_really_old_version(); - } else if('true'==wcs_update_script_data.upgrade_to_1_5){ - wcs_ajax_update_products(); - wcs_ajax_update_hooks(); - } else if('true'==wcs_update_script_data.upgrade_to_2_0){ - wcs_ajax_update_subscriptions(); - } else if('true'==wcs_update_script_data.repair_2_0){ - wcs_ajax_repair_subscriptions(); - } else { - wcs_ajax_update_complete(); - } - e.preventDefault(); - }); - function wcs_ajax_update_really_old_version(){ - $.ajax({ - url: wcs_update_script_data.ajax_url, - type: 'POST', - data: { - action: 'wcs_upgrade', - upgrade_step: 'really_old_version', - nonce: wcs_update_script_data.upgrade_nonce - }, - success: function(results) { - $('#update-messages ol').append($('
').text(results.message)); - wcs_ajax_update_products(); - wcs_ajax_update_hooks(); - }, - error: function(results,status,errorThrown){ - wcs_ajax_update_error(); - } - }); - } - function wcs_ajax_update_products(){ - $.ajax({ - url: wcs_update_script_data.ajax_url, - type: 'POST', - data: { - action: 'wcs_upgrade', - upgrade_step: 'products', - nonce: wcs_update_script_data.upgrade_nonce - }, - success: function(results) { - $('#update-messages ol').append($('').text(results.message)); - }, - error: function(results,status,errorThrown){ - wcs_ajax_update_error(); - } - }); - } - function wcs_ajax_update_hooks() { - var start_time = new Date(); - $.ajax({ - url: wcs_update_script_data.ajax_url, - type: 'POST', - data: { - action: 'wcs_upgrade', - upgrade_step: 'hooks', - nonce: wcs_update_script_data.upgrade_nonce - }, - success: function(results) { - if(results.message){ - var end_time = new Date(), - execution_time = Math.ceil( ( end_time.getTime() - start_time.getTime() ) / 1000 ); - $('#update-messages ol').append($('').text(results.message.replace('{execution_time}',execution_time))); - } - if( undefined == typeof(results.upgraded_count) || parseInt(results.upgraded_count) <= ( wcs_update_script_data.hooks_per_request - 1 ) ){ - wcs_ajax_update_subscriptions(); - } else { - wcs_ajax_update_hooks(); - } - }, - error: function(results,status,errorThrown){ - wcs_ajax_update_error(); - } - }); - } - function wcs_ajax_update_subscriptions() { - var start_time = new Date(); - - if ( null === upgrade_start_time ) { - upgrade_start_time = start_time; - } - - $.ajax({ - url: wcs_update_script_data.ajax_url, - type: 'POST', - data: { - action: 'wcs_upgrade', - upgrade_step: 'subscriptions', - nonce: wcs_update_script_data.upgrade_nonce - }, - success: function(results) { - if('success'==results.status){ - var end_time = new Date(), - execution_time = Math.ceil( ( end_time.getTime() - start_time.getTime() ) / 1000 ); - - $('#update-messages ol').append($('').text(results.message.replace('{execution_time}',execution_time))); - - wcs_update_script_data.subscription_count -= results.upgraded_count; - - if( "undefined" === typeof(results.upgraded_count) || parseInt(wcs_update_script_data.subscription_count) <= 0 ) { - wcs_ajax_update_complete(); - } else { - wcs_ajax_update_estimated_time(results.time_message); - wcs_ajax_update_subscriptions(); - } - } else { - wcs_ajax_update_error(results.message); - } - }, - error: function(results,status,errorThrown){ - $('%s
', - esc_html__( 'Subscription locked to Manual Renewal while the store is in staging mode. Payment method changes will take effect in live mode.', 'woocommerce-subscriptions' ) - ); - } - } - - /** - * Returns the content for a tooltip explaining a subscription's payment method while in staging mode. - * - * @param WC_Subscription $subscription - * @return string HTML content for a tooltip. - * @since 2.6.0 - */ - public static function get_payment_method_tooltip( $subscription ) { - // translators: placeholder is a payment method title. - return ''; - } -} diff --git a/includes/class-wcs-subscriber-role-manager.php b/includes/class-wcs-subscriber-role-manager.php new file mode 100644 index 0000000..1f8c46c --- /dev/null +++ b/includes/class-wcs-subscriber-role-manager.php @@ -0,0 +1,98 @@ + $details ) { + $roles_options[ $role ] = translate_user_role( $details['name'] ); + } + + $role_settings = array( + array( + 'name' => __( 'Roles', 'woocommerce-subscriptions' ), + 'type' => 'title', + // translators: placeholders are tags + 'desc' => sprintf( __( 'Choose the default roles to assign to active and inactive subscribers. For record keeping purposes, a user account must be created for subscribers. Users with the %1$sadministrator%2$s role, such as yourself, will never be allocated these roles to prevent locking out administrators.', 'woocommerce-subscriptions' ), '', '' ), + 'id' => WC_Subscriptions_Admin::$option_prefix . '_role_options', + ), + array( + 'name' => __( 'Subscriber Default Role', 'woocommerce-subscriptions' ), + 'desc' => __( 'When a subscription is activated, either manually or after a successful purchase, new users will be assigned this role.', 'woocommerce-subscriptions' ), + 'tip' => '', + 'id' => WC_Subscriptions_Admin::$option_prefix . '_subscriber_role', + 'css' => 'min-width:150px;', + 'default' => 'subscriber', + 'type' => 'select', + 'options' => $roles_options, + 'desc_tip' => true, + ), + array( + 'name' => __( 'Inactive Subscriber Role', 'woocommerce-subscriptions' ), + 'desc' => __( 'If a subscriber\'s subscription is manually cancelled or expires, she will be assigned this role.', 'woocommerce-subscriptions' ), + 'tip' => '', + 'id' => WC_Subscriptions_Admin::$option_prefix . '_cancelled_role', + 'css' => 'min-width:150px;', + 'default' => 'customer', + 'type' => 'select', + 'options' => $roles_options, + 'desc_tip' => true, + ), + array( + 'type' => 'sectionend', + 'id' => WC_Subscriptions_Admin::$option_prefix . '_role_options', + ), + ); + + WC_Subscriptions_Admin::insert_setting_after( $settings, WC_Subscriptions_Admin::$option_prefix . '_button_text', $role_settings, 'multiple_settings', 'sectionend' ); + return $settings; + } + + /** + * Gets the subscriber role. + * + * @since 4.0.0 + * + * @return string The role to apply to subscribers. + */ + public static function get_subscriber_role() { + return get_option( WC_Subscriptions_Admin::$option_prefix . '_subscriber_role', 'subscriber' ); + } + + /** + * Gets the inactive subscriber role. + * + * @since 4.0.0 + * + * @return string The role to apply to inactive subscribers. + */ + public static function get_inactive_subscriber_role() { + return get_option( WC_Subscriptions_Admin::$option_prefix . '_cancelled_role', 'customer' ); + } +} diff --git a/includes/class-wcs-template-loader.php b/includes/class-wcs-template-loader.php deleted file mode 100644 index 155e8d7..0000000 --- a/includes/class-wcs-template-loader.php +++ /dev/null @@ -1,117 +0,0 @@ -get_id() ) ) { - echo '' . - __( 'Action Scheduler is a scalable, traceable job queue for background processing large sets of actions. Action Scheduler works by triggering an action hook to run at some time in the future. Scheduled actions can also be scheduled to run on a recurring schedule.', 'action-scheduler' ) . - '
', - ) - ); - - $screen->add_help_tab( - array( - 'id' => 'action_scheduler_columns', - 'title' => __( 'Columns', 'action-scheduler' ), - 'content' => - '%s => %s
' . $action->get_hook() . '
';
- if ( 1 == $notification['success'] ) {
- $class = 'updated';
- switch ( $notification['row_action_type'] ) {
- case 'run' :
- /* translators: %s: action HTML */
- $action_message_html = sprintf( __( 'Successfully executed action: %s', 'action-scheduler' ), $action_hook_html );
- break;
- case 'cancel' :
- /* translators: %s: action HTML */
- $action_message_html = sprintf( __( 'Successfully canceled action: %s', 'action-scheduler' ), $action_hook_html );
- break;
- default :
- /* translators: %s: action HTML */
- $action_message_html = sprintf( __( 'Successfully processed change for action: %s', 'action-scheduler' ), $action_hook_html );
- break;
- }
- } else {
- $class = 'error';
- /* translators: 1: action HTML 2: action ID 3: error message */
- $action_message_html = sprintf( __( 'Could not process change for action: "%1$s" (ID: %2$d). Error: %3$s', 'action-scheduler' ), $action_hook_html, esc_html( $notification['action_id'] ), esc_html( $notification['error_message'] ) );
- }
-
- $action_message_html = apply_filters( 'action_scheduler_admin_notice_html', $action_message_html, $action, $notification );
-
- $this->admin_notices[] = array(
- 'class' => $class,
- 'message' => $action_message_html,
- );
- }
-
- parent::display_admin_notices();
- }
-
- /**
- * Prints the scheduled date in a human friendly format.
- *
- * @param array $row The array representation of the current row of the table
- *
- * @return string
- */
- public function column_schedule( $row ) {
- return $this->get_schedule_display_string( $row['schedule'] );
- }
-
- /**
- * Get the scheduled date in a human friendly format.
- *
- * @param ActionScheduler_Schedule $schedule
- * @return string
- */
- protected function get_schedule_display_string( ActionScheduler_Schedule $schedule ) {
-
- $schedule_display_string = '';
-
- if ( ! $schedule->get_date() ) {
- return '0000-00-00 00:00:00';
- }
-
- $next_timestamp = $schedule->get_date()->getTimestamp();
-
- $schedule_display_string .= $schedule->get_date()->format( 'Y-m-d H:i:s O' );
- $schedule_display_string .= '' . wp_kses_post( $notice ) . '
- | ||||
---|---|---|---|---|
- | - | - | - | - |
%1$s | %2$s | %3$s | %4$s |
' . wp_kses_post( $notice['message'] ) . '
'; - echo '%s