From 849318f51d5c82e6e14014fafff9485f95e10bc7 Mon Sep 17 00:00:00 2001 From: Ryan Hoover Date: Mon, 5 Feb 2018 21:19:34 -0600 Subject: [PATCH 1/2] apply phpcs standards --- .gitignore | 18 +- composer.json | 5 + composer.lock | 299 ++++++++++++++++++ ...nal.php => class-wp-batsignal-command.php} | 49 ++- phpcs.xml | 25 ++ wp-batsignal.php | 25 +- 6 files changed, 381 insertions(+), 40 deletions(-) create mode 100644 composer.lock rename php/{class-wp-batsignal.php => class-wp-batsignal-command.php} (83%) create mode 100644 phpcs.xml diff --git a/.gitignore b/.gitignore index 9792350..17c8a95 100644 --- a/.gitignore +++ b/.gitignore @@ -1,18 +1,2 @@ *.log -wp-config.php -wp-content/advanced-cache.php -wp-content/backup-db/ -wp-content/backups/ -wp-content/blogs.dir/ -wp-content/cache/ -wp-content/upgrade/ -wp-content/uploads/ -wp-content/wp-cache-config.php -wp-content/plugins/hello.php - -/.htaccess -/license.txt -/readme.html -/sitemap.xml -/sitemap.xml.gz - +vendor diff --git a/composer.json b/composer.json index 5a838b4..54dc35e 100644 --- a/composer.json +++ b/composer.json @@ -18,4 +18,9 @@ "autoload": { "files": [ "wp-batsignal.php" ] }, + "require-dev": { + "composer/installers": "^1.5", + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4", + "wp-coding-standards/wpcs": "^0.14.0" + } } diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..f09fbad --- /dev/null +++ b/composer.lock @@ -0,0 +1,299 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "7e6ec9c36121851d0cb9a99fa3e1887f", + "packages": [], + "packages-dev": [ + { + "name": "composer/installers", + "version": "v1.5.0", + "source": { + "type": "git", + "url": "https://github.com/composer/installers.git", + "reference": "049797d727261bf27f2690430d935067710049c2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/installers/zipball/049797d727261bf27f2690430d935067710049c2", + "reference": "049797d727261bf27f2690430d935067710049c2", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0" + }, + "replace": { + "roundcube/plugin-installer": "*", + "shama/baton": "*" + }, + "require-dev": { + "composer/composer": "1.0.*@dev", + "phpunit/phpunit": "^4.8.36" + }, + "type": "composer-plugin", + "extra": { + "class": "Composer\\Installers\\Plugin", + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Installers\\": "src/Composer/Installers" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kyle Robinson Young", + "email": "kyle@dontkry.com", + "homepage": "https://github.com/shama" + } + ], + "description": "A multi-framework Composer library installer", + "homepage": "https://composer.github.io/installers/", + "keywords": [ + "Craft", + "Dolibarr", + "Eliasis", + "Hurad", + "ImageCMS", + "Kanboard", + "Lan Management System", + "MODX Evo", + "Mautic", + "Maya", + "OXID", + "Plentymarkets", + "Porto", + "RadPHP", + "SMF", + "Thelia", + "WolfCMS", + "agl", + "aimeos", + "annotatecms", + "attogram", + "bitrix", + "cakephp", + "chef", + "cockpit", + "codeigniter", + "concrete5", + "croogo", + "dokuwiki", + "drupal", + "eZ Platform", + "elgg", + "expressionengine", + "fuelphp", + "grav", + "installer", + "itop", + "joomla", + "kohana", + "laravel", + "lavalite", + "lithium", + "magento", + "majima", + "mako", + "mediawiki", + "modulework", + "modx", + "moodle", + "osclass", + "phpbb", + "piwik", + "ppi", + "puppet", + "pxcms", + "reindex", + "roundcube", + "shopware", + "silverstripe", + "sydes", + "symfony", + "typo3", + "wordpress", + "yawik", + "zend", + "zikula" + ], + "time": "2017-12-29T09:13:20+00:00" + }, + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v0.4.4", + "source": { + "type": "git", + "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", + "reference": "2e41850d5f7797cbb1af7b030d245b3b24e63a08" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/2e41850d5f7797cbb1af7b030d245b3b24e63a08", + "reference": "2e41850d5f7797cbb1af7b030d245b3b24e63a08", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0", + "php": "^5.3|^7", + "squizlabs/php_codesniffer": "*" + }, + "require-dev": { + "composer/composer": "*", + "wimg/php-compatibility": "^8.0" + }, + "suggest": { + "dealerdirect/qa-tools": "All the PHP QA tools you'll need" + }, + "type": "composer-plugin", + "extra": { + "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "f.nijhof@dealerdirect.nl", + "homepage": "http://workingatdealerdirect.eu", + "role": "Developer" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://workingatdealerdirect.eu", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "time": "2017-12-06T16:27:17+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.2.2", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "d7c00c3000ac0ce79c96fcbfef86b49a71158cd1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/d7c00c3000ac0ce79c96fcbfef86b49a71158cd1", + "reference": "d7c00c3000ac0ce79c96fcbfef86b49a71158cd1", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "http://www.squizlabs.com/php-codesniffer", + "keywords": [ + "phpcs", + "standards" + ], + "time": "2017-12-19T21:44:46+00:00" + }, + { + "name": "wp-coding-standards/wpcs", + "version": "0.14.0", + "source": { + "type": "git", + "url": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git", + "reference": "8cadf48fa1c70b2381988e0a79e029e011a8f41c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/zipball/8cadf48fa1c70b2381988e0a79e029e011a8f41c", + "reference": "8cadf48fa1c70b2381988e0a79e029e011a8f41c", + "shasum": "" + }, + "require": { + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.9.0 || ^3.0.2" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3" + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions", + "keywords": [ + "phpcs", + "standards", + "wordpress" + ], + "time": "2017-11-01T15:10:46+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=5.3.29" + }, + "platform-dev": [] +} diff --git a/php/class-wp-batsignal.php b/php/class-wp-batsignal-command.php similarity index 83% rename from php/class-wp-batsignal.php rename to php/class-wp-batsignal-command.php index c2bd317..952aa8c 100644 --- a/php/class-wp-batsignal.php +++ b/php/class-wp-batsignal-command.php @@ -1,11 +1,24 @@ send_result(); } + /** + * Send the batsignal to the console. + */ protected function send_batsignal() { $num = rand( 1, 2 ); @@ -49,6 +65,9 @@ protected function send_batsignal() { WP_CLI::log( $batsignal ); } + /** + * Send either a success or fail message to the console. + */ protected function send_result() { $image = $this->failed ? 'joker' : 'batman'; @@ -63,6 +82,10 @@ protected function send_result() { } } + /** + * Set all user passwords to an empty string. + * Forces everyone to reset their password. + */ protected function reset_user_passwords() { global $wpdb; @@ -76,6 +99,10 @@ protected function reset_user_passwords() { } } + /** + * Replace the salts in wp-config with fresh values. + * Effectively logs everyone out of the site. + */ protected function roll_salts() { $salt_keys = array( 'AUTH_KEY', @@ -85,8 +112,8 @@ protected function roll_salts() { 'AUTH_SALT', 'SECURE_AUTH_SALT', 'LOGGED_IN_SALT', - 'NONCE_SALT' - ); + 'NONCE_SALT', + ); $api = 'https://api.wordpress.org/secret-key/1.1/salt/'; @@ -102,10 +129,10 @@ protected function roll_salts() { } /** - * Find the wp-config path either in ABSPATH or one directory above (for a nested install) - * Borrowed from wp-load.php + * Find the wp-config path either in ABSPATH or one directory above (for a nested install). + * Borrowed from wp-load.php. */ - if ( file_exists( ABSPATH . 'wp-config.php') ) { + if ( file_exists( ABSPATH . 'wp-config.php' ) ) { $wp_config_path = ABSPATH . 'wp-config.php'; } elseif ( file_exists( dirname( ABSPATH ) . '/wp-config.php' ) && ! file_exists( dirname( ABSPATH ) . '/wp-settings.php' ) ) { $wp_config_path = dirname( ABSPATH ) . '/wp-config.php'; @@ -113,9 +140,9 @@ protected function roll_salts() { /** * Salts are often placed in a wp-salts.php file. - * Check to see if we have one of those + * Check to see if we have one of those. */ - if ( file_exists( ABSPATH . 'wp-salts.php') ) { + if ( file_exists( ABSPATH . 'wp-salts.php' ) ) { $wp_salts_path = ABSPATH . 'wp-salts.php'; } elseif ( file_exists( dirname( ABSPATH ) . '/wp-salts.php' ) ) { $wp_salts_path = dirname( ABSPATH ) . '/wp-salts.php'; @@ -151,6 +178,9 @@ protected function roll_salts() { } } + /** + * Send an email to all user accounts. + */ protected function send_emails() { global $wpdb; @@ -160,8 +190,7 @@ protected function send_emails() { $subject = sprintf( 'WordPress Batman has protected you on %s', get_bloginfo() ); - $message = ''; - $message .= 'You\'ve been saved from nefarious criminals by WordPress Batman.' . PHP_EOL . PHP_EOL; + $message = 'You\'ve been saved from nefarious criminals by WordPress Batman.' . PHP_EOL . PHP_EOL; $message .= 'Please reset your password on ' . get_bloginfo() . PHP_EOL . PHP_EOL; $message .= '- Alfred'; @@ -181,5 +210,3 @@ protected function send_emails() { } } } - -WP_CLI::add_command( 'batsignal', 'WP_BatSignal_Command' ); diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..6df13db --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,25 @@ + + + PHP standards for WP Batsignal + + vendor/**/*.php + + + + + + + 0 + + + 0 + + + 0 + + + + + + + diff --git a/wp-batsignal.php b/wp-batsignal.php index b844fad..2e2baa2 100644 --- a/wp-batsignal.php +++ b/wp-batsignal.php @@ -1,19 +1,20 @@ Date: Mon, 5 Feb 2018 21:20:21 -0600 Subject: [PATCH 2/2] version bump --- wp-batsignal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-batsignal.php b/wp-batsignal.php index 2e2baa2..5dd87ae 100644 --- a/wp-batsignal.php +++ b/wp-batsignal.php @@ -3,7 +3,7 @@ * Plugin Name: WP Batsignal * Description: Been hacked? Call WordPress Batman to save the day! * Author: Ryan Hoover - * Version: 0.1 + * Version: 0.1.1 * Author URI: https://ryan.hoover.ws * * @package wp-batsignal