1
1
<?php
2
2
class Certificates_Website {
3
- public static function set_certificates_logo ( ) {
3
+
4
+ public static function set_certificates_logo () {
4
5
return 'products/certificates.svg#certificates ' ;
5
6
}
6
- public static function set_certificates_logo_image_size ( ) {
7
+ public static function set_certificates_logo_image_size () {
7
8
return '215 40 ' ;
8
9
}
9
10
// Add a class to the page body to override styles from the base theme
10
11
public static function add_body_class ( $ classes ) {
11
- return array_merge ( $ classes , array ( 'creativecommons-certificate ' ) );
12
+ return array_merge ( $ classes , array ( 'creativecommons-certificate ' ) );
12
13
}
13
- public static function modify_breadcrumb_seperator ( ) {
14
+ public static function modify_breadcrumb_seperator () {
14
15
return '<i class="icon chevron-right is-6"></i> ' ;
15
16
}
16
- public static function get_upcoming_course_events ( ) {
17
- return [ 'wow ' ] ;
17
+ public static function get_upcoming_course_events () {
18
+ return array ( 'wow ' ) ;
18
19
}
19
20
public static function register_columns_shortcode ( $ atts , $ content ) {
20
- $ a = shortcode_atts ( array ( 'cols ' => '4 ' ), $ atts );
21
- return '<div class="cols" style="--col-count: ' . $ a ['cols ' ] . ';"> ' . $ content .'</div> ' ;
21
+ $ a = shortcode_atts ( array ( 'cols ' => '4 ' ), $ atts );
22
+ return '<div class="cols" style="--col-count: ' . $ a ['cols ' ] . ';"> ' . $ content . '</div> ' ;
22
23
}
23
24
public static function register_stats_shortcode ( $ atts , $ content ) {
24
- return '<div class="stats has-text-black"> ' . do_shortcode ($ content). '</div> ' ;
25
+ return '<div class="stats has-text-black"> ' . do_shortcode ( $ content ) . '</div> ' ;
25
26
}
26
27
public static function register_stat_shortcode ( $ atts , $ content ) {
27
- $ a = shortcode_atts ( array ( 'title ' => '' , 'number ' => '' , 'subtitle ' => '' ), $ atts );
28
- return '<div class="stat"><h3 class="title is-5"> ' .$ a ['title ' ].'</h3><span class="number has-text-weight-bold is-size-1"> ' .$ a ['number ' ].'</span><p class="caption has-text-weight-bold"> ' .$ a ['subtitle ' ].'</p></div> ' ;
28
+ $ a = shortcode_atts (
29
+ array (
30
+ 'title ' => '' ,
31
+ 'number ' => '' ,
32
+ 'subtitle ' => '' ,
33
+ ),
34
+ $ atts
35
+ );
36
+ return '<div class="stat"><h3 class="title is-5"> ' . $ a ['title ' ] . '</h3><span class="number has-text-weight-bold is-size-1"> ' . $ a ['number ' ] . '</span><p class="caption has-text-weight-bold"> ' . $ a ['subtitle ' ] . '</p></div> ' ;
29
37
}
30
38
// @todo: Make this do more (add colors)/throw this out and use the card somehow
31
39
public static function register_box_shortcode ( $ atts , $ content ) {
32
- return '<div class="has-background-grey-lighter padding-vertical-big padding-horizontal-bigger cc-box margin-bottom-larger"> ' . $ content. '</div> ' ;
40
+ return '<div class="has-background-grey-lighter padding-vertical-big padding-horizontal-bigger cc-box margin-bottom-larger"> ' . $ content . '</div> ' ;
33
41
}
34
42
// Pressbooks hides the WordPress Admin bar, but doesn't remove the empty space :/
35
- public static function remove_admin_bar_top_whitespace ( ) {
43
+ public static function remove_admin_bar_top_whitespace () {
36
44
if ( is_admin_bar_showing () ) {
37
- echo '<style type="text/css">html {margin-top: 0 !important;}</style> ' ;
45
+ echo '<style type="text/css">html {margin-top: 0 !important;}</style> ' ;
38
46
}
39
47
}
40
48
public static function add_alumni_login_button ( $ items , $ args ) {
41
49
if ( $ args ->theme_location == 'main-navigation ' ) {
42
- $ items .= '<div class="navbar-item"><a class="button alumni" href=" ' . get_page_link (788 ) .'"><svg class="margin-right-small" width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg">
50
+ $ items .= '<div class="navbar-item"><a class="button alumni" href=" ' . get_page_link ( 788 ) . '"><svg class="margin-right-small" width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg">
43
51
<path d="M5 5.625C6.55273 5.625 7.8125 4.36523 7.8125 2.8125C7.8125 1.25977 6.55273 0 5 0C3.44727 0 2.1875 1.25977 2.1875 2.8125C2.1875 4.36523 3.44727 5.625 5 5.625ZM7.5 6.25H6.42383C5.99023 6.44922 5.50781 6.5625 5 6.5625C4.49219 6.5625 4.01172 6.44922 3.57617 6.25H2.5C1.11914 6.25 0 7.36914 0 8.75V9.0625C0 9.58008 0.419922 10 0.9375 10H9.0625C9.58008 10 10 9.58008 10 9.0625V8.75C10 7.36914 8.88086 6.25 7.5 6.25Z" fill="#008000"/>
44
52
</svg>
45
53
Alumni</a></div> ' ;
@@ -51,16 +59,16 @@ public static function add_alumni_login_button( $items, $args ) {
51
59
// add filters
52
60
add_filter ( 'cc_theme_base_set_default_size_logo ' , array ( 'Certificates_Website ' , 'set_certificates_logo_image_size ' ) );
53
61
add_filter ( 'cc_theme_base_set_default_logo ' , array ( 'Certificates_Website ' , 'set_certificates_logo ' ) );
54
- add_filter ( 'body_class ' , array ( 'Certificates_Website ' , 'add_body_class ' ) );
55
- add_filter ( 'wpseo_breadcrumb_separator ' , array ( 'Certificates_Website ' , 'modify_breadcrumb_seperator ' ) );
56
- add_filter ( 'wp_head ' , array ( 'Certificates_Website ' , 'remove_admin_bar_top_whitespace ' ), 11 );
57
- add_filter ( 'wp_nav_menu_items ' , array ( 'Certificates_Website ' , 'add_alumni_login_button ' ), 10 , 2 );
62
+ add_filter ( 'body_class ' , array ( 'Certificates_Website ' , 'add_body_class ' ) );
63
+ add_filter ( 'wpseo_breadcrumb_separator ' , array ( 'Certificates_Website ' , 'modify_breadcrumb_seperator ' ) );
64
+ add_filter ( 'wp_head ' , array ( 'Certificates_Website ' , 'remove_admin_bar_top_whitespace ' ), 11 );
65
+ add_filter ( 'wp_nav_menu_items ' , array ( 'Certificates_Website ' , 'add_alumni_login_button ' ), 10 , 2 );
58
66
59
67
// Register shortcodes
60
- add_shortcode ( 'columns ' , array ( 'Certificates_Website ' , 'register_columns_shortcode ' ) );
61
- add_shortcode ( 'stats ' , array ( 'Certificates_Website ' , 'register_stats_shortcode ' ) );
62
- add_shortcode ( 'stat ' , array ( 'Certificates_Website ' , 'register_stat_shortcode ' ) );
63
- add_shortcode ( 'box ' , array ( 'Certificates_Website ' , 'register_box_shortcode ' ) );
68
+ add_shortcode ( 'columns ' , array ( 'Certificates_Website ' , 'register_columns_shortcode ' ) );
69
+ add_shortcode ( 'stats ' , array ( 'Certificates_Website ' , 'register_stats_shortcode ' ) );
70
+ add_shortcode ( 'stat ' , array ( 'Certificates_Website ' , 'register_stat_shortcode ' ) );
71
+ add_shortcode ( 'box ' , array ( 'Certificates_Website ' , 'register_box_shortcode ' ) );
64
72
65
73
/**
66
74
* Populate the 'Featured FAQs' dropdown on the homepage edit page with the actual FAQs.
@@ -69,29 +77,29 @@ function acf_load_featured_faq_choices( $field ) {
69
77
$ field ['choices ' ] = array ();
70
78
71
79
// @todo: FAQ page id is hardcoded here, find a way to make this dynamic
72
- $ faq_groups = get_field ('faq_group ' , 32 );
80
+ $ faq_groups = get_field ( 'faq_group ' , 32 );
73
81
74
- foreach ($ faq_groups as $ faqGroup ) {
75
- foreach ($ faqGroup ['questions ' ] as $ question ) {
76
- $ field ['choices ' ][$ question ['question ' ]] = $ question ['question ' ];
82
+ foreach ( $ faq_groups as $ faqGroup ) {
83
+ foreach ( $ faqGroup ['questions ' ] as $ question ) {
84
+ $ field ['choices ' ][ $ question ['question ' ] ] = $ question ['question ' ];
77
85
}
78
86
}
79
87
80
- return $ field ;
88
+ return $ field ;
81
89
};
82
90
83
91
add_filter ( 'acf/load_field/name=featured_faqs ' , 'acf_load_featured_faq_choices ' );
84
92
85
93
86
- function get_faqs_by_titles ($ titles = array (), $ faqs = array ()) {
94
+ function get_faqs_by_titles ( $ titles = array (), $ faqs = array () ) {
87
95
// @todo: FAQ page id is hardcoded here, find a way to make this dynamic
88
- $ faq_groups = get_field ('faq_group ' , 32 );
96
+ $ faq_groups = get_field ( 'faq_group ' , 32 );
89
97
$ filtered_faqs = array ();
90
98
91
- foreach ($ faq_groups as $ faq_group ) {
92
- foreach ($ faq_group ['questions ' ] as $ question ) {
93
- if ( in_array ($ question ['question ' ], $ titles) ) {
94
- array_push ($ filtered_faqs , $ question );
99
+ foreach ( $ faq_groups as $ faq_group ) {
100
+ foreach ( $ faq_group ['questions ' ] as $ question ) {
101
+ if ( in_array ( $ question ['question ' ], $ titles ) ) {
102
+ array_push ( $ filtered_faqs , $ question );
95
103
}
96
104
}
97
105
}
@@ -101,30 +109,30 @@ function get_faqs_by_titles($titles = array(), $faqs = array()) {
101
109
102
110
// @todo: Also store in transient (even if short)
103
111
function load_home_featured_posts () {
104
- $ url = 'https://creativecommons.org/wp-json/wp/v2/posts?per_page=50 ' ;
105
- $ media_url = 'https://creativecommons.org/wp-json/wp/v2/media ' ;
112
+ $ url = 'https://creativecommons.org/wp-json/wp/v2/posts?per_page=50 ' ;
113
+ $ media_url = 'https://creativecommons.org/wp-json/wp/v2/media ' ;
106
114
$ author_url = 'https://creativecommons.org/wp-json/wp/v2/users ' ;
107
115
108
116
$ transient_key = 'home_posts ' . $ url ;
109
117
110
118
foreach ( get_field ( 'featured_news ' , get_option ( 'page_on_front ' ) ) as $ news ) {
111
- if ($ news ['post_id ' ]) {
119
+ if ( $ news ['post_id ' ] ) {
112
120
$ url .= '&include[]= ' . $ news ['post_id ' ];
113
121
}
114
122
}
115
123
116
124
if ( false === ( $ results = get_transient ( $ transient_key ) ) ) {
117
125
118
- $ posts = query_api ($ url );
126
+ $ posts = query_api ( $ url );
119
127
120
- foreach ($ posts as $ post ) {
128
+ foreach ( $ posts as $ post ) {
121
129
// Attach featured image info
122
130
if ( ! empty ( $ post ->featured_media ) ) {
123
131
$ api_response = query_api ( $ media_url . '/ ' . $ post ->featured_media );
124
132
125
133
if ( ! empty ( $ api_response ) ) {
126
- $ post ->featured_media_url = $ api_response ->media_details ->sizes ->cc_list_post_thumbnail ->source_url ;
127
- $ post ->alt_text = $ api_response ->alt_text ;
134
+ $ post ->featured_media_url = $ api_response ->media_details ->sizes ->cc_list_post_thumbnail ->source_url ;
135
+ $ post ->alt_text = $ api_response ->alt_text ;
128
136
}
129
137
}
130
138
@@ -134,17 +142,17 @@ function load_home_featured_posts() {
134
142
135
143
if ( ! empty ( $ api_response ) ) {
136
144
$ post ->author_name = $ api_response ->name ;
137
- $ post ->author_url = $ api_response ->link ;
145
+ $ post ->author_url = $ api_response ->link ;
138
146
}
139
147
}
140
148
}
141
149
142
- $ results = [] ;
143
- foreach ($ posts as $ post ) {
144
- $ results [$ post ->id ] = $ post ;
150
+ $ results = array () ;
151
+ foreach ( $ posts as $ post ) {
152
+ $ results [ $ post ->id ] = $ post ;
145
153
}
146
154
147
- set_transient ( $ transient_key , $ results , HOUR_IN_SECONDS ); // @todo Maybe longer?
155
+ set_transient ( $ transient_key , $ results , HOUR_IN_SECONDS ); // @todo Maybe longer?
148
156
}
149
157
150
158
return $ results ;
@@ -163,31 +171,32 @@ function query_api( $url ) {
163
171
164
172
function load_org_blog_posts () {
165
173
$ posts_url = 'https://creativecommons.org/wp-json/wp/v2/posts?per_page=50 ' ;
166
- $ posts = query_api ( $ posts_url );
174
+ $ posts = query_api ( $ posts_url );
167
175
168
- if (! $ posts ) {
169
- return [] ;
176
+ if ( ! $ posts ) {
177
+ return array () ;
170
178
}
171
179
172
180
return $ posts ;
173
181
}
174
182
175
183
/**
176
184
* This only runs on the back-end, when editing a page using the page-home.php template.
185
+ *
177
186
* @todo Maybe add a short transient here? Not sure if necessary since on the back-end only.
178
187
* @todo Maybe need to load more than 50 most recent posts? Download multiple pages and build list.
179
188
*/
180
189
function acf_load_blog_posts ( $ field ) {
181
- // reset choices
182
- $ field ['choices ' ] = array ();
183
- $ blog_posts = load_org_blog_posts ();
190
+ // reset choices
191
+ $ field ['choices ' ] = array ();
192
+ $ blog_posts = load_org_blog_posts ();
184
193
185
- foreach ($ blog_posts as $ post ) {
186
- $ field ['choices ' ][$ post ->id ] = $ post ->title ->rendered ;
187
- }
194
+ foreach ( $ blog_posts as $ post ) {
195
+ $ field ['choices ' ][ $ post ->id ] = $ post ->title ->rendered ;
196
+ }
188
197
189
- // return the field
190
- return $ field ;
198
+ // return the field
199
+ return $ field ;
191
200
}
192
201
193
- add_filter ('acf/load_field/name=blog_posts ' , 'acf_load_blog_posts ' );
202
+ add_filter ( 'acf/load_field/name=blog_posts ' , 'acf_load_blog_posts ' );
0 commit comments