Version Description
Download this release
Release Info
Developer | mspyratos |
Plugin | Show Hide Author |
Version | 1.2 |
Comparing to | |
See all releases |
Version 1.2
- readme.txt +90 -0
- show_hide_author.php +426 -0
readme.txt
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Show Hide Author ===
|
2 |
+
Contributors: mspyratos
|
3 |
+
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=EP9SLMTGLMRGY&lc=CA&item_name=WP%20Plugin%20%2d%20Show%20Hide%20Author&item_number=plugin_show_hide_author¤cy_code=CAD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
|
4 |
+
Tags: show author, hide author, remove author, author name
|
5 |
+
Requires at least: 3.0.1
|
6 |
+
Tested up to: 3.5
|
7 |
+
Stable tag: 1.2
|
8 |
+
License: GPLv2 or later
|
9 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
+
|
11 |
+
Choose whether to show or hide author name from posts.
|
12 |
+
|
13 |
+
== Description ==
|
14 |
+
|
15 |
+
With this plugin you can choose to show or hide the author name in posts.
|
16 |
+
You also can choose where to show the name.
|
17 |
+
|
18 |
+
= Choose to show or hide author name =
|
19 |
+
|
20 |
+
* In Different Post Types
|
21 |
+
* In Individual Pages
|
22 |
+
* In Custom URLs
|
23 |
+
|
24 |
+
= Themes Tested =
|
25 |
+
|
26 |
+
* Twenty Ten by Wordpress
|
27 |
+
* Twenty Eleven by Wordpress
|
28 |
+
* Twenty Twelve by Wordpress
|
29 |
+
* Theme Revenge on themerevenge.com
|
30 |
+
* Magnificent by ElegantThemes
|
31 |
+
|
32 |
+
= Note =
|
33 |
+
|
34 |
+
If plugin doesn't work as supposed to on your theme, please send me an email with the name of your theme and I will update the plugin.
|
35 |
+
|
36 |
+
= In Future Versions =
|
37 |
+
If the plugin proves to be useful and I find the time needed, I will extend its funcionality to choose whether to show or hide author name:
|
38 |
+
|
39 |
+
* In Individual Categories
|
40 |
+
* By Author Role and Name
|
41 |
+
|
42 |
+
and also make it compatible in more themes.
|
43 |
+
|
44 |
+
== Installation ==
|
45 |
+
|
46 |
+
= Method 1 =
|
47 |
+
|
48 |
+
Through default WP plugin installation page, using the "show_hide_author.zip" file.
|
49 |
+
|
50 |
+
= Method 2 =
|
51 |
+
|
52 |
+
By uploading the unzipped "show_hide_author" folder to the plugin directory.
|
53 |
+
|
54 |
+
= After Installation =
|
55 |
+
|
56 |
+
The plugin settings will be available under the "Plugins" main menu.
|
57 |
+
Click on "Plugins" main menu and then click on "Show Hide Author".
|
58 |
+
|
59 |
+
== FAQ ==
|
60 |
+
|
61 |
+
= Doens't work on my theme =
|
62 |
+
|
63 |
+
Please send me an email to m.spyratos@hotmail.ca and provide me the name of your theme you are using.
|
64 |
+
I will respond as quick as possible with a new version of the plugin, that will include your theme.
|
65 |
+
|
66 |
+
== Screenshots ==
|
67 |
+
|
68 |
+
1. One page settings, under the main menu "Plugins".
|
69 |
+
2. A post without the Author name in Twenty Eleven.
|
70 |
+
|
71 |
+
== Changelog ==
|
72 |
+
|
73 |
+
= Version 1.0 =
|
74 |
+
|
75 |
+
First Release
|
76 |
+
|
77 |
+
= Version 1.1 =
|
78 |
+
|
79 |
+
Fixed a misspelling in the code.
|
80 |
+
|
81 |
+
= Version 1.2 =
|
82 |
+
|
83 |
+
More Themes Support
|
84 |
+
|
85 |
+
== Contact Me ==
|
86 |
+
|
87 |
+
Please send me an email at m.spyratos@hotmail.ca.
|
88 |
+
|
89 |
+
If you have problems with the plugin, it's better to use the support forum.
|
90 |
+
This way other users can benefit.
|
show_hide_author.php
ADDED
@@ -0,0 +1,426 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Show Hide Author
|
4 |
+
Description: Choose whether to show or hide the author name.
|
5 |
+
Version: 1.2
|
6 |
+
Author: Michael Spyratos
|
7 |
+
Author URI: http://mspyratos.com/
|
8 |
+
License: GPL2
|
9 |
+
*/
|
10 |
+
|
11 |
+
/* Copyright 2013 Michael Spyratos (email : m.spyratos@hotmail.com)
|
12 |
+
|
13 |
+
This program is free software; you can redistribute it and/or modify
|
14 |
+
it under the terms of the GNU General Public License, version 2, as
|
15 |
+
published by the Free Software Foundation.
|
16 |
+
|
17 |
+
This program is distributed in the hope that it will be useful,
|
18 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20 |
+
GNU General Public License for more details.
|
21 |
+
|
22 |
+
You should have received a copy of the GNU General Public License
|
23 |
+
along with this program; if not, write to the Free Software
|
24 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
25 |
+
*/
|
26 |
+
|
27 |
+
/**
|
28 |
+
*
|
29 |
+
* FUNCTIONS
|
30 |
+
*
|
31 |
+
*/
|
32 |
+
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Creates default settings values uppon plugin activation
|
36 |
+
*/
|
37 |
+
function show_author_after_activation() {
|
38 |
+
global $wpdb;
|
39 |
+
$db_prefix = $wpdb->prefix;
|
40 |
+
$query = $wpdb->prepare("SELECT * FROM " . $db_prefix . "options WHERE `option_name`=%s", 'show_author_options');
|
41 |
+
$db_result = $wpdb->get_row($query);
|
42 |
+
if(is_null($db_result) || $db_result == "" || !isset($db_result)) {
|
43 |
+
$query = $wpdb->prepare("INSERT INTO " . $db_prefix . "options SET
|
44 |
+
option_name = %s,
|
45 |
+
option_value = %s,
|
46 |
+
autoload = %s
|
47 |
+
",
|
48 |
+
'show_author_options',
|
49 |
+
'a:6:{s:11:"option_post";s:4:"post";s:11:"option_page";s:4:"page";s:15:"option_url_show";s:0:"";s:15:"option_url_hide";s:0:"";s:15:"option_by_class";s:0:"";s:15:"option_by_regex";s:0:"";}',
|
50 |
+
'yes'
|
51 |
+
);
|
52 |
+
$wpdb->query($query);
|
53 |
+
}
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Deletes options from the database uppon plugin uninstall
|
58 |
+
*/
|
59 |
+
function show_author_after_uninstall() {
|
60 |
+
global $wpdb;
|
61 |
+
$db_prefix = $wpdb->prefix;
|
62 |
+
$query = $wpdb->prepare("DELETE FROM " . $db_prefix . "options WHERE `option_name`='show_author_options'");
|
63 |
+
$db_result = $wpdb->query($query);
|
64 |
+
}
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Creates the settings page
|
68 |
+
*/
|
69 |
+
function adminPanel() {
|
70 |
+
?>
|
71 |
+
|
72 |
+
<?php if( isset($_GET['settings-updated']) ) { ?>
|
73 |
+
<div id="message" class="updated">
|
74 |
+
<p><strong><?php _e('Settings saved.'); ?></strong></p>
|
75 |
+
</div>
|
76 |
+
<?php } ?>
|
77 |
+
<div class="wrap">
|
78 |
+
<?php screen_icon(); ?>
|
79 |
+
<h2>Show Hide Author - Settings</h2>
|
80 |
+
<p>On this page you configure where and if to show the aurhor name/link.</p>
|
81 |
+
<form method="post" action="options.php" id="show_author_form">
|
82 |
+
<?php settings_fields('admin_panel_group') ?>
|
83 |
+
<?php $options = get_option('show_author_options'); ?>
|
84 |
+
<fieldset>
|
85 |
+
<h2>Show author name in:</h2>
|
86 |
+
<p> </p>
|
87 |
+
<h3>Post Types</h3>
|
88 |
+
<?php
|
89 |
+
$all_post_type_names = get_post_types();
|
90 |
+
if(isset($all_post_type_names)) : ?>
|
91 |
+
<?php foreach($all_post_type_names as $post_type_name) : ?>
|
92 |
+
<div>
|
93 |
+
<input type="checkbox" id="show_author_<?php echo $post_type_name; ?>" name="show_author_options[option_<?php echo $post_type_name; ?>]"
|
94 |
+
value="<?php echo $post_type_name;?>" <?php if(isset($options['option_' . $post_type_name])) checked($post_type_name, $options['option_' . $post_type_name]); ?>>
|
95 |
+
<label for="show_author_options[option_<?php echo $post_type_name; ?>]"><?php echo ucfirst($post_type_name) . 's'; ?></label>
|
96 |
+
</div>
|
97 |
+
<?php endforeach; ?>
|
98 |
+
<?php endif; ?>
|
99 |
+
<p> </p>
|
100 |
+
<h3>Individual Pages</h3>
|
101 |
+
<p>Choose to show the author name in individual pages, from inside the editor while you compose a new post.</p>
|
102 |
+
<div>
|
103 |
+
<input type="checkbox" id="show_author_individual" name="show_author_options[option_individual]"
|
104 |
+
value="individual" <?php if(isset($options['option_individual'])) checked('individual', $options['option_individual']); ?>>
|
105 |
+
<label for="show_author_options[option_individual]">Individual Pages **</label>
|
106 |
+
</div>
|
107 |
+
<p> </p>
|
108 |
+
<h3>Custom URLs to Show Author Name</h3>
|
109 |
+
<div>
|
110 |
+
<p><label for="show_author_options[option_url_show]">Enter Custom Urls in seperate lines</label></p>
|
111 |
+
<textarea id="show_author_url_show" name="show_author_options[option_url_show]" rows="10" cols="50"><?php
|
112 |
+
if(isset($options['option_url_show']) && $options['option_url_show'] != '') echo $options['option_url_show']; ?></textarea>
|
113 |
+
</div>
|
114 |
+
<h3>Custom URLs to Hide Author Name</h3>
|
115 |
+
<div>
|
116 |
+
<p><label for="show_author_options[option_url_hide]">Enter Custom Urls in seperate lines</label></p>
|
117 |
+
<textarea id="show_author_url_hide" name="show_author_options[option_url_hide]" rows="10" cols="50"><?php
|
118 |
+
if(isset($options['option_url_hide']) && $options['option_url_hide'] != '') echo $options['option_url_hide']; ?></textarea>
|
119 |
+
<p>
|
120 |
+
<i>
|
121 |
+
For example:<br />
|
122 |
+
http://mydomain.com/<br />
|
123 |
+
http://mydomain.com/category
|
124 |
+
</i>
|
125 |
+
</p>
|
126 |
+
</div>
|
127 |
+
<h3>Advanced: Hide the "by" word</h3>
|
128 |
+
<p>If when removed the author name you're left with a "by" word, remove it by adding the class of the its parent element and/or a regex.</p>
|
129 |
+
<div>
|
130 |
+
<p><label for="show_author_options[option_by_class]">The parent classes<br /><i><?php echo 'e.g. entry-meta;author-meta'; ?></i></label></p>
|
131 |
+
<input type="text" id="show_author_by_class" name="show_author_options[option_by_class]" value="<?php
|
132 |
+
if(isset($options['option_by_class']) && $options['option_by_class'] != '') echo htmlspecialchars ($options['option_by_class']); ?>">
|
133 |
+
</div>
|
134 |
+
<div>
|
135 |
+
<p><label for="show_author_options[option_by_regex]">The regular expressions<br /><i><?php echo htmlspecialchars ('e.g. by <a(.*?)/a>;<span class="sep"> by </span>'); ?></i></label></p>
|
136 |
+
<input type="text" id="show_author_by_regex" name="show_author_options[option_by_regex]" value="<?php
|
137 |
+
if(isset($options['option_by_regex']) && $options['option_by_regex'] != '') echo htmlspecialchars ($options['option_by_regex']); ?>">
|
138 |
+
</div>
|
139 |
+
<p>
|
140 |
+
<i>Use multiple values by seperating them with a semicolon (;).<br />
|
141 |
+
The Default regex value is: <?php echo htmlspecialchars ('by <a(.*?)/a>'); ?>, which means select the word "by", followed by a link "a" tag.</i>
|
142 |
+
</p>
|
143 |
+
</fieldset>
|
144 |
+
<p><input name="Submit" type="submit" class="button button-primary button-large" value="<?php esc_attr_e('Save Changes'); ?>" /></p>
|
145 |
+
<p> </p>
|
146 |
+
<p><i><u>Notes</u>:<br />
|
147 |
+
If nothing submitted, author name will be hidden everywhere.<br />
|
148 |
+
If a post type (from above) doesn't support the display of author name, then even if you check it, it will not show up.<br />
|
149 |
+
</i></p>
|
150 |
+
</form>
|
151 |
+
</div> <!-- End of "wrap" -->
|
152 |
+
<?php
|
153 |
+
}
|
154 |
+
|
155 |
+
|
156 |
+
/**
|
157 |
+
* Displays the settings page
|
158 |
+
*/
|
159 |
+
function adminPanelPage() {
|
160 |
+
add_submenu_page('plugins.php', 'Show or hide the author name', 'Show/Hide Author', 'edit_plugins', 'show_hide_author', 'adminPanel');
|
161 |
+
}
|
162 |
+
|
163 |
+
/**
|
164 |
+
* Registers the settings to the ini
|
165 |
+
*/
|
166 |
+
function show_hide_author_init() {
|
167 |
+
register_setting( 'admin_panel_group', 'show_author_options');
|
168 |
+
}
|
169 |
+
|
170 |
+
/**
|
171 |
+
* Adds a meta-box in every post type
|
172 |
+
* This way you can choose to show author's name in individual pages
|
173 |
+
*/
|
174 |
+
function show_author_metabox($post) {
|
175 |
+
$show_author_inthis_post = get_post_meta( $post->ID, '_show_author_inthis_post', true );
|
176 |
+
?>
|
177 |
+
<p>Select whether to display or not the author's name, independently of the settings in <i>Show Hide Author</i> plugin.</p>
|
178 |
+
<div>
|
179 |
+
<input type="radio" id="show_author_inthis_post" name="show_author_inthis_post" value="author_default"
|
180 |
+
<?php if($show_author_inthis_post != 'inthis_post' && $show_author_inthis_post != 'not_inthis_post') {echo 'checked="checked"';} ?>>
|
181 |
+
<label>Use Settings in <i>Show Hide Author</i> plugin</label>
|
182 |
+
</div>
|
183 |
+
<div>
|
184 |
+
<input type="radio" id="show_author_inthis_post" name="show_author_inthis_post" value="inthis_post" <?php checked($show_author_inthis_post, 'inthis_post'); ?>>
|
185 |
+
<label>Show Author Name</label>
|
186 |
+
</div>
|
187 |
+
<div>
|
188 |
+
<input type="radio" id="hide_author_inthis_post" name="show_author_inthis_post" value="not_inthis_post" <?php checked($show_author_inthis_post, 'not_inthis_post'); ?>>
|
189 |
+
<label>Hide Author Name</label>
|
190 |
+
</div>
|
191 |
+
<?php
|
192 |
+
}
|
193 |
+
|
194 |
+
/**
|
195 |
+
* Creates the metaboxes calls
|
196 |
+
*/
|
197 |
+
function add_author_metabox() {
|
198 |
+
$all_post_type_names = get_post_types();
|
199 |
+
if(isset($all_post_type_names)) {
|
200 |
+
foreach($all_post_type_names as $post_type_name) {
|
201 |
+
add_meta_box( 'show_author_metabox', 'Show Hide Author Name', 'show_author_metabox', $post_type_name, 'normal' );
|
202 |
+
}
|
203 |
+
}
|
204 |
+
}
|
205 |
+
|
206 |
+
/**
|
207 |
+
* Saves/updates the meta-box settings
|
208 |
+
*/
|
209 |
+
function show_author_metabox_save($post_id) {
|
210 |
+
if ( isset( $_POST['show_author_inthis_post'] ) ) {
|
211 |
+
update_post_meta( $post_id, '_show_author_inthis_post', strip_tags( $_POST['show_author_inthis_post'] ) );
|
212 |
+
}
|
213 |
+
}
|
214 |
+
|
215 |
+
/**
|
216 |
+
* Removes the author name.
|
217 |
+
* Also overrides the core function in wp themes
|
218 |
+
*/
|
219 |
+
function remove_author() {
|
220 |
+
// Remove the "by" word with hooks
|
221 |
+
remove_the_by_hooks();
|
222 |
+
}
|
223 |
+
|
224 |
+
/**
|
225 |
+
* Gets the current - full url
|
226 |
+
* Source: http://webcheatsheet.com/php/get_current_page_url.php
|
227 |
+
*/
|
228 |
+
function current_full_url() {
|
229 |
+
$pageURL = 'http';
|
230 |
+
if (isset( $_SERVER["HTTPS"] ) && strtolower( $_SERVER["HTTPS"] )) {$pageURL .= "s";}
|
231 |
+
$pageURL .= "://";
|
232 |
+
if ($_SERVER["SERVER_PORT"] != "80") {
|
233 |
+
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
|
234 |
+
} else {
|
235 |
+
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
|
236 |
+
}
|
237 |
+
return $pageURL;
|
238 |
+
}
|
239 |
+
|
240 |
+
/**
|
241 |
+
* Checks whether to remove or not the author name
|
242 |
+
*/
|
243 |
+
function show_hide_author() {
|
244 |
+
$url = current_full_url();
|
245 |
+
// Get post id
|
246 |
+
global $post;
|
247 |
+
$ID = $post->ID;
|
248 |
+
// Get and prepare current url
|
249 |
+
$replace = array('/http:\/\/www./', '/https:\/\/www./', '/www./', '/\n\r/');
|
250 |
+
$with = array('', '', '', '\n');
|
251 |
+
$current_url_nohttp = preg_replace($replace, $with, $url);
|
252 |
+
$options_array = get_option('show_author_options');
|
253 |
+
// Get and prepare Show url
|
254 |
+
$option_urls_show_nohttp = preg_replace($replace, $with, $options_array['option_url_show']);
|
255 |
+
$urls_show_array = explode("\n", $option_urls_show_nohttp);
|
256 |
+
// Get and prepare Hide url
|
257 |
+
$option_urls_hide_nohttp = preg_replace($replace, $with, $options_array['option_url_hide']);
|
258 |
+
$urls_hide_array = explode("\n", $option_urls_hide_nohttp);
|
259 |
+
// If nothing submitted, hide the name everywhere
|
260 |
+
if(!is_array($options_array)) {
|
261 |
+
remove_author();
|
262 |
+
}
|
263 |
+
// If current url in Show urls
|
264 |
+
else if(in_array($current_url_nohttp, $urls_show_array)) {
|
265 |
+
// Show Author
|
266 |
+
}
|
267 |
+
// If current url in Hide urls
|
268 |
+
else if(in_array($current_url_nohttp, $urls_hide_array)) {
|
269 |
+
remove_author();
|
270 |
+
}
|
271 |
+
// Post Types
|
272 |
+
else if(in_array('individual', $options_array) && get_post_meta( $ID, '_show_author_inthis_post', true ) == 'inthis_post') {
|
273 |
+
// Show Author
|
274 |
+
} else if(in_array('individual', $options_array) && get_post_meta( $ID, '_show_author_inthis_post', true ) == 'not_inthis_post') {
|
275 |
+
remove_author();
|
276 |
+
} else if(empty($options_array) || !in_array(get_post_type($ID), $options_array)) {
|
277 |
+
remove_author();
|
278 |
+
} else {
|
279 |
+
// Show Author
|
280 |
+
}
|
281 |
+
}
|
282 |
+
|
283 |
+
/**
|
284 |
+
* Removes the author name
|
285 |
+
*/
|
286 |
+
function remove_author_name_filter() {
|
287 |
+
remove_filter('the_author', 'the_author');
|
288 |
+
}
|
289 |
+
|
290 |
+
/**
|
291 |
+
* Removes the author link
|
292 |
+
*/
|
293 |
+
function remove_author_link_filter() {
|
294 |
+
remove_filter('author_link', 'get_author_posts_url');
|
295 |
+
}
|
296 |
+
|
297 |
+
/**
|
298 |
+
* Removes the html remains, such as the word by, <a> tags, etc..
|
299 |
+
* Uses javascript
|
300 |
+
*/
|
301 |
+
function remove_the_by() {
|
302 |
+
$options_by = get_option('show_author_options');
|
303 |
+
// Get the classes submittes
|
304 |
+
$custom_classes = '';
|
305 |
+
if(isset($options_by['option_by_class']) && $options_by['option_by_class'] != '') {
|
306 |
+
$custom_classes_array = explode(';', $options_by['option_by_class']);
|
307 |
+
} else {
|
308 |
+
$custom_classes_array = array('');
|
309 |
+
}
|
310 |
+
foreach($custom_classes_array as $custom_class) {
|
311 |
+
$custom_classes .= "'" . $custom_class . "', ";
|
312 |
+
}
|
313 |
+
$custom_classes = substr($custom_classes, 0, -2);
|
314 |
+
// Get the regex submitted
|
315 |
+
if(isset($options_by['option_by_regex']) && $options_by['option_by_regex'] != '') {
|
316 |
+
$custom_regexs_array = explode(';', $options_by['option_by_regex']);
|
317 |
+
} else {
|
318 |
+
$custom_regexs_array = array('');
|
319 |
+
}
|
320 |
+
if($custom_regexs_array[0] != '') {
|
321 |
+
foreach($custom_regexs_array as $custom_regex) {
|
322 |
+
$custom_regexs .= $custom_regex . '|';
|
323 |
+
}
|
324 |
+
$custom_regexs = substr($custom_regexs, 0, -1);
|
325 |
+
$custom_regex_string = '/' . preg_replace('/\//', '\/', $custom_regexs) . '/';
|
326 |
+
} else {
|
327 |
+
$custom_regex_string = '';
|
328 |
+
}
|
329 |
+
|
330 |
+
//$custom_regexs = substr($custom_classes, 0, -2);
|
331 |
+
?>
|
332 |
+
<script>
|
333 |
+
<?php if(isset($options_by['option_by_class']) && $options_by['option_by_class'] != '') : ?>
|
334 |
+
// Custom Classes and Regexs
|
335 |
+
var classes = [<?php echo $custom_classes; ?>];
|
336 |
+
alert(<?php echo $custom_regex_string; ?>);
|
337 |
+
<?php if(isset($custom_regex_string) && $custom_regex_string != '') : ?>
|
338 |
+
var regex = <?php echo $custom_regex_string; ?>;
|
339 |
+
<?php else : ?>
|
340 |
+
var regex = / by <a(.*?)\/a>|<span class="sep"> by <\/span>/;
|
341 |
+
<?php endif; ?>
|
342 |
+
<?php else : ?>
|
343 |
+
// List of Themes, Classes and Regular expressions
|
344 |
+
var template_name = '<?php echo get_template(); ?>';
|
345 |
+
switch(template_name) {
|
346 |
+
case 'twentyeleven' :
|
347 |
+
var classes = ['entry-meta'];
|
348 |
+
var regex = / by <a(.*?)\/a>|<span class="sep"> by <\/span>/;
|
349 |
+
break;
|
350 |
+
case 'twentyten' :
|
351 |
+
var classes = ['entry-meta'];
|
352 |
+
var regex = / by <a(.*?)\/a>|<span class="meta-sep">by<\/span>/;
|
353 |
+
break;
|
354 |
+
case 'object' :
|
355 |
+
var classes = ['post-details', 'post'];
|
356 |
+
var regex = / by <span(.*?)\/span>|<p class="post-details">by/;
|
357 |
+
break;
|
358 |
+
case 'theme-revenge' :
|
359 |
+
var classes = ['post-entry-meta'];
|
360 |
+
var regex = /By <a(.*?)\/a> on/;
|
361 |
+
break;
|
362 |
+
case 'Magnificent' :
|
363 |
+
var classes = ['meta-info'];
|
364 |
+
var regex = /<span>by<\/span> <a(.*?)\/a>|Posted by <a(.*?)\/a> on /;
|
365 |
+
break;
|
366 |
+
default:
|
367 |
+
var classes = ['entry-meta'];
|
368 |
+
var regex = / by <a(.*?)\/a>|<span class="sep"> by <\/span>| <span class="meta-sep">by<\/span>/;
|
369 |
+
}
|
370 |
+
<?php endif; ?>
|
371 |
+
if (typeof classes[0] !== 'undefined' && classes[0] !== null) {
|
372 |
+
for(var i = 0; i < classes.length; i++) {
|
373 |
+
var elements = document.getElementsByClassName(classes[i]);
|
374 |
+
for (var j = 0; j < elements.length; j++) {
|
375 |
+
if (elements[j].innerHTML.match(regex)) {
|
376 |
+
var replaced_txt = elements[j].innerHTML.replace(regex, '');
|
377 |
+
elements[j].innerHTML = replaced_txt;
|
378 |
+
}
|
379 |
+
}
|
380 |
+
}
|
381 |
+
}
|
382 |
+
|
383 |
+
</script>
|
384 |
+
<?php
|
385 |
+
}
|
386 |
+
|
387 |
+
/**
|
388 |
+
* Hooks the functions to remove the author
|
389 |
+
*/
|
390 |
+
function remove_the_by_hooks() {
|
391 |
+
add_filter('the_author', 'remove_author_name_filter');
|
392 |
+
add_filter('author_link', 'remove_author_link_filter');
|
393 |
+
add_action('wp_footer', 'remove_the_by');
|
394 |
+
}
|
395 |
+
|
396 |
+
|
397 |
+
/**
|
398 |
+
*
|
399 |
+
* HOOKS
|
400 |
+
*
|
401 |
+
*/
|
402 |
+
|
403 |
+
// After plugin activation, create default settings values
|
404 |
+
register_activation_hook( __FILE__, 'show_author_after_activation' );
|
405 |
+
|
406 |
+
// When uninstall, delete plugin's options from the database
|
407 |
+
register_uninstall_hook( __FILE__, 'show_author_after_uninstall' );
|
408 |
+
|
409 |
+
// Add submenu to the plugin menu that links to the plugin's settings page
|
410 |
+
add_action('admin_menu', 'adminPanelPage');
|
411 |
+
|
412 |
+
// Register the settings to the ini
|
413 |
+
add_action('admin_init', 'show_hide_author_init');
|
414 |
+
|
415 |
+
// Adds the metabox
|
416 |
+
// ! backwards compatible (before WP 3.0)
|
417 |
+
// add_action( 'admin_init', 'add_author_metabox', 1 );
|
418 |
+
add_action( 'add_meta_boxes', 'add_author_metabox' );
|
419 |
+
|
420 |
+
// Save the meta box settings
|
421 |
+
add_action( 'save_post', 'show_author_metabox_save' );
|
422 |
+
|
423 |
+
// Decides whether to show or hide the author
|
424 |
+
add_action('wp_head', 'show_hide_author');
|
425 |
+
|
426 |
+
|