Skip to content

Commit

Permalink
Comments disabled, xml rpc, emojis
Browse files Browse the repository at this point in the history
  • Loading branch information
Praesidiarius committed Dec 4, 2019
1 parent b7612de commit deef011
Show file tree
Hide file tree
Showing 7 changed files with 246 additions and 3 deletions.
86 changes: 86 additions & 0 deletions wpplc-swissknife/includes/Modules/Comments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

/**
* Plugin loader.
*
* @package OnePlace\Swissknife
* @copyright 2019 Verein onePlace
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html GNU General Public License, version 2
* @link https://1plc.ch/wordpress-plugins/swissknife
*/

namespace OnePlace\Swissknife\Modules;

use OnePlace\Swissknife\Plugin;

final class Comments {
/**
* Main instance of the module
*
* @since 0.1-stable
* @var Plugin|null
*/
private static $instance = null;

/**
* Disable wordpress comments entirely
*
* @since 0.1-stable
*/
public function register() {
// Close comments on the front-end
add_filter('comments_open', '__return_false', 20, 2);
add_filter('pings_open', '__return_false', 20, 2);

// Hide existing comments
add_filter('comments_array', '__return_empty_array', 10, 2);

// Remove comments page in menu
add_action('admin_menu', function () {
remove_menu_page('edit-comments.php');
});

// Remove comments links from admin bar
add_action('init', function () {
if (is_admin_bar_showing()) {
remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
}
});

add_action('admin_init', function () {
// Redirect any user trying to access comments page
global $pagenow;

if ($pagenow === 'edit-comments.php') {
wp_redirect(admin_url());
exit;
}
// Remove comments metabox from dashboard
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
// Disable support for comments and trackbacks in post types
foreach (get_post_types() as $post_type) {
if (post_type_supports($post_type, 'comments')) {
remove_post_type_support($post_type, 'comments');
remove_post_type_support($post_type, 'trackbacks');
}
}
});
}

/**
* Loads the plugin main instance and initializes it.
*
* @since 0.1-stable
*
* @param string $main_file Absolute path to the plugin main file.
* @return bool True if the plugin main instance could be loaded, false otherwise.
*/
public static function load() {
if ( null !== static::$instance ) {
return false;
}
static::$instance = new self();
static::$instance->register();
return true;
}
}
54 changes: 54 additions & 0 deletions wpplc-swissknife/includes/Modules/Revisions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/**
* Plugin loader.
*
* @package OnePlace\Swissknife
* @copyright 2019 Verein onePlace
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html GNU General Public License, version 2
* @link https://1plc.ch/wordpress-plugins/swissknife
*/

namespace OnePlace\Swissknife\Modules;

use OnePlace\Swissknife\Plugin;

final class Revisions {
/**
* Main instance of the module
*
* @since 0.1-stable
* @var Plugin|null
*/
private static $instance = null;

/**
* Enable Google Sitekit IP Anonymization
*
* @since 0.1-stable
*/
public function register() {
// change autosave interval from 60 to 300 seconds
define('AUTOSAVE_INTERVAL', 300);

// disable post revision
define('WP_POST_REVISIONS', false);
}

/**
* Loads the plugin main instance and initializes it.
*
* @since 0.1-stable
*
* @param string $main_file Absolute path to the plugin main file.
* @return bool True if the plugin main instance could be loaded, false otherwise.
*/
public static function load() {
if ( null !== static::$instance ) {
return false;
}
static::$instance = new self();
static::$instance->register();
return true;
}
}
65 changes: 65 additions & 0 deletions wpplc-swissknife/includes/Modules/Tweaks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

/**
* Plugin loader.
*
* @package OnePlace\Swissknife
* @copyright 2019 Verein onePlace
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html GNU General Public License, version 2
* @link https://1plc.ch/wordpress-plugins/swissknife
*/

namespace OnePlace\Swissknife\Modules;

use OnePlace\Swissknife\Plugin;

final class Tweaks {
/**
* Main instance of the module
*
* @since 0.1-stable
* @var Plugin|null
*/
private static $instance = null;

/**
* Disable wordpress comments entirely
*
* @since 0.1-stable
*/
public function register() {
// Disable wordpress emojis
add_action( 'init', [ $this, 'disableEmojis' ] );

// Disable XML-RPC
add_filter('xmlrpc_enabled', '__return_false');
}

public function disableEmojis() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );
}

/**
* Loads the plugin main instance and initializes it.
*
* @since 0.1-stable
*
* @param string $main_file Absolute path to the plugin main file.
* @return bool True if the plugin main instance could be loaded, false otherwise.
*/
public static function load() {
if ( null !== static::$instance ) {
return false;
}
static::$instance = new self();
static::$instance->register();
return true;
}
}
28 changes: 27 additions & 1 deletion wpplc-swissknife/includes/Modules/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,17 @@ public function register() {
add_filter( "plugins_api", [ $this, "setPluginInfo" ], 10, 3 );
}

// Push in plugin version information to display in the details lightbox
/**
* Push in plugin version information to display in the details lightbox
*
* @param $false
* @param $action
* @param $response
*
* @since 0.2-stable
*
* @return bool
*/
public function setPluginInfo( $false, $action, $response ) {
// Get plugin & GitHub release information
//$this->initPluginData();
Expand Down Expand Up @@ -96,6 +106,17 @@ public function setPluginInfo( $false, $action, $response ) {
return $response;
}

/**
* Set Update Information for Wordpress
*
* Shows Update Message if new version is available
*
* @param $transient
*
* @since 0.2-stable
*
* @return mixed
*/
public function setTransient($transient) {
// If we have checked the plugin data before, don't re-check
if ( empty( $transient->checked ) ) {
Expand Down Expand Up @@ -131,6 +152,11 @@ public function setTransient($transient) {
return $transient;
}

/**
* Get Release information from github
*
* @since 0.2-stable
*/
public function getRepoReleaseInfo() {
if ( ! empty( $this->githubAPIResult ) ) {
return;
Expand Down
9 changes: 9 additions & 0 deletions wpplc-swissknife/includes/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,18 @@ public static function instance() {
* @since 0.1-stable
*/
public function register() {
// Enable Custom Comments Settings
Modules\Comments::load();

// Enable Custom Revision Settings
Modules\Revisions::load();

// Enable Sitekit Custom Settings
Modules\Sitekit::load();

// Enable custom wordpress tweaks
Modules\Tweaks::load();

// Enable Auto-Updates via Github
Modules\Updater::load();
}
Expand Down
3 changes: 3 additions & 0 deletions wpplc-swissknife/includes/loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
require_once __DIR__.'/Plugin.php';

// Load Modules
require_once __DIR__.'/Modules/Comments.php';
require_once __DIR__.'/Modules/Revisions.php';
require_once __DIR__.'/Modules/Sitekit.php';
require_once __DIR__.'/Modules/Tweaks.php';
require_once __DIR__.'/Modules/Updater.php';

ini_set('display_errors', 1);
Expand Down
4 changes: 2 additions & 2 deletions wpplc-swissknife/wpplc-swissknife.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Plugin Name: WP PLC Swissknife
* Plugin URI: https://1plc.ch/wordpress-plugins/swissknife
* Description: onePlace Swissknife for Wordpress. Increase Wordpress Security and Performance
* Version: 0.2-stable
* Version: 0.3-stable
* Author: Verein onePlace
* Author URI: https://1plc.ch
* License: GNU General Public License, version 2
Expand All @@ -23,7 +23,7 @@
}

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

0 comments on commit deef011

Please sign in to comment.