'_slms_parent_lesson', 'slms_lesson' => '_slms_parent_unit', 'slms_unit' => '_slms_parent_course', ); while ( $id && count( $chain ) < 4 ) { $chain[] = $id; $type = get_post_type( $id ); $id = isset( $up[ $type ] ) ? (int) get_post_meta( $id, $up[ $type ], true ) : 0; } return $chain; } /** * The header image's attachment id, or 0. * * @param int $post_id Course, unit, lesson or quiz. * @return int */ public static function image_id( $post_id ) { $chain = self::chain( $post_id ); if ( ! Settings::get( 'header_inherit', 1 ) ) { $chain = array_slice( $chain, 0, 1 ); } foreach ( $chain as $id ) { $thumb = (int) get_post_thumbnail_id( $id ); if ( $thumb ) { return $thumb; } } return 0; } /** * The header style: the nearest one set, or "banner". * * @param int $post_id Course, unit, lesson or quiz. * @return string One of self::STYLES. */ public static function style( $post_id ) { foreach ( self::chain( $post_id ) as $id ) { $style = get_post_meta( $id, self::META, true ); if ( in_array( $style, self::STYLES, true ) ) { return $style; } } return 'banner'; } /** * The header for a page: image id and style. * * @param int $post_id Course, lesson or quiz. * @return array{image_id:int,style:string} */ public static function get( $post_id ) { $header = array( 'image_id' => self::image_id( $post_id ), 'style' => self::style( $post_id ), ); /** * The header shown at the top of a course, lesson or quiz page. * * @param array $header 'image_id' (attachment id, 0 for none) and 'style' ('banner', 'compact' or 'none'). * @param int $post_id The course, lesson or quiz. */ $header = apply_filters( 'accessnow_slms_page_header', $header, $post_id ); return array( 'image_id' => isset( $header['image_id'] ) ? absint( $header['image_id'] ) : 0, 'style' => isset( $header['style'] ) && in_array( $header['style'], self::STYLES, true ) ? $header['style'] : 'banner', ); } /** * Print the header (templates/partials/page-header.php, which themes can override). * * @param int $post_id Course, lesson or quiz. */ public static function render( $post_id ) { $header = self::get( $post_id ); if ( ! $header['image_id'] || 'none' === $header['style'] ) { return; } Template_Loader::get_partial( 'page-header.php', $header ); } /** * The "Header style" row for the course, unit and lesson settings boxes. * * @param \WP_Post $post The post being edited. */ public static function render_field( $post ) { $value = get_post_meta( $post->ID, self::META, true ); $default = array( 'slms_course' => __( 'Banner (default)', 'accessnow-lms' ), 'slms_unit' => __( 'Same as the course', 'accessnow-lms' ), 'slms_lesson' => __( 'Same as the unit', 'accessnow-lms' ), ); $labels = array( 'banner' => __( 'Banner: the whole image', 'accessnow-lms' ), 'compact' => __( 'Compact: a short strip', 'accessnow-lms' ), 'none' => __( 'None: no image', 'accessnow-lms' ), ); ?>