Added publication-embed shortcode.

This commit is contained in:
dcooperdalrymple
2024-09-12 17:30:57 -05:00
parent df844495b1
commit 4c9c39aa52
3 changed files with 93 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
<?php
/**
* @package CleverOgre
* @subpackage OgreIssuu
* @version 0.1.0
* @since 0.1.0
*/
namespace OgreIssuu\Shortcodes;
defined('ABSPATH') || exit;
use OgreIssuu\Singleton;
abstract class Shortcode {
use Singleton;
public function __construct() {
$this->register();
}
protected function get_tag():string {
$parts = explode('\\', get_called_class());
return sanitize_key(preg_replace('/([a-z])([A-Z])/', '$1-$2', array_pop($parts)));
}
protected function register():void {
add_shortcode($this->get_tag(), [$this, 'callback']);
}
public function get_default_attributes():array {
return [];
}
public function get_attributes(array $atts = []):array {
return shortcode_atts($this->get_default_attributes(), $atts, $this->get_tag());
}
public function callback(array $atts, ?string $content = null) {
ob_start();
$this->render($this->get_attributes($atts), (!is_null($content) ? $content : ''));
return ob_get_clean();
}
public abstract function render(array $atts, string $content):void;
}