From 1e71139007c0244d4d2f8677c19663a184892b68 Mon Sep 17 00:00:00 2001 From: Woo Date: Tue, 23 Apr 2024 18:02:29 +0000 Subject: [PATCH] Updates to 2.5.0 --- .gitattributes | 7 + LICENSE.txt | 339 +++++++++ admin/assets/css/admin.css | 69 ++ admin/assets/css/index.php | 1 + admin/assets/js/index.php | 1 + admin/assets/js/main.js | 5 + ...s-woocommerce-role-based-methods-admin.php | 685 ++++++++++++++++++ admin/views/admin-payment.php | 95 +++ admin/views/admin-settings-tabs.php | 20 + admin/views/admin-shipping.php | 141 ++++ admin/views/flash-activation.php | 0 admin/views/flash-updated.php | 16 + admin/views/index.php | 1 + assets/index.php | 1 + changelog.txt | 114 +++ index.php | 1 + languages/index.php | 1 + .../class-woocommerce-role-based-methods.php | 358 +++++++++ public/views/index.php | 1 + public/views/public.php | 3 + readme.txt | 18 + uninstall.php | 37 + woo-includes/class-wc-dependencies.php | 28 + woo-includes/woo-functions.php | 97 +++ woocommerce-role-based-methods.php | 109 +++ 25 files changed, 2148 insertions(+) create mode 100644 .gitattributes create mode 100755 LICENSE.txt create mode 100644 admin/assets/css/admin.css create mode 100755 admin/assets/css/index.php create mode 100755 admin/assets/js/index.php create mode 100644 admin/assets/js/main.js create mode 100755 admin/class-woocommerce-role-based-methods-admin.php create mode 100644 admin/views/admin-payment.php create mode 100644 admin/views/admin-settings-tabs.php create mode 100755 admin/views/admin-shipping.php create mode 100644 admin/views/flash-activation.php create mode 100644 admin/views/flash-updated.php create mode 100755 admin/views/index.php create mode 100755 assets/index.php create mode 100644 changelog.txt create mode 100755 index.php create mode 100755 languages/index.php create mode 100755 public/class-woocommerce-role-based-methods.php create mode 100755 public/views/index.php create mode 100755 public/views/public.php create mode 100755 readme.txt create mode 100755 uninstall.php create mode 100755 woo-includes/class-wc-dependencies.php create mode 100755 woo-includes/woo-functions.php create mode 100755 woocommerce-role-based-methods.php diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fc22c98 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +# Ignore files when creating archive +/.idea export-ignore +/.editorconfig export-ignore +/.gitignore export-ignore +/composer.json export-ignore +/composer.lock export-ignore +/phpcs.xml export-ignore \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100755 index 0000000..ecbc059 --- /dev/null +++ b/LICENSE.txt @@ -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. + + + Copyright (C) + + 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. + + , 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/admin/assets/css/admin.css b/admin/assets/css/admin.css new file mode 100644 index 0000000..274c2de --- /dev/null +++ b/admin/assets/css/admin.css @@ -0,0 +1,69 @@ +/* BASE STYLES */ + +.role-methods-main-title { + margin: 40px 0; +} + +.paymentrolepanel { + float:left; + width:100%; + padding-right:20px; +} +.wc_shipping td { + padding: 10px; + width: 200px; +} + +.wc_shipping th strong { + color: #000; + font-size: 1.1em; +} + +.wc_shipping th { + color: #666; +} + +.roletd { + width:220px; +} + +/* GROUPS */ + +.group-settings { + display: none; +} + +.groups--visible { + display: block; +} + +.enable-groups-toggle { + margin-bottom: 20px; +} + +.enable-groups-toggle .groups-toggle { + margin-left: 5px; +} + +.widefat thead th { + border-bottom: 0; +} + +.wc_shipping .zone-heading { + border-left: 1px solid #e1e1e1; + border-bottom: 1px solid #e1e1e1; +} + +.wc_shipping th, +.wc_shipping td { + border-left: 1px solid #e1e1e1; +} + +.wc_shipping .zone-title { + border-bottom: 1px solid #e1e1e1; +} + +.shippingrolepanel { + max-width: 100%; + overflow: auto; +} diff --git a/admin/assets/css/index.php b/admin/assets/css/index.php new file mode 100755 index 0000000..e71af0e --- /dev/null +++ b/admin/assets/css/index.php @@ -0,0 +1 @@ + + * @license GPL-2.0+ + * @link http://woothemes.com/woocommerce + * @copyright 2015 WPBackOffice + */ + +/** + * @package WC_Role_Methods_Admin + * @author WPBackOffice + */ + +class WC_Role_Methods_Admin { + + /** + * Instance of this class. + * + * @since 2.0.0 + * + * @var object + */ + protected static $instance = null; + + /** + * Slug of the plugin screen. + * + * @since 2.0.0 + * + * @var string + */ + protected $plugin_screen_hook_suffix = null; + + /** + * Initialize the plugin by loading admin scripts & styles and adding a + * settings page and menu. + * + * @since 2.0.0 + */ + private function __construct() { + + $plugin = WC_Role_Methods::get_instance(); + $this->plugin_slug = $plugin->get_plugin_slug(); + + // Add the options page and menu item. + add_action( 'admin_menu', array( $this, 'add_roles_admin_menu' ) ); + add_action( 'admin_init', array($this, 'add_role_methods_save_flash')); + add_action( 'admin_enqueue_scripts', array($this, 'enqueue_admin_scripts' )); + + /* Add sanitaion case for role option */ + + add_filter( 'sanitize_option_woocommerce_payment_roles', array($this, 'sanitize_role_options'), 10, 2); + add_filter( 'sanitize_option_woocommerce_shipping_roles', array($this, 'sanitize_role_options'), 10, 2); + + /* Add sanitaion case for group option */ + + add_filter( 'sanitize_option_woocommerce_group_payment_roles', array($this, 'sanitize_group_options'), 10, 2); + add_filter( 'sanitize_option_woocommerce_group_shipping_roles', array($this, 'sanitize_group_options'), 10, 2); + + /* Add sanitaion case for general plugin options */ + + add_filter( 'sanitize_option_woocommerce_role_methods_options', array($this, 'sanitize_general_settings'), 10, 2); + + + } + + /** + * Clear any existing shipping quote transients, because the shipping + * when the shipping policies changes + * + * @since 2.0.5 + */ + private function clear_shipping_transients() { + if ( version_compare( WOOCOMMERCE_VERSION, '2.2.0', '>' ) ) { + wc_delete_product_transients(); + wc_delete_shop_order_transients(); + WC_Cache_Helper::get_transient_version( 'shipping', true ); + } else { + global $wpdb; + $sql = "DELETE FROM $wpdb->options WHERE option_name LIKE '%transient_timeout_wc_ship%' OR option_name LIKE '%transient_wc_ship%'"; + $wpdb->query( $sql ); + } + } + + /** + * Return true if the mollie gateway plugin is activated, false otherwise. + * + * @since 2.0.3 + * + * @return boolean + */ + + private function has_mollie() { + if(class_exists('WC_Mollie')) { + return true; + } else { + return false; + } + } + + /** + * Return true if shipping zones are supported. + * + * @since 2.1.0 + * + * @return boolean + */ + + private function supports_zones() { + return class_exists('WC_Shipping_Zone'); + } + + /** + * Return the methods' correct title + * + * @since 2.0.3 + * + * @return string + */ + public function get_col_title($method) { + if(isset($method->title)) { + $title = $method->title; + } elseif(isset($method->description)) { + $title = $method->description; + } else { + $title = 'Unknown Method'; + } + return $title; + } + + /* Display Settings Updated Flash When Role Method Settings are updated */ + + public function add_role_methods_save_flash() { + if(isset($_POST['settings-updated']) && $_POST['settings-updated']) { + add_action('admin_notices', array($this, 'save_role_methods_admin_notice')); + } + } + + /* Flash Updated Alert*/ + + public function save_role_methods_admin_notice(){ + include_once( 'views/flash-updated.php' ); + } + + /** + * Return an instance of this class. + * + * @since 2.0.0 + * + * @return object A single instance of this class. + */ + public static function get_instance() { + + // If the single instance hasn't been set, set it now. + if ( null == self::$instance ) { + self::$instance = new self; + } + + return self::$instance; + } + + /** + * Register and enqueue role-methods specific scripts. + * + * @since 2.0.0 + * + * @return null Return early if no settings page is registered. + */ + public function enqueue_admin_scripts() { + + if ( ! isset( $this->plugin_screen_hook_suffix ) ) { + return; + } + + $screen = get_current_screen(); + if ( $this->plugin_screen_hook_suffix == $screen->id ) { + wp_enqueue_style( $this->plugin_slug .'-admin-styles', plugins_url( 'assets/css/admin.css', __FILE__ ), array(), WC_Role_Methods::VERSION ); + wp_enqueue_script( $this->plugin_slug .'-admin-scripts', plugins_url( 'assets/js/main.js', __FILE__ ), array(), WC_Role_Methods::VERSION ); + } + } + + /** + * Register the administration menu for this plugin into the WordPress Dashboard menu. + * + * @since 2.0.0 + */ + public function add_roles_admin_menu() { + $this->plugin_screen_hook_suffix = add_submenu_page('woocommerce', __( 'Role Based Methods', 'woocommerce-role-based-methods-settings' ), __( 'Role Based Methods', 'woocommerce-role-based-methods' ), 'manage_woocommerce', 'woocommerce-role-based-methods-settings', array($this, 'display_woocommerce_role_based_methods_settings' )); + } + + /** + * Print single Shipping row with all methods, for a specific roll. + * + * @param string $role Role row to print. + * @param array $shipping_zones Zones to iterate over. + * @param array $methodarray Stored settings for the role based methods plugin. + */ + function print_shipping_row( $role, $shipping_zones, $methodarray ) { + echo ''; + echo '' . esc_attr( ucfirst( $role ) ) . ''; + + if (isset($methodarray[$role])) { + foreach ($methodarray[$role] as $method_id => $value) { + if (count(explode(':', $method_id)) === 1) { + unset($methodarray[$role][$method_id]); + $methodarray[$role][$method_id . ':0'] = $value; + } + } + } + + foreach ( $shipping_zones as $shipping_zone ) { + + foreach ( $shipping_zone['shipping_methods'] as $instance_id => $shipping_method ) { + if ( ! $shipping_method->supports( 'shipping-zones' ) ) { + $id = implode( ':', array( + $shipping_method->id, + $shipping_method->get_instance_id() + )); + } elseif ( method_exists( $shipping_method, 'get_rate_id' ) ) { + $id = $shipping_method->get_rate_id(); + } else { + $id = $shipping_method->id . ':' . $instance_id; + } + + if ( + ( + isset( $methodarray[ $role ][ $id ] ) + && 'on' == $methodarray[ $role ][ $id ] + ) + || false == $methodarray ) { + $checked = ' checked '; + } else { + $checked = ''; + } + + echo ""; + } + } + echo ''; + } + + /** + * Get the title for the method. Title is a user supplied version, method_title is used as a fallback + * + * @param obj $method Method + * + * @return string + */ + function get_shipping_method_title($method) { + if ( isset( $method->title ) ) { + return $method->title; + } + + if ( method_exists( $method, 'get_method_title' ) ) { + return $method->get_method_title(); + } + + return ''; + } + + + /** + * Print single Shipping row with all methods, for a specific group. + * + * @param string $group Group row to print. + * @param array $shipping_zones Available Shipping Zones. + * @param array $group_methodarray Stored settings for the group. + */ + function print_shipping_group_row( $group, $shipping_zones, $group_methodarray ) { + echo ''; + echo '

' . esc_attr( ucfirst( $group->name ) ) . '

'; + + $group_id = $group->group_id; + foreach ( $shipping_zones as $shipping_zone ) { + foreach ( $shipping_zone['shipping_methods'] as $instance_id => $method ) { + if ( method_exists( $method, 'get_rate_id' ) ) { + $id = $method->get_rate_id(); + } else { + $id = $method->id . ':' . $instance_id; + } + + if ( ( isset( $group_methodarray[ $group_id ][ $id ] ) && 'on' == $group_methodarray[ $group_id ][ $id ] ) || false == $group_methodarray ) { + $checked = ' checked '; + } else { + $checked = ''; + } + + echo ""; + } + } + + echo ''; + } + + /** + * Print single Gateway row with all gateways for a specific $roll. + * + * @param string $roll Role identity row to print. + * @param array $shipping_methods + * @param array $methodarray + */ + function print_gateway_row($roll, $payment_methods, $gatewayarray) { + + echo "

" . ucfirst($roll) . "

"; + foreach($payment_methods as $g): + + if ( ( isset( $gatewayarray[ $roll ][ $g->id ] ) && $gatewayarray[ $roll ][ $g->id ] == 'on' ) || $gatewayarray == false ) + $checked=' checked '; + else + $checked=''; + + echo ""; + + endforeach; + echo ""; + } + + /** + * Print single Gateway row with all gateways for a specific group. + * + * @param string $roll Role identity row to print. + * @param array $shipping_methods + * @param array $methodarray + */ + function print_group_gateway_row($group, $payment_methods, $group_gatewayarray) { + echo "

" . $group->name . "

"; + foreach($payment_methods as $g): + + if ( ( isset( $group_gatewayarray[ $group->group_id ][ $g->id ] ) && $group_gatewayarray[ $group->group_id ][ $g->id ] == 'on' ) || $group_gatewayarray == false ) + $checked=' checked '; + else + $checked=''; + + echo ""; + + endforeach; + echo ""; + } + + /** + * Render the settings page for the shipping methods page + * + * @since 2.0.3 + */ + + /* https://gist.github.com/esthezia/5804445 */ + public function display_woocommerce_payment_page() { + global $woocommerce; + global $wp_roles; + + // Clean post variable + $posted = $this->clean_multidimensional_array($_POST); + + // Check the user capabilities + if ( !current_user_can( 'manage_woocommerce' ) ) { + wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce-payment_shipping' ) ); + } + + if ( isset( $posted['payment_is_enabled'] ) ) { + update_option( 'woocommerce_payment_roles', $posted['payment_is_enabled'] ); + } + + if ( isset( $posted['group_payment_is_enabled'] ) ) { + update_option( 'woocommerce_group_payment_roles', $posted['group_payment_is_enabled'] ); + } + + if ( isset( $posted['woocommerce_role_methods_options'] ) && is_array($posted['woocommerce_role_methods_options'])) { + $current_options = get_option('woocommerce_role_methods_options'); + foreach($posted['woocommerce_role_methods_options'] as $option => $value) { + $current_options[wc_clean($option)] = wc_clean($value); + } + + if(!isset($posted['woocommerce_role_methods_options']['pay-groups-enable'])) { + $current_options['pay-groups-enable'] = 'No'; + } else { + $current_options['pay-groups-enable'] = 'Yes'; + } + + update_option( 'woocommerce_role_methods_options', $current_options ); + } + + $payment_methods = $this->get_all_payment_methods(); + + $gatewayarray = get_option('woocommerce_payment_roles'); + $group_gatewayarray = get_option('woocommerce_group_payment_roles'); + + $groups = $this->get_all_groups(); + $options = get_option('woocommerce_role_methods_options'); + + include_once( 'views/admin-payment.php' ); + } + + public function get_all_payment_methods() { + global $woocommerce; + $payment_methods_loaded = $woocommerce->payment_gateways->payment_gateways; + + $payment_methods = array(); + foreach($payment_methods_loaded as $method){ + if ($method->enabled == 'yes') { + if($method->title == 'Mollie' && $this->has_mollie()) { + $instance = $GLOBALS['wc_mollie']; + $gateway = $instance->get_gateway(); + $methods = $gateway->get_methods(); + foreach($methods as $method) { + $method->id = 'mollie_' . $method->id; + $method->description = $method->description . ' (Mollie)'; + $payment_methods[] = $method; + } + } else { + $payment_methods[] = $method; + } + } + } + return $payment_methods; + } + + public function get_all_payment_method_slugs() { + $payment_methods = $this->get_all_payment_methods(); + $slugs = array(); + foreach($payment_methods as $method){ + $slugs[] = $method->id; + } + return $slugs; + } + + /** + * Render the settings page for the payment methods page. + * + * @since 2.0.0 + */ + public function display_woocommerce_shipping_page() { + + global $woocommerce; + global $wp_roles; + + $posted = $this->clean_multidimensional_array($_POST); + + // Check the user capabilities + if ( !current_user_can( 'manage_woocommerce' ) ) { + wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce-payment_shipping' ) ); + } + + if ( isset( $posted['shipping_is_enabled'] ) ) { + $uploaded_shipping_options = $posted['shipping_is_enabled']; + $current_shipping_options = get_option('woocommerce_shipping_roles'); + if($uploaded_shipping_options != $current_shipping_options) { + update_option( 'woocommerce_shipping_roles', $uploaded_shipping_options ); + $this->clear_shipping_transients(); + } + } + + if ( isset( $posted['group_shipping_is_enabled'] ) ) { + update_option( 'woocommerce_group_shipping_roles', $posted['group_shipping_is_enabled'] ); + } + + if ( isset( $posted['woocommerce_role_methods_options'] ) && is_array($posted['woocommerce_role_methods_options'])) { + $current_options = get_option('woocommerce_role_methods_options'); + foreach($posted['woocommerce_role_methods_options'] as $option => $value) { + $current_options[wc_clean($option)] = wc_clean($value); //Sanitize the key and value + } + + if(!isset($posted['woocommerce_role_methods_options']['ship-groups-enable'])) { + $current_options['ship-groups-enable'] = 'No'; + } else { + $current_options['ship-groups-enable'] = 'Yes'; + } + + update_option( 'woocommerce_role_methods_options', $current_options ); + } + + + $shipping_zones = $this->get_shipping_zones(); + + $methodarray = get_option('woocommerce_shipping_roles'); + $group_methodarray = get_option('woocommerce_group_shipping_roles'); + + $groups = $this->get_all_groups(); + $options = get_option('woocommerce_role_methods_options'); + include_once( 'views/admin-shipping.php' ); + } + + + public function get_shipping_zones() { + $zones = array(); + $no_zone_methods = array(); + + // Get all shipping methods + $all_shippping_methods = wc()->shipping->get_shipping_methods(); + + // If they don't support zones, add them to a 'none' zone. + foreach ( $all_shippping_methods as $shipping_method ) { + if ( ! $shipping_method->supports( 'shipping-zones' ) ) { + $no_zone_methods[] = $shipping_method; + } + } + + if (class_exists('WC_Shipping_Zone')) { + + // Rest of the World zone + $zone = new WC_Shipping_Zone(0); + $zones[ $zone->get_id() ] = $zone->get_data(); + $zones[ $zone->get_id() ]['formatted_zone_location'] = $zone->get_formatted_location(); + $zones[ $zone->get_id() ]['shipping_methods'] = array_merge( $zone->get_shipping_methods(), $no_zone_methods ); + + // Add user configured zones + $zones = array_merge( $zones, WC_Shipping_Zones::get_zones() ); + } + + return $zones; + } + + public function get_site_roles() { + global $wp_roles; + $site_roles = $wp_roles->get_names(); + return array_keys($site_roles); + } + + /** + * Validate posted roles options + * + * @since 2.0.6 + */ + + public function sanitize_role_options( $updated_value, $option_name) { + $validation_passed = true; + + if(!isset($updated_value) || !is_array($updated_value)) { + $validation_passed = false; + } + + //Now loop through the array to make sure everything is valid. + + foreach($updated_value as $role => $role_settings) { + + // Validate the key (payment method) first. + if(!is_string($role)) { + $validation_passed = false; + } + + //Next, validate the value, + + if(is_array($role_settings)) { + foreach($role_settings as $method => $setting) { + if(!is_scalar($method)) { + $validation_passed = false; + } + + if($setting != 'on') { + $validation_passed = false; + } + } + } else { + $validation_passed = false; + } + } + //If everything checks out, return the new value. + if($validation_passed) { + return $updated_value; + } else { + $original_option_value = get_option( $option_name ); + return $original_option_value; + } + } + + /** + * Validate posted groups options + * + * @since 2.0.6 + */ + + public function sanitize_group_options( $updated_value, $option_name) { + $validation_passed = true; + + if(!isset($updated_value) || !is_array($updated_value)) { + $validation_passed = false; + } + + //Now loop through the array to make sure everything is valid. + + foreach($updated_value as $group => $group_settings) { + + // Validate the key (payment method) first. + if(!is_int($group)) { + $validation_passed = false; + } + + //Next, validate the value, + + if(is_array($group_settings)) { + foreach($group_settings as $method => $setting) { + if(!is_scalar($method)) { + $validation_passed = false; + } + + if($setting != 'on') { + $validation_passed = false; + } + } + } else { + $validation_passed = false; + } + } + //If everything checks out, return the new value. + if($validation_passed) { + return $updated_value; + } else { + $original_option_value = get_option( $option_name ); + return $original_option_value; + } + } + + /** + * Verify all the roles and methods exist and the options array is in good shape before saving the option + * + * @since 2.0.6 + */ + + public function sanitize_general_settings( $updated_value, $option_name ) { + $validation_passed = true; + + if(!isset($updated_value) || !is_array($updated_value)) { + $validation_passed = false; + } + + //Now loop through the array to make sure everything is valid. + + foreach($updated_value as $setting_label => $setting_value) { + + // Validate the key (payment method) first. + if(!is_string($setting_label) || !is_string($setting_value)) { + $validation_passed = false; + } + } + + //If everything checks out, return the new value. + if($validation_passed) { + return $updated_value; + } else { + $original_option_value = get_option( $option_name ); + return $original_option_value; + } + } + + public function display_woocommerce_role_based_methods_settings() { + + include_once( 'views/admin-settings-tabs.php' ); + + if((isset($_GET['tab']) && $_GET['tab'] == 'pay-role-gateways') || !isset($_GET['tab'])) { + $this->display_woocommerce_payment_page(); + + } elseif(isset($_GET['tab']) && $_GET['tab'] == 'ship-role-methods') { + $this->display_woocommerce_shipping_page(); + } + } + + function get_all_groups() { + global $wpdb; + if( function_exists('_groups_get_tablename')){ + $groups_table = _groups_get_tablename( 'group' ); + return $wpdb->get_results( "SELECT * FROM $groups_table ORDER BY name" ); + } else { + return false; + } + } + + /* Based on https://gist.github.com/esthezia/5804445 */ + + private function clean_multidimensional_array ($data = array()) { + if (!is_array($data) || !count($data)) { + return array(); + } + foreach ($data as $k => $v) { + if (!is_array($v) && !is_object($v)) { + $data[$k] = wc_clean($v); + } + if (is_array($v)) { + $data[$k] = $this->clean_multidimensional_array($v); + } + } + return $data; + } +} diff --git a/admin/views/admin-payment.php b/admin/views/admin-payment.php new file mode 100644 index 0000000..2b566f1 --- /dev/null +++ b/admin/views/admin-payment.php @@ -0,0 +1,95 @@ + + * @license GPL-2.0+ + * @link http://woothemes.com/woocommerce + * @copyright 2015 WPBackOffice + */ +?> + +
+

+ +

+

+ +

+
+
+ + + + + + + + + + + get_names() as $roll): ?> + print_gateway_row(strtolower($roll), $payment_methods, $gatewayarray); ?> + + print_gateway_row("Guest", $payment_methods, $gatewayarray); ?> + + +
 

get_col_title($method); ?>

+
+ +
+ +

+ +
+ +
+ +
groups--visible "> + + + + + +

+ +

+ +
+ + + + + + + + + + + + print_group_gateway_row($group, $payment_methods, $group_gatewayarray); ?> + + +
 

title; ?>

+
+
+ + +
+

+ ' /> + +

+
+
diff --git a/admin/views/admin-settings-tabs.php b/admin/views/admin-settings-tabs.php new file mode 100644 index 0000000..3bb7722 --- /dev/null +++ b/admin/views/admin-settings-tabs.php @@ -0,0 +1,20 @@ + + * @license GPL-2.0+ + * @link http://woothemes.com/woocommerce + * @copyright 2015 WPBackOffice + */ +?> +

+ +

+ + \ No newline at end of file diff --git a/admin/views/admin-shipping.php b/admin/views/admin-shipping.php new file mode 100755 index 0000000..aec04b2 --- /dev/null +++ b/admin/views/admin-shipping.php @@ -0,0 +1,141 @@ + + * @license GPL-2.0+ + * @link http://woothemes.com/woocommerce + * @copyright 2015 WPBackOffice + */ + +?> + +
+

+ + +

+ +

+ +
+
+ + + + + + 0 ) : ?> + + + + + + + + + + + + + + + + get_names() as $roll ) : ?> + print_shipping_row( strtolower( $roll ), $shipping_zones, $methodarray ); ?> + + + print_shipping_row( 'Guest', $shipping_zones, $methodarray ); ?> + +
  +

+
  + get_shipping_method_title( $col ); ?> +
+
+ + +
+

+ +

+ +
+ +
+ +
+ + + + +

+ +

+ +
+ + + + + + 0 ) : ?> + + + + + + + + + + + + + + + + + print_shipping_group_row( $group, $shipping_zones, $group_methodarray ); ?> + + +
  +

+
  + get_shipping_method_title( $col ); ?> +
+
+ +
+ + + +
+

+ + +

+
+
diff --git a/admin/views/flash-activation.php b/admin/views/flash-activation.php new file mode 100644 index 0000000..e69de29 diff --git a/admin/views/flash-updated.php b/admin/views/flash-updated.php new file mode 100644 index 0000000..323e39f --- /dev/null +++ b/admin/views/flash-updated.php @@ -0,0 +1,16 @@ + + * @license GPL-2.0+ + * @link http://woothemes.com/woocommerce + * @copyright 2015 WPBackOffice + */ +?> + +
+

+
\ No newline at end of file diff --git a/admin/views/index.php b/admin/views/index.php new file mode 100755 index 0000000..e71af0e --- /dev/null +++ b/admin/views/index.php @@ -0,0 +1 @@ + + * @license GPL-2.0+ + * @link http://woothemes.com/woocommerce + * @copyright 2014 WPBackOffice + */ + +/** + * Main Role Based Methods class + * + * @package WC_Role_Methods + * @author WPBackOffice + */ +class WC_Role_Methods { + + /** + * Plugin version, used for cache-busting of style and script file references. + * + * @since 2.0.0 + * + * @var string + */ + const VERSION = '2.0.7'; + /** + * Instance of this class. + * + * @since 2.0.0 + * + * @var object + */ + protected static $instance = null; + /** + * Unique identifier for your plugin. + * + * The variable name is used as the text domain when internationalizing strings + * of text. Its value should match the Text Domain file header in the main + * plugin file. + * + * @since 2.0.0 + * + * @var string + */ + protected $plugin_slug = 'woocommerce-role-based-methods'; + + /** + * Initialize the plugin by setting localization and loading public scripts + * and styles. + * + * @since 2.0.0 + */ + private function __construct() { + if ( is_woocommerce_active() ) { + add_filter( 'woocommerce_available_payment_gateways', array( $this, 'get_available_payment_gateways' ) ); + + // General Options. + $this->options = get_option( 'woocommerce_role_methods_options' ); + + $this->shipping_options = get_option( 'woocommerce_shipping_roles' ); + $this->payment_options = get_option( 'woocommerce_payment_roles' ); + + // Set up Shipping group options. + $this->allowed_payment_groups = get_option( 'woocommerce_group_payment_roles' ); + $this->allowed_shipping_groups = get_option( 'woocommerce_group_shipping_roles' ); + + // Check for 2.1. + if ( function_exists( 'WC' ) ) { + add_filter( 'woocommerce_package_rates', array( $this, 'get_available_shipping_methods' ), 9, 2 ); + } else { + add_filter( 'woocommerce_available_shipping_methods', array( + $this, + 'get_available_shipping_methods' + ) ); + } + } + } + + /** + * Return an instance of this class. + * + * @return object A single instance of this class. + * @since 2.0.0 + */ + public static function get_instance() { + + // If the single instance hasn't been set, set it now. + if ( null == self::$instance ) { + self::$instance = new self; + } + + return self::$instance; + } + + /** + * Return the slug. + * + * @return Plugin slug variable. + * @since 2.0.0 + */ + public function get_plugin_slug() { + return $this->plugin_slug; + } + + /** + * Get a list of all shipping methods globally available for use. + * + * @param array $rates shipping rates for the package. + * + * @return array $avail_methods only shipping methods deemed permitted by the Role-Based Plugin + */ + public function get_available_shipping_methods( $rates ) { + $current_user_roles = $this->get_user_roles(); + + unset( $avail_methods ); + $avail_methods = array(); + + foreach ( $rates as $id => $rate ) { + if ( 'table_rate' === $rate->method_id ) { + $rate_id = implode( + ':', + array( + $rate->method_id, + $rate->instance_id, + ) + ); + } elseif ( 'flexible_shipping' === $rate->method_id ) { + $rate_id = implode( + ':', + array( + $rate->method_id, + $rate->instance_id, + ) + ); + } elseif ( 'wbs' === $rate->method_id ) { + // WBS features it's own logic for handling when a method is shown + // so we just let it through. + $avail_methods[ $id ] = $rate; + } elseif ( method_exists( $rate, 'get_instance_id' ) ) { + $rate_id = implode( + ':', + array( + $rate->get_method_id(), + $rate->get_instance_id(), + ) + ); + } else { + $rate_id = $id; + } + + foreach ( $current_user_roles as $user_role ) { + if ( $this->check_rolea_methods( $user_role, $rate_id ) ) { + $avail_methods[ $id ] = $rate; + } + } + } + + return $avail_methods; + } + + /** + * Accept a user role and a shipping method, return true or false depending on whether it's allowed. + * + * @param string $the_role The current user role as-per the logged in user. + * @param string $rate_id ID of the shipping method to be checked. + * + * @return bool true if allowed, false if not allowed + */ + public function check_rolea_methods( $the_role, $rate_id ) { + $rate_id = apply_filters( 'wc_role_based_rate_id', $rate_id ); + + // The role isn't even defined in here, get out + if ( isset( $this->shipping_options[ $the_role ] ) ) { + $role_options = $this->shipping_options[ $the_role ]; + } else { + return false; + } + + // Check if user is in one of the allowed groups, but only if groups plugin is installed. + $active_in_groups = false; + if ( function_exists( '_groups_get_tablename' ) && $this->allowed_shipping_groups ) { + foreach ( $this->allowed_shipping_groups as $group_id => $group_allowed_methods ) { + if ( Groups_User_Group::read( get_current_user_id(), $group_id ) && isset( $group_allowed_methods[ $rate_id ] ) && 'on' == $group_allowed_methods[ $rate_id ] ) { + $active_in_groups = true; + } + } + } + + if ( ( isset( $role_options[ $rate_id ] ) && 'on' === $role_options[ $rate_id ] ) || ! $this->shipping_options ) { + $active_in_roles = true; + } else { + $active_in_roles = false; + } + + // Guests aren't in groups, so only check the role settings for guests. + if ( 'Guest' === $the_role && $active_in_roles ) { + return true; + } + + // Check the operator - either AND or OR. + if ( $this->using_ship_role_based_groups() && isset( $this->options['shipping_operator'] ) ) { + if ( 'and' === $this->options['shipping_operator'] ) { + return $active_in_groups && $active_in_roles; + } else { + return $active_in_groups || $active_in_roles; + } + } else { + return $active_in_roles; + } + } + + /** + * Checks user's roles against payment gateways + * + * @param string $current_user_role The current user role as-per the logged in user. + * @param string $gateway_id ID of the payment gateway. + */ + public function check_rolea( $current_user_role, $gateway_id ) { + global $current_user; + + // Check if user is in one of the allowed groups, but only if groups plugin is installed. + $active_in_groups = false; + + if ( function_exists( '_groups_get_tablename' ) && $this->allowed_payment_groups ) { + foreach ( $this->allowed_payment_groups as $group_id => $group_allowed_gateways ) { + if ( Groups_User_Group::read( get_current_user_id(), $group_id ) && isset( $group_allowed_gateways[ $gateway_id ] ) && 'on' == $group_allowed_gateways[ $gateway_id ] ) { + $active_in_groups = true; + } + } + } + + $active_in_roles = false; + if ( + ( + isset( $this->payment_options[ $current_user_role ][ $gateway_id ] ) && + 'on' == $this->payment_options[ $current_user_role ][ $gateway_id ] + ) || + false == $this->payment_options + ) { + $active_in_roles = true; + } elseif ( ! is_user_logged_in() && isset( $this->payment_options['Guest'][ $gateway_id ] ) && 'on' == $this->payment_options['Guest'][ $gateway_id ] ) { + $active_in_roles = true; + } else { + $active_in_roles = false; + } + + // Guests aren't in groups, so only check the role settings for guests. + if ( 'Guest' == $current_user_role && $active_in_roles ) { + return true; + } + + // Check the operator - either AND or OR. + if ( $this->using_pay_role_based_groups() && isset( $this->options['payment_operator'] ) ) { + if ( 'and' === $this->options['payment_operator'] ) { + return $active_in_groups && $active_in_roles; + } else { + return $active_in_groups || $active_in_roles; + } + } else { + return $active_in_roles; + } + } + + /** + * Gets any and all roles for the current user + * + * @return array roles of the current user + */ + public function get_user_roles() { + global $current_user; + + if ( ! isset( $wp_roles ) ) { + $wp_roles = new WP_Roles(); + } + + $the_roles = $wp_roles->roles; + $current_user_roles = array(); + + if ( is_user_logged_in() ) { + $user = new WP_User( $current_user->ID ); + if ( ! empty( $user->roles ) && is_array( $user->roles ) ) { + foreach ( $user->roles as $role ) { + $current_user_roles[] = strtolower( $the_roles[ $role ]['name'] ); + } + } + } else { + $current_user_roles[] = 'Guest'; + } + + return $current_user_roles; + } + + /** + * Get a list of all gateway globally available for use. + * + * @param array $gateways loop through all enabled payment gateways, but remove any gateways that are not permitted through Role-Based Methods. + * + * @return array Array of permitted gateways + */ + public function get_available_payment_gateways( $gateways ) { + $current_user_roles = $this->get_user_roles(); + + $avail_gateways = array(); + foreach ( $gateways as $gateway ) { + foreach ( $current_user_roles as $user_role ) { + if ( $this->check_rolea( $user_role, $gateway->id ) ) { + $avail_gateways[ $gateway->id ] = $gateway; + } + } + } + + return $avail_gateways; + } + + /** + * Check if we're in bewteen woo versions + * + * @param float $start_version minimum version. + * @param float $end_version maximum version. + * + * @deprecated + */ + private function is_version_between( $start_version, $end_version ) { + if ( version_compare( WOOCOMMERCE_VERSION, $start_version, '>=' ) && version_compare( WOOCOMMERCE_VERSION, $end_version, '<' ) ) { + return true; + } else { + return false; + } + } + + /** + * Check if using shipping groups + * + * @return boolean + */ + private function using_ship_role_based_groups() { + if ( isset( $this->options['ship-groups-enable'] ) && 'Yes' == $this->options['ship-groups-enable'] ) { + return true; + } else { + return false; + } + } + + /** + * Check if using pay role based groups + * + * @return boolean + */ + private function using_pay_role_based_groups() { + if ( isset( $this->options['pay-groups-enable'] ) && 'Yes' == $this->options['pay-groups-enable'] ) { + return true; + } else { + return false; + } + } +} diff --git a/public/views/index.php b/public/views/index.php new file mode 100755 index 0000000..e71af0e --- /dev/null +++ b/public/views/index.php @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/readme.txt b/readme.txt new file mode 100755 index 0000000..8bd8025 --- /dev/null +++ b/readme.txt @@ -0,0 +1,18 @@ +=== WooCommerce Payment/Shipping Roles === +Contributors: brianjhanson +Tags: woocommerce +Requires at least: 4.0 +Tested up to: 7.5 +Stable tag: 2.5.0 + +This plugin adds role-based control of shipping and payment methods for WooCommerce + +== Installation == + +1. Upload the plugin folder to the '/wp-content/plugins/' directory. + +2. Activate the plugin through the 'Plugins' menu in WordPress. + +== Usage == + +Visit WooCommerce > Pay Roles Settings and Ship Roles Settings sections in the WooCommerce administration area. Check the desired methods for each payment and shipping method per user role. Activate the Wordpress Groups Plugin (https://wordpress.org/plugins/groups/) to control available payment gateways and shipping methods on a per-group basis. diff --git a/uninstall.php b/uninstall.php new file mode 100755 index 0000000..d684fb0 --- /dev/null +++ b/uninstall.php @@ -0,0 +1,37 @@ + + * @license GPL-2.0+ + * @link http://woothemes.com/woocommerce + * @copyright 2014 WPBackOffice + */ + +// If uninstall not called from WordPress, then exit +if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { + exit; +} +if (is_multisite()) { + global $wpdb; + $blogs = $wpdb->get_results("SELECT blog_id FROM {$wpdb->blogs}", ARRAY_A); + delete_option('OPTION_NAME'); + + if ($blogs) { + foreach($blogs as $blog) { + switch_to_blog($blog['blog_id']); + delete_option('woocommerce_payment_roles'); + delete_option('woocommerce_shipping_roles'); + delete_option('woocommerce_group_shipping_roles'); + delete_option('woocommerce_group_payment_roles'); + } + } +} +else +{ + delete_option('woocommerce_payment_roles'); + delete_option('woocommerce_shipping_roles'); + delete_option('woocommerce_group_shipping_roles'); + delete_option('woocommerce_group_payment_roles'); +} \ No newline at end of file diff --git a/woo-includes/class-wc-dependencies.php b/woo-includes/class-wc-dependencies.php new file mode 100755 index 0000000..2064ea6 --- /dev/null +++ b/woo-includes/class-wc-dependencies.php @@ -0,0 +1,28 @@ +file = $file; + $plugin->file_id = $file_id; + $plugin->product_id = $product_id; + + $woothemes_queued_updates[] = $plugin; + } +} + +/** + * Load installer for the WooThemes Updater. + * @return $api Object + */ +if ( ! class_exists( 'WooThemes_Updater' ) && ! function_exists( 'woothemes_updater_install' ) ) { + function woothemes_updater_install( $api, $action, $args ) { + $download_url = 'http://woodojo.s3.amazonaws.com/downloads/woothemes-updater/woothemes-updater.zip'; + + if ( 'plugin_information' != $action || + false !== $api || + ! isset( $args->slug ) || + 'woothemes-updater' != $args->slug + ) return $api; + + $api = new stdClass(); + $api->name = 'WooThemes Updater'; + $api->version = '1.0.0'; + $api->download_link = esc_url( $download_url ); + return $api; + } + + add_filter( 'plugins_api', 'woothemes_updater_install', 10, 3 ); +} + +/** + * WooUpdater Installation Prompts + */ +if ( ! class_exists( 'WooThemes_Updater' ) && ! function_exists( 'woothemes_updater_notice' ) ) { + + /** + * Display a notice if the "WooThemes Updater" plugin hasn't been installed. + * @return void + */ + function woothemes_updater_notice() { + $active_plugins = apply_filters( 'active_plugins', get_option('active_plugins' ) ); + if ( in_array( 'woothemes-updater/woothemes-updater.php', $active_plugins ) ) return; + + $slug = 'woothemes-updater'; + $install_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $slug ), 'install-plugin_' . $slug ); + $activate_url = 'plugins.php?action=activate&plugin=' . urlencode( 'woothemes-updater/woothemes-updater.php' ) . '&plugin_status=all&paged=1&s&_wpnonce=' . urlencode( wp_create_nonce( 'activate-plugin_woothemes-updater/woothemes-updater.php' ) ); + + $message = 'Install the WooThemes Updater plugin to get updates for your WooThemes plugins.'; + $is_downloaded = false; + $plugins = array_keys( get_plugins() ); + foreach ( $plugins as $plugin ) { + if ( strpos( $plugin, 'woothemes-updater.php' ) !== false ) { + $is_downloaded = true; + $message = 'Activate the WooThemes Updater plugin to get updates for your WooThemes plugins.'; + } + } + echo '

' . $message . '

' . "\n"; + } + + add_action( 'admin_notices', 'woothemes_updater_notice' ); +} + +/** + * Prevent conflicts with older versions + */ +if ( ! class_exists( 'WooThemes_Plugin_Updater' ) ) { + class WooThemes_Plugin_Updater { function init() {} } +} \ No newline at end of file diff --git a/woocommerce-role-based-methods.php b/woocommerce-role-based-methods.php new file mode 100755 index 0000000..cb897a8 --- /dev/null +++ b/woocommerce-role-based-methods.php @@ -0,0 +1,109 @@ +ID; + + /* Check that the user hasn't already clicked to ignore the message */ + if ( ! get_user_meta( $user_id, + 'checkrolegroups_ignore_notice' ) && ( ! isset( $options['ship-groups-enable'] ) && ! isset( $options['pay-groups-enable'] ) ) && function_exists( '_groups_get_tablename' ) && $options ) { + echo '

'; + printf( __( 'Please verify your Groups settings in WooCommerce -> Settings -> Role Based Methods | Hide Notice' ), + '?checkrolegroups_ignore=0' ); + echo '

'; + } +} + +add_action( 'admin_init', 'checkrolegroups_admin_notice_nag_ignore' ); + +function checkrolegroups_admin_notice_nag_ignore() { + global $current_user; + $user_id = $current_user->ID; + /* If user clicks to ignore the notice, add that to their user meta */ + if ( isset( $_GET['checkrolegroups_ignore'] ) && '0' == $_GET['checkrolegroups_ignore'] ) { + add_user_meta( $user_id, 'checkrolegroups_ignore_notice', 'true', true ); + } +} + + +/** + * Public-Facing Functionality + */ +require_once plugin_dir_path( __FILE__ ) . 'public/class-woocommerce-role-based-methods.php'; + +add_action( 'plugins_loaded', array( 'WC_Role_Methods', 'get_instance' ) ); + +/** + * Dashboard and Administrative Functionality + */ + +/* + * The code below is intended to to give the lightest footprint possible. + */ +if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) { + require_once plugin_dir_path( __FILE__ ) . 'admin/class-woocommerce-role-based-methods-admin.php'; + add_action( 'plugins_loaded', array( 'WC_Role_Methods_Admin', 'get_instance' ) ); +}