Skip to content

Commit 496c2ca

Browse files
Merge branch 'master' into bugfix-empty-repeatable-multiselect
2 parents 223fd1d + 915af49 commit 496c2ca

23 files changed

+501
-77
lines changed

.editorconfig

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
# WordPress Coding Standards
5+
# http://make.wordpress.org/core/handbook/coding-standards/
6+
7+
root = true
8+
9+
[*]
10+
charset = utf-8
11+
end_of_line = lf
12+
insert_final_newline = true
13+
trim_trailing_whitespace = true
14+
indent_style = tab
15+
indent_size = 4
16+
17+
[*.json,*.yml,*.feature]
18+
indent_style = space
19+
indent_size = 2

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ todo.txt
1919
/report/
2020

2121
.svn
22+
23+
composer.lock
24+
/vendor/
25+
/node_modules

.travis.yml

+38-35
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,48 @@ sudo: false
22

33
language: php
44

5-
php:
6-
- 5.3
7-
- 5.4
8-
- 5.5
9-
- 5.6
10-
11-
env:
12-
- WP_VERSION=master WP_MULTISITE=0
13-
- WP_VERSION=master WP_MULTISITE=1
14-
- WP_VERSION=4.4 WP_MULTISITE=0
15-
- WP_VERSION=4.4 WP_MULTISITE=1
16-
- WP_VERSION=4.3 WP_MULTISITE=0
17-
- WP_VERSION=4.3 WP_MULTISITE=1
18-
195
matrix:
20-
include:
21-
- php: 7.0
22-
env: WP_VERSION=master
23-
allow_failures:
24-
- php: 7.0
25-
fast_finish: true
6+
include:
7+
- php: 5.3
8+
env: WP_VERSION=4.3.3
9+
- php: 5.3
10+
env: WP_VERSION=latest
11+
- php: 5.6
12+
env: WP_VERSION=latest
13+
- php: 7.0
14+
env: WP_VERSION=latest
15+
- php: 5.6
16+
env: WP_VERSION=nightly
17+
- php: 5.6
18+
env: WP_TRAVISCI=phpcs
19+
allow_failures:
20+
- php: 7.0
21+
fast_finish: true
2622

2723
branches:
28-
only:
29-
- master
24+
only:
25+
- master
3026

3127
before_script:
32-
- export WP_TESTS_DIR=/tmp/wordpress/tests/phpunit
33-
- export WP_CORE_DIR=/tmp/wordpress/src/
34-
- git clone --depth=50 --branch="$WP_VERSION" git://develop.git.wordpress.org/ /tmp/wordpress
35-
- mysql -e "CREATE DATABASE wordpress_tests;" -uroot
36-
- cp /tmp/wordpress/wp-tests-config-sample.php /tmp/wordpress/wp-tests-config.php
37-
- sed -i "s/youremptytestdbnamehere/wordpress_tests/" /tmp/wordpress/wp-tests-config.php
38-
- sed -i "s/yourusernamehere/travis/" /tmp/wordpress/wp-tests-config.php
39-
- sed -i "s/yourpasswordhere//" /tmp/wordpress/wp-tests-config.php
40-
- npm install -g npm
41-
- npm install -g grunt-cli
42-
- npm install
28+
- |
29+
if [[ ! -z "$WP_VERSION" ]] ; then
30+
bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
31+
npm install
32+
fi
33+
- |
34+
if [[ "$WP_TRAVISCI" == "phpcs" ]] ; then
35+
npm install
36+
composer install
37+
fi
4338
4439
script:
45-
- phpunit
46-
- grunt qunit:specific --wp=$WP_VERSION
40+
- |
41+
if [[ ! -z "$WP_VERSION" ]] ; then
42+
phpunit
43+
phpunit -c multisite.xml
44+
grunt qunit:specific --wp=$WP_VERSION
45+
fi
46+
- |
47+
if [[ "$WP_TRAVISCI" == "phpcs" ]] ; then
48+
grunt phpcs
49+
fi

Gruntfile.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,22 @@ module.exports = function( grunt ) {
3434
urls: [ 'http://localhost:8000/tests/js/index.html?wp=' + grunt.option( 'wp' ) ]
3535
}
3636
}
37-
}
37+
},
38+
phpcs: {
39+
plugin: {
40+
src: './'
41+
},
42+
options: {
43+
bin: "vendor/bin/phpcs --extensions=php --ignore=\"*/vendor/*,*/node_modules/*,/*\"",
44+
standard: "phpcs.ruleset.xml"
45+
}
46+
},
3847
});
3948

49+
4050
grunt.loadNpmTasks( 'grunt-contrib-connect' );
4151
grunt.loadNpmTasks( 'grunt-contrib-qunit' );
52+
grunt.loadNpmTasks( 'grunt-phpcs' );
4253

4354
grunt.task.run( 'connect' );
4455

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# Fieldmanager <img align="right" src="https://travis-ci.org/alleyinteractive/wordpress-fieldmanager.png?branch=master" alt="Travis CI Build Status" />
1+
# Fieldmanager
22

33
Fieldmanager is a comprehensive toolkit for building forms, metaboxes, and custom admin screens for WordPress.
44

5+
[![Build Status](https://travis-ci.org/alleyinteractive/wordpress-fieldmanager.svg?branch=master)](https://travis-ci.org/alleyinteractive/wordpress-fieldmanager)
6+
57
## Using Fieldmanager in your WordPress Project
68

79
Fieldmanager is a powerful library which can make the development of sophisticated features a breeze. To get started, simply [download](#downloads-and-versioning) and install this plugin into your plugins directory and activate it on the plugins screen. To learn how to use Fieldmanager's API, visit the project's official website at [Fieldmanager.org](http://fieldmanager.org). There is also [a demo plugin](https://github.com/alleyinteractive/fieldmanager-demos) which illustrates a lot of what you can do with Fieldmanager.
@@ -26,4 +28,4 @@ apigen -c apigen.neon
2628

2729
## Running QUnit tests
2830

29-
Fieldmanager uses QUnit for JavaScript unit tests. To quickly check the status of the tests, open `/tests/js/index.html` in your browser. You can also run the tests from the command line: Install the dependencies with `npm install`, then use `grunt qunit:latest` to run the tests against WordPress trunk or `grunt qunit:recent` to run the tests against trunk and the last two major releases.
31+
Fieldmanager uses QUnit for JavaScript unit tests. To quickly check the status of the tests, open `/tests/js/index.html` in your browser. You can also run the tests from the command line: Install the dependencies with `npm install`, then use `grunt qunit:latest` to run the tests against WordPress trunk or `grunt qunit:recent` to run the tests against trunk and the last two major releases.

bin/install-wp-tests.sh

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/usr/bin/env bash
2+
3+
if [ $# -lt 3 ]; then
4+
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
5+
exit 1
6+
fi
7+
8+
DB_NAME=$1
9+
DB_USER=$2
10+
DB_PASS=$3
11+
DB_HOST=${4-localhost}
12+
WP_VERSION=${5-latest}
13+
14+
WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
15+
WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}
16+
17+
download() {
18+
if [ `which curl` ]; then
19+
curl -s "$1" > "$2";
20+
elif [ `which wget` ]; then
21+
wget -nv -O "$2" "$1"
22+
fi
23+
}
24+
25+
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then
26+
WP_TESTS_TAG="tags/$WP_VERSION"
27+
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
28+
WP_TESTS_TAG="trunk"
29+
else
30+
# http serves a single offer, whereas https serves multiple. we only want one
31+
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
32+
grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
33+
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
34+
if [[ -z "$LATEST_VERSION" ]]; then
35+
echo "Latest WordPress version could not be found"
36+
exit 1
37+
fi
38+
WP_TESTS_TAG="tags/$LATEST_VERSION"
39+
fi
40+
41+
set -ex
42+
43+
install_wp() {
44+
45+
if [ -d $WP_CORE_DIR ]; then
46+
return;
47+
fi
48+
49+
mkdir -p $WP_CORE_DIR
50+
51+
if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
52+
mkdir -p /tmp/wordpress-nightly
53+
download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip
54+
unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/
55+
mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR
56+
else
57+
if [ $WP_VERSION == 'latest' ]; then
58+
local ARCHIVE_NAME='latest'
59+
else
60+
local ARCHIVE_NAME="wordpress-$WP_VERSION"
61+
fi
62+
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
63+
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
64+
fi
65+
66+
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
67+
}
68+
69+
install_test_suite() {
70+
# portable in-place argument for both GNU sed and Mac OSX sed
71+
if [[ $(uname -s) == 'Darwin' ]]; then
72+
local ioption='-i .bak'
73+
else
74+
local ioption='-i'
75+
fi
76+
77+
# set up testing suite if it doesn't yet exist
78+
if [ ! -d $WP_TESTS_DIR ]; then
79+
# set up testing suite
80+
mkdir -p $WP_TESTS_DIR
81+
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
82+
fi
83+
84+
cd $WP_TESTS_DIR
85+
86+
if [ ! -f wp-tests-config.php ]; then
87+
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
88+
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" "$WP_TESTS_DIR"/wp-tests-config.php
89+
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
90+
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
91+
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
92+
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
93+
fi
94+
95+
}
96+
97+
install_db() {
98+
# parse DB_HOST for port or socket references
99+
local PARTS=(${DB_HOST//\:/ })
100+
local DB_HOSTNAME=${PARTS[0]};
101+
local DB_SOCK_OR_PORT=${PARTS[1]};
102+
local EXTRA=""
103+
104+
if ! [ -z $DB_HOSTNAME ] ; then
105+
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
106+
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
107+
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
108+
EXTRA=" --socket=$DB_SOCK_OR_PORT"
109+
elif ! [ -z $DB_HOSTNAME ] ; then
110+
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
111+
fi
112+
fi
113+
114+
# create database
115+
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
116+
}
117+
118+
install_wp
119+
install_test_suite
120+
install_db

composer.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "alleyinteractive/wordpress-fieldmanager",
3+
"authors": [
4+
{
5+
"name": "Alley Interactive",
6+
"email": "[email protected]"
7+
}
8+
],
9+
"require-dev": {
10+
"squizlabs/php_codesniffer": "2.3.4",
11+
"wp-coding-standards/wpcs": "0.8.0"
12+
},
13+
"scripts": {
14+
"post-install-cmd": "\"vendor/bin/phpcs\" --config-set installed_paths vendor/wp-coding-standards/wpcs",
15+
"post-update-cmd" : "\"vendor/bin/phpcs\" --config-set installed_paths vendor/wp-coding-standards/wpcs"
16+
}
17+
}

css/fieldmanager.css

-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ div.fm-group-label-wrapper .fmjs-remove {
328328
background: #fff;
329329
height: 100px;
330330
width: 600px;
331-
border: solid 1px #444;
332331
padding: 5px;
333332
margin: 10px 0;
334333
}

fieldmanager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function fieldmanager_load_file( $file ) {
101101
*/
102102
function fieldmanager_enqueue_scripts() {
103103
wp_enqueue_script( 'fieldmanager_script', fieldmanager_get_baseurl() . 'js/fieldmanager.js', array( 'jquery' ), '1.0.7' );
104-
wp_enqueue_style( 'fieldmanager_style', fieldmanager_get_baseurl() . 'css/fieldmanager.css', array(), '1.0.3' );
104+
wp_enqueue_style( 'fieldmanager_style', fieldmanager_get_baseurl() . 'css/fieldmanager.css', array(), '1.0.4' );
105105
wp_enqueue_script( 'jquery-ui-sortable' );
106106
}
107107
add_action( 'admin_enqueue_scripts', 'fieldmanager_enqueue_scripts' );

multisite.xml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<phpunit
2+
bootstrap="tests/php/bootstrap.php"
3+
backupGlobals="false"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
>
9+
<php>
10+
<const name="WP_TESTS_MULTISITE" value="1" />
11+
</php>
12+
<testsuites>
13+
<testsuite>
14+
<directory prefix="test-" suffix=".php">tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
</phpunit>

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"devDependencies": {
1111
"grunt": "^0.4.5",
1212
"grunt-contrib-connect": "~0.11.0",
13-
"grunt-contrib-qunit": "~0.7.0"
13+
"grunt-contrib-qunit": "~0.7.0",
14+
"grunt-phpcs": "^0.4.0"
1415
}
15-
}
16+
}

php/class-fieldmanager-autocomplete.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,14 @@ public function form_element( $value = Null ) {
146146
* @param array $current_values existing post values
147147
*/
148148
public function presave_alter_values( $values, $current_values = array() ) {
149-
// return if there are no saved values, if this isn't a post, or if the reciprocal relationship isn't set.
150-
if ( empty( $this->data_id ) || $this->data_type !== 'post' ) return $values;
149+
// return if there is no data id
150+
if ( empty( $this->data_id ) ) {
151+
return $values;
152+
}
153+
154+
if ( ! empty( $this->datasource->only_save_to_taxonomy ) ) {
155+
$this->skip_save = true;
156+
}
151157
return $this->datasource->presave_alter_values( $this, $values, $current_values );
152158
}
153159

0 commit comments

Comments
 (0)