PluginProbe
Hide/Remove Metadata / 2.0
Hide/Remove Metadata v2.0
trunk 1.0.0 1.0.1 1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.1
← All changes | hide-metadata.php +126 -138 1.2.72.0 View file →
@@ -4,9 +4,9 @@
4 4 * Description: Hide/Remove Metadata is a free, simple yet extremely handy WordPress plugin that helps you hide author and published date either by CSS or PHP from your website effortlessly.
5 5 * Plugin URI: http://catchplugins.com/plugins/hide-metadata
6 6 * Author: Catch Plugins
7 7 * Author URI: http://catchplugins.com/
8 - * Version: 1.2.7
8 + * Version: 2.0
9 9 * License: GPL2
10 10 * Text Domain: hide-metadata
11 11 * Domain Path: /languages
12 12 */
@@ -27,59 +27,81 @@
27 27 along with this program; if not, write to the Free Software
28 28 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 29 */
30 30
31 -define( 'HIDE_METADATA_VERSION', '1.2.7' );
32 -define( 'HIDE_METADATA_BASENAME', plugin_basename( __FILE__ ) );
31 +if (! defined('ABSPATH')) {
32 + exit; // Exit if accessed directly
33 +}
33 34
34 -class Hide_Metadata {
35 +// Define Version
36 +if ( ! defined( 'HIDE_METADATA_VERSION' ) ) {
37 + define( 'HIDE_METADATA_VERSION', '2.0' );
38 +}
39 +
40 +if ( ! defined( 'HIDE_METADATA_BASENAME' ) ) {
41 + define('HIDE_METADATA_BASENAME', plugin_basename(__FILE__));
42 +}
43 +
44 +class Hide_Metadata
45 +{
35 46 private $plugin_name;
36 47 private $version;
37 48 private $options;
38 49
39 - function __construct() {
50 + function __construct()
51 + {
40 52 $this->plugin_name = 'hide-metadata';
41 53 $this->version = HIDE_METADATA_VERSION;
42 54 $this->options = hide_metadata_get_options();
43 55
44 - add_action( 'admin_init', array( $this, 'register_settings' ) );
45 - add_action( 'admin_menu', array( $this, 'add_plugin_settings_menu' ) );
46 - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) );
47 - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
56 + add_filter('body_class', array($this, 'hide_metadata_body_class'));
57 + add_action('admin_init', array($this, 'register_settings'));
58 + add_action('admin_menu', array($this, 'add_plugin_settings_menu'));
59 + add_action('admin_enqueue_scripts', array($this, 'enqueue_styles'));
60 + add_action('wp_enqueue_scripts', array($this, 'plugin_styles'));
61 + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
48 62
49 - add_filter( 'plugin_row_meta', array( $this, 'add_plugin_meta_links' ), 10, 2 );
63 + add_filter('plugin_row_meta', array($this, 'add_plugin_meta_links'), 10, 2);
50 64
51 - add_filter( 'plugin_action_links', array( $this, 'action_links' ), 10, 2 );
65 + add_filter('plugin_action_links', array($this, 'action_links'), 10, 2);
52 66
53 - if ( 'php' === $this->options['hide_by'] ) {
54 - add_action( 'loop_start', array( $this, 'remove_php' ) );
55 - add_action( 'init', array( $this, 'remove_php' ) );
67 + if ('php' === $this->options['hide_by']) {
68 + add_action('loop_start', array($this, 'remove_php'));
69 + add_action('init', array($this, 'remove_php'));
56 70 }
57 - add_action( 'wp_head', array( $this, 'css_filter_option' ) );
58 71 }
59 72
73 +
60 74 /**
61 75 * Register the stylesheets for the admin area.
62 76 *
63 77 * @since 1.0.0
64 78 */
65 - function enqueue_styles() {
66 - if ( isset( $_GET['page'] ) && 'hide-metadata' === $_GET['page'] ) {
67 - wp_enqueue_style( $this->plugin_name . '-display-dashboard', plugin_dir_url( __FILE__ ) . 'css/admin-dashboard.css', array(), $this->version, 'all' );
79 + function enqueue_styles()
80 + {
81 + if (isset($_GET['page']) && 'hide-metadata' === $_GET['page']) {
82 + wp_enqueue_style($this->plugin_name . '-display-dashboard', plugin_dir_url(__FILE__) . 'css/admin-dashboard.css', array(), $this->version, 'all');
68 83 }
69 84 }
70 85
86 +
87 + function plugin_styles()
88 + {
89 + wp_enqueue_style($this->plugin_name . '-style', plugin_dir_url(__FILE__) . 'css/style.css', array(), $this->version, 'all');
90 + }
91 +
92 +
71 93 /**
72 94 * Register the scripts for the admin area.
73 95 *
74 96 * @since 1.0.0
75 97 */
76 - function enqueue_scripts() {
77 - if ( isset( $_GET['page'] ) && 'hide-metadata' === $_GET['page'] ) {
78 - wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/hide-metadata-admin.js', array( 'jquery', 'matchHeight', 'jquery-ui-tooltip' ), $this->version, false );
98 + function enqueue_scripts()
99 + {
100 + if (isset($_GET['page']) && 'hide-metadata' === $_GET['page']) {
101 + wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/hide-metadata-admin.js', array('jquery', 'matchHeight', 'jquery-ui-tooltip'), $this->version, false);
79 102
80 - wp_enqueue_script( 'matchHeight', plugin_dir_url( __FILE__ ) . 'js/jquery-matchHeight.min.js', array( 'jquery' ), $this->version, false );
81 -
103 + wp_enqueue_script('matchHeight', plugin_dir_url(__FILE__) . 'js/jquery-matchHeight.min.js', array('jquery'), $this->version, false);
82 104 }
83 105 }
84 106
85 107 /**
@@ -89,13 +111,14 @@
89 111 * @param arrray $links Link url.
90 112 *
91 113 * @param arrray $file File name.
92 114 */
93 - function action_links( $links, $file ) {
94 - if ( $file === $this->plugin_name . '/' . $this->plugin_name . '.php' ) {
95 - $settings_link = '<a href="' . esc_url( admin_url( 'admin.php?page=hide-metadata' ) ) . '">' . esc_html__( 'Settings', 'hide-metadata' ) . '</a>';
115 + function action_links($links, $file)
116 + {
117 + if ($file === $this->plugin_name . '/' . $this->plugin_name . '.php') {
118 + $settings_link = '<a href="' . esc_url(admin_url('admin.php?page=hide-metadata')) . '">' . esc_html__('Settings', 'hide-metadata') . '</a>';
96 119
97 - array_unshift( $links, $settings_link );
120 + array_unshift($links, $settings_link);
98 121 }
99 122 return $links;
100 123 }
101 124
@@ -101,17 +124,18 @@
101 124
102 125 /**
103 126 * Add settings menu
104 127 */
105 - function add_plugin_settings_menu() {
128 + function add_plugin_settings_menu()
129 + {
106 130 // Add menu under tools
107 131 add_submenu_page(
108 132 'tools.php',
109 - esc_html__( 'Hide/Remove Metadata', 'hide-metadata' ),
110 - esc_html__( 'Hide/Remove Metadata', 'hide-metadata' ),
133 + esc_html__('Hide/Remove Metadata', 'hide-metadata'),
134 + esc_html__('Hide/Remove Metadata', 'hide-metadata'),
111 135 'manage_options',
112 136 'hide-metadata',
113 - array( $this, 'settings_page' )
137 + array($this, 'settings_page')
114 138 );
115 139 }
116 140
117 141 /**
@@ -117,27 +141,30 @@
117 141 /**
118 142 * Hide/Remove MetaData: settings_page
119 143 * Hide/Remove MetaData Setting function
120 144 */
121 - function settings_page() {
122 - if ( ! current_user_can( 'manage_options' ) ) {
123 - wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) );
145 + function settings_page()
146 + {
147 + if (! current_user_can('manage_options')) {
148 + wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'hide-metadata'));
124 149 }
125 150
126 - require plugin_dir_path( __FILE__ ) . 'partials/admin-display.php';
151 + require plugin_dir_path(__FILE__) . 'partials/admin-display.php';
127 152 }
128 153
129 - function register_settings() {
154 + function register_settings()
155 + {
130 156 register_setting(
131 157 'hide-metadata-group',
132 158 'hide_metadata_options',
133 - array( $this, 'sanitize_callback' )
159 + array($this, 'sanitize_callback')
134 160 );
135 161 }
136 162
137 - public function sanitize_callback( $input ) {
163 + public function sanitize_callback($input)
164 + {
138 165
139 - if ( isset( $input['reset'] ) && $input['reset'] ) {
166 + if (isset($input['reset']) && $input['reset']) {
140 167 // If reset, restore defaults
141 168 return hide_metadata_default_options();
142 169 }
143 170 $message = null;
@@ -143,135 +170,95 @@
143 170 $message = null;
144 171 $type = null;
145 172
146 173 // Verify the nonce before proceeding.
147 - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
148 - || ( ! isset( $_POST['hide_metadata_nonce'] )
149 - || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['hide_metadata_nonce'] ) ), HIDE_METADATA_BASENAME ) )
150 - || ( ! check_admin_referer( HIDE_METADATA_BASENAME, 'hide_metadata_nonce' ) ) ) {
174 + if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
175 + || (! isset($_POST['hide_metadata_nonce'])
176 + || ! wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['hide_metadata_nonce'])), HIDE_METADATA_BASENAME))
177 + || (! check_admin_referer(HIDE_METADATA_BASENAME, 'hide_metadata_nonce'))
178 + ) {
151 179
152 - return esc_html__( 'Invalid Nonce', 'hide-metadata' );
153 -
180 + return esc_html__('Invalid Nonce', 'hide-metadata');
154 181 } else {
155 - if ( null !== $input ) {
182 + if (null !== $input) {
156 183
157 - $input['hide_by'] = sanitize_key( $input['hide_by'] );
158 - $input['hide_author'] = ( isset( $input['hide_author'] ) && '1' === $input['hide_author'] ) ? '1' : '0';
159 - $input['hide_date'] = ( isset( $input['hide_date'] ) && '1' === $input['hide_date'] ) ? '1' : '0';
160 -
184 + $input['hide_by'] = sanitize_key($input['hide_by']);
185 + $input['hide_author'] = (isset($input['hide_author']) && '1' === $input['hide_author']) ? '1' : '0';
186 + $input['hide_date'] = (isset($input['hide_date']) && '1' === $input['hide_date']) ? '1' : '0';
161 187 }
162 188 return $input;
163 189 }
164 190 }
165 191
166 - function hide_by_css() {
167 192
168 - $css = '';
193 + // Removal using css
194 +
195 + public function hide_metadata_body_class($classes)
196 + {
197 +
169 198 $options = hide_metadata_get_options();
170 - // Hide author CSS
171 - if ( '1' === $options['hide_author'] && 'css' === $options['hide_by'] ) {
172 - $css .= ".entry-meta .byline,
173 - .entry-meta .by-author,
174 - .entry-header .entry-meta > span.byline,
175 - .entry-meta .author.vcard {
176 - display: none;
177 - }\n";
199 +
200 + if ('1' === $options['hide_author'] && 'css' === $options['hide_by']) {
201 + $classes[] = 'hide-meta-author';
178 202 }
179 -
180 - // Hide date CSS
181 - if ( '1' === $options['hide_date'] && 'css' === $options['hide_by'] ) {
182 - $css .= ".entry-meta .posted-on,
183 - .entry-header .entry-meta > span.posted-on {
184 - display: none;
185 - }\n";
203 + if ('1' === $options['hide_date'] && 'css' === $options['hide_by']) {
204 + $classes[] = 'hide-meta-date';
186 205 }
187 -
188 - // Hide author
189 - if ( '1' === $options['hide_author'] && 'php' === $options['hide_by'] ) {
190 - $css .= ".entry-meta .byline:before,
191 - .entry-header .entry-meta span.byline:before,
192 - .entry-meta .byline:after,
193 - .entry-header .entry-meta span.byline:after,
194 - .single .byline, .group-blog .byline,
195 - .entry-meta .byline,
196 - .entry-header .entry-meta > span.byline,
197 - .entry-meta .author.vcard {
198 - content: '';
199 - display: none;
200 - margin: 0;
201 - }\n";
206 + if ('1' === $options['hide_date'] && 'php' === $options['hide_by']) {
207 + $classes[] = 'hide-meta-date-php';
202 208 }
203 -
204 - // Hide date
205 - if ( '1' === $options['hide_date'] && 'php' === $options['hide_by'] ) {
206 - $css .= ".entry-meta .posted-on:before,
207 - .entry-header .entry-meta > span.posted-on:before,
208 - .entry-meta .posted-on:after,
209 - .entry-header .entry-meta > span.posted-on:after,
210 - .entry-meta .posted-on,
211 - .entry-header .entry-meta > span.posted-on {
212 - content: '';
213 - display: none;
214 - margin: 0;
215 - }\n";
209 + if ('1' === $options['hide_author'] && 'php' === $options['hide_by']) {
210 + $classes[] = 'hide-meta-author-php';
216 211 }
217 212
218 - return $css;
213 + return $classes;
219 214 }
220 215
221 - // Removal using css
222 216
223 - function inline_style() {
224 - $css = $this->hide_by_css();
225 - if ( ! empty( $css ) ) {
226 - echo "<style>\n\n/* CSS added by Hide Metadata Plugin */\n\n" . wp_strip_all_tags( $css ) . "</style>\n";
227 - }
228 - }
229 217
230 - function remove_php() {
218 + function remove_php()
219 + {
231 220 $options = hide_metadata_get_options();
232 221
233 - if ( '1' === $options['hide_author'] ) {
234 - add_filter( 'the_author', '__return_false' );
235 - add_filter( 'get_the_author', '__return_false' );
236 - add_filter( 'author_link', '__return_false' );
222 + if ('1' === $options['hide_author']) {
223 + add_filter('the_author', '__return_false');
224 + add_filter('get_the_author', '__return_false');
225 + add_filter('author_link', '__return_false');
237 226 }
238 227
239 - if ( '1' === $options['hide_date'] ) {
240 - add_filter( 'the_date', '__return_false' );
241 - add_filter( 'the_time', '__return_false' );
242 - add_filter( 'the_modified_date', '__return_false' );
243 - add_filter( 'get_the_date', '__return_false' );
244 - add_filter( 'get_the_title', '__return_false' );
245 - add_filter( 'get_the_time', '__return_false' );
246 - add_filter( 'get_the_modified_date', '__return_false' );
228 + if ('1' === $options['hide_date']) {
229 + add_filter('the_date', '__return_false');
230 + add_filter('the_time', '__return_false');
231 + add_filter('the_modified_date', '__return_false');
232 + add_filter('get_the_date', '__return_false');
233 + add_filter('get_the_title', '__return_false');
234 + add_filter('get_the_time', '__return_false');
235 + add_filter('get_the_modified_date', '__return_false');
247 236 }
248 237 }
249 238
250 - function css_filter_option() {
251 - $this->inline_style();
252 - }
253 239
254 - function add_plugin_meta_links( $meta_fields, $file ) {
240 + function add_plugin_meta_links($meta_fields, $file)
241 + {
255 242
256 - if ( plugin_basename( __FILE__ ) === $file ) {
243 + if (plugin_basename(__FILE__) === $file) {
257 244
258 245 $meta_fields[] = "<a href='https://catchplugins.com/support-forum/forum/hide-metadata/' target='_blank'>Support Forum</a>";
259 246 $meta_fields[] = "<a href='https://wordpress.org/support/plugin/hide-metadata/reviews#new-post' target='_blank' title='Rate'>
260 247 <i class='ct-rate-stars'>"
261 - . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>"
262 - . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>"
263 - . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>"
264 - . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>"
265 - . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>"
266 - . '</i></a>';
248 + . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>"
249 + . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>"
250 + . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>"
251 + . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>"
252 + . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>"
253 + . '</i></a>';
267 254
268 255 $stars_color = '#ffb900';
269 256
270 257 echo '<style>'
271 - . '.ct-rate-stars{display:inline-block;color:' . $stars_color . ';position:relative;top:3px;}'
272 - . '.ct-rate-stars svg{fill:' . $stars_color . ';}'
273 - . '.ct-rate-stars svg:hover{fill:' . $stars_color . '}'
258 + . '.ct-rate-stars{display:inline-block;color:' . esc_html($stars_color) . ';position:relative;top:3px;}'
259 + . '.ct-rate-stars svg{fill:' . esc_html($stars_color) . ';}'
260 + . '.ct-rate-stars svg:hover{fill:' . esc_html($stars_color) . '}'
274 261 . '.ct-rate-stars svg:hover ~ svg{fill:none;}'
275 262 . '</style>';
276 263 }
277 264
@@ -276,15 +263,15 @@
276 263 }
277 264
278 265 return $meta_fields;
279 266 }
280 -
281 267 }
282 268
283 269 new Hide_Metadata();
284 270
285 271
286 -function hide_metadata_default_options( $option = null ) {
272 +function hide_metadata_default_options($option = null)
273 +{
287 274 $default_options = array(
288 275 'hide_by' => 'css',
289 276 'hide_author' => '0',
290 277 'hide_date' => '0',
@@ -289,17 +276,18 @@
289 276 'hide_author' => '0',
290 277 'hide_date' => '0',
291 278 );
292 279
293 - if ( null === $option ) {
294 - return apply_filters( 'hide_metadata_options', $default_options );
280 + if (null === $option) {
281 + return apply_filters('hide_metadata_options', $default_options);
295 282 } else {
296 - return $default_options[ $option ];
283 + return $default_options[$option];
297 284 }
298 285 }
299 286
300 -function hide_metadata_get_options() {
287 +function hide_metadata_get_options()
288 +{
301 289 $defaults = hide_metadata_default_options();
302 - $options = get_option( 'hide_metadata_options', $defaults );
290 + $options = get_option('hide_metadata_options', $defaults);
303 291
304 - return wp_parse_args( $options, $defaults );
292 + return wp_parse_args($options, $defaults);
305 293 }