Skip to content
Snippets Groups Projects

Feature/gutenberg

Merged Krzysztof Dyszczyk requested to merge feature/gutenberg into master
2 unresolved threads
1 file
+ 9
7
Compare changes
  • Side-by-side
  • Inline
+ 48
11
@@ -58,6 +58,12 @@ class Notice
*/
protected $attributes = array();
/**
* Show notice in gutenberg editor.
*
* @var bool
*/
protected $showInGutenberg = false;
/**
* WPDesk_Flexible_Shipping_Notice constructor.
@@ -67,22 +73,37 @@ class Notice
* @param bool $dismissible Is dismissible.
* @param int $priority Notice priority.
* @param array $attributes Attributes.
* @param bool $showInGutenberg Show notice in gutenberg editor.
*/
public function __construct(
$noticeContent,
$noticeType = 'info',
$dismissible = false,
$priority = 10,
$attributes = array()
$attributes = array(),
$showInGutenberg = false
) {
$this->noticeContent = $noticeContent;
$this->noticeType = $noticeType;
$this->dismissible = $dismissible;
$this->priority = $priority;
$this->attributes = $attributes;
$this->showInGutenberg = $showInGutenberg;
$this->addAction();
}
/**
* @return bool
*/
public function isBlockEditor()
{
if ( !function_exists( 'get_current_screen' ) ) {
require_once ABSPATH . '/wp-admin/includes/screen.php';
}
return \get_current_screen()->is_block_editor();
}
/**
* @return string
*/
@@ -163,6 +184,7 @@ class Notice
[$this, 'showNotice'],
self::ADMIN_FOOTER_BASE_PRIORITY + intval($this->priority)
);
add_action('admin_head', [$this,'addGutenbergScript']);
$this->actionAdded = true;
}
}
@@ -183,6 +205,16 @@ class Notice
}
}
/**
* Enqueue admin scripts.
*/
public function addGutenbergScript()
{
if ($this->isBlockEditor()) {
include_once __DIR__ . '/views/admin-head-js-gutenberg.php';
}
}
/**
* Add attribute.
*
@@ -201,18 +233,23 @@ class Notice
*/
protected function getNoticeClass()
{
$notice_classes = ['notice'];
if ('updated' === $this->noticeType) {
$notice_class = 'notice ' . $this->noticeType;
$notice_classes[] = $this->noticeType;
} else {
$notice_class = 'notice notice-' . $this->noticeType;
$notice_classes[] = 'notice-' . $this->noticeType;
}
if ($this->dismissible) {
$notice_class .= ' is-dismissible';
$notice_classes[] = 'is-dismissible';
}
if (isset($this->attributes['class'])) {
$notice_class .= ' ' . $this->attributes['class'];
$notice_classes[] = $this->attributes['class'];
}
return $notice_class;
if ($this->showInGutenberg) {
$notice_classes[] = 'wpdesk-notice-gutenberg';
}
return implode( ' ', $notice_classes );
}
/**
Loading