Skip to content

Commit

Permalink
Merge branch 'master' of bitbucket.org:incsub/membership-2 into new/k…
Browse files Browse the repository at this point in the history
…eep_coupon_data
  • Loading branch information
Joel-James committed Mar 7, 2019
2 parents 9144aa1 + 6ed229a commit 7aa1186
Show file tree
Hide file tree
Showing 20 changed files with 462 additions and 135 deletions.
111 changes: 110 additions & 1 deletion app/addon/buddypress/class-ms-addon-buddypress.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,27 @@ public function init() {
'rule_tabs'
);

// Export xprofile fields.
$this->add_filter(
'ms_export/export_member',
'export_xprofile_fields',
10, 3
);

// Import xprofile fields.
$this->add_action(
'ms_import_member_imported',
'import_xprofile_fields',
10, 2
);

// Import xprofile fields.
$this->add_action(
'ms_import_member_imported',
'import_xprofile_fields',
10, 2
);

MS_Factory::load( 'MS_Addon_BuddyPress_Rule' );

/*
Expand Down Expand Up @@ -138,7 +159,6 @@ public function init() {
'bp_core_signup_user',
'disable_validation'
);

}


Expand Down Expand Up @@ -690,4 +710,93 @@ public function disable_validation( $user_id ) {
$member->confirm();
}

/**
* Export member xprofile data if BuddyPress addon is enabled.
*
* Export all member BuddyPress XProfile fields using BP functions.
*
* @param array $output Output array.
* @param MS_Model_Member $member Member object.
* @param object $export_base_obj Export object.
*
* @since 1.1.7
*
* @return array Export data.
*/
public function export_xprofile_fields( $output, $member, $export_base_obj ) {
// Get X Profile field values.
if ( function_exists( 'bp_is_active' ) && bp_is_active( 'xprofile' ) ) {
// Get profile field groups.
$profile_groups = BP_XProfile_Group::get( array(
'fetch_fields' => true,
'user_id' => $member->id
) );

// Make sure it is array.
$profile_groups = mslib3()->array->get( $profile_groups );

// Loop through each fields.
foreach ( $profile_groups as $profile_group ) {
$fields = mslib3()->array->get( $profile_group->fields );
// Loop through each fields in group.
foreach ( $fields as $field ) {
$output['xprofile'][] = array(
'id' => $field->id,
'type' => $field->type,
'value' => xprofile_get_field_data( $field->id, $member->id ),
);
}
}
}

/**
* Filter to add/edit fields to member export.
*
* @param array $output Output data.
* @param object $member Member object.
* @param object $export_base_obj Export modal.
*
* @since 1.1.7
*/
return apply_filters( 'ms_export_xprofile_fields', $output, $member, $export_base_obj );
}

/**
* Import member xprofile data if BuddyPress addon is enabled.
*
* Import all member BuddyPress XProfile fields using BP functions.
* NOTE: We will import the field values only if the same field exist
* in new site.
*
* @param object $member Member object.
* @param object $obj Export object.
*
* @since 1.1.7
*
* @return void
*/
public function import_xprofile_fields( $member, $obj ) {
if ( empty( $obj->xprofile ) ) {
return;
}

// Continue only if BuddyPress is available.
if ( function_exists( 'bp_is_active' ) && bp_is_active( 'xprofile' ) ) {
// Loop through each field.
foreach ( $obj->xprofile as $field ) {
// Continue only if field id is set.
if ( ! isset( $field['id'], $field['type'], $field['value'] ) ) {
continue;
}

// Get current site's field data.
$field_data = xprofile_get_field( $field['id'] );
// Import only if the field type is same.
if ( isset( $field_data->type ) && $field_data->type === $field['type'] ) {
// Set the data.
xprofile_set_field_data( $field['id'], $member->id, $field['value'] );
}
}
}
}
}
11 changes: 11 additions & 0 deletions app/assets/css/src/_module_shortcode.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Shortcode Styles
*/
.ms-membership-form-wrapper {
position: relative;

legend {
display: block;
margin-bottom: 20px;
Expand Down Expand Up @@ -50,6 +52,15 @@
background: #AAA;
}
}

.ms-login-form {
.nav {
position: absolute;
bottom: 0;
right: 0;
}
}

}

.ms-membership-details-wrapper {
Expand Down
7 changes: 6 additions & 1 deletion app/assets/js/src/ms-view-settings-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ window.ms_init.view_settings_import = function init() {
sel_batchsize = form_import.find( '#batchsize' ),
the_popup = null,
the_progress = null,
action_name = null,
queue = [],
queue_count = 0;

Expand Down Expand Up @@ -158,7 +159,11 @@ window.ms_init.view_settings_import = function init() {
.label( icon + '<span>' + batch.label + '</span>' );

// Prepare the ajax payload.
batch.action = btn_import.val();
if( ! action_name ){
action_name = btn_import.length ? btn_import.val() : btn_user_import.val();
}
batch.action = action_name;

delete batch.label;

// Send the ajax request and call this function again when done.
Expand Down
5 changes: 5 additions & 0 deletions app/assets/js/vendor/wpmu-ui.3.js
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,11 @@
if ( html_classes) {
_html.removeClass( html_classes );
}

// should be remove olverlay class too
if( null !== _modal_overlay ){
_modal_overlay.removeClass();
}
};

/**
Expand Down
2 changes: 1 addition & 1 deletion app/controller/class-ms-controller-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ public function payment_table( $content ) {
$subscription,
$membership
);
$invoice->save();
// $invoice->save();//already run save action in MS_View_Frontend_Payment->to_html

$data['invoice'] = $invoice;
$data['membership'] = $membership;
Expand Down
12 changes: 6 additions & 6 deletions app/controller/class-ms-controller-member.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public function members_admin_page_process_editor() {
) {
$data = array(
'user_login' => sanitize_text_field( $_POST['username'] ),
'user_email' => sanitize_text_field( $_POST['email'] ),
'user_email' => sanitize_email( $_POST['email'] ),
'first_name' => sanitize_text_field( $_POST['first_name'] ),
'last_name' => sanitize_text_field( $_POST['last_name'] ),
'user_pass' => $_POST['password'],
Expand Down Expand Up @@ -437,11 +437,11 @@ public function members_admin_page_process_editor() {
&& self::validate_required( $fields_update, 'POST' )
) {
$data = array(
'ID' => intval( $_POST['user_id'] ),
'user_email' => sanitize_text_field( $_POST['email'] ),
'first_name' => sanitize_text_field( $_POST['first_name'] ),
'last_name' => sanitize_text_field( $_POST['last_name'] ),
'display_name' => sanitize_text_field( $_POST['displayname'] ),
'ID' => intval( $_POST['user_id'] ),
'user_email' => sanitize_email( $_POST['email'] ),
'first_name' => sanitize_text_field( $_POST['first_name'] ),
'last_name' => sanitize_text_field( $_POST['last_name'] ),
'display_name' => sanitize_text_field( $_POST['displayname'] ),
);
$user_id = wp_update_user( $data );

Expand Down
26 changes: 13 additions & 13 deletions app/controller/class-ms-controller-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1005,32 +1005,32 @@ public function register_admin_scripts() {
// Dont add dependants that hav not already loaded - Paul Kevin
wp_register_script(
'ms-admin',
$plugin_url . 'app/assets/js/ms-admin.min.js',
$plugin_url . MS_Helper_Utility::asset_link( 'app/assets/js/ms-admin' ),
array( 'jquery' ), $version
);

wp_register_script(
'ms-admin-wpmui',
$plugin_url . 'app/assets/js/m2.wpmu-ui.3.min.js',
$plugin_url . MS_Helper_Utility::asset_link( 'app/assets/js/m2.wpmu-ui.3' ),
array( 'jquery' ), $version
);

wp_register_script(
'm2-jquery-plugins',
$plugin_url . 'app/assets/js/jquery.m2.plugins.js',
$plugin_url . MS_Helper_Utility::asset_link( 'app/assets/js/jquery.m2.plugins' ),
array( 'jquery' ), $version
);

wp_register_script(
'ms-admin-pointers',
$plugin_url . 'app/assets/js/ms-admin-pointers.min.js',
$plugin_url . MS_Helper_Utility::asset_link( 'app/assets/js/ms-admin-pointers' ),
array( 'jquery' ), $version
);

if ( !wp_script_is( 'jquery-validate', 'registered' ) ){
if ( ! wp_script_is( 'jquery-validate', 'registered' ) ) {
wp_register_script(
'jquery-validate',
$plugin_url . 'app/assets/js/jquery.m2.validate.js',
$plugin_url . MS_Helper_Utility::asset_link( 'app/assets/js/jquery.m2.validate' ),
array( 'jquery' ), $version
);
}
Expand Down Expand Up @@ -1078,7 +1078,7 @@ public function register_admin_styles() {
// The main plugin style.
wp_register_style(
'ms-admin-styles',
$plugin_url . 'app/assets/css/ms-admin.min.css',
$plugin_url . MS_Helper_Utility::asset_link( 'app/assets/css/ms-admin', 'css' ),
null, $version
);
}
Expand All @@ -1095,28 +1095,28 @@ public function register_public_scripts() {
// The main plugin script.
wp_register_script(
'ms-admin',
$plugin_url . 'app/assets/js/ms-admin.min.js',
$plugin_url . MS_Helper_Utility::asset_link( 'app/assets/js/ms-admin' ),
array( 'jquery', 'jquery-validate', 'm2-jquery-plugins' ), $version
);
wp_register_script(
'ms-ajax-login',
$plugin_url . 'app/assets/js/ms-public-ajax.min.js',
$plugin_url . MS_Helper_Utility::asset_link( 'app/assets/js/ms-public-ajax' ),
array( 'jquery' ), $version, true // last param forces script to load in footer
);
wp_register_script(
'ms-public',
$plugin_url . 'app/assets/js/ms-public.min.js',
$plugin_url . MS_Helper_Utility::asset_link( 'app/assets/js/ms-public' ),
array( 'jquery' ), $version
);

wp_register_script(
'm2-jquery-plugins',
$plugin_url . 'app/assets/js/jquery.m2.plugins.min.js',
$plugin_url . MS_Helper_Utility::asset_link( 'app/assets/js/jquery.m2.plugins' ),
array( 'jquery' ), $version
);
wp_register_script(
'jquery-validate',
$plugin_url . 'app/assets/js/jquery.m2.validate.min.js',
$plugin_url . MS_Helper_Utility::asset_link( 'app/assets/js/jquery.m2.validate' ),
array( 'jquery' ), $version
);
}
Expand All @@ -1133,7 +1133,7 @@ public function register_public_styles() {
// The main plugin style.
wp_register_style(
'ms-styles',
$plugin_url . 'app/assets/css/ms-public.min.css',
$plugin_url . MS_Helper_Utility::asset_link( 'app/assets/css/ms-public', 'css' ),
array(),
$version
);
Expand Down
10 changes: 9 additions & 1 deletion app/controller/class-ms-controller-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,15 @@ public function membership_signup( $atts ) {
}
}
}


// If there are no memberships to register.
if ( empty( $memberships ) ) {
// Show an error message.
return $this->ms_note(
array( 'type' => 'error' ),
__( 'Sorry there are no memberships available for registration.', 'membership2' )
);
}

$data['memberships'] = $memberships;
$move_from_ids = array();
Expand Down
2 changes: 1 addition & 1 deletion app/core/class-ms-rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ public function reset_rule_values() {
* @param MS_Rule $base_rule The source rule model to merge rules to.
*/
public function protect_undefined_items( $base_rule ) {
if ( $base_rule->rule_type == $this->rule_type ) { return; }
if ( $base_rule->rule_type != $this->rule_type ) { return; }

if ( ! is_array( $this->rule_value ) ) {
$this->rule_value = array();
Expand Down
8 changes: 8 additions & 0 deletions app/gateway/stripe/class-ms-gateway-stripe-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,14 @@ public function subscribe( $customer, $invoice ) {
'coupon' => $coupon_id,
);
$subscription = $customer->subscriptions->create( $args );
} elseif ( $subscription->cancel_at_period_end ) {
// Reactivate if a cancel already scheduled.
try {
$subscription->cancel_at_period_end = false;
$subscription->save();
} catch( Exception $e ) {
// Well, failed to reactivate.
}
}

return apply_filters(
Expand Down
7 changes: 4 additions & 3 deletions app/helper/class-ms-helper-html.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,13 @@ public static function html_admin_vertical_tabs( $tabs, $active_tab = null, $per
$url = $tab['url'];
$attributes = array();

$url = remove_query_arg( 'status', $url );

foreach ( $persistent as $param ) {
mslib3()->array->equip_request( $param );
$value = $_REQUEST[ $param ];
$url = esc_url_raw(
add_query_arg( $param, $value, $url )
);

$url = add_query_arg( $param, $value, $url );
}

$attributes[] = 'class="ms-tab-link"';
Expand Down
Loading

0 comments on commit 7aa1186

Please sign in to comment.