PluginProbe
Embed Privacy / 1.10.10
Embed Privacy v1.10.10
1.14.0 1.13.0 trunk 0.1 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.1.3 1.10.0 1.10.1 1.10.10 1.10.2 1.10.3 1.10.4 1.10.5 1.10.6 1.10.7 1.10.8 1.10.9 1.11.0 1.11.1 1.11.2 All 68 releases
embed-privacy / inc / class-embed-privacy-widget-output-filter.php

class-embed-privacy-widget-output-filter.php in Embed Privacy 1.10.10, at inc/class-embed-privacy-widget-output-filter.php

155 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace epiphyt\Embed_Privacy;
3
4 /**
5 * Filter the output of widgets.
6 *
7 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\handler\Widget instead
8 * @see https://github.com/philipnewcomer/widget-output-filters
9 * @since 1.1.0
10 *
11 * @author Epiphyt
12 * @license GPL2
13 * @package epiphyt\Embed_Privacy
14 */
15 class Embed_Privacy_Widget_Output_Filter {
16 /**
17 * @var string The alternative option name of this filter
18 */
19 public $alt_option_name = '';
20
21 /**
22 * @var string The ID of this filter
23 */
24 public $id = '';
25
26 /**
27 * @var string The ID base of this filter
28 */
29 public $id_base = 'embed_privacy_widget_output_filter';
30
31 /**
32 * @var string The name of this filter
33 */
34 public $name = 'Embed Privacy';
35
36 /**
37 * @var string The option name of this filter
38 */
39 public $option_name = 'widget_embed_privacy_widget_output_filter';
40
41 /**
42 * @var bool The updated value of this filter
43 */
44 public $updated = false;
45
46 /**
47 * @var array The widget options of this filter
48 */
49 public $widget_options = [];
50
51 /**
52 * @var \epiphyt\Embed_Privacy\Embed_Privacy_Widget_Output_Filter
53 */
54 private static $instance;
55
56 /**
57 * Return the single instance of this class.
58 *
59 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\handler\Widget::get_instance() instead
60 *
61 * @return \epiphyt\Embed_Privacy\Embed_Privacy_Widget_Output_Filter The single instance of this class
62 */
63 public static function get_instance() {
64 if ( self::$instance === null ) {
65 self::$instance = new self();
66 }
67
68 return self::$instance;
69 }
70
71 /**
72 * Initialize the functionality by registering actions and filters.
73 *
74 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\handler\Widget instead
75 */
76 private function __construct() {
77 \add_filter( 'dynamic_sidebar_params', [ $this, 'filter_dynamic_sidebar_params' ], \PHP_INT_MAX );
78 }
79
80 /**
81 * Replace the widget's display callback with the Dynamic Sidebar Params display callback, storing the original callback for use later.
82 * The $sidebar_params variable is not modified; it is only used to get the current widget's ID.
83 *
84 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\handler\Widget::filter_dynamic_sidebar_params() instead
85 *
86 * @param array $sidebar_params The sidebar parameters
87 * @return array The sidebar parameters
88 */
89 public function filter_dynamic_sidebar_params( $sidebar_params ) {
90 \_doing_it_wrong(
91 __METHOD__,
92 \sprintf(
93 /* translators: alternative method */
94 \esc_html__( 'Use %s instead', 'embed-privacy' ),
95 'epiphyt\Embed_Privacy\handler\Widget::filter_dynamic_sidebar_params()'
96 ),
97 '1.10.0'
98 );
99
100 if ( \is_admin() ) {
101 return $sidebar_params;
102 }
103
104 global $wp_registered_widgets;
105 $current_widget_id = $sidebar_params[0]['widget_id'];
106
107 $wp_registered_widgets[ $current_widget_id ]['original_callback'] = $wp_registered_widgets[ $current_widget_id ]['callback']; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
108 $wp_registered_widgets[ $current_widget_id ]['callback'] = [ $this, 'display_widget' ]; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
109
110 return $sidebar_params;
111 }
112
113 /**
114 * Execute the widget's original callback function, filtering its output.
115 *
116 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\handler\Widget::display_widget() instead
117 */
118 public function display_widget() {
119 \_doing_it_wrong(
120 __METHOD__,
121 \sprintf(
122 /* translators: alternative method */
123 \esc_html__( 'Use %s instead', 'embed-privacy' ),
124 'epiphyt\Embed_Privacy\handler\Widget::display_widget()'
125 ),
126 '1.10.0'
127 );
128
129 global $wp_registered_widgets;
130 $original_callback_params = \func_get_args();
131
132 $widget_id = isset( $original_callback_params[0]['widget_id'] ) ? $original_callback_params[0]['widget_id'] : null;
133 $original_callback = $wp_registered_widgets[ $widget_id ]['original_callback'];
134
135 $wp_registered_widgets[ $widget_id ]['callback'] = $original_callback; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
136
137 $sidebar_id = isset( $original_callback_params[0]['id'] ) ? $original_callback_params[0]['id'] : null;
138
139 if ( \is_callable( $original_callback ) ) {
140 \ob_start();
141 \call_user_func_array( $original_callback, $original_callback_params ); // phpcs:ignore NeutronStandard.Functions.DisallowCallUserFunc.CallUserFunc
142 $widget_output = \ob_get_clean();
143
144 /**
145 * Filter the widget's output.
146 *
147 * @param string $widget_output The widget's output
148 * @param string $widget_id The widget's full ID
149 * @param string $sidebar_id The current sidebar ID
150 */
151 echo \apply_filters( 'embed_privacy_widget_output', $widget_output, $widget_id, $sidebar_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
152 }
153 }
154 }
155