functions.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * Course functions and definitions
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package Course
  8. * @since Course 1.0
  9. */
  10. if ( ! function_exists( 'course_support' ) ) :
  11. /**
  12. * Sets up theme defaults and registers support for various WordPress features.
  13. *
  14. * @since Course 1.0
  15. *
  16. * @return void
  17. */
  18. function course_support() {
  19. add_theme_support( 'sensei-learning-mode' );
  20. // Enqueue editor styles.
  21. add_editor_style( 'style.css' );
  22. }
  23. endif;
  24. add_action( 'after_setup_theme', 'course_support' );
  25. if ( ! function_exists( 'course_scripts' ) ) :
  26. /**
  27. * Enqueue scripts and styles.
  28. *
  29. * @since Course 1.0
  30. *
  31. * @return void
  32. */
  33. function course_scripts() {
  34. wp_register_style( 'course-style', get_stylesheet_directory_uri() . '/style.css', array(), wp_get_theme()->get( 'Version' ) );
  35. wp_enqueue_script( 'course-header', get_template_directory_uri() . '/assets/js/header.js', [], wp_get_theme()->get( 'Version' ), true );
  36. wp_enqueue_style( 'course-style' );
  37. /**
  38. * Temporary Hook to skip the learning mode style when the Sensei LMS is able to provide it.
  39. * It is only used to continue loading the deprecated styles if a old sensei version is installed.
  40. */
  41. $use_deprecated_style = apply_filters( 'course_learning_mode_load_styles', true );
  42. if ( class_exists( 'Sensei_Main' ) && $use_deprecated_style ) {
  43. wp_register_style( 'course-sensei-learning-mode', get_stylesheet_directory_uri() . '/learning-mode.css', array(), wp_get_theme()->get( 'Version' ) );
  44. wp_enqueue_style( 'course-sensei-learning-mode' );
  45. }
  46. }
  47. endif;
  48. add_action( 'wp_enqueue_scripts', 'course_scripts' );
  49. function course_theme_init() {
  50. register_block_style(
  51. 'core/navigation-link',
  52. array(
  53. 'name' => 'navigation-link-button',
  54. 'label' => __( 'Button', 'course' ),
  55. )
  56. );
  57. }
  58. add_action( 'init', 'course_theme_init' );
  59. /**
  60. * Register Sensei LMS block patterns category.
  61. */
  62. function course_register_block_patterns_category() {
  63. register_block_pattern_category(
  64. 'sensei-lms',
  65. [ 'label' => 'Sensei LMS' ]
  66. );
  67. }
  68. add_action( 'init', 'course_register_block_patterns_category' );
  69. add_filter(
  70. 'theme_lesson_templates',
  71. 'course_theme_filter_single_lesson_template_for_sensei_learning_mode',
  72. 11,
  73. 3
  74. );
  75. /**
  76. * Filter the list of templates for the single lesson page.
  77. *
  78. * @param array $page_templates Array of page templates.
  79. * @param string $theme The current theme.
  80. * @param WP_Post $post The post being edited, provided for context, or null.
  81. *
  82. * @since Course 1.3.2
  83. *
  84. * @return array Array of page templates.
  85. */
  86. function course_theme_filter_single_lesson_template_for_sensei_learning_mode( $page_templates, $theme, $post ) {
  87. // In case some other plugin has a post type called lesson.
  88. if ( ! $post || ! class_exists( 'Sensei_Main' ) ) {
  89. return $page_templates;
  90. }
  91. $course_id = Sensei()->lesson->get_course_id( $post->ID );
  92. $is_learning_mode_enabled = Sensei_Course_Theme_Option::has_learning_mode_enabled( $course_id );
  93. if ( $is_learning_mode_enabled ) {
  94. unset( $page_templates['single-lesson'] );
  95. }
  96. return $page_templates;
  97. }