first commit

This commit is contained in:
2024-07-15 11:28:08 +02:00
commit f52d538ea5
21891 changed files with 6161164 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
jQuery( document ).on( 'click', '.notice-dismiss', function() {
var notice_name = jQuery(this).closest('div.notice').data('notice-name');
var source = jQuery(this).closest('div.notice').data('source');
if ('' !== notice_name) {
jQuery.ajax({
url: ajaxurl,
type: 'post',
data: {
action: 'wpdesk_notice_dismiss',
notice_name: notice_name,
source: source,
},
success: function (response) {
}
});
}
});
jQuery( document ).on( 'click', '.notice-dismiss-link', function() {
jQuery(this).closest('div.notice').data('source',jQuery(this).data('source'));
jQuery(this).closest('div.notice').find('.notice-dismiss').click();
});

View File

@@ -0,0 +1 @@
jQuery(document).on("click",".notice-dismiss",function(){var a=jQuery(this).closest("div.notice").data("notice-name");var b=jQuery(this).closest("div.notice").data("source");if(""!==a){jQuery.ajax({url:ajaxurl,type:"post",data:{action:"wpdesk_notice_dismiss",notice_name:a,source:b},success:function(c){}})}});jQuery(document).on("click",".notice-dismiss-link",function(){jQuery(this).closest("div.notice").data("source",jQuery(this).data("source"));jQuery(this).closest("div.notice").find(".notice-dismiss").click()});

View File

@@ -0,0 +1,46 @@
{
"name": "wpdesk\/wp-notice",
"description": "Library for displaying Wordpress notices.",
"license": "MIT",
"keywords": [
"wordpress",
"notice",
"admin"
],
"homepage": "https:\/\/gitlab.com\/wpdesk\/wp-notice",
"minimum-stability": "stable",
"authors": [
{
"name": "grola",
"email": "grola@wpdesk.net"
}
],
"require": {
"php": ">=5.5",
"wpdesk\/wp-builder": "^1.0"
},
"require-dev": {
"phpunit\/phpunit": "<7",
"wp-coding-standards\/wpcs": "^0.14.1",
"squizlabs\/php_codesniffer": "^3.0.2",
"mockery\/mockery": "*",
"10up\/wp_mock": "*",
"wimg\/php-compatibility": "^8"
},
"autoload": {
"psr-4": {
"ActivePaymentsVendor\\WPDesk\\Notice\\": "src\/WPDesk\/Notice\/"
},
"files": [
"src\/WPDesk\/notice-functions.php"
]
},
"autoload-dev": {},
"scripts": {
"phpcs": "phpcs",
"phpunit-unit": "phpunit --configuration phpunit-unit.xml --coverage-text --colors=never",
"phpunit-unit-fast": "phpunit --configuration phpunit-unit.xml --no-coverage",
"phpunit-integration": "phpunit --configuration phpunit-integration.xml --coverage-text --colors=never",
"phpunit-integration-fast": "phpunit --configuration phpunit-integration.xml --no-coverage"
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace ActivePaymentsVendor;
require_once __DIR__ . '/vendor/autoload.php';
if (!\class_exists('ActivePaymentsVendor\\WPDesk\\Notice\\AjaxHandler')) {
require_once __DIR__ . '/src/WPDesk/Notice/AjaxHandler.php';
}
if (!\class_exists('ActivePaymentsVendor\\WPDesk\\Notice\\Notice')) {
require_once __DIR__ . 'src/WPDesk/Notice/Notice.php';
}
if (!\class_exists('ActivePaymentsVendor\\WPDesk\\Notice\\PermanentDismissibleNotice')) {
require_once __DIR__ . '/src/WPDesk/Notice/PermanentDismissibleNotice.php';
}
if (!\class_exists('ActivePaymentsVendor\\WPDesk\\Notice\\Factory')) {
require_once __DIR__ . '/src/WPDesk/Notice/Factory.php';
}
require_once __DIR__ . '/src/WPDesk/notice-functions.php';

View File

@@ -0,0 +1,83 @@
<?php
namespace ActivePaymentsVendor\WPDesk\Notice;
use ActivePaymentsVendor\WPDesk\PluginBuilder\Plugin\HookablePluginDependant;
use ActivePaymentsVendor\WPDesk\PluginBuilder\Plugin\PluginAccess;
/**
* Class AjaxHandler
*
* AjaxHandler for dismissible notices.
*
* @package WPDesk\Notice
*/
class AjaxHandler implements \ActivePaymentsVendor\WPDesk\PluginBuilder\Plugin\HookablePluginDependant
{
use PluginAccess;
const POST_FIELD_NOTICE_NAME = 'notice_name';
const POST_FIELD_SOURCE = 'source';
const SCRIPTS_VERSION = '4';
const SCRIPT_HANDLE = 'wpdesk_notice';
/**
* @var string
*/
private $assetsURL;
/**
* AjaxHandler constructor.
*
* @param string|null $assetsURL Assets URL.
*/
public function __construct($assetsURL = null)
{
$this->assetsURL = $assetsURL;
}
/**
* Hooks.
*/
public function hooks()
{
if ($this->assetsURL) {
\add_action('admin_enqueue_scripts', [$this, 'enqueueAdminScripts']);
} else {
\add_action('admin_head', [$this, 'addScriptToAdminHead']);
}
\add_action('wp_ajax_wpdesk_notice_dismiss', [$this, 'processAjaxNoticeDismiss']);
}
/**
* Enqueue admin scripts.
*/
public function enqueueAdminScripts()
{
$suffix = \defined('SCRIPT_DEBUG') && \SCRIPT_DEBUG ? '' : '.min';
\wp_register_script(self::SCRIPT_HANDLE, \trailingslashit($this->assetsURL) . 'js/notice' . $suffix . '.js', array('jquery'), self::SCRIPTS_VERSION);
\wp_enqueue_script(self::SCRIPT_HANDLE);
}
/**
* Add Java Script to admin header.
*/
public function addScriptToAdminHead()
{
include 'views/admin-head-js.php';
}
/**
* Process AJAX notice dismiss.
*
* Updates corresponded WordPress option and fires wpdesk_notice_dismissed_notice action with notice name.
*/
public function processAjaxNoticeDismiss()
{
if (isset($_POST[self::POST_FIELD_NOTICE_NAME])) {
$noticeName = $_POST[self::POST_FIELD_NOTICE_NAME];
if (isset($_POST[self::POST_FIELD_SOURCE])) {
$source = $_POST[self::POST_FIELD_SOURCE];
} else {
$source = null;
}
\update_option(\ActivePaymentsVendor\WPDesk\Notice\PermanentDismissibleNotice::OPTION_NAME_PREFIX . $noticeName, \ActivePaymentsVendor\WPDesk\Notice\PermanentDismissibleNotice::OPTION_VALUE_DISMISSED);
\do_action('wpdesk_notice_dismissed_notice', $noticeName, $source);
}
if (\defined('DOING_AJAX') && \DOING_AJAX) {
die;
}
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace ActivePaymentsVendor\WPDesk\Notice;
/**
* Class Factory
*
* Factory for notices.
* @package WPDesk\Notice
*/
class Factory
{
/**
* Creates Notice object.
*
* @param string $noticeType Notice type.
* @param string $noticeContent Notice content.
* @param bool $isDismissible Is dismissible.
* @param int $priority Priority.
*
* @return Notice
*/
public static function notice($noticeContent = '', $noticeType = 'info', $isDismissible = \false, $priority = 10)
{
return new \ActivePaymentsVendor\WPDesk\Notice\Notice($noticeContent, $noticeType, $isDismissible, $priority);
}
/**
* Creates PermanentDismissibleNotice object.
*
* @param string $noticeContent
* @param string $noticeType
* @param string $noticeName
* @param int $priority
*
* @return PermanentDismissibleNotice
*/
public static function permanentDismissibleNotice($noticeContent = '', $noticeName = '', $noticeType = '', $priority = 10)
{
return new \ActivePaymentsVendor\WPDesk\Notice\PermanentDismissibleNotice($noticeContent, $noticeName, $noticeType, $priority);
}
}

View File

@@ -0,0 +1,219 @@
<?php
namespace ActivePaymentsVendor\WPDesk\Notice;
/**
* Class Notice
*
* WordPress admin notice.
* @package WPDesk\Notice
*/
class Notice
{
const NOTICE_TYPE_ERROR = 'error';
const NOTICE_TYPE_WARNING = 'warning';
const NOTICE_TYPE_SUCCESS = 'success';
const NOTICE_TYPE_INFO = 'info';
const ADMIN_FOOTER_BASE_PRIORITY = 9999999;
/**
* Notice type.
*
* @var string
*/
protected $noticeType;
/**
* Notice content.
*
* @var string
*/
protected $noticeContent;
/**
* Is dismissible.
*
* @var bool
*/
protected $dismissible;
/**
* Notice hook priority.
* @var int;
*/
protected $priority;
/**
* Is action added?
* @var bool
*/
private $actionAdded = \false;
/**
* Attributes.
*
* @var string[]
*/
protected $attributes = array();
/**
* WPDesk_Flexible_Shipping_Notice constructor.
*
* @param string $noticeContent Notice content.
* @param string $noticeType Notice type.
* @param bool $dismissible Is dismissible.
* @param int $priority Notice priority.
* @param array $attributes Attributes.
*/
public function __construct($noticeContent, $noticeType = 'info', $dismissible = \false, $priority = 10, $attributes = array())
{
$this->noticeContent = $noticeContent;
$this->noticeType = $noticeType;
$this->dismissible = $dismissible;
$this->priority = $priority;
$this->attributes = $attributes;
$this->addAction();
}
/**
* @return string
*/
public function getNoticeContent()
{
return $this->noticeContent;
}
/**
* @param string $noticeContent
*/
public function setNoticeContent($noticeContent)
{
$this->noticeContent = $noticeContent;
}
/**
* @return string
*/
public function getNoticeType()
{
return $this->noticeType;
}
/**
* @param string $noticeType
*/
public function setNoticeType($noticeType)
{
$this->noticeType = $noticeType;
}
/**
* @return bool
*/
public function isDismissible()
{
return $this->dismissible;
}
/**
* @param bool $dismissible
*/
public function setDismissible($dismissible)
{
$this->dismissible = $dismissible;
}
/**
* @return int
*/
public function getPriority()
{
return $this->priority;
}
/**
* @param int $priority
*/
public function setPriority($priority)
{
$this->priority = $priority;
if ($this->actionAdded) {
$this->removeAction();
$this->addAction();
}
}
/**
* Add notice action.
*/
protected function addAction()
{
if (!$this->actionAdded) {
\add_action('admin_notices', [$this, 'showNotice'], $this->priority);
\add_action('admin_footer', [$this, 'showNotice'], self::ADMIN_FOOTER_BASE_PRIORITY + \intval($this->priority));
$this->actionAdded = \true;
}
}
/**
* Remove action.
*/
protected function removeAction()
{
if ($this->actionAdded) {
\remove_action('admin_notices', [$this, 'showNotice'], $this->priority);
\remove_action('admin_footer', [$this, 'showNotice'], self::ADMIN_FOOTER_BASE_PRIORITY + \intval($this->priority));
$this->actionAdded = \false;
}
}
/**
* Add attribute.
*
* @param string $name Name
* @param string $value Value.
*/
public function addAttribute($name, $value)
{
$this->attributes[$name] = $value;
}
/**
* Get notice class.
*
* @return string
*/
protected function getNoticeClass()
{
if ('updated' === $this->noticeType) {
$notice_class = 'notice ' . $this->noticeType;
} else {
$notice_class = 'notice notice-' . $this->noticeType;
}
if ($this->dismissible) {
$notice_class .= ' is-dismissible';
}
if (isset($this->attributes['class'])) {
$notice_class .= ' ' . $this->attributes['class'];
}
return $notice_class;
}
/**
* Get attributes as string.
*
* @return string
*/
protected function getAttributesAsString()
{
$attribute_string = \sprintf('class="%1$s"', \esc_attr($this->getNoticeClass()));
foreach ($this->attributes as $attribute_name => $attribute_value) {
if ('class' !== $attribute_name) {
$attribute_string .= \sprintf(' %1$s="%2$s"', \esc_html($attribute_name), \esc_attr($attribute_value));
}
}
return $attribute_string;
}
private function addParagraphToContent()
{
if (0 === \strpos($this->noticeContent, '<p>')) {
return \false;
}
if (0 === \strpos($this->noticeContent, '<div>') || 0 === \strpos($this->noticeContent, '<div ')) {
return \false;
}
return \true;
}
/**
* Show notice;
*/
public function showNotice()
{
$this->removeAction();
$noticeFormat = '<div %1$s>%2$s</div>';
if ($this->addParagraphToContent()) {
$noticeFormat = '<div %1$s><p>%2$s</p></div>';
}
echo \sprintf($noticeFormat, $this->getAttributesAsString(), $this->noticeContent);
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace ActivePaymentsVendor\WPDesk\Notice;
/**
* Class PermanentDismissibleNotice
*
* WordPress admin dismissible notice.
* @package WPDesk\Notice
*/
class PermanentDismissibleNotice extends \ActivePaymentsVendor\WPDesk\Notice\Notice
{
const OPTION_NAME_PREFIX = 'wpdesk_notice_dismiss_';
const OPTION_VALUE_DISMISSED = '1';
/**
* @var string
*/
private $noticeName;
/**
* @var string
*/
private $noticeDismissOptionName;
/**
* WPDesk_Flexible_Shipping_Notice constructor.
*
* @param string $noticeContent Notice content.
* @param string $noticeName Notice dismiss option name.
* @param string $noticeType Notice type.
* @param int $priority Priority
* @param array $attributes Attributes.
*/
public function __construct($noticeContent, $noticeName, $noticeType = 'info', $priority = 10, $attributes = array())
{
parent::__construct($noticeContent, $noticeType, \true, $priority, $attributes);
$this->noticeName = $noticeName;
$this->noticeDismissOptionName = static::OPTION_NAME_PREFIX . $noticeName;
if (self::OPTION_VALUE_DISMISSED === \get_option($this->noticeDismissOptionName, '')) {
$this->removeAction();
}
}
/**
* Undo dismiss notice.
*/
public function undoDismiss()
{
\delete_option($this->noticeDismissOptionName);
$this->addAction();
}
/**
* Get attributes as string.
*
* @return string
*/
protected function getAttributesAsString()
{
$attributesAsString = parent::getAttributesAsString();
$attributesAsString .= \sprintf(' data-notice-name="%1$s"', \esc_attr($this->noticeName));
$attributesAsString .= \sprintf(' id="wpdesk-notice-%1$s"', \esc_attr($this->noticeName));
return $attributesAsString;
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace ActivePaymentsVendor;
if (!\defined('ABSPATH')) {
exit;
}
// Exit if accessed directly
?>
<script type="text/javascript">
<?php
include \dirname(__FILE__) . '/../../../../assets/js/notice.min.js';
?>
</script>
<?php

View File

@@ -0,0 +1,228 @@
<?php
namespace ActivePaymentsVendor;
if (!\function_exists('ActivePaymentsVendor\\WPDeskInitWpNoticeAjaxHandler')) {
/**
* Init notices AJAX Handler.
*
* @param string|null $assetsUrl
*
* @return \WPDesk\Notice\AjaxHandler
*/
function WPDeskInitWpNoticeAjaxHandler($assetsUrl = null)
{
$ajax_handler = new \ActivePaymentsVendor\WPDesk\Notice\AjaxHandler($assetsUrl);
$ajax_handler->hooks();
return $ajax_handler;
}
}
if (!\function_exists('ActivePaymentsVendor\\wpdesk_init_wp_notice_ajax_handler')) {
/**
* Alias for {@see WPDeskInitNoticeAjaxHandler()} function.
*
* @param null $assetsUrl
*
* @return \WPDesk\Notice\AjaxHandler
*/
function wpdesk_init_wp_notice_ajax_handler($assetsUrl = null)
{
return \ActivePaymentsVendor\WPDeskInitWpNoticeAjaxHandler($assetsUrl);
}
}
if (!\function_exists('ActivePaymentsVendor\\WPDeskWpNotice')) {
/**
* Creates Notice.
*
* @param string $noticeContent Notice content.
* @param string $noticeType Notice type.
* @param bool $dismissible Dismissible notice.
* @param int $priority Notice priority,
*
* @return \WPDesk\Notice\Notice
*/
function WPDeskWpNotice($noticeContent, $noticeType = 'info', $dismissible = \false, $priority = 10)
{
return \ActivePaymentsVendor\WPDesk\Notice\Factory::notice($noticeContent, $noticeType, $dismissible, $priority);
}
}
if (!\function_exists('ActivePaymentsVendor\\wpdesk_wp_notice')) {
/**
* Creates Notice.
*
* Alias for {@see WPDeskNotice()} function.
*
* @param string $noticeContent Notice content.
* @param string $noticeType Notice type.
* @param bool $dismissible Dismissible notice.
* @param int $priority Notice priority,
*
* @return \WPDesk\Notice\Notice
*/
function wpdesk_wp_notice($noticeContent, $noticeType = 'info', $dismissible = \false, $priority = 10)
{
return \ActivePaymentsVendor\WPDeskWpNotice($noticeContent, $noticeType, $dismissible, $priority);
}
}
if (!\function_exists('ActivePaymentsVendor\\WPDeskWpNoticeInfo')) {
/**
* Creates Notice Info.
*
* @param string $noticeContent Notice content.
* @param bool $dismissible Dismissible notice.
* @param int $priority Notice priority,
*
* @return \WPDesk\Notice\Notice
*/
function WPDeskWpNoticeInfo($noticeContent, $dismissible = \false, $priority = 10)
{
return \ActivePaymentsVendor\WPDesk\Notice\Factory::notice($noticeContent, \ActivePaymentsVendor\WPDesk\Notice\Notice::NOTICE_TYPE_INFO, $dismissible, $priority);
}
}
if (!\function_exists('ActivePaymentsVendor\\wpdesk_wp_notice_info')) {
/**
* Creates Notice Info.
*
* Alias for {@see WPDeskNoticeInfo()} function.
*
* @param string $noticeContent Notice content.
* @param bool $dismissible Dismissible notice.
* @param int $priority Notice priority,
*
* @return \WPDesk\Notice\Notice
*/
function wpdesk_wp_notice_info($noticeContent, $dismissible = \false, $priority = 10)
{
return \ActivePaymentsVendor\WPDeskWpNoticeInfo($noticeContent, $dismissible, $priority);
}
}
if (!\function_exists('ActivePaymentsVendor\\WPDeskWpNoticeError')) {
/**
* Creates Notice Error.
*
* @param string $noticeContent Notice content.
* @param bool $dismissible Dismissible notice.
* @param int $priority Notice priority,
*
* @return \WPDesk\Notice\Notice
*/
function WPDeskWpNoticeError($noticeContent, $dismissible = \false, $priority = 10)
{
return \ActivePaymentsVendor\WPDesk\Notice\Factory::notice($noticeContent, \ActivePaymentsVendor\WPDesk\Notice\Notice::NOTICE_TYPE_ERROR, $dismissible, $priority);
}
}
if (!\function_exists('ActivePaymentsVendor\\wpdesk_wp_notice_error')) {
/**
* Creates Notice Error.
*
* Alias for {@see WPDeskNoticeError()} function.
*
* @param string $noticeContent Notice content.
* @param bool $dismissible Dismissible notice.
* @param int $priority Notice priority,
*
* @return \WPDesk\Notice\Notice
*/
function wpdesk_wp_notice_error($noticeContent, $dismissible = \false, $priority = 10)
{
return \ActivePaymentsVendor\WPDeskWpNoticeError($noticeContent, $dismissible, $priority);
}
}
if (!\function_exists('ActivePaymentsVendor\\WPDeskWpNoticeWarning')) {
/**
* Creates Notice Warning.
*
* @param string $noticeContent Notice content.
* @param bool $dismissible Dismissible notice.
* @param int $priority Notice priority,
*
* @return \WPDesk\Notice\Notice
*/
function WPDeskWpNoticeWarning($noticeContent, $dismissible = \false, $priority = 10)
{
return \ActivePaymentsVendor\WPDesk\Notice\Factory::notice($noticeContent, \ActivePaymentsVendor\WPDesk\Notice\Notice::NOTICE_TYPE_WARNING, $dismissible, $priority);
}
}
if (!\function_exists('ActivePaymentsVendor\\wpdesk_wp_notice_warning')) {
/**
* Creates Notice Warning.
*
* Alias for {@see WPDeskNoticeWarning()} function.
*
* @param string $noticeContent Notice content.
* @param bool $dismissible Dismissible notice.
* @param int $priority Notice priority,
*
* @return \WPDesk\Notice\Notice
*/
function wpdesk_wp_notice_warning($noticeContent, $dismissible = \false, $priority = 10)
{
return \ActivePaymentsVendor\WPDeskWpNoticeWarning($noticeContent, $dismissible, $priority);
}
}
if (!\function_exists('ActivePaymentsVendor\\WPDeskWpNoticeSuccess')) {
/**
* Creates Notice Success.
*
* @param string $noticeContent Notice content.
* @param bool $dismissible Dismissible notice.
* @param int $priority Notice priority,
*
* @return \WPDesk\Notice\Notice
*/
function WPDeskWpNoticeSuccess($noticeContent, $dismissible = \false, $priority = 10)
{
return \ActivePaymentsVendor\WPDesk\Notice\Factory::notice($noticeContent, \ActivePaymentsVendor\WPDesk\Notice\Notice::NOTICE_TYPE_SUCCESS, $dismissible, $priority);
}
}
if (!\function_exists('ActivePaymentsVendor\\wpdesk_wp_notice_success')) {
/**
* Creates Notice Success.
*
* Alias for {@see WPDeskNoticeSuccess()} function.
*
* @param string $noticeContent Notice content.
* @param bool $dismissible Dismissible notice.
* @param int $priority Notice priority,
*
* @return \WPDesk\Notice\Notice
*/
function wpdesk_wp_notice_success($noticeContent, $dismissible = \false, $priority = 10)
{
return \ActivePaymentsVendor\WPDeskWpNoticeSuccess($noticeContent, $dismissible, $priority);
}
}
if (!\function_exists('ActivePaymentsVendor\\WPDeskPermanentDismissibleWpNotice')) {
/**
* Creates Permanent Dismissible Notice.
*
* @param string $noticeContent Notice content.
* @param string $noticeType Notice type.
* @param string $noticeName Notice name.
* @param int $priority Notice priority.
*
* @return \WPDesk\Notice\Notice
*/
function WPDeskPermanentDismissibleWpNotice($noticeContent, $noticeName, $noticeType = 'info', $priority = 10)
{
return \ActivePaymentsVendor\WPDesk\Notice\Factory::permanentDismissibleNotice($noticeContent, $noticeName, $noticeType, $priority);
}
}
if (!\function_exists('ActivePaymentsVendor\\wpdesk_permanent_dismissible_wp_notice')) {
/**
* Creates Permanent Dismissible Notice.
*
* Alias for {@see WPDeskPermanentDismissibleNotice()} function.
*
* @param string $noticeContent Notice content.
* @param string $noticeName Notice name.
* @param string $noticeType Notice type.
* @param int $priority Notice priority.
*
* @return \WPDesk\Notice\Notice
*/
function wpdesk_permanent_dismissible_wp_notice($noticeContent, $noticeName, $noticeType = 'info', $priority = 10)
{
return \ActivePaymentsVendor\WPDeskPermanentDismissibleWpNotice($noticeContent, $noticeName, $noticeType, $priority);
}
}