diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ee680e5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,79 @@ +# Created by http://www.gitignore.io + +### OSX ### +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear on external disk +.Spotlight-V100 +.Trashes + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + + +### Node ### +# Logs +logs +*.log + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# Deployed apps should consider commenting this line out: +# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git +node_modules + +# PHPStorm +.idea + +# Zip Files +*.zip + +# Sass Cache +*.sass-cache + +dandelion.yml +ocular.phar +.tx + +# PHPunit config +phpunit.xml + +# Composer +vendor + +# General +NOTES.md + +# Cypress +/cypress.env.json +/tests/cypress/videos +/tests/cypress/screenshots diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist new file mode 100644 index 0000000..4646967 --- /dev/null +++ b/.phpcs.xml.dist @@ -0,0 +1,181 @@ + + + The coding standard for CMB2. + + + + + . + + node_modules/* + vendor/* + themes/omappv4/src/View/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + error + + + + + + + + + + + + + + + + + + + + + error + Scheduling crons at %s sec ( less than %s minutes ) is prohibited. + + + + + error + + + error + + + + + + + + + + + + + + + + + + + + 0 + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..22fbe5d --- /dev/null +++ b/LICENSE @@ -0,0 +1,339 @@ +GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {description} + Copyright (C) {year} {fullname} + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + {signature of Ty Coon}, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..c1d5361 --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +CMB2 WooCommerce HPOS Orders +================== + +Custom field for [CMB2](https://github.com/CMB2/CMB2). + +Adds the ability to add custom fields to the new WooCommerce HPOS orders page. + +## Installation + +Follow the example in [`example-field-setup.php`](https://github.com/CMB2/cmb2-woocommerce-hpos-orders/blob/master/example-field-setup.php) for a demonstration. The example assumes you have both CMB2 and this extension in your mu-plugins directory. If you're using CMB2 installed as a plugin, you can remove the `require_once` line. + +## Usage +You can retrieve the meta data using the following: + +```php +$test_text_value = wc_get_order( $order_id )->get_meta( 'yourprefix_woo_orders_text', true, 'edit' ); +``` + +## Changelog + +### 1.0.0 +* Release \ No newline at end of file diff --git a/bin/phpcbf b/bin/phpcbf new file mode 100755 index 0000000..a1f0915 --- /dev/null +++ b/bin/phpcbf @@ -0,0 +1,120 @@ +#!/usr/bin/env php +realpath = realpath($opened_path) ?: $opened_path; + $opened_path = $this->realpath; + $this->handle = fopen($this->realpath, $mode); + $this->position = 0; + + return (bool) $this->handle; + } + + public function stream_read($count) + { + $data = fread($this->handle, $count); + + if ($this->position === 0) { + $data = preg_replace('{^#!.*\r?\n}', '', $data); + } + + $this->position += strlen($data); + + return $data; + } + + public function stream_cast($castAs) + { + return $this->handle; + } + + public function stream_close() + { + fclose($this->handle); + } + + public function stream_lock($operation) + { + return $operation ? flock($this->handle, $operation) : true; + } + + public function stream_seek($offset, $whence) + { + if (0 === fseek($this->handle, $offset, $whence)) { + $this->position = ftell($this->handle); + return true; + } + + return false; + } + + public function stream_tell() + { + return $this->position; + } + + public function stream_eof() + { + return feof($this->handle); + } + + public function stream_stat() + { + return array(); + } + + public function stream_set_option($option, $arg1, $arg2) + { + return true; + } + + public function url_stat($path, $flags) + { + $path = substr($path, 17); + if (file_exists($path)) { + return stat($path); + } + + return false; + } + } + } + + if ( + (function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true)) + || (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper')) + ) { + include("phpvfscomposer://" . __DIR__ . '/..'.'/vendor/squizlabs/php_codesniffer/bin/phpcbf'); + exit(0); + } +} + +include __DIR__ . '/..'.'/vendor/squizlabs/php_codesniffer/bin/phpcbf'; diff --git a/bin/phpcs b/bin/phpcs new file mode 100755 index 0000000..392d5e1 --- /dev/null +++ b/bin/phpcs @@ -0,0 +1,120 @@ +#!/usr/bin/env php +realpath = realpath($opened_path) ?: $opened_path; + $opened_path = $this->realpath; + $this->handle = fopen($this->realpath, $mode); + $this->position = 0; + + return (bool) $this->handle; + } + + public function stream_read($count) + { + $data = fread($this->handle, $count); + + if ($this->position === 0) { + $data = preg_replace('{^#!.*\r?\n}', '', $data); + } + + $this->position += strlen($data); + + return $data; + } + + public function stream_cast($castAs) + { + return $this->handle; + } + + public function stream_close() + { + fclose($this->handle); + } + + public function stream_lock($operation) + { + return $operation ? flock($this->handle, $operation) : true; + } + + public function stream_seek($offset, $whence) + { + if (0 === fseek($this->handle, $offset, $whence)) { + $this->position = ftell($this->handle); + return true; + } + + return false; + } + + public function stream_tell() + { + return $this->position; + } + + public function stream_eof() + { + return feof($this->handle); + } + + public function stream_stat() + { + return array(); + } + + public function stream_set_option($option, $arg1, $arg2) + { + return true; + } + + public function url_stat($path, $flags) + { + $path = substr($path, 17); + if (file_exists($path)) { + return stat($path); + } + + return false; + } + } + } + + if ( + (function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true)) + || (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper')) + ) { + include("phpvfscomposer://" . __DIR__ . '/..'.'/vendor/squizlabs/php_codesniffer/bin/phpcs'); + exit(0); + } +} + +include __DIR__ . '/..'.'/vendor/squizlabs/php_codesniffer/bin/phpcs'; diff --git a/bin/phplint b/bin/phplint new file mode 100755 index 0000000..c6750bd --- /dev/null +++ b/bin/phplint @@ -0,0 +1,120 @@ +#!/usr/bin/env php +realpath = realpath($opened_path) ?: $opened_path; + $opened_path = $this->realpath; + $this->handle = fopen($this->realpath, $mode); + $this->position = 0; + + return (bool) $this->handle; + } + + public function stream_read($count) + { + $data = fread($this->handle, $count); + + if ($this->position === 0) { + $data = preg_replace('{^#!.*\r?\n}', '', $data); + } + + $this->position += strlen($data); + + return $data; + } + + public function stream_cast($castAs) + { + return $this->handle; + } + + public function stream_close() + { + fclose($this->handle); + } + + public function stream_lock($operation) + { + return $operation ? flock($this->handle, $operation) : true; + } + + public function stream_seek($offset, $whence) + { + if (0 === fseek($this->handle, $offset, $whence)) { + $this->position = ftell($this->handle); + return true; + } + + return false; + } + + public function stream_tell() + { + return $this->position; + } + + public function stream_eof() + { + return feof($this->handle); + } + + public function stream_stat() + { + return array(); + } + + public function stream_set_option($option, $arg1, $arg2) + { + return true; + } + + public function url_stat($path, $flags) + { + $path = substr($path, 17); + if (file_exists($path)) { + return stat($path); + } + + return false; + } + } + } + + if ( + (function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true)) + || (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper')) + ) { + include("phpvfscomposer://" . __DIR__ . '/..'.'/vendor/awesomemotive/am-cli-tools/bin/phplint'); + exit(0); + } +} + +include __DIR__ . '/..'.'/vendor/awesomemotive/am-cli-tools/bin/phplint'; diff --git a/bin/sniff b/bin/sniff new file mode 100755 index 0000000..9ec0606 --- /dev/null +++ b/bin/sniff @@ -0,0 +1,37 @@ +#!/usr/bin/env sh + +# Support bash to support `source` with fallback on $0 if this does not run with bash +# https://stackoverflow.com/a/35006505/6512 +selfArg="$BASH_SOURCE" +if [ -z "$selfArg" ]; then + selfArg="$0" +fi + +self=$(realpath $selfArg 2> /dev/null) +if [ -z "$self" ]; then + self="$selfArg" +fi + +dir=$(cd "${self%[/\\]*}" > /dev/null; cd '../vendor/fig-r/psr2r-sniffer/bin' && pwd) + +if [ -d /proc/cygdrive ]; then + case $(which php) in + $(readlink -n /proc/cygdrive)/*) + # We are in Cygwin using Windows php, so the path must be translated + dir=$(cygpath -m "$dir"); + ;; + esac +fi + +export COMPOSER_RUNTIME_BIN_DIR="$(cd "${self%[/\\]*}" > /dev/null; pwd)" + +# If bash is sourcing this file, we have to source the target as well +bashSource="$BASH_SOURCE" +if [ -n "$bashSource" ]; then + if [ "$bashSource" != "$0" ]; then + source "${dir}/sniff" "$@" + return + fi +fi + +"${dir}/sniff" "$@" diff --git a/bin/tag b/bin/tag new file mode 100755 index 0000000..5fd7804 --- /dev/null +++ b/bin/tag @@ -0,0 +1,120 @@ +#!/usr/bin/env php +realpath = realpath($opened_path) ?: $opened_path; + $opened_path = $this->realpath; + $this->handle = fopen($this->realpath, $mode); + $this->position = 0; + + return (bool) $this->handle; + } + + public function stream_read($count) + { + $data = fread($this->handle, $count); + + if ($this->position === 0) { + $data = preg_replace('{^#!.*\r?\n}', '', $data); + } + + $this->position += strlen($data); + + return $data; + } + + public function stream_cast($castAs) + { + return $this->handle; + } + + public function stream_close() + { + fclose($this->handle); + } + + public function stream_lock($operation) + { + return $operation ? flock($this->handle, $operation) : true; + } + + public function stream_seek($offset, $whence) + { + if (0 === fseek($this->handle, $offset, $whence)) { + $this->position = ftell($this->handle); + return true; + } + + return false; + } + + public function stream_tell() + { + return $this->position; + } + + public function stream_eof() + { + return feof($this->handle); + } + + public function stream_stat() + { + return array(); + } + + public function stream_set_option($option, $arg1, $arg2) + { + return true; + } + + public function url_stat($path, $flags) + { + $path = substr($path, 17); + if (file_exists($path)) { + return stat($path); + } + + return false; + } + } + } + + if ( + (function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true)) + || (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper')) + ) { + include("phpvfscomposer://" . __DIR__ . '/..'.'/vendor/awesomemotive/am-cli-tools/bin/tag'); + exit(0); + } +} + +include __DIR__ . '/..'.'/vendor/awesomemotive/am-cli-tools/bin/tag'; diff --git a/bin/tokenize b/bin/tokenize new file mode 100755 index 0000000..0047c93 --- /dev/null +++ b/bin/tokenize @@ -0,0 +1,37 @@ +#!/usr/bin/env sh + +# Support bash to support `source` with fallback on $0 if this does not run with bash +# https://stackoverflow.com/a/35006505/6512 +selfArg="$BASH_SOURCE" +if [ -z "$selfArg" ]; then + selfArg="$0" +fi + +self=$(realpath $selfArg 2> /dev/null) +if [ -z "$self" ]; then + self="$selfArg" +fi + +dir=$(cd "${self%[/\\]*}" > /dev/null; cd '../vendor/fig-r/psr2r-sniffer/bin' && pwd) + +if [ -d /proc/cygdrive ]; then + case $(which php) in + $(readlink -n /proc/cygdrive)/*) + # We are in Cygwin using Windows php, so the path must be translated + dir=$(cygpath -m "$dir"); + ;; + esac +fi + +export COMPOSER_RUNTIME_BIN_DIR="$(cd "${self%[/\\]*}" > /dev/null; pwd)" + +# If bash is sourcing this file, we have to source the target as well +bashSource="$BASH_SOURCE" +if [ -n "$bashSource" ]; then + if [ "$bashSource" != "$0" ]; then + source "${dir}/tokenize" "$@" + return + fi +fi + +"${dir}/tokenize" "$@" diff --git a/cmb2-woocommerce-hpos-orders.php b/cmb2-woocommerce-hpos-orders.php new file mode 100644 index 0000000..f2c175c --- /dev/null +++ b/cmb2-woocommerce-hpos-orders.php @@ -0,0 +1,159 @@ + + * @copyright 2016 CMB2 + * @license GPL-2.0+ + * @version 1.0.0 + * @link https://github.com/CMB2/cmb2-woocommerce-hpos-orders + * @since 1.2.3 + */ + +/** + * Copyright (c) 2016 CMB2 (email : info@cmb2.io) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2 or, at + * your discretion, any later version, as published by the Free + * Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * Loader versioning: http://jtsternberg.github.io/wp-lib-loader/ + */ + +if ( ! class_exists( 'CMB2_Woo_HPOS_Orders_127', false ) ) { + + /** + * Versioned loader class-name + * + * This ensures each version is loaded/checked. + * + * @category WordPressLibrary + * @package CMB2_Woo_HPOS_Orders + * @author CMB2 + * @license GPL-2.0+ + * @version 1.0.0 + * @link https://github.com/CMB2/cmb2-woocommerce-hpos-orders + * @since 1.0.0 + */ + class CMB2_Woo_HPOS_Orders_127 { + + /** + * CMB2_Woo_HPOS_Orders version number + * @var string + * @since 1.2.3 + */ + const VERSION = '1.0.0'; + + /** + * Current version hook priority. + * Will decrement with each release + * + * @var int + * @since 1.2.3 + */ + const PRIORITY = 9999; + + /** + * Starts the version checking process. + * Creates CMB2_WOO_HPOS_ORDERS_LOADED definition for early detection by + * other scripts. + * + * Hooks CMB2_Woo_HPOS_Orders inclusion to the cmb2_woo_hpos_orders_load hook + * on a high priority which decrements (increasing the priority) with + * each version release. + * + * @since 1.2.3 + */ + public function __construct() { + if ( ! defined( 'CMB2_WOO_HPOS_ORDERS_LOADED' ) ) { + /** + * A constant you can use to check if CMB2_Woo_HPOS_Orders is loaded + * for your plugins/themes with CMB2_Woo_HPOS_Orders dependency. + * + * Can also be used to determine the priority of the hook + * in use for the currently loaded version. + */ + define( 'CMB2_WOO_HPOS_ORDERS_LOADED', self::PRIORITY ); + } + + // Use the hook system to ensure only the newest version is loaded. + add_action( 'cmb2_woo_hpos_orders_load', array( $this, 'include_lib' ), self::PRIORITY ); + + // Use the hook system to ensure only the newest version is loaded. + add_action( 'after_setup_theme', array( $this, 'do_hook' ) ); + } + + /** + * Fires the cmb2_woo_hpos_orders_load action hook + * (from the after_setup_theme hook). + * + * @since 1.2.3 + */ + public function do_hook() { + // Then fire our hook. + do_action( 'cmb2_woo_hpos_orders_load' ); + } + + /** + * A final check if CMB2_Woo_HPOS_Orders exists before kicking off + * our CMB2_Woo_HPOS_Orders loading. + * + * CMB2_WOO_HPOS_ORDERS_VERSION and CMB2_WOO_HPOS_ORDERS_DIR constants are + * set at this point. + * + * @since 1.2.3 + */ + public function include_lib() { + if ( class_exists( 'CMB2_Woo_HPOS_Orders', false ) ) { + return; + } + + if ( ! defined( 'CMB2_WOO_HPOS_ORDERS_VERSION' ) ) { + /** + * Defines the currently loaded version of CMB2_Woo_HPOS_Orders. + */ + define( 'CMB2_WOO_HPOS_ORDERS_VERSION', self::VERSION ); + } + + if ( ! defined( 'CMB2_WOO_HPOS_ORDERS_DIR' ) ) { + /** + * Defines the directory of the currently loaded version of CMB2_Woo_HPOS_Orders. + */ + define( 'CMB2_WOO_HPOS_ORDERS_DIR', dirname( __FILE__ ) . '/' ); + } + + // Include and initiate CMB2_Woo_HPOS_Orders. + require_once CMB2_WOO_HPOS_ORDERS_DIR . 'init.php'; + } + + } + + // Kick it off. + new CMB2_Woo_HPOS_Orders_127; +} diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..5b16952 --- /dev/null +++ b/composer.json @@ -0,0 +1,43 @@ +{ + "name": "cmb2/woocommerce-hpos-orders", + "description": "Adds the ability to add custom fields to the new WooCommerce HPOS orders page.", + "license": "GPL-2.0+", + "authors": [ + { + "name": "CMB2", + "email": "info@cmb2.io", + "homepage": "https://github.com/CMB2", + "role": "Developer" + } + ], + "keywords": ["wordpress", "plugin", "metabox", "woocommerce", "hpos", "orders"], + "homepage": "https://github.com/CMB2/CMB2", + "type": "wordpress-plugin", + "support": { + "issues": "https://github.com/CMB2/cmb2-woocommerce-hpos-orders/issues", + "source": "https://github.com/CMB2/cmb2-woocommerce-hpos-orders/" + }, + "require": { + "php": ">7.0.0" + }, + "suggest": { + "composer/installers": "~1.0" + }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/awesomemotive/am-cli-tools" + } + ], + "config": { + "bin-dir": "bin", + "discard-changes": true, + "sort-packages": true, + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } + }, + "require-dev": { + "awesomemotive/am-cli-tools": ">=1.3.7" + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..06f98c6 --- /dev/null +++ b/composer.lock @@ -0,0 +1,541 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "8874f2736054c0e5621c93811527b9e0", + "packages": [], + "packages-dev": [ + { + "name": "awesomemotive/am-cli-tools", + "version": "1.3.7", + "source": { + "type": "git", + "url": "git@github.com:awesomemotive/am-cli-tools.git", + "reference": "dd93bad7e64589f4eb06e752cfd5d733baaf33ec" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/awesomemotive/am-cli-tools/zipball/dd93bad7e64589f4eb06e752cfd5d733baaf33ec", + "reference": "dd93bad7e64589f4eb06e752cfd5d733baaf33ec", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.2", + "fig-r/psr2r-sniffer": "^0.6.4", + "php": ">=5.6", + "phpcompatibility/php-compatibility": "^9.3", + "phpcompatibility/phpcompatibility-wp": "^2.1.3", + "sirbrillig/phpcs-variable-analysis": "^2.11.3", + "squizlabs/php_codesniffer": "^3.6.2", + "wp-coding-standards/wpcs": "^2.3" + }, + "bin": [ + "bin/tag", + "bin/phplint" + ], + "type": "library", + "autoload": { + "psr-4": { + "AwesomeMotive\\Cli\\Tools\\": "tools/" + } + }, + "scripts": { + "post-install-cmd": [ + "bash ./utils/setup-pre-commit-hook" + ] + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "AwesomeMotive", + "email": "dev@awesomemotive.com" + } + ], + "description": "Awesome Motive internal tooling for cli, git and other productivity tools.", + "support": { + "source": "https://github.com/awesomemotive/am-cli-tools/tree/v1.3.7", + "issues": "https://github.com/awesomemotive/am-cli-tools/issues" + }, + "time": "2022-12-29T18:22:58+00:00" + }, + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v0.7.2", + "source": { + "type": "git", + "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", + "reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db", + "reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "*", + "php-parallel-lint/php-parallel-lint": "^1.3.1", + "phpcompatibility/php-compatibility": "^9.0" + }, + "type": "composer-plugin", + "extra": { + "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + }, + { + "name": "Contributors", + "homepage": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcbf", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "support": { + "issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues", + "source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer" + }, + "time": "2022-02-04T12:51:07+00:00" + }, + { + "name": "fig-r/psr2r-sniffer", + "version": "0.6.4", + "source": { + "type": "git", + "url": "https://github.com/php-fig-rectified/psr2r-sniffer.git", + "reference": "e1f0975404ab4744f13f16ac041b6551ef9ecd7a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig-rectified/psr2r-sniffer/zipball/e1f0975404ab4744f13f16ac041b6551ef9ecd7a", + "reference": "e1f0975404ab4744f13f16ac041b6551ef9ecd7a", + "shasum": "" + }, + "require": { + "php": ">=5.6", + "squizlabs/php_codesniffer": "^3.5.0" + }, + "bin": [ + "bin/tokenize", + "bin/sniff" + ], + "type": "phpcodesniffer-standard", + "autoload": { + "psr-4": { + "PSR2R\\": "PSR2R/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mark Scherer", + "homepage": "https://www.dereuromark.de", + "role": "Contributor" + } + ], + "description": "Code-Sniffer, Auto-Fixer and Tokenizer for PSR2-R", + "keywords": [ + "codesniffer", + "cs" + ], + "support": { + "issues": "https://github.com/php-fig-rectified/psr2r-sniffer/issues", + "source": "https://github.com/php-fig-rectified/psr2r-sniffer/tree/master" + }, + "time": "2019-11-28T21:22:29+00:00" + }, + { + "name": "phpcompatibility/php-compatibility", + "version": "9.3.5", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibility.git", + "reference": "9fb324479acf6f39452e0655d2429cc0d3914243" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibility/zipball/9fb324479acf6f39452e0655d2429cc0d3914243", + "reference": "9fb324479acf6f39452e0655d2429cc0d3914243", + "shasum": "" + }, + "require": { + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.3 || ^3.0.2" + }, + "conflict": { + "squizlabs/php_codesniffer": "2.6.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.5 || ^5.0 || ^6.0 || ^7.0" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "homepage": "https://github.com/wimg", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCompatibility/PHPCompatibility/graphs/contributors" + } + ], + "description": "A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.", + "homepage": "http://techblog.wimgodden.be/tag/codesniffer/", + "keywords": [ + "compatibility", + "phpcs", + "standards" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibility/issues", + "source": "https://github.com/PHPCompatibility/PHPCompatibility" + }, + "time": "2019-12-27T09:44:58+00:00" + }, + { + "name": "phpcompatibility/phpcompatibility-paragonie", + "version": "1.3.2", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie.git", + "reference": "bba5a9dfec7fcfbd679cfaf611d86b4d3759da26" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/bba5a9dfec7fcfbd679cfaf611d86b4d3759da26", + "reference": "bba5a9dfec7fcfbd679cfaf611d86b4d3759da26", + "shasum": "" + }, + "require": { + "phpcompatibility/php-compatibility": "^9.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7", + "paragonie/random_compat": "dev-master", + "paragonie/sodium_compat": "dev-master" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "lead" + } + ], + "description": "A set of rulesets for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by the Paragonie polyfill libraries.", + "homepage": "http://phpcompatibility.com/", + "keywords": [ + "compatibility", + "paragonie", + "phpcs", + "polyfill", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/issues", + "source": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie" + }, + "time": "2022-10-25T01:46:02+00:00" + }, + { + "name": "phpcompatibility/phpcompatibility-wp", + "version": "2.1.4", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git", + "reference": "b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5", + "reference": "b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5", + "shasum": "" + }, + "require": { + "phpcompatibility/php-compatibility": "^9.0", + "phpcompatibility/phpcompatibility-paragonie": "^1.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "lead" + } + ], + "description": "A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.", + "homepage": "http://phpcompatibility.com/", + "keywords": [ + "compatibility", + "phpcs", + "standards", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibilityWP/issues", + "source": "https://github.com/PHPCompatibility/PHPCompatibilityWP" + }, + "time": "2022-10-24T09:00:36+00:00" + }, + { + "name": "sirbrillig/phpcs-variable-analysis", + "version": "v2.11.17", + "source": { + "type": "git", + "url": "https://github.com/sirbrillig/phpcs-variable-analysis.git", + "reference": "3b71162a6bf0cde2bff1752e40a1788d8273d049" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sirbrillig/phpcs-variable-analysis/zipball/3b71162a6bf0cde2bff1752e40a1788d8273d049", + "reference": "3b71162a6bf0cde2bff1752e40a1788d8273d049", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "squizlabs/php_codesniffer": "^3.5.6" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || ^1.0", + "phpcsstandards/phpcsdevcs": "^1.1", + "phpstan/phpstan": "^1.7", + "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.5 || ^7.0 || ^8.0 || ^9.0", + "sirbrillig/phpcs-import-detection": "^1.1", + "vimeo/psalm": "^0.2 || ^0.3 || ^1.1 || ^4.24 || ^5.0@beta" + }, + "type": "phpcodesniffer-standard", + "autoload": { + "psr-4": { + "VariableAnalysis\\": "VariableAnalysis/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Sam Graham", + "email": "php-codesniffer-variableanalysis@illusori.co.uk" + }, + { + "name": "Payton Swick", + "email": "payton@foolord.com" + } + ], + "description": "A PHPCS sniff to detect problems with variables.", + "keywords": [ + "phpcs", + "static analysis" + ], + "support": { + "issues": "https://github.com/sirbrillig/phpcs-variable-analysis/issues", + "source": "https://github.com/sirbrillig/phpcs-variable-analysis", + "wiki": "https://github.com/sirbrillig/phpcs-variable-analysis/wiki" + }, + "time": "2023-08-05T23:46:11+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.7.2", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ed8e00df0a83aa96acf703f8c2979ff33341f879", + "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", + "source": "https://github.com/squizlabs/PHP_CodeSniffer", + "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + }, + "time": "2023-02-22T23:07:41+00:00" + }, + { + "name": "wp-coding-standards/wpcs", + "version": "2.3.0", + "source": { + "type": "git", + "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", + "reference": "7da1894633f168fe244afc6de00d141f27517b62" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/7da1894633f168fe244afc6de00d141f27517b62", + "reference": "7da1894633f168fe244afc6de00d141f27517b62", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "squizlabs/php_codesniffer": "^3.3.1" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || ^0.6", + "phpcompatibility/php-compatibility": "^9.0", + "phpcsstandards/phpcsdevtools": "^1.0", + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.6 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/WordPress/WordPress-Coding-Standards/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions", + "keywords": [ + "phpcs", + "standards", + "wordpress" + ], + "support": { + "issues": "https://github.com/WordPress/WordPress-Coding-Standards/issues", + "source": "https://github.com/WordPress/WordPress-Coding-Standards", + "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki" + }, + "time": "2020-05-13T23:57:56+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">7.0.0" + }, + "platform-dev": [], + "plugin-api-version": "2.3.0" +} diff --git a/example-field-setup.php b/example-field-setup.php new file mode 100644 index 0000000..c81ccd7 --- /dev/null +++ b/example-field-setup.php @@ -0,0 +1,44 @@ + 'yourprefix_woocommerce_orders_page', + 'title' => esc_html__( 'Order Stuff', 'cmb2' ), + 'desc' => __FILE__, + 'object_types' => array( 'woocommerce_page_wc-orders' ), + ) ); + + $cmb_woo_orders->add_field( array( + 'name' => '👋', + 'id' => 'yourprefix_woo_orders_title', + 'type' => 'title', + ) ); + + $cmb_woo_orders->add_field( array( + 'name' => esc_html__( 'Some other color', 'cmb2' ), + 'desc' => esc_html__( 'field description (optional)', 'cmb2' ), + 'id' => 'yourprefix_woo_orders_other_color', + 'type' => 'colorpicker', + 'default' => '#ffffff', + ) ); + + $cmb_woo_orders->add_field( array( + 'name' => __( 'Test Text', 'cmb2' ), + 'desc' => __( 'field description (optional)', 'cmb2' ), + 'id' => 'yourprefix_woo_orders_text', + 'type' => 'text', + ) ); +} +add_action( 'cmb2_admin_init', 'yourprefix_register_woocommerce_orders_metabox' ); diff --git a/includes/CMB2_Woo_Order.php b/includes/CMB2_Woo_Order.php new file mode 100644 index 0000000..7e60e18 --- /dev/null +++ b/includes/CMB2_Woo_Order.php @@ -0,0 +1,208 @@ +get_id(); + if ( ! isset( self::$instances[ $id ] ) ) { + new self( $id ); + } + + self::$instances[ $id ]->set_order( $order ); + + } elseif ( ! empty( $id->ID ) ) { + $id = (int) $id->ID; + } else { + $id = (int) $id; + } + + if ( ! $cached || ! isset( self::$instances[ $id ] ) ) { + $me = new self( $id ); + $me->fetch_and_set_order(); + } + + return self::$instances[ $id ]; + } + + /** + * Class constructor. + * + * @since {{next}} + * + * @param string $id The order ID. + */ + protected function __construct( $id = '' ) { + + // If no data has been passed, don't setup anything. Maybe we are in test or create mode? + if ( empty( $id ) ) { + return; + } + + // Prepare properties. + $this->id = $id; + + self::$instances[ $id ] = $this; + } + + /** + * Fetches the order object and sets it. + * + * @since {{next}} + * + * @return self + */ + protected function fetch_and_set_order() { + $this->set_order( wc_get_order( $this->id ) ); + + return $this; + } + + /** + * Sets the order object. + * + * @since {{next}} + * + * @param WC_Order $order The order object. + * + * @return self + */ + protected function set_order( $order ) { + $this->order = $order; + + return $this; + } + + /** + * Checks if the order exists/is valid. + * + * @since {{next}} + * + * @return boolean + */ + public function is() { + if ( empty( $this->order ) ) { + return false; + } + $id = $this->order->get_id(); + + return ! empty( $id ); + } + + /** + * Gets order meta, use HPOS API when possible. + * + * @since {{next}} + * + * @param string $key Meta Key. + * @param bool $single return first found meta with key, or all with $key. + * @param string $context What the value is for. Valid values are view and edit. + * @return mixed + */ + public function get_meta( $key = '', $single = true, $context = 'edit' ) { + return ! empty( $this->order ) && method_exists( $this->order, 'get_meta' ) + ? $this->order->get_meta( $key, $single, $context ) + : get_post_meta( $this->id, $key, $single ); + } + + /** + * Updates order meta, use HPOS API when possible. + * + * If using HPOS, can pass $save = false to not save the order (for bulk updates). + * + * @since {{next}} + * + * @param string $key The meta key. + * @param mixed $value The meta value. + * @param bool $save Whether to save the order after meta update (if using HPOS). + * + * @return boolean + */ + public function update_meta_data( $key, $value, $save = true ) { + if ( ! empty( $this->order ) && method_exists( $this->order, 'update_meta_data' ) ) { + $this->order->update_meta_data( $key, $value ); + return $save ? $this->order->save() : false; + } + + return update_post_meta( $this->id, $key, $value ); + } + + public function delete_meta_data( $key, $save = true ) { + if ( ! empty( $this->order ) && method_exists( $this->order, 'delete_meta_data' ) ) { + $this->order->delete_meta_data( $key ); + return $save ? $this->order->save() : false; + } + + return delete_post_meta( $this->id, $key ); + } + + /** + * Proxy calls to the order object. + * + * @since {{next}} + * + * @param string $method The method name. + * @param array $args The method arguments. + * + * @return mixed + */ + public function __call( $method, $args ) { + return $this->order + ? call_user_func_array( array( $this->order, $method ), $args ) + : null; + } +} diff --git a/includes/CMB2_Woo_Orders_Hookup.php b/includes/CMB2_Woo_Orders_Hookup.php new file mode 100644 index 0000000..fc5c3af --- /dev/null +++ b/includes/CMB2_Woo_Orders_Hookup.php @@ -0,0 +1,209 @@ +cmb = $cmb; + } + + /** + * Hook in and add metaboxes, override meta values, and save meta values, etc. + * + * @since {{next}} + * @return void + */ + public function hooks() { + add_action( 'add_meta_boxes', array( $this, 'add_metaboxes' ) ); + add_filter( 'cmb2_should_pre_enqueue', array( $this, 'maybe_pre_enqueue' ), 10, 2 ); + add_action( 'woocommerce_process_shop_order_meta', array( $this, 'save_order' ), 10, 2 ); + add_filter( 'cmb2_override_meta_value', array( $this, 'get_order_meta' ), 10, 3 ); + add_filter( 'cmb2_override_meta_save', array( $this, 'update_order_meta' ), 10, 2 ); + add_filter( 'cmb2_override_meta_remove', array( $this, 'remove_order_meta' ), 10, 2 ); + } + + /** + * If the current page is the object type, pre-enqueue the CMB2 scripts/styles. + * + * @since {{next}} + * @param bool $should_pre_enqueue Whether to pre-enqueue. + * @param string $hook The current page hook. + * @return bool + */ + public function maybe_pre_enqueue( $should_pre_enqueue, $hook ) { + if ( $this->object_type === $hook ) { + $should_pre_enqueue = true; + } + + return $should_pre_enqueue; + } + + /** + * Save the order meta. + * + * @since {{next}} + * + * @param int $order_id The order ID. + * @param WC_Order $order The order object. + * + * @return void + */ + public function save_order( $order_id, $order ) { + // Cache the order object. + $this->get_order( $order ); + + // check permissions. + if ( $this->can_save( $this->object_type ) ) { + $this->cmb->save_fields( $order_id, $this->object_type, wp_unslash( $_POST ) ); + } + } + + /** + * Get the order meta. + * + * @since {{next}} + * + * @param mixed $data The meta value. + * @param int $object_id The object ID. + * @param string $args The field args. + * + * @return mixed + */ + public function get_order_meta( $data, $object_id, $args ) { + $order = $this->get_order( $object_id ); + if ( ! $order->is() ) { + return $data; + } + + return $order->get_meta( $args['field_id'], true, 'edit' ); + } + + /** + * Update the order meta. + * + * @since {{next}} + * + * @param bool|array $override Whether to override the meta value. + * @param array $args The field args. + * + * @return bool + */ + public function update_order_meta( $override, $args ) { + $order = $this->get_order( $args['id'] ); + if ( ! $order->is() ) { + return $override; + } + + $order->update_meta_data( $args['field_id'], $args['value'], false ); + + add_action( "cmb2_save_{$this->object_type}_fields_{$this->cmb->cmb_id}", array( $this, 'save_order_meta_changes' ), 10, 2 ); + + return true; + } + + /** + * Remove the order meta. + * + * @since {{next}} + * + * @param bool|array $override Whether to override the meta value. + * @param array $args The field args. + * + * @return bool + */ + public function remove_order_meta( $override, $args ) { + $order = $this->get_order( $args['id'] ); + if ( ! $order->is() ) { + return $override; + } + + $order->delete_meta_data( $args['field_id'], false ); + + add_action( "cmb2_save_{$this->object_type}_fields_{$this->cmb->cmb_id}", array( $this, 'save_order_meta_changes' ), 10, 2 ); + + return true; + } + + /** + * Trigger the save of the order meta. + * + * @since {{next}} + * + * @param int $object_id The object ID. + * @param array $updated The updated fields. + * + * @return void + */ + public function save_order_meta_changes( $object_id, $updated ) { + if ( empty( $updated ) ) { + return; + } + + $order = $this->get_order( $object_id ); + if ( ! $order->is() ) { + return; + } + + $order->save(); + } + + /** + * Get the order object and load the CMB2_Woo_Order class if needed. + * + * @since {{next}} + * + * @param int|WC_Order $id The order ID or object. + * + * @return CMB2_Woo_Order + */ + public function get_order( $id ) { + if ( ! class_exists( 'CMB2_Woo_Order', false ) ) { + require_once __DIR__ . '/CMB2_Woo_Order.php'; + } + + return CMB2_Woo_Order::get( $id ); + + } + /** + * Magic getter for our object. + * + * @since {{next}} + * + * @param string $field Property to retrieve. + * + * @throws Exception Throws an exception if the field is invalid. + * @return mixed + */ + public function __get( $field ) { + switch ( $field ) { + case 'object_type': + case 'cmb': + return $this->{$field}; + default: + throw new Exception( sprintf( 'Invalid %1$s property: %2$s', __CLASS__, $field ) ); + } + } +} diff --git a/init.php b/init.php new file mode 100644 index 0000000..b1128d8 --- /dev/null +++ b/init.php @@ -0,0 +1,121 @@ +wooorders_hookup = new CMB2_Woo_Orders_Hookup( $hookup->cmb ); + $this->wooorders_hookup->hooks(); + + return $this; + } + + /** + * Hook in and update the object id if on the orders page. + * + * @since {{next}} + * + * @param int $object_id The object ID. + * @param CMB2 $cmb The CMB2 object. + * + * @return int + */ + public function set_order_object_id( $object_id, $cmb ) { + // Try to get our object ID from the global space. + if ( self::OBJECT_TYPE === $cmb->object_type() ) { + $object_id = isset( $_REQUEST['id'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ) : $object_id; + } + + return $object_id; + } + + /** + * Hook in and update the box object type if on the orders page. + * + * @since {{next}} + * + * @param string $mb_object_type The metabox object type. + * @param string $found_type The found object type. + * + * @return string + */ + public function set_box_object_type( $mb_object_type, $found_type ) { + if ( self::OBJECT_TYPE === $found_type ) { + $mb_object_type = $found_type; + } + + return $mb_object_type; + } + + /** + * Magic getter for our object. + * + * @param string $field Property to return. + * @throws Exception Throws an exception if the field is invalid. + * @return mixed + */ + public function __get( $field ) { + return $this->{$field}; + } +} +CMB2_Woo_HPOS_Orders::get_instance();