Compare commits

...

10 Commits

Author SHA1 Message Date
dcooperdalrymple
457c17d5d3 Fixed settings color picker loading issue. 2022-12-06 16:01:27 -06:00
dcooperdalrymple
7743278185 Fixed bug in build system. 2022-11-16 15:29:47 -06:00
dcooperdalrymple
dd02b7546b Updated Makefile to use slug as file name. 2022-11-16 14:16:17 -06:00
dcooperdalrymple
24efd02e0a Converted array() to [] 2022-04-13 10:18:38 -05:00
dcooperdalrymple
b3ea11c7ce Body class filter implemented. has-alert and has-alert-{id} 2022-04-13 09:48:14 -05:00
dcooperdalrymple
60e924ba32 has_active function with ogrealert/has_active filter. 2022-04-13 09:47:35 -05:00
dcooperdalrymple
bb08ce8a51 Pushed to version 0.1.9. 2021-05-24 15:05:36 -05:00
dcooperdalrymple
0dfafdbf68 Added z-index setting for all alerts. 2021-05-24 15:05:08 -05:00
dcooperdalrymple
f383778510 WP 5.5.0 deprecated filter. 2021-05-24 14:56:31 -05:00
dcooperdalrymple
400b1109f7 Renamed display.js to frontend.js to prevent blockers. 2021-05-24 14:56:21 -05:00
14 changed files with 162 additions and 131 deletions

2
.gitignore vendored
View File

@@ -1,4 +1,4 @@
/assets/sass/*.css /assets/sass/*.css
*.map *.map
/OgreAlert /OgreAlert
OgreAlert.zip ogrealert.zip

View File

@@ -1,9 +1,10 @@
PACKAGE = OgreAlert PACKAGE = OgreAlert
SLUG = ogrealert
DIR = ./$(PACKAGE) DIR = ./$(PACKAGE)
all: $(PACKAGE).zip all: $(SLUG).zip
$(PACKAGE).zip: clean dir copy zip $(SLUG).zip: clean dir copy zip
dir: dir:
mkdir $(DIR) mkdir $(DIR)
@@ -16,16 +17,16 @@ copy:
cp -f ./* $(DIR) || true cp -f ./* $(DIR) || true
rm $(DIR)/Makefile rm $(DIR)/Makefile
rm $(DIR)/$(PACKAGE).zip || true rm $(DIR)/$(SLUG).zip || true
rm -r $(DIR)/assets/sass/lib rm -r $(DIR)/assets/sass/lib
rm $(DIR)/assets/sass/*.scss rm $(DIR)/assets/sass/*.scss
rm $(DIR)/assets/sass/*.map rm $(DIR)/assets/sass/*.map
zip: zip:
zip -r ./$(PACKAGE).zip $(DIR) zip -r ./$(SLUG).zip $(DIR)
rm -r $(DIR) || true rm -r $(DIR) || true
clean: clean:
rm -r $(DIR) || true rm -r $(DIR) || true
rm ./$(PACKAGE).zip || true rm ./$(SLUG).zip || true

View File

@@ -2,7 +2,7 @@
Plugin Name: OgreAlert Plugin Name: OgreAlert
Plugin URI: https://plugins.cleverogre.com/plugin/ogrealert/ Plugin URI: https://plugins.cleverogre.com/plugin/ogrealert/
Description: OgreAlert is a plugin developed by CleverOgre in Pensacola, Florida. Description: OgreAlert is a plugin developed by CleverOgre in Pensacola, Florida.
Version: 0.1.7 Version: 0.1.9
Author: CleverOgre Author: CleverOgre
Author URI: https://cleverogre.com/ Author URI: https://cleverogre.com/
Icon1x: https://plugins.cleverogre.com/plugin/ogrealert/?asset=icon-sm Icon1x: https://plugins.cleverogre.com/plugin/ogrealert/?asset=icon-sm
@@ -29,7 +29,7 @@ Copyright: © 2020 CleverOgre, Inc. All rights reserved.
`'---' `--' `" `'-' `'---' `--' `" `'-'
*/ */
jQuery(function ($) { (function ($) {
if (typeof ogrealert === 'undefined' || ogrealert == null || ogrealert.length <= 0) return falase; if (typeof ogrealert === 'undefined' || ogrealert == null || ogrealert.length <= 0) return falase;
// Cookie functions // Cookie functions
@@ -196,4 +196,4 @@ jQuery(function ($) {
} }
$(document).ready(documentReady); $(document).ready(documentReady);
}); })(jQuery);

View File

@@ -29,8 +29,8 @@ Copyright: © 2020 CleverOgre, Inc. All rights reserved.
`'---' `--' `" `'-' `'---' `--' `" `'-'
*/ */
jQuery(function ($) { (function ($) {
$(document).on('ready', function () { $(document).ready(function () {
if ($.fn.datepicker) { if ($.fn.datepicker) {
// Not using datepicker atm // Not using datepicker atm
/* $('.ogrealert-date-picker').datepicker({ /* $('.ogrealert-date-picker').datepicker({
@@ -40,4 +40,4 @@ jQuery(function ($) {
console.log('OgreAlert Error: datepicker does not exist.'); console.log('OgreAlert Error: datepicker does not exist.');
} }
}); });
}); })(jQuery);

View File

@@ -29,12 +29,12 @@ Copyright: © 2020 CleverOgre, Inc. All rights reserved.
`'---' `--' `" `'-' `'---' `--' `" `'-'
*/ */
jQuery(function ($) { (function ($) {
$(document).on('ready', function () { $(document).ready(function () {
if ($.fn.wpColorPicker) { if ($.fn.wpColorPicker) {
$('.ogrealert-color-picker').wpColorPicker(); $('.ogrealert-color-picker').wpColorPicker();
} else { } else {
console.log('OgreAlert Error: wpColorPicker does not exist.'); console.log('OgreAlert Error: wpColorPicker does not exist.');
} }
}); });
}); })(jQuery);

View File

@@ -2,7 +2,7 @@
Plugin Name: OgreAlert Plugin Name: OgreAlert
Plugin URI: https://plugins.cleverogre.com/plugin/ogrealert/ Plugin URI: https://plugins.cleverogre.com/plugin/ogrealert/
Description: OgreAlert is a plugin developed by CleverOgre in Pensacola, Florida. Description: OgreAlert is a plugin developed by CleverOgre in Pensacola, Florida.
Version: 0.1.8 Version: 0.1.9
Author: CleverOgre Author: CleverOgre
Author URI: https://cleverogre.com/ Author URI: https://cleverogre.com/
Icon1x: https://plugins.cleverogre.com/plugin/ogrealert/?asset=icon-sm Icon1x: https://plugins.cleverogre.com/plugin/ogrealert/?asset=icon-sm
@@ -57,15 +57,13 @@ $content-line: 1.5 * $content-text;
$icon-text: $content-line; $icon-text: $content-line;
// Layering
$messages-index: 10001;
/******************* /*******************
* Message * * Message *
*******************/ *******************/
section.ogrealert-messages { section.ogrealert-messages {
--messages-index: 10001;
display: block; display: block;
width: 100%; width: 100%;
height: auto; height: auto;
@@ -73,7 +71,7 @@ section.ogrealert-messages {
padding: 0; padding: 0;
position: relative; position: relative;
z-index: $messages-index; z-index: var(--messages-index);
font-size: 0; font-size: 0;
line-height: 0; line-height: 0;

View File

@@ -2,7 +2,7 @@
/** /**
* @package CleverOgre * @package CleverOgre
* @subpackage OgreAlert * @subpackage OgreAlert
* @since OgreAlert 0.1.7 * @since OgreAlert 0.1.9
*/ */
namespace OgreAlert; namespace OgreAlert;
@@ -12,9 +12,9 @@ if (!defined('ABSPATH')) exit;
class Alert { class Alert {
public static function load() { public static function load() {
add_action('init', array(__CLASS__, 'init')); add_action('init', [__CLASS__, 'init']);
add_filter('manage_alert_posts_columns', array(__CLASS__, 'register_columns')); add_filter('manage_alert_posts_columns', [__CLASS__, 'register_columns']);
add_action('manage_alert_posts_custom_column', array(__CLASS__, 'display_column'), 10, 2); add_action('manage_alert_posts_custom_column', [__CLASS__, 'display_column'], 10, 2);
// OgreAlert Content Filters // OgreAlert Content Filters
add_filter('ogrealert/content', 'wptexturize'); add_filter('ogrealert/content', 'wptexturize');
@@ -22,13 +22,13 @@ class Alert {
add_filter('ogrealert/content', 'wpautop'); add_filter('ogrealert/content', 'wpautop');
add_filter('ogrealert/content', 'shortcode_unautop'); add_filter('ogrealert/content', 'shortcode_unautop');
add_filter('ogrealert/content', 'prepend_attachment'); add_filter('ogrealert/content', 'prepend_attachment');
add_filter('ogrealert/content', 'wp_make_content_images_responsive'); add_filter('ogrealert/content', 'wp_filter_content_tags');
add_filter('ogrealert/content', 'do_shortcode', 11); // After wpautop add_filter('ogrealert/content', 'do_shortcode', 11); // After wpautop
} }
static function init() { static function init() {
$post_type_args = array( $post_type_args = [
'supports' => array('title', 'editor', 'revisions'), 'supports' => ['title', 'editor', 'revisions'],
'public' => true, 'public' => true,
'exclude_from_search' => true, 'exclude_from_search' => true,
'publicly_queryable' => false, 'publicly_queryable' => false,
@@ -38,22 +38,22 @@ class Alert {
'show_in_admin_bar' => true, 'show_in_admin_bar' => true,
'menu_position' => apply_filters('ogrealert/menu_position', 20), 'menu_position' => apply_filters('ogrealert/menu_position', 20),
'menu_icon' => 'dashicons-format-status', 'menu_icon' => 'dashicons-format-status',
); ];
if (class_exists('Ogre')) { if (class_exists('Ogre')) {
$post_type_args['labels'] = \Ogre::get_labels(__('Alerts', 'ogrealert'), __('Alert', 'ogrealert')); $post_type_args['labels'] = \Ogre::get_labels(__('Alerts', 'ogrealert'), __('Alert', 'ogrealert'));
} else { } else {
$post_type_args['labels'] = array( $post_type_args['labels'] = [
'name' => __('Alerts', 'ogrealert'), 'name' => __('Alerts', 'ogrealert'),
'singular_name' => __('Alert', 'ogrealert'), 'singular_name' => __('Alert', 'ogrealert'),
); ];
} }
register_post_type('alert', apply_filters('ogrealert/post_type_args', $post_type_args)); register_post_type('alert', apply_filters('ogrealert/post_type_args', $post_type_args));
} }
static function register_columns($columns) { static function register_columns($columns) {
$_columns = array(); $_columns = [];
foreach ($columns as $key => $label) { foreach ($columns as $key => $label) {
if ($key == 'date') { if ($key == 'date') {
@@ -97,7 +97,7 @@ class Alert {
$ids = array_map('intval', $ids); $ids = array_map('intval', $ids);
$remove_keys = array(); $remove_keys = [];
foreach ($ids as $key => $id) { foreach ($ids as $key => $id) {
if (!self::valid($id)) $remove_keys[] = $key; if (!self::valid($id)) $remove_keys[] = $key;
} }
@@ -125,7 +125,7 @@ class Alert {
} }
public static function get_active() { public static function get_active() {
$alerts = get_posts(apply_filters('ogrealert/get_active_args', array( $alerts = get_posts(apply_filters('ogrealert/get_active_args', [
'posts_per_page' => -1, 'posts_per_page' => -1,
'offset' => 0, 'offset' => 0,
'orderby' => 'rand', 'orderby' => 'rand',
@@ -133,13 +133,16 @@ class Alert {
'post_type' => 'alert', 'post_type' => 'alert',
'post_stauts' => 'publish', 'post_stauts' => 'publish',
'fields' => 'ids', 'fields' => 'ids',
))); ]));
$alerts = !is_wp_error($alerts) && !empty($alerts) ? $alerts : false; $alerts = !is_wp_error($alerts) && !empty($alerts) ? $alerts : false;
self::validate_ids($alerts); self::validate_ids($alerts);
return apply_filters('ogrealert/get_active', $alerts); return apply_filters('ogrealert/get_active', $alerts);
} }
public static function has_active() {
return apply_filters('ogrealert/has_active', !empty(self::get_active()));
}
public static function get_random() { public static function get_random() {
$alerts = self::get_active(); $alerts = self::get_active();
@@ -170,29 +173,29 @@ class AlertMetaBox {
public static function load() { public static function load() {
if (is_admin()) { if (is_admin()) {
add_action('load-post.php', array(__ClASS__, 'init')); add_action('load-post.php', [__CLASS__, 'init']);
add_action('load-post-new.php', array(__ClASS__, 'init')); add_action('load-post-new.php', [__CLASS__, 'init']);
} }
} }
public static function init() { public static function init() {
add_action('add_meta_boxes_alert', array(__CLASS__, 'add')); add_action('add_meta_boxes_alert', [__CLASS__, 'add']);
add_action('save_post', array(__CLASS__, 'save'), 10, 2); add_action('save_post', [__CLASS__, 'save'], 10, 2);
add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts')); add_action('admin_enqueue_scripts', [__CLASS__, 'enqueue_scripts']);
} }
static function enqueue_scripts() { static function enqueue_scripts() {
if (!wp_style_is('jquery-ui-datepicker', 'enqueued')) { if (!wp_style_is('jquery-ui-datepicker', 'enqueued')) {
wp_enqueue_style('jquery-ui-datepicker'); wp_enqueue_style('jquery-ui-datepicker');
} }
wp_enqueue_script('ogrealert-post', \OgreAlert\Settings::get('dir') . 'assets/js/post.js', array('jquery', 'jquery-ui-core', 'jquery-ui-datepicker'), \OgreAlert\Settings::get('version'), true); wp_enqueue_script('ogrealert-post', \OgreAlert\Settings::get('dir') . 'assets/js/post.js', ['jquery', 'jquery-ui-core', 'jquery-ui-datepicker'], \OgreAlert\Settings::get('version'), true);
} }
static function add() { static function add() {
add_meta_box( add_meta_box(
'ogrealert_post_settings', 'ogrealert_post_settings',
__('Message Settings', 'ogrealert'), __('Message Settings', 'ogrealert'),
array(__CLASS__, 'render'), [__CLASS__, 'render'],
'alert', 'alert',
'side', 'side',
'default' 'default'
@@ -203,35 +206,35 @@ class AlertMetaBox {
wp_nonce_field('post_settings', '_ogrealert_nonce'); wp_nonce_field('post_settings', '_ogrealert_nonce');
echo '<p>'; echo '<p>';
self::field_select(array( self::field_select([
'id' => 'ogrealert_post_settings_priority', 'id' => 'ogrealert_post_settings_priority',
'name' => '_ogrealert_priority', 'name' => '_ogrealert_priority',
'label' => __('Priority', 'ogrealert'), 'label' => __('Priority', 'ogrealert'),
'options' => array( 'options' => [
'high' => __('High', 'ogrealert'), 'high' => __('High', 'ogrealert'),
'normal' => __('Normal', 'ogrealert'), 'normal' => __('Normal', 'ogrealert'),
'low' => __('Low', 'ogrealert'), 'low' => __('Low', 'ogrealert'),
), ],
'default' => 'normal', 'default' => 'normal',
'class' => 'widefat', 'class' => 'widefat',
)); ]);
echo '</p>'; echo '</p>';
echo '<p>'; echo '<p>';
self::field_date(array( self::field_date([
'id' => 'ogrealert_post_settings_expiration', 'id' => 'ogrealert_post_settings_expiration',
'name' => '_ogrealert_expiration', 'name' => '_ogrealert_expiration',
'label' => __('Expires On', 'ogrealer'), 'label' => __('Expires On', 'ogrealert'),
'class' => 'widefat', 'class' => 'widefat',
)); ]);
echo '</p>'; echo '</p>';
echo '<p>'; echo '<p>';
self::field_select(array( self::field_select([
'id' => 'ogrealert_post_settings_duration', 'id' => 'ogrealert_post_settings_duration',
'name' => '_ogrealert_duration', 'name' => '_ogrealert_duration',
'label' => __('Dismiss Duration', 'ogrealert'), 'label' => __('Dismiss Duration', 'ogrealert'),
'options' => array( 'options' => [
'none' => __('None', 'ogrealert'), 'none' => __('None', 'ogrealert'),
'page' => __('Page', 'ogrealert'), 'page' => __('Page', 'ogrealert'),
'minute' => __('Minute', 'ogrealert'), 'minute' => __('Minute', 'ogrealert'),
@@ -240,11 +243,11 @@ class AlertMetaBox {
'week' => __('Week', 'ogrealert'), 'week' => __('Week', 'ogrealert'),
'month' => __('Month', 'ogrealert'), 'month' => __('Month', 'ogrealert'),
'year' => __('Year', 'ogrealert'), 'year' => __('Year', 'ogrealert'),
), ],
'default' => \OgreAlert\Settings::get('message_dismiss_duration'), 'default' => \OgreAlert\Settings::get('message_dismiss_duration'),
'class' => 'widefat', 'class' => 'widefat',
'description' => __('If "None" is selected, the notice will not be able to be dismissed.', 'ogrealert'), 'description' => __('If "None" is selected, the notice will not be able to be dismissed.', 'ogrealert'),
)); ]);
echo '</p>'; echo '</p>';
} }
@@ -258,11 +261,11 @@ class AlertMetaBox {
// Check if not an autosave or revision // Check if not an autosave or revision
if (wp_is_post_autosave($post_id) || wp_is_post_revision($post_id)) return; if (wp_is_post_autosave($post_id) || wp_is_post_revision($post_id)) return;
$keys = array( $keys = [
'_ogrealert_priority', '_ogrealert_priority',
'_ogrealert_expiration', '_ogrealert_expiration',
'_ogrealert_duration', '_ogrealert_duration',
); ];
foreach ($keys as $key) { foreach ($keys as $key) {
if (isset($_POST[$key])) update_post_meta($post_id, $key, $_POST[$key]); if (isset($_POST[$key])) update_post_meta($post_id, $key, $_POST[$key]);
} }
@@ -272,10 +275,10 @@ class AlertMetaBox {
if (!isset($args['id']) || empty($args['id'])) return; if (!isset($args['id']) || empty($args['id'])) return;
if (isset($args['label']) && !empty($args['label'])) { if (isset($args['label']) && !empty($args['label'])) {
self::field_label(array( self::field_label([
'title' => $args['label'], 'title' => $args['label'],
'required' => isset($args['required']) && $args['required'] == true, 'required' => isset($args['required']) && $args['required'] == true,
)); ]);
} }
$selected = ''; $selected = '';
@@ -321,10 +324,10 @@ class AlertMetaBox {
if (!isset($args['id']) || empty($args['id'])) return; if (!isset($args['id']) || empty($args['id'])) return;
if (isset($args['label']) && !empty($args['label'])) { if (isset($args['label']) && !empty($args['label'])) {
self::field_label(array( self::field_label([
'title' => $args['label'], 'title' => $args['label'],
'required' => isset($args['required']) && $args['required'] == true, 'required' => isset($args['required']) && $args['required'] == true,
)); ]);
} }
$value = get_post_meta(get_the_ID(), $args['name'], true); $value = get_post_meta(get_the_ID(), $args['name'], true);

View File

@@ -2,7 +2,7 @@
/** /**
* @package CleverOgre * @package CleverOgre
* @subpackage OgreAlert * @subpackage OgreAlert
* @since OgreAlert 0.1.8 * @since OgreAlert 0.1.9
*/ */
namespace OgreAlert; namespace OgreAlert;
@@ -14,50 +14,62 @@ class Display {
public static function load() { public static function load() {
if (is_admin()) return; if (is_admin()) return;
add_action('wp', array(__CLASS__, 'init')); add_action('wp', [__CLASS__, 'init']);
} }
static function init() { static function init() {
if (empty(\OgreAlert\Alert::get_active())) return; if (!\OgreAlert\Alert::has_active()) return;
add_action('wp_enqueue_scripts', array(__CLASS__, 'enqueue_scripts')); add_action('wp_enqueue_scripts', [__CLASS__, 'enqueue_scripts']);
$position = \OgreAlert\Settings::get('message_position'); $position = \OgreAlert\Settings::get('message_position');
switch ($position) { switch ($position) {
case 'top': case 'top':
case 'bottom': case 'bottom':
case 'footer': case 'footer':
add_action('wp_footer', array(__CLASS__, 'display_alerts')); add_action('wp_footer', [__CLASS__, 'display_alerts']);
break; break;
case 'custom': case 'custom':
add_action('display_alerts', array(__CLASS__, 'display_alerts')); add_action('display_alerts', [__CLASS__, 'display_alerts']);
break; break;
} }
add_filter('body_class', [__CLASS__, 'body_class'], 10, 1);
} }
static function enqueue_scripts() { static function enqueue_scripts() {
wp_enqueue_style('ogrealert', \OgreAlert\Settings::get('dir') . 'assets/sass/style.css', array(), \OgreAlert\Settings::get('version'), 'all'); wp_enqueue_style('ogrealert', \OgreAlert\Settings::get('dir') . 'assets/sass/style.css', [], \OgreAlert\Settings::get('version'), 'all');
wp_enqueue_script('ogrealert', \OgreAlert\Settings::get('dir') . 'assets/js/display.js', array('jquery'), \OgreAlert\Settings::get('version'), true); wp_enqueue_script('ogrealert', \OgreAlert\Settings::get('dir') . 'assets/js/frontend.js', ['jquery'], \OgreAlert\Settings::get('version'), true);
wp_localize_script('ogrealert', 'ogrealert', array( wp_localize_script('ogrealert', 'ogrealert', [
'text_color' => \OgreAlert\Settings::get('message_text_color'), 'text_color' => \OgreAlert\Settings::get('message_text_color'),
'background_color' => \OgreAlert\Settings::get('message_background_color'), 'background_color' => \OgreAlert\Settings::get('message_background_color'),
'transition_duration' => intval(\OgreAlert\Settings::get('message_transition_duration')), 'transition_duration' => intval(\OgreAlert\Settings::get('message_transition_duration')),
'transition_animation' => \OgreAlert\Settings::get('message_transition_animation'), 'transition_animation' => \OgreAlert\Settings::get('message_transition_animation'),
)); ]);
} }
static function display_alerts() { static function display_alerts() {
$ids = \OgreAlert\Alert::get_active(); if (!\OgreAlert\Alert::has_active()) return;
if (empty($ids)) return;
self::load_template('loop-start'); self::load_template('loop-start');
foreach ($ids as $id) { foreach (\OgreAlert\Alert::get_active() as $id) {
self::load_template('alert', \OgreAlert\Priority::get($id), true, array('id' => $id)); self::load_template('alert', \OgreAlert\Priority::get($id), true, ['id' => $id]);
} }
self::load_template('loop-end'); self::load_template('loop-end');
} }
private static function load_template($filename, $filepart = '', $echo = true, $vars = array()) { static function body_class($classes) {
if (is_admin() || !\OgreAlert\Alert::has_active()) return $classes;
$classes[] = 'has-alert';
foreach (\OgreAlert\Alert::get_active() as $id) {
$classes[] = sprintf('has-alert-%d', $id);
}
return $classes;
}
private static function load_template($filename, $filepart = '', $echo = true, $vars = []) {
$path = \OgreAlert\Settings::get('path') . 'templates/' . $filename . '-' . $filepart . '.php'; $path = \OgreAlert\Settings::get('path') . 'templates/' . $filename . '-' . $filepart . '.php';
if (!file_exists($path)) { if (!file_exists($path)) {
$path = \OgreAlert\Settings::get('path') . 'templates/' . $filename . '.php'; $path = \OgreAlert\Settings::get('path') . 'templates/' . $filename . '.php';

View File

@@ -12,7 +12,7 @@ if (!defined('ABSPATH')) exit;
class Expiration { class Expiration {
public static function load() { public static function load() {
add_filter('ogrealert/valid_id', array(__CLASS__, 'check'), 10, 2); add_filter('ogrealert/valid_id', [__CLASS__, 'check'], 10, 2);
} }
static function check($valid, $id) { static function check($valid, $id) {

View File

@@ -11,25 +11,25 @@ if (!defined('ABSPATH')) exit;
class Priority { class Priority {
private static $priorities = array( private static $priorities = [
'high', 'high',
'normal', 'normal',
'low', 'low',
); ];
public static function load() { public static function load() {
add_filter('ogrealert/get_active', array(__CLASS__, 'order'), 10, 1); add_filter('ogrealert/get_active', [__CLASS__, 'order'], 10, 1);
} }
static function order($alerts) { static function order($alerts) {
if (!is_array($alerts) || empty($alerts)) return $alerts; if (!is_array($alerts) || empty($alerts)) return $alerts;
$_alerts = array(); $_alerts = [];
foreach ($alerts as $id) { foreach ($alerts as $id) {
$_alerts[] = array( $_alerts[] = [
'id' => $id, 'id' => $id,
'priority' => self::get($id), 'priority' => self::get($id),
); ];
} }
usort($_alerts, function ($a, $b) { usort($_alerts, function ($a, $b) {

View File

@@ -28,6 +28,7 @@ class Settings {
public static $message_transition_duration; public static $message_transition_duration;
public static $message_transition_animation; public static $message_transition_animation;
public static $message_dismiss_duration; public static $message_dismiss_duration;
public static $message_index;
public static $message_high_text_color; public static $message_high_text_color;
public static $message_high_background_color; public static $message_high_background_color;
@@ -39,13 +40,14 @@ class Settings {
public static $message_low_background_color; public static $message_low_background_color;
public static function init() { public static function init() {
self::$defaults = array( self::$defaults = [
'message_enabled' => '1', 'message_enabled' => '1',
'message_position' => 'bottom', 'message_position' => 'bottom',
'message_container' => '1200', 'message_container' => '1200',
'message_transition_duration' => '250', 'message_transition_duration' => '250',
'message_dismiss_duration' => 'day', 'message_dismiss_duration' => 'day',
'message_animation' => 'slide', 'message_animation' => 'slide',
'message_index' => '10001',
'message_high_text_color' => 'rgba(255, 255, 255, 1)', 'message_high_text_color' => 'rgba(255, 255, 255, 1)',
'message_high_background_color' => 'rgba(220, 53, 69, 1)', 'message_high_background_color' => 'rgba(220, 53, 69, 1)',
@@ -55,7 +57,7 @@ class Settings {
'message_low_text_color' => 'rgba(255, 255, 255, 1)', 'message_low_text_color' => 'rgba(255, 255, 255, 1)',
'message_low_background_color' => 'rgba(23, 162, 184, 1)', 'message_low_background_color' => 'rgba(23, 162, 184, 1)',
); ];
} }
public static function get($key) { public static function get($key) {
@@ -95,7 +97,7 @@ class Settings {
default: default:
$options = get_option('ogrealert_options'); $options = get_option('ogrealert_options');
if (!is_array($options)) $options = array(); if (!is_array($options)) $options = [];
$options["ogrealert_settings_{$key}"] = $value; $options["ogrealert_settings_{$key}"] = $value;
update_option('ogrealert_options', $options); update_option('ogrealert_options', $options);
break; break;
@@ -120,7 +122,7 @@ class Settings {
$regex = '/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/'; $regex = '/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/';
if (preg_match($regex, $hex) != 1) return false; if (preg_match($regex, $hex) != 1) return false;
$dec = array('r' => 0, 'g' => 0, 'b' => 0); $dec = ['r' => 0, 'g' => 0, 'b' => 0];
if (strlen($hex) == strlen('#000')) { if (strlen($hex) == strlen('#000')) {
$dec['r'] = hexdec(substr($hex, 1, 1) . substr($hex, 1, 1)); $dec['r'] = hexdec(substr($hex, 1, 1) . substr($hex, 1, 1));
@@ -167,28 +169,28 @@ class Settings {
class SettingsPage { class SettingsPage {
public static function init() { public static function init() {
add_action('admin_init', array(__CLASS__, 'register_settings')); add_action('admin_init', [__CLASS__, 'register_settings']);
add_action('admin_menu', array(__CLASS__, 'menu')); add_action('admin_menu', [__CLASS__, 'menu']);
} }
static function menu() { static function menu() {
if (!current_user_can(\OgreAlert\Settings::get('capability'))) return; if (!current_user_can(\OgreAlert\Settings::get('capability'))) return;
$page = add_submenu_page('edit.php?post_type=alert', __('OgreAlert Settings', 'ogrealert'), __('Settings', 'ogrealert'), \OgreAlert\Settings::get('capability'), 'ogrealert_settings', array(__CLASS__, 'page')); $page = add_submenu_page('edit.php?post_type=alert', __('OgreAlert Settings', 'ogrealert'), __('Settings', 'ogrealert'), \OgreAlert\Settings::get('capability'), 'ogrealert_settings', [__CLASS__, 'page']);
add_action('load-' . $page, array(__CLASS__, 'load_page')); add_action('load-' . $page, [__CLASS__, 'load_page']);
} }
static function load_page() { static function load_page() {
if (!current_user_can(\OgreAlert\Settings::get('capability'))) return; if (!current_user_can(\OgreAlert\Settings::get('capability'))) return;
add_action('admin_enqueue_scripts', array(__CLASS__, 'admin_enqueue_scripts')); add_action('admin_enqueue_scripts', [__CLASS__, 'admin_enqueue_scripts']);
} }
static function admin_enqueue_scripts() { static function admin_enqueue_scripts() {
if (!wp_style_is('wp-color-picker', 'enqueued')) { if (!wp_style_is('wp-color-picker', 'enqueued')) {
wp_enqueue_style('wp-color-picker'); wp_enqueue_style('wp-color-picker');
} }
wp_enqueue_script('ogrealert-settings', \OgreAlert\Settings::get('dir') . 'assets/js/settings.js', array('jquery', 'wp-color-picker'), \OgreAlert\Settings::get('version'), true); wp_enqueue_script('ogrealert-settings', \OgreAlert\Settings::get('dir') . 'assets/js/settings.js', ['jquery', 'wp-color-picker'], \OgreAlert\Settings::get('version'), true);
} }
static function register_settings() { static function register_settings() {
@@ -196,53 +198,53 @@ class SettingsPage {
// Message Settings // Message Settings
add_settings_section('ogrealert_section_general', __('General Settings', 'ogrealert'), array(__CLASS__, 'section'), 'ogrealert'); add_settings_section('ogrealert_section_general', __('General Settings', 'ogrealert'), [__CLASS__, 'section'], 'ogrealert');
add_settings_field('ogrealert_message_enabled', __('Enable Alerts', 'ogrealert'), array(__CLASS__, 'field_checkbox'), 'ogrealert', 'ogrealert_section_general', array( add_settings_field('ogrealert_message_enabled', __('Enable Alerts', 'ogrealert'), [__CLASS__, 'field_checkbox'], 'ogrealert', 'ogrealert_section_general', [
'id' => 'ogrealert_settings_message_enabled', 'id' => 'ogrealert_settings_message_enabled',
'default' => \OgreAlert\Settings::get_default('message_enabled'), 'default' => \OgreAlert\Settings::get_default('message_enabled'),
)); ]);
add_settings_field('ogrealert_message_position', __('Position', 'ogrealert'), array(__CLASS__, 'field_select'), 'ogrealert', 'ogrealert_section_general', array( add_settings_field('ogrealert_message_position', __('Position', 'ogrealert'), [__CLASS__, 'field_select'], 'ogrealert', 'ogrealert_section_general', [
'id' => 'ogrealert_settings_message_position', 'id' => 'ogrealert_settings_message_position',
'options' => array( 'options' => [
'top' => __('Fixed Top', 'ogrealert'), 'top' => __('Fixed Top', 'ogrealert'),
'bottom' => __('Fixed Bottom', 'ogrealert'), 'bottom' => __('Fixed Bottom', 'ogrealert'),
'footer' => __('After Footer', 'ogrealert'), 'footer' => __('After Footer', 'ogrealert'),
'custom' => __('Custom', 'ogrealert'), 'custom' => __('Custom', 'ogrealert'),
), ],
'default' => \OgreAlert\Settings::get_default('message_position'), 'default' => \OgreAlert\Settings::get_default('message_position'),
'description' => __('If you choose Custom, you must add "do_action(\'display_alerts\');" to a suitable location in your template files.', 'ogrealert'), 'description' => __('If you choose Custom, you must add "do_action(\'display_alerts\');" to a suitable location in your template files.', 'ogrealert'),
)); ]);
add_settings_field('ogrealert_message_container', __('Container Width', 'ogrealert'), array(__CLASS__, 'field_text'), 'ogrealert', 'ogrealert_section_general', array( add_settings_field('ogrealert_message_container', __('Container Width', 'ogrealert'), [__CLASS__, 'field_text'], 'ogrealert', 'ogrealert_section_general', [
'id' => 'ogrealert_settings_message_container', 'id' => 'ogrealert_settings_message_container',
'description' => 'A positive integer in pixels.', 'description' => 'A positive integer in pixels.',
'placeholder' => \OgreAlert\Settings::get_default('message_container'), 'placeholder' => \OgreAlert\Settings::get_default('message_container'),
'default' => \OgreAlert\Settings::get_default('message_container'), 'default' => \OgreAlert\Settings::get_default('message_container'),
)); ]);
add_settings_field('ogrealert_message_transition_duration', __('Transition Duration', 'ogrealert'), array(__CLASS__, 'field_text'), 'ogrealert', 'ogrealert_section_general', array( add_settings_field('ogrealert_message_transition_duration', __('Transition Duration', 'ogrealert'), [__CLASS__, 'field_text'], 'ogrealert', 'ogrealert_section_general', [
'id' => 'ogrealert_settings_message_transition_duration', 'id' => 'ogrealert_settings_message_transition_duration',
'description' => 'A positive integer in milliseconds.', 'description' => 'A positive integer in milliseconds.',
'placeholder' => \OgreAlert\Settings::get_default('message_transition_duration'), 'placeholder' => \OgreAlert\Settings::get_default('message_transition_duration'),
'default' => \OgreAlert\Settings::get_default('message_transition_duration'), 'default' => \OgreAlert\Settings::get_default('message_transition_duration'),
)); ]);
add_settings_field('ogrealert_message_transition_animation', __('Transition Animation', 'ogrealert'), array(__CLASS__, 'field_select'), 'ogrealert', 'ogrealert_section_general', array( add_settings_field('ogrealert_message_transition_animation', __('Transition Animation', 'ogrealert'), [__CLASS__, 'field_select'], 'ogrealert', 'ogrealert_section_general', [
'id' => 'ogrealert_settings_message_transition_animation', 'id' => 'ogrealert_settings_message_transition_animation',
'options' => array( 'options' => [
'slide' => __('Slide', 'ogrealert'), 'slide' => __('Slide', 'ogrealert'),
'fade' => __('Fade', 'ogrealert'), 'fade' => __('Fade', 'ogrealert'),
'custom' => __('Custom', 'ogrealert'), 'custom' => __('Custom', 'ogrealert'),
), ],
'default' => \OgreAlert\Settings::get_default('message_transition_animation'), 'default' => \OgreAlert\Settings::get_default('message_transition_animation'),
'description' => __('If you choose Custom, the animation must be handled with the "ogrealert-message-transition-custom" class in css.', 'ogrealert'), 'description' => __('If you choose Custom, the animation must be handled with the "ogrealert-message-transition-custom" class in css.', 'ogrealert'),
)); ]);
add_settings_field('ogrealert_message_dismiss_duration', __('Default Dismiss Duration', 'ogrealert'), array(__CLASS__, 'field_select'), 'ogrealert', 'ogrealert_section_general', array( add_settings_field('ogrealert_message_dismiss_duration', __('Default Dismiss Duration', 'ogrealert'), [__CLASS__, 'field_select'], 'ogrealert', 'ogrealert_section_general', [
'id' => 'ogrealert_settings_message_dismiss_duration', 'id' => 'ogrealert_settings_message_dismiss_duration',
'options' => array( 'options' => [
'none' => __('None', 'ogrealert'), 'none' => __('None', 'ogrealert'),
'page' => __('Page', 'ogrealert'), 'page' => __('Page', 'ogrealert'),
'minute' => __('Minute', 'ogrealert'), 'minute' => __('Minute', 'ogrealert'),
@@ -251,45 +253,52 @@ class SettingsPage {
'week' => __('Week', 'ogrealert'), 'week' => __('Week', 'ogrealert'),
'month' => __('Month', 'ogrealert'), 'month' => __('Month', 'ogrealert'),
'year' => __('Year', 'ogrealert'), 'year' => __('Year', 'ogrealert'),
), ],
'default' => \OgreAlert\Settings::get_default('message_dismiss_duration'), 'default' => \OgreAlert\Settings::get_default('message_dismiss_duration'),
)); ]);
add_settings_section('ogrealert_section_high', __('High Priority', 'ogrealert'), array(__CLASS__, 'section'), 'ogrealert'); add_settings_field('ogrealert_message_index', __('Z-Index', 'ogrealert'), [__CLASS__, 'field_text'], 'ogrealert', 'ogrealert_section_general', [
'id' => 'ogrealert_settings_message_index',
'description' => 'Sets the z-index value of all OgreAlert messages. Useful for ensuring your messages appear above certain elements of your site.',
'placeholder' => \OgreAlert\Settings::get_default('message_index'),
'default' => \OgreAlert\Settings::get_default('message_index'),
]);
add_settings_field('ogrealert_message_high_text_color', __('Text Color', 'ogrealert'), array(__CLASS__, 'field_color'), 'ogrealert', 'ogrealert_section_high', array( add_settings_section('ogrealert_section_high', __('High Priority', 'ogrealert'), [__CLASS__, 'section'], 'ogrealert');
add_settings_field('ogrealert_message_high_text_color', __('Text Color', 'ogrealert'), [__CLASS__, 'field_color'], 'ogrealert', 'ogrealert_section_high', [
'id' => 'ogrealert_settings_message_high_text_color', 'id' => 'ogrealert_settings_message_high_text_color',
'default' => \OgreAlert\Settings::get_default('message_high_text_color'), 'default' => \OgreAlert\Settings::get_default('message_high_text_color'),
)); ]);
add_settings_field('ogrealert_message_high_background_color', __('Background Color', 'ogrealert'), array(__CLASS__, 'field_color'), 'ogrealert', 'ogrealert_section_high', array( add_settings_field('ogrealert_message_high_background_color', __('Background Color', 'ogrealert'), [__CLASS__, 'field_color'], 'ogrealert', 'ogrealert_section_high', [
'id' => 'ogrealert_settings_message_high_background_color', 'id' => 'ogrealert_settings_message_high_background_color',
'default' => \OgreAlert\Settings::get_default('message_high_background_color'), 'default' => \OgreAlert\Settings::get_default('message_high_background_color'),
)); ]);
add_settings_section('ogrealert_section_normal', __('Normal Priority', 'ogrealert'), array(__CLASS__, 'section'), 'ogrealert'); add_settings_section('ogrealert_section_normal', __('Normal Priority', 'ogrealert'), [__CLASS__, 'section'], 'ogrealert');
add_settings_field('ogrealert_message_normal_text_color', __('Text Color', 'ogrealert'), array(__CLASS__, 'field_color'), 'ogrealert', 'ogrealert_section_normal', array( add_settings_field('ogrealert_message_normal_text_color', __('Text Color', 'ogrealert'), [__CLASS__, 'field_color'], 'ogrealert', 'ogrealert_section_normal', [
'id' => 'ogrealert_settings_message_normal_text_color', 'id' => 'ogrealert_settings_message_normal_text_color',
'default' => \OgreAlert\Settings::get_default('message_normal_text_color'), 'default' => \OgreAlert\Settings::get_default('message_normal_text_color'),
)); ]);
add_settings_field('ogrealert_message_normal_background_color', __('Background Color', 'ogrealert'), array(__CLASS__, 'field_color'), 'ogrealert', 'ogrealert_section_normal', array( add_settings_field('ogrealert_message_normal_background_color', __('Background Color', 'ogrealert'), [__CLASS__, 'field_color'], 'ogrealert', 'ogrealert_section_normal', [
'id' => 'ogrealert_settings_message_normal_background_color', 'id' => 'ogrealert_settings_message_normal_background_color',
'default' => \OgreAlert\Settings::get_default('message_normal_background_color'), 'default' => \OgreAlert\Settings::get_default('message_normal_background_color'),
)); ]);
add_settings_section('ogrealert_section_low', __('Low Priority', 'ogrealert'), array(__CLASS__, 'section'), 'ogrealert'); add_settings_section('ogrealert_section_low', __('Low Priority', 'ogrealert'), [__CLASS__, 'section'], 'ogrealert');
add_settings_field('ogrealert_message_low_text_color', __('Text Color', 'ogrealert'), array(__CLASS__, 'field_color'), 'ogrealert', 'ogrealert_section_low', array( add_settings_field('ogrealert_message_low_text_color', __('Text Color', 'ogrealert'), [__CLASS__, 'field_color'], 'ogrealert', 'ogrealert_section_low', [
'id' => 'ogrealert_settings_message_low_text_color', 'id' => 'ogrealert_settings_message_low_text_color',
'default' => \OgreAlert\Settings::get_default('message_low_text_color'), 'default' => \OgreAlert\Settings::get_default('message_low_text_color'),
)); ]);
add_settings_field('ogrealert_message_low_background_color', __('Background Color', 'ogrealert'), array(__CLASS__, 'field_color'), 'ogrealert', 'ogrealert_section_low', array( add_settings_field('ogrealert_message_low_background_color', __('Background Color', 'ogrealert'), [__CLASS__, 'field_color'], 'ogrealert', 'ogrealert_section_low', [
'id' => 'ogrealert_settings_message_low_background_color', 'id' => 'ogrealert_settings_message_low_background_color',
'default' => \OgreAlert\Settings::get_default('message_low_background_color'), 'default' => \OgreAlert\Settings::get_default('message_low_background_color'),
)); ]);
} }
static function page() { static function page() {
@@ -376,12 +385,12 @@ class SettingsPage {
if (isset($args['default'])) $value = $args['default']; if (isset($args['default'])) $value = $args['default'];
if (isset($options[$args['id']]) && !empty($options[$args['id']])) $value = $options[$args['id']]; if (isset($options[$args['id']]) && !empty($options[$args['id']])) $value = $options[$args['id']];
$settings = array( $settings = [
'tinymce' => true, 'tinymce' => true,
'textarea_name' => 'ogrealert_options[' . $args['id'] . ']', 'textarea_name' => 'ogrealert_options[' . $args['id'] . ']',
'textarea_rows' => 15, 'textarea_rows' => 15,
'tabindex' => 1, 'tabindex' => 1,
); ];
wp_editor($value, $args['id'], $settings); wp_editor($value, $args['id'], $settings);
if (isset($args['description']) && !empty($args['description'])) { if (isset($args['description']) && !empty($args['description'])) {

View File

@@ -3,7 +3,7 @@
Plugin Name: OgreAlert Plugin Name: OgreAlert
Plugin URI: https://plugins.cleverogre.com/plugin/ogrealert/ Plugin URI: https://plugins.cleverogre.com/plugin/ogrealert/
Description: OgreAlert is a plugin developed by CleverOgre in Pensacola, Florida. Description: OgreAlert is a plugin developed by CleverOgre in Pensacola, Florida.
Version: 0.1.8 Version: 0.1.9
Author: CleverOgre Author: CleverOgre
Author URI: https://cleverogre.com/ Author URI: https://cleverogre.com/
Icon1x: https://plugins.cleverogre.com/plugin/ogrealert/?asset=icon-sm Icon1x: https://plugins.cleverogre.com/plugin/ogrealert/?asset=icon-sm
@@ -45,7 +45,7 @@ class Plugin {
// Default Settings // Default Settings
\OgreAlert\Settings::set('name', 'OgreAlert'); \OgreAlert\Settings::set('name', 'OgreAlert');
\OgreAlert\Settings::set('version', '0.1.8'); \OgreAlert\Settings::set('version', '0.1.9');
\OgreAlert\Settings::set('capability', 'edit_posts'); \OgreAlert\Settings::set('capability', 'edit_posts');
\OgreAlert\Settings::set('path', $path); \OgreAlert\Settings::set('path', $path);
\OgreAlert\Settings::set('dir', self::get_dir(__FILE__)); \OgreAlert\Settings::set('dir', self::get_dir(__FILE__));

View File

@@ -4,7 +4,7 @@ Donate link: https://cleverogre.com/
Tags: development, warning, modal, dismissable Tags: development, warning, modal, dismissable
Requires at least: 4.8.0 Requires at least: 4.8.0
Tested up to: 5.7.1 Tested up to: 5.7.1
Stable tag: 0.1.8 Stable tag: 0.1.9
License: GPLv2 or later License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html License URI: https://www.gnu.org/licenses/gpl-2.0.html
@@ -62,6 +62,11 @@ By default, the OgreAlert plugin will be able to update without an activated lic
== Changelog == == Changelog ==
= 0.1.9 - 05-24-2021 =
* NEW: Z-index field in OgreAlert settings.
* BUG: Replaced wp_make_content_images_responsive filter with wp_filter_content_tags for WP 5.5.0 compatibility.
* BUG: Renamed display.js to frontend.js to prevent ad blockers.
= 0.1.8 - 05-12-2021 = = 0.1.8 - 05-12-2021 =
* DEV: Moved FontAwesome webfonts to separated folder in assets. * DEV: Moved FontAwesome webfonts to separated folder in assets.
* DEV: Added plugin packaging makefile. * DEV: Added plugin packaging makefile.

View File

@@ -7,6 +7,9 @@
if (!defined('ABSPATH')) exit; if (!defined('ABSPATH')) exit;
$index = \OgreAlert\Settings::get('message_index');
if (!is_numeric($index)) $index = 10001;
?> ?>
<section class="ogrealert-messages ogrealert-position-<?php esc_attr_e(\OgreAlert\Settings::get('message_position')); ?>"> <section class="ogrealert-messages ogrealert-position-<?php esc_attr_e(\OgreAlert\Settings::get('message_position')); ?>" style="--messages-index: <?php echo intval($index); ?>">
<ul class="ogrealert-messages__list"> <ul class="ogrealert-messages__list">