Skip to content

Commit 8e9806e

Browse files
Merge pull request #7 from ITS-Digital-Technology/options_updates
Add extended options, update UI
2 parents a66e821 + 6c333a8 commit 8e9806e

File tree

5 files changed

+193
-35
lines changed

5 files changed

+193
-35
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,13 @@ The global elements package includes a few elements that should be included on a
2424
2. Add the new plugin through WP Admin, uploading the `.zip` file from step 1.
2525
3. Activate the new plugin once it has finished uploading.
2626
4. If you need to stop this plugin from displaying the global header, footer, or TrustArc elements, you can do so from the settings page for this plugin in WP Admin.
27-
5. If you need more detailed instructions, see this [KB article](https://service.northeastern.edu/tech?id=kb_article_view&sysparm_article=KB000022192).
27+
5. If you need more detailed instructions, see this [KB article](https://service.northeastern.edu/tech?id=kb_article_view&sysparm_article=KB000022192).
28+
29+
### TrustArc Visibility
30+
31+
Some themes may have a height style on iframes. This can be tested by opening the Cookie Preferences link found as the last item in the footer (front end), where the TrustArc modal may be partly obscured when open. If so, you can override with the following style:
32+
33+
.truste_popframe {
34+
height: var(--truste-popframe-height) !important;
35+
}
36+
124 KB
Loading

manifest/info.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"slug" : "global-elements-wordpress",
44
"author" : "<a href='https://its.northeastern.edu/'>ITS Digital Technology & Services</a>",
55
"author_profile" : "https://its.northeastern.edu/",
6-
"version" : "1.3.0",
6+
"version" : "1.4.0",
77
"download_url" : "https://github.com/ITS-Digital-Technology/global-elements-wordpress/releases/download/v1.3.0/global-elements-wordpress.zip",
88
"requires" : "5.6",
99
"tested" : "6.6.1",
@@ -12,7 +12,7 @@
1212
"sections" : {
1313
"description" : "A Wordpress plugin developed by the Northeastern University ITS Web Solutions team that inserts the Northeastern University global header, footer, and TrustArc cookie consent manager. Each elemenent can be enabled/disabled from the plugin's settings.",
1414
"installation" : "Click the activate button to install. In order for the global header to display, the active theme must support a call to wp_body_open() after the opening &lt;body&gt; tag.",
15-
"changelog" : "Fixed 'unexpected output' bug and tweaked TrustArc link formatting."
15+
"changelog" : "Added global header options to WP Admin"
1616
},
1717
"banners" : {
1818
"low" : "",

nu-global-elements-admin.css

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
table.form-table {
2+
max-width: 45rem;
3+
}
4+
5+
.form-table th {
6+
width: 80%;
7+
}
8+
9+
.form-table th {
10+
padding-top: 1rem;
11+
}
12+
13+
.form-table td {
14+
padding-bottom: 2rem;
15+
}
16+
17+
@media screen and (min-width: 783px) {
18+
.form-table td {
19+
vertical-align: top;
20+
text-align:center;
21+
}
22+
23+
.form-table th,
24+
.form-table td {
25+
padding-top: 1rem;
26+
padding-bottom: 1rem;
27+
}
28+
}
29+
30+
.form-table tr:not(:last-child),
31+
.form-table tr:not(:last-child) {
32+
border-bottom: 1px solid rgba(0,0,0,0.3)
33+
}
34+
35+
.nuge-img-max-width {
36+
max-width :300px;
37+
}
38+
39+
.nuge-skip-link-selector {
40+
max-width: 200px;
41+
}
42+
43+
.sr-only { display: none; }

nu_global_elements.php

Lines changed: 138 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,72 +10,109 @@
1010

1111
if (!defined('ABSPATH')) { exit; }
1212

13-
const NU_GLOBAL_ELEMENTS_PLUGIN_VER = "1.3.0";
13+
const NU_GLOBAL_ELEMENTS_PLUGIN_VER = "1.4.0";
1414
const 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
*
@@ -86,7 +123,7 @@
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+
209315
if ( is_admin() )
210316
$nu_global_elements = new NUGlobalElements();
211317

212-
213318
add_filter( 'plugin_action_links_global-elements-wordpress/nu_global_elements.php', 'nu_global_elements_link' );
214319
function 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-
236343
if( ! 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

Comments
 (0)