Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[WordPress] De-coupling Domain Logic in WordPress
<?php
/*
* This file is part of Remove Empty Shortcodes.
*
* (c) Tom McFarlin <tom@tommcfarlin.com>
*
* This source file is subject to the GPL license that is bundled
* with this source code in the file LICENSE.
*/
namespace TomMcFarlin\RESC\Subscriber;
use TomMcFarlin\Utilities\Registry;
/**
* An abstract implementation of a subscriber that requires a hook and the ability to
* start the class.
*/
abstract class AbstractSubscriber
{
/**
* @var string a reference to the hook to which the subscriber should be registered
*/
protected $hook;
/**
* @var Registry a reference to the simple container used to maintain plugin objects
*/
protected $registry;
/**
* @param string $hook the hook to which the subscriber is registered
*/
public function __construct(string $hook)
{
$this->hook = $hook;
$this->registry = apply_filters('rescRegistry', null);
}
/**
* @return string the hook to which the subscriber is registered
*/
public function getHook(): string
{
return $this->hook;
}
abstract public function load();
}
<?php
/*
* This file is part of Remove Empty Shortcodes.
*
* (c) Tom McFarlin <tom@tommcfarlin.com>
*
* This source file is subject to the GPL license that is bundled
* with this source code in the file LICENSE.
*/
namespace TomMcFarlin\RESC\WordPress;
/**
* Processes the post content by looking to see if any orphaned shortcode
* exists and then removes it from displaying it from the user.
*/
class PostContentProcessor
{
/**
* A reference to the Shortcode Manager for processing orphaned shortcodes.
*/
private $shortcodeManager;
/**
* Initializes the class by setting up a reference to the Registry and the
* Shortcode Manager.
*/
public function __construct()
{
$registry = apply_filters('rescRegistry', null);
$this->shortcodeManager = $registry->get('shortcodeManager');
}
/**
* @param string $content the filtered post content
*
* @return string $content the filtered post content without the shortcode
*/
public function run(string $content): string
{
return $this->shortcodeManager->processShortcodes($content);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.