Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/plugin-dev-lib' into issue-482
Browse files Browse the repository at this point in the history
Conflicts:
	includes/extensions.php
  • Loading branch information
Luke Carbis committed May 1, 2014
2 parents ee0636e + 84d1b6f commit fd9b301
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 126 deletions.
5 changes: 5 additions & 0 deletions .ci-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export PHPCS_GITHUB_SRC=x-team/PHP_CodeSniffer
export PHPCS_GIT_TREE=subset-selection
export WPCS_GIT_TREE=rule-subset-with-phpcs-pr
export WPCS_STANDARD=WordPress:core-extra
export PHPCS_IGNORE='tests/*,includes/vendor/*'
21 changes: 13 additions & 8 deletions bin/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,29 @@ node_js:
- 0.10

env:
- WP_VERSION=master WP_MULTISITE=0
- WP_VERSION=master WP_MULTISITE=1
- WP_VERSION=latest WP_MULTISITE=0
- WP_VERSION=latest WP_MULTISITE=1
- WP_VERSION=3.8 WP_MULTISITE=0
- WP_VERSION=3.8 WP_MULTISITE=1

before_script:
- export WP_TESTS_DIR=/tmp/wordpress-tests/
- export PLUGIN_DIR=$(pwd)
- export PLUGIN_SLUG=$(basename $(pwd) | sed 's/^wp-//')
- if [ -e phpunit.xml ] || [ -e phpunit.xml.dist ]; then bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION; cd /tmp/wordpress/wp-content/plugins; ln -s $PLUGIN_DIR $PLUGIN_SLUG; cd $PLUGIN_DIR; 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
- export PHPCS_DIR=/tmp/phpcs
- export PHPCS_GITHUB_SRC=squizlabs/PHP_CodeSniffer
- export PHPCS_GIT_TREE=master
- export WPCS_GITHUB_SRC=WordPress-Coding-Standards/WordPress-Coding-Standards
- export WPCS_GIT_TREE=master
- export WPCS_STANDARD=$(if [ -e phpcs.ruleset.xml ]; then echo phpcs.ruleset.xml; else echo WordPress; fi)
- if [ -e .ci-env.sh ]; then source .ci-env.sh; fi
- if [ -e phpunit.xml ] || [ -e phpunit.xml.dist ]; then wget -O /tmp/install-wp-tests.sh https://raw.githubusercontent.com/wp-cli/wp-cli/master/templates/install-wp-tests.sh; bash /tmp/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION; cd /tmp/wordpress/wp-content/plugins; ln -s $PLUGIN_DIR $PLUGIN_SLUG; cd $PLUGIN_DIR; fi
- mkdir -p $PHPCS_DIR && curl -L https://github.com/$PHPCS_GITHUB_SRC/archive/$PHPCS_GIT_TREE.tar.gz | tar xvz --strip-components=1 -C $PHPCS_DIR
- mkdir -p $PHPCS_DIR/CodeSniffer/Standards/WordPress && curl -L https://github.com/$WPCS_GITHUB_SRC/archive/$WPCS_GIT_TREE.tar.gz | tar xvz --strip-components=1 -C $PHPCS_DIR/CodeSniffer/Standards/WordPress
- npm install -g jshint

script:
- find . -path ./bin -prune -o \( -name '*.php' -o -name '*.inc' \) -exec php -lf {} \;
- if [ -e phpunit.xml ] || [ -e phpunit.xml.dist ]; then phpunit; fi
- phpcs --standard=$(if [ -e phpcs.ruleset.xml ]; then echo phpcs.ruleset.xml; else echo WordPress; fi) $(find . -name '*.php')
- $PHPCS_DIR/scripts/phpcs --standard=$WPCS_STANDARD $(if [ -n "$PHPCS_IGNORE" ]; then echo --ignore=$PHPCS_IGNORE; fi) $(find . -name '*.php')
- jshint .
6 changes: 3 additions & 3 deletions bin/class-wordpress-readme-parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function __construct( $args = array() ) {
throw new Exception( "Parse error in $metadatum" );
}
list( $name, $value ) = array_slice( $metadataum_matches, 1, 2 );
$this->metadata[$name] = $value;
$this->metadata[ $name ] = $value;
}
$this->metadata['Contributors'] = preg_split( '/\s*,\s*/', $this->metadata['Contributors'] );
$this->metadata['Tags'] = preg_split( '/\s*,\s*/', $this->metadata['Tags'] );
Expand Down Expand Up @@ -181,8 +181,8 @@ function ( $tag ) {
$body = $section['body'];

$body = call_user_func( $general_section_formatter, $body );
if ( isset( $section_formatters[$section['heading']] ) ) {
$body = trim( call_user_func( $section_formatters[$section['heading']], $body ) );
if ( isset( $section_formatters[ $section['heading'] ] ) ) {
$body = trim( call_user_func( $section_formatters[ $section['heading'] ], $body ) );
}

if ( $body ) {
Expand Down
65 changes: 0 additions & 65 deletions bin/install-wp-tests.sh

This file was deleted.

35 changes: 30 additions & 5 deletions bin/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

set -e

WPCS_STANDARD=$(if [ -e phpcs.ruleset.xml ]; then echo phpcs.ruleset.xml; else echo WordPress; fi)
if [ -e .ci-env.sh ]; then
source .ci-env.sh
fi

message="Checking staged changes..."
git_status_egrep='^[MARC].+'

Expand Down Expand Up @@ -44,9 +49,30 @@ if [ ${#staged_php_files[@]} != 0 ]; then
# 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
if [ "$USER" != 'vagrant' ]; then

# Check if we're in VVV
plugin_dir=$(pwd)
while [ ! -e Vagrantfile ]; do
if [ $(pwd) == '/' ] || [ "$last_dir" == $(pwd) ]; then
break
fi
last_dir=$(pwd)
cd ..
done
if [ -e Vagrantfile ] && grep -q vvv Vagrantfile; then
vvv_root=$(pwd)
absolute_vvv_plugin_path=/srv${plugin_dir:${#vvv_root}}
fi
cd $plugin_dir

if [ ! -z "$absolute_vvv_plugin_path" ]; then
echo "Running phpunit in VVV"
vagrant ssh -c "cd $absolute_vvv_plugin_path && phpunit"
elif command -v vassh >/dev/null 2>&1; then
echo "Running phpunit in vagrant via vassh..."
vassh phpunit
fi
elif ! command -v phpunit >/dev/null 2>&1;then
echo "Skipping phpunit since not installed"
elif [ -z "$WP_TESTS_DIR" ]; then
Expand All @@ -59,8 +85,7 @@ if [ ${#staged_php_files[@]} != 0 ]; then
# PHP_CodeSniffer WordPress Coding Standards
echo "## phpcs"
if command -v phpcs >/dev/null 2>&1; then
phpcs_standard=$(if [ -e phpcs.ruleset.xml ]; then echo phpcs.ruleset.xml; else echo WordPress; fi)
phpcs -p -s -v --standard=$phpcs_standard "${staged_php_files[@]}"
phpcs -p -s -v --standard=$WPCS_STANDARD $(if [ -n "$PHPCS_IGNORE" ]; then echo --ignore=$PHPCS_IGNORE; fi) "${staged_php_files[@]}"
else
echo "Skipping phpcs since not installed"
fi
Expand Down
11 changes: 11 additions & 0 deletions bin/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ cd .git/hooks
ln -s ../../bin/pre-commit .
```

You may customize the behavior of the `.travis.yml` and `pre-commit` hook by
specifying a `.ci-env.sh` in the root of the repo, for example:

```bash
export PHPCS_GITHUB_SRC=x-team/PHP_CodeSniffer
export PHPCS_GIT_TREE=subset-selection
export WPCS_GIT_TREE=rule-subset-with-phpcs-pr
export WPCS_STANDARD=WordPress:core-extra
export PHPCS_IGNORE='tests/*,includes/vendor/*'
```

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
Expand Down
6 changes: 4 additions & 2 deletions connectors/menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static function action_links( $links, $record ) {
$menu_ids = wp_list_pluck( $menus, 'term_id' );

if ( in_array( $record->object_id, $menu_ids ) ) {
$links[ __( 'Edit Menu', 'stream' ) ] = admin_url( 'nav-menus.php?action=edit&menu=' . $record->object_id );
$links[ __( 'Edit Menu', 'stream' ) ] = admin_url( 'nav-menus.php?action=edit&menu=' . $record->object_id ); // xss ok (@todo fix WPCS rule)
}
}

Expand Down Expand Up @@ -148,7 +148,9 @@ public static function callback_delete_nav_menu( $term, $tt_id, $deleted_term )
*/
public static function callback_update_option_theme_mods( $old, $new ) {
// Disable if we're switching themes
if ( did_action( 'after_switch_theme' ) ) return;
if ( did_action( 'after_switch_theme' ) ) {
return;
}

$key = 'nav_menu_locations';

Expand Down
2 changes: 1 addition & 1 deletion connectors/widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static function action_links( $links, $record ) {
global $wp_registered_sidebars;

if ( array_key_exists( $sidebar, $wp_registered_sidebars ) ) {
$links[ __( 'Edit Widget Area', 'stream' ) ] = admin_url( 'widgets.php#' . $sidebar );
$links[ __( 'Edit Widget Area', 'stream' ) ] = admin_url( 'widgets.php#' . $sidebar ); // xss ok (@todo fix WPCS rule)
}
}

Expand Down
15 changes: 8 additions & 7 deletions includes/extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ class WP_Stream_Extensions {
/**
* @var string|null
*/
var $license_key = NULL;
var $license_key = null;

/**
* @var bool
*/
public static $instance = false;

public static function get_instance() {
if ( ! self::$instance )
if ( ! self::$instance ) {
self::$instance = new self();

}
return self::$instance;
}

Expand Down Expand Up @@ -202,7 +202,7 @@ function get_plugin_paths() {
$plugin_paths = array();
foreach ( get_plugins() as $path => $data ) {
if ( isset( $data['TextDomain'] ) && ! empty( $data['TextDomain'] ) ) {
$plugin_paths[$data['TextDomain']] = $path;
$plugin_paths[ $data['TextDomain'] ] = $path;
}
}
return $plugin_paths;
Expand Down Expand Up @@ -249,12 +249,13 @@ function extensions_display_header( $extensions ) {
* @return void
*/
function extensions_display_body( $extensions ) {
$extensions_url = self::API_TRANSPORT . self::API_DOMAIN . '/#extensions' . $this->get_affiliate();
if ( empty( $extensions ) ) { ?>
<h2><?php _e( 'Stream Extensions', 'stream' ) ?></h2>
<p>
<em><?php esc_html_e( 'Sorry, there was a problem loading the list of extensions.', 'stream' ) ?></em></p>
<p>
<a class="button button-primary" href="<?php echo esc_url( self::API_TRANSPORT . self::API_DOMAIN . '/#extensions' . $this->get_affiliate() ) ?>" target="_blank"><?php esc_html_e( 'Browse All Extensions', 'stream' ) ?></a>
<a class="button button-primary" href="<?php echo esc_url( $extensions_url ) ?>" target="_blank"><?php esc_html_e( 'Browse All Extensions', 'stream' ) ?></a>
</p>
<?php
return;
Expand Down Expand Up @@ -365,8 +366,8 @@ function prepare_extensions_for_js( $extensions ) {
'activate18n' => __( 'Activate', 'stream' ),
'active18n' => __( 'Active', 'stream' ),
'actions' => array(
'activate' => wp_nonce_url( add_query_arg( array( 'action' => 'activate', 'plugin' => $extension->post_meta->plugin_path[0], 'plugin_status' => 'all', 'paged' => '1' ), self_admin_url( 'plugins.php' ) ), 'activate-plugin_' . $extension->post_meta->plugin_path[0] ),
'install' => wp_nonce_url( add_query_arg( array( 'action' => 'install-plugin', 'plugin' => $extension->slug ), self_admin_url( 'update.php' ) ), 'install-plugin_' . $extension->slug ),
'activate' => wp_nonce_url( add_query_arg( array( 'action' => 'activate', 'plugin' => $extension->post_meta->plugin_path[0], 'plugin_status' => 'all', 'paged' => '1' ), self_admin_url( 'plugins.php' ) ), 'activate-plugin_' . $extension->post_meta->plugin_path[0] ), // xss ok (todo fix WPCS sniff)
'install' => wp_nonce_url( add_query_arg( array( 'action' => 'install-plugin', 'plugin' => $extension->slug ), self_admin_url( 'update.php' ) ), 'install-plugin_' . $extension->slug ), // xss ok (todo fix WPCS sniff)
'delete' => null,
),
);
Expand Down
4 changes: 2 additions & 2 deletions includes/feeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ public static function feed_template() {
$die_title = esc_html__( 'Access Denied', 'stream' );
$die_message = '<h1>' . $die_title .'</h1><p>' . esc_html__( 'You don\'t have permission to view this feed, please contact your site Administrator.', 'stream' ) . '</p>';

if ( ! isset( $_GET[self::FEED_QUERY_VAR] ) || empty( $_GET[self::FEED_QUERY_VAR] ) ) {
if ( ! isset( $_GET[ self::FEED_QUERY_VAR ] ) || empty( $_GET[ self::FEED_QUERY_VAR ] ) ) {
wp_die( $die_message, $die_title );
}

$args = array(
'meta_key' => self::USER_FEED_KEY,
'meta_value' => $_GET[self::FEED_QUERY_VAR],
'meta_value' => $_GET[ self::FEED_QUERY_VAR ],
'number' => 1,
);
$user = get_users( $args );
Expand Down
2 changes: 2 additions & 0 deletions includes/filter-input.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ public static function filter( $var, $filter = null, $options = array() ) {
}

public static function is_regex( $var ) {
// @codingStandardsIgnoreStart
$test = @preg_match( $var, '' );
// @codingStandardsIgnoreEnd

return $test !== false;
}
Expand Down
5 changes: 2 additions & 3 deletions includes/list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ function column_link( $display, $key, $value = null, $title = null ) {
}

public function get_term_title( $term, $type ) {
if ( isset( WP_Stream_Connectors::$term_labels["stream_$type"][ $term ] ) ) {
return WP_Stream_Connectors::$term_labels["stream_$type"][ $term ];
if ( isset( WP_Stream_Connectors::$term_labels[ "stream_$type" ][ $term ] ) ) {
return WP_Stream_Connectors::$term_labels[ "stream_$type" ][ $term ];
}
else {
return $term;
Expand Down Expand Up @@ -557,7 +557,6 @@ public function get_filters() {
'items' => $this->assemble_records( 'action' ),
);


/**
* Filter allows additional filters in the list table dropdowns
* Note the format of the filters above, with they key and array
Expand Down
6 changes: 3 additions & 3 deletions includes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ public static function render_field( $field ) {
$output .= '</fieldset></div>';
break;
case 'select':
$current_value = (array) self::$options[$section . '_' . $name];
$current_value = (array) self::$options[ $section . '_' . $name ];
$default_value = isset( $default['value'] ) ? $default['value'] : '-1';
$default_name = isset( $default['name'] ) ? $default['name'] : 'Choose Setting';

Expand Down Expand Up @@ -831,8 +831,8 @@ public static function get_default_connectors() {
*/
public static function get_terms_labels( $column ) {
$return_labels = array();
if ( isset ( WP_Stream_Connectors::$term_labels['stream_' . $column ] ) ) {
$return_labels = WP_Stream_Connectors::$term_labels['stream_' . $column ];
if ( isset ( WP_Stream_Connectors::$term_labels[ 'stream_' . $column ] ) ) {
$return_labels = WP_Stream_Connectors::$term_labels[ 'stream_' . $column ];
ksort( $return_labels );
}

Expand Down
Loading

0 comments on commit fd9b301

Please sign in to comment.