Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Last active May 2, 2019 13:48
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/ef4b0da5c94fab0f17e4c8471f085867 to your computer and use it in GitHub Desktop.
Save wpmudev-sls/ef4b0da5c94fab0f17e4c8471f085867 to your computer and use it in GitHub Desktop.
[CoursePress] - Custom Save And Exit Button
<?php
/**
* Plugin Name: [CoursePress] - Custom Save And Exit Button
* Description: [CoursePress] - Custom Save And Exit Button
* Author: Thobk @ WPMUDEV
* Author URI: https://premium.wpmudev.org/profile/tho2757
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_action( 'plugins_loaded', 'wpmudev_cp_custom_save_exit_button_func', 100 );
function wpmudev_cp_custom_save_exit_button_func() {
if( class_exists('CoursePress_Module') ){
function wpmudev_cp_is_quiz_page($modules){
$is_quiz_course = false;
if( $modules && is_array( $modules ) ){
foreach( $modules as $module_id ){
if( 'input-quiz' === get_post_meta( $module_id, 'module_type', true ) ){
$is_quiz_course = true;
break;
}
}
}
return $is_quiz_course;
}
// stay quiz result page
add_filter('coursepress_module_submit_atts', 'wpmudev_cp_show_result_page' );
function wpmudev_cp_show_result_page($data){
if( ! empty( $_REQUEST['_wp_http_referer'] ) && ! ( isset( $_REQUEST['finish'] ) || isset( $_REQUEST['next_unit'] ) || isset( $_REQUEST['next_page'] ) ) && ! empty( $_REQUEST['module_id'] ) && wpmudev_cp_is_quiz_page( $_REQUEST['module_id'] ) ){
$data['data']['url'] = esc_url( $_REQUEST['_wp_http_referer'] );
}
return $data;
}
// change button text
add_filter( 'coursepress_view_course_unit', 'wpmudev_cp_change_save_exit_button_name', 10, 3 );
function wpmudev_cp_change_save_exit_button_name($content, $course_id, $post_id){
if( wpmudev_cp_is_quiz_page( CoursePress_Data_Module::get_modules_ids_by_unit( $post_id ) ) ){
$content = preg_replace('/\<a href\="#" class\="save-progress-and-exit"\>[\w&; ]*\<\/a\>/',
sprintf( __('<a href="#" class="save-progress-and-exit">%s</a>', 'coursepress'), __( 'Save and see results', 'coursepress' ) ), $content);
}
return $content;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment