forked from agucova/ppwp2-cl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
executable file
·191 lines (168 loc) · 5.68 KB
/
functions.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
<?php
/**
* PPWP2 functions and definitions
*
* @package PPWP2
*/
/**
* Custom functions that act independently of the theme templates.
*/
require get_stylesheet_directory() . '/inc/extras.php';
/**
* Enqueue all JS and CSS files
*/
require get_stylesheet_directory() . '/inc/scripts.php';
/**
* PPWP2 menu walker
*/
require get_stylesheet_directory() . '/inc/nav-walker-mdl.php';
/**
* Image render
*/
require get_stylesheet_directory() . '/inc/img-caption-shortcode.php';
/**
* Page finder
*/
function get_page_by_slug($path){
$page = get_page_by_path($path);
if (!empty($path)){
return get_permalink($page);
}
return "";
}
/**
* Register widget area.
*
* @link http://codex.wordpress.org/Function_Reference/register_sidebar
*/
function ppwp2_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Hero banner', 'ppwp2' ),
'id' => 'homepage-hero',
'description' => '',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
) );
register_sidebar( array(
'name' => esc_html__( 'Banner row 1', 'ppwp2' ),
'id' => 'homepage-banner-1',
'description' => '',
'before_widget' => '<div class="mdl-cell mdl-cell--4-col">',
'after_widget' => '</div>',
'before_title' => '<h1>',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => esc_html__( 'Banner row 2', 'ppwp2' ),
'id' => 'homepage-banner-2',
'description' => '',
'before_widget' => '<div class="mdl-cell mdl-cell--4-col">',
'after_widget' => '</div>',
'before_title' => '<h1>',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => esc_html__( 'Banner row 3', 'ppwp2' ),
'id' => 'homepage-banner-3',
'description' => '',
'before_widget' => '<div class="mdl-cell mdl-cell--4-col">',
'after_widget' => '</div>',
'before_title' => '<h1>',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => esc_html__( 'Banner row 4', 'ppwp2' ),
'id' => 'homepage-banner-4',
'description' => '',
'before_widget' => '<div id="%1$s" class="mdl-mega-footer__drop-down-section footer-widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h1>',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer Authorisation', 'ppwp2' ),
'id' => 'footer-authorisation-1',
'description' => '',
'before_widget' => '<p>',
'after_widget' => '</p>',
'before_title' => '',
'after_title' => '',
) );
}
add_action( 'widgets_init', 'ppwp2_widgets_init' );
if ( ! function_exists( 'ppwp2_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
*/
function ppwp2_posted_on() {
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
$posted_on = sprintf(
esc_html_x( '%s', 'post date', 'mdlwp' ),
'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
);
$byline = sprintf(
esc_html_x( '%s', 'post author', 'mdlwp' ),
'<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
);
echo '<span class="posted-on">Posted on ' . $posted_on . '</span>'; // WPCS: XSS OK.
if ( comments_open() AND ! post_password_required() ) { ?>
<span class="sep"> | </span>
<span class="comments-link">
<?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'ppwp2' ) . '</span>', __( '<strong>1</strong> Reply', 'ppwp2' ), __( '<strong>%</strong> Replies', 'ppwp2' ) ); ?>
</span>
<?php
}
}
endif;
/**
* Remove jQuery Migrate warning
*/
add_action('wp_default_scripts', function ($scripts) {
if (!empty($scripts->registered['jquery'])) {
$scripts->registered['jquery']->deps = array_diff($scripts->registered['jquery']->deps, array('jquery-migrate'));
}
});
/**
* Add Pin.js script if widget is used
*/
function check_widget() {
if( is_active_widget( '', '', 'ppwp2_widget_quick_donate' ) ) { // check if search widget is used
wp_enqueue_script('', 'https://cdn.pin.net.au/pin.v2.js');
}
}
add_action( 'init', 'check_widget' );
/**
* Override the author of posts/pages to always be the Party.
*/
function f_the_author( $display_name ) {
// $display_name === string $authordata->display_name
if ( is_feed() ) {
return "Pirate Party Australia";
}
return "Pirate Party Australia";
}
add_filter( 'the_author', 'f_the_author', PHP_INT_MAX, 1 );
/**
* Register widgets.
*/
require get_stylesheet_directory() . '/inc/ppwp2-widget-authorisation.php';
require get_stylesheet_directory() . '/inc/ppwp2-widget-ship-party.php';
require get_stylesheet_directory() . '/inc/ppwp2-widget-data-retention.php';
require get_stylesheet_directory() . '/inc/ppwp2-widget-we-are-a-movement.php';
require get_stylesheet_directory() . '/inc/ppwp2-widget-discussion-boards.php';
require get_stylesheet_directory() . '/inc/ppwp2-widget-quick-donate.php';
require get_stylesheet_directory() . '/inc/ppwp2-widget-newsletter.php';
require get_stylesheet_directory() . '/inc/ppwp2-widget-upcoming-events.php';
require get_stylesheet_directory() . '/inc/ppwp2-hero-broken-politics.php';
require get_stylesheet_directory() . '/inc/ppwp2-hero-congress.php';