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