Skip to content

Commit da694b1

Browse files
authored
Merge pull request #6 from firstandthird/yoast-fixes
add an option to disable author output from Yoast
2 parents 1d084d7 + 4e7342b commit da694b1

File tree

7 files changed

+204
-11
lines changed

7 files changed

+204
-11
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
tmp
22
wp-disable-authors.zip
3-
vendor
3+
vendor
4+
test-plugins

composer.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,22 @@
33
"description": "Prevents leaking of author information in Wordpress",
44
"type": "library",
55
"require": {
6-
"automattic/vipwpcs": "^2.0"
6+
"automattic/vipwpcs": "^2.0",
7+
"wpackagist-plugin/wordpress-seo": "14.1"
78
},
89
"require-dev": {
910
"squizlabs/php_codesniffer": "^3.5",
1011
"dealerdirect/phpcodesniffer-composer-installer": "^0.6.2"
12+
},
13+
"repositories":[
14+
{
15+
"type":"composer",
16+
"url":"https://wpackagist.org"
17+
}
18+
],
19+
"extra": {
20+
"installer-paths": {
21+
"test-plugins/{$name}/": ["type:wordpress-plugin"]
22+
}
1123
}
1224
}

composer.lock

Lines changed: 152 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ services:
1010
ABSPATH: /usr/src/wordpress/
1111
volumes:
1212
- wordpress:/var/www/html
13+
- ./test-plugins:/var/www/html/wp-content/plugins
1314
- .:/var/www/html/wp-content/plugins/wp-disable-authors
1415
depends_on:
1516
- mysql
@@ -21,4 +22,4 @@ services:
2122
MYSQL_DATABASE: wordpress_test
2223

2324
volumes:
24-
wordpress:
25+
wordpress:

inc/plugin-patcher.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
// Yoast (wordpress-seo)
4+
$disableauthorsYoast = get_option('disableauthors_yoast', 'on');
5+
if ($disableauthorsYoast) {
6+
add_filter('wpseo_schema_needs_author', '__return_false');
7+
add_filter('wpseo_schema_needs_person', '__return_false');
8+
add_filter('wpseo_schema_article', 'disableauthorsYoastSchema');
9+
add_filter('wpseo_schema_webpage', 'disableauthorsYoastSchema');
10+
11+
function disableauthorsYoastSchema($schema) {
12+
$schema['author'] = get_bloginfo('name');
13+
return $schema;
14+
}
15+
}

inc/settings-page.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function disableauthors_settings_init( ) {
1111
register_setting('disableauthors', 'disableauthors_default_name', array( 'default' => 'Anonymous' ));
1212
register_setting('disableauthors', 'disableauthors_disable_feed', array( 'default' => true ));
1313
register_setting('disableauthors', 'disableauthors_disable_author_pages', array( 'default' => true ));
14+
register_setting('disableauthors', 'disableauthors_yoast', array( 'default' => true ));
1415

1516
add_settings_section(
1617
'disableauthors_pluginPage_settings_section',
@@ -36,7 +37,14 @@ function disableauthors_settings_init( ) {
3637
add_settings_field(
3738
'disable-author-pages',
3839
__('Disable Author Pages', 'disableauthors'),
39-
'disableauthors_field_default_disable_author_pages',
40+
'disableauthors_field_disable_author_pages',
41+
'disableauthors',
42+
'disableauthors_pluginPage_settings_section'
43+
);
44+
add_settings_field(
45+
'disable-author-yoast',
46+
__('Patch Yoast (wordpress-seo)', 'disableauthors'),
47+
'disableauthors_field_yoast',
4048
'disableauthors',
4149
'disableauthors_pluginPage_settings_section'
4250
);
@@ -59,7 +67,7 @@ function disableauthors_field_disable_feed_render() {
5967
<?php
6068
}
6169

62-
function disableauthors_field_default_disable_author_pages() {
70+
function disableauthors_field_disable_author_pages() {
6371
$option = get_option('disableauthors_disable_author_pages', 'on');
6472
$checked = $option === 'on';
6573
?>
@@ -68,6 +76,15 @@ function disableauthors_field_default_disable_author_pages() {
6876
<?php
6977
}
7078

79+
function disableauthors_field_yoast() {
80+
$option = get_option('disableauthors_yoast', 'on');
81+
$checked = $option === 'on';
82+
?>
83+
<label><input type="checkbox" name='disableauthors_yoast' <?php checked($checked); ?> /> <?php esc_html_e('Patch Yoast (wordpress-seo) plugin?', 'disableauthors'); ?></label>
84+
<p><?php esc_html_e('Customizes Yoast to not output author details. Primarily affects ld+json output and may have an impact on seo.', 'disableauthors'); ?></p>
85+
<?php
86+
}
87+
7188
function disableauthors_options_page() {
7289
?>
7390
<form action='options.php' method='post'>

wp-disable-authors.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
require_once(__DIR__ . '/inc/disable-feeds.php');
1414
require_once(__DIR__ . '/inc/rename-author.php');
1515
require_once(__DIR__ . '/inc/disable-author.php');
16+
require_once(__DIR__ . '/inc/plugin-patcher.php');

0 commit comments

Comments
 (0)