Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpmudev-sls/d951bd1721a902c3f53aa39ca6c938b9 to your computer and use it in GitHub Desktop.
Save wpmudev-sls/d951bd1721a902c3f53aa39ca6c938b9 to your computer and use it in GitHub Desktop.
[CoursePress] - Stay On Unit Course Page After Submit
<?php
/**
* Plugin Name: [CoursePress] - Stay On After Submit Unit Course Test
* Description: [CoursePress] - Stay On After Submit Unit Course Test
* Author: Thobk @ WPMUDEV
* Author URI: https://premium.wpmudev.org
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_action( 'plugins_loaded', 'wpmudev_cp_stay_on_save_process_exit_button_func', 100 );
function wpmudev_cp_stay_on_save_process_exit_button_func() {
if( class_exists('CoursePress_Module') ){
// stay quiz result page
add_filter('coursepress_module_submit_atts', 'wpmudev_cp_stay_on_result_page' );
function wpmudev_cp_stay_on_result_page($data){
if( ! empty( $_REQUEST['_wp_http_referer'] ) && ! ( isset( $_REQUEST['finish'] ) || isset( $_REQUEST['next_unit'] ) || isset( $_REQUEST['next_page'] ) ) ){
$data['data']['url'] = esc_url( $_REQUEST['_wp_http_referer'] );
}
return $data;
}
add_action( 'init', function(){
// change value of this var to true if you want to change the button label name
$change_the_button_label = false;
if( apply_filters( 'wpmudev_cp_change_save_exit_button_text', $change_the_button_label ) ){
add_filter( 'coursepress_view_course_unit', 'wpmudev_cp_change_save_exit_button_text', 10, 3 );
function wpmudev_cp_change_save_exit_button_text($content, $course_id, $post_id){
// change your button name here
$button_name = __( 'Save and see results', 'coursepress' );
$content = preg_replace('/\<a href\="#" class\="save-progress-and-exit"\>[\w&; ]*\<\/a\>/',
sprintf( __('<a href="#" class="save-progress-and-exit">%s</a>', 'coursepress'), $button_name ), $content);
return $content;
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment