Skip to content

Commit

Permalink
Updates to 1.11.7
Browse files Browse the repository at this point in the history
  • Loading branch information
MemberPress committed Jul 11, 2023
1 parent 3e8db67 commit ebe66b5
Show file tree
Hide file tree
Showing 71 changed files with 13,174 additions and 983 deletions.
32 changes: 6 additions & 26 deletions app/controllers/MeprAccountCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
if(!defined('ABSPATH')) {die('You are not allowed to call this page directly.');}

class MeprAccountCtrl extends MeprBaseCtrl {
//Prevent a silly error with BuddyPress and our account links widget
//We should eventually change our account links widget to properly inherit the WP_Widget class
public $id_base = 'mepr_account_links_widget';

public function load_hooks() {
add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
Expand Down Expand Up @@ -141,7 +138,8 @@ public function enqueue_scripts($force = false) {
wp_enqueue_script( 'mepr-tel-config-js', MEPR_JS_URL . '/tel_input.js', array( 'mepr-phone-js', 'mp-account' ), MEPR_VERSION, true );
wp_localize_script( 'mepr-tel-config-js', 'meprTel', MeprHooks::apply_filters( 'mepr-phone-input-config', array(
'defaultCountry' => strtolower( get_option( 'mepr_biz_country' ) ),
'utilsUrl' => MEPR_JS_URL . '/intlTelInputUtils.js'
'utilsUrl' => MEPR_JS_URL . '/intlTelInputUtils.js',
'onlyCountries' => ''
) ) );
}
}
Expand Down Expand Up @@ -524,27 +522,6 @@ public function get_account_links() {
return ob_get_clean();
}

public function account_links_widget($args) {
$mepr_options = MeprOptions::fetch();

extract($args);

echo $before_widget;
echo $before_title.__('Account', 'memberpress').$after_title;

if(MeprUtils::is_user_logged_in()) {
$account_url = $mepr_options->account_page_url();
$logout_url = MeprUtils::logout_url();
MeprView::render('/account/logged_in_widget', get_defined_vars());
}
else {
$login_url = MeprUtils::login_url();
MeprView::render('/account/logged_out_widget', get_defined_vars());
}

echo $after_widget;
}

public function output_account_meta($atts=array(), $content='') {
global $mepr_options, $user_ID;

Expand Down Expand Up @@ -589,7 +566,10 @@ public function output_account_meta($atts=array(), $content='') {
return wpautop(stripslashes(do_shortcode($usermeta[$atts['field']])));
break;
default:
return $usermeta[$atts['field']];
//Make sure field actually exists
if(isset($usermeta[$atts['field']]) && !empty($usermeta[$atts['field']])) {
return $usermeta[$atts['field']];
}
break;
}
}
Expand Down
9 changes: 0 additions & 9 deletions app/controllers/MeprAntiCardTestingCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class MeprAntiCardTestingCtrl extends MeprBaseCtrl {
public function load_hooks() {
add_action('mepr_display_general_options', array($this, 'display_options'));
add_action('mepr_stripe_payment_failed', array($this, 'record_payment_failure'));
add_action('mepr_stripe_before_create_payment_client_secret', array($this, 'maybe_block_create_payment_client_secret'));
add_action('mepr_stripe_before_confirm_payment', array($this, 'maybe_block_confirm_payment'));
add_action('mepr_stripe_before_create_checkout_session', array($this, 'maybe_block_create_checkout_session'));
add_action('wp_ajax_mepr_anti_card_testing_get_ip', array($this, 'get_detected_ip_ajax'));
Expand Down Expand Up @@ -269,14 +268,6 @@ public function record_payment_failure($ip) {
}
}

public function maybe_block_create_payment_client_secret() {
$this->maybe_block_ip();

if($this->is_ip_blocked()) {
wp_send_json_error(__('We are not able to complete your purchase at this time. Please contact us for more information.', 'memberpress'));
}
}

public function maybe_block_confirm_payment() {
$this->maybe_block_ip();

Expand Down
18 changes: 3 additions & 15 deletions app/controllers/MeprAppCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public function load_hooks() {
add_action('admin_enqueue_scripts', 'MeprAppCtrl::load_admin_scripts', 1);
add_action('init', 'MeprAppCtrl::parse_standalone_request', 10);
add_action('wp_dashboard_setup', 'MeprAppCtrl::add_dashboard_widgets');
add_action('widgets_init', 'MeprAppCtrl::add_sidebar_widgets');
add_filter('custom_menu_order', '__return_true');
add_filter('menu_order', 'MeprAppCtrl::admin_menu_order');
add_filter('menu_order', 'MeprAppCtrl::admin_submenu_order');
add_action('widgets_init', 'MeprAccountLinksWidget::register_widget');
add_action('widgets_init', 'MeprLoginWidget::register_widget');
add_action('widgets_init', 'MeprSubscriptionsWidget::register_widget');
add_action('add_meta_boxes', 'MeprAppCtrl::add_meta_boxes', 10, 2);
Expand Down Expand Up @@ -967,18 +967,6 @@ public static function add_dashboard_widgets()
$wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard;
}

public static function add_sidebar_widgets() {
try {
$account_ctrl = MeprCtrlFactory::fetch('account');
wp_register_sidebar_widget( 'mepr-account-links', __('MemberPress Account Links', 'memberpress'), array($account_ctrl,'account_links_widget') );
//control func below doesn't do anything, but without it a bunch of debug notices are logged when in the theme customizer
wp_register_widget_control( 'mepr-account-links', __('MemberPress Account Links', 'memberpress'), function($args=array(), $params=array()){} );
}
catch(Exception $e) {
// Silently fail if the account controller is absent
}
}

public static function weekly_stats_widget() {
$mepr_options = MeprOptions::fetch();
$failed_transactions = $pending_transactions = $refunded_transactions = $completed_transactions = $revenue = $refunds = 0;
Expand Down Expand Up @@ -1147,7 +1135,7 @@ public static function mepr_menu(){

add_submenu_page('memberpress', __('Subscriptions', 'memberpress'), __('Subscriptions', 'memberpress'), $capability, 'memberpress-subscriptions', array( $sub_ctrl, 'listing' ));
// Specifically for subscriptions listing
add_submenu_page(null, __('Subscriptions', 'memberpress'), __('Subscriptions', 'memberpress'), $capability, 'memberpress-lifetimes', array( $sub_ctrl, 'listing' ));
add_submenu_page('', __('Subscriptions', 'memberpress'), __('Subscriptions', 'memberpress'), $capability, 'memberpress-lifetimes', array( $sub_ctrl, 'listing' ));
add_submenu_page('memberpress', __('Transactions', 'memberpress'), __('Transactions', 'memberpress'), $capability, 'memberpress-trans', array( $txn_ctrl, 'listing' ));
add_submenu_page('memberpress', __('Reports', 'memberpress'), __('Reports', 'memberpress'), $capability, 'memberpress-reports', 'MeprReportsCtrl::main');
add_dashboard_page(__('MemberPress', 'memberpress'), __('MemberPress', 'memberpress'), $capability, 'memberpress-reports', 'MeprReportsCtrl::main');
Expand Down Expand Up @@ -1180,7 +1168,7 @@ public static function mepr_menu(){
}
}

add_submenu_page(null, __('Support', 'memberpress'), __('Support', 'memberpress'), $capability, 'memberpress-support', 'MeprAppCtrl::render_admin_support');
add_submenu_page('', __('Support', 'memberpress'), __('Support', 'memberpress'), $capability, 'memberpress-support', 'MeprAppCtrl::render_admin_support');

MeprHooks::do_action('mepr_menu');
}
Expand Down
139 changes: 137 additions & 2 deletions app/controllers/MeprBlocksCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function register_block_types_serverside() {
register_block_type(
'memberpress/login-form',
array(
'api_version' => 2,
'attributes' => array(
'use_redirect' => array(
'type' => 'boolean',
Expand Down Expand Up @@ -154,6 +155,7 @@ public function register_block_types_serverside() {
)
);

// Checkout
register_block_type(
'memberpress/checkout',
array(
Expand All @@ -171,6 +173,59 @@ public function register_block_types_serverside() {
'editor_style' => 'mp-pro-checkout'
)
);

// Account Links
register_block_type(
'memberpress/account-links',
array(
'api_version' => 2,
'attributes' => array(),
'render_callback' => array( $this, 'render_account_links_block')
)
);

// Subscriptions
register_block_type(
'memberpress/subscriptions',
array(
'api_version' => 2,
'attributes' => array(
'not_logged_in_message' => array(
'type' => 'string',
'default' => __('You are not logged in.', 'memberpress')
),
'no_subscriptions_message' => array(
'type' => 'string',
'default' => __('You have no Subscriptions yet.', 'memberpress')
),
'top_description' => array(
'type' => 'string'
),
'bottom_description' => array(
'type' => 'string'
),
'use_access_url' => array(
'type' => 'boolean'
)
),
'render_callback' => array( $this, 'render_subscriptions_block')
)
);

// Accounts Info
register_block_type(
'memberpress/account-info',
array(
'api_version' => 2,
'attributes' => array(
'field' => array(
'type' => 'string',
'default' => 'full_name'
),
),
'render_callback' => array( $this, 'render_account_info' ),
)
);
}

/**
Expand Down Expand Up @@ -212,7 +267,7 @@ public function render_account_block() {
* @return string
*/
public function render_login_block( $props ) {
$shortcode = isset( $props['use_redirect'] ) && true === $props['use_redirect'] ? "[mepr-login-form show_logged_in='false' use_redirect='true']" : '[mepr-login-form]';
$shortcode = isset( $props['use_redirect'] ) && true === $props['use_redirect'] ? "[mepr-login-form use_redirect='true']" : '[mepr-login-form]';
ob_start();
echo do_shortcode( $shortcode );
return ob_get_clean();
Expand Down Expand Up @@ -342,9 +397,74 @@ public function render_checkout_block( $atts ) {
return ob_get_clean();
}

/**
* Renders the MP account links
*
* @param array $atts Properties/data from the block
*
* @return string
*/
public function render_account_links_block(array $atts ) {
ob_start();
$mepr_options = MeprOptions::fetch();
if(MeprUtils::is_user_logged_in()) {
$account_url = $mepr_options->account_page_url();
$logout_url = MeprUtils::logout_url();
MeprView::render('/account/logged_in_widget', get_defined_vars());
}
else {
$login_url = MeprUtils::login_url();
MeprView::render('/account/logged_out_widget', get_defined_vars());
}
return ob_get_clean();
}

/**
* Renders the MP subscriptions
*
* @param array $atts Properties/data from the block
*
* @return string
*/
public function render_subscriptions_block(array $atts ) {
ob_start();
$user = MeprUtils::get_currentuserinfo();
$mepr_options = MeprOptions::fetch();

$not_logged_in_message = isset( $atts['not_logged_in_message'] ) ?
sanitize_text_field( $atts['not_logged_in_message'] ) : '';
$no_subscriptions_message = isset( $atts['no_subscriptions_message'] ) ?
sanitize_text_field( $atts['no_subscriptions_message'] ) : '';
$top_desc = isset( $atts['top_description'] ) ?
sanitize_text_field( $atts['top_description'] ) : '';
$bottom_desc = isset( $atts['bottom_description'] ) ?
sanitize_text_field( $atts['bottom_description'] ) : '';
$use_access_url = isset( $atts['use_access_url'] ) &&
filter_var( $atts['use_access_url'], FILTER_VALIDATE_BOOLEAN ) ?
true : false;

MeprView::render('/account/subscriptions_widget', get_defined_vars());
return ob_get_clean();
}

/**
* Enqueue the necessary JS in the editor
* Renders the MP account info
*
* @param array $props Properties/data from the block
*
* @return string
*/
public function render_account_info(array $props ) {
$shortcode = isset( $props['field'] )
? '[mepr-account-info field="' . sanitize_text_field($props['field']) . '"]'
: '[mepr-account-info field="full_name"]';
ob_start();
echo '<p>' . do_shortcode( $shortcode ) . '</p>';
return ob_get_clean();
}

/**
* Enqueue the necessary scripts/styles in the editor
*
* @return void
*/
Expand Down Expand Up @@ -400,6 +520,18 @@ public function enqueue_editor_block_scripts() {
);
}

// Assemble custom fields into an options array
$mepr_options = MeprOptions::fetch();
$custom_fields = array();
if(!empty($mepr_options->custom_fields)) {
foreach ( $mepr_options->custom_fields as $field ) {
$custom_fields[] = array(
'label' => $field->field_key,
'value' => $field->field_key,
);
}
}

// Make the data available to the script
wp_localize_script(
'memberpress/blocks',
Expand All @@ -408,10 +540,13 @@ public function enqueue_editor_block_scripts() {
'memberships' => $membership_options,
'rules' => $rule_options,
'groups' => $groups,
'custom_fields' => $custom_fields,
'redirect_url_setting_url' => menu_page_url( 'memberpress-options', false ) . '#mepr-accounts',
)
);

wp_enqueue_style('mp-theme', MEPR_CSS_URL . '/ui/theme.css', null, MEPR_VERSION);

}

/**
Expand Down
10 changes: 6 additions & 4 deletions app/controllers/MeprCheckoutCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ public function enqueue_scripts() {
wp_enqueue_script( 'mepr-tel-config-js', MEPR_JS_URL . '/tel_input.js', array( 'mepr-phone-js', 'mp-signup' ), MEPR_VERSION, true );
wp_localize_script( 'mepr-tel-config-js', 'meprTel', MeprHooks::apply_filters( 'mepr-phone-input-config', array(
'defaultCountry' => strtolower( get_option( 'mepr_biz_country' ) ),
'utilsUrl' => MEPR_JS_URL . '/intlTelInputUtils.js'
'utilsUrl' => MEPR_JS_URL . '/intlTelInputUtils.js',
'onlyCountries' => ''
) ) );
}

Expand Down Expand Up @@ -474,7 +475,7 @@ public function process_signup_form() {
}
}

$txn->set_subtotal($price);
$txn->set_subtotal(MeprUtils::maybe_round_to_minimum_amount($price));

// Set the coupon id of the transaction
$txn->coupon_id = $cpn->ID;
Expand Down Expand Up @@ -528,7 +529,8 @@ public function process_signup_form() {
$price = $product->adjusted_price($cpn->post_title);
}
}
$txn->set_subtotal($price);
$txn->set_subtotal(MeprUtils::maybe_round_to_minimum_amount($price));

// Set the coupon id of the transaction
$txn->coupon_id = $cpn->ID;
// Create a new subscription
Expand Down Expand Up @@ -945,7 +947,7 @@ public static function prepare_transaction(MeprProduct $product, $order_id, $use
$txn->coupon_id = $cpn->ID;
}

$txn->set_subtotal($price);
$txn->set_subtotal(MeprUtils::maybe_round_to_minimum_amount($price));

if($product->is_one_time_payment()) {
$sub = null;
Expand Down
1 change: 1 addition & 0 deletions app/controllers/MeprDrmCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ public function drm_app_fee_reversal() {
return; // bail.
}

$meprdrm = new MeprDrmAppFee();
$api_version = MeprDrmHelper::get_drm_app_fee_version();
$current_percentage = MeprDrmHelper::get_application_fee_percentage();
$subscriptions = $meprdrm->get_all_active_subs(array('mepr_app_fee_applied' => MeprDrmHelper::get_drm_app_fee_version()));
Expand Down

0 comments on commit ebe66b5

Please sign in to comment.