157 lines
4.7 KiB
PHP
157 lines
4.7 KiB
PHP
<?php
|
|
/**
|
|
* Plugin Name: Hi-School Slide Manager
|
|
* Plugin URI: https://hi-school.com/slide-manager
|
|
* Description: Multi-site slide management system for Hi-School websites. Allows staff to create and schedule slides on the main site, display them as headers on companion sites via REST API, with advanced preview and editing capabilities.
|
|
* Version: 1.1.9
|
|
* Author: Hi-School Development Team
|
|
* Author URI: https://hi-school.com
|
|
* License: GPL v2 or later
|
|
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
|
* Text Domain: hi-school-slide-manager
|
|
* Domain Path: /languages
|
|
* Network: false
|
|
* Requires at least: 5.0
|
|
* Tested up to: 6.4
|
|
* Requires PHP: 7.4
|
|
*/
|
|
|
|
// Prevent direct access
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit( 'Direct access forbidden.' );
|
|
}
|
|
|
|
// Plugin constants
|
|
define( 'HSSM_VERSION', '1.1.9' );
|
|
define( 'HSSM_PLUGIN_FILE', __FILE__ );
|
|
define( 'HSSM_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
|
define( 'HSSM_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
|
define( 'HSSM_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
|
|
|
// Database table names (if needed for future features)
|
|
// define( 'HSSM_SLIDES_TABLE', 'hssm_slides' );
|
|
// define( 'HSSM_SITES_TABLE', 'hssm_companion_sites' );
|
|
|
|
/**
|
|
* Write a debug log line only when WP_DEBUG and WP_DEBUG_LOG are enabled.
|
|
*
|
|
* @since 1.1.2
|
|
* @param mixed $message Message or data to log.
|
|
*/
|
|
function hssm_debug_log( $message ) {
|
|
if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG || ! defined( 'WP_DEBUG_LOG' ) || ! WP_DEBUG_LOG ) {
|
|
return;
|
|
}
|
|
|
|
if ( ! is_string( $message ) ) {
|
|
$message = print_r( $message, true );
|
|
}
|
|
|
|
error_log( 'HSSM: ' . $message );
|
|
}
|
|
|
|
/**
|
|
* Permalink for a published page using a plugin template.
|
|
*
|
|
* Prefers a matching slug, then any page with the template, including children.
|
|
* get_pages() with hierarchical=1 can skip child pages, so this uses WP_Query.
|
|
*
|
|
* @since 1.1.3
|
|
* @param string $template Page template filename.
|
|
* @param string $fallback_path Optional path used when no page is found.
|
|
* @return string
|
|
*/
|
|
function hssm_get_page_url_by_template( $template, $fallback_path = '' ) {
|
|
$preferred_slug = '';
|
|
if ( 'page-slide-preview.php' === $template ) {
|
|
$preferred_slug = 'slide-preview';
|
|
} elseif ( 'page-slide-dashboard.php' === $template ) {
|
|
$preferred_slug = 'slide-dashboard';
|
|
} elseif ( 'page-slide-confirmation.php' === $template ) {
|
|
$preferred_slug = 'slide-confirmation';
|
|
}
|
|
|
|
$query = new WP_Query(
|
|
array(
|
|
'post_type' => 'page',
|
|
'post_status' => array( 'publish', 'private' ),
|
|
'posts_per_page' => 20,
|
|
'no_found_rows' => true,
|
|
'meta_key' => '_wp_page_template',
|
|
'meta_value' => $template,
|
|
'orderby' => array(
|
|
'menu_order' => 'ASC',
|
|
'ID' => 'ASC',
|
|
),
|
|
)
|
|
);
|
|
|
|
$match = null;
|
|
if ( $query->have_posts() ) {
|
|
foreach ( $query->posts as $page ) {
|
|
if ( $preferred_slug && $preferred_slug === $page->post_name ) {
|
|
$match = $page;
|
|
break;
|
|
}
|
|
if ( ! $match ) {
|
|
$match = $page;
|
|
}
|
|
}
|
|
}
|
|
wp_reset_postdata();
|
|
|
|
if ( $match ) {
|
|
return get_permalink( $match->ID );
|
|
}
|
|
|
|
$path_candidates = array();
|
|
if ( $preferred_slug ) {
|
|
$path_candidates[] = 'slide-dashboard/' . $preferred_slug;
|
|
$path_candidates[] = $preferred_slug;
|
|
}
|
|
if ( $fallback_path ) {
|
|
$path_candidates[] = trim( $fallback_path, '/' );
|
|
}
|
|
|
|
foreach ( array_unique( $path_candidates ) as $path ) {
|
|
$page = get_page_by_path( $path );
|
|
if ( $page ) {
|
|
return get_permalink( $page->ID );
|
|
}
|
|
}
|
|
|
|
return $fallback_path ? home_url( $fallback_path ) : '';
|
|
}
|
|
|
|
// Include core files
|
|
require_once HSSM_PLUGIN_DIR . 'includes/class-hssm-autoloader.php';
|
|
require_once HSSM_PLUGIN_DIR . 'includes/class-hssm-main.php';
|
|
|
|
|
|
/**
|
|
* Initialize the Hi-School Slide Manager plugin
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
function hssm_init() {
|
|
// Check if we're on the main site (this plugin should only run on main site)
|
|
if ( is_multisite() && ! is_main_site() ) {
|
|
return;
|
|
}
|
|
|
|
// Initialize autoloader
|
|
HSSM_Autoloader::init();
|
|
|
|
// Get the main plugin instance and initialize
|
|
$hssm = HSSM_Main::get_instance();
|
|
$hssm->init();
|
|
}
|
|
|
|
// Hook into WordPress
|
|
add_action( 'plugins_loaded', 'hssm_init' );
|
|
|
|
// Activation and deactivation hooks
|
|
register_activation_hook( __FILE__, array( 'HSSM_Main', 'activate' ) );
|
|
register_deactivation_hook( __FILE__, array( 'HSSM_Main', 'deactivate' ) );
|
|
register_uninstall_hook( __FILE__, array( 'HSSM_Main', 'uninstall' ) );
|