email working - remove clients - preview polish

This commit is contained in:
stack_admn committed 2026-11-01 21:41:37 -08:00
1 parent 2b1424d127
commit da83beaec3
19 files changed
+1342 -1060

No files matched your search

+52 -41
View File
@@ -1,9 +1,9 @@
<?php
/**
* Template Name: Slide Live Confirmation
*
*
* Page for ITC team to confirm a slide is live
*
*
* @package Hi_School_Slide_Manager
* @since 1.0.0
*/
@@ -13,64 +13,71 @@ if ( ! defined( 'ABSPATH' ) ) {
exit( 'Direct access forbidden.' );
}
get_header();
get_header();
$slide_id = isset( $_GET['slide_id'] ) ? intval( $_GET['slide_id'] ) : 0;
// Note: We used a simplified token/hash check in the email link generation.
// Ideally, we would verify that here.
// For now, let's assume if they have the link, they can confirm (or we add basic checks).
$slide_id = isset( $_REQUEST['slide_id'] ) ? absint( $_REQUEST['slide_id'] ) : 0;
$token = isset( $_REQUEST['hssm_token'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['hssm_token'] ) ) : '';
$slide = get_post( $slide_id );
$is_valid_slide = ( $slide && $slide->post_type === 'hssm_slide' );
$confirmed = false;
$error_message = '';
$slide = $slide_id ? get_post( $slide_id ) : null;
$is_valid_slide = ( $slide && 'hssm_slide' === $slide->post_type );
$has_valid_token = $is_valid_slide && class_exists( 'HSSM_Notifications' ) && HSSM_Notifications::is_valid_confirm_token( $slide_id, $token );
$already_confirmed = $is_valid_slide && (bool) get_post_meta( $slide_id, '_hssm_live_confirmed', true );
$confirmed = $already_confirmed;
$error_message = '';
// Handle confirmation action
if ( $is_valid_slide && isset( $_POST['confirm_live_action'] ) && $_POST['confirm_live_action'] === 'confirm' ) {
if ( wp_verify_nonce( $_POST['hssm_live_nonce'], 'hssm_confirm_live_action' ) ) {
// Trigger the final notification
if ( class_exists( 'HSSM_Notifications' ) ) {
$notifications = new HSSM_Notifications();
$notifications->notify_all_confirmed_live( $slide_id );
// Mark as confirmed in metadata
update_post_meta( $slide_id, '_hssm_live_confirmed', current_time( 'timestamp' ) );
$confirmed = true;
} else {
$error_message = 'Notification system not available.';
if ( $is_valid_slide && ! $has_valid_token ) {
$error_message = 'This confirmation link is invalid or expired.';
}
if ( $has_valid_token && ! $already_confirmed && isset( $_POST['confirm_live_action'] ) && 'confirm' === $_POST['confirm_live_action'] ) {
if ( isset( $_POST['hssm_live_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['hssm_live_nonce'] ) ), 'hssm_confirm_live_action' ) ) {
$notifications = new HSSM_Notifications();
$notifications->notify_all_confirmed_live( $slide_id );
$confirmed = (bool) get_post_meta( $slide_id, '_hssm_live_confirmed', true );
if ( ! $confirmed ) {
$error_message = 'Could not send the confirmation email. Please try again.';
}
} else {
$error_message = 'Security check failed. Please refresh and try again.';
}
}
$thumbnail = $is_valid_slide ? get_the_post_thumbnail_url( $slide_id, 'medium' ) : '';
?>
<div id="main-content">
<div class="container-fluid">
<div id="content-area" class="clearfix full-width">
<div class="hssm-confirmation-container" style="max-width: 600px; margin: 50px auto; padding: 30px; background: #fff; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); text-align: center;">
<?php if ( ! $is_valid_slide ) : ?>
<div class="hssm-error">
<h2>Invalid Slide</h2>
<p>The slide you are trying to confirm could not be found.</p>
<a href="<?php echo home_url(); ?>" class="button">Return Home</a>
<a href="<?php echo esc_url( home_url() ); ?>" class="button">Return Home</a>
</div>
<?php elseif ( ! $has_valid_token ) : ?>
<div class="hssm-error">
<h2>Invalid Confirmation Link</h2>
<p><?php echo esc_html( $error_message ); ?></p>
<a href="<?php echo esc_url( home_url() ); ?>" class="button">Return Home</a>
</div>
<?php elseif ( $confirmed ) : ?>
<div class="hssm-success">
<h2 style="color: #46b450;">Confirmation Sent!</h2>
<h2 style="color: #46b450;"><?php echo $already_confirmed && empty( $_POST['confirm_live_action'] ) ? 'Already Confirmed' : 'Confirmation Sent!'; ?></h2>
<p class="dashicons dashicons-yes-alt" style="font-size: 64px; width: 64px; height: 64px; color: #46b450;"></p>
<p><strong>Thank you!</strong></p>
<p>Notifications have been sent to the Editor and Creator confirming that "<?php echo esc_html( $slide->post_title ); ?>" is Live.</p>
<a href="<?php echo home_url(); ?>" class="button">Return Home</a>
<a href="<?php echo esc_url( home_url() ); ?>" class="button">Return Home</a>
</div>
<?php else : ?>
<div class="hssm-confirm-form">
<h2>Confirm Slide is Live</h2>
<?php if ( $error_message ) : ?>
<div style="background: #f8d7da; color: #721c24; padding: 10px; margin-bottom: 20px; border-radius: 4px;">
<?php echo esc_html( $error_message ); ?>
@@ -79,23 +86,27 @@ if ( $is_valid_slide && isset( $_POST['confirm_live_action'] ) && $_POST['confir
<div style="margin: 30px 0; padding: 20px; background: #f9f9f9; border: 1px solid #eee; border-radius: 4px;">
<h3 style="margin-top: 0;"><?php echo esc_html( $slide->post_title ); ?></h3>
<?php
$target_sites = wp_get_post_terms( $slide_id, 'hssm_site', array( 'fields' => 'names' ) );
if ( ! empty( $target_sites ) ) {
echo '<p><strong>Target Sites:</strong> ' . esc_html( implode( ', ', $target_sites ) ) . '</p>';
}
?>
<div style="margin-top: 15px;">
<img src="<?php echo get_the_post_thumbnail_url( $slide_id, 'medium' ); ?>" style="max-width: 100%; height: auto; border-radius: 4px;">
</div>
<?php
$target_sites = wp_get_post_terms( $slide_id, 'hssm_site', array( 'fields' => 'names' ) );
if ( ! empty( $target_sites ) && ! is_wp_error( $target_sites ) ) {
echo '<p><strong>Target Sites:</strong> ' . esc_html( implode( ', ', $target_sites ) ) . '</p>';
}
if ( $thumbnail ) :
?>
<div style="margin-top: 15px;">
<img src="<?php echo esc_url( $thumbnail ); ?>" alt="" style="max-width: 100%; height: auto; border-radius: 4px;">
</div>
<?php endif; ?>
</div>
<p>I confirm that the slide <strong>"<?php echo esc_html( $slide->post_title ); ?>"</strong> is Live and displaying correctly on the target sites.</p>
<form method="post">
<input type="hidden" name="confirm_live_action" value="confirm">
<input type="hidden" name="slide_id" value="<?php echo esc_attr( $slide_id ); ?>">
<input type="hidden" name="hssm_token" value="<?php echo esc_attr( $token ); ?>">
<?php wp_nonce_field( 'hssm_confirm_live_action', 'hssm_live_nonce' ); ?>
<button type="submit" class="button" style="background-color: #46b450; color: #fff; border: none; padding: 15px 30px; font-size: 18px; cursor: pointer; border-radius: 4px;">
<span class="dashicons dashicons-yes"></span> Confirm Slide is Live
</button>
+6 -151
View File
@@ -37,7 +37,7 @@ get_header(); ?>
<span class="dashicons dashicons-admin-generic"></span>
Admin
</a>
<a href="<?php echo home_url( '/slide-preview/' ); ?>" class="hssm-nav-btn hssm-nav-preview" target="_blank">
<a href="<?php echo esc_url( hssm_get_page_url_by_template( 'page-slide-preview.php', '/slide-preview/' ) ); ?>" class="hssm-nav-btn hssm-nav-preview" target="_blank">
<span class="dashicons dashicons-visibility"></span>
Slide Preview
</a>
@@ -109,12 +109,6 @@ get_header(); ?>
</div>
<div class="hssm-bulk-actions">
<button id="save-all-slides" class="hssm-btn hssm-btn-success hssm-btn-large">
<span class="dashicons dashicons-yes"></span> Save All Slides
</button>
<button id="save-draft-all" class="hssm-btn hssm-btn-secondary">
<span class="dashicons dashicons-edit"></span> Save as Drafts
</button>
<button id="clear-all-forms" class="hssm-btn hssm-btn-outline">
<span class="dashicons dashicons-trash"></span> Clear All Forms
</button>
@@ -128,22 +122,20 @@ get_header(); ?>
<div class="hssm-filters">
<select id="filter-site" class="hssm-select">
<option value="">All Sites</option>
<option value="hi-school">Hi-School Pharmacy</option>
<option value="one-stop">One Stop Hardware</option>
<option value="ace">Ace Hardware</option>
</select>
<select id="filter-client" class="hssm-select">
<option value="">All Clients</option>
</select>
<select id="filter-status" class="hssm-select">
<option value="">All Status</option>
<option value="publish">Published</option>
<option value="draft">Draft</option>
<option value="pending">Pending Approval</option>
<option value="scheduled">Scheduled</option>
</select>
<button id="apply-filters" class="hssm-btn hssm-btn-primary">
<span class="dashicons dashicons-filter"></span> Apply Filters
</button>
<button id="clear-filters" class="hssm-btn hssm-btn-outline">
Clear
</button>
<button id="export-slides" class="hssm-btn hssm-btn-secondary">
<span class="dashicons dashicons-download"></span> Export
</button>
@@ -229,141 +221,4 @@ get_header(); ?>
</div> <!-- .container-fluid -->
</div> <!-- #main-content -->
<!-- Slide Form Template (Hidden) -->
<script type="text/html" id="slide-form-template">
<div class="hssm-slide-form" data-form-id="{{form_id}}">
<div class="hssm-form-header">
<h3><strong>New Slide #{{form_number}}</strong></h3>
<button type="button" class="hssm-remove-form" aria-label="Remove this form">
<span class="dashicons dashicons-no"> test</span>
</button>
</div>
<div class="hssm-form-grid">
<!-- Left Column: Basic Information -->
<div class="hssm-form-section hssm-form-basic">
<h4>Basic Information</h4>
<div class="hssm-field-row">
<div class="hssm-field">
<label for="title_{{form_id}}">Title *</label>
<input type="text" id="title_{{form_id}}" name="title" class="hssm-input" required>
</div>
<div class="hssm-field">
<label for="client_{{form_id}}">Client</label>
<input type="text" id="client_{{form_id}}" name="client" class="hssm-input">
</div>
</div>
<div class="hssm-field">
<label for="subtitle_{{form_id}}">Subtitle</label>
<input type="text" id="subtitle_{{form_id}}" name="subtitle" class="hssm-input">
</div>
<div class="hssm-field">
<label for="content_{{form_id}}">Content</label>
<textarea id="content_{{form_id}}" name="content" class="hssm-textarea" rows="3"></textarea>
</div>
</div>
<!-- Center Column: Image & Buttons -->
<div class="hssm-form-section hssm-form-media">
<h4>Background Image</h4>
<div class="hssm-image-upload-compact">
<div class="hssm-image-preview-small" id="image_preview_{{form_id}}">
<span class="hssm-placeholder">Click to upload</span>
</div>
<div class="hssm-image-controls">
<input type="file" id="image_upload_{{form_id}}" name="background_image" accept="image/*" style="display: none;">
<input type="hidden" id="image_id_{{form_id}}" name="featured_image_id" value="">
<button type="button" class="hssm-btn hssm-btn-small hssm-upload-btn" data-target="{{form_id}}">
Choose Image
</button>
<button type="button" class="hssm-btn hssm-btn-small hssm-btn-text hssm-remove-image" data-target="{{form_id}}" style="display: none;">
Remove
</button>
</div>
</div>
<h4>Call-to-Action Buttons</h4>
<div class="hssm-buttons-container-compact" id="buttons_{{form_id}}">
<div class="hssm-button-row-compact">
<input type="text" name="buttons[0][text]" placeholder="Button Text" class="hssm-input-small">
<input type="url" name="buttons[0][url]" placeholder="Button URL" class="hssm-input-small">
<button type="button" class="hssm-btn hssm-btn-tiny hssm-remove-button">×</button>
</div>
</div>
<button type="button" class="hssm-btn hssm-btn-small hssm-add-button" data-form="{{form_id}}">
<span class="dashicons dashicons-plus"></span> Add Button
</button>
</div>
<!-- Right Column: Targeting & Scheduling -->
<div class="hssm-form-section hssm-form-targeting">
<h4>Targeting & Scheduling</h4>
<div class="hssm-field">
<label>Target Sites *</label>
<div class="hssm-checkboxes-compact">
<label class="hssm-checkbox-compact">
<input type="checkbox" name="target_sites[]" value="hi-school">
Hi-School Pharmacy
</label>
<label class="hssm-checkbox-compact">
<input type="checkbox" name="target_sites[]" value="one-stop">
One Stop Hardware
</label>
<label class="hssm-checkbox-compact">
<input type="checkbox" name="target_sites[]" value="ace">
Ace Hardware
</label>
</div>
</div>
<div class="hssm-field" style="margin-top: 15px;">
<label class="hssm-checkbox-compact hssm-hide-text-option">
<input type="checkbox" name="hide_all_text" value="1">
Hide All Text (Image Only)
<small style="display: block; color: #666; margin-top: 5px;">Check this to display only the image without any overlay text</small>
</label>
</div>
<div class="hssm-field-row">
<div class="hssm-field">
<label for="start_date_{{form_id}}">Start Date</label>
<input type="date" id="start_date_{{form_id}}" name="start_date" class="hssm-input">
</div>
<div class="hssm-field">
<label for="end_date_{{form_id}}">End Date</label>
<input type="date" id="end_date_{{form_id}}" name="end_date" class="hssm-input">
</div>
</div>
<div class="hssm-field-row">
<div class="hssm-field">
<label for="order_{{form_id}}">Display Order</label>
<input type="number" id="order_{{form_id}}" name="order" class="hssm-input" value="0" min="0">
</div>
<div class="hssm-field">
<!-- Spacer for alignment -->
</div>
</div>
</div>
</div>
<div class="hssm-form-actions">
<button type="button" class="hssm-btn hssm-btn-secondary hssm-schedule-slide" data-form="{{form_id}}">
<span class="dashicons dashicons-calendar-alt"></span> Schedule for Approval
</button>
<button type="button" class="hssm-btn hssm-btn-primary hssm-publish-slide" data-form="{{form_id}}">
<span class="dashicons dashicons-yes"></span> Publish Immediately
</button>
<button type="button" class="hssm-btn hssm-btn-outline hssm-preview-slide" data-form="{{form_id}}">
<span class="dashicons dashicons-visibility"></span> Preview
</button>
</div>
</div>
</script>
<?php get_footer(); ?>
<?php get_footer(); ?>
+113 -14
View File
@@ -108,6 +108,33 @@ function hssm_get_preview_request() {
$date_param = isset( $_GET['hssm_date'] ) ? sanitize_text_field( wp_unslash( $_GET['hssm_date'] ) ) : $today->format( 'Y-m-d' );
$site_param = isset( $_GET['hssm_site'] ) ? sanitize_text_field( wp_unslash( $_GET['hssm_site'] ) ) : '';
$show_past = isset( $_GET['hssm_past'] ) && $_GET['hssm_past'] === '1';
$slide_id = 0;
if ( isset( $_GET['hssm_preview'] ) ) {
$slide_id = absint( $_GET['hssm_preview'] );
} elseif ( isset( $_GET['hssm_slide'] ) ) {
$slide_id = absint( $_GET['hssm_slide'] );
}
if ( $slide_id ) {
$slide = get_post( $slide_id );
if ( $slide && 'hssm_slide' === $slide->post_type ) {
if ( empty( $_GET['hssm_date'] ) ) {
$start_date = get_post_meta( $slide_id, '_hssm_start_date', true );
if ( $start_date && preg_match( '/^(\d{4}-\d{2}-\d{2})/', $start_date, $matches ) ) {
$date_param = $matches[1];
}
}
if ( empty( $site_param ) ) {
$site_terms = wp_get_post_terms( $slide_id, HSSM_Slides_CPT::SITE_TAXONOMY );
if ( ! is_wp_error( $site_terms ) && ! empty( $site_terms ) ) {
$site_param = $site_terms[0]->slug;
}
}
} else {
$slide_id = 0;
}
}
// Validate date (YYYY-MM-DD)
$date_obj = DateTime::createFromFormat( 'Y-m-d', $date_param );
@@ -119,6 +146,7 @@ function hssm_get_preview_request() {
'date' => $date_obj->format( 'Y-m-d' ),
'site_slug' => $site_param,
'show_past' => $show_past,
'slide_id' => $slide_id,
);
}
@@ -317,6 +345,11 @@ function hssm_get_preview_slides_for_date( $date, $site_slug = '' ) {
$request = hssm_get_preview_request();
$sites = hssm_get_preview_sites();
$events = hssm_get_calendar_events( $request['site_slug'] );
$can_approve = current_user_can( 'edit_posts' );
$focused_slide = $request['slide_id'] ? get_post( $request['slide_id'] ) : null;
if ( $focused_slide && 'hssm_slide' !== $focused_slide->post_type ) {
$focused_slide = null;
}
$current_site_name = '';
if ( ! empty( $request['site_slug'] ) ) {
@@ -341,23 +374,69 @@ if ( empty( $current_site_name ) && ! empty( $sites ) ) {
<div class="container-fluid">
<div id="content-area" class="clearfix full-width">
<div class="hssm-header-bar">
<div class="hssm-header-content">
<div class="hssm-logo-section">
<h1 class="hssm-site-title"><?php esc_html_e( 'Slide Preview', 'hi-school-slide-manager' ); ?></h1>
</div>
<div class="hssm-header-nav">
<a href="<?php echo esc_url( hssm_get_page_url_by_template( 'page-slide-dashboard.php', '/slide-dashboard/' ) ); ?>" class="hssm-nav-btn hssm-nav-home">
<span class="dashicons dashicons-admin-home"></span>
<?php esc_html_e( 'Dashboard', 'hi-school-slide-manager' ); ?>
</a>
<a href="<?php echo esc_url( admin_url() ); ?>" class="hssm-nav-btn hssm-nav-admin">
<span class="dashicons dashicons-admin-generic"></span>
<?php esc_html_e( 'Admin', 'hi-school-slide-manager' ); ?>
</a>
<div class="hssm-user-menu">
<span class="hssm-user-name"><?php echo esc_html( wp_get_current_user()->display_name ); ?></span>
<a href="<?php echo esc_url( wp_logout_url( home_url() ) ); ?>" class="hssm-nav-btn hssm-nav-logout">
<span class="dashicons dashicons-exit"></span>
<?php esc_html_e( 'Logout', 'hi-school-slide-manager' ); ?>
</a>
</div>
</div>
</div>
</div>
<?php
// Render the live slider preview using the modular shortcode
echo do_shortcode( sprintf(
'[hssm_slider site="%s" date="%s"]',
'[hssm_slider site="%s" date="%s" slide="%d" include_pending="1"]',
esc_attr( $request['site_slug'] ),
esc_attr( $request['date'] )
esc_attr( $request['date'] ),
absint( $request['slide_id'] )
) );
// Normal page content (Divi builder, header, etc.).
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
// the_content(); // We might not want the_content if we're replacing it with the shortcode,
// but let's keep it in case there's other content.
endwhile;
endif;
?>
if ( $focused_slide && 'pending' === $focused_slide->post_status && $can_approve ) :
$focus_start = get_post_meta( $focused_slide->ID, '_hssm_start_date', true );
$start_ts = $focus_start ? strtotime( $focus_start ) : false;
$is_future = $start_ts && $start_ts > current_time( 'timestamp' );
?>
<div class="hssm-preview-approve-bar">
<div class="hssm-preview-approve-copy">
<strong><?php echo esc_html( get_the_title( $focused_slide ) ); ?></strong>
<span><?php esc_html_e( 'This slide is pending approval.', 'hi-school-slide-manager' ); ?></span>
</div>
<div class="hssm-preview-approve-actions">
<?php if ( $is_future ) : ?>
<button type="button" class="hssm-btn hssm-btn-success hssm-approve-slide" data-id="<?php echo esc_attr( $focused_slide->ID ); ?>" data-approve-action="schedule">
<span class="dashicons dashicons-yes"></span>
<?php esc_html_e( 'Approve & Schedule', 'hi-school-slide-manager' ); ?>
</button>
<button type="button" class="hssm-btn hssm-btn-primary hssm-approve-slide" data-id="<?php echo esc_attr( $focused_slide->ID ); ?>" data-approve-action="publish">
<span class="dashicons dashicons-upload"></span>
<?php esc_html_e( 'Approve & Publish Now', 'hi-school-slide-manager' ); ?>
</button>
<?php else : ?>
<button type="button" class="hssm-btn hssm-btn-success hssm-approve-slide" data-id="<?php echo esc_attr( $focused_slide->ID ); ?>" data-approve-action="publish">
<span class="dashicons dashicons-yes"></span>
<?php esc_html_e( 'Approve & Publish', 'hi-school-slide-manager' ); ?>
</button>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<div class="hssm-dashboard-main hssm-mt-20">
<div class="hssm-tab-header">
@@ -374,6 +453,9 @@ if ( empty( $current_site_name ) && ! empty( $sites ) ) {
</div>
<form method="get" class="hssm-filters hssm-mt-20">
<?php if ( ! empty( $request['slide_id'] ) ) : ?>
<input type="hidden" name="hssm_preview" value="<?php echo esc_attr( $request['slide_id'] ); ?>" />
<?php endif; ?>
<div>
<label for="hssm_date"><strong><?php esc_html_e( 'Preview Date', 'hi-school-slide-manager' ); ?></strong></label><br>
<input type="text" id="hssm_date" name="hssm_date" class="hssm-input" value="<?php echo esc_attr( $request['date'] ); ?>" autocomplete="off" />
@@ -412,6 +494,23 @@ if ( empty( $current_site_name ) && ! empty( $sites ) ) {
<?php
$slides = hssm_get_preview_slides_for_date( $request['date'], $request['site_slug'] );
if ( ! empty( $request['slide_id'] ) ) {
$has_focus = false;
foreach ( $slides as $existing_slide ) {
if ( (int) $existing_slide->ID === (int) $request['slide_id'] ) {
$has_focus = true;
break;
}
}
if ( ! $has_focus ) {
$focus_slide = get_post( $request['slide_id'] );
if ( $focus_slide && 'hssm_slide' === $focus_slide->post_type ) {
array_unshift( $slides, $focus_slide );
}
}
}
if ( empty( $slides ) ) :
?>
<div class="hssm-empty-state">
@@ -434,7 +533,7 @@ if ( empty( $current_site_name ) && ! empty( $sites ) ) {
}
$thumb_url = get_the_post_thumbnail_url( $slide->ID, 'thumbnail' );
?>
<div class="hssm-slide-item">
<div class="hssm-slide-item<?php echo ( (int) $slide->ID === (int) $request['slide_id'] ) ? ' hssm-slide-item-focus' : ''; ?>">
<div class="hssm-slide-info">
<div class="hssm-list-slide-title">
<?php echo esc_html( get_the_title( $slide ) ); ?>
@@ -467,9 +566,9 @@ if ( empty( $current_site_name ) && ! empty( $sites ) ) {
<?php endif; ?>
</div>
<?php if ( $slide->post_status === 'pending' && current_user_can( 'edit_others_posts' ) ) : ?>
<?php if ( $slide->post_status === 'pending' && $can_approve ) : ?>
<div class="hssm-slide-actions hssm-mt-10">
<button type="button" class="hssm-btn hssm-btn-success hssm-approve-slide" data-id="<?php echo esc_attr( $slide->ID ); ?>">
<button type="button" class="hssm-btn hssm-btn-success hssm-approve-slide" data-id="<?php echo esc_attr( $slide->ID ); ?>" data-approve-action="schedule">
<span class="dashicons dashicons-yes"></span> <?php esc_html_e( 'Approve Slide', 'hi-school-slide-manager' ); ?>
</button>
</div>