| @@ -2,9 +2,9 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Plugin Name: WpStream - Live Streaming, Video on Demand, Pay Per View |
| 4 | 4 | * Plugin URI: http://wpstream.net |
| 5 | 5 | * Description: WpStream is a platform that allows you to live stream, create Video-on-Demand, and offer Pay-Per-View videos. We provide an affordable and user-friendly way for businesses, non-profits, and public institutions to broadcast their content and monetize their work. |
| 6 | - * Version: 4.13.2 | |
| 6 | + * Version: 4.8.2 | |
| 7 | 7 | * Author: wpstream |
| 8 | 8 | * Author URI: http://wpstream.net |
| 9 | 9 | * Text Domain: wpstream |
| 10 | 10 | * Domain Path: /languages/ |
| @@ -9,78 +9,27 @@ | ||
| 9 | 9 | * Text Domain: wpstream |
| 10 | 10 | * Domain Path: /languages/ |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | -/** | |
| 14 | - * Main plugin bootstrap file for WpStream. | |
| 15 | - * | |
| 16 | - * WordPress reads the header comment above to list the plugin. This file then | |
| 17 | - * defines the plugin's global constants (version, remote API/player/click host | |
| 18 | - * URLs, path helpers), wires activation/deactivation hooks, schedules a daily | |
| 19 | - * log cleanup cron event, loads the core plugin class plus the Elementor and | |
| 20 | - * streamify integrations, conditionally loads the hello-wpstream theme | |
| 21 | - * framework, registers the custom broadcaster-page rewrite endpoint, and finally | |
| 22 | - * instantiates and runs the Wpstream class. | |
| 23 | - * | |
| 24 | - * @package Wpstream | |
| 25 | - */ | |
| 26 | - | |
| 27 | 13 | // If this file is called directly, abort. |
| 28 | -// WPINC is defined by WordPress core; its absence means direct access. | |
| 29 | 14 | if ( ! defined( 'WPINC' ) ) { |
| 30 | 15 | die; |
| 31 | 16 | } |
| 32 | -// Current plugin version (kept in sync with the header "Version" field above). | |
| 33 | -define('WPSTREAM_PLUGIN_VERSION', '4.13.2'); | |
| 34 | -// Base host for WpStream account/club links. | |
| 17 | +define('WPSTREAM_PLUGIN_VERSION', '4.8.2'); | |
| 35 | 18 | define('WPSTREAM_CLUBLINK', 'wpstream.net'); |
| 36 | -// Scheme used when building club links. | |
| 37 | 19 | define('WPSTREAM_CLUBLINKSSL', 'https'); |
| 38 | -// URL to the site's plugins directory. | |
| 39 | 20 | define('WPSTREAM_PLUGIN_URL', plugins_url() ); |
| 40 | -// URL to this plugin's own directory. | |
| 41 | 21 | define('WPSTREAM_PLUGIN_DIR_URL', plugin_dir_url(__FILE__) ); |
| 42 | -// Filesystem path to this plugin's directory. | |
| 43 | 22 | define('WPSTREAM_PLUGIN_PATH', plugin_dir_path(__FILE__) ); |
| 44 | -// Plugin basename (folder/file) used for hook identification. | |
| 45 | 23 | define('WPSTREAM_PLUGIN_BASE', plugin_basename(__FILE__) ); |
| 46 | -// Remote WpStream API endpoint; guarded so it can be overridden before load. | |
| 47 | -if( !defined('WPSTREAM_API' ) ) { | |
| 48 | - // Default API host. | |
| 49 | - define('WPSTREAM_API', 'https://baker.wpstream.net'); | |
| 50 | -} | |
| 51 | -// Telemetry/click-tracking host; guarded so it can be overridden. | |
| 52 | -if ( !defined( 'WPSTREAM_CLICK' ) ) { | |
| 53 | - // Default click-tracking host. | |
| 54 | - define( 'WPSTREAM_CLICK', 'https://click.wpstream.net' ); | |
| 55 | -} | |
| 56 | -// Player host; guarded so it can be overridden. | |
| 57 | -if ( !defined( 'WPSTREAM_PLAYER') ) { | |
| 58 | - // Default player host. | |
| 59 | - define ( 'WPSTREAM_PLAYER', 'https://player.wpstream.net' ); | |
| 60 | -} | |
| 61 | -// Prefix for live player URLs; guarded so it can be overridden. | |
| 62 | -if ( !defined( 'LIVE_PLAYER_URL_PREFIX' ) ) { | |
| 63 | - // Default live player URL prefix. | |
| 64 | - define('LIVE_PLAYER_URL_PREFIX', 'https://player.wpstream.net/player/live'); | |
| 65 | -} | |
| 24 | +define('WPSTREAM_API', 'https://baker.wpstream.net'); | |
| 66 | 25 | |
| 67 | - | |
| 68 | -// Default network timeout (seconds) for remote API requests. | |
| 69 | 26 | define('WPSTREAM_TIMEOUT_CONST', 20); // in seconds |
| 70 | 27 | |
| 71 | -/** | |
| 72 | - * Cron callback that purges expired WpStream log entries. | |
| 73 | - * | |
| 74 | - * @return void | |
| 75 | - */ | |
| 76 | 28 | function wpstream_cleanup_logs_handler() { |
| 77 | - // Instantiate the logger. | |
| 78 | 29 | $logger = new WpStream_Logger(); |
| 79 | - // Delete log entries older than the retention window. | |
| 80 | 30 | $logger->clear_old_logs(); |
| 81 | 31 | } |
| 82 | -// Run the cleanup handler whenever the scheduled 'wpstream_log_cleanup' event fires. | |
| 83 | 32 | add_action('wpstream_log_cleanup', 'wpstream_cleanup_logs_handler'); |
| 84 | 33 | |
| 85 | 34 | /** |
| 86 | 35 | * The code that runs during plugin activation. |
| @@ -86,16 +35,12 @@ | ||
| 86 | 35 | * The code that runs during plugin activation. |
| 87 | 36 | * This action is documented in includes/class-wpstream-activator.php |
| 88 | 37 | */ |
| 89 | 38 | function activate_wpstream() { |
| 90 | - // Load the activator class on demand. | |
| 91 | 39 | require_once plugin_dir_path( __FILE__ ) . 'includes/class-wpstream-activator.php'; |
| 92 | - // Run the activation routine (creates DB tables, options, etc.). | |
| 93 | 40 | Wpstream_Activator::activate(); |
| 94 | 41 | |
| 95 | - // Schedule the daily log-cleanup cron event if it isn't already scheduled. | |
| 96 | 42 | if( !wp_next_scheduled( 'wpstream_log_cleanup' ) ) { |
| 97 | - // Register a daily recurring event starting now. | |
| 98 | 43 | wp_schedule_event( time(), 'daily', 'wpstream_log_cleanup' ); |
| 99 | 44 | } |
| 100 | 45 | } |
| 101 | 46 | |
| @@ -103,18 +48,14 @@ | ||
| 103 | 48 | * The code that runs during plugin deactivation. |
| 104 | 49 | * This action is documented in includes/class-wpstream-deactivator.php |
| 105 | 50 | */ |
| 106 | 51 | function deactivate_wpstream() { |
| 107 | - // Load the deactivator class on demand. | |
| 108 | 52 | require_once plugin_dir_path( __FILE__ ) . 'includes/class-wpstream-deactivator.php'; |
| 109 | - // Run the deactivation routine. | |
| 110 | 53 | Wpstream_Deactivator::deactivate(); |
| 111 | 54 | |
| 112 | - // Remove the scheduled daily log-cleanup cron event. | |
| 113 | 55 | wp_clear_scheduled_hook( 'wpstream_log_cleanup' ); |
| 114 | 56 | } |
| 115 | 57 | |
| 116 | -// Register the activation/deactivation callbacks with WordPress. | |
| 117 | 58 | register_activation_hook( __FILE__, 'activate_wpstream' ); |
| 118 | 59 | register_deactivation_hook( __FILE__, 'deactivate_wpstream' ); |
| 119 | 60 | |
| 120 | 61 | /** |
| @@ -121,13 +62,10 @@ | ||
| 121 | 62 | * Wrapper function for wpstream_dashboard_save_channel_data to be called from theme |
| 122 | 63 | * This provides backward compatibility for the theme |
| 123 | 64 | */ |
| 124 | 65 | function wpstream_dashboard_save_channel_data_plugin() { |
| 125 | - // Reach the global plugin instance created at the bottom of this file. | |
| 126 | 66 | global $wpstream_plugin; |
| 127 | - // Only delegate if the plugin and its AJAX handler are available. | |
| 128 | 67 | if (isset($wpstream_plugin) && isset($wpstream_plugin->wpstream_ajax)) { |
| 129 | - // Forward the call to the real AJAX save-channel handler. | |
| 130 | 68 | $wpstream_plugin->wpstream_ajax->wpstream_dashboard_save_channel_data(); |
| 131 | 69 | } |
| 132 | 70 | } |
| 133 | 71 | |
| @@ -134,32 +72,17 @@ | ||
| 134 | 72 | /** |
| 135 | 73 | * The core plugin class that is used to define internationalization, |
| 136 | 74 | * admin-specific hooks, and public-facing site hooks. |
| 137 | 75 | */ |
| 138 | -// Load the core plugin class (defines i18n, admin, and public hooks). | |
| 139 | 76 | require plugin_dir_path( __FILE__ ) . 'includes/class-wpstream.php'; |
| 140 | -// Load the Elementor requirement gate/integration. | |
| 141 | 77 | require plugin_dir_path( __FILE__ ) . 'wpstream-elementor.php'; |
| 142 | -// Load the streamify HLS proxy integration. | |
| 143 | 78 | require plugin_dir_path( __FILE__ ) . 'streamify/streamify.php'; |
| 144 | 79 | |
| 145 | -// Load third-party integrations bootstrap. | |
| 146 | 80 | require plugin_dir_path( __FILE__ ) . 'integrations/integrations.php'; |
| 147 | 81 | |
| 148 | -/** | |
| 149 | - * Load the bundled hello-wpstream theme framework files. | |
| 150 | - * | |
| 151 | - * Hooked to after_setup_theme so the theme's helper functions, post types, | |
| 152 | - * WooCommerce glue, widgets, and (when Elementor is active) Elementor pieces are | |
| 153 | - * available. Missing files are logged rather than fatal. | |
| 154 | - * | |
| 155 | - * @return void | |
| 156 | - */ | |
| 157 | 82 | function wpstream_load_theme_functionality() { |
| 158 | - // Absolute path to the bundled hello-wpstream framework directory. | |
| 159 | 83 | define ('WPSTREAM_FRAMEWORK_BASE', plugin_dir_path(__FILE__) . 'hello-wpstream' ); |
| 160 | 84 | |
| 161 | - // Framework files to load, relative to WPSTREAM_FRAMEWORK_BASE. | |
| 162 | 85 | $core_files = array( |
| 163 | 86 | '/framework/metaboxes.php', |
| 164 | 87 | '/framework/query-functions.php', |
| 165 | 88 | '/framework/wpstream-video-functions.php', |
| @@ -179,42 +102,30 @@ | ||
| 179 | 102 | '/framework/classes/class-wpstream_theme-social-login.php', |
| 180 | 103 | ); |
| 181 | 104 | |
| 182 | 105 | // Load core files |
| 183 | - // Include each framework file, or log it if the file is missing. | |
| 184 | 106 | foreach ( $core_files as $file ) { |
| 185 | - // Build the absolute path to this framework file. | |
| 186 | 107 | $file_path = WPSTREAM_FRAMEWORK_BASE . $file; |
| 187 | - // Include it if present; otherwise record the missing file. | |
| 188 | 108 | if ( file_exists( $file_path ) ) { |
| 189 | - // File exists: load it once. | |
| 190 | 109 | require_once $file_path; |
| 191 | 110 | } else { |
| 192 | - // File missing: log an error but keep loading the rest. | |
| 193 | 111 | error_log( 'Missing required file: ' . $file_path ); |
| 194 | 112 | } |
| 195 | 113 | } |
| 196 | 114 | |
| 197 | 115 | // Load Elementor integration if the plugin is active |
| 198 | - // ELEMENTOR_VERSION is only defined when Elementor is loaded. | |
| 199 | 116 | if ( defined( 'ELEMENTOR_VERSION' ) ) { |
| 200 | 117 | |
| 201 | - // Additional framework files needed only for the Elementor integration. | |
| 202 | 118 | $elementor_files = array( |
| 203 | 119 | '/elementor/functions/blog_functions.php', |
| 204 | 120 | '/elementor/wpstream-elementor.php' |
| 205 | 121 | ); |
| 206 | 122 | |
| 207 | - // Include each Elementor file, or log it if missing. | |
| 208 | 123 | foreach ( $elementor_files as $file ) { |
| 209 | - // Build the absolute path to this Elementor file. | |
| 210 | 124 | $file_path = WPSTREAM_FRAMEWORK_BASE . $file; |
| 211 | - // Include it if present; otherwise record the missing file. | |
| 212 | 125 | if ( file_exists( $file_path ) ) { |
| 213 | - // File exists: load it once. | |
| 214 | 126 | require_once $file_path; |
| 215 | 127 | } else { |
| 216 | - // File missing: log an error but keep loading the rest. | |
| 217 | 128 | error_log( 'Missing required file: ' . $file_path ); |
| 218 | 129 | } |
| 219 | 130 | } |
| 220 | 131 | } |
| @@ -219,9 +130,8 @@ | ||
| 219 | 130 | } |
| 220 | 131 | } |
| 221 | 132 | } |
| 222 | 133 | |
| 223 | -// Load the theme framework after the active theme is set up. | |
| 224 | 134 | add_action( 'after_setup_theme', 'wpstream_load_theme_functionality' ); |
| 225 | 135 | |
| 226 | 136 | /** |
| 227 | 137 | * Load js for players |
| @@ -227,24 +137,14 @@ | ||
| 227 | 137 | * Load js for players |
| 228 | 138 | * |
| 229 | 139 | * @return void |
| 230 | 140 | */ |
| 231 | -// Guard the definition so the theme can define its own version without collision. | |
| 232 | 141 | if ( ! function_exists( 'wpstream_load_player_js_on_demand' ) ) { |
| 233 | - /** | |
| 234 | - * Enqueue player scripts only when unit cards are configured to use video. | |
| 235 | - * | |
| 236 | - * @return void | |
| 237 | - */ | |
| 238 | 142 | function wpstream_load_player_js_on_demand() |
| 239 | 143 | { |
| 240 | - // Read the customizer setting that toggles video previews on unit cards. | |
| 241 | 144 | $wpstream_unit_card_use_video = get_theme_mod('wpstream_unit_card_use_video'); |
| 242 | - // Only enqueue the player assets when that setting is enabled. | |
| 243 | 145 | if ($wpstream_unit_card_use_video) { |
| 244 | - // Video.js core. | |
| 245 | 146 | wp_enqueue_script('video.min'); |
| 246 | - // WpStream player wrapper script. | |
| 247 | 147 | wp_enqueue_script('wpstream-player'); |
| 248 | 148 | } |
| 249 | 149 | |
| 250 | 150 | } |
| @@ -259,44 +159,25 @@ | ||
| 259 | 159 | * |
| 260 | 160 | * @since 3.0.1 |
| 261 | 161 | */ |
| 262 | 162 | |
| 263 | -// Expose the plugin instance globally so themes/helpers can reach it. | |
| 264 | 163 | global $wpstream_plugin; |
| 265 | -// Build the core plugin object. | |
| 266 | 164 | $wpstream_plugin = new Wpstream(); |
| 267 | -// Register all of the plugin's hooks and start it running. | |
| 268 | 165 | $wpstream_plugin->run(); |
| 269 | 166 | |
| 270 | -// After any core/plugin/theme update completes, run our upgrade cleanup. | |
| 271 | 167 | add_action( 'upgrader_process_complete', 'wpstream_my_upgrate_function',10, 2); |
| 272 | 168 | |
| 273 | -/** | |
| 274 | - * Clear cached API token data after this plugin is updated. | |
| 275 | - * | |
| 276 | - * @param WP_Upgrader $upgrader_object The upgrader instance (unused). | |
| 277 | - * @param array $options Details about what was upgraded. | |
| 278 | - * @return void | |
| 279 | - */ | |
| 280 | 169 | function wpstream_my_upgrate_function( $upgrader_object, $options ) { |
| 281 | 170 | |
| 282 | - | |
| 283 | - // This plugin's basename, used to detect if it was among the updated plugins. | |
| 171 | + | |
| 284 | 172 | $current_plugin_path_name = plugin_basename( __FILE__ ); |
| 285 | - | |
| 286 | - // Only act on plugin update operations. | |
| 173 | + | |
| 287 | 174 | if ($options['action'] == 'update' && $options['type'] == 'plugin' ) { |
| 288 | - // Guard against a missing/non-array options payload. | |
| 289 | 175 | if(is_array($options)): |
| 290 | - // Inspect every plugin that was updated in this batch. | |
| 291 | 176 | foreach($options['plugins'] as $each_plugin) { |
| 292 | - // Match against this plugin. | |
| 293 | 177 | if ($each_plugin==$current_plugin_path_name) { |
| 294 | - // Drop the cached API token transient. | |
| 295 | 178 | delete_transient('wpstream_token_api'); |
| 296 | - // Reset the stored token expiry timestamp. | |
| 297 | 179 | update_option('wp_estate_token_expire',0); |
| 298 | - // Blank out the stored current token. | |
| 299 | 180 | update_option('wp_estate_curent_token',' '); |
| 300 | 181 | |
| 301 | 182 | } |
| 302 | 183 | } |
| @@ -301,34 +182,23 @@ | ||
| 301 | 182 | } |
| 302 | 183 | } |
| 303 | 184 | endif; |
| 304 | 185 | } |
| 305 | - | |
| 306 | - | |
| 186 | + | |
| 187 | + | |
| 307 | 188 | } |
| 308 | 189 | |
| 309 | 190 | |
| 310 | 191 | |
| 311 | -// Inject Open Graph share meta tags into the document head. | |
| 312 | 192 | add_action('wp_head', 'wpstream_add_custom_meta_to_header'); |
| 313 | 193 | |
| 314 | -/** | |
| 315 | - * Output Open Graph meta tags on product / stream / VOD single pages. | |
| 316 | - * | |
| 317 | - * @return void | |
| 318 | - */ | |
| 319 | 194 | function wpstream_add_custom_meta_to_header(){ |
| 320 | - // The current post being displayed. | |
| 321 | 195 | global $post; |
| 322 | 196 | |
| 323 | 197 | |
| 324 | - // Only add share tags on WooCommerce product and WpStream product/VOD singles. | |
| 325 | 198 | if ( is_singular('product') || is_singular('wpstream_product') || is_singular('wpstream_product_vod') ){ |
| 326 | - // Featured image attachment ID for this post. | |
| 327 | 199 | $image_id = get_post_thumbnail_id(); |
| 328 | - // Full-size image source array ([0] is the URL) for og:image. | |
| 329 | 200 | $share_img = wp_get_attachment_image_src( $image_id, 'full'); |
| 330 | - // Full post object, used for the description below. | |
| 331 | 201 | $the_post = get_post($post->ID); ?> |
| 332 | 202 | |
| 333 | 203 | <meta property='og:title' content="<?php print esc_html(get_the_title($post->ID)); ?>"/> |
| 334 | 204 | <?php if(isset($share_img[0])){ ?> |
| @@ -347,24 +217,14 @@ | ||
| 347 | 217 | * |
| 348 | 218 | * Check integrations |
| 349 | 219 | * |
| 350 | 220 | */ |
| 351 | -// Only wire the One Click Demo Import (OCDI) hooks when the hello-wpstream theme is active. | |
| 352 | -if ( get_template() === 'hello-wpstream' ) { | |
| 353 | - // Load the theme-import helper functions referenced by the filters below. | |
| 354 | - require_once plugin_dir_path( __FILE__ ) . 'integrations/hello-wpstream/theme-import.php'; | |
| 355 | - // Register the set of demo import files offered by OCDI. | |
| 356 | - add_filter( 'pt-ocdi/import_files', 'wpstream_ocdi_import_files' ); | |
| 357 | - // Run post-import setup (menus, pages, options) after a demo import. | |
| 358 | - add_action( 'pt-ocdi/after_import', 'wpstream_ocdi_after_import_setup' ); | |
| 359 | - // Customize the intro text shown on the OCDI import screen. | |
| 360 | - add_filter( 'pt-ocdi/plugin_intro_text', 'wpstream_ocdi_plugin_intro_text' ); | |
| 361 | - // Send telemetry when a demo content import is attempted. | |
| 362 | - add_action( 'ocdi/before_content_import', 'wpstream_track_ocdi_import_attempt', 10, 1 ); | |
| 363 | -} | |
| 221 | +require_once plugin_dir_path(__FILE__) . 'integrations/hello-wpstream/theme-import.php'; | |
| 222 | +add_filter('pt-ocdi/import_files', 'ocdi_import_files'); | |
| 223 | +add_action('pt-ocdi/after_import', 'ocdi_after_import_setup'); | |
| 224 | +add_filter('pt-ocdi/plugin_intro_text', 'ocdi_plugin_intro_text'); | |
| 364 | 225 | |
| 365 | 226 | |
| 366 | -// Once all plugins are loaded, evaluate which integrations should run. | |
| 367 | 227 | add_action( 'plugins_loaded', 'wpstream_check_integrations' ); |
| 368 | 228 | |
| 369 | 229 | |
| 370 | 230 | /* |
| @@ -372,22 +232,13 @@ | ||
| 372 | 232 | * Redirect on plugin activation |
| 373 | 233 | * |
| 374 | 234 | */ |
| 375 | 235 | |
| 376 | -/** | |
| 377 | - * Redirect to the onboarding screen right after this plugin is activated. | |
| 378 | - * | |
| 379 | - * @param string $plugin Basename of the plugin that was just activated. | |
| 380 | - * @return void | |
| 381 | - */ | |
| 382 | 236 | function wpstream_activation_redirect( $plugin ) { |
| 383 | - // Only redirect when it is this plugin that was activated. | |
| 384 | 237 | if( $plugin == plugin_basename( __FILE__ ) ) { |
| 385 | - // Send the admin to the onboarding page and stop further execution. | |
| 386 | 238 | exit( wp_redirect( admin_url( 'admin.php?page=wpstream_onboard' ) ) ); |
| 387 | 239 | } |
| 388 | 240 | } |
| 389 | -// Fire the redirect on the activated_plugin hook. | |
| 390 | 241 | add_action( 'activated_plugin', 'wpstream_activation_redirect' ); |
| 391 | 242 | |
| 392 | 243 | |
| 393 | 244 | |
| @@ -395,30 +246,24 @@ | ||
| 395 | 246 | * |
| 396 | 247 | * remove the style selectWoo for the theme |
| 397 | 248 | * |
| 398 | 249 | */ |
| 399 | -// The existence of wpstream_get_author_id signals the wpstream theme is active. | |
| 400 | 250 | if ( function_exists( 'wpstream_get_author_id' ) ) { |
| 401 | 251 | // only if wpstream-theme is activated |
| 402 | - | |
| 252 | + | |
| 403 | 253 | remove_filter( 'pre_user_description', 'wp_filter_kses' ); // Removes the filter that applies KSES filtering for user descriptions |
| 404 | 254 | remove_filter( 'term_description', 'wp_kses_data' ); // Removes the filter that applies KSES data filtering for term descriptions |
| 405 | 255 | |
| 406 | - // Define the Select2 dequeue callback only once (guard against redefinition). | |
| 407 | 256 | if ( ! function_exists( 'wsis_dequeue_stylesandscripts_select2' ) ) { |
| 408 | - // Run the dequeue late (priority 100) so it overrides earlier enqueues. | |
| 409 | 257 | add_action( 'wp_enqueue_scripts', 'wsis_dequeue_stylesandscripts_select2', 100 ); |
| 410 | 258 | /** |
| 411 | 259 | * Remove CSS and/or JS for Select2 used by WooCommerce |
| 412 | 260 | */ |
| 413 | 261 | function wsis_dequeue_stylesandscripts_select2() { |
| 414 | - // Only relevant when WooCommerce is present. | |
| 415 | 262 | if ( class_exists( 'woocommerce' ) ) { |
| 416 | - // Remove WooCommerce's selectWoo stylesheet. | |
| 417 | 263 | wp_dequeue_style( 'selectWoo' ); |
| 418 | 264 | wp_deregister_style( 'selectWoo' ); |
| 419 | 265 | |
| 420 | - // Remove WooCommerce's selectWoo script. | |
| 421 | 266 | wp_dequeue_script( 'selectWoo' ); |
| 422 | 267 | wp_deregister_script( 'selectWoo' ); |
| 423 | 268 | } |
| 424 | 269 | } |
| @@ -428,29 +273,20 @@ | ||
| 428 | 273 | /** |
| 429 | 274 | * Register broadcaster page endpoint |
| 430 | 275 | */ |
| 431 | 276 | function wpstream_register_broadcaster_endpoint() { |
| 432 | - // Register the query var that flags a broadcaster page request (0 or 1). | |
| 433 | 277 | add_rewrite_tag('%broadcaster_page%', '([0-1]{1})'); |
| 434 | - // Register the numeric channel-id query var. | |
| 435 | 278 | add_rewrite_tag('%channel_id%', '([0-9]+)'); |
| 436 | 279 | |
| 437 | - // Current stored rewrite rules, used to detect if our rule already exists. | |
| 438 | 280 | $rewrite_rules = get_option('rewrite_rules'); |
| 439 | - // Pretty-URL pattern: /broadcaster-page/{id}/ | |
| 440 | 281 | $rule_pattern = 'broadcaster-page/([0-9]+)/?$'; |
| 441 | - // Internal target that maps the captured id onto our query vars. | |
| 442 | 282 | $rule_target = 'index.php?broadcaster_page=1&channel_id=$matches[1]'; |
| 443 | 283 | |
| 444 | - // Add the rewrite rule at the top so it takes precedence. | |
| 445 | 284 | add_rewrite_rule($rule_pattern, $rule_target, 'top'); |
| 446 | - // Flush rules only when they are missing our pattern (avoids flushing every request). | |
| 447 | 285 | if ( !is_array($rewrite_rules) || !key_exists( $rule_pattern, $rewrite_rules ) ) { |
| 448 | - // Rebuild the rewrite rules so the new endpoint works immediately. | |
| 449 | 286 | flush_rewrite_rules(); |
| 450 | 287 | } |
| 451 | 288 | } |
| 452 | -// Register the broadcaster endpoint on every init. | |
| 453 | 289 | add_action('init', 'wpstream_register_broadcaster_endpoint'); |
| 454 | 290 | |
| 455 | 291 | /** |
| 456 | 292 | * Load broadcaster template when the custom endpoint is accessed |
| @@ -455,17 +291,14 @@ | ||
| 455 | 291 | /** |
| 456 | 292 | * Load broadcaster template when the custom endpoint is accessed |
| 457 | 293 | */ |
| 458 | 294 | function wpstream_load_broadcaster_template($template) { |
| 459 | - // When the broadcaster_page query var is set, serve our custom template. | |
| 460 | 295 | if (get_query_var('broadcaster_page') == 1) { |
| 461 | 296 | // Return the path to our broadcaster template |
| 462 | 297 | return plugin_dir_path(__FILE__) . 'templates/broadcaster-template.php'; |
| 463 | 298 | } |
| 464 | - // Otherwise fall back to the theme's normal template. | |
| 465 | 299 | return $template; |
| 466 | 300 | } |
| 467 | -// Intercept template selection to swap in the broadcaster template when needed. | |
| 468 | 301 | add_filter('template_include', 'wpstream_load_broadcaster_template'); |
| 469 | 302 | |
| 470 | 303 | /** |
| 471 | 304 | * Flush rewrite rules on plugin activation to ensure our endpoint works |
| @@ -470,11 +303,8 @@ | ||
| 470 | 303 | /** |
| 471 | 304 | * Flush rewrite rules on plugin activation to ensure our endpoint works |
| 472 | 305 | */ |
| 473 | 306 | function wpstream_flush_rewrite_rules() { |
| 474 | - // Register the endpoint's rewrite tags/rules first. | |
| 475 | 307 | wpstream_register_broadcaster_endpoint(); |
| 476 | - // Then flush so the new rules are active immediately after activation. | |
| 477 | 308 | flush_rewrite_rules(); |
| 478 | 309 | } |
| 479 | -// Ensure rewrite rules are flushed when the plugin is activated. | |
| 480 | 310 | register_activation_hook(__FILE__, 'wpstream_flush_rewrite_rules'); |