| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Tag Groups Pro |
| 5 |
* |
| 6 |
* @package Tag Groups Pro |
| 7 |
* @author Christoph Amthor |
| 8 |
* @copyright 2017 Christoph Amthor (@ Chatty Mango, chattymango.com) |
| 9 |
* @license see official vendor website |
| 10 |
* |
| 11 |
* |
| 12 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 13 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 14 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 15 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 16 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 17 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 18 |
* THE SOFTWARE. |
| 19 |
* |
| 20 |
*/ |
| 21 |
|
| 22 |
if (! class_exists('TagGroups_Admin_Notice')) { |
| 23 |
// phpcs:ignore PSR1.Classes.ClassDeclaration.MissingNamespace, Squiz.Classes.ValidClassName.NotCamelCaps -- Legacy class structure |
| 24 |
class TagGroups_Admin_Notice |
| 25 |
{ |
| 26 |
public function __construct() |
| 27 |
{ |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Add an admin notice to the queue |
| 32 |
* |
| 33 |
* @param string $type One of: error, info |
| 34 |
* @param string $content with HTML |
| 35 |
* @return void |
| 36 |
*/ |
| 37 |
public static function add($type, $content) |
| 38 |
{ |
| 39 |
|
| 40 |
$notices = TagGroups_Options::get_option('tag_group_admin_notice', array()); |
| 41 |
/** |
| 42 |
* Avoid duplicate entries |
| 43 |
*/ |
| 44 |
$found = false; |
| 45 |
foreach ($notices as $notice) { |
| 46 |
if ($notice['type'] == $type && $notice['content'] == $content) { |
| 47 |
$found = true; |
| 48 |
break; |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
if (! $found) { |
| 53 |
$notices[] = array( |
| 54 |
'type' => $type, |
| 55 |
'content' => $content |
| 56 |
); |
| 57 |
TagGroups_Options::update_option('tag_group_admin_notice', $notices); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
/** |
| 63 |
* Check if an admin notice is pending and, if necessary, display it |
| 64 |
* |
| 65 |
* @param void |
| 66 |
* @return void |
| 67 |
*/ |
| 68 |
public static function display() |
| 69 |
{ |
| 70 |
|
| 71 |
$notices = TagGroups_Options::get_option('tag_group_admin_notice', array()); |
| 72 |
if (! empty($notices)) { |
| 73 |
foreach ($notices as $notice) { |
| 74 |
if ('cache' == $notice['type']) { |
| 75 |
$notice['type'] = 'info'; |
| 76 |
$protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
| 77 |
$ajax_link = admin_url('admin-ajax.php?', $protocol); |
| 78 |
} else { |
| 79 |
$ajax_link = ''; |
| 80 |
} |
| 81 |
|
| 82 |
// wrap the message in <p></p> if not already a complex formatting |
| 83 |
if (strpos('<p>', $notice['content']) === false) { |
| 84 |
$notice['content'] = '<p>' . $notice['content'] . '</p>'; |
| 85 |
} |
| 86 |
|
| 87 |
$view = new TagGroups_View('partials/admin_notice'); |
| 88 |
$view->set(array( |
| 89 |
'ajax_link' => $ajax_link, |
| 90 |
'notice' => $notice, |
| 91 |
)); |
| 92 |
$view->render(); |
| 93 |
} |
| 94 |
|
| 95 |
update_option('tag_group_admin_notice', array()); |
| 96 |
} |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
} |
| 101 |
|