LocalizeScript


Source

File: classes/LocalizeScript.php

class LocalizeScript {

	public function __construct() {
		add_action( 'admin_enqueue_scripts', [ $this, 'load_localization' ] );
		add_action( 'wp_enqueue_scripts', [ $this, 'load_localization' ] );

	}

	public function load_localization() {

		$localization = [
			'ajaxurl'                  => admin_url( 'admin-ajax.php' ),
			'placeholder_img_src'      => dozent_placeholder_img_src(),
			'current_dashboard_page'   => dozent_get_dashboard_url_segment(),
			'option_changed_msg'       => __( 'Settings have changed, you should save them!', 'dozent' ),
			'new_section_saved'        => __( 'New section has been created', 'dozent' ),
			'section_updated_message'  => __( 'Section has been updated', 'dozent' ),
			'something_wrong_msg'      => __( 'Something went wrong, please try again later', 'dozent' ),
			'lecture_add_msg'          => __( 'Lecture has been added', 'dozent' ),
			'course_metabox_save_msg'  => __( 'Course has been saved', 'dozent' ),
			'lecture_updated_msg'      => __( 'Lecture has been updated', 'dozent' ),
			'expand_btn_see_more_text' => __( '+ See More', 'dozent' ),
			'quiz_add_msg'             => __( 'Quiz has been added', 'dozent' ),
			'quiz_updated_msg'         => __( 'Quiz has been updated', 'dozent' ),
			'question_add_msg'         => __( 'Question has been added', 'dozent' ),
			'question_updated_msg'     => __( 'Question has been updated', 'dozent' ),
			'expired'                  => __( 'Expired', 'dozent' ),
		];

		$localization['message'] = [
			'asked_discussion_question' => __( 'Your question sent to instructor', 'dozent' ),
		];

		$localization['instructor_search_term_error']
			= dozent_notice( sprintf( __( 'Enter %d more characters to start search', 'dozent' ), 3 ), 'warning',
			false );

		$localization['current_user'] = is_user_logged_in() ? get_current_user_id() : false;

		$dozent_localize_object = apply_filters( 'dozent_localize_object', $localization );

		wp_localize_script( 'dozent', '_dozent', $dozent_localize_object );
	}

}

Methods