Skip to content

Commit

Permalink
Updates to 1.11.27
Browse files Browse the repository at this point in the history
  • Loading branch information
MemberPress committed Mar 21, 2024
1 parent 018b785 commit b6aaff4
Show file tree
Hide file tree
Showing 37 changed files with 3,115 additions and 595 deletions.
4 changes: 1 addition & 3 deletions app/controllers/MeprAccountCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function home($atts = array()) {
$delim = MeprAppCtrl::get_param_delimiter_char($account_url);
$errors = array();
$saved = false;
$welcome_message = wpautop(stripslashes($mepr_options->custom_message));
$welcome_message = do_shortcode(wp_kses_post(wpautop(stripslashes($mepr_options->custom_message))));

if( MeprUtils::is_post_request() &&
isset($_POST['mepr-process-account']) && $_POST['mepr-process-account'] == 'Y' ) {
Expand Down Expand Up @@ -265,8 +265,6 @@ public function home($atts = array()) {

$mepr_current_user = MeprUtils::get_currentuserinfo();

$welcome_message = do_shortcode ( wp_kses_post( wpautop( $mepr_options->custom_message ) ) );

$address_fields = MeprUsersHelper::get_address_fields( $mepr_current_user );
$address_values = array();
foreach ( $address_fields as $address_field ) {
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/MeprAppCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function load_hooks() {
add_action('admin_notices', 'MeprAppCtrl::php_min_version_check');
add_action('admin_notices', 'MeprAppCtrl::maybe_show_get_started_notice');
add_action('wp_ajax_mepr_dismiss_notice', 'MeprAppCtrl::dismiss_notice');
add_action('wp_ajax_mepr_dismiss_global_notice', 'MeprAppCtrl::dismiss_global_notice');
add_action('wp_ajax_mepr_dismiss_daily_notice', 'MeprAppCtrl::dismiss_daily_notice');
add_action('wp_ajax_mepr_dismiss_weekly_notice', 'MeprAppCtrl::dismiss_weekly_notice');
add_action('wp_ajax_mepr_todays_date', 'MeprAppCtrl::todays_date');
Expand Down Expand Up @@ -300,6 +301,15 @@ public static function dismiss_notice() {
wp_send_json_success();
}

public static function dismiss_global_notice() {
if(check_ajax_referer('mepr_dismiss_notice', false, false) && isset($_POST['notice']) && is_string($_POST['notice'])) {
$notice = sanitize_key($_POST['notice']);
update_option("mepr_dismiss_notice_{$notice}", true);
}

wp_send_json_success();
}

public static function dismiss_daily_notice() {
if(check_ajax_referer('mepr_dismiss_notice', false, false) && isset($_POST['notice']) && is_string($_POST['notice'])) {
$notice = sanitize_key($_POST['notice']);
Expand Down
119 changes: 119 additions & 0 deletions app/controllers/MeprMigratorCtrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php
class MeprMigratorCtrl extends MeprBaseCtrl {
/**
* Loads the hooks for this controller.
*/
public function load_hooks() {
add_action('admin_enqueue_scripts', 'MeprMigratorCtrl::admin_enqueue_scripts');
add_action('mpcs_admin_options_tab', 'MeprMigratorCtrl::add_options_tab');
add_action('mpcs_admin_options_tab_content', 'MeprMigratorCtrl::add_options_tab_content');
add_action('wp_ajax_mepr_migrator_migrate', 'MeprMigratorCtrl::migrate');
add_action('admin_notices', 'MeprMigratorCtrl::admin_notices');
}

/**
* Enqueue admin scripts.
*/
public static function admin_enqueue_scripts() {
if(MeprMigratorHelper::is_migrator_page() && ($migrators = MeprMigratorHelper::get_usable_course_migrators())) {
wp_enqueue_style('memberpress-migrator', MEPR_CSS_URL . '/migrator.css', [], MEPR_VERSION);
wp_enqueue_script('memberpress-migrator', MEPR_JS_URL . '/migrator.js', ['jquery'], MEPR_VERSION, true);

if(in_array(MeprMigratorLearnDash::KEY, $migrators, true)) {
wp_enqueue_script('memberpress-migrator-learndash', MEPR_JS_URL . '/migrator.learndash.js', ['jquery', 'memberpress-migrator'], MEPR_VERSION, true);
}

wp_localize_script('memberpress-migrator', 'MeprMigratorL10n', [
'ajax_url' => admin_url('admin-ajax.php'),
'migrate_nonce' => wp_create_nonce('mepr_migrator_migrate'),
'leave_are_you_sure' => __('The migration has not yet completed, are you sure you want to leave this page?', 'memberpress'),
'migration_complete' => __('Migration complete', 'memberpress'),
]);
}
}

/**
* Adds the Migrator tab to the Courses Settings within MP Settings.
*/
public static function add_options_tab() {
?>
<li><a data-id="migrator"><?php esc_html_e('Migrator', 'memberpress'); ?></a></li>
<?php
}

/**
* Adds the content of the Migrator tab.
*/
public static function add_options_tab_content() {
MeprView::render('/admin/options/courses_migrator');
}

/**
* Handles the Ajax request to run a migration.
*/
public static function migrate() {
$data = MeprUtils::get_json_request_data('mepr_migrator_migrate');

if(!isset($data['migrator'])) {
wp_send_json_error(__('Bad request.', 'memberpress'));
}

$migrator = null;

switch($data['migrator']) {
case MeprMigratorLearnDash::KEY:
$migrator = new MeprMigratorLearnDash();
break;
}

if(!$migrator instanceof MeprMigrator) {
wp_send_json_error(__('Migrator not found', 'memberpress'));
}

try {
$migrator->migrate($data);
}
catch(Exception $e) {
wp_send_json_error($e->getMessage());
}
}

/**
* Display admin notices.
*/
public static function admin_notices() {
global $pagenow, $typenow;

if(
!MeprUtils::is_logged_in_and_an_admin() ||
get_option('mepr_dismiss_notice_learndash_migrator') ||
$pagenow != 'edit.php' ||
$typenow != 'mpcs-course'
) {
return;
}

if(
MeprMigratorHelper::has_completed_migration(MeprMigratorLearnDash::KEY) ||
!MeprMigratorLearnDash::is_migration_possible()
) {
update_option('mepr_dismiss_notice_learndash_migrator', true);
return;
}
?>
<div class="notice notice-info is-dismissible mepr-learndash-migrator-notice mepr-notice-dismiss-permanently" data-notice="learndash_migrator">
<div>
<img src="<?php echo esc_url(MEPR_IMAGES_URL . '/info-icon.jpg'); ?>" alt="" style="width: 30px; height: 30px;">
<div>
<p class="mepr-learndash-migrator-notice-heading"><?php esc_html_e('Migrate from LearnDash to MemberPress Courses?', 'memberpress'); ?></p>
<p><?php esc_html_e('We noticed that you have some LearnDash courses that could be migrated to MemberPress Courses automatically. Click the button below to get started.', 'memberpress'); ?></p>
<p class="mepr-learndash-migrator-notice-button-row">
<a href="<?php echo esc_url(admin_url('admin.php?page=memberpress-options&courses-tab=migrator#mepr-courses')); ?>" class="button button-primary"><?php esc_html_e('Let\'s Do It', 'memberpress'); ?></a>
<a href="#" class="mepr-dismiss-this-notice"><?php esc_html_e('Dismiss', 'memberpress'); ?></a>
</p>
</div>
</div>
</div>
<?php
}
}

0 comments on commit b6aaff4

Please sign in to comment.