diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 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/apsfc.php b/apsfc.php new file mode 100644 index 0000000..ae16071 --- /dev/null +++ b/apsfc.php @@ -0,0 +1,47 @@ +Polylang plugin must be activated for Add Polylang support for Customizer plugin to work. Please activate it now!', 'sample-text-domain'); + + printf('

%2$s

', esc_attr($class), $message); + } + add_action('admin_notices', 'apsfc_error_notice__error'); +} else { + /** + * Currently plugin version. + * Start at version 1.0.2 and use SemVer - https://semver.org + * Rename this for your plugin and update it as you release new versions. + */ + define('APSFC_VERSION', '1.4.4'); + define('APSFC_BASENAME', plugin_basename(__FILE__)); + + require_once plugin_dir_path(__FILE__) . '/includes/class-apsfc.php'; +} \ No newline at end of file diff --git a/assets/index.php b/assets/index.php new file mode 100644 index 0000000..e71af0e --- /dev/null +++ b/assets/index.php @@ -0,0 +1 @@ +' + pcLangTrans + ': '; + html += ''; + $(html).prependTo('#customize-header-actions'); + + + $('body').on('change', '#pll-language-select', function () { + var language = $(this).val(); + var old_url = window.location.href; + window.location.href = updateQueryStringParameter(window.location.href, 'lang', language); + }); + }); + + function updateQueryStringParameter(uri, key, value) { + var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i"); + var separator = uri.indexOf('?') !== -1 ? "&" : "?"; + if (uri.match(re)) { + return uri.replace(re, '$1' + key + "=" + value + '$2'); + } else { + return uri + separator + key + "=" + value; + } + } + }; + + return component; +} ( wp.customize, jQuery ) ); \ No newline at end of file diff --git a/assets/js/index.php b/assets/js/index.php new file mode 100644 index 0000000..e71af0e --- /dev/null +++ b/assets/js/index.php @@ -0,0 +1 @@ +Settings->URL modifications) + */ + if (get_option('apsfc_force_lang') == "on") { + if (isset($options['force_lang']) && 0 !== $options['force_lang']) { + $options['force_lang'] = 0; + update_option('polylang', $options); + } + } + + /** + * Disable detect browser language, will return default language instead. + */ + // add_filter( 'pll_preferred_language', '__return_false' ); + + \add_action('customize_controls_enqueue_scripts', [$self, 'add_lang_to_customizer_previewer'], 9); + \add_action('wp_before_admin_bar_render', [$self, 'on_wp_before_admin_bar_render'], 100); + \add_action('admin_menu', [$self, 'on_admin_menu'], 100); + + $theme_stylesheet_slug = get_option('stylesheet'); + $option_types = ['blogname', 'blogdescription', 'site_icon']; + + // Get theme mod options. + add_filter('option_theme_mods_' . $theme_stylesheet_slug, [$self, 'on_option_theme_mods_get'], 10, 1); + // Update theme mod options. + add_filter('pre_update_option_theme_mods_' . $theme_stylesheet_slug, [$self, 'on_option_theme_mods_update'], 10, 2); + + foreach ($option_types as $option_type) { + add_filter('pre_option_' . $option_type, [$self, 'on_wp_option_get'], 10, 3); // get_option hook. + add_filter('pre_update_option_' . $option_type, [$self, 'on_wp_option_update'], 10, 3); // update_option hook. + } + + return $self; + } + + /** + * Initialize Polylang API so we can call some function prematurely its initialization. + * + * @return void + */ + public function premature_initialization() + { + if (!function_exists('pll_current_language')) { + $poly_file = WP_PLUGIN_DIR . '/polylang/include/api.php'; + if (!file_exists($poly_file)) { + $poly_file = WP_PLUGIN_DIR . '/polylang-pro/include/api.php'; + if (!file_exists($poly_file)) $poly_file = WP_PLUGIN_DIR . '/polylang-pro/vendor/wpsyntex/polylang/include/api.php'; + } + + require $poly_file; + if (!isset($GLOBALS['polylang'])) $GLOBALS['polylang'] = null; + } + } + + /** + * Load plugin textdomain. + * + * @since 1.0.2 + */ + public function pc_load_textdomain() + { + load_plugin_textdomain('apsfc', false, basename(dirname(__FILE__)) . '/languages'); + } + + + /** + * Constructor. + */ + private function __construct() + { + /** + * Prematurely initialize Polylang API + */ + add_action('plugins_loaded', [$this, 'premature_initialization']); + + /** + * Load plugin text domain (l10n) + */ + add_action('plugins_loaded', [$this, 'pc_load_textdomain'], 0); + $this->setup_settings(); + } + + /** + * Setup settings & pages + */ + function setup_settings() + { + require_once dirname(__FILE__) . '/class-settings.php'; + $settings = new ApsfcSettings(); + } + + /** + * Helper to fetch custom customizer db content. + * + * @return mixed Customizer array or false. + */ + protected function get_custom_customizer_option() + { + $current_language = pll_current_language(); + $theme_slug = get_option('template'); + $option_prefix = \str_replace('-', '_', $theme_slug); + $option_name = $option_prefix . '_apsfc_settings_' . $current_language; + + return get_option($option_name, false); + } + + /** + * Helper to update custom customizer db content. + * + * @param mixed $data Data to insert. + * + * @return bool Success. + */ + protected function update_custom_customizer_option($data) + { + $current_language = pll_current_language(); + $theme_slug = get_option('template'); + $option_prefix = \str_replace('-', '_', $theme_slug); + $option_name = $option_prefix . '_apsfc_settings_' . $current_language; + + return update_option($option_name, $data); + } + + /** + * Helper + * + * @return bool If the current language is the default language. + */ + protected function current_lang_not_default() + { + if (function_exists('pll_current_language')) return pll_current_language() !== pll_default_language(); + return false; + } + + /** + * Check the custom db field on get_option hook to be able to return custom language value. + * If the current language is default, then return from default wp option + * + * @param bool $pre_option This is false. If something else is returned wp exits the check in db and uses this value. + * @param string $option Option name asked for. + * @param mixed $default Default value, second args when asking for options. + * + * @return mixed + */ + public function on_wp_option_get($pre_option, $option, $default) + { + + // If not the default language, then skip the custom check and wp will the use default options. + if ($this->current_lang_not_default()) { + $data = $this->get_custom_customizer_option(); + + // Found the custom option. Move on. + if (is_array($data) && isset($data['options']) && isset($data['options'][$option])) { + return $data['options'][$option]; + } + } + + return $default; + } + + /** + * Update the custom db field on get_option hook. + * If the current language is not default, then return old value to prevent from saving to default wp option. + * + * @param mixed $value The new, unserialized option value. + * @param mixed $old_value The old option value. + * @param string $option Option name. + * + * @return mixed + */ + public function on_wp_option_update($value, $old_value, $option) + { + // Fetch custom option db field. + $data = $this->get_custom_customizer_option(); + $theme_slug = get_option('template'); + // If false, the field hasn't been created yet, so it must be created. + if (false === $data) { + $data = [ + 'template' => $theme_slug, + 'mods' => [], + 'options' => [], + ]; + } + + // Make sure the options array exists. We are going to use it soon. + if (!isset($data['options'])) { + $data['options'] = []; + } + + $data['options'][$option] = $value; + + // Update option value in custom db field. (Not necessary to save for default language since it uses default wp option fields for values when get option). + $this->update_custom_customizer_option($data); + + // If the current language is not the default language, prevent saving to option table by passing the old value back. It will then exit after the filter. + if ($this->current_lang_not_default()) { + return $old_value; + } + + return $value; + } + + /** + * Check the custom db field on get_option customizer field option name hook to be able to return custom language value. + * Parse arguments with default wp customizer values to make sure all are present in the return. + * + * @param array $value The customizer settings. + * + * @return array + */ + public function on_option_theme_mods_get($value) + { + $data = $this->get_custom_customizer_option(); + + if (isset($data['mods']) && is_array($data['mods']) && !empty($data['mods'])) { + $value = wp_parse_args($data['mods'], $value); + } + + // Remove members with integer key from mods. + foreach ($value as $key => $mod) { + if (is_numeric($key)) { + unset($value[$key]); + } + } + + return $value; + } + + /** + * Update custom customizer option. + * If the current language is not default, then return old value to prevent from saving to customizer wp option. + * + * @param mixed $value The new, unserialized option value. + * @param mixed $old_value The old option value. + */ + public function on_option_theme_mods_update($value, $old_value) + { + + $current_data = $this->get_custom_customizer_option(); + $theme_slug = get_option('template'); + + $data = [ + 'template' => $theme_slug, + 'mods' => isset($current_data['mods']) ? $current_data['mods'] : [], + 'options' => isset($current_data['options']) ? $current_data['options'] : [], + ]; + + if (is_array($value) && !empty($value)) { + foreach ($value as $key => $val) { + $data['mods'][$key] = $val; + } + } + $this->update_custom_customizer_option($data); + + if ($this->current_lang_not_default()) { + return $old_value; + } + + return $value; + } + + /** + * If Polylang activated, set the preview url and add select language control + * + * @author soderlind + * @version 1.0.0 + * @link https://gist.github.com/soderlind/1908634f5eb0c1f69428666dd2a291d0 + */ + public function add_lang_to_customizer_previewer() + { + $language = (empty($_REQUEST['lang'])) ? pll_current_language() : $_REQUEST['lang']; + if (empty($language)) $language = pll_default_language(); + + if (is_customize_preview() && (!isset($_REQUEST['lang']) || $_REQUEST['lang'] == 'all' || empty($_REQUEST['lang']))) { + $url = get_admin_url() . 'customize.php?lang=' . $language; // EDIT this to your needs + wp_safe_redirect($url); + var_dump($url); + exit(); + } + + $handle = 'dss-add-lang-to-template'; + $src = plugin_dir_url(dirname(__FILE__)) . 'assets/js/apsfc.js'; + $deps = ['customize-controls']; + $version = rand(); + $in_footer = 1; + wp_enqueue_script($handle, $src, $deps, $version, $in_footer); + + if (empty($language)) { + $language = pll_default_language(); + } + + if (!empty($_REQUEST['url'])) { + $current_url = add_query_arg('lang', $language, $_REQUEST['url']); + } else { + $current_url = add_query_arg('lang', $language, pll_home_url($language)); + } + wp_add_inline_script( + $handle, + sprintf( + 'var pcLangTrans = "' . __('Language', 'apsfc') . '";' . + 'PSPolyLang.init( %s );', + wp_json_encode( + [ + 'url' => $current_url, + 'languages' => get_transient('pll_languages_list'), + 'current_language' => $language, + ] + ) + ), + 'after' + ); + } + + /** + * Append lang="contrycode" to the customizer url in the adminbar + * + * @return void + */ + public function on_wp_before_admin_bar_render() + { + global $wp_admin_bar; + $customize_node = $wp_admin_bar->get_node('customize'); + if (!empty($customize_node)) { + $customize_node->href = add_query_arg('lang', pll_current_language(), $customize_node->href); + $wp_admin_bar->add_node($customize_node); + } + } + + /** + * Append lang="contrycode" to the customizer url in the Admin->Apperance->Customize menu + * + * @return void + */ + public function on_admin_menu() + { + global $submenu; + $parent = 'themes.php'; + if (!isset($submenu[$parent])) { + return; + } + foreach ($submenu[$parent] as $k => $d) { + if ('customize' === $d['1']) { + $submenu[$parent][$k]['2'] = add_query_arg('lang', pll_current_language(), $submenu[$parent][$k]['2']); + break; + } + } + } +} + +if (class_exists('WP_Customize_Setting')) { + /** + * A class that extends WP_Customize_Setting so we can access + * the protected updated method when importing options. + * + * @since 0.3 + */ + final class CustomizerPolylangOption extends \WP_Customize_Setting + { + + + /** + * Import an option value for this setting. + * + * @since 0.3 + * + * @param mixed $value The option value. + * + * @return void + */ + public function import($value) + { + $this->update($value); + } + } +} + +/** + * Polylang register strings. + */ + +if (function_exists('pll_register_string')) { + + /** + * Register fields for Polylang string translations + * + * @param string $option_name Option name + * @param array $fields Field names + * + * @return void + */ + function register_polylang_column_strings($option_name, $fields) + { + $columns = get_option($option_name); + $theme_name = wp_get_theme()->get('Name'); + if (!empty($columns)) : + for ($i = 0; $i < $columns; $i++) : + foreach ($fields as $field) { + pll_register_string($option_name . '_' . $i . '_' . $field, get_option($option_name . '_' . $i . '_' . $field), $theme_name, true); + } + endfor; + endif; + } + + register_polylang_column_strings('options_footer_columns', ['title', 'text']); + register_polylang_column_strings('options_footer_logos', ['image', 'url']); +} diff --git a/includes/class-settings.php b/includes/class-settings.php new file mode 100644 index 0000000..3ada014 --- /dev/null +++ b/includes/class-settings.php @@ -0,0 +1,117 @@ +" . __('Settings') . ''; + // Adds the link to the end of the array. + array_push( + $links, + $settings_link + ); + return $links; + } //end nc_settings_link() + + /** + * Display submenu page contents + */ + public function submenu_page() + { + $this->options = get_option('apsfc_force_lang'); + if (isset($_POST)) { + if (isset($_POST['apsfc_force_lang'])) { + update_option('apsfc_force_lang', "on"); + } else { + if (isset($_POST['submit'])) { + update_option('apsfc_force_lang', "off"); + } + } + } +?> +
+

+
+ + + + + + + + + +

+
+
+\n" +"Language-Team: \n" +"Language: \n" +"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Loco https://localise.biz/\n" +"X-Loco-Version: 2.3.1; wp-5.3.2" + +#: includes/class-apsfc.php:294 +msgid "Language" +msgstr "" + +#. Third party plugin Slug +#: includes/class-settings.php:31 includes/class-settings.php:32 +msgid "Customizer Support" +msgstr "" + +#: includes/class-settings.php:56 +msgid "Customizer Support Settings" +msgstr "" + +#: includes/class-settings.php:66 +msgid "Language setup" +msgstr "" + +#. Name of the plugin +msgid "Add Polylang support for Customizer" +msgstr "" + +#. Description of the plugin +msgid "This plugin adds Polylang support for Customizer." +msgstr "" + +#. URI of the plugin +msgid "https://wordpress.org/plugins/add-polylang-support-for-customizer" +msgstr "" + +#. Author of the plugin +msgid "richardev" +msgstr "" + +#. Author URI of the plugin +msgid "https://richardev.com" +msgstr "" diff --git a/languages/index.php b/languages/index.php new file mode 100644 index 0000000..e71af0e --- /dev/null +++ b/languages/index.php @@ -0,0 +1 @@ + `Settings` > `URL modifications` + +## Prerequisite + +1. Polylang must be installed and activated. +2. Languages must be set in **Admin > Languages**. +3. _If you have a static front page_: + 1. _Create a front page per each language._ + 2. _Select the front page in **Admin > Settings > Reading** per language._ +4. Expect customizer to use setting type = `theme_mod` (default) as in: + +`$wp_customize->add_setting( 'setting_id', [ 'type' => 'theme_mod', ] );` + +## Installation + +This plugin can be installed directly into your plugins folder "as-is"
+or: + +- go to **Plugins > Add new** and type in Search `Add Polylang support for Customizer` and click **Install** and then **Activate** buttons. +- if you go to **Admin panel > Plugins > Add new > Upload Plugin** and select the archive containing this plugin. + +It's safe to activate the plugin at this point. Because the plugin just injects some functionality - there will be no plugin menus or settings to play with. +License + +## License + +This plugin is licensed under the GPL v2 or later. + +> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, 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 + +A copy of the license is included in the root of the plugin’s directory. The file is named `LICENSE`. + +## Important Notes + +### Licensing + +This plugin is licensed under the GPL v2 or later; however, if you opt to use third-party code that is not compatible with v2, then you may need to switch to using code that is GPL v3 compatible. + +For reference, [here's a discussion](http://make.wordpress.org/themes/2013/03/04/licensing-note-apache-and-gpl/) that covers the Apache 2.0 License used by [Bootstrap](http://twitter.github.io/bootstrap/). + +# Credits + +Original solution made by [@soderlind](https://github.com/soderlind) is available [here](https://github.com/soderlind/customizer-polylang). Share some love! This is WordPress plugin version of his solution. diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..21a4c51 --- /dev/null +++ b/readme.txt @@ -0,0 +1,120 @@ +=== Add Polylang support for Customizer === +Contributors: richardevcom,pers +Tags: polylang,customizer,support,translate,wordpress +Donate link: paypal.me/ricardsmucelans +Requires at least: 4.7 +Tested up to: 5.8 +Requires PHP: 5.6 +Stable tag: trunk +License: GPL-2.0+ +License URI: http://www.gnu.org/licenses/gpl-2.0.txt + +This plugin adds Polylang support for WordPress Customizer. + +== Description == +# Add Polylang support for Customizer + +This plugin adds Polylang support for WordPress Customizer. + +## Support + +We provide direct support via our [Frontbee Discord server](https://discord.gg/ZptSdXMPrM) + +## Features + +* Language switcher in Customizer. +* Localized theme_mods and options for both default and custom made Customizer values. +* Enable/disable forcing "The language is set from content" setting in Language->Settings->URL modifications + +## Prerequisite + +1. Polylang must be installed and activated. +2. Languages must be set in **Admin > Languages**. +3. _If you have a static front page_: + 1. _Create a front page per each language._ + 2. _Select the front page in **Admin > Settings > Reading** per language._ +5. Expect customizer to use setting type = `theme_mod` (default) as in: + +`$wp_customize->add_setting( 'setting_id', [ 'type' => 'theme_mod', ] );` + +## Installation + +This plugin can be installed directly into your plugins folder \"as-is\" + +or if you go to **Admin panel > Plugins > Add new > Upload Plugin** and select the archive containing this plugin. + +It\'s safe to activate the plugin at this point. Because the plugin just injects some functionality - there will be no plugin menus or settings to play with. + +## License + +This plugin is licensed under the GPL v2 or later. + +> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, 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 + +A copy of the license is included in the root of the plugin’s directory. The file is named `LICENSE`. + +## Important Notes + +### Licensing + +This plugin is licensed under the GPL v2 or later; however, if you opt to use third-party code that is not compatible with v2, then you may need to switch to using code that is GPL v3 compatible. + +# Credits + +Original solution made by [@soderlind](https://github.com/soderlind) is available [here](https://github.com/soderlind/customizer-polylang). Share some love! This is WordPress plugin version of his solution. + + +== Installation == +This plugin can be installed directly into your plugins folder \"as-is\" +or if you go to Admin panel > Plugins > Add new > Upload Plugin and select the archive containing this plugin. + +== Screenshots == +1. Polylang language dropdown in Customizer + +== Changelog == += 1.0.1 = +* First release += 1.0.2 = +* Fixed issues with option rewriting and polylang translatable strings. += 1.1.2 = +* Fixed issues with pll_current_language() missing due to Polylang API being not included. += 1.1.2 = +* Added settings page & Enable/disable forcing "The language is set from content" setting in Language->Settings->URL modifications += 1.1.2 = +* Added quick settings link += 1.1.2 = +* Fixed missing includes += 1.2.0 = +* Fixed 404 page & removed prefered language dismissal. Thanks @penhtech += 1.3.0 = +* If Polylang is not active, don't run the app and throw an error notice += 1.3.1 = +* Changed way Polylang API is called += 1.3.2 = +* fixed API.php location error for multisites. += 1.3.3 = +* Changed how API.php is included. += 1.3.4 = +* Added Polylang PRO dir check += 1.3.5 = +* Added Polylang PRO dir check += 1.3.6 = +* Added Polylang PRO dir check += 1.3.7 = +* Fixed no language selection issue on customizer. += 1.3.8 = +* Fixed no language selection issue on customizer. += 1.4.0 = +* Fixed premature Polylang API initialization error while activating/deactivating Polylang. += 1.4.1 = +* Fixed non existing function (early) call for some 3rd party plugins. += 1.4.2 = +* Added support up to WordPress 5.8 += 1.4.3 = +* Workaround for update version mismatch += 1.4.4 = +* Added support URL \ No newline at end of file