email working - remove clients - preview polish
This commit is contained in:
1 parent
2b1424d127
commit
da83beaec3
19 files changed
+1342
-1060
No files matched your search
@@ -22,6 +22,7 @@ class HSSM_Shortcode {
|
||||
*/
|
||||
public function __construct() {
|
||||
add_shortcode( 'hssm_slider', array( $this, 'render_shortcode' ) );
|
||||
add_shortcode( 'hssm_slides', array( $this, 'render_shortcode' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,14 +50,37 @@ class HSSM_Shortcode {
|
||||
$slides = $result;
|
||||
} else {
|
||||
// Manager mode - Fetch locally
|
||||
$site_slug = isset( $atts['site'] ) ? sanitize_text_field( $atts['site'] ) : get_option( 'hssm_client_site_slug', 'hi-school' );
|
||||
$date = isset( $atts['date'] ) ? sanitize_text_field( $atts['date'] ) : current_time( 'Y-m-d' );
|
||||
if ( isset( $atts['count'] ) && ! isset( $atts['limit'] ) ) {
|
||||
$atts['limit'] = $atts['count'];
|
||||
}
|
||||
|
||||
$atts = shortcode_atts(
|
||||
array(
|
||||
'site' => get_option( 'hssm_client_site_slug', 'hi-school' ),
|
||||
'date' => current_time( 'Y-m-d' ),
|
||||
'limit' => 10,
|
||||
'slide' => 0,
|
||||
'include_pending' => '0',
|
||||
),
|
||||
$atts,
|
||||
'hssm_slider'
|
||||
);
|
||||
|
||||
$site_slug = sanitize_text_field( $atts['site'] );
|
||||
$date = sanitize_text_field( $atts['date'] );
|
||||
$focus_slide_id = absint( $atts['slide'] );
|
||||
$include_pending = filter_var( $atts['include_pending'], FILTER_VALIDATE_BOOLEAN );
|
||||
|
||||
$post_status = array( 'publish', 'future' );
|
||||
if ( $include_pending ) {
|
||||
$post_status[] = 'pending';
|
||||
}
|
||||
|
||||
// Build query args similar to what's in the REST API or Frontend class
|
||||
$args = array(
|
||||
'post_type' => 'hssm_slide',
|
||||
'posts_per_page' => isset( $atts['limit'] ) ? intval( $atts['limit'] ) : 10,
|
||||
'post_status' => array( 'publish', 'future', 'pending' ),
|
||||
'posts_per_page' => intval( $atts['limit'] ),
|
||||
'post_status' => $post_status,
|
||||
'meta_key' => '_hssm_order',
|
||||
'orderby' => 'meta_value_num',
|
||||
'order' => 'ASC',
|
||||
@@ -94,21 +118,14 @@ class HSSM_Shortcode {
|
||||
if ( $query->have_posts() ) {
|
||||
while ( $query->have_posts() ) {
|
||||
$query->the_post();
|
||||
$slide_id = get_the_ID();
|
||||
|
||||
// Format data to match what the API returns
|
||||
$slides[] = array(
|
||||
'id' => $slide_id,
|
||||
'title' => get_the_title(),
|
||||
'subtitle' => get_post_meta( $slide_id, '_hssm_subtitle', true ),
|
||||
'content' => get_the_content(),
|
||||
'buttons' => get_post_meta( $slide_id, '_hssm_buttons', true ),
|
||||
'featured_image' => get_the_post_thumbnail_url( $slide_id, 'full' ),
|
||||
'hide_all_text' => get_post_meta( $slide_id, '_hssm_hide_all_text', true ) === '1',
|
||||
);
|
||||
$slides[] = $this->format_slide_for_slider( get_the_ID() );
|
||||
}
|
||||
wp_reset_postdata();
|
||||
}
|
||||
|
||||
if ( $focus_slide_id ) {
|
||||
$slides = $this->prepend_focus_slide( $slides, $focus_slide_id, $include_pending );
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $slides ) ) {
|
||||
@@ -118,4 +135,77 @@ class HSSM_Shortcode {
|
||||
$slider = new HSSM_Slider();
|
||||
return $slider->render( $slides, $atts );
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a slide for the public slider.
|
||||
*
|
||||
* @since 1.1.3
|
||||
* @param int $slide_id Slide ID.
|
||||
* @return array|null
|
||||
*/
|
||||
private function format_slide_for_slider( $slide_id ) {
|
||||
$slide = get_post( $slide_id );
|
||||
if ( ! $slide || 'hssm_slide' !== $slide->post_type ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return array(
|
||||
'id' => $slide->ID,
|
||||
'title' => $slide->post_title,
|
||||
'subtitle' => get_post_meta( $slide->ID, '_hssm_subtitle', true ),
|
||||
'content' => $slide->post_content,
|
||||
'buttons' => get_post_meta( $slide->ID, '_hssm_buttons', true ),
|
||||
'featured_image' => get_the_post_thumbnail_url( $slide->ID, 'full' ),
|
||||
'hide_all_text' => get_post_meta( $slide->ID, '_hssm_hide_all_text', true ) === '1',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a specific slide first in the slider.
|
||||
*
|
||||
* Pending and draft slides are only prepended when include_pending is true
|
||||
* (preview). The public slider stays publish + future.
|
||||
*
|
||||
* @since 1.1.3
|
||||
* @param array $slides Existing slides.
|
||||
* @param int $slide_id Focus slide ID.
|
||||
* @param bool $include_pending Whether pending/draft focus slides are allowed.
|
||||
* @return array
|
||||
*/
|
||||
private function prepend_focus_slide( $slides, $slide_id, $include_pending = false ) {
|
||||
foreach ( $slides as $index => $slide ) {
|
||||
if ( (int) $slide['id'] === (int) $slide_id ) {
|
||||
if ( 0 !== $index ) {
|
||||
$focus = $slides[ $index ];
|
||||
unset( $slides[ $index ] );
|
||||
array_unshift( $slides, $focus );
|
||||
}
|
||||
return array_values( $slides );
|
||||
}
|
||||
}
|
||||
|
||||
$post = get_post( $slide_id );
|
||||
if ( ! $post || 'hssm_slide' !== $post->post_type ) {
|
||||
return $slides;
|
||||
}
|
||||
|
||||
$allowed_statuses = array( 'publish', 'future' );
|
||||
if ( $include_pending ) {
|
||||
$allowed_statuses[] = 'pending';
|
||||
if ( current_user_can( 'edit_post', $slide_id ) ) {
|
||||
$allowed_statuses[] = 'draft';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! in_array( $post->post_status, $allowed_statuses, true ) ) {
|
||||
return $slides;
|
||||
}
|
||||
|
||||
$formatted = $this->format_slide_for_slider( $slide_id );
|
||||
if ( $formatted ) {
|
||||
array_unshift( $slides, $formatted );
|
||||
}
|
||||
|
||||
return $slides;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user