PluginProbe
Hide/Remove Metadata / 1.2.2
Hide/Remove Metadata v1.2.2
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
hide-metadata / hide-metadata.php

hide-metadata.php in Hide/Remove Metadata 1.2.2, at hide-metadata.php

305 lines 10.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Hide/Remove Metadata
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 * Plugin URI: http://catchplugins.com/plugins/hide-metadata
6 * Author: Catch Plugins
7 * Author URI: http://catchplugins.com/
8 * Version: 1.2.2
9 * License: GPL2
10 * Text Domain: hide-metadata
11 * Domain Path: /languages
12 */
13
14 /*
15 Copyright (C) Year Author Email
16
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License, version 2, as
19 published by the Free Software Foundation.
20
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 */
30
31 define( 'HIDE_METADATA_VERSION', '1.2.2' );
32 define( 'HIDE_METADATA_BASENAME', plugin_basename( __FILE__ ) );
33
34 class Hide_Metadata {
35 private $plugin_name;
36 private $version;
37 private $options;
38
39 function __construct() {
40 $this->plugin_name = 'hide-metadata';
41 $this->version = HIDE_METADATA_VERSION;
42 $this->options = hide_metadata_get_options();
43
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' ) );
48
49 add_filter( 'plugin_row_meta', array( $this, 'add_plugin_meta_links' ), 10, 2 );
50
51 add_filter( 'plugin_action_links', array( $this, 'action_links' ), 10, 2 );
52
53 if ( 'php' === $this->options['hide_by'] ) {
54 add_action( 'loop_start', array( $this, 'remove_php' ) );
55 add_action( 'init', array( $this, 'remove_php' ) );
56 }
57 add_action( 'wp_head', array( $this, 'css_filter_option' ) );
58 }
59
60 /**
61 * Register the stylesheets for the admin area.
62 *
63 * @since 1.0.0
64 */
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' );
68 }
69 }
70
71 /**
72 * Register the scripts for the admin area.
73 *
74 * @since 1.0.0
75 */
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 );
79
80 wp_enqueue_script( 'matchHeight', plugin_dir_url( __FILE__ ) . 'js/jquery-matchHeight.min.js', array( 'jquery' ), $this->version, false );
81
82 }
83 }
84
85 /**
86 * Hide/Remove MetaData: action_links
87 * Hide/Remove MetaData Settings Link function callback
88 *
89 * @param arrray $links Link url.
90 *
91 * @param arrray $file File name.
92 */
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>';
96
97 array_unshift( $links, $settings_link );
98 }
99 return $links;
100 }
101
102 /**
103 * Add settings menu
104 */
105 function add_plugin_settings_menu() {
106 // Add menu under tools
107 add_submenu_page(
108 'tools.php',
109 esc_html__( 'Hide/Remove Metadata', 'hide-metadata' ),
110 esc_html__( 'Hide/Remove Metadata', 'hide-metadata' ),
111 'manage_options',
112 'hide-metadata',
113 array( $this, 'settings_page' )
114 );
115 }
116
117 /**
118 * Hide/Remove MetaData: settings_page
119 * Hide/Remove MetaData Setting function
120 */
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.' ) );
124 }
125
126 require plugin_dir_path( __FILE__ ) . 'partials/admin-display.php';
127 }
128
129 function register_settings() {
130 register_setting(
131 'hide-metadata-group',
132 'hide_metadata_options',
133 array( $this, 'sanitize_callback' )
134 );
135 }
136
137 public function sanitize_callback( $input ) {
138
139 if ( isset( $input['reset'] ) && $input['reset'] ) {
140 //If reset, restore defaults
141 return hide_metadata_default_options();
142 }
143 $message = null;
144 $type = null;
145
146 // 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' ) ) ) {
151
152 return esc_html__( 'Invalid Nonce', 'hide-metadata' );
153
154 } else {
155 if ( null !== $input ) {
156
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
161 }
162 return $input;
163 }
164 }
165
166 function hide_by_css() {
167
168 $css = '';
169 $options = hide_metadata_get_options();
170
171 // Hide author CSS
172 if ( '1' === $options['hide_author'] && 'css' === $options['hide_by'] ) {
173 $css .= ".entry-meta .byline,
174 .entry-meta .by-author,
175 .entry-header .entry-meta > span.byline {
176 display: none;
177 }\n";
178 }
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";
186 }
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 content: '';
198 display: none;
199 margin: 0;
200 }\n";
201 }
202
203 // Hide date
204 if ( '1' === $options['hide_date'] && 'php' === $options['hide_by'] ) {
205 $css .= ".entry-meta .posted-on:before,
206 .entry-header .entry-meta > span.posted-on:before,
207 .entry-meta .posted-on:after,
208 .entry-header .entry-meta > span.posted-on:after,
209 .entry-meta .posted-on,
210 .entry-header .entry-meta > span.posted-on {
211 content: '';
212 display: none;
213 margin: 0;
214 }\n";
215 }
216
217 return $css;
218 }
219
220 //Removal using css
221
222 function inline_style() {
223 $css = $this->hide_by_css();
224 if ( ! empty( $css ) ) {
225 echo "<style>\n\n/* CSS added by Hide Metadata Plugin */\n\n" . wp_strip_all_tags( $css ) . "</style>\n";
226 }
227 }
228
229 function remove_php() {
230 $options = hide_metadata_get_options();
231
232 if ( '1' === $options['hide_author'] ) {
233 add_filter( 'the_author', '__return_false' );
234 add_filter( 'get_the_author', '__return_false' );
235 add_filter( 'author_link', '__return_false' );
236 }
237
238 if ( '1' === $options['hide_date'] ) {
239 add_filter( 'the_date', '__return_false' );
240 add_filter( 'the_time', '__return_false' );
241 add_filter( 'the_modified_date', '__return_false' );
242 add_filter( 'get_the_date', '__return_false' );
243 add_filter( 'get_the_title', '__return_false' );
244 add_filter( 'get_the_time', '__return_false' );
245 add_filter( 'get_the_modified_date', '__return_false' );
246 }
247 }
248
249 function css_filter_option() {
250 $this->inline_style();
251 }
252
253 function add_plugin_meta_links( $meta_fields, $file ) {
254
255 if ( plugin_basename( __FILE__ ) === $file ) {
256
257 $meta_fields[] = "<a href='https://catchplugins.com/support-forum/forum/hide-metadata/' target='_blank'>Support Forum</a>";
258 $meta_fields[] = "<a href='https://wordpress.org/support/plugin/hide-metadata/reviews#new-post' target='_blank' title='Rate'>
259 <i class='ct-rate-stars'>"
260 . "<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>"
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 . '</i></a>';
266
267 $stars_color = '#ffb900';
268
269 echo '<style>'
270 . '.ct-rate-stars{display:inline-block;color:' . $stars_color . ';position:relative;top:3px;}'
271 . '.ct-rate-stars svg{fill:' . $stars_color . ';}'
272 . '.ct-rate-stars svg:hover{fill:' . $stars_color . '}'
273 . '.ct-rate-stars svg:hover ~ svg{fill:none;}'
274 . '</style>';
275 }
276
277 return $meta_fields;
278 }
279
280 }
281
282 new Hide_Metadata();
283
284
285 function hide_metadata_default_options( $option = null ) {
286 $default_options = array(
287 'hide_by' => 'css',
288 'hide_author' => '0',
289 'hide_date' => '0',
290 );
291
292 if ( null === $option ) {
293 return apply_filters( 'hide_metadata_options', $default_options );
294 } else {
295 return $default_options[ $option ];
296 }
297 }
298
299 function hide_metadata_get_options() {
300 $defaults = hide_metadata_default_options();
301 $options = get_option( 'hide_metadata_options', $defaults );
302
303 return wp_parse_args( $options, $defaults );
304 }
305