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