-
-
Save tommcfarlin/66976b4ee98960c8e86aef286d1c12a9 to your computer and use it in GitHub Desktop.
[WordPress] De-coupling Domain Logic in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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