-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshare-wp-plugin.php
414 lines (322 loc) · 12.6 KB
/
share-wp-plugin.php
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
<?php
/*
Plugin Name: SHARE-research.org Plugin
Description: Custom, site specific code and widgets for SHARE-research.org. Contact [email protected] with questions.
*/
include_once( ABSPATH . 'wp-content/plugins/advanced-custom-fields-pro/acf.php' );
// =====================================================
//
// SECTIONAL NAVIGATION WIDGET
//
// =====================================================
class display_section_navigation extends WP_Widget {
function __construct() {
parent::__construct(
'display_section_navigation', // Widget base ID
__('Display Section Navigation', 'display_section_navigation_domain'), // Widget name in UI
array( 'description' => __( 'Displays subnavigation tree for the parent section.', 'display_section_navigation_domain' ), ) // Widget description
);
}
// Creating widget front-end
public function widget( $args, $instance ) {
global $post;
$section = get_post_type($post); // Get the post type (aka 'section')
$sectionObject = get_post_type_object($section); // Get the post type object
$sectionName = $sectionObject->labels->singular_name; // Get the section's name for rendering in markup
if ($sectionName === 'Page') { // In the case that the parent section is named "Page", give it a better name.
$sectionName = 'Pages';
}
$childpages = wp_list_pages(
array(
'authors' => '',
'child_of' => 0,
'date_format' => get_option('date_format'),
'depth' => 0,
'echo' => 1,
'exclude' => '',
'include' => '',
'link_after' => '',
'link_before' => '',
'post_type' => $section,
'post_status' => 'publish',
'show_date' => '',
'sort_column' => 'menu_order, post_title',
'sort_order' => '',
'title_li' => __('<h3>' . $sectionName . '</h3>'),
'walker' => ''
));
if ( $childpages ) { // If there are child pages, create a navigation list
$string = '<ul>' . $childpages . '</ul>';
}
// Echo front-end results
echo __( $string, 'display_section_navigation_domain' );
// echo $args['after_widget'];
}
// Widget Backend
public function form( $instance ) {
// Widget admin form
?>
<?php
}
// Updating widget replacing old instances with new
public function update( $new_instance, $old_instance ) {
$instance = array();
return $instance;
}
} // Class display_section_navigation ends here
// Register and load the widget
function display_section_navigation_load() {
register_widget( 'display_section_navigation' );
}
add_action( 'widgets_init', 'display_section_navigation_load' );
// =====================================================
//
// END SECTIONAL NAVIGATION WIDGET
//
// =====================================================
// =====================================================
//
// RELATED POSTS WIDGET
//
// =====================================================
class display_related_posts extends WP_Widget {
function __construct() {
parent::__construct(
'display_related_posts', // Widget base ID
__('Display Related Posts', 'display_related_posts_domain'), // Widget name in UI
array( 'description' => __( 'Displays posts related to a single News item automatically chosen based on tag similarity.', 'display_related_posts_domain' ), ) // Widget description
);
}
// Creating widget front-end
public function widget( $args, $instance ) {
if (is_single()) {
global $post;
$tags = wp_get_post_tags($post->ID);
// Post has tags, look for related posts
if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
// Construct a wp_query to find related posts by tags
$args=array(
'tag__in' => $tag_ids,
'post__not_in' => array($post->ID),
'posts_per_page'=> 2, // How many related posts should be displayed?
'ignore_sticky_posts'=> true
);
$my_query = new wp_query( $args );
$posts = '<li class="pagenav">';
$posts .= '<h3>Related Posts</h3>';
$posts .= '<ul class="related-posts">';
while( $my_query->have_posts() ) {
$my_query->the_post();
$posts .= '<li class="post">';
$posts .= '<span class="date">' . get_the_date('F j, Y') . '</span>';
$posts .= '<a class="post-title" href="' . get_the_permalink() . '">' . get_the_title() . '</a>';
$posts .= '<p class="excerpt">' . excerpt(20) . ' <a href="' . get_the_permalink() . '">... read more.</a></p>';
$posts .= '</li>';
}
$posts .= '</ul>';
$posts .= '</li>';
wp_reset_query();
$related_posts = array(
'has_posts' => true,
'posts' => $posts,
'tags' => $tags
);
}
// Echo front-end results
echo __( $related_posts['posts'], 'display_related_posts_domain' );
}
}
// Widget Backend
public function form( $instance ) {
// Widget admin form
?>
<?php
}
// Updating widget replacing old instances with new
public function update( $new_instance, $old_instance ) {
$instance = array();
return $instance;
}
} // Class display_related_posts ends here
// Register and load the widget
function display_related_posts_load() {
register_widget( 'display_related_posts' );
}
add_action( 'widgets_init', 'display_related_posts_load' );
// =====================================================
//
// END RELATED POSTS WIDGET
//
// =====================================================
// =====================================================
//
// KNOWLEDGE BASE NAVIGATION WIDGET
//
// =====================================================
class display_knowledge_base_navigation extends WP_Widget {
function __construct() {
parent::__construct(
'display_knowledge_base_navigation', // Widget base ID
__('Display Knowledge Domain Navigation', 'display_knowledge_base_navigation_domain'), // Widget name in UI
array( 'description' => __( 'Displays posts related to a single News item automatically chosen based on tag similarity.', 'display_knowledge_base_navigation_domain' ), ) // Widget description
);
}
// Creating widget front-end
public function widget( $args, $instance ) {
if (!is_search()) {
// Build subnavigation based on the section this knowledge domain is in
global $post;
$currentPageID = $post->ID;
$terms = wp_get_post_terms($post->ID, 'section');
foreach( $terms as $term ) :
$return = '<li class="pagenav knowledge-base-items">';
$return .= '<h3>' . $term->name . '</h3>';
$return .= '<ul>';
$posts = new WP_Query( "taxonomy=section&term=$term->slug" );
if( $posts->have_posts() ): while( $posts->have_posts() ) : $posts->the_post();
if (get_the_ID() === $currentPageID) { // Mark current item as active
$return .= '<li class="current_page_item">';
}
else {
$return .= '<li>';
}
$return .= '<a href="' . get_the_permalink() . '" title="' . get_the_title() . '" rel="bookmark">' . get_the_title() . '</a>';
$return .= '</li>';
endwhile; endif;
$return .= '<li><a href="' . get_bloginfo('url') . '/kb/" title="SHARE Knowledge Base">« SHARE Knowledge Base home</a></li>';
$return .= '</ul>';
$return .= '</li>';
endforeach;
}
// Sidbar for Knowledge Base search results
else {
$return = '<li class="pagenav knowledge-base-items">';
$return .= '<h3>Knowledge Base</h3>';
$return .= '<a href="' . get_bloginfo('url') . '/kb/" title="SHARE Knowledge Base">« SHARE Knowledge Base home</a>';
$return .= '</li>';
}
// Echo front-end results
echo __( $return, 'display_knowledge_base_navigation_domain' );
}
// Widget Backend
public function form( $instance ) {
// Widget admin form
?>
<?php
}
// Updating widget replacing old instances with new
public function update( $new_instance, $old_instance ) {
$instance = array();
return $instance;
}
} // Class display_knowledge_base_navigation ends here
// Register and load the widget
function display_knowledge_base_navigation_load() {
register_widget( 'display_knowledge_base_navigation' );
}
add_action( 'widgets_init', 'display_knowledge_base_navigation_load' );
// =====================================================
//
// END KNOWLEDGE BASE NAVIGATION WIDGET
//
// =====================================================
// =====================================================
//
// CONTACT INFORMATION WIDGET
//
// =====================================================
class display_contact_information extends WP_Widget {
function __construct() {
parent::__construct(
'display_contact_information', // Widget base ID
__('Display Contact Information', 'display_contact_information_domain'), // Widget name in UI
array( 'description' => __( 'Displays contact information and social media icons included on the Site-wide Options page.', 'display_contact_information_domain' ), ) // Widget description
);
}
// Creating widget front-end
public function widget( $args, $instance ) {
$return = '<li class="social-media">';
$return .= '<h3>Get In Touch</h3>';
$return .= '<address>' . get_field('address', 'option') . '</address>';
// Grab social media links from Site-wide Options page
if(get_field('social_media_links', 'option')):
$return .= '<ul class="social">';
while(has_sub_field('social_media_links', 'option')):
$return .= '<li><a href="' . get_sub_field('url') . '" target="_blank"><span class="ss-icon ss-' . get_sub_field('icon') . '"></span> ' . get_sub_field('title') . '</a></li>';
endwhile;
$return .= '</ul>';
endif;
$return .= '</li>';
// Echo front-end results
echo __( $return, 'display_contact_information_domain' );
}
// Widget Backend
public function form( $instance ) {
// Widget admin form
?>
<?php
}
// Updating widget replacing old instances with new
public function update( $new_instance, $old_instance ) {
$instance = array();
return $instance;
}
} // Class display_contact_information ends here
// Register and load the widget
function display_contact_information_load() {
register_widget( 'display_contact_information' );
}
add_action( 'widgets_init', 'display_contact_information_load' );
// =====================================================
//
// END CONTACT INFORMATION WIDGET
//
// =====================================================
// =====================================================
//
// TWITTER FEED WIDGET
//
// =====================================================
class twitter_feed extends WP_Widget {
function __construct() {
parent::__construct(
'twitter_feed', // Widget base ID
__('@SHARE_research Twitter Feed', 'twitter_feed_domain'), // Widget name in UI
array( 'description' => __( 'Displays recent tweets from @SHARE_research in the default Twitter embed.', 'twitter_feed_domain' ), ) // Widget description
);
}
// Creating widget front-end
public function widget( $args, $instance ) {
$return = '<li class="widget-container">';
$return .= '<h3>@SHARE_research</h3>';
$return .= '<a class="twitter-timeline" href="https://twitter.com/SHARE_research" data-widget-id="568555918565335040">Tweets by @SHARE_research</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?\'http\':\'https\';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>';
$return .= '</li>';
// Echo front-end results
echo __( $return, 'twitter_feed_domain' );
}
// Widget Backend
public function form( $instance ) {
// Widget admin form
?>
<?php
}
// Updating widget replacing old instances with new
public function update( $new_instance, $old_instance ) {
$instance = array();
return $instance;
}
} // Class twitter_feed ends here
// Register and load the widget
function twitter_feed_load() {
register_widget( 'twitter_feed' );
}
add_action( 'widgets_init', 'twitter_feed_load' );
// =====================================================
//
// END TWITTER FEED WIDGET
//
// =====================================================
?>