Skip to content

Commit 6403d35

Browse files
committed
House Keeping
2 parents 9e5b97b + 96fc288 commit 6403d35

File tree

8 files changed

+1766
-1520
lines changed

8 files changed

+1766
-1520
lines changed

plugins/osi-features/inc/classes/class-plugin.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ public function load_post_types() {
5252
Post_Type_Board_Member::get_instance();
5353
Post_Type_License::get_instance();
5454
Post_Type_Meeting_Minutes::get_instance();
55-
Post_Type_Press_Mentions::get_instance();
55+
56+
// Get instance and initialize Press Mentions
57+
$press_mentions = Post_Type_Press_Mentions::get_instance();
58+
$press_mentions->init();
5659

5760
}
5861

plugins/osi-features/inc/classes/post-types/class-post-type-press-mentions.php

Lines changed: 206 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,23 @@ class Post_Type_Press_Mentions extends Base {
2626
*/
2727
const LABEL = 'Press mentions';
2828

29+
/**
30+
* Initialize the class and set up hooks
31+
*/
32+
public function init() {
33+
\add_action( 'add_meta_boxes', array( $this, 'register_custom_fields' ) );
34+
\add_action( 'save_post_' . self::SLUG, array( $this, 'save_custom_fields' ), 10, 2 );
35+
\add_action( 'rest_api_init', array( $this, 'register_rest_fields' ) );
36+
}
37+
2938
/**
3039
* To get list of labels for post type.
3140
*
3241
* @return array
3342
*/
3443
public function get_labels() {
3544

36-
return [
45+
return array(
3746
'name' => __( 'Press mentions', 'osi-features' ),
3847
'singular_name' => __( 'Press mentions', 'osi-features' ),
3948
'all_items' => __( 'Press mentions', 'osi-features' ),
@@ -45,8 +54,7 @@ public function get_labels() {
4554
'search_items' => __( 'Search Press mentions', 'osi-features' ),
4655
'not_found' => __( 'No Press mentions found', 'osi-features' ),
4756
'not_found_in_trash' => __( 'No Press mentions found in Trash', 'osi-features' ),
48-
];
49-
57+
);
5058
}
5159

5260
/**
@@ -56,14 +64,205 @@ public function get_labels() {
5664
*/
5765
public function get_args() {
5866

59-
return [
67+
return array(
6068
'show_in_rest' => true,
6169
'public' => true,
6270
'has_archive' => true,
6371
'menu_position' => 6,
64-
'supports' => [ 'title', 'author', 'excerpt' ],
65-
'rewrite' => [ 'slug' => 'press-mentions', 'with_front' => false ]
66-
];
72+
'supports' => array( 'title', 'author', 'excerpt' ),
73+
'rewrite' => array(
74+
'slug' => 'press-mentions',
75+
'with_front' => false,
76+
),
77+
);
78+
}
79+
80+
/**
81+
* Register custom fields for press mentions
82+
*/
83+
public function register_custom_fields() {
84+
\add_meta_box(
85+
'press_mentions_meta_box',
86+
\__( 'Press Mention Details', 'osi-features' ),
87+
array( $this, 'render_meta_box' ),
88+
self::SLUG,
89+
'normal',
90+
'high'
91+
);
92+
}
93+
94+
/**
95+
* Render the meta box
96+
*
97+
* @param \WP_Post $post The post object
98+
*/
99+
public function render_meta_box( $post ) {
100+
\wp_nonce_field( 'press_mentions_meta_box', 'press_mentions_meta_box_nonce' );
101+
102+
$date_of_publication = \get_post_meta( $post->ID, 'date_of_publication', true );
103+
// Convert Ymd format to Y-m-d for the input field
104+
if ( ! empty( $date_of_publication ) ) {
105+
$date_of_publication = \DateTime::createFromFormat( 'Ymd', $date_of_publication )->format( 'Y-m-d' );
106+
}
107+
$article_url = \get_post_meta( $post->ID, 'article_url', true );
108+
109+
?>
110+
<div class="press-mentions-fields">
111+
<p>
112+
<label for="date_of_publication"><?php \esc_html_e( 'Date of Publication', 'osi-features' ); ?> *</label><br>
113+
<input
114+
type="date"
115+
id="date_of_publication"
116+
name="date_of_publication"
117+
value="<?php echo \esc_attr( $date_of_publication ); ?>"
118+
required
119+
data-first-day="1"
120+
>
121+
</p>
122+
<p>
123+
<label for="article_url"><?php \esc_html_e( 'Article URL', 'osi-features' ); ?> *</label><br>
124+
<input
125+
type="url"
126+
id="article_url"
127+
name="article_url"
128+
value="<?php echo \esc_url( $article_url ); ?>"
129+
required
130+
style="width: 100%;"
131+
>
132+
</p>
133+
</div>
134+
<?php
135+
}
136+
137+
/**
138+
* Save custom fields
139+
*
140+
* @param int $post_id The post ID
141+
* @param \WP_Post $post The post object
142+
*/
143+
public function save_custom_fields( $post_id, $post ) {
144+
if ( ! isset( $_POST['press_mentions_meta_box_nonce'] ) ) {
145+
return;
146+
}
147+
148+
if ( ! \wp_verify_nonce( $_POST['press_mentions_meta_box_nonce'], 'press_mentions_meta_box' ) ) {
149+
return;
150+
}
151+
152+
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
153+
return;
154+
}
155+
156+
if ( ! \current_user_can( 'edit_post', $post_id ) ) {
157+
return;
158+
}
159+
160+
// Save date of publication
161+
if ( isset( $_POST['date_of_publication'] ) ) {
162+
$date = \sanitize_text_field( $_POST['date_of_publication'] );
163+
// Convert to Ymd format
164+
$formatted_date = gmdate( 'Ymd', strtotime( $date ) );
165+
\update_post_meta( $post_id, 'date_of_publication', $formatted_date );
166+
}
167+
168+
// Save article URL
169+
if ( isset( $_POST['article_url'] ) ) {
170+
$url = \esc_url_raw( $_POST['article_url'] );
171+
\update_post_meta( $post_id, 'article_url', $url );
172+
}
173+
}
174+
175+
/**
176+
* Register REST API fields
177+
*/
178+
public function register_rest_fields() {
179+
\register_rest_field(
180+
self::SLUG,
181+
'date_of_publication',
182+
array(
183+
'get_callback' => function ( $post ) {
184+
return \get_post_meta( $post['id'], 'date_of_publication', true );
185+
},
186+
'update_callback' => function ( $value, $post ) {
187+
// Handle array input from Make.com
188+
$date_value = is_array( $value ) && ! empty( $value ) ? $value[0] : $value;
189+
if ( ! empty( $date_value ) ) {
190+
// Convert the date to Ymd format
191+
$formatted_date = gmdate( 'Ymd', strtotime( $date_value ) );
192+
\update_post_meta( $post->ID, 'date_of_publication', $formatted_date );
193+
}
194+
},
195+
'schema' => array(
196+
'type' => array( 'string', 'array' ),
197+
'items' => array( 'type' => 'string' ),
198+
'description' => 'Date of Publication in Ymd format',
199+
'required' => true,
200+
),
201+
),
202+
);
203+
204+
\register_rest_field(
205+
self::SLUG,
206+
'article_url',
207+
array(
208+
'get_callback' => function ( $post ) {
209+
return \get_post_meta( $post['id'], 'article_url', true );
210+
},
211+
'update_callback' => function ( $value, $post ) {
212+
// Handle array input from Make.com
213+
$url_value = is_array( $value ) && ! empty( $value ) ? $value[0] : $value;
214+
if ( ! empty( $url_value ) ) {
215+
\update_post_meta( $post->ID, 'article_url', \esc_url_raw( $url_value ) );
216+
}
217+
},
218+
'schema' => array(
219+
'type' => array( 'string', 'array' ),
220+
'items' => array( 'type' => 'string' ),
221+
'description' => 'Article URL',
222+
'required' => true,
223+
),
224+
),
225+
);
226+
227+
\register_rest_field(
228+
self::SLUG,
229+
'publication_name',
230+
array(
231+
'get_callback' => function ( $post ) {
232+
$terms = \get_the_terms( $post['id'], 'taxonomy-publication' );
233+
if ( ! empty( $terms ) && ! \is_wp_error( $terms ) ) {
234+
return $terms[0]->name;
235+
}
236+
return '';
237+
},
238+
'update_callback' => function ( $value, $post ) {
239+
// Handle array input from Make.com
240+
$pub_value = is_array( $value ) && ! empty( $value ) ? $value[0] : $value;
241+
if ( ! empty( $pub_value ) ) {
242+
$term = \get_term_by( 'name', $pub_value, 'taxonomy-publication' );
243+
244+
if ( ! $term ) {
245+
$new_term = \wp_insert_term( $pub_value, 'taxonomy-publication' );
246+
if ( ! \is_wp_error( $new_term ) ) {
247+
$term_id = $new_term['term_id'];
248+
}
249+
} else {
250+
$term_id = $term->term_id;
251+
}
67252

253+
if ( isset( $term_id ) ) {
254+
// Set the taxonomy term for the post
255+
\wp_set_object_terms( $post->ID, array( $term_id ), 'taxonomy-publication' );
256+
}
257+
}
258+
},
259+
'schema' => array(
260+
'type' => array( 'string', 'array' ),
261+
'items' => array( 'type' => 'string' ),
262+
'description' => 'Publication Name',
263+
'required' => true,
264+
),
265+
),
266+
);
68267
}
69268
}

plugins/osi-features/inc/classes/taxonomies/class-taxonomy-publication.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Taxonomy_Publication extends Base {
2828
*/
2929
public function get_labels() {
3030

31-
return [
31+
return array(
3232
'name' => _x( 'Publication', 'taxonomy general name', 'osi-features' ),
3333
'singular_name' => _x( 'Publication', 'taxonomy singular name', 'osi-features' ),
3434
'search_items' => __( 'Search Publication', 'osi-features' ),
@@ -45,8 +45,7 @@ public function get_labels() {
4545
'choose_from_most_used' => __( 'Choose from the most used Publications', 'osi-features' ),
4646
'not_found' => __( 'No Publication found.', 'osi-features' ),
4747
'menu_name' => __( 'Publications', 'osi-features' ),
48-
];
49-
48+
);
5049
}
5150

5251
/**
@@ -56,10 +55,9 @@ public function get_labels() {
5655
*/
5756
public function get_post_types() {
5857

59-
return [
58+
return array(
6059
Post_Type_Press_Mentions::get_instance()->get_slug(),
61-
];
62-
60+
);
6361
}
6462

6563
/**
@@ -68,18 +66,17 @@ public function get_post_types() {
6866
* @return array
6967
*/
7068
public function get_args() {
71-
72-
return wp_parse_args(
73-
[
69+
70+
return wp_parse_args(
71+
array(
7472
'hierarchical' => true,
73+
'show_in_rest' => true,
7574
'rewrite' => array(
76-
'slug' => 'publication',
75+
'slug' => 'publication',
7776
'with_front' => false,
7877
),
79-
80-
],
78+
),
8179
parent::get_args()
8280
);
8381
}
84-
8582
}

plugins/osi-features/inc/classes/taxonomies/class-taxonomy-status.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,20 @@ public function get_post_types() {
6868
* @return array
6969
*/
7070
public function get_args() {
71-
72-
return wp_parse_args(
73-
[
74-
'hierarchical' => false,
75-
'rewrite' => array(
76-
'slug' => 'about/board-of-directors',
77-
'with_front' => false,
78-
'hierarchical' => false,
79-
),
80-
],
71+
return wp_parse_args(
72+
array(
73+
'hierarchical' => false,
74+
'rewrite' => false,
75+
'public' => false,
76+
'publicly_queryable' => true,
77+
'show_ui' => true,
78+
'show_in_menu' => true,
79+
'show_in_nav_menus' => false,
80+
'show_in_rest' => true,
81+
'show_admin_column' => true,
82+
'query_var' => true,
83+
),
8184
parent::get_args()
8285
);
8386
}
84-
8587
}

themes/osi/functions.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,3 +592,20 @@ function osi_full_width_editor( array $editor_settings ): array {
592592
return $editor_settings;
593593
}
594594
add_filter( 'block_editor_settings_all', 'osi_full_width_editor' );
595+
596+
add_filter( 'jetpack_disable_tracking', '__return_true' );
597+
598+
/**
599+
* Modify the post type arguments for the podcast post type.
600+
*
601+
* @param array $args The post type arguments.
602+
*
603+
* @return array The modified post type arguments.
604+
*/
605+
function osi_ssp_register_post_type_args( array $args ): array {
606+
$args['rewrite']['slug'] = 'ai';
607+
$args['rewrite']['with_front'] = false;
608+
return $args;
609+
}
610+
add_filter( 'ssp_register_post_type_args', 'osi_ssp_register_post_type_args', 10, 1 );
611+

themes/osi/template-parts/breadcrumbs.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,31 @@
88
$post_type = is_page() ? 'page' : get_query_var( 'post_type' );
99
$is_post_type_hierarchical = is_post_type_hierarchical( $post_type );
1010

11+
// Special handling for podcast post type
12+
if ( $post_type === 'podcast' ) {
13+
$breadcrumb = '';
14+
$position = 1;
15+
$podcast_archive_url = home_url( '/ai/podcast/' );
16+
17+
if ( is_archive() || is_post_type_archive( 'podcast' ) ) {
18+
$breadcrumb .= '<span class="current-page" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><meta itemprop="position" content="' . esc_attr( $position ) . '"><span itemprop="name">Podcast</span></span>';
19+
} else {
20+
$breadcrumb .= '<span itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><meta itemprop="position" content="' . esc_attr( $position ) . '"><a href="' . esc_url( $podcast_archive_url ) . '" itemprop="item"><span itemprop="name">Podcast</span></a></span>';
21+
++$position;
22+
23+
$post_id = get_queried_object_id();
24+
$breadcrumb .= '<span class="current-page" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><meta itemprop="position" content="' . esc_attr( $position ) . '"><span itemprop="name">' . esc_html( get_the_title( $post_id ) ) . '</span></span>';
25+
}
26+
27+
$home = '<span itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><meta itemprop="position" content="0"><a href="' . esc_url( home_url( '/' ) ) . '" class="home-link" itemprop="item" rel="home"><span itemprop="name">' . esc_html__( 'Home', 'jetpack' ) . '</span></a></span>';
28+
29+
echo '<nav class="entry-breadcrumbs" itemscope itemtype="https://schema.org/BreadcrumbList">' . $home . $breadcrumb . '</nav>'; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
30+
echo '</div></div>'; // Close the breadcrumb area
31+
return;
32+
}
33+
1134
if ( ! ( $is_post_type_hierarchical || $is_taxonomy_hierarchical ) || is_front_page() ) {
35+
echo '</div></div>'; // Close the breadcrumb area
1236
return;
1337
}
1438

0 commit comments

Comments
 (0)