. */ class AddActionsAndFilters_ShortCode { /** * @var AddActionsAndFilters_Plugin */ var $plugin; /** * @var array */ var $codeItem; /** * AddActionsAndFilters_ShortCode constructor. * @param AddActionsAndFilters_Plugin $plugin * @param array $codeItem */ public function __construct(AddActionsAndFilters_Plugin $plugin, array $codeItem) { $this->plugin = $plugin; $this->codeItem = $codeItem; } public function register_shortcode() { add_shortcode($this->codeItem['name'], array($this, 'handle_shortcode')); } /** * Wrapper function for the shortcode code. * @param $atts array shortcode attributes * @param null|string $content shortcode content * @return string */ public function handle_shortcode($atts, $content = null) { if (isset($this->codeItem['capability']) && $this->codeItem['capability'] && !current_user_can($this->codeItem['capability']) ) { // if a capability is required and the user doesn't have it, // then let the short code do nothing. return ''; } $buffer = isset($this->codeItem['buffer']) && $this->codeItem['buffer']; if ($buffer) { ob_start(); } $result = eval($this->codeItem['code']); if ($result === FALSE) { $url = $this->plugin->getAdminPageUrl() . "&id={$this->codeItem['id']}&action=edit"; $result = sprintf("

%s Plugin: Error in shortcode [%s]

", $this->plugin->getPluginDisplayName(), $url, $this->codeItem['name']); } if ($buffer) { $output = ob_get_contents(); ob_end_clean(); } else { $output = ''; } return $output . $result; } }