Initial commit of 0.2.0
This commit is contained in:
73
inc/filter.php
Normal file
73
inc/filter.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* @package ogre-obfuscation
|
||||
* @author cleverogre
|
||||
* @version 0.2.0
|
||||
* @since 0.1.0
|
||||
*/
|
||||
|
||||
namespace Ogre\Obfuscation;
|
||||
|
||||
use Ogre\Singleton;
|
||||
use Ogre\Obfuscation;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
final class Filter {
|
||||
use Singleton;
|
||||
|
||||
protected function __construct() {
|
||||
add_action('wp', array($this, 'init'));
|
||||
}
|
||||
|
||||
public function init() {
|
||||
if (!email_enabled()) return;
|
||||
|
||||
add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
|
||||
|
||||
add_action('the_content', array($this, 'filter_content'), 100, 1);
|
||||
add_filter('wp_nav_menu_items', array($this, 'filter_content'), 100, 1);
|
||||
add_filter('dynamic_sidebar_params', array($this, 'sidebar_params'), 100, 1);
|
||||
add_filter('widget_output', array($this, 'filter_content'), 100, 1);
|
||||
}
|
||||
|
||||
public function enqueue_scripts() {
|
||||
wp_enqueue_script('obfuscation', Obfuscation::get_url('assets/js/obfuscation.js'), array(), Obfuscation::get_version(), true);
|
||||
}
|
||||
|
||||
public function filter_content($content) {
|
||||
if (!find_emails($content)) return $content;
|
||||
return filter($content);
|
||||
}
|
||||
|
||||
public function sidebar_params($params) {
|
||||
global $wp_registered_widgets;
|
||||
$widget_id = $params[0]['widget_id'];
|
||||
|
||||
$wp_registered_widgets[$widget_id]['_callback'] = $wp_registered_widgets[$widget_id]['callback'];
|
||||
$wp_registered_widgets[$widget_id]['callback'] = array($this, 'widget_callback');
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function widget_callback() {
|
||||
global $wp_registered_widgets;
|
||||
$params = func_get_args();
|
||||
$widget_id = $params[0]['widget_id'];
|
||||
|
||||
$callback = $wp_registered_widgets[$widget_id]['_callback'];
|
||||
$wp_registered_widgets[$widget_id]['callback'] = $callback;
|
||||
|
||||
$widget_id_base = $wp_registered_widgets[$widget_id]['callback'][0]->id_base;
|
||||
|
||||
if (is_callable($callback)) {
|
||||
ob_start();
|
||||
call_user_func_array($callback, $params);
|
||||
$widget_output = ob_get_clean();
|
||||
|
||||
echo apply_filters('widget_output', $widget_output, $widget_id_base, $widget_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Filter::instance();
|
||||
Reference in New Issue
Block a user