Skip to content

Commit deef011

Browse files
author
Praesidiarius
committed
Comments disabled, xml rpc, emojis
1 parent b7612de commit deef011

File tree

7 files changed

+246
-3
lines changed

7 files changed

+246
-3
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
/**
4+
* Plugin loader.
5+
*
6+
* @package OnePlace\Swissknife
7+
* @copyright 2019 Verein onePlace
8+
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html GNU General Public License, version 2
9+
* @link https://1plc.ch/wordpress-plugins/swissknife
10+
*/
11+
12+
namespace OnePlace\Swissknife\Modules;
13+
14+
use OnePlace\Swissknife\Plugin;
15+
16+
final class Comments {
17+
/**
18+
* Main instance of the module
19+
*
20+
* @since 0.1-stable
21+
* @var Plugin|null
22+
*/
23+
private static $instance = null;
24+
25+
/**
26+
* Disable wordpress comments entirely
27+
*
28+
* @since 0.1-stable
29+
*/
30+
public function register() {
31+
// Close comments on the front-end
32+
add_filter('comments_open', '__return_false', 20, 2);
33+
add_filter('pings_open', '__return_false', 20, 2);
34+
35+
// Hide existing comments
36+
add_filter('comments_array', '__return_empty_array', 10, 2);
37+
38+
// Remove comments page in menu
39+
add_action('admin_menu', function () {
40+
remove_menu_page('edit-comments.php');
41+
});
42+
43+
// Remove comments links from admin bar
44+
add_action('init', function () {
45+
if (is_admin_bar_showing()) {
46+
remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
47+
}
48+
});
49+
50+
add_action('admin_init', function () {
51+
// Redirect any user trying to access comments page
52+
global $pagenow;
53+
54+
if ($pagenow === 'edit-comments.php') {
55+
wp_redirect(admin_url());
56+
exit;
57+
}
58+
// Remove comments metabox from dashboard
59+
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
60+
// Disable support for comments and trackbacks in post types
61+
foreach (get_post_types() as $post_type) {
62+
if (post_type_supports($post_type, 'comments')) {
63+
remove_post_type_support($post_type, 'comments');
64+
remove_post_type_support($post_type, 'trackbacks');
65+
}
66+
}
67+
});
68+
}
69+
70+
/**
71+
* Loads the plugin main instance and initializes it.
72+
*
73+
* @since 0.1-stable
74+
*
75+
* @param string $main_file Absolute path to the plugin main file.
76+
* @return bool True if the plugin main instance could be loaded, false otherwise.
77+
*/
78+
public static function load() {
79+
if ( null !== static::$instance ) {
80+
return false;
81+
}
82+
static::$instance = new self();
83+
static::$instance->register();
84+
return true;
85+
}
86+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/**
4+
* Plugin loader.
5+
*
6+
* @package OnePlace\Swissknife
7+
* @copyright 2019 Verein onePlace
8+
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html GNU General Public License, version 2
9+
* @link https://1plc.ch/wordpress-plugins/swissknife
10+
*/
11+
12+
namespace OnePlace\Swissknife\Modules;
13+
14+
use OnePlace\Swissknife\Plugin;
15+
16+
final class Revisions {
17+
/**
18+
* Main instance of the module
19+
*
20+
* @since 0.1-stable
21+
* @var Plugin|null
22+
*/
23+
private static $instance = null;
24+
25+
/**
26+
* Enable Google Sitekit IP Anonymization
27+
*
28+
* @since 0.1-stable
29+
*/
30+
public function register() {
31+
// change autosave interval from 60 to 300 seconds
32+
define('AUTOSAVE_INTERVAL', 300);
33+
34+
// disable post revision
35+
define('WP_POST_REVISIONS', false);
36+
}
37+
38+
/**
39+
* Loads the plugin main instance and initializes it.
40+
*
41+
* @since 0.1-stable
42+
*
43+
* @param string $main_file Absolute path to the plugin main file.
44+
* @return bool True if the plugin main instance could be loaded, false otherwise.
45+
*/
46+
public static function load() {
47+
if ( null !== static::$instance ) {
48+
return false;
49+
}
50+
static::$instance = new self();
51+
static::$instance->register();
52+
return true;
53+
}
54+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
/**
4+
* Plugin loader.
5+
*
6+
* @package OnePlace\Swissknife
7+
* @copyright 2019 Verein onePlace
8+
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html GNU General Public License, version 2
9+
* @link https://1plc.ch/wordpress-plugins/swissknife
10+
*/
11+
12+
namespace OnePlace\Swissknife\Modules;
13+
14+
use OnePlace\Swissknife\Plugin;
15+
16+
final class Tweaks {
17+
/**
18+
* Main instance of the module
19+
*
20+
* @since 0.1-stable
21+
* @var Plugin|null
22+
*/
23+
private static $instance = null;
24+
25+
/**
26+
* Disable wordpress comments entirely
27+
*
28+
* @since 0.1-stable
29+
*/
30+
public function register() {
31+
// Disable wordpress emojis
32+
add_action( 'init', [ $this, 'disableEmojis' ] );
33+
34+
// Disable XML-RPC
35+
add_filter('xmlrpc_enabled', '__return_false');
36+
}
37+
38+
public function disableEmojis() {
39+
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
40+
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
41+
remove_action( 'wp_print_styles', 'print_emoji_styles' );
42+
remove_action( 'admin_print_styles', 'print_emoji_styles' );
43+
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
44+
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
45+
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
46+
add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );
47+
}
48+
49+
/**
50+
* Loads the plugin main instance and initializes it.
51+
*
52+
* @since 0.1-stable
53+
*
54+
* @param string $main_file Absolute path to the plugin main file.
55+
* @return bool True if the plugin main instance could be loaded, false otherwise.
56+
*/
57+
public static function load() {
58+
if ( null !== static::$instance ) {
59+
return false;
60+
}
61+
static::$instance = new self();
62+
static::$instance->register();
63+
return true;
64+
}
65+
}

wpplc-swissknife/includes/Modules/Updater.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,17 @@ public function register() {
5454
add_filter( "plugins_api", [ $this, "setPluginInfo" ], 10, 3 );
5555
}
5656

57-
// Push in plugin version information to display in the details lightbox
57+
/**
58+
* Push in plugin version information to display in the details lightbox
59+
*
60+
* @param $false
61+
* @param $action
62+
* @param $response
63+
*
64+
* @since 0.2-stable
65+
*
66+
* @return bool
67+
*/
5868
public function setPluginInfo( $false, $action, $response ) {
5969
// Get plugin & GitHub release information
6070
//$this->initPluginData();
@@ -96,6 +106,17 @@ public function setPluginInfo( $false, $action, $response ) {
96106
return $response;
97107
}
98108

109+
/**
110+
* Set Update Information for Wordpress
111+
*
112+
* Shows Update Message if new version is available
113+
*
114+
* @param $transient
115+
*
116+
* @since 0.2-stable
117+
*
118+
* @return mixed
119+
*/
99120
public function setTransient($transient) {
100121
// If we have checked the plugin data before, don't re-check
101122
if ( empty( $transient->checked ) ) {
@@ -131,6 +152,11 @@ public function setTransient($transient) {
131152
return $transient;
132153
}
133154

155+
/**
156+
* Get Release information from github
157+
*
158+
* @since 0.2-stable
159+
*/
134160
public function getRepoReleaseInfo() {
135161
if ( ! empty( $this->githubAPIResult ) ) {
136162
return;

wpplc-swissknife/includes/Plugin.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,18 @@ public static function instance() {
4040
* @since 0.1-stable
4141
*/
4242
public function register() {
43+
// Enable Custom Comments Settings
44+
Modules\Comments::load();
45+
46+
// Enable Custom Revision Settings
47+
Modules\Revisions::load();
48+
4349
// Enable Sitekit Custom Settings
4450
Modules\Sitekit::load();
4551

52+
// Enable custom wordpress tweaks
53+
Modules\Tweaks::load();
54+
4655
// Enable Auto-Updates via Github
4756
Modules\Updater::load();
4857
}

wpplc-swissknife/includes/loader.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
require_once __DIR__.'/Plugin.php';
2424

2525
// Load Modules
26+
require_once __DIR__.'/Modules/Comments.php';
27+
require_once __DIR__.'/Modules/Revisions.php';
2628
require_once __DIR__.'/Modules/Sitekit.php';
29+
require_once __DIR__.'/Modules/Tweaks.php';
2730
require_once __DIR__.'/Modules/Updater.php';
2831

2932
ini_set('display_errors', 1);

wpplc-swissknife/wpplc-swissknife.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Plugin Name: WP PLC Swissknife
1212
* Plugin URI: https://1plc.ch/wordpress-plugins/swissknife
1313
* Description: onePlace Swissknife for Wordpress. Increase Wordpress Security and Performance
14-
* Version: 0.2-stable
14+
* Version: 0.3-stable
1515
* Author: Verein onePlace
1616
* Author URI: https://1plc.ch
1717
* License: GNU General Public License, version 2
@@ -23,7 +23,7 @@
2323
}
2424

2525
// Define Version and directories for further use in plugin
26-
define( 'WPPLC_SWISSKNIFE_VERSION', '0.2-stable' );
26+
define( 'WPPLC_SWISSKNIFE_VERSION', '0.3-stable' );
2727
define( 'WPPLC_SWISSKNIFE_MAIN_FILE', __FILE__ );
2828
define( 'WPPLC_SWISSKNIFE_MAIN_DIR', __DIR__ );
2929
define( 'WPPLC_SWISSKNIFE_PUB_DIR',str_replace([$_SERVER['DOCUMENT_ROOT']],[''],WPPLC_SWISSKNIFE_MAIN_DIR));

0 commit comments

Comments
 (0)