esc_url_raw( $url ) ) ) : false; } /** * show_admin_bar: hide WordPress's toolbar on the front end from students, when the setting is on. * Only for users with the student role who can't edit posts: anyone who edits keeps it. * * @param bool $show Whether to show the toolbar. * @return bool */ public static function student_toolbar( $show ) { if ( ! $show || ! is_user_logged_in() || ! Settings::get( 'hide_toolbar_students', 0 ) ) { return $show; } $user = wp_get_current_user(); if ( in_array( 'slms_student', (array) $user->roles, true ) && ! user_can( $user, 'edit_posts' ) ) { return false; } return $show; } /** * Register the public stylesheet and the local-time script, so the blocks (block.json "style" * and "viewScript") and the pages below share one handle each. */ public static function register_assets() { if ( ! wp_style_is( 'slms-public', 'registered' ) ) { wp_register_style( 'slms-public', ACCESSNOW_SLMS_PLUGIN_URL . 'assets/css/slms-public.css', array( 'dashicons' ), ACCESSNOW_SLMS_VERSION ); } if ( ! wp_script_is( 'slms-local-time', 'registered' ) ) { wp_register_script( 'slms-local-time', ACCESSNOW_SLMS_PLUGIN_URL . 'assets/js/slms-local-time.js', array(), ACCESSNOW_SLMS_VERSION, true ); } } public static function enqueue_assets() { if ( ! is_singular( array( 'slms_course', 'slms_lesson', 'slms_quiz' ) ) && ! is_post_type_archive( 'slms_course' ) && ! self::is_slms_shortcode_page() ) { return; } self::register_assets(); wp_enqueue_style( 'slms-public' ); wp_enqueue_script( 'slms-local-time' ); if ( is_singular( 'slms_quiz' ) || is_singular( 'slms_lesson' ) ) { wp_enqueue_script( 'slms-quiz', ACCESSNOW_SLMS_PLUGIN_URL . 'assets/js/slms-quiz.js', array( 'jquery' ), ACCESSNOW_SLMS_VERSION, true ); wp_localize_script( 'slms-quiz', 'slms_quiz', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'accessnow_slms_quiz' ), 'hide_results' => __( 'Hide My Results', 'accessnow-lms' ), 'show_results' => __( 'Show My Results', 'accessnow-lms' ), 'submitting' => __( 'Submitting...', 'accessnow-lms' ), 'quiz_results' => __( 'Quiz Results', 'accessnow-lms' ), 'score_label' => __( 'Score: ', 'accessnow-lms' ), 'passed' => __( 'Passed!', 'accessnow-lms' ), 'failed' => __( 'Failed', 'accessnow-lms' ), 'question' => __( 'Question', 'accessnow-lms' ), 'try_again' => __( 'Try Again', 'accessnow-lms' ), 'submit_quiz' => __( 'Submit Quiz', 'accessnow-lms' ), 'error' => __( 'An error occurred. Please try again.', 'accessnow-lms' ), 'time_up' => __( 'Time ran out before this quiz was submitted, so this attempt scored 0.', 'accessnow-lms' ), 'your_answer' => __( 'Your answer:', 'accessnow-lms' ), 'right_answer' => __( 'Correct answer:', 'accessnow-lms' ), 'explanation' => __( 'Why:', 'accessnow-lms' ), 'correct' => __( 'Correct', 'accessnow-lms' ), 'incorrect' => __( 'Incorrect', 'accessnow-lms' ), 'to_be_marked' => __( 'To be marked', 'accessnow-lms' ), 'awaiting_review' => __( 'Thanks: your answers are in. Part of this quiz is marked by hand, so your score will appear once it has been marked.', 'accessnow-lms' ), /* translators: 1: current question number, 2: total number of questions. */ 'question_of' => __( 'Question %1$s of %2$s', 'accessnow-lms' ), /* translators: %d: minutes left (5). */ 'minutes_left' => __( '%d minutes left.', 'accessnow-lms' ), 'minute_left' => __( 'One minute left.', 'accessnow-lms' ), /* translators: %d: seconds left (30). */ 'seconds_left' => __( '%d seconds left.', 'accessnow-lms' ), 'time_is_up' => __( 'Time is up. Submitting your answers.', 'accessnow-lms' ), ) ); } if ( is_singular( 'slms_lesson' ) || is_singular( 'slms_course' ) ) { $progress_strings = array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'accessnow_slms_progress' ), 'enrolling' => __( 'Enrolling...', 'accessnow-lms' ), 'enroll_now' => __( 'Enroll Now', 'accessnow-lms' ), 'saving' => __( 'Saving...', 'accessnow-lms' ), 'completed' => __( 'Completed', 'accessnow-lms' ), 'course_completed' => __( 'Congratulations! You have completed this course!', 'accessnow-lms' ), 'mark_complete' => __( 'Mark as Complete', 'accessnow-lms' ), 'error' => __( 'An error occurred. Please try again.', 'accessnow-lms' ), 'back_to_course' => __( 'Back to the course', 'accessnow-lms' ), 'can_complete_now' => __( 'Done! You can now mark this lesson complete.', 'accessnow-lms' ), ); } if ( is_singular( 'slms_lesson' ) ) { wp_enqueue_script( 'slms-progress', ACCESSNOW_SLMS_PLUGIN_URL . 'assets/js/slms-progress.js', array( 'jquery' ), ACCESSNOW_SLMS_VERSION, true ); wp_localize_script( 'slms-progress', 'slms_progress', $progress_strings ); wp_enqueue_script( 'slms-notes', ACCESSNOW_SLMS_PLUGIN_URL . 'assets/js/slms-notes.js', array( 'jquery' ), ACCESSNOW_SLMS_VERSION, true ); wp_localize_script( 'slms-notes', 'slms_notes', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'accessnow_slms_notes' ), 'unsaved' => __( 'Unsaved changes...', 'accessnow-lms' ), 'saving' => __( 'Saving...', 'accessnow-lms' ), 'saved' => __( 'Saved', 'accessnow-lms' ), 'error_saving' => __( 'Error saving note', 'accessnow-lms' ), ) ); } if ( is_singular( 'slms_course' ) ) { wp_enqueue_script( 'slms-progress', ACCESSNOW_SLMS_PLUGIN_URL . 'assets/js/slms-progress.js', array( 'jquery' ), ACCESSNOW_SLMS_VERSION, true ); wp_localize_script( 'slms-progress', 'slms_progress', $progress_strings ); if ( ! is_user_logged_in() ) { wp_enqueue_script( 'slms-auth', ACCESSNOW_SLMS_PLUGIN_URL . 'assets/js/slms-auth.js', array( 'jquery' ), ACCESSNOW_SLMS_VERSION, true ); wp_localize_script( 'slms-auth', 'slms_auth', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'accessnow_slms_auth' ), 'log_in' => __( 'Log In', 'accessnow-lms' ), 'logging_in' => __( 'Logging in...', 'accessnow-lms' ), 'create_account' => __( 'Create Account', 'accessnow-lms' ), 'creating' => __( 'Creating account...', 'accessnow-lms' ), 'error' => __( 'An error occurred. Please try again.', 'accessnow-lms' ), ) ); } } } /** * The header image for any SLMS post: its own, else its unit's or course's (see Lesson_Header). * Kept for theme templates copied from earlier versions. */ public static function get_effective_thumbnail_id( $post_id ) { return Lesson_Header::image_id( $post_id ); } /** * Whether the current post shows one of the plugin's shortcodes or blocks. * * @return bool */ private static function is_slms_shortcode_page() { global $post; if ( ! $post ) { return false; } foreach ( array_keys( Shortcodes::TAGS ) as $tag ) { if ( has_shortcode( $post->post_content, $tag ) ) { return true; } } foreach ( Blocks::names() as $block ) { if ( has_block( $block, $post ) ) { return true; } } return false; } }