From 61064345efc01202b8a64eaf82a282f2a925bb91 Mon Sep 17 00:00:00 2001 From: Daniel Hewes Date: Thu, 3 Nov 2016 17:58:41 -0700 Subject: [PATCH 1/4] Refactor plugin. --- .gitattributes | 5 - .travis.yml | 27 ------ README.md | 27 +++--- bin/install-wp-tests.sh | 98 ------------------- composer.json | 22 ----- modules/clean-up.php | 123 +++++++++++++----------- modules/disable-attachment-pages.php | 20 ++-- modules/disable-author-pages.php | 15 ++- modules/disable-comments.php | 45 +++++---- modules/disable-emojicons.php | 44 ++++----- modules/disable-feed.php | 28 +++--- modules/disable-json-api.php | 39 ++++++++ modules/disable-posts.php | 74 ++++++++++++-- modules/disable-search.php | 19 ++-- modules/disable-trackbacks.php | 29 +++--- modules/no-redirect-on-404.php | 14 ++- modules/remove-dashboard-widgets.php | 39 +++++--- phpunit.xml | 14 --- tests/bootstrap.php | 20 ---- tests/test-clean-up.php | 96 ------------------ tests/test-disable-attachment-pages.php | 13 --- tests/test-disable-author-pages.php | 13 --- tests/test-disable-comments.php | 21 ---- tests/test-disable-emojicons.php | 24 ----- tests/test-disable-feed.php | 19 ---- tests/test-disable-search.php | 17 ---- tests/test-disable-trackbacks.php | 17 ---- tests/test-no-redirect-on-404.php | 13 --- tests/test-remove-dashboard-widgets.php | 13 --- tests/tests-disable-posts.php | 13 --- wp-clean.php | 16 ++- wp-multifilter.php | 46 +++++++++ 32 files changed, 375 insertions(+), 648 deletions(-) delete mode 100644 .gitattributes delete mode 100644 .travis.yml delete mode 100755 bin/install-wp-tests.sh delete mode 100644 composer.json create mode 100644 modules/disable-json-api.php delete mode 100644 phpunit.xml delete mode 100644 tests/bootstrap.php delete mode 100644 tests/test-clean-up.php delete mode 100644 tests/test-disable-attachment-pages.php delete mode 100644 tests/test-disable-author-pages.php delete mode 100644 tests/test-disable-comments.php delete mode 100644 tests/test-disable-emojicons.php delete mode 100644 tests/test-disable-feed.php delete mode 100644 tests/test-disable-search.php delete mode 100644 tests/test-disable-trackbacks.php delete mode 100644 tests/test-no-redirect-on-404.php delete mode 100644 tests/test-remove-dashboard-widgets.php delete mode 100644 tests/tests-disable-posts.php create mode 100644 wp-multifilter.php diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 6b89f49..0000000 --- a/.gitattributes +++ /dev/null @@ -1,5 +0,0 @@ -/tests export-ignore -/bin export-ignore -/.gitattributes export-ignore -/.travis.yml export-ignore -/phpunit.xml export-ignore diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7f052b1..0000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -language: php - -notifications: - email: - on_success: never - on_failure: change - -php: - - 5.3 - - 5.4 - - 5.5 - - 5.6 - - hhvm - - 7.0 - -env: - - WP_VERSION=latest WP_MULTISITE=0 - -matrix: - include: - - php: 5.3 - env: WP_VERSION=latest WP_MULTISITE=1 - -before_script: - - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION - -script: phpunit diff --git a/README.md b/README.md index d9ee6fa..f4b6079 100644 --- a/README.md +++ b/README.md @@ -1,40 +1,41 @@ -[![Build Status](https://travis-ci.org/danimalweb/wp-clean.svg)](https://travis-ci.org/danimalweb/wp-clean) - # wp-clean WordPress plugin to clean up unused functionality and extra bloat. # Modules # * **Cleaner Markup**
-`add_theme_support('WP_Clean-clean-up');` +`add_theme_support('wp-clean-clean-up');` * **Disable Attachement Pages**
-`add_theme_support('WP_Clean-disable-attachment-pages');` +`add_theme_support('wp-clean-disable-attachment-pages');` * **Disable Author Pages**
-`add_theme_support('WP_Clean-disable-author-pages');` +`add_theme_support('wp-clean-disable-author-pages');` * **Disable Comments**
-`add_theme_support('WP_Clean-disable-comments');` +`add_theme_support('wp-clean-disable-comments');` * **Disable Emojicons**
-`add_theme_support('WP_Clean-disable-emojicons');` +`add_theme_support('wp-clean-disable-emojicons');` * **Disable RSS Feeds**
-`add_theme_support('WP_Clean-disable-feed');` +`add_theme_support('wp-clean-disable-feed');` + +* **Remove JSON API**
+`add_theme_support('wp-clean-disable-json-api');` * **Disable Posts**
The built in posts that come with the default install.
-`add_theme_support('WP_Clean-disable-posts');` +`add_theme_support('wp-clean-disable-posts');` * **Disable Search**
-`add_theme_support('WP_Clean-disable-search');` +`add_theme_support('wp-clean-disable-search');` * **Disable Trackbacks**
-`add_theme_support('WP_Clean-disable-trackbacks');` +`add_theme_support('wp-clean-disable-trackbacks');` * **No redirect to fuzzy match on 404 error**
-`add_theme_support('WP_Clean-no-redirect-on-404');` +`add_theme_support('wp-clean-no-redirect-on-404');` * **Remove Dashboard Widgets**
-`add_theme_support('WP_Clean-remove-dashboard-widgets');` +`add_theme_support('wp-clean-remove-dashboard-widgets');` diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh deleted file mode 100755 index c96a09f..0000000 --- a/bin/install-wp-tests.sh +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env bash - -if [ $# -lt 3 ]; then - echo "usage: $0 [db-host] [wp-version]" - exit 1 -fi - -DB_NAME=$1 -DB_USER=$2 -DB_PASS=$3 -DB_HOST=${4-localhost} -WP_VERSION=${5-latest} - -WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib} -WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/} - -set -ex - -download() { - if [ `which curl` ]; then - curl -s "$1" > "$2"; - elif [ `which wget` ]; then - wget -nv -O "$2" "$1" - fi -} - -install_wp() { - - if [ -d $WP_CORE_DIR ]; then - return; - fi - - mkdir -p $WP_CORE_DIR - - if [ $WP_VERSION == 'latest' ]; then - local ARCHIVE_NAME='latest' - else - local ARCHIVE_NAME="wordpress-$WP_VERSION" - fi - - download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz - tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR - - download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php -} - -install_test_suite() { - # portable in-place argument for both GNU sed and Mac OSX sed - if [[ $(uname -s) == 'Darwin' ]]; then - local ioption='-i .bak' - else - local ioption='-i' - fi - - # set up testing suite if it doesn't yet exist - if [ ! -d $WP_TESTS_DIR ]; then - # set up testing suite - mkdir -p $WP_TESTS_DIR - svn co --quiet http://develop.svn.wordpress.org/trunk/tests/phpunit/includes/ $WP_TESTS_DIR/includes - fi - - cd $WP_TESTS_DIR - - if [ ! -f wp-tests-config.php ]; then - download https://develop.svn.wordpress.org/trunk/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php - fi - -} - -install_db() { - # parse DB_HOST for port or socket references - local PARTS=(${DB_HOST//\:/ }) - local DB_HOSTNAME=${PARTS[0]}; - local DB_SOCK_OR_PORT=${PARTS[1]}; - local EXTRA="" - - if ! [ -z $DB_HOSTNAME ] ; then - if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then - EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp" - elif ! [ -z $DB_SOCK_OR_PORT ] ; then - EXTRA=" --socket=$DB_SOCK_OR_PORT" - elif ! [ -z $DB_HOSTNAME ] ; then - EXTRA=" --host=$DB_HOSTNAME --protocol=tcp" - fi - fi - - # create database - mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA -} - -install_wp -install_test_suite -install_db diff --git a/composer.json b/composer.json deleted file mode 100644 index ee83f6c..0000000 --- a/composer.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "danimalweb/wp-clean", - "type": "library", - "description": "WordPress plugin to clean up unused functionality and extra bloat.", - "keywords": ["wp","wordpress", "clean"], - "homepage": "https://github.com/danimalweb/wp-clean", - "license": "MIT", - "authors": [ - { - "name": "Daniel Hewes", - "email": "daniel@lambdacreatives.com", - "homepage": "http://lambdacreatives.com", - "role": "Developer" - } - ], - "require": { - "php": ">=5.3" - }, - "autoload": { - "files": ["wp-clean.php"] - } -} diff --git a/modules/clean-up.php b/modules/clean-up.php index 9333e21..3118458 100644 --- a/modules/clean-up.php +++ b/modules/clean-up.php @@ -1,84 +1,95 @@ ', '>', $input); -} +}); -add_filter( 'style_loader_tag', __NAMESPACE__ . '\\remove_self_closing_tags' ); -// Remove style and script versions from source code URL's -function filter_remove_version_script_style( $target_url ) { - if ( strpos( $target_url, 'ver=' ) ) { // check if "ver=" argument exists in the url or not - $target_url = remove_query_arg( 'ver', $target_url ); +/** + * Remove style and script versions from urls + */ +add_filters(['style_loader_src', 'script_loader_src'], function($target_url) { + if (strpos($target_url, 'ver=')) { // check if "ver=" argument exists in the url + $target_url = remove_query_arg('ver', $target_url); } return $target_url; -} +}, 20000); -add_filter( 'style_loader_src', __NAMESPACE__ . '\\filter_remove_version_script_style', 20000 ); -add_filter( 'script_loader_src', __NAMESPACE__ . '\\filter_remove_version_script_style', 20000 ); -// Remove thumbnail width and height dimensions that prevent fluid images in the_thumbnail -function filter_remove_thumbnail_dimensions( $html ) { +/* + * Remove thumbnail width and height dimensions + */ +add_filters(['post_thumbnail_html', 'image_send_to_editor'], function($html) { $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html ); return $html; -} +}, 10); -add_filter( 'post_thumbnail_html', __NAMESPACE__ . '\\filter_remove_thumbnail_dimensions', 10 ); -add_filter( 'image_send_to_editor', __NAMESPACE__ . '\\filter_remove_thumbnail_dimensions', 10 ); -//Remove WP logo from admin bar -function admin_bar_render() { +/** + * Remove WP logo from admin bar + */ +add_action('wp_before_admin_bar_render', function() { global $wp_admin_bar; $wp_admin_bar->remove_node('wp-logo'); -} +}); -add_action( 'wp_before_admin_bar_render', __NAMESPACE__ . '\\admin_bar_render' ); -// Add and remove body_class() classes -function body_class($classes) { +/** + * Add and remove body_class() classes + */ +add_filter('body_class', function($classes) { // Add post/page slug if not present if (is_single() || is_page() && !is_front_page()) { if (!in_array(basename(get_permalink()), $classes)) { $classes[] = basename(get_permalink()); } } + // Remove unnecessary classes - $home_id_class = 'page-id-' . get_option('page_on_front'); + $home_id_class = 'page-id-' . get_option('page_on_front'); $remove_classes = array('page-template-default', $home_id_class); - $classes = array_diff($classes, $remove_classes); + $classes = array_diff($classes, $remove_classes); return $classes; -} - -add_filter( 'body_class', __NAMESPACE__ . '\\body_class' ); +}); diff --git a/modules/disable-attachment-pages.php b/modules/disable-attachment-pages.php index 11b588c..309faed 100644 --- a/modules/disable-attachment-pages.php +++ b/modules/disable-attachment-pages.php @@ -1,18 +1,16 @@ post_parent; - if ( $post_parent ) { - wp_redirect( get_permalink( $post->post_parent ), 301 ); - exit; + if ($post_parent) { + wp_redirect(get_permalink($post->post_parent), 301); + exit; } $wp_query->set_404(); return; } -} - -add_action( 'template_redirect', __NAMESPACE__ . '\\action_attachement_template_redirect' ); +}); diff --git a/modules/disable-author-pages.php b/modules/disable-author-pages.php index 666592e..6a70fbf 100644 --- a/modules/disable-author-pages.php +++ b/modules/disable-author-pages.php @@ -1,11 +1,10 @@ set_404(); } -} - -add_action( 'template_redirect', __NAMESPACE__ . '\\action_author_template_redirect' ); +}); diff --git a/modules/disable-comments.php b/modules/disable-comments.php index 4a215b5..9e196b6 100644 --- a/modules/disable-comments.php +++ b/modules/disable-comments.php @@ -1,26 +1,35 @@ remove_menu('comments'); -} - -add_action( 'wp_before_admin_bar_render', __NAMESPACE__ . '\\admin_bar_render' ); +}); diff --git a/modules/disable-emojicons.php b/modules/disable-emojicons.php index c248277..e6839f1 100644 --- a/modules/disable-emojicons.php +++ b/modules/disable-emojicons.php @@ -1,26 +1,22 @@ set_404(); status_header(404); - wp_die( __( 'No feed available, please visit the homepage!' ) ); -} - -add_action( 'do_feed', __NAMESPACE__ . '\\disable_feed', 1 ); -add_action( 'do_feed_rdf', __NAMESPACE__ . '\\disable_feed', 1 ); -add_action( 'do_feed_rss', __NAMESPACE__ . '\\disable_feed', 1 ); -add_action( 'do_feed_rss2', __NAMESPACE__ . '\\disable_feed', 1 ); -add_action( 'do_feed_atom', __NAMESPACE__ . '\\disable_feed', 1 ); -add_action( 'do_feed_rss2_comments', __NAMESPACE__ . '\\disable_feed', 1 ); -add_action( 'do_feed_atom_comments', __NAMESPACE__ . '\\disable_feed', 1 ); + wp_die(__('No feed available. Please visit the homepage')); +}, 1); diff --git a/modules/disable-json-api.php b/modules/disable-json-api.php new file mode 100644 index 0000000..49b1bd9 --- /dev/null +++ b/modules/disable-json-api.php @@ -0,0 +1,39 @@ +remove_node('new-post'); +}, 999); + + +/** + * Check requests for post_tpe and redirect to dashboard + */ +add_action('init', function() { + global $pagenow, $wp; + switch($pagenow) { + case 'edit.php': + case 'edit-tags.php': + case 'post-new.php': + if (!array_key_exists('post_type', $_GET) && !array_key_exists('taxonomy', $_GET) && !$_POST) { + wp_safe_redirect(get_admin_url(), 301); + exit; + } + break; + } +}); + + +/** + * Remove Posts from search + */ +add_filter('pre_get_posts', function($query) { + if (!is_search() || !$query->is_main_query()) { + return $query; + } + + $post_types = get_post_types(['exclude_from_search' => false]); + + if (array_key_exists('post', $post_types)) { + // exclude post_type `post` from the query results */ + unset($post_types['post']); + } + + $query->set('post_type', array_values($post_types)); + + return $query; +}); + + +/* + * Checks the SQL statement to see if we are trying to fetch post_type `post` + */ +add_action('posts_results', function($posts = []) { + global $wp_query; + $look_for = "wp_posts.post_type = 'post'"; + $instance = strpos($wp_query->request, $look_for); + + if ($instance !== false) { + $posts = []; // we are querying for post type `post` + } + + return $posts; +}); diff --git a/modules/disable-search.php b/modules/disable-search.php index 052a48e..f3b2baf 100644 --- a/modules/disable-search.php +++ b/modules/disable-search.php @@ -1,17 +1,16 @@ is_search = false; $query->query_vars[s] = false; $query->query[s] = false; - if ( $error == true ) + if ($error == true) { $query->is_404 = true; + } } -} - -add_action( 'parse_query', __NAMESPACE__ . '\\disable_search' ); +}); -add_filter( 'get_search_form', '__return_false' ); +add_filter('get_search_form', '__return_false'); diff --git a/modules/disable-trackbacks.php b/modules/disable-trackbacks.php index a49e901..3dee53f 100644 --- a/modules/disable-trackbacks.php +++ b/modules/disable-trackbacks.php @@ -1,20 +1,23 @@ - - - ./tests/ - - - diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index e1caad9..0000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,20 +0,0 @@ -assertTrue( current_theme_supports( 'WP_Clean-clean-up' ) ); - } - - function test_admin_bar() { - $this->assertTrue( has_filter( 'show_admin_bar' ) ); - } - - function test_admin_footer_text() { - $this->assertTrue( has_filter( 'admin_footer_text' ) ); - } - - function test_action_remove_wp_head_extras() { - $this->assertNotFalse( has_action( 'init', 'WP_Clean\CleanUp\\action_remove_wp_head_extras' ) ); - } - - function test_feed_links_extra() { - $this->assertFalse( has_action( 'wp_head', 'feed_links_extra' ) ); - } - - function test_feed_links() { - $this->assertFalse( has_action( 'wp_head', 'feed_links' ) ); - } - - function test_rsd_link() { - $this->assertFalse( has_action( 'wp_head', 'rsd_link' ) ); - } - - function test_wlwmanifest_link() { - $this->assertFalse( has_action( 'wp_head', 'wlwmanifest_link' ) ); - } - - function test_index_rel_link() { - $this->assertFalse( has_action( 'wp_head', 'index_rel_link' ) ); - } - - function test_parent_post_rel_link() { - $this->assertFalse( has_action( 'wp_head', 'parent_post_rel_link' ) ); - } - - function test_start_post_rel_link() { - $this->assertFalse( has_action( 'wp_head', 'start_post_rel_link' ) ); - } - - function test_adjacent_posts_rel_link() { - $this->assertFalse( has_action( 'wp_head', 'adjacent_posts_rel_link' ) ); - } - - function test_wp_generator() { - $this->assertFalse( has_action( 'wp_head', 'wp_generator' ) ); - } - - function test_adjacent_posts_rel_link_wp_head() { - $this->assertFalse( has_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' ) ); - } - - function test_rel_canonical() { - $this->assertFalse( has_action( 'wp_head', 'rel_canonical' ) ); - } - - function test_wp_shortlink_wp_head() { - $this->assertFalse( has_action( 'wp_head', 'wp_shortlink_wp_head' ) ); - } - - function test_filter_type_remove() { - $this->assertNotFalse( has_filter( 'style_loader_tag', 'WP_Clean\CleanUp\\filter_type_remove' ) ); - $this->assertNotFalse( has_filter( 'script_loader_tag', 'WP_Clean\CleanUp\\filter_type_remove' ) ); - } - - function test_remove_self_closing_tags() { - $this->assertNotFalse( has_filter( 'style_loader_tag', 'WP_Clean\CleanUp\\remove_self_closing_tags' ) ); - } - - function test_filter_remove_version_script_style() { - $this->assertNotFalse( has_filter( 'style_loader_src', 'WP_Clean\CleanUp\\filter_remove_version_script_style' ) ); - $this->assertNotFalse( has_filter( 'script_loader_src', 'WP_Clean\CleanUp\\filter_remove_version_script_style' ) ); - } - - function test_filter_remove_thumbnail_dimensions() { - $this->assertNotFalse( has_filter( 'post_thumbnail_html', 'WP_Clean\CleanUp\\filter_remove_thumbnail_dimensions' ) ); - $this->assertNotFalse( has_filter( 'image_send_to_editor', 'WP_Clean\CleanUp\\filter_remove_thumbnail_dimensions' ) ); - } - - function test_admin_bar_render() { - $this->assertNotFalse( has_filter( 'wp_before_admin_bar_render', 'WP_Clean\CleanUp\\admin_bar_render' ) ); - } - - function test_body_class() { - $this->assertNotFalse( has_filter( 'body_class', 'WP_Clean\CleanUp\\body_class' ) ); - } - -} diff --git a/tests/test-disable-attachment-pages.php b/tests/test-disable-attachment-pages.php deleted file mode 100644 index fa6af1e..0000000 --- a/tests/test-disable-attachment-pages.php +++ /dev/null @@ -1,13 +0,0 @@ -assertTrue( current_theme_supports( 'WP_Clean-disable-attachment-pages' ) ); - } - - function test_action_attachement_template_redirect() { - $this->assertNotFalse( has_action( 'template_redirect', 'WP_Clean\\DisableAttachmentPages\action_attachement_template_redirect' ) ); - } - -} diff --git a/tests/test-disable-author-pages.php b/tests/test-disable-author-pages.php deleted file mode 100644 index 9a0bf91..0000000 --- a/tests/test-disable-author-pages.php +++ /dev/null @@ -1,13 +0,0 @@ -assertTrue( current_theme_supports( 'WP_Clean-disable-author-pages' ) ); - } - - function test_action_author_template_redirect() { - $this->assertNotFalse( has_action( 'template_redirect', 'WP_Clean\\DisableAuthorPages\action_author_template_redirect' ) ); - } - -} diff --git a/tests/test-disable-comments.php b/tests/test-disable-comments.php deleted file mode 100644 index be9c333..0000000 --- a/tests/test-disable-comments.php +++ /dev/null @@ -1,21 +0,0 @@ -assertTrue( current_theme_supports( 'WP_Clean-disable-comments' ) ); - } - - function test_action_remove_admin_menus() { - $this->assertNotFalse( has_action( 'admin_menu', 'WP_Clean\\DisableComments\action_remove_admin_menus' ) ); - } - - function test_custom_pages_columns() { - $this->assertNotFalse( has_filter( 'manage_pages_columns', 'WP_Clean\\DisableComments\custom_pages_columns' ) ); - } - - function test_admin_bar_render() { - $this->assertNotFalse( has_action( 'wp_before_admin_bar_render', 'WP_Clean\\DisableComments\admin_bar_render' ) ); - } - -} diff --git a/tests/test-disable-emojicons.php b/tests/test-disable-emojicons.php deleted file mode 100644 index c03d905..0000000 --- a/tests/test-disable-emojicons.php +++ /dev/null @@ -1,24 +0,0 @@ -assertTrue( current_theme_supports( 'WP_Clean-disable-emojicons' ) ); - } - - function test_action_disable_wp_emojicons() { - $this->assertNotFalse( has_action( 'init', 'WP_Clean\\DisableEmojIcons\action_disable_wp_emojicons' ) ); - $this->assertFalse( has_action( 'wp_head', 'print_emoji_detection_script' ) ); - $this->assertFalse( has_action( 'admin_print_scripts', 'print_emoji_detection_script' ) ); - $this->assertFalse( has_action( 'admin_print_styles', 'print_emoji_styles' ) ); - $this->assertFalse( has_action( 'wp_print_styles', 'print_emoji_styles' ) ); - $this->assertFalse( has_action( 'wp_mail', 'wp_staticize_emoji_for_email' ) ); - $this->assertFalse( has_action( 'the_content_feed', 'wp_staticize_emoji' ) ); - $this->assertFalse( has_action( 'comment_text_rss', 'wp_staticize_emoji' ) ); - } - - function test_filter_disable_emojicons_tinymce() { - $this->assertNotFalse( has_filter( 'tiny_mce_plugins', 'WP_Clean\\DisableEmojIcons\filter_disable_emojicons_tinymce' ) ); - } - -} diff --git a/tests/test-disable-feed.php b/tests/test-disable-feed.php deleted file mode 100644 index 1b51265..0000000 --- a/tests/test-disable-feed.php +++ /dev/null @@ -1,19 +0,0 @@ -assertTrue( current_theme_supports( 'WP_Clean-disable-feed' ) ); - } - - function test_disable_feed() { - $this->assertNotFalse( has_action( 'do_feed', 'WP_Clean\DisableFeed\\disable_feed' ) ); - $this->assertNotFalse( has_action( 'do_feed_rdf', 'WP_Clean\DisableFeed\\disable_feed' ) ); - $this->assertNotFalse( has_action( 'do_feed_rss', 'WP_Clean\DisableFeed\\disable_feed' ) ); - $this->assertNotFalse( has_action( 'do_feed_rss2', 'WP_Clean\DisableFeed\\disable_feed' ) ); - $this->assertNotFalse( has_action( 'do_feed_atom', 'WP_Clean\DisableFeed\\disable_feed' ) ); - $this->assertNotFalse( has_action( 'do_feed_rss2_comments', 'WP_Clean\DisableFeed\\disable_feed' ) ); - $this->assertNotFalse( has_action( 'do_feed_atom_comments', 'WP_Clean\DisableFeed\\disable_feed' ) ); - } - -} diff --git a/tests/test-disable-search.php b/tests/test-disable-search.php deleted file mode 100644 index 7733f12..0000000 --- a/tests/test-disable-search.php +++ /dev/null @@ -1,17 +0,0 @@ -assertTrue( current_theme_supports( 'WP_Clean-disable-search' ) ); - } - - function test_disable_search() { - $this->assertNotFalse( has_action( 'parse_query', 'WP_Clean\\DisableSearch\disable_search' ) ); - } - - function test_get_search_form() { - $this->assertNotFalse( has_filter( 'get_search_form' ) ); - } - -} diff --git a/tests/test-disable-trackbacks.php b/tests/test-disable-trackbacks.php deleted file mode 100644 index 4cfd170..0000000 --- a/tests/test-disable-trackbacks.php +++ /dev/null @@ -1,17 +0,0 @@ -assertTrue( current_theme_supports( 'WP_Clean-disable-trackbacks' ) ); - } - - function test_filter_remove_header_pingback() { - $this->assertNotFalse( has_filter( 'wp_headers', 'WP_Clean\\DisableTrackbacks\filter_remove_header_pingback' ) ); - } - - function test_filter_disable_pingback() { - $this->assertNotFalse( has_filter( 'xmlrpc_methods', 'WP_Clean\\DisableTrackbacks\filter_disable_pingback' ) ); - } - -} diff --git a/tests/test-no-redirect-on-404.php b/tests/test-no-redirect-on-404.php deleted file mode 100644 index 86d50b0..0000000 --- a/tests/test-no-redirect-on-404.php +++ /dev/null @@ -1,13 +0,0 @@ -assertTrue( current_theme_supports( 'WP_Clean-no-redirect-on-404' ) ); - } - - function test_filter_no_redirect_on_404() { - $this->assertNotFalse( has_filter( 'redirect_canonical', 'WP_Clean\\NoRedirect\filter_no_redirect_on_404' ) ); - } - -} diff --git a/tests/test-remove-dashboard-widgets.php b/tests/test-remove-dashboard-widgets.php deleted file mode 100644 index 2e0f3a9..0000000 --- a/tests/test-remove-dashboard-widgets.php +++ /dev/null @@ -1,13 +0,0 @@ -assertTrue( current_theme_supports( 'WP_Clean-remove-dashboard-widgets' ) ); - } - - function test_remove_dashboard_widgets() { - $this->assertNotFalse( has_filter( 'admin_init', 'WP_Clean\\RemoveDashboardWidgets\remove_dashboard_widgets' ) ); - } - -} diff --git a/tests/tests-disable-posts.php b/tests/tests-disable-posts.php deleted file mode 100644 index 53e631f..0000000 --- a/tests/tests-disable-posts.php +++ /dev/null @@ -1,13 +0,0 @@ -assertTrue( current_theme_supports( 'WP_Clean-disable-posts' ) ); - } - - function test_action_remove_menus() { - $this->assertNotFalse( has_action( 'wp_before_admin_bar_render', 'WP_Clean\\DisablePosts\action_remove_menus' ) ); - } - -} diff --git a/wp-clean.php b/wp-clean.php index 4e4d6a9..7a28992 100644 --- a/wp-clean.php +++ b/wp-clean.php @@ -1,21 +1,19 @@ $tag) + add_filter($tag, $function_to_add, (int)(is_array($priority) ? $priority[$index] : $priority), (int)(is_array($accepted_args) ? $accepted_args[$index] : $accepted_args)); + + return true; +} + +/** + * Add multiple actions to a closure + * + * @param $tags + * @param $function_to_add + * @param int $priority + * @param int $accepted_args + * + * @return bool true + */ +function add_actions($tags, $function_to_add, $priority = 10, $accepted_args = 1) +{ + //add_action() is just a wrapper around add_filter(), so we do the same + return add_filters($tags, $function_to_add, $priority, $accepted_args); +} From 0c171516aaee37d7df3c9f326b616700ee71d86d Mon Sep 17 00:00:00 2001 From: Daniel Hewes Date: Thu, 3 Nov 2016 21:58:31 -0700 Subject: [PATCH 2/4] Move multi filter / actions functions in the main plugin file. --- wp-clean.php | 30 +++++++++++++++++++++++++++++- wp-multifilter.php | 46 ---------------------------------------------- 2 files changed, 29 insertions(+), 47 deletions(-) delete mode 100644 wp-multifilter.php diff --git a/wp-clean.php b/wp-clean.php index 7a28992..1cf5a4f 100644 --- a/wp-clean.php +++ b/wp-clean.php @@ -8,8 +8,10 @@ * Author URI: http://lambdacreatives.com/ */ -require_once 'wp-multifilter.php'; +/** + * Module include based on add_theme_support value + */ add_action('after_setup_theme', function() { foreach (glob(__DIR__ . '/modules/*.php') as $file) { if (current_theme_supports('wp-clean-' . basename($file, '.php'))) { @@ -17,3 +19,29 @@ } } }); + + +/** + * Hooks a single callback to multiple tags + */ +function add_filters($tags, $function, $priority = 10, $accepted_args = 1) { + foreach ((array) $tags as $tag) { + add_filter($tag, $function, $priority, $accepted_args); + } +} + + +/** + * Add multiple actions to a closure + * + * @param $tags + * @param $function_to_add + * @param int $priority + * @param int $accepted_args + * + * @return bool true + */ +function add_actions($tags, $function_to_add, $priority = 10, $accepted_args = 1) { + //add_action() is just a wrapper around add_filter(), so we do the same + return add_filters($tags, $function_to_add, $priority, $accepted_args); +} diff --git a/wp-multifilter.php b/wp-multifilter.php deleted file mode 100644 index 6b00470..0000000 --- a/wp-multifilter.php +++ /dev/null @@ -1,46 +0,0 @@ - $tag) - add_filter($tag, $function_to_add, (int)(is_array($priority) ? $priority[$index] : $priority), (int)(is_array($accepted_args) ? $accepted_args[$index] : $accepted_args)); - - return true; -} - -/** - * Add multiple actions to a closure - * - * @param $tags - * @param $function_to_add - * @param int $priority - * @param int $accepted_args - * - * @return bool true - */ -function add_actions($tags, $function_to_add, $priority = 10, $accepted_args = 1) -{ - //add_action() is just a wrapper around add_filter(), so we do the same - return add_filters($tags, $function_to_add, $priority, $accepted_args); -} From b917e57fbba41c19a83c84b1744205ac2f771eff Mon Sep 17 00:00:00 2001 From: Daniel Hewes Date: Thu, 3 Nov 2016 22:14:26 -0700 Subject: [PATCH 3/4] Rename plugin due to public plugin name clash. --- wp-clean.php => lambda-wp-clean.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename wp-clean.php => lambda-wp-clean.php (97%) diff --git a/wp-clean.php b/lambda-wp-clean.php similarity index 97% rename from wp-clean.php rename to lambda-wp-clean.php index 1cf5a4f..d82ced6 100644 --- a/wp-clean.php +++ b/lambda-wp-clean.php @@ -1,6 +1,6 @@ Date: Thu, 3 Nov 2016 22:16:01 -0700 Subject: [PATCH 4/4] Update readme. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f4b6079..8351237 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# wp-clean +# lambda-wp-clean WordPress plugin to clean up unused functionality and extra bloat. # Modules #