Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .nojekyll
Empty file.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

## Introduction

Simple Wordpress Plugin developed by the Northeastern University ITS Web Solutions team. Loads the latest version of [kernl(ui) Global Elements](https://northeastern.netlify.app/pattern-library/page-chrome/global-elements/) to your website, plus the code for the [TrustArc](https://trustarc.com/) cookie consent manager.
A WordPress plugin developed by the Northeastern University ITS Web Solutions team. Loads the latest version of [kernl(ui) Global Elements](https://northeastern.netlify.app/pattern-library/page-chrome/global-elements/) to your website, including the code for the [TrustArc](https://trustarc.com/) cookie consent manager.

The global elements package includes a few elements that should be included on almost all Northeastern sites. They have dynamic content and fixed designs for consistency across sites.
The global elements package includes a few elements that should be included on almost all Northeastern sites. They have dynamic content and fixed designs for consistency across sites. TrustArc allows users to set their cookie preferences, and is now required on all Northestern University websites.

[Learn more about the kernl(ui) design system](https://northeastern.netlify.app/)

TrustArc allows users to set their cookie preferences, and is now required on all Northestern University websites.

## Requirements
- **Global Header.** In order for the global header to display, the active theme must support a call to `wp_body_open()` after the opening `<body>` tag:
```php
Expand All @@ -22,7 +20,8 @@ TrustArc allows users to set their cookie preferences, and is now required on al

## Installation

1. Download repository as a `.zip` file on GitHub
2. Upload the `.zip` file to the WordPress site's plugins
3. Activate the new Plugin once it has finished uploading
4. If you need to disable this plugin adding either the global header, footer, or TrustArc code, you can do so from the settings page for this plugin in wp-admin.
1. Download the latest version of the plugin from [GitHub](https://github.com/ITS-Digital-Technology/global-elements-wordpress/releases/latest/download/global-elements-wordpress.zip).
2. Add the new plugin through WP Admin, uploading the `.zip` file from step 1.
3. Activate the new plugin once it has finished uploading.
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.
5. If you need more detailed instructions, see this [KB article](https://service.northeastern.edu/tech?id=kb_article_view&sysparm_article=KB000022192).
21 changes: 21 additions & 0 deletions manifest/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name" : "Northeastern Global Elements",
"slug" : "global-elements-wordpress",
"author" : "<a href='https://its.northeastern.edu/'>ITS Digital Technology & Services</a>",
"author_profile" : "https://its.northeastern.edu/",
"version" : "1.3.0",
"download_url" : "https://github.com/ITS-Digital-Technology/global-elements-wordpress/releases/download/v1.3.0/global-elements-wordpress.zip",
"requires" : "5.6",
"tested" : "6.6.1",
"requires_php" : "5.6",
"last_updated" : "2024-08-12 16:00:00",
"sections" : {
"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.",
"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.",
"changelog" : "Fixed 'unexpected output' bug and tweaked TrustArc link formatting."
},
"banners" : {
"low" : "",
"high" : ""
}
}
168 changes: 167 additions & 1 deletion nu_global_elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
Description: Inserts the Northeastern University global header, footer, and TrustArc cookie consent manager. Requires wp_body_open() under the body tag to display the global header.
Author: Northeastern University ITS Web Solutions
Author URI: https://its.northeastern.edu
Version: 1.2.2
Version: 1.3.0
*/

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

const NU_GLOBAL_ELEMENTS_PLUGIN_VER = "1.3.0";
const NU_GLOBAL_ELEMENTS_PLUGIN_MANIFEST_URL = "https://its-digital-technology.github.io/global-elements-wordpress/manifest/info.json";

/**
* Get options values for plugin
*/
Expand Down Expand Up @@ -222,3 +227,164 @@ function nu_global_elements_link( $links ) {
);
return $links;
}

/**
* Check for updates to this plugin and if available allow updating through WP admin plugin manager
*/


if( ! class_exists( 'UpdateChecker' ) ) {

class UpdateChecker{

public $plugin_slug;
public $version;
public $cache_key;
public $cache_allowed;

public function __construct() {

$this->plugin_slug = plugin_basename( __DIR__ );
$this->version = NU_GLOBAL_ELEMENTS_PLUGIN_VER;
$this->cache_key = 'global_elements_updater';
$this->cache_allowed = false;

add_filter( 'plugins_api', array( $this, 'info' ), 20, 3 );
add_filter( 'site_transient_update_plugins', array( $this, 'update' ) );
add_action( 'upgrader_process_complete', array( $this, 'purge' ), 10, 2 );

}

public function request(){

$remote = get_transient( $this->cache_key );

if( false === $remote || ! $this->cache_allowed ) {

$remote = wp_remote_get(
NU_GLOBAL_ELEMENTS_PLUGIN_MANIFEST_URL,
array(
'timeout' => 10,
'headers' => array(
'Accept' => 'application/json'
)
)
);

if(
is_wp_error( $remote )
|| 200 !== wp_remote_retrieve_response_code( $remote )
|| empty( wp_remote_retrieve_body( $remote ) )
) {
return false;
}

set_transient( $this->cache_key, $remote, DAY_IN_SECONDS );

}

$remote = json_decode( wp_remote_retrieve_body( $remote ) );

return $remote;

}


function info( $res, $action, $args ) {

// do nothing if you're not getting plugin information right now
if( 'plugin_information' !== $action ) {
return $res;
}

// do nothing if it is not our plugin
if( $this->plugin_slug !== $args->slug ) {
return $res;
}

// get updates
$remote = $this->request();

if( ! $remote ) {
return $res;
}

$res = new stdClass();

$res->name = $remote->name;
$res->slug = $remote->slug;
$res->version = $remote->version;
$res->tested = $remote->tested;
$res->requires = $remote->requires;
$res->author = $remote->author;
$res->author_profile = $remote->author_profile;
$res->download_link = $remote->download_url;
$res->trunk = $remote->download_url;
$res->requires_php = $remote->requires_php;
$res->last_updated = $remote->last_updated;

$res->sections = array(
'description' => $remote->sections->description,
'installation' => $remote->sections->installation,
'changelog' => $remote->sections->changelog
);

if( ! empty( $remote->banners ) ) {
$res->banners = array(
'low' => $remote->banners->low,
'high' => $remote->banners->high
);
}

return $res;

}

public function update( $transient ) {

if ( empty($transient->checked ) ) {
return $transient;
}

$remote = $this->request();

if(
$remote
&& version_compare( $this->version, $remote->version, '<' )
&& version_compare( $remote->requires, get_bloginfo( 'version' ), '<=' )
&& version_compare( $remote->requires_php, PHP_VERSION, '<' )
) {
$res = new stdClass();
$res->slug = $this->plugin_slug;
$res->plugin = plugin_basename( __FILE__ );
$res->new_version = $remote->version;
$res->tested = $remote->tested;
$res->package = $remote->download_url;

$transient->response[ $res->plugin ] = $res;

}

return $transient;

}

public function purge( $upgrader, $options ){

if (
$this->cache_allowed
&& 'update' === $options['action']
&& 'plugin' === $options[ 'type' ]
) {
// just clean the cache when new plugin version is installed
delete_transient( $this->cache_key );
}

}


}

new UpdateChecker();

}