├── .babelrc
├── .editorconfig
├── .eslintrc.js
├── .gitignore
├── .sass-lint.yml
├── .travis.yml
├── CHANGELOG.md
├── Gulpfile.js
├── LICENSE
├── README.md
├── advanced-custom-fields-auto-json-sync.php
├── bin
├── index.php
└── install-wp-tests.sh
├── gulp-tasks
├── bump.js
├── imagemin.js
├── index.php
├── pot.js
├── scripts.js
├── styles.js
└── watch.js
├── includes
├── class-directory-structure.php
├── class-update-field-groups.php
└── index.php
├── index.php
├── languages
├── afc-ajs.pot
└── index.php
├── package.json
├── phpcs.xml
├── phpmd.xml
├── phpunit.xml
└── tests
├── base.php
├── bootstrap.php
├── index.php
├── test-advanced-custom-fields-auto-json-sync.php
├── test-class-directory-strucure.php
└── test-class-update-filed-groups.php
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["es2015"]
3 | }
4 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig is awesome: http://EditorConfig.org
2 |
3 | # top-most EditorConfig file
4 | root = true
5 |
6 | # Unix-style newlines with a newline ending every file
7 | [*]
8 | end_of_line = lf
9 | insert_final_newline = true
10 |
11 | # Matches multiple files with brace expansion notation
12 | # Set default charset
13 | [*.{html,js,php,css,scss}]
14 | charset = utf-8
15 |
16 | # 4 space indentation
17 | [*.{html,js,php,css,scss}]
18 | indent_style = tab
19 | indent_size = 2
20 |
21 | # Matches the exact files
22 | [{package.json,bower.json,.bowerrc,.eslintrc.js,.travis.yml,.sass-lint.yml,phpcs.xml}]
23 | indent_style = space
24 | indent_size = 2
25 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | "env": {
3 | "browser": true,
4 | "jquery": true,
5 | "es6": true,
6 | },
7 | "extends": "wordpress",
8 | "installedESLint": true,
9 | "plugins": [],
10 | "rules": {
11 | // Enforce spacing inside array brackets
12 | 'array-bracket-spacing': ['error', 'always'],
13 | // Enforce one true brace style
14 | 'brace-style': 'error',
15 | // Require camel case names
16 | 'camelcase': ['error', {
17 | properties: 'always'
18 | }],
19 | // Disallow or enforce trailing commas
20 | 'comma-dangle': ['error', 'never'],
21 | // Enforce spacing before and after comma
22 | 'comma-spacing': 'error',
23 | // Enforce one true comma style
24 | 'comma-style': ['error', 'last'],
25 | // Encourages use of dot notation whenever possible
26 | 'dot-notation': ['error', {
27 | allowKeywords: true,
28 | allowPattern: '^[a-z]+(_[a-z]+)+$'
29 | }],
30 | // Enforce newline at the end of file, with no multiple empty lines
31 | 'eol-last': 'error',
32 | // Require or disallow spacing between function identifiers and their invocations
33 | 'func-call-spacing': 'off',
34 | // Enforces spacing between keys and values in object literal properties
35 | 'key-spacing': ['error', {
36 | beforeColon: false,
37 | afterColon: true
38 | }],
39 | // Enforce spacing before and after keywords
40 | 'keyword-spacing': 'error',
41 | // Disallow mixed "LF" and "CRLF" as linebreaks
42 | 'linebreak-style': ['error', 'unix'],
43 | // Enforces empty lines around comments
44 | 'lines-around-comment': ['error', {
45 | beforeLineComment: true
46 | }],
47 | // Disallow mixed spaces and tabs for indentation
48 | 'no-mixed-spaces-and-tabs': 'error',
49 | // Disallow use of multiline strings
50 | 'no-multi-str': 'error',
51 | // Disallow multiple empty lines
52 | 'no-multiple-empty-lines': 'error',
53 | // Disallow use of the with statement
54 | 'no-with': 'error',
55 | // Require or disallow an newline around variable declarations
56 | 'one-var-declaration-per-line': ['error', 'initializations'],
57 | // Enforce operators to be placed before or after line breaks
58 | 'operator-linebreak': ['error', 'after'],
59 | // Require or disallow use of semicolons instead of ASI
60 | 'semi': ['error', 'always'],
61 | // Require or disallow space before blocks
62 | 'space-before-blocks': ['error', 'always'],
63 | // Require or disallow space before function opening parenthesis
64 | 'space-before-function-paren': ['error', 'never'],
65 | // Require or disallow space before blocks
66 | 'space-in-parens': ['error', 'always', { 'exceptions': ['{}', '[]'] }],
67 | // Require spaces around operators
68 | 'space-infix-ops': 'error',
69 | // Require or disallow spaces before/after unary operators (words on by default, nonwords)
70 | 'space-unary-ops': ['error', {
71 | overrides: {'!': true}
72 | }],
73 | // Requires to declare all vars on top of their containing scope
74 | 'vars-on-top': 'error',
75 | // Require or disallow Yoda conditions. Yoda should only be used on equality checks.
76 | 'yoda': ['error', 'never', { 'onlyEquality': true }]
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Node/npm
2 | node_modules/
3 | npm-debug.log
4 | .grunt
5 | .sass-cache
6 |
7 | # OSX
8 | .DS_Store
9 | .AppleDouble
10 | .LSOverride
11 | .Spotlight-V100
12 | .Trashes
13 | .AppleDB
14 | .AppleDesktop
15 | Network Trash Folder
16 | Temporary Items
17 | .apdisk
18 |
19 | # Icon must end with two \r
20 | Icon
21 |
22 | # Thumbnails
23 | ._*
24 |
25 | # Vim
26 | [._]*.s[a-w][a-z]
27 | [._]s[a-w][a-z]
28 | *.un~
29 | Session.vim
30 | .netrwhist
31 | *~
32 |
33 | ### Bower ###
34 | bower_components
35 | .bower-cache
36 | .bower-registry
37 | .bower-tmp
38 |
39 | # Logs
40 | logs
41 | *.log
42 |
43 | # Runtime data
44 | pids
45 | *.pid
46 | *.seed
47 |
48 | # Directory for instrumented libs generated by jscoverage/JSCover
49 | lib-cov
50 |
51 | # Coverage directory used by tools like istanbul
52 | coverage
53 |
54 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
55 | .grunt
56 |
57 | # node-waf configuration
58 | .lock-wscript
59 |
60 | # Compiled binary addons (http://nodejs.org/api/addons.html)
61 | build/Release
62 |
63 | !LICENSE
64 |
--------------------------------------------------------------------------------
/.sass-lint.yml:
--------------------------------------------------------------------------------
1 | # See: https://github.com/sasstools/sass-lint/tree/master/docs
2 | # Rule Options
3 | options:
4 | formatter: stylish
5 | # Don't merge default rules
6 | merge-default-rules: false
7 | max-warnings: 50
8 |
9 | # Files
10 | files:
11 | include: '**/*.s+(a|c)ss'
12 |
13 | # Rule Configuration
14 | rules:
15 |
16 | # Extends
17 | extends-before-mixins: 1
18 | extends-before-declarations: 1
19 | placeholder-in-extend: 0
20 |
21 | # Mixins
22 | mixins-before-declarations: 1
23 |
24 | # Line Spacing
25 | one-declaration-per-line: 1
26 | empty-line-between-blocks:
27 | - 1
28 | -
29 | allow-single-line-rulesets: false
30 | single-line-per-selector: 1
31 |
32 | # Disallows
33 | no-attribute-selectors: 0
34 | no-color-hex: 0
35 | no-color-keywords: 1
36 | no-color-literals:
37 | - 1
38 | -
39 | allow-rgba: true
40 | no-combinators: 0
41 | no-css-comments: 1
42 | no-debug: 1
43 | no-disallowed-properties: 0
44 | no-duplicate-properties: 1
45 | no-empty-rulesets: 1
46 | no-extends: 0
47 | no-ids: 1
48 | no-important: 1
49 | no-invalid-hex: 1
50 | no-mergeable-selectors: 1
51 | no-misspelled-properties:
52 | - 1
53 | -
54 | 'extra-properties':
55 | - 'overflow-scrolling'
56 | no-qualifying-elements:
57 | - 1
58 | -
59 | allow-element-with-attribute: true
60 | no-trailing-whitespace: 1
61 | no-trailing-zero: 1
62 | no-transition-all: 1
63 | no-universal-selectors: 0
64 | no-url-domains: 1
65 | no-url-protocols: 1
66 | no-vendor-prefixes: 1
67 | no-warn: 1
68 | property-units:
69 | - 1
70 | -
71 | per-property: { width: ['rem', 'vw'], height: ['rem', 'vh'], margin: ['rem'], padding: ['rem'] }
72 |
73 | # Nesting
74 | declarations-before-nesting: 1
75 | force-attribute-nesting: 0
76 | force-element-nesting: 0
77 | force-pseudo-nesting: 0
78 |
79 | # Name Formats
80 | class-name-format:
81 | - 1
82 | -
83 | convention: 'hyphenatedbem'
84 | function-name-format:
85 | - 1
86 | -
87 | convention: 'hyphenatedlowercase'
88 | allow-leading-underscore: true
89 | id-name-format:
90 | - 1
91 | -
92 | allow-leading-underscore: false
93 | convention: hyphenatedlowercase
94 | mixin-name-format:
95 | - 1
96 | -
97 | convention: 'hyphenatedlowercase'
98 | allow-leading-underscore: true
99 | placeholder-name-format:
100 | - 1
101 | -
102 | convention: 'hyphenatedbem'
103 | allow-leading-underscore: true
104 | variable-name-format:
105 | - 1
106 | -
107 | convention: 'hyphenatedlowercase'
108 | allow-leading-underscore: true
109 |
110 | # Style Guide
111 | attribute-quotes: 1
112 | bem-depth: 0
113 | border-zero:
114 | - 1
115 | - convention: 'none' # border: 0; will set border-width: 0; while border: none; will set border-style: none;
116 | brace-style: #
117 | - 1
118 | - style: '1tbs'
119 | allow-single-line: false
120 | clean-import-paths: 0
121 | empty-args: 1
122 | hex-length:
123 | - 1
124 | - style: long
125 | hex-notation:
126 | - 1
127 | - style: uppercase
128 | indentation:
129 | - 1
130 | - size: 2
131 | leading-zero: 1
132 | max-line-length:
133 | - 1
134 | - length: 80
135 | max-file-line-count: 0
136 | nesting-depth:
137 | - 1
138 | - max-depth: 2
139 | property-sort-order: 1
140 | pseudo-element: 1
141 | quotes:
142 | - 1
143 | -
144 | style: double
145 | shorthand-values:
146 | - 1
147 | -
148 | allowed-shorthands:
149 | - 1
150 | - 2
151 | url-quotes: 1
152 | variable-for-property:
153 | - 1
154 | -
155 | properties: ['color']
156 | zero-unit: 0
157 |
158 | # Inner Spacing
159 | space-after-comma: 1
160 | space-before-colon: 0
161 | space-after-colon: 1
162 | space-before-brace: 1
163 | space-before-bang: 1
164 | space-after-bang: 0
165 | space-between-parens: 1
166 | space-around-operator: 1
167 |
168 | # Final Items
169 | trailing-semicolon: 1
170 | final-newline: 1
171 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 | language: php
3 |
4 | notifications:
5 | email:
6 | on_success: never
7 | on_failure: change
8 |
9 | php:
10 | - nightly
11 | - "7.1"
12 | - "7.0"
13 | - "5.6"
14 | - "5.3"
15 |
16 | env:
17 | - WP_PROJECT_TYPE=plugin WP_VERSION=latest WP_MULTISITE=0 WP_TEST_URL=http://localhost:12000 WP_TEST_USER=test WP_TEST_USER_PASS=test
18 |
19 | before_script:
20 | - bash bin/install-wp-tests.sh test root '' localhost $WP_VERSION
21 |
22 | script:
23 | - phpunit
24 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Advanced Custom Fields: Auto JSON Sync Change Log #
2 |
3 | ## 0.2.0 ##
4 | - Added URL check for page refresh
5 | - Replace static JSON directory string with ACF set directories
6 |
7 | ## 0.1.1 ##
8 | - Fixed unwanted Sync indicator display
9 | - Added redirect after field group sync
10 |
11 | ## 0.1.0 ##
12 | - Initial Commit
13 |
--------------------------------------------------------------------------------
/Gulpfile.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Gulp Tasks.
3 | *
4 | * @package Boilderplate
5 | *
6 | * @since 1.0.0
7 | */
8 |
9 | /* global require */
10 | /* eslint no-undef: 0 */
11 | /* eslint no-unused-expressions: 0 */
12 |
13 | var requireDir = require( 'require-dir' );
14 |
15 | // Declare global variables for the gulp tasks.
16 | args = require( 'yargs' ).argv,
17 | autoprefixer = require( 'autoprefixer' );
18 | babel = require( 'gulp-babel' );
19 | bump = require( 'gulp-bump' );
20 | concat = require( 'gulp-concat' );
21 | cssnano = require( 'gulp-cssnano' );
22 | del = require( 'del' );
23 | fs = require( 'fs' );
24 | gulp = require( 'gulp' );
25 | gulpUtil = require( 'gulp-util' );
26 | imagemin = require( 'gulp-imagemin' );
27 | mqpacker = require( 'css-mqpacker' );
28 | notify = require( 'gulp-notify' );
29 | notify = require( 'gulp-notify' );
30 | plumber = require( 'gulp-plumber' );
31 | postcss = require( 'gulp-postcss' );
32 | rename = require( 'gulp-rename' );
33 | replace = require( 'gulp-replace' );
34 | sass = require( 'gulp-sass' );
35 | sassLint = require( 'gulp-sass-lint' );
36 | sort = require( 'gulp-sort' );
37 | sourcemaps = require( 'gulp-sourcemaps' );
38 | wpPot = require( 'gulp-wp-pot' );
39 | uglify = require( 'gulp-uglify' ),
40 | paths = {
41 | 'styles': 'assets/styles',
42 | 'images': 'assets/images',
43 | 'scripts': 'assets/scripts',
44 | 'sass': 'assets/styles/sass'
45 | },
46 | files = {
47 | 'css': paths.styles + '/*.css',
48 | 'cssmin': paths.styles + '/*.min.css',
49 | 'concatScripts': paths.scripts + '/concat/*.js',
50 | 'html': [ './*.html', './**/*.html' ],
51 | 'images': paths.images + '/*',
52 | 'svg': paths.images + '/*.svg',
53 | 'js': paths.scripts + '/*.js',
54 | 'jsmin': paths.scripts + '/*.min.js',
55 | 'php': [ './*.php', './**/*.php' ],
56 | 'sass': paths.sass + '/**/*.scss',
57 | 'styles': paths.styles + '/style.css'
58 | },
59 | getPackageJson = () => {
60 | return JSON.parse( fs.readFileSync( './package.json', 'utf8' ) );
61 | };
62 | handleErrors = () => {
63 | var args = Array.prototype.slice.call( arguments );
64 | notify.onError({
65 | 'title': 'Task Failed [<%= error.message %>',
66 | 'message': 'See console.',
67 | 'sound': 'Sosumi'
68 | }).apply( this, args );
69 | gutil.beep();
70 | this.emit( 'end' );
71 | };
72 |
73 | // Require the gulp tasks.
74 | requireDir( './gulp-tasks', { recurse: true });
75 |
76 | gulp.task( 'default', [ 'scripts', 'styles', 'imagemin', 'bump', 'pot' ]);
77 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://travis-ci.org/jawittdesigns/advanced-custom-fields-auto-json-sync)
2 |
3 | # Advanced Custom Fields: Auto JSON Sync #
4 | This is an addon plugin for Advanced Custom Fields. This addon will automate the JSON sync functionality to update your ACF field groups when you are using version control with your project.
5 |
6 | The plugin will create the `acf-json` directory in your active theme, and scans the `acf-json` directory for any changes to the field group JSON files. When changes are detected your ACF fields groups will be updated.
7 |
8 | ### Requirements ###
9 | [Advanced Custom Fields](https://wordpress.org/plugins/advanced-custom-fields/)
10 |
--------------------------------------------------------------------------------
/advanced-custom-fields-auto-json-sync.php:
--------------------------------------------------------------------------------
1 | basename = plugin_basename( __FILE__ );
99 | $this->path = plugin_dir_path( __FILE__ );
100 | }
101 |
102 | /**
103 | * Attach other plugin classes to the base plugin class.
104 | *
105 | * @since 0.1.0
106 | * @author Jason Witt
107 | */
108 | public function plugin_classes() {
109 | $this->include_file( 'includes/class-directory-structure' );
110 | new ACF_AJS_Directory_Structure;
111 | $this->include_file( 'includes/class-update-field-groups' );
112 | new ACF_AJS_Update_Field_Groups;
113 | } // END OF PLUGIN CLASSES FUNCTION
114 |
115 | /**
116 | * Activate the plugin.
117 | *
118 | * @since 0.1.0
119 | * @author Jason Witt
120 | */
121 | public function _activate() {
122 | // Bail early if requirements aren't met.
123 | if ( ! $this->check_requirements() ) {
124 | return;
125 | }
126 |
127 | // Make sure any rewrite functionality has been loaded.
128 | flush_rewrite_rules();
129 | }
130 |
131 | /**
132 | * Init hooks
133 | *
134 | * @since 0.1.0
135 | * @author Jason Witt
136 | */
137 | public function init() {
138 |
139 | // Bail early if requirements aren't met.
140 | if ( ! $this->check_requirements() ) {
141 | return;
142 | }
143 |
144 | // Load translated strings for plugin.
145 | load_plugin_textdomain( 'afc-ajs', false, dirname( $this->basename ) . '/languages/' );
146 |
147 | // Initialize plugin classes.
148 | $this->plugin_classes();
149 | }
150 |
151 | /**
152 | * Check if the plugin meets requirements and
153 | * disable it if they are not present.
154 | *
155 | * @since 0.1.0
156 | * @author Jason Witt
157 | *
158 | * @return boolean True if requirements met, false if not.
159 | */
160 | public function check_requirements() {
161 |
162 | // Bail early if plugin meets requirements.
163 | if ( $this->meets_requirements() ) {
164 | return true;
165 | }
166 |
167 | // Add a dashboard notice.
168 | add_action( 'all_admin_notices', array( $this, 'requirements_not_met_notice' ) );
169 |
170 | // Deactivate our plugin.
171 | add_action( 'admin_init', array( $this, 'deactivate_me' ) );
172 |
173 | // Didn't meet the requirements.
174 | return false;
175 | }
176 |
177 | /**
178 | * Deactivates this plugin, hook this function on admin_init.
179 | *
180 | * @since 0.1.0
181 | * @author Jason Witt
182 | */
183 | public function deactivate_me() {
184 |
185 | // We do a check for deactivate_plugins before calling it, to protect
186 | // any developers from accidentally calling it too early and breaking things.
187 | if ( function_exists( 'deactivate_plugins' ) ) {
188 | deactivate_plugins( $this->basename );
189 | }
190 | }
191 |
192 | /**
193 | * Check that all plugin requirements are met.
194 | *
195 | * @since 0.1.0
196 | * @author Jason Witt
197 | *
198 | * @return boolean True if requirements are met.
199 | */
200 | public function meets_requirements() {
201 |
202 | // Include plugin.php file to use the is_plugin_active() function.
203 | if ( file_exists( ABSPATH . 'wp-admin/includes/plugin.php' ) ) {
204 | include_once ABSPATH . 'wp-admin/includes/plugin.php';
205 | }
206 |
207 | // Check for Advanced custom fileds pro.
208 | if ( ! is_plugin_active( 'advanced-custom-fields-pro/acf.php' ) ) {
209 |
210 | return false;
211 | }
212 |
213 | return true;
214 | }
215 |
216 | /**
217 | * Adds a notice to the dashboard if the plugin requirements are not met.
218 | *
219 | * @since 0.1.0
220 | * @author Jason Witt
221 | */
222 | public function requirements_not_met_notice() {
223 |
224 | // compile default message.
225 | $default_message = sprintf(
226 | __( 'The Advanced Custom Fields: Auto JSON Sync plugin requires the Advanced Custom Fields Pro plugin to be active.', 'afc-ajs' ),
227 | admin_url( 'plugins.php' )
228 | );
229 |
230 | // add details if any exist.
231 | if ( ! empty( $this->activation_errors ) && is_array( $this->activation_errors ) ) {
232 | $details = '' . implode( '
', $this->activation_errors ) . '';
233 | }
234 |
235 | // output errors.
236 | ?>
237 |
240 | true ) ); }
2 |
--------------------------------------------------------------------------------
/bin/install-wp-tests.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | if [ $# -lt 3 ]; then
4 | echo "usage: $0 [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 | else
28 | # http serves a single offer, whereas https serves multiple. we only want one
29 | download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
30 | grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
31 | LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
32 | if [[ -z "$LATEST_VERSION" ]]; then
33 | echo "Latest WordPress version could not be found"
34 | exit 1
35 | fi
36 | WP_TESTS_TAG="tags/$LATEST_VERSION"
37 | fi
38 |
39 | set -ex
40 |
41 | install_wp() {
42 |
43 | if [ -d $WP_CORE_DIR ]; then
44 | return;
45 | fi
46 |
47 | mkdir -p $WP_CORE_DIR
48 |
49 | if [ $WP_VERSION == 'latest' ]; then
50 | local ARCHIVE_NAME='latest'
51 | else
52 | local ARCHIVE_NAME="wordpress-$WP_VERSION"
53 | fi
54 |
55 | download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
56 | tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
57 |
58 | download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
59 | }
60 |
61 | install_test_suite() {
62 | # portable in-place argument for both GNU sed and Mac OSX sed
63 | if [[ $(uname -s) == 'Darwin' ]]; then
64 | local ioption='-i .bak'
65 | else
66 | local ioption='-i'
67 | fi
68 |
69 | # set up testing suite if it doesn't yet exist
70 | if [ ! -d $WP_TESTS_DIR ]; then
71 | # set up testing suite
72 | mkdir -p $WP_TESTS_DIR
73 | svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
74 | fi
75 |
76 | cd $WP_TESTS_DIR
77 |
78 | if [ ! -f wp-tests-config.php ]; then
79 | download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
80 | sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" "$WP_TESTS_DIR"/wp-tests-config.php
81 | sed $ioption "s:define( 'WP_DEBUG', true );:define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true );:" "$WP_TESTS_DIR"/wp-tests-config.php
82 | sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
83 | sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
84 | sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
85 | sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
86 | fi
87 |
88 | }
89 |
90 | install_db() {
91 | # parse DB_HOST for port or socket references
92 | local PARTS=(${DB_HOST//\:/ })
93 | local DB_HOSTNAME=${PARTS[0]};
94 | local DB_SOCK_OR_PORT=${PARTS[1]};
95 | local EXTRA=""
96 |
97 | if ! [ -z $DB_HOSTNAME ] ; then
98 | if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
99 | EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
100 | elif ! [ -z $DB_SOCK_OR_PORT ] ; then
101 | EXTRA=" --socket=$DB_SOCK_OR_PORT"
102 | elif ! [ -z $DB_HOSTNAME ] ; then
103 | EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
104 | fi
105 | fi
106 |
107 | # create database
108 | mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
109 | }
110 |
111 | install_wp
112 | install_test_suite
113 | install_db
114 |
--------------------------------------------------------------------------------
/gulp-tasks/bump.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Bump Project Version.
3 | *
4 | * 1. gulp bump : Bumps the package.json and bower.json to the next minor revision.
5 | * 2. gulp bump --version 1.1.1 : Bumps/sets the package.json and bower.json to the specified revision.
6 | * 3. gulp bump --type major : Bumps to 1.0.0.
7 | * gulp bump --type minor : Bumps to 0.1.0.
8 | * gulp bump --type patch : Bumps to 0.0.2.
9 | * gulp bump --type prerelease : Bumps to 0.0.1-2.
10 | *
11 | * @package Boilderplate
12 | *
13 | * @since 1.0.0
14 | */
15 |
16 | /* global args, bump, getPackageJson, gulp, handleErrors, plumber, replace */
17 |
18 | /**
19 | * package.json version bump.
20 | *
21 | * @since 1.0.0
22 | */
23 | gulp.task( 'packageBump', () => {
24 |
25 | var type = args.type,
26 | version = args.version,
27 | options = {};
28 |
29 | if ( version ) {
30 | options.version = version;
31 | } else {
32 | options.type = type;
33 | }
34 |
35 | return gulp.src([ './package.json' ])
36 | .pipe( plumber({'errorHandler': handleErrors}) )
37 | .pipe( bump( options ) )
38 | .pipe( gulp.dest( './' ) );
39 | });
40 |
41 | /**
42 | * All files version bump.
43 | *
44 | * @since 1.0.0
45 | */
46 | gulp.task( 'bump', [ 'packageBump' ], () => {
47 | var pkg = getPackageJson(),
48 | filePaths = [
49 | '!node_modules/',
50 | '!node_modules/**',
51 | '!Gulpfile.js',
52 | '!package.json',
53 | '!./gulp-tasks/bump.js',
54 | './**/*'
55 | ];
56 |
57 | gulp.src( filePaths, { base: './', dot: false })
58 | .pipe( plumber({'errorHandler': handleErrors}) )
59 | .pipe( replace( /@since[ \t]+NEXT/g, '@since ' + pkg.version ) )
60 | .pipe( replace( /@version(.*)/g, '@version ' + pkg.version ) )
61 | .pipe( gulp.dest( './' ) );
62 | });
63 |
--------------------------------------------------------------------------------
/gulp-tasks/imagemin.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Minify Images.
3 | *
4 | * @package Boilderplate
5 | *
6 | * @since 1.0.0
7 | */
8 |
9 | /* global files, gulp, handleErrors, imagemin, paths, plumber */
10 |
11 | var images = [ files.images, '!' + files.svg ];
12 |
13 | /**
14 | * Optimize images.
15 | *
16 | * @since 1.0.0
17 | */
18 | gulp.task( 'imagemin', () =>
19 | gulp.src( images )
20 | .pipe( plumber({'errorHandler': handleErrors}) )
21 | .pipe( imagemin({
22 | 'optimizationLevel': 5,
23 | 'progressive': true,
24 | 'interlaced': true
25 | }) )
26 | .pipe( gulp.dest( paths.images ) )
27 | );
28 |
--------------------------------------------------------------------------------
/gulp-tasks/index.php:
--------------------------------------------------------------------------------
1 | true ) ); }
2 |
--------------------------------------------------------------------------------
/gulp-tasks/pot.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Generate .po file for translatable text.
3 | *
4 | * @package Boilderplate
5 | *
6 | * @since 1.0.0
7 | */
8 |
9 | /* global del, files, getPackageJson, gulp, handleErrors, plumber, sort, wpPot */
10 |
11 | var pkg = getPackageJson(),
12 | domain = pkg.name;
13 |
14 | /**
15 | * Delete the theme's .pot before we create a new one.
16 | *
17 | * @since 1.0.
18 | */
19 | gulp.task( 'cleanPot', () =>
20 | del([ 'languages/' + domain + '.pot' ])
21 | );
22 |
23 | /**
24 | * Scan the files and create a POT file.
25 | *
26 | * @since 1.0.0
27 | */
28 | gulp.task( 'pot', [ 'cleanPot' ], () =>
29 | gulp.src( files.php )
30 | .pipe( plumber({'errorHandler': handleErrors}) )
31 | .pipe( sort() )
32 | .pipe( wpPot({
33 | 'domain': domain,
34 | 'package': domain
35 | }) )
36 | .pipe( gulp.dest( 'languages/' + domain + '.pot' ) )
37 | );
38 |
--------------------------------------------------------------------------------
/gulp-tasks/scripts.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Compile Scripts.
3 | *
4 | * @package Boilderplate
5 | *
6 | * @since 1.0.0
7 | */
8 |
9 | /* global babel, concat, files, gulp, handleErrors, paths, plumber, sourcemaps, rename, uglify */
10 |
11 | var js = [ files.js, '!' + files.jsmin ];
12 |
13 | /**
14 | * Concatenate and transform JavaScript.
15 | *
16 | * @since 1.0.0
17 | */
18 | gulp.task( 'concat', () =>
19 | gulp.src( files.concatScripts )
20 | .pipe( plumber({'errorHandler': handleErrors}) )
21 | .pipe( sourcemaps.init() )
22 | .pipe( babel({ presets: [ 'es2015' ] }) )
23 | .pipe( concat( 'index.js' ) )
24 | .pipe( sourcemaps.write() )
25 | .pipe( gulp.dest( 'assets/scripts' ) )
26 | );
27 |
28 | /**
29 | * Minify compiled JavaScript.
30 | *
31 | * @since 1.0.0
32 | */
33 | gulp.task( 'uglify', [ 'concat' ], () =>
34 | gulp.src( js )
35 | .pipe( plumber({'errorHandler': handleErrors}) )
36 | .pipe( rename({ 'suffix': '.min' }) )
37 | .pipe( uglify({ 'mangle': false }) )
38 | .pipe( gulp.dest( paths.scripts ) )
39 | );
40 |
41 | /**
42 | * Compile JavaScript.
43 | *
44 | * @since 1.0.0
45 | */
46 | gulp.task( 'scripts', [ 'uglify' ]);
47 |
--------------------------------------------------------------------------------
/gulp-tasks/styles.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Compile Styles.
3 | *
4 | * @package Boilderplate
5 | *
6 | * @since 1.0.0
7 | */
8 |
9 | /* global autoprefixer, cssnano, del, files, gulp, handleErrors, mqpacker, paths, plumber, postcss, rename, sass, sourcemaps, strip */
10 |
11 | /**
12 | * Delete style.css and style.min.css before we minify and optimize
13 | *
14 | * @since 1.0.0
15 | */
16 | gulp.task( 'cleanStyles', () =>
17 | del([ files.css, files.cssmin ])
18 | );
19 |
20 | /**
21 | * Compile Sass and run stylesheet through PostCSS.
22 | *
23 | * @since 1.0.0
24 | */
25 | gulp.task( 'compileStyles', [ 'cleanStyles' ], () =>
26 | gulp.src( files.sass, [ files.css, ! files.cssmin ])
27 | .pipe( plumber({'errorHandler': handleErrors}) )
28 | .pipe( sourcemaps.init() )
29 | .pipe( sass({'errLogToConsole': true, 'outputStyle': 'expanded'}) )
30 | .pipe(
31 | postcss([
32 | autoprefixer({'browsers': [ 'last 2 version' ]}),
33 | mqpacker({'sort': true})
34 | ]) )
35 | .pipe( sourcemaps.write() )
36 | .pipe( gulp.dest( paths.styles ) )
37 | );
38 |
39 | /**
40 | * Minify and optimize style.css.
41 | *
42 | * @since 1.0.0
43 | */
44 | gulp.task( 'minifyStyles', [ 'compileStyles' ], () =>
45 | gulp.src( files.styles )
46 | .pipe( plumber({'errorHandler': handleErrors}) )
47 | .pipe( cssnano({'safe': true, discardComments: {removeAll: true}}) )
48 | .pipe( rename( 'style.min.css' ) )
49 | .pipe( gulp.dest( paths.styles ) )
50 | );
51 |
52 | /**
53 | * Compile Styles.
54 | *
55 | * @since 1.0.0
56 | */
57 | gulp.task( 'styles', [ 'minifyStyles' ]);
58 |
--------------------------------------------------------------------------------
/gulp-tasks/watch.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Watch.
3 | *
4 | * @package Boilderplate
5 | *
6 | * @since 1.0.0
7 | */
8 |
9 | /* global files, gulp */
10 |
11 | /**
12 | * Watch
13 | *
14 | * @since 1.0.0
15 | */
16 | gulp.task( 'watch', () => {
17 | gulp.watch( files.sass, [ 'styles' ]);
18 | gulp.watch( files.concatScripts, [ 'scripts' ]);
19 | gulp.watch( files.images, [ 'imagemin' ]);
20 | });
21 |
--------------------------------------------------------------------------------
/includes/class-directory-structure.php:
--------------------------------------------------------------------------------
1 | acf_json_dirs = acf_get_setting( 'load_json' );
40 | } else {
41 | $this->acf_json_dirs = array( trailingslashit( get_template_directory() ) . 'acf-json' );
42 | }
43 | $this->hooks();
44 | }
45 |
46 | /**
47 | * Initiate our hooks.
48 | *
49 | * @since 0.1.0
50 | * @author Jason Witt
51 | *
52 | * @return void
53 | */
54 | public function hooks() {
55 |
56 | add_action( 'init', array( $this, 'init' ) );
57 | }
58 |
59 | /**
60 | * Instantiate.
61 | *
62 | * @since 0.1.0
63 | * @author Jason Witt
64 | *
65 | * @return void
66 | */
67 | public function init() {
68 |
69 | // The ACF json directory.
70 | $this->maybe_create_directories();
71 | $this->maybe_create_file();
72 | }
73 |
74 | /**
75 | * Get WP Filesystem.
76 | *
77 | * @author Jason Witt
78 | * @since 0.1.0
79 | *
80 | * @return object $wp_filesystem The WP Filesystem.
81 | */
82 | public function get_wp_filesystem() {
83 |
84 | if ( ! function_exists( 'WP_Filesystem' ) ) {
85 | require_once ABSPATH . 'wp-admin/includes/file.php';
86 | }
87 |
88 | WP_Filesystem();
89 |
90 | global $wp_filesystem;
91 |
92 | return $wp_filesystem;
93 | }
94 |
95 | /**
96 | * Create ACF directories.
97 | *
98 | * @since 0.1.0
99 | * @author Jason Witt
100 | *
101 | * @return bool Return if directory exists.
102 | */
103 | private function maybe_create_directories() {
104 |
105 | foreach ( $this->acf_json_dirs as $dir ) {
106 |
107 | // Bail early if directory exists.
108 | if ( file_exists( $dir ) ) {
109 | return;
110 | }
111 |
112 | // Create the directory if it doesn't exist.
113 | wp_mkdir_p( $dir );
114 | }
115 | }
116 |
117 | /**
118 | * Create index.php file
119 | *
120 | * @since 0.1.0
121 | * @author Jason Witt
122 | *
123 | * @return bool return Return if file exists.
124 | */
125 | private function maybe_create_file() {
126 |
127 | foreach ( $this->acf_json_dirs as $dir ) {
128 | $file = trailingslashit( $dir ) . 'index.php';
129 | $wp_filesystem = $this->get_wp_filesystem();
130 | $content = " true ) ); }";
131 |
132 | // Bail eraly if file exists.
133 | if ( file_exists( $file ) ) {
134 | return;
135 | }
136 |
137 | // Create the file.
138 | if ( wp_is_writable( $dir ) ) {
139 | $wp_filesystem->put_contents( $file, $content );
140 | }
141 | }
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/includes/class-update-field-groups.php:
--------------------------------------------------------------------------------
1 | hooks();
35 | }
36 |
37 | /**
38 | * Initiate our hooks.
39 | *
40 | * @since 0.1.0
41 | * @author Jason Witt
42 | */
43 | public function hooks() {
44 | add_action( 'init', array( $this, 'init' ) );
45 | }
46 |
47 | /**
48 | * Instantiate.
49 | *
50 | * @since 0.1.0
51 | * @author Jason Witt
52 | *
53 | * @return void
54 | */
55 | public function init() {
56 | $this->maybe_update_field_groups();
57 | }
58 |
59 | /**
60 | * Maybe update field groups
61 | *
62 | * @since 0.1.0
63 | * @author Jason Witt
64 | *
65 | * @return void
66 | */
67 | public function maybe_update_field_groups() {
68 |
69 | // Get the JSON dirs.
70 | if ( function_exists( 'acf_get_setting' ) ) {
71 | $json_dirs = acf_get_setting( 'load_json' );
72 | } else {
73 | $json_dirs = array( trailingslashit( get_template_directory() ) . 'acf-json' );
74 | }
75 |
76 | // Bail if no JSON directories are set.
77 | if ( empty( $json_dirs ) ) {
78 | return;
79 | }
80 |
81 | // Loop through the JSON file directories.
82 | foreach ( $json_dirs as $dir ) {
83 | $this->maybe_update_field_groups_from_json( $dir );
84 | $this->maybe_trash_field_group_from_database( $dir );
85 | }
86 | }
87 |
88 | /**
89 | * Update from json
90 | *
91 | * @since 0.1.0
92 | * @author Jason Witt
93 | *
94 | * @param string $json_dir The directory to the field group JSON files.
95 | *
96 | * @return void
97 | */
98 | public function maybe_update_field_groups_from_json( $json_dir ) {
99 |
100 | // Bail early if no field groups exist.
101 | if ( ! $this->get_json_field_groups( $json_dir ) ) {
102 | return;
103 | }
104 |
105 | $sync = $this->get_json_field_groups( $json_dir );
106 | $url = 'edit.php?post_type=acf-field-group';
107 | $current_url = ( isset( $_SERVER['HTTPS'] ) ? 'https' : 'http' ) . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
108 |
109 | // disable filters to ensure ACF loads raw data from DB.
110 | acf_disable_filters();
111 | acf_enable_filter( 'local' );
112 |
113 | // disable JSON - this prevents a new JSON file being created and causing a 'change' to theme files - solves git anoyance.
114 | acf_update_setting( 'json', false );
115 |
116 | if ( ! empty( $sync ) ) {
117 | foreach ( $sync as $key => $v ) {
118 |
119 | // Append the fields to the array.
120 | if ( acf_have_local_fields( $key ) ) {
121 | $sync[ $key ]['fields'] = acf_get_local_fields( $key );
122 | }
123 | // Import the field groups.
124 | $field_group = acf_import_field_group( $sync[ $key ] );
125 |
126 | // New IDs.
127 | $new_ids[] = $field_group['ID'];
128 | }
129 |
130 | // Check if on the ACF Filed FGroups page.
131 | if ( admin_url( $url ) === $current_url ) {
132 | // Redirect.
133 | wp_redirect( admin_url( $url . '&acfsynccomplete=' . implode( ',', $new_ids ) ) );
134 | exit;
135 | }
136 | }
137 | }
138 |
139 | /**
140 | * Delete field group from databse.
141 | *
142 | * @since 0.1.0
143 | * @author Jason Witt
144 | *
145 | * @param string $json_dir The directory to the field group JSON files.
146 | *
147 | * @return void
148 | */
149 | public function maybe_trash_field_group_from_database( $json_dir ) {
150 | $database_keys = $this->get_database_field_group_keys();
151 | $json_key = $this->get_json_field_group_keys( $json_dir );
152 | $diffs = array_diff( $database_keys, $json_key );
153 |
154 | // Bail early if there are no database or json keys.
155 | if ( empty( $database_keys ) ) {
156 | return;
157 | }
158 |
159 | // Bail earky if array is empty.
160 | if ( empty( $diffs ) ) {
161 | return;
162 | }
163 |
164 | // Loop through the field groups.
165 | foreach ( $diffs as $key => $value ) {
166 | if ( isset( $key ) ) {
167 |
168 | // Trash the field groups.
169 | acf_trash_field_group( $key );
170 | }
171 | }
172 | }
173 |
174 | /**
175 | * Get database fields groups.
176 | *
177 | * @since 0.1.0
178 | * @author Jason Witt
179 | *
180 | * @return array $keys An array of the field group keys in set in the database.
181 | */
182 | public function get_database_field_group_keys() {
183 | $keys = array();
184 | $field_groups = get_posts( array(
185 | 'post_type' => 'acf-field-group',
186 | 'posts_per_page' => 99,
187 | 'orderby' => 'menu_order title',
188 | 'order' => 'asc',
189 | 'suppress_filters' => false,
190 | 'post_status' => array( 'publish', 'acf-disabled' ),
191 | 'update_post_meta_cache' => false,
192 | ));
193 | if ( ! empty( $field_groups ) ) {
194 |
195 | // Build array for the post name and IDs.
196 | $keys = wp_list_pluck( $field_groups, 'post_name', 'ID' );
197 | }
198 | return $keys;
199 | }
200 |
201 | /**
202 | * Get WP Filesystem.
203 | *
204 | * @author Jason Witt
205 | * @since 0.1.0
206 | *
207 | * @return object $wp_filesystem The WP Filesystem.
208 | */
209 | public function get_wp_filesystem() {
210 |
211 | // Include the file.php to load WP_Filesystem().
212 | if ( ! function_exists( 'WP_Filesystem' ) ) {
213 | require_once ABSPATH . 'wp-admin/includes/file.php';
214 | }
215 | WP_Filesystem();
216 | global $wp_filesystem;
217 | return $wp_filesystem;
218 | }
219 |
220 | /**
221 | * Get json field group keys.
222 | *
223 | * @since 0.1.0
224 | * @author Jason Witt
225 | *
226 | * @param string $json_dir The directory to the field group JSON files.
227 | *
228 | * @return keys $field_groups An array of the jason field group keys.
229 | */
230 | public function get_json_field_group_keys( $json_dir ) {
231 |
232 | // Bail if no JSON directory is set.
233 | if ( ! $json_dir ) {
234 | return;
235 | }
236 |
237 | $path = untrailingslashit( $json_dir );
238 | $wp_filesystem = $this->get_wp_filesystem();
239 | $field_groups = array();
240 | $keys = array();
241 | $dir = opendir( $path );
242 |
243 | // Bail if directory doesn't exist.
244 | if ( ! file_exists( $path ) ) {
245 | return;
246 | }
247 |
248 | // Get the filed group keys.
249 | while ( false !== ( $file = readdir( $dir ) ) ) {
250 |
251 | // validate type.
252 | if ( pathinfo( $file, PATHINFO_EXTENSION ) !== 'json' ) {
253 | continue;
254 | }
255 |
256 | // read json.
257 | $json = $wp_filesystem->get_contents( "{$path}/{$file}" );
258 |
259 | // validate json.
260 | if ( empty( $json ) ) {
261 | continue;
262 | }
263 |
264 | // decode.
265 | $json = json_decode( $json, true );
266 |
267 | $field_groups[] = $json;
268 | }
269 |
270 | // Build an array of the field group keys.
271 | if ( ! empty( $field_groups ) ) {
272 |
273 | $keys = wp_list_pluck( $field_groups, 'key' );
274 | }
275 |
276 | return $keys;
277 | }
278 |
279 | /**
280 | * Is json update.
281 | *
282 | * @since 0.1.0
283 | * @author Jason Witt
284 | *
285 | * @param string $json_dir The directory to the field group JSON files.
286 | *
287 | * @return array $sync An Array of json group fields that have been updated.
288 | */
289 | public function get_json_field_groups( $json_dir ) {
290 |
291 | // Bail if no JSON directory is set.
292 | if ( ! $json_dir ) {
293 | return;
294 | }
295 |
296 | // Return empty array if no field groups exist.
297 | if ( count( glob( trailingslashit( $json_dir ) . '/*.json', GLOB_BRACE ) ) < 1 ) {
298 | return array();
299 | }
300 |
301 | $groups = acf_get_field_groups();
302 | $sync = array();
303 |
304 | // bail early if no field groups.
305 | if ( empty( $groups ) ) {
306 | return false;
307 | }
308 |
309 | // find JSON field groups which have not yet been imported.
310 | foreach ( $groups as $group ) {
311 | $local = acf_maybe_get( $group, 'local', false );
312 | $modified = acf_maybe_get( $group, 'modified', 0 );
313 | $private = acf_maybe_get( $group, 'private', false );
314 |
315 | // ignore DB / PHP / private field groups.
316 | if ( 'json' === $local || ! $private ) {
317 | if ( ! $group['ID'] ) {
318 | $sync[ $group['key'] ] = $group;
319 | } elseif ( $modified && $modified > get_post_modified_time( 'U', true, $group['ID'], true ) ) {
320 | $sync[ $group['key'] ] = $group;
321 | }
322 | }
323 | }
324 |
325 | // bail if no sync needed.
326 | if ( empty( $sync ) ) {
327 | return false;
328 | }
329 |
330 | return $sync;
331 | }
332 | }
333 |
--------------------------------------------------------------------------------
/includes/index.php:
--------------------------------------------------------------------------------
1 | true ) ); }
2 |
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 | true ) ); }
2 |
--------------------------------------------------------------------------------
/languages/afc-ajs.pot:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2017 afc-ajs
2 | # This file is distributed under the same license as the afc-ajs package.
3 | msgid ""
4 | msgstr ""
5 | "Project-Id-Version: afc-ajs\n"
6 | "MIME-Version: 1.0\n"
7 | "Content-Type: text/plain; charset=UTF-8\n"
8 | "Content-Transfer-Encoding: 8bit\n"
9 | "X-Poedit-Basepath: ..\n"
10 | "X-Poedit-KeywordsList: __;_e;_ex:1,2c;_n:1,2;_n_noop:1,2;_nx:1,2,4c;_nx_noop:1,2,3c;_x:1,2c;esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c\n"
11 | "X-Poedit-SearchPath-0: .\n"
12 | "X-Poedit-SearchPathExcluded-0: *.js\n"
13 | "X-Poedit-SourceCharset: UTF-8\n"
14 | "Plural-Forms: nplurals=2; plural=(n != 1);\n"
15 |
16 | #: advanced-custom-fields-auto-json-sync.php:257
17 | msgid "The Advanced Custom Fields: Auto JSON Sync plugin requires the Advanced Custom Fields Pro plugin to be active."
18 | msgstr ""
19 |
--------------------------------------------------------------------------------
/languages/index.php:
--------------------------------------------------------------------------------
1 | true ) ); }
2 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "afc-ajs",
3 | "version": "0.2.0",
4 | "description": "Automatically update your local ACF JSON field groups.",
5 | "main": "Gulpfile.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "author": "Jason Witt",
10 | "license": "MIT",
11 | "devDependencies": {
12 | "autoprefixer": "latest",
13 | "babel-core": "latest",
14 | "babel-preset-es2015": "latest",
15 | "css-mqpacker": "latest",
16 | "del": "latest",
17 | "eslint-config-wordpress": "latest",
18 | "gulp": "latest",
19 | "gulp-babel": "latest",
20 | "gulp-bump": "latest",
21 | "gulp-concat": "latest",
22 | "gulp-cssnano": "latest",
23 | "gulp-eslint": "latest",
24 | "gulp-imagemin": "latest",
25 | "gulp-notify": "latest",
26 | "gulp-plumber": "latest",
27 | "gulp-postcss": "latest",
28 | "gulp-rename": "latest",
29 | "gulp-replace": "latest",
30 | "gulp-require-tasks": "latest",
31 | "gulp-sass": "latest",
32 | "gulp-sass-lint": "latest",
33 | "gulp-sort": "latest",
34 | "gulp-sourcemaps": "latest",
35 | "gulp-uglify": "latest",
36 | "gulp-util": "latest",
37 | "gulp-watch": "latest",
38 | "gulp-wp-pot": "latest",
39 | "require-dir": "latest",
40 | "yargs": "latest"
41 | },
42 | "dependencies": {
43 | "normalize-scss": "latest"
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/phpcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | A custom ruleset to take in account both WordPress and WebDevStudios code standards.
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | 0
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/phpmd.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 | PHPMD Ruleset for a WordPress Theme
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 | ./tests/
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/tests/base.php:
--------------------------------------------------------------------------------
1 | file && is_string( $this->file ) || $this->file && ! empty( $this->file ) ) {
66 | $this->assertFileExists( $this->file );
67 | }
68 | }
69 |
70 | /**
71 | * Test if class exists.
72 | *
73 | * @since 0.1.1
74 | */
75 | public function test_class_exists() {
76 |
77 | // Is String sanity check.
78 | if ( $this->class_name && is_string( $this->class_name ) || $this->class_name && ! empty( $this->class_name ) ) {
79 | $this->assertTrue( class_exists( $this->class_name ), 'The class "' . $this->class_name . '()" doesn\'t exist!' );
80 | }
81 | }
82 |
83 | /**
84 | * Test if methods exist.
85 | *
86 | * @since 0.1.1
87 | *
88 | * @return void
89 | */
90 | public function test_methods_exist() {
91 |
92 | // Is Array sanity check.
93 | if ( $this->methods && ( is_array( $this->methods ) && ! empty( $this->methods ) ) ) {
94 | foreach ( $this->methods as $method ) {
95 | $this->assertTrue( method_exists( $this->class_name, $method ), 'The method "' . $method . '()" doesn\'t exist!' );
96 | }
97 | }
98 | }
99 |
100 | /**
101 | * Test if wp_roles property exists.
102 | *
103 | * @since 0.1.1
104 | *
105 | * @return void
106 | */
107 | public function test_property_exists() {
108 |
109 | // Is Array sanity check.
110 | if ( $this->properties && ( is_array( $this->properties ) && ! empty( $this->properties ) ) ) {
111 | foreach ( $this->properties as $property ) {
112 | $this->assertTrue( property_exists( $this->class_name, $property ), 'The property "$' . $property . '" doesn\'t exist!' );
113 | }
114 | }
115 | }
116 |
117 | /**
118 | * Set Property.
119 | *
120 | * @since 0.1.1
121 | *
122 | * @param object $object The class object.
123 | * @param string $property The name of the property to set.
124 | * @param mixed $value The value to set the property to.
125 | *
126 | * @return void
127 | */
128 | public function set_property( $object, $property, $value ) {
129 | $reflection = new ReflectionClass( $object );
130 | $reflection_property = $reflection->getProperty( $property );
131 | $reflection_property->setAccessible( true );
132 | $reflection_property->setValue( $object, $value );
133 | }
134 |
135 | /**
136 | * Invoke Private Method.
137 | *
138 | * @since 0.1.1
139 | *
140 | * @param object $object The class object.
141 | * @param string $method_name The name of the method to invoke.
142 | * @param mixed $parameters The parameters of the method.
143 | *
144 | * @return mixed Method return.
145 | */
146 | public function invoke_private_method( &$object, $method_name, $parameters = array() ) {
147 | $reflection = new \ReflectionClass( get_class( $object ) );
148 | $reflection_method = $reflection->getMethod( $method_name );
149 | $reflection_method->setAccessible( true );
150 |
151 | return $reflection_method->invokeArgs( $object, $parameters );
152 | }
153 | }
154 |
--------------------------------------------------------------------------------
/tests/bootstrap.php:
--------------------------------------------------------------------------------
1 | true ) ); }
2 |
--------------------------------------------------------------------------------
/tests/test-advanced-custom-fields-auto-json-sync.php:
--------------------------------------------------------------------------------
1 |
10 | * @copyright Copyright (c) 2017, Jason Witt
11 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
12 | * @since 0.1.1
13 | */
14 |
15 | /**
16 | * Base Plugin File Test
17 | *
18 | * @author Jason Witt
19 | * @since 0.1.1
20 | */
21 | class Test_ACF_Auto_JSON_Sync extends Base_UnitTestCase {
22 |
23 | /**
24 | * SetUp.
25 | *
26 | * @author Jason Witt
27 | * @since 0.1.1
28 | *
29 | * @return void
30 | */
31 | public function setUp() {
32 | $this->file = plugin_dir_path( __DIR__ ) . 'advanced-custom-fields-auto-json-sync.php';
33 | $this->class_name = 'ACF_Auto_JSON_Sync';
34 | $this->methods = array(
35 | 'plugin_classes',
36 | '_activate',
37 | 'init',
38 | );
39 | $this->proprties = array(
40 | 'url',
41 | 'path',
42 | 'basename',
43 | 'plugin_prefix',
44 | 'acf_json_dir',
45 | 'directory_structure',
46 | 'update_field_groups',
47 | );
48 | }
49 |
50 | /**
51 | * Test that our main helper function is an instance of our class.
52 | *
53 | * @author Jason Witt
54 | * @since 0.1.1
55 | *
56 | * @return void
57 | */
58 | function test_get_instance() {
59 | $this->assertInstanceOf( $this->class_name, afc_ajs() );
60 | }
61 |
62 | /**
63 | * Test Plugin Classes.
64 | *
65 | * @author Jason Witt
66 | * @since 0.1.1
67 | *
68 | * @return void
69 | */
70 | public function test_plugin_classes() {
71 | $this->assertInstanceOf( 'ACF_AJS_Directory_Structure', new ACF_AJS_Directory_Structure( afc_ajs() ) );
72 | $this->assertInstanceOf( 'ACF_AJS_Update_Field_Groups', new ACF_AJS_Update_Field_Groups( afc_ajs() ) );
73 | }
74 |
75 | /**
76 | * Test Meets requirements.
77 | *
78 | * @author Jason Witt
79 | * @since 0.1.1
80 | *
81 | * @return void
82 | */
83 | public function test_meets_requirements() {
84 | $this->assertTrue( is_plugin_active( 'advanced-custom-fields-pro/acf.php' ) );
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/tests/test-class-directory-strucure.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright Copyright (c) 2017, Jason Witt
9 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
10 | * @since 0.1.1
11 | */
12 |
13 | /**
14 | * Directory Structure Test
15 | *
16 | * @author Jason Witt
17 | * @since 0.1.1
18 | */
19 | class Test_ACF_AJS_Directory_Structure extends Base_UnitTestCase {
20 |
21 | /**
22 | * SetUp.
23 | *
24 | * @author Jason Witt
25 | * @since 0.1.1
26 | *
27 | * @return void
28 | */
29 | public function setUp() {
30 | $this->file = plugin_dir_path( __DIR__ ) . 'includes/class-directory-structure.php';
31 | $this->class = new ACF_AJS_Directory_Structure( afc_ajs() );
32 | $this->class_name = 'ACF_AJS_Directory_Structure';
33 | $this->methods = array(
34 | 'hooks',
35 | 'init',
36 | 'get_wp_filesystem',
37 | 'maybe_create_directories',
38 | 'maybe_create_file',
39 | );
40 | $this->proprties = array(
41 | 'plugin',
42 | );
43 | }
44 |
45 | /**
46 | * Test Hooks.
47 | *
48 | * @author Jason Witt
49 | * @since 0.1.1
50 | *
51 | * @return void
52 | */
53 | public function test_hooks() {
54 | $this->class->init();
55 | $hooks = array(
56 | array(
57 | 'hook_name' => 'init',
58 | 'method' => 'init',
59 | 'priority' => 10,
60 | ),
61 | );
62 | foreach ( $hooks as $hook ) {
63 | $this->assertEquals( $hook['priority'], has_action( $hook['hook_name'], array( $this->class, $hook['method'] ) ), 'hooks() is not attaching ' . $hook['method'] . '() to ' . $hook['hook_name'] . '!' );
64 | }
65 | }
66 |
67 | /**
68 | * ACF Directory exists.
69 | *
70 | * @author Jason Witt
71 | * @since 0.1.1
72 | *
73 | * @return void
74 | */
75 | public function test_does_acf_directory_exist() {
76 | $this->assertTrue( file_exists( trailingslashit( get_template_directory() ) . 'acf-json' ) );
77 | }
78 |
79 | /**
80 | * Does File Exist.
81 | *
82 | * @author Jason Witt
83 | * @since 0.1.1
84 | *
85 | * @return void
86 | */
87 | public function test_does_file_exist() {
88 | $this->assertTrue( file_exists( trailingslashit( get_template_directory() ) . 'acf-json/index.php' ) );
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/tests/test-class-update-filed-groups.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright Copyright (c) 2017, Jason Witt
9 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
10 | * @since 0.1.1
11 | */
12 |
13 | /**
14 | * Test Update Filed Groups Test
15 | *
16 | * @author Jason Witt
17 | * @since 0.1.1
18 | */
19 | class Test_ACF_AJS_Update_Field_Groups extends Base_UnitTestCase {
20 |
21 | /**
22 | * SetUp.
23 | *
24 | * @author Jason Witt
25 | * @since 0.1.1
26 | *
27 | * @return void
28 | */
29 | public function setUp() {
30 | $this->file = plugin_dir_path( __DIR__ ) . 'includes/class-update-field-groups.php';
31 | $this->class = new ACF_AJS_Update_Field_Groups( afc_ajs() );
32 | $this->class_name = 'ACF_AJS_Update_Field_Groups';
33 | $this->methods = array(
34 | 'hooks',
35 | 'init',
36 | 'maybe_update_field_groups',
37 | 'maybe_update_field_groups_from_json',
38 | 'maybe_trash_field_group_from_database',
39 | 'get_database_field_group_keys',
40 | 'get_wp_filesystem',
41 | 'get_json_field_group_keys',
42 | 'get_json_field_groups',
43 | );
44 | $this->proprties = array(
45 | 'plugin',
46 | );
47 | }
48 |
49 | /**
50 | * Test Hooks.
51 | *
52 | * @author Jason Witt
53 | * @since 0.1.1
54 | *
55 | * @return void
56 | */
57 | public function test_hooks() {
58 | $this->class->init();
59 | $hooks = array(
60 | array(
61 | 'hook_name' => 'init',
62 | 'method' => 'init',
63 | 'priority' => 10,
64 | ),
65 | );
66 | foreach ( $hooks as $hook ) {
67 | $this->assertEquals( $hook['priority'], has_action( $hook['hook_name'], array( $this->class, $hook['method'] ) ), 'hooks() is not attaching ' . $hook['method'] . '() to ' . $hook['hook_name'] . '!' );
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------