From a7f751e9f19e6415e3f161cfb68b52055ea625d9 Mon Sep 17 00:00:00 2001 From: Shady Sharaf Date: Sun, 25 Aug 2013 11:26:50 +0200 Subject: [PATCH 01/16] + Adds a new Tabbed Settings page + Adds option to disable minification alltogether + Adds option to disable minification based on specific conditions ( islogged, is_admin, query var present ) + Adds option to exclude resources, line-delimited, based on string search not matching, means it matches any part of the url * Note: Disabling minification does not disable serving minified files, so cached pages does not break. --- admin.css | 13 ++++ admin.js | 20 +++++ dependency-minification.php | 141 ++++++++++++++++++++++++++++++++---- 3 files changed, 160 insertions(+), 14 deletions(-) diff --git a/admin.css b/admin.css index 5199a48..3c63c93 100644 --- a/admin.css +++ b/admin.css @@ -14,3 +14,16 @@ .fixed .column-expires { width: 12%; } + +.nav-tab-content { + display: none; +} +.form-table th small { + display: block; + clear: both; + color: #999; +} +.form-table td label { + display: block; + clear:both; +} \ No newline at end of file diff --git a/admin.js b/admin.js index e69de29..2b6d574 100644 --- a/admin.js +++ b/admin.js @@ -0,0 +1,20 @@ +jQuery(function($){ + + // Admin page tabs + var $tabs = $('.nav-tab-wrapper'), + $panels = $('.nav-tab-content'), + currentHash = window.location.hash; + + $tabs.on('click', 'a', function(e){ + var hash = $(this).attr('href').replace('#tab-', '#tab-content-'); // prevents page scrolling if hash is present + $panels.hide().filter(hash).show(); + $tabs.find('a').removeClass('nav-tab-active').filter($(this)).addClass('nav-tab-active'); + }); + $tabs.find( currentHash ? 'a[href="'+currentHash+'"]' : ':first').trigger('click'); + + // Fix input-inside-label glitch + $panels.on('click', 'input[type=text]', function(e){ + e.preventDefault(); + }) + +}); \ No newline at end of file diff --git a/dependency-minification.php b/dependency-minification.php index 1cc347b..e0c7d36 100644 --- a/dependency-minification.php +++ b/dependency-minification.php @@ -14,13 +14,14 @@ class Dependency_Minification { protected static $minified_count = 0; static $admin_page_hook; - const DEFAULT_ENDPOINT = '_minify'; - const CRON_MINIFY_ACTION = 'minify_dependencies'; - const CACHE_KEY_PREFIX = 'depmin_cache_'; - const FILENAME_PATTERN = '([^/]+?)\.([0-9a-f]+)(?:\.([0-9a-f]+))?\.(css|js)'; - const AJAX_ACTION = 'dependency_minification'; - const ADMIN_PAGE_SLUG = 'dependency-minification'; - const ADMIN_PARENT_PAGE = 'tools.php'; + const DEFAULT_ENDPOINT = '_minify'; + const CRON_MINIFY_ACTION = 'minify_dependencies'; + const CACHE_KEY_PREFIX = 'depmin_cache_'; + const FILENAME_PATTERN = '([^/]+?)\.([0-9a-f]+)(?:\.([0-9a-f]+))?\.(css|js)'; + const AJAX_ACTION = 'dependency_minification'; + const AJAX_OPTIONS_ACTION = 'dependency_minification_options'; + const ADMIN_PAGE_SLUG = 'dependency-minification'; + const ADMIN_PARENT_PAGE = 'tools.php'; static $query_vars = array( 'depmin_handles', @@ -30,8 +31,7 @@ class Dependency_Minification { ); static function setup() { - self::$options = apply_filters( 'dependency_minification_options', array_merge( - array( + $defaults = array( 'endpoint' => self::DEFAULT_ENDPOINT, 'default_exclude_remote_dependencies' => true, 'cache_control_max_age_cache' => 2629743, // 1 month in seconds @@ -40,8 +40,13 @@ static function setup() { 'admin_page_capability' => 'edit_theme_options', 'show_error_messages' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ), 'disable_if_wp_debug' => true, - ), - self::$options + 'exclude_dependencies' => '', + 'disabled_on_conditions' => array(), + ); + $options = get_option( 'dependency_minification_options', array() ); + self::$options = apply_filters( 'dependency_minification_options', array_merge( + $defaults, + $options ) ); $is_frontend = ! ( @@ -49,7 +54,21 @@ static function setup() { || in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ) ); - if ( $is_frontend ) { + $disabled = ( + ! empty( self::$options['disabled_on_conditions']['all'] ) + || ( !empty( self::$options['disabled_on_conditions']['loggedin'] ) && is_user_logged_in() ) + || ( !empty( self::$options['disabled_on_conditions']['admin'] ) && is_user_logged_in() && current_user_can( 'manage_plugins' ) ) + || ( !empty( self::$options['disabled_on_conditions']['queryvar']['enabled'] ) + && !empty( self::$options['disabled_on_conditions']['queryvar']['enabled'] ) + && !empty( $_GET[ self::$options['disabled_on_conditions']['queryvar']['value'] ] ) + ) + ); + + if ( + $is_frontend + && + ! $disabled + ) { add_filter( 'print_scripts_array', array( __CLASS__, 'filter_print_scripts_array' ) ); add_filter( 'print_styles_array', array( __CLASS__, 'filter_print_styles_array' ) ); } @@ -59,6 +78,7 @@ static function setup() { add_action( 'admin_notices', array( __CLASS__, 'admin_notices' ) ); add_action( 'admin_enqueue_scripts', array( __CLASS__, 'admin_enqueue_scripts' ) ); add_action( 'wp_ajax_' . self::AJAX_ACTION, array( __CLASS__, 'admin_ajax_handler' ) ); + add_action( 'wp_ajax_' . self::AJAX_OPTIONS_ACTION, array( __CLASS__, 'admin_ajax_options_handler' ) ); add_filter( 'plugin_action_links', array( __CLASS__, 'admin_plugin_action_links' ), 10, 2 ); } @@ -237,6 +257,32 @@ static function admin_ajax_handler() { exit; } + /** + * @action wp_ajax_dependency_minification_options + */ + static function admin_ajax_options_handler() { + if ( ! current_user_can( self::$options['admin_page_capability'] ) ) { + wp_die( __( 'You are not allowed to do that.', 'depmin' ) ); + } + if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], self::AJAX_OPTIONS_ACTION ) ) { + wp_die( __( 'Nonce check failed. Try reloading the previous page.', 'depmin' ) ); + } + $updated_count = 0; + if ( ! empty( $_REQUEST['options'] ) ) { + $options = get_option( 'dependency_minification_options' ); + $options['exclude_dependencies'] = array_filter( preg_split( "#[\n\r]+#", $_REQUEST['options']['exclude_dependencies'] ) ); + $options['disabled_on_conditions'] = $_REQUEST['options']['disabled_on_conditions']; + update_option( 'dependency_minification_options', $options ); + } + + $redirect_url = add_query_arg( 'page', self::ADMIN_PAGE_SLUG, admin_url( self::ADMIN_PARENT_PAGE ) ); + $redirect_url = add_query_arg( 'updated', 1, $redirect_url ); + $redirect_url.= '#tab-settings'; + wp_redirect( $redirect_url ); + + die(); + } + /** * @filter plugin_action_links */ @@ -258,8 +304,11 @@ static function admin_page() {

- - + + + +
registered[$handle]->src; $is_local = self::is_self_hosted_src( $src ); $is_excluded = !$is_local && self::$options['default_exclude_remote_dependencies']; + $is_excluded = $is_excluded || self::is_url_included( $src, self::$options['exclude_dependencies'] ); $is_excluded = apply_filters( 'dependency_minification_excluded', $is_excluded, $handle, $src ); if ( $last_was_excluded !== $is_excluded ) { From a0c2b874bb10482523aa204e9d96c8f9cadd4084 Mon Sep 17 00:00:00 2001 From: Shady Sharaf Date: Sun, 25 Aug 2013 12:04:20 +0200 Subject: [PATCH 02/16] + Exposes the option of defaulting to exclude the external dependencies. #5 * Fix a small translation missing text domain --- dependency-minification.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/dependency-minification.php b/dependency-minification.php index e0c7d36..383d747 100644 --- a/dependency-minification.php +++ b/dependency-minification.php @@ -272,6 +272,7 @@ static function admin_ajax_options_handler() { $options = get_option( 'dependency_minification_options' ); $options['exclude_dependencies'] = array_filter( preg_split( "#[\n\r]+#", $_REQUEST['options']['exclude_dependencies'] ) ); $options['disabled_on_conditions'] = $_REQUEST['options']['disabled_on_conditions']; + $options['default_exclude_remote_dependencies'] = isset( $_REQUEST['options']['default_exclude_remote_dependencies'] ); update_option( 'dependency_minification_options', $options ); } @@ -515,6 +516,15 @@ static function admin_page() { + + + + + + + @@ -535,7 +545,7 @@ static function admin_page() { - + From f29016831c83c45f43092b33f284559527738f67 Mon Sep 17 00:00:00 2001 From: Shady Sharaf Date: Sun, 25 Aug 2013 12:56:23 +0200 Subject: [PATCH 03/16] * Fix manage_plugins to manage_options * Remove trailing spaces --- dependency-minification.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/dependency-minification.php b/dependency-minification.php index 383d747..64bcba9 100644 --- a/dependency-minification.php +++ b/dependency-minification.php @@ -55,17 +55,17 @@ static function setup() { in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ) ); $disabled = ( - ! empty( self::$options['disabled_on_conditions']['all'] ) - || ( !empty( self::$options['disabled_on_conditions']['loggedin'] ) && is_user_logged_in() ) - || ( !empty( self::$options['disabled_on_conditions']['admin'] ) && is_user_logged_in() && current_user_can( 'manage_plugins' ) ) - || ( !empty( self::$options['disabled_on_conditions']['queryvar']['enabled'] ) + ! empty( self::$options['disabled_on_conditions']['all'] ) + || ( !empty( self::$options['disabled_on_conditions']['loggedin'] ) && is_user_logged_in() ) + || ( !empty( self::$options['disabled_on_conditions']['admin'] ) && is_user_logged_in() && current_user_can( 'manage_options' ) ) + || ( !empty( self::$options['disabled_on_conditions']['queryvar']['enabled'] ) && !empty( self::$options['disabled_on_conditions']['queryvar']['enabled'] ) && !empty( $_GET[ self::$options['disabled_on_conditions']['queryvar']['value'] ] ) ) ); - if ( - $is_frontend + if ( + $is_frontend && ! $disabled ) { @@ -174,7 +174,7 @@ static function admin_notices() { ?>

%1$s: %2$s', __( 'Dependency Minification', 'depmin' ), sprintf( From 41dd1729ab2967fcc2d553a6b43f1bf786a76a86 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 13 Oct 2013 23:15:52 -0700 Subject: [PATCH 04/16] Squashed 'bin/' changes from 5614813..774bdc3 774bdc3 Check modified files, pass select JS to jshint, run phpunit in vagrant bc955c7 Fix pre-commit detection of staged_php_files d0194bb Add PHP syntax checks for travis-ci and pre-commit hook c98d9c4 Merge branch 'master' of github.com:x-team/wp-plugin-dev-lib 2e1b928 Remove dependency on WP_CLI 0e07a75 Note how add .travis.yml and .jshintrc to host plugin via symlinks da3555c Also check for presence of phpunit.xml.dist 0ae29af Update pre-commit hook so PHPCS only looks at staged PHP files 00d36fb Merge commit '7ef48bd5aa6680d02589a9f5697b35cd9a9520ca' into develop f5f2c1c Update pre-commit hook to look for staged php files 3ddac64 Revamp pre-commit hook, adding jshint 9f7df05 Rename .jshint => .jshintrc 817f4c2 Add travis-ci with support for jshint, phpcs, phpunit a3a984d Add jshint and fix warnings 730cf4f Merge commit '32585ea10effb3de33aa7136424364359c199969' 1095520 Apply phpcs fixes git-subtree-dir: bin git-subtree-split: 774bdc3be5ba985f15ef4eefea94dd0dc5baac1c --- .jshintrc | 63 ++++++++++++++++++++++++ .travis.yml | 31 ++++++++++++ class-wordpress-readme-parser.php | 61 +++++++++++++---------- pre-commit | 81 ++++++++++++++++++++++++------- readme.md | 16 +++++- 5 files changed, 208 insertions(+), 44 deletions(-) create mode 100644 .jshintrc create mode 100644 .travis.yml diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..a2bb92b --- /dev/null +++ b/.jshintrc @@ -0,0 +1,63 @@ +// -------------------------------------------------------------------- +// WordPress JSHint Configuration +// -------------------------------------------------------------------- +{ + "bitwise" : true, // Prohibit bitwise operators (&, |, ^, etc.). + "curly" : true, // Require {} for every new block or scope. + "eqeqeq" : true, // Require triple equals i.e. `===`. + "forin" : true, // Tolerate `for in` loops without `hasOwnPrototype`. + "immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );` + "latedef" : true, // Prohibit variable use before definition. + "newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`. + "noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`. + "noempty" : true, // Prohibit use of empty blocks. + "nonew" : true, // Prohibit use of constructors for side-effects. + "plusplus" : false, // Prohibit use of `++` & `--`. + "regexp" : false, // Prohibit `.` and `[^...]` in regular expressions. + "undef" : true, // Require all non-global variables be declared before they are used. + "strict" : true, // Require `use strict` pragma in every file. + "trailing" : true, // Prohibit trailing whitespaces. + "asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons). + "boss" : false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments. + "debug" : false, // Allow debugger statements e.g. browser breakpoints. + "eqnull" : false, // Tolerate use of `== null`. + "es5" : false, // Allow EcmaScript 5 syntax. + "esnext" : false, // Allow ES.next specific features such as `const` and `let`. + "evil" : false, // Tolerate use of `eval`. + "expr" : false, // Tolerate `ExpressionStatement` as Programs. + "funcscope" : false, // Tolerate declarations of variables inside of control structures while accessing them later from the outside. + "globalstrict" : false, // Allow global "use strict" (also enables 'strict'). + "iterator" : false, // Allow usage of __iterator__ property. + "lastsemic" : false, // Tolerate missing semicolons when it is omitted for the last statement in a one-line block. + "laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons. + "laxcomma" : false, // Suppress warnings about comma-first coding style. + "loopfunc" : false, // Allow functions to be defined within loops. + "multistr" : false, // Tolerate multi-line strings. + "onecase" : false, // Tolerate switches with just one case. + "proto" : false, // Tolerate __proto__ property. This property is deprecated. + "regexdash" : false, // Tolerate unescaped last dash i.e. `[-...]`. + "scripturl" : false, // Tolerate script-targeted URLs. + "smarttabs" : false, // Tolerate mixed tabs and spaces when the latter are used for alignmnent only. + "shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`. + "sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`. + "supernew" : true, // Tolerate `new function () { ... };` and `new Object;`. + "validthis" : false, // Tolerate strict violations when the code is running in strict mode and you use this in a non-constructor function. + "browser" : true, // Standard browser globals e.g. `window`, `document`. + "couch" : false, // Enable globals exposed by CouchDB. + "devel" : false, // Allow development statements e.g. `console.log();`. + "dojo" : false, // Enable globals exposed by Dojo Toolkit. + "jquery" : true, // Enable globals exposed by jQuery JavaScript library. + "mootools" : false, // Enable globals exposed by MooTools JavaScript framework. + "node" : false, // Enable globals available when code is running inside of the NodeJS runtime environment. + "nonstandard" : false, // Define non-standard but widely adopted globals such as escape and unescape. + "prototypejs" : false, // Enable globals exposed by Prototype JavaScript framework. + "rhino" : false, // Enable globals available when your code is running inside of the Rhino runtime environment. + "wsh" : false, // Enable globals available when your code is running as a script for the Windows Script Host. + "nomen" : false, // Prohibit use of initial or trailing underbars in names. + "onevar" : false, // Allow only one `var` statement per function. + "passfail" : false, // Stop on first error. + "white" : false, // Check against strict whitespace and indentation rules. + "maxerr" : 100, // Maximum errors before stopping. + "predef" : [], // Extra globals. + "indent" : 4 // Specify indentation spacing +} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f686519 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,31 @@ +language: + - php + - node_js + +php: + - 5.3 + - 5.4 + +node_js: + - 0.10 + +env: + - WP_VERSION=master WP_MULTISITE=0 + - WP_VERSION=master WP_MULTISITE=1 + - WP_VERSION=3.6.1 WP_MULTISITE=0 + - WP_VERSION=3.6.1 WP_MULTISITE=1 + +before_script: + - export WP_TESTS_DIR=/tmp/wordpress-tests/ + - if [ -e phpunit.xml ]; then bash bin/install-wp-tests.sh wordpress_test root '' $WP_VERSION; fi + - pear config-set auto_discover 1 + - pear install PHP_CodeSniffer + - git clone git://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git $(pear config-get php_dir)/PHP/CodeSniffer/Standards/WordPress + - phpenv rehash + - npm install -g jshint + +script: + - find . \( -name '*.php' -o -name '*.inc' \) -exec php -lf {} \; + - if [ -e phpunit.xml ] || [ -e phpunit.xml.dist ]; then phpunit; fi + - phpcs --standard=$(if [ -e ruleset.xml ]; then echo ruleset.xml; else echo WordPress; fi) $(find . -name '*.php') + - jshint . diff --git a/class-wordpress-readme-parser.php b/class-wordpress-readme-parser.php index 6918dd7..08e121d 100644 --- a/class-wordpress-readme-parser.php +++ b/class-wordpress-readme-parser.php @@ -19,7 +19,7 @@ class WordPress_Readme_Parser { function __construct( $args = array() ) { $args = array_merge( get_object_vars( $this ), $args ); - foreach ($args as $key => $value) { + foreach ( $args as $key => $value ) { $this->$key = $value; } @@ -37,9 +37,11 @@ function __construct( $args = array() ) { $this->short_description = $matches[3]; $readme_txt_rest = $matches[4]; $this->metadata = array_fill_keys( array( 'Contributors', 'Tags', 'Requires at least', 'Tested up to', 'Stable tag', 'License', 'License URI' ), null ); - foreach( explode( "\n", $matches[2] ) as $metadatum ) { - preg_match( '/^(.+?):\s+(.+)$/', $metadatum, $metadataum_matches ) || \WP_CLI::error( "Parse error in $metadatum" ); - list( $name, $value ) = array_slice( $metadataum_matches, 1, 2 ); + foreach ( explode( "\n", $matches[2] ) as $metadatum ) { + if ( ! preg_match( '/^(.+?):\s+(.+)$/', $metadatum, $metadataum_matches ) ) { + throw new \Exception( "Parse error in $metadatum" ); + } + list( $name, $value ) = array_slice( $metadataum_matches, 1, 2 ); $this->metadata[$name] = $value; } $this->metadata['Contributors'] = preg_split( '/\s*,\s*/', $this->metadata['Contributors'] ); @@ -52,8 +54,8 @@ function __construct( $args = array() ) { foreach ( $section_matches as $section_match ) { array_shift( $section_match ); - $heading = array_shift( $section_match ); - $body = trim( array_shift( $section_match ) ); + $heading = array_shift( $section_match ); + $body = trim( array_shift( $section_match ) ); $subsections = array(); // @todo Parse out front matter /(.+?)(\n=\s+.+$)/s @@ -76,6 +78,7 @@ function __construct( $args = array() ) { /** * Convert the parsed readme.txt into Markdown + * @param array|string [$params] * @return string */ function to_markdown( $params = array() ) { @@ -91,10 +94,12 @@ function to_markdown( $params = array() ) { 'Screenshots' => function ( $body ) { $body = trim( $body ); $new_body = ''; - $screenshots = array(); - preg_match_all( '/^\d+\. (.+?)$/m', $body, $screenshot_matches, PREG_SET_ORDER ) || \WP_CLI::error( 'Malformed screenshot section' ); + if ( ! preg_match_all( '/^\d+\. (.+?)$/m', $body, $screenshot_matches, PREG_SET_ORDER ) ) { + throw new Exception( 'Malformed screenshot section' ); + } foreach ( $screenshot_matches as $i => $screenshot_match ) { - foreach ( array( 'jpg', 'gif', 'png' ) as $ext ) { + $img_extensions = array( 'jpg', 'gif', 'png' ); + foreach ( $img_extensions as $ext ) { $filepath = sprintf( 'assets/screenshot-%d.%s', $i + 1, $ext ); if ( file_exists( dirname( $this->path ) . DIRECTORY_SEPARATOR . $filepath ) ) { break; @@ -119,20 +124,26 @@ function to_markdown( $params = array() ) { // Format metadata $formatted_metadata = $this->metadata; - $formatted_metadata['Contributors'] = join(', ', array_map( - function ( $contributor ) { - $contributor = strtolower( $contributor ); - // @todo Map to GitHub account - return sprintf( '[%1$s](http://profiles.wordpress.org/%1$s)', $contributor ); - }, - $this->metadata['Contributors'] - )); - $formatted_metadata['Tags'] = join(', ', array_map( - function ( $tag ) { - return sprintf( '[%1$s](http://wordpress.org/plugins/tags/%1$s)', $tag ); - }, - $this->metadata['Tags'] - )); + $formatted_metadata['Contributors'] = join( + ', ', + array_map( + function ( $contributor ) { + $contributor = strtolower( $contributor ); + // @todo Map to GitHub account + return sprintf( '[%1$s](http://profiles.wordpress.org/%1$s)', $contributor ); + }, + $this->metadata['Contributors'] + ) + ); + $formatted_metadata['Tags'] = join( + ', ', + array_map( + function ( $tag ) { + return sprintf( '[%1$s](http://wordpress.org/plugins/tags/%1$s)', $tag ); + }, + $this->metadata['Tags'] + ) + ); $formatted_metadata['License'] = sprintf( '[%s](%s)', $formatted_metadata['License'], $formatted_metadata['License URI'] ); unset( $formatted_metadata['License URI'] ); if ( $this->metadata['Stable tag'] === 'trunk' ) { @@ -140,7 +151,7 @@ function ( $tag ) { } // Render metadata - $markdown = "\n"; + $markdown = "\n"; $markdown .= sprintf( "# %s\n", $this->title ); $markdown .= "\n"; if ( file_exists( 'assets/banner-1544x500.png' ) ) { @@ -160,7 +171,7 @@ function ( $tag ) { $body = $section['body']; if ( isset( $section_formatters[$section['heading']] ) ) { - $body = trim(call_user_func( $section_formatters[$section['heading']], $body )); + $body = trim( call_user_func( $section_formatters[$section['heading']], $body ) ); } if ( $body ) { $markdown .= sprintf( "%s\n", $body ); diff --git a/pre-commit b/pre-commit index 17d9685..630c0a2 100755 --- a/pre-commit +++ b/pre-commit @@ -1,27 +1,74 @@ #!/bin/sh -# An example pre-commit hook for WordPress +# WordPress Plugin pre-commit hook set -e +message="Checking staged changes..." +git_status_egrep='^[MARC].+' + +for i; do + case "$i" + in + -m) + message="Checking any uncommitted changes..." + git_status_egrep='^.?[MARC].+' + shift;; + esac +done + +echo $message + +# Check for staged JS files +IFS=$'\n' staged_js_files=( $(git status --porcelain | egrep $git_status_egrep'\.js$' | cut -c4-) ) +if [ ${#staged_js_files[@]} != 0 ]; then + # JSHint + if [ -e .jshintrc ]; then + echo "## jslint" + if command -v jshint >/dev/null 2>&1; then + jshint "${staged_js_files[@]}" + else + echo "Skipping jshint since not installed" + fi + fi + +fi + +# Check for staged PHP files +IFS=$'\n' staged_php_files=( $(git status --porcelain | egrep $git_status_egrep'\.php$' | cut -c4-) ) +if [ ${#staged_php_files[@]} != 0 ]; then + # PHP Syntax Check + for php_file in "${staged_php_files[@]}"; do + php -lf $php_file + done + + # PHPUnit + if [ -e phpunit.xml ] || [ -e phpunit.xml.dist ]; then + echo "## phpunit" + if [ "$USER" != 'vagrant' ] && command -v vagrant >/dev/null 2>&1 && command -v vassh >/dev/null 2>&1; then + echo "Running phpunit in vagrant..." + vassh phpunit + elif ! command -v phpunit >/dev/null 2>&1;then + echo "Skipping phpunit since not installed" + elif [ -z "$WP_TESTS_DIR" ]; then + echo "Skipping phpunit since WP_TESTS_DIR env missing" + else + phpunit + fi + fi + + # PHP_CodeSniffer WordPress Coding Standards + echo "## phpcs" + if command -v jshint >/dev/null 2>&1; then + phpcs_standard=$(if [ -e ruleset.xml ]; then echo ruleset.xml; else echo WordPress; fi) + phpcs -p -s -v --standard=$phpcs_standard "${staged_php_files[@]}" + else + echo "Skipping phpcs since not installed" + fi +fi + # Make sure the readme.md never gets out of sync with the readme.txt generate_markdown_readme=$(find . -name generate-markdown-readme -print -quit) if [ -n "$generate_markdown_readme" ]; then markdown_readme_path=$($generate_markdown_readme) git add $markdown_readme_path fi - -if [ -e phpunit.xml.dist ]; then - # @todo Check to see if phpunit is even installed - # @todo Check if WP_TESTS_DIR is not set - phpunit -fi - -if [ -e .jshintrc ]; then - # @todo Check to see if jshint is even installed - jshint -fi - -# Run through PHP_CodeSniffer rules for WordPress Coding Standards -# @todo Check if phpcs is installed -# @todo Check if WordPress standard sniffs are installed -phpcs -p -s -v --standard=WordPress $(git status --porcelain | egrep '^[MARC]' | cut -c4- | egrep '.php$') diff --git a/readme.md b/readme.md index 9d48e48..5015dff 100644 --- a/readme.md +++ b/readme.md @@ -5,9 +5,21 @@ wp-plugin-dev-lib It is intended that this repo be included in plugin repo via git-subtree/submodule in a `bin/` directory. -Symlink to `pre-commit` from your project's `.git/hooks/pre-commit` +Symlink to the `.travis.yml` and `.jshintrc` inside of the same directory: -Includes a WordPress README [parser](class-wordpress-readme-parser.php) and [converter](generate-markdown-readme) to Markdown, +```bash +ln -s bin/.travis.yml . && git add .travis.yml +ln -s bin/.jshintrc . && git add .jshintrc +``` + +Symlink to `pre-commit` from your project's `.git/hooks/pre-commit`: + +```bash +cd .git/hooks +ln -s ../../bin/pre-commit . +``` + +The library includes a WordPress README [parser](class-wordpress-readme-parser.php) and [converter](generate-markdown-readme) to Markdown, so you don't have to manually keep your `readme.txt` on WordPress.org in sync with the `readme.md` you have on GitHub. The converter will also automatically recognize the presence of projects with Travis CI and include the status image in the markdown. Screenshots and banner images for WordPress.org are also automatically incorporated into the `readme.md`. From 8c7cb6ef44753498423ff7e274821d42756dc600 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 13 Oct 2013 23:25:38 -0700 Subject: [PATCH 05/16] Add travis, jshint, and phpcs ruleset --- .jshintrc | 1 + .travis.yml | 1 + readme.md | 2 ++ ruleset.xml | 8 ++++++++ 4 files changed, 12 insertions(+) create mode 120000 .jshintrc create mode 120000 .travis.yml create mode 100644 ruleset.xml diff --git a/.jshintrc b/.jshintrc new file mode 120000 index 0000000..e566925 --- /dev/null +++ b/.jshintrc @@ -0,0 +1 @@ +bin/.jshintrc \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 120000 index 0000000..948a887 --- /dev/null +++ b/.travis.yml @@ -0,0 +1 @@ +bin/.travis.yml \ No newline at end of file diff --git a/readme.md b/readme.md index b19754c..e4b4591 100644 --- a/readme.md +++ b/readme.md @@ -50,6 +50,8 @@ If you are using Nginx with the default Varying Vagrant Vagrants config, you'll log_not_found off; } +[![Build Status](https://travis-ci.org/x-team/wp-dependency-minification.png)](https://travis-ci.org/x-team/wp-dependency-minification) + ## Changelog ## ### 0.9.7 ### diff --git a/ruleset.xml b/ruleset.xml new file mode 100644 index 0000000..50eddd7 --- /dev/null +++ b/ruleset.xml @@ -0,0 +1,8 @@ + + + We want all WordPress standards but we want to exclude the vendor directories + + /minify/* + + + From 15a71391586aa47a218621466230f001ea2786c9 Mon Sep 17 00:00:00 2001 From: Shady Sharaf Date: Mon, 14 Oct 2013 12:18:21 +0200 Subject: [PATCH 06/16] Notices / CS fixes, Related #27 --- dependency-minification.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/dependency-minification.php b/dependency-minification.php index 64bcba9..5a2b9ff 100644 --- a/dependency-minification.php +++ b/dependency-minification.php @@ -55,12 +55,12 @@ static function setup() { in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ) ); $disabled = ( - ! empty( self::$options['disabled_on_conditions']['all'] ) - || ( !empty( self::$options['disabled_on_conditions']['loggedin'] ) && is_user_logged_in() ) - || ( !empty( self::$options['disabled_on_conditions']['admin'] ) && is_user_logged_in() && current_user_can( 'manage_options' ) ) - || ( !empty( self::$options['disabled_on_conditions']['queryvar']['enabled'] ) - && !empty( self::$options['disabled_on_conditions']['queryvar']['enabled'] ) - && !empty( $_GET[ self::$options['disabled_on_conditions']['queryvar']['value'] ] ) + ( isset( self::$options['disabled_on_conditions']['all'] ) && ! empty( self::$options['disabled_on_conditions']['all'] ) ) + || ( isset( self::$options['disabled_on_conditions']['loggedin'] ) && ! empty( self::$options['disabled_on_conditions']['loggedin'] ) && is_user_logged_in() ) + || ( ! empty( self::$options['disabled_on_conditions']['admin'] ) && is_user_logged_in() && current_user_can( 'manage_options' ) ) + || ( ! empty( self::$options['disabled_on_conditions']['queryvar']['enabled'] ) + && ! empty( self::$options['disabled_on_conditions']['queryvar']['enabled'] ) + && ! empty( $_GET[ self::$options['disabled_on_conditions']['queryvar']['value'] ] ) ) ); @@ -534,7 +534,7 @@ static function admin_page() {

%1$s: %2$s', __( 'Dependency Minification', 'depmin' ), sprintf( @@ -217,6 +216,7 @@ static function admin_notices() { __( 'Permalinks Settings', 'depmin' ) ) ) + ) ); ?>

@@ -239,19 +239,23 @@ static function admin_notices() {

- +

@@ -296,21 +300,21 @@ static function admin_ajax_options_handler() { if ( ! current_user_can( self::$options['admin_page_capability'] ) ) { wp_die( __( 'You are not allowed to do that.', 'depmin' ) ); } - if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], self::AJAX_OPTIONS_ACTION ) ) { + if ( ! wp_verify_nonce( $_POST['_wpnonce'], self::AJAX_OPTIONS_ACTION ) ) { wp_die( __( 'Nonce check failed. Try reloading the previous page.', 'depmin' ) ); } $updated_count = 0; - if ( ! empty( $_REQUEST['options'] ) ) { + if ( ! empty( $_POST['options'] ) ) { $options = get_option( 'dependency_minification_options' ); - $options['exclude_dependencies'] = array_filter( preg_split( "#[\n\r]+#", $_REQUEST['options']['exclude_dependencies'] ) ); - $options['disabled_on_conditions'] = $_REQUEST['options']['disabled_on_conditions']; - $options['default_exclude_remote_dependencies'] = isset( $_REQUEST['options']['default_exclude_remote_dependencies'] ); + $options['exclude_dependencies'] = array_filter( preg_split( "#[\n\r]+#", $_POST['options']['exclude_dependencies'] ) ); + $options['disabled_on_conditions'] = $_POST['options']['disabled_on_conditions']; + $options['default_exclude_remote_dependencies'] = isset( $_POST['options']['default_exclude_remote_dependencies'] ); update_option( 'dependency_minification_options', $options ); } - $redirect_url = add_query_arg( 'page', self::ADMIN_PAGE_SLUG, admin_url( self::ADMIN_PARENT_PAGE ) ); - $redirect_url = add_query_arg( 'updated', 1, $redirect_url ); - $redirect_url.= '#tab-settings'; + $redirect_url = add_query_arg( 'page', self::ADMIN_PAGE_SLUG, admin_url( self::ADMIN_PARENT_PAGE ) ); + $redirect_url = add_query_arg( 'updated', 1, $redirect_url ); + $redirect_url .= '#tab-settings'; wp_redirect( $redirect_url ); die(); @@ -335,7 +339,7 @@ static function admin_page() { $nonce = wp_create_nonce( self::AJAX_ACTION ); ?>
-

+