-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextrachill-news-wire.php
More file actions
127 lines (113 loc) · 4.53 KB
/
Copy pathextrachill-news-wire.php
File metadata and controls
127 lines (113 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/**
* Plugin Name: Extra Chill News Wire
* Description: Festival Wire custom post type and functionality for music festival coverage with fast-loading archives and template overrides.
* Version: 0.5.2
* Author: Chris Huber
* Text Domain: extrachill
* Domain Path: /languages
*
* @package ExtraChillNewsWire
* @since 0.1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'FESTIVAL_WIRE_PLUGIN_DIR', plugin_dir_path(__FILE__) );
define( 'FESTIVAL_WIRE_INCLUDE_DIR', FESTIVAL_WIRE_PLUGIN_DIR . 'includes/' );
define( 'FESTIVAL_WIRE_TEMPLATE_DIR', FESTIVAL_WIRE_PLUGIN_DIR . 'templates/' );
require_once FESTIVAL_WIRE_INCLUDE_DIR . 'festival-wire-post-type.php';
require_once FESTIVAL_WIRE_INCLUDE_DIR . 'festival-wire-query-filters.php';
require_once FESTIVAL_WIRE_INCLUDE_DIR . 'festival-metadata.php';
require_once FESTIVAL_WIRE_INCLUDE_DIR . 'festival-wire-notifications.php';
require_once FESTIVAL_WIRE_INCLUDE_DIR . 'recent-activity-ability.php';
require_once FESTIVAL_WIRE_INCLUDE_DIR . 'theme-integration.php';
require_once FESTIVAL_WIRE_INCLUDE_DIR . 'core/breadcrumbs.php';
require_once FESTIVAL_WIRE_INCLUDE_DIR . 'core/post-meta.php';
require_once FESTIVAL_WIRE_INCLUDE_DIR . 'core/festival-term-meta.php';
require_once FESTIVAL_WIRE_INCLUDE_DIR . 'core/festival-hub-header.php';
require_once FESTIVAL_WIRE_INCLUDE_DIR . 'core/network-bridge.php';
function enqueue_festival_wire_assets() {
global $wp_query;
$wire_site_url = function_exists( 'ec_get_site_url' ) ? ec_get_site_url( 'wire' ) : null;
// Archive pages: Load CSS and JS
if ( is_post_type_archive( 'festival_wire' ) || ( $wire_site_url && ( is_front_page() || is_home() ) && untrailingslashit( home_url() ) === untrailingslashit( $wire_site_url ) ) ) {
// Main Festival Wire CSS
$css_file_path = plugin_dir_path(__FILE__) . 'assets/festival-wire.css';
$css_file_uri = plugin_dir_url(__FILE__) . 'assets/festival-wire.css';
if ( file_exists( $css_file_path ) ) {
wp_enqueue_style(
'extrachill-festival-wire',
$css_file_uri,
array( 'extrachill-root', 'extrachill-style' ),
filemtime( $css_file_path )
);
}
// Festival Wire JavaScript (filters and FAQ accordion).
// Distinct handle from the stylesheet; the script is a self-contained
// IIFE with no JavaScript dependencies, so it declares none. The theme
// handles extrachill-root / extrachill-style are stylesheet handles and
// must never be passed as script dependencies.
$js_file_path = plugin_dir_path(__FILE__) . 'assets/festival-wire.js';
$js_file_uri = plugin_dir_url(__FILE__) . 'assets/festival-wire.js';
if ( file_exists( $js_file_path ) ) {
wp_enqueue_script(
'extrachill-festival-wire-script',
$js_file_uri,
array(),
filemtime( $js_file_path ),
true
);
}
} elseif ( is_singular( 'festival_wire' ) ) {
// Single pages: Load CSS only
$css_file_path = plugin_dir_path(__FILE__) . 'assets/festival-wire.css';
$css_file_uri = plugin_dir_url(__FILE__) . 'assets/festival-wire.css';
if ( file_exists( $css_file_path ) ) {
wp_enqueue_style(
'extrachill-festival-wire',
$css_file_uri,
array(),
filemtime( $css_file_path )
);
}
}
}
add_action( 'wp_enqueue_scripts', 'enqueue_festival_wire_assets' );
add_filter( 'extrachill_template_archive', 'ec_news_wire_override_archive_template' );
add_filter( 'extrachill_template_single_post', 'ec_news_wire_override_single_template' );
add_action( 'extrachill_homepage_content', 'ec_news_wire_render_wire_hub_homepage' );
/**
* Override archive template for festival_wire post type
*
* @param string $template Default template path from theme
* @return string Template path to use
*/
function ec_news_wire_override_archive_template( $template ) {
if ( is_post_type_archive( 'festival_wire' ) ) {
return FESTIVAL_WIRE_TEMPLATE_DIR . 'archive-festival_wire.php';
}
return $template;
}
/**
* Override single template for festival_wire post type
*
* @param string $template Default template path from theme
* @return string Template path to use
*/
function ec_news_wire_override_single_template( $template ) {
if ( is_singular( 'festival_wire' ) ) {
return FESTIVAL_WIRE_TEMPLATE_DIR . 'single-festival_wire.php';
}
return $template;
}
function ec_news_wire_render_wire_hub_homepage() {
if ( ! is_front_page() && ! is_home() ) {
return;
}
$wire_site_url = function_exists( 'ec_get_site_url' ) ? ec_get_site_url( 'wire' ) : '';
if ( ! $wire_site_url || untrailingslashit( home_url() ) !== untrailingslashit( $wire_site_url ) ) {
return;
}
require FESTIVAL_WIRE_TEMPLATE_DIR . 'home-wire.php';
}