Added publication-embed shortcode.
This commit is contained in:
47
includes/shortcodes/abstract-shortcode.php
Normal file
47
includes/shortcodes/abstract-shortcode.php
Normal 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;
|
||||
|
||||
}
|
||||
44
includes/shortcodes/class-publication-embed.php
Normal file
44
includes/shortcodes/class-publication-embed.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* @package CleverOgre
|
||||
* @subpackage OgreIssuu
|
||||
* @version 0.1.0
|
||||
* @since 0.1.0
|
||||
*/
|
||||
|
||||
namespace OgreIssuu\Shortcodes;
|
||||
|
||||
use OgreIssuu\Api;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class PublicationEmbed extends Shortcode {
|
||||
|
||||
public function get_default_attributes():array {
|
||||
return [
|
||||
'slug' => '',
|
||||
'responsive' => true,
|
||||
'width' => '100%',
|
||||
'height' => '100%',
|
||||
'hideIssuuLogo' => false,
|
||||
'hideShareButton' => false,
|
||||
'showOtherPublications' => false,
|
||||
'bgColor' => '',
|
||||
'fullScreenShareBgColor' => '',
|
||||
];
|
||||
}
|
||||
|
||||
public function render(array $atts, string $content):void {
|
||||
$slug = $atts['slug'];
|
||||
unset($atts['slug']);
|
||||
if (empty($slug)) return;
|
||||
|
||||
$embed = Api::instance()->get_publication_embed($slug, $atts);
|
||||
if (is_null($embed) || !property_exists($embed, 'embed')) return;
|
||||
|
||||
echo $embed->embed;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PublicationEmbed::instance();
|
||||
@@ -39,6 +39,8 @@ class Plugin extends PluginBase {
|
||||
'includes/api/class-publications.php',
|
||||
'includes/api/class-user.php',
|
||||
'includes/class-api.php',
|
||||
'includes/shortcodes/abstract-shortcode.php',
|
||||
'includes/shortcodes/class-publication-embed.php',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user