1010
1111if (!defined ('ABSPATH ' )) { exit ; }
1212
13- const NU_GLOBAL_ELEMENTS_PLUGIN_VER = "1.3 .0 " ;
13+ const NU_GLOBAL_ELEMENTS_PLUGIN_VER = "1.4 .0 " ;
1414const NU_GLOBAL_ELEMENTS_PLUGIN_MANIFEST_URL = "https://its-digital-technology.github.io/global-elements-wordpress/manifest/info.json " ;
1515
16+
1617/**
1718 * Get options values for plugin
1819 */
1920
2021$ nu_global_elements_options = get_option ( 'nu_global_elements_option_name ' );
2122
23+
2224/**
23- * Include global elements CSS, kernl UI and javascript from CDN
25+ * Include global elements CSS, kernl UI and javascript from CDN on front end
2426 */
25- add_action ( ' wp_head ' , function () {
26- echo '
27- <link rel="stylesheet" href="https://global-packages.cdn.northeastern.edu/global-elements/dist/css/index.css">
28- <script src="https://global-packages.cdn.northeastern.edu/global-elements/dist/js/index.umd.js"></script>
29- <script src="https://global-packages.cdn.northeastern.edu/kernl-ui/dist/js/index.umd.js" defer></script>
30- ' ;
31- });
27+
28+ add_action ( ' wp_head ' , function () { ?>
29+ <link rel="stylesheet" href="https://global-packages.cdn.northeastern.edu/global-elements/dist/css/index.css">
30+ <script src="https://global-packages.cdn.northeastern.edu/global-elements/dist/js/index.umd.js"></script>
31+ <script src="https://global-packages.cdn.northeastern.edu/kernl-ui/dist/js/index.umd.js" defer></script>
32+ <?php }) ;
33+
3234
3335/**
3436 * Include the global NU header, if it is not disabled in the options
3537 *
3638 * NOTE: There must be a wp_body_open() statement under the <body> tag,
3739 * most likely in header.php of the theme.
3840 */
39- if (!isset ($ nu_global_elements_options ['disable_global_header ' ])){
40- add_action ('wp_body_open ' , function () {
4141
42- echo '<div
43- x-data="NUGlobalElements.header({
44- wordmark: true
45- })"
46- x-init="init()"
47- style="height: 48px; background-color: black"
48- ></div> ' ;
42+ if (!isset ($ nu_global_elements_options ['disable_global_header ' ])) {
43+
44+ add_action ('wp_body_open ' , function () use ($ nu_global_elements_options ) {
45+
46+ // Determine whether to show the wordmark
47+ $ show_wordmark = isset ($ nu_global_elements_options ['show_nu_wordmark ' ]) && $ nu_global_elements_options ['show_nu_wordmark ' ];
48+
49+ // Determine whether to show the menu
50+ $ disable_menu = isset ($ nu_global_elements_options ['disable_menu ' ]) && $ nu_global_elements_options ['disable_menu ' ];
51+
52+ // Get the skipToMainSelector value, defaulting to "#main"
53+ $ skip_link_selector = isset ($ nu_global_elements_options ['skip_link_selector ' ]) ? $ nu_global_elements_options ['skip_link_selector ' ] : '#main ' ;
54+
55+ // Create the x-data attribute dynamically with additional options
56+ $ x_data = sprintf (
57+ 'x-data="NUGlobalElements.header({ wordmark: %s, menu: %s, skipToMainSelector: \'%s \' })" ' ,
58+ $ show_wordmark ? 'true ' : 'false ' ,
59+ $ disable_menu ? 'false ' : 'true ' ,
60+ esc_js ($ skip_link_selector ) // Escape for safe JavaScript insertion
61+ );
62+
63+ // Output the HTML structure
64+ echo sprintf (
65+ '<div %s x-init="init()" style="height: 48px; background-color: black"></div> ' ,
66+ $ x_data
67+ );
4968
5069 }, 10 );
5170}
5271
72+
5373/**
5474 * Include the global NU footer, if it is not disabled in the options
5575 */
56- if (!isset ($ nu_global_elements_options ['disable_global_footer ' ])){
57- add_action ('wp_footer ' , function () {
5876
77+ if (!isset ($ nu_global_elements_options ['disable_global_footer ' ])) {
78+ add_action ('wp_footer ' , function () {
5979 echo '<div x-data="NUGlobalElements.footer()" x-init="init()"></div> ' ;
60-
6180 });
6281}
6382
83+
6484/**
6585 * Include TrustArc, if it is not disabled in the options
6686 */
67- if (!isset ($ nu_global_elements_options ['disable_trustarc ' ])){
87+
88+ if (!isset ($ nu_global_elements_options ['disable_trustarc ' ])){
6889
6990 if (isset ($ nu_global_elements_options ['disable_global_footer ' ])){
70- add_action ('wp_footer ' , function () {
71- echo '<style>#trustarc-global-element footer {padding-top: .6rem !important;} #trustarc-global-element footer a {color: #ccc; text-decoration: none;}</style> ' ;
91+ add_action ('wp_head ' , function () {
92+ echo '<style>
93+ #trustarc-global-element footer {padding-top: .6rem !important;}
94+ #trustarc-global-element footer a {color: #ccc; text-decoration: none;}
95+ </style> ' ;
7296 });
7397 }
98+
7499 add_action ('wp_footer ' , function () {
75100 echo '<div id="trustarc-global-element" x-data="NUGlobalElements.trustarc()" x-init="init()"></div> ' ;
76101 });
77102}
78103
104+ // custom plugin styles
105+ add_action ('admin_enqueue_scripts ' , 'nu_global_elements_admin ' );
106+
107+ function nu_global_elements_admin ($ hook ) {
108+ if ( 'admin.php?page=nu-global-elements ' == $ hook ) {
109+ return ;
110+ }
111+
112+ wp_enqueue_style ('nu-global-elements-admin ' , plugins_url ('nu-global-elements-admin.css ' , __FILE__ ));
113+ }
114+
115+
79116/**
80117 * Create plugin settings/options menu item, page and fields
81118 *
86123 * $disable_trustarc = $nu_global_elements_options['disable_trustarc']; // Disable TrustArc
87124 */
88125
89- class NUGlobalElements {
126+ class NUGlobalElements {
90127 private $ nu_global_elements_options ;
91128
92129 public function __construct () {
@@ -146,6 +183,35 @@ public function nu_global_elements_page_init() {
146183 'nu_global_elements_setting_section ' // section
147184 );
148185
186+ add_settings_field (
187+ 'show_nu_wordmark ' , // id
188+ 'Show "Northeastern University" Wordmark next to large "N"
189+ <p style="font-weight: normal">(uncheck if "Northeastern University" already exists in your website department logo)</p>
190+ <img class="nuge-img-max-width" src=" ' . plugin_dir_url ( __FILE__ ) . 'images/duplicate-wordmark-example.png" alt=""><br>
191+ <p><i style="font-weight: normal">Avoid duplicate wordmarks in the global and local headers.</i></p> ' , // title
192+ array ( $ this , 'show_nu_wordmark_callback ' ), // callback
193+ 'nu-global-elements-admin ' , // page
194+ 'nu_global_elements_setting_section ' // section
195+ );
196+
197+ add_settings_field (
198+ 'skip_link_selector ' , // id
199+ 'Skip link selector
200+ <p style="font-weight: normal">Enter the ID selector for the "Skip to main content" destination. Include the <code>#</code> (<i>e.g.</i> <code>#main</code>)</p>
201+ <p style="font-weight: normal">Be sure to remove existing skip-to-main elements from your theme.</p> ' , // title
202+ array ( $ this , 'skip_link_selector_callback ' ), // callback
203+ 'nu-global-elements-admin ' , // page
204+ 'nu_global_elements_setting_section ' // section
205+ );
206+
207+ add_settings_field (
208+ 'disable_menu ' , // id
209+ 'Hide the "Explore Northeastern" menu ' , // title
210+ array ( $ this , 'disable_menu_callback ' ), // callback
211+ 'nu-global-elements-admin ' , // page
212+ 'nu_global_elements_setting_section ' // section
213+ );
214+
149215 add_settings_field (
150216 'disable_global_footer ' , // id
151217 'Disable Global Footer ' , // title
@@ -177,6 +243,18 @@ public function nu_global_elements_sanitize($input) {
177243 $ sanitary_values ['disable_trustarc ' ] = $ input ['disable_trustarc ' ];
178244 }
179245
246+ if ( isset ( $ input ['show_nu_wordmark ' ] ) ) {
247+ $ sanitary_values ['show_nu_wordmark ' ] = $ input ['show_nu_wordmark ' ];
248+ }
249+
250+ if ( isset ( $ input ['skip_link_selector ' ] ) ) {
251+ $ sanitary_values ['skip_link_selector ' ] = $ input ['skip_link_selector ' ];
252+ }
253+
254+ if ( isset ( $ input ['disable_menu ' ] ) ) {
255+ $ sanitary_values ['disable_menu ' ] = $ input ['disable_menu ' ];
256+ }
257+
180258 return $ sanitary_values ;
181259 }
182260
@@ -191,6 +269,34 @@ public function disable_global_header_callback() {
191269 );
192270 }
193271
272+ public function show_nu_wordmark_callback () {
273+ printf (
274+ '<input type="checkbox" name="nu_global_elements_option_name[show_nu_wordmark]" id="show_nu_wordmark" value="show_nu_wordmark" %s> ' ,
275+ ( isset ( $ this ->nu_global_elements_options ['show_nu_wordmark ' ] ) && $ this ->nu_global_elements_options ['show_nu_wordmark ' ] === 'show_nu_wordmark ' ) ? 'checked ' : ''
276+ );
277+ }
278+
279+ public function skip_link_selector_callback () {
280+ // Get the existing value of the skip link selector from the options
281+ $ skip_link_selector = isset ($ this ->nu_global_elements_options ['skip_link_selector ' ]) ? $ this ->nu_global_elements_options ['skip_link_selector ' ] : '#main ' ;
282+
283+ // Output the text input field with the existing value
284+ printf (
285+ '<input type="text" name="nu_global_elements_option_name[skip_link_selector]" id="skip_link_selector" value="%s" class="nuge-skip-link-selector" /> ' ,
286+ esc_attr ($ skip_link_selector ) // Ensure the value is properly escaped
287+ );
288+
289+ // Provide a description about what the input is for
290+ echo '<p class="sr-only">Enter the ID selector for the "Skip to main content" destination (e.g., <code>#main</code>).</p> ' ;
291+ }
292+
293+ public function disable_menu_callback () {
294+ printf (
295+ '<input type="checkbox" name="nu_global_elements_option_name[disable_menu]" id="disable_menu" value="disable_menu" %s> ' ,
296+ ( isset ( $ this ->nu_global_elements_options ['disable_menu ' ] ) && $ this ->nu_global_elements_options ['disable_menu ' ] === 'disable_menu ' ) ? 'checked ' : ''
297+ );
298+ }
299+
194300 public function disable_global_footer_callback () {
195301 printf (
196302 '<input type="checkbox" name="nu_global_elements_option_name[disable_global_footer]" id="disable_global_footer" value="disable_global_footer" %s> ' ,
@@ -204,23 +310,25 @@ public function disable_trustarc_callback() {
204310 ( isset ( $ this ->nu_global_elements_options ['disable_trustarc ' ] ) && $ this ->nu_global_elements_options ['disable_trustarc ' ] === 'disable_trustarc ' ) ? 'checked ' : ''
205311 );
206312 }
207-
208313}
314+
209315if ( is_admin () )
210316 $ nu_global_elements = new NUGlobalElements ();
211317
212-
213318add_filter ( 'plugin_action_links_global-elements-wordpress/nu_global_elements.php ' , 'nu_global_elements_link ' );
214319function nu_global_elements_link ( $ links ) {
215- // Build and escape the URL.
320+
321+ // Build and escape the URL.
216322 $ url = esc_url ( add_query_arg (
217323 'page ' ,
218324 'nu-global-elements ' ,
219325 get_admin_url () . 'admin.php '
220326 ) );
221- // Create the link.
327+
328+ // Create the link.
222329 $ settings_link = "<a href=' $ url'> " . __ ( 'Settings ' ) . '</a> ' ;
223- // Adds the link to the end of the array.
330+
331+ // Adds the link to the end of the array.
224332 array_push (
225333 $ links ,
226334 $ settings_link
@@ -232,7 +340,6 @@ function nu_global_elements_link( $links ) {
232340 * Check for updates to this plugin and if available allow updating through WP admin plugin manager
233341 */
234342
235-
236343if ( ! class_exists ( 'UpdateChecker ' ) ) {
237344
238345 class UpdateChecker{
@@ -382,7 +489,6 @@ public function purge( $upgrader, $options ){
382489
383490 }
384491
385-
386492 }
387493
388494 new UpdateChecker ();
0 commit comments