Changeset 2091443
- Timestamp:
- 05/20/2019 12:43:29 PM (5 years ago)
- Location:
- acf-options-for-polylang
- Files:
-
- 30 added
- 9 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
acf-options-for-polylang/trunk/CHANGELOG.md
r2082004 r2091443 1 1 # Changelog 2 3 4 5 6 7 8 9 2 10 3 11 ## 1.1.6 - 19 Mar 2019 -
acf-options-for-polylang/trunk/README.md
r2082004 r2091443 1 <a href="https://beapi.fr">![Be API Github Banner]( assets/images/banner-github.png)</a>1 <a href="https://beapi.fr">![Be API Github Banner](/banner-github.png)</a> 2 2 3 3 # BEA - ACF Options For Polylang 4 4 5 6 5 7 You are using Advanced Custom Fields for creating option pages and you have Polylang installed for awsome multilingual site ? 6 8 7 Sadly, Polylang is not handling ACF's Option Pages. Which means values will be the same for all languages you have set :(9 Sadly, Polylang is not handling ACF's Option Pages. Which means values will be the same for all languages you have set 8 10 9 11 We are here to save your life ! Once this plugin is activated, you will be able to set a different value for each language, and if none is set, the "All languages" value will be used as default one. … … 11 13 # How ? 12 14 13 This plugin is storing a value for each language into database. <b>That means at activation, all data will not be anymore available, but still in database.</b>Then Polylang's lang is used to get the values from the DB. Simply contribute your option page by selecting the Polylang's language from admin flags ui. 15 This plugin will store a value for each language into database. Then Polylang's languages are used to get the values from the DB. <b>That means at activation, all existing data will not be anymore available, but still in database. You will retrieve it ad plugin deactivation.</b> 16 17 Then to set and contribute your option page, simply use the Polylang's language admin flags ui. 14 18 15 19 # Requirements 16 20 17 - [WordPress](https://wordpress.org/) 4.7+ 18 - Tested up to 4.9.4 19 - PHP 5.6 21 - Require [WordPress](https://wordpress.org/) 4.7+ / Tested up to 5.2 22 - Require PHP 5.6 20 23 - [Advanced Custom Fields](https://www.advancedcustomfields.com/pro) 5.6.0+ 21 24 - [Polylang](https://polylang.pro/) … … 23 26 # Installation 24 27 25 Once activated Polylang's languages into admin area will affect ACF's options pages. 28 First activate and configure Polylang in you site. 29 Then activate ACF Options For Polylang to handle ACF Options in setted Polylang's languages. 26 30 27 31 ## WordPress … … 43 47 44 48 - Almost simple fields (text, textarea, links, etc) 45 - Repeater fields ( with simple fields)49 - Repeater fields () 46 50 47 51 ## More features to come … … 52 56 53 57 ## Next Roadmap 54 - todo58 - 55 59 56 60 ## Contributing … … 63 67 64 68 ## For developers 69 70 71 72 73 74 75 76 77 65 78 66 79 The plugin is designed to get the Polylang "All languages" value if the current lang one is empty. But if you are not interested about this behaviour, you can programmatically deactivate it using the following filter by setting to false. … … 95 108 ## License 96 109 97 BEA - ACF Options for Polylang is licensed under the [GPLv 3or later](LICENSE.md).110 BEA - ACF Options for Polylang is licensed under the [GPLv or later](LICENSE.md). -
acf-options-for-polylang/trunk/bea-acf-options-for-polylang.php
r2082004 r2091443 1 1 <?php 2 3 4 5 6 7 8 9 10 2 11 3 /* 4 Plugin Name: BEA - ACF Options for Polylang 5 Version: 1.1.6 6 Plugin URI: https://github.com/BeAPI/acf-options-for-polylang 7 Description: Add ACF options page support for Polylang. 8 Author: Be API Technical team 9 Author URI: https://beapi.fr 10 Contributors: Maxime Culea 11 ---- 12 Copyright 2018-2019 Be API Technical team (human@beapi.fr) 12 13 13 Copyright 2018 Be API Technical team (human@beapi.fr) 14 This program is free software; you can redistribute it and/or modify 15 it under the terms of the GNU General Public License as published by 16 the Free Software Foundation; either version 2 of the License, or 17 (at your option) any later version. 14 18 15 This program is free software; you can redistribute it and/or modify 16 it under the terms of the GNU General Public License as published by 17 the Free Software Foundation; either version 2 of the License, or 18 (at your option) any later version.19 This program is distributed in the hope that it will be useful, 20 but WITHOUT ANY WARRANTY; without even the implied warranty of 21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 . 19 23 20 This program is distributed in the hope that it will be useful, 21 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 GNU General Public License for more details. 24 25 You should have received a copy of the GNU General Public License 26 along with this program; if not, write to the Free Software 27 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 28 */ 29 24 You should have received a copy of the GNU General Public License 25 along with this program; if not, write to the Free Software 26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 27 */ 30 28 31 29 // don't load directly … … 35 33 36 34 // Plugin constants 37 define( 'BEA_ACF_OPTIONS_FOR_POLYLANG_VERSION', '1.1. 6' );35 define( 'BEA_ACF_OPTIONS_FOR_POLYLANG_VERSION', '1.1.' ); 38 36 define( 'BEA_ACF_OPTIONS_FOR_POLYLANG_MIN_PHP_VERSION', '5.6' ); 39 37 … … 46 44 // Check PHP min version 47 45 if ( version_compare( PHP_VERSION, BEA_ACF_OPTIONS_FOR_POLYLANG_MIN_PHP_VERSION, '<' ) ) { 48 require_once ( BEA_ACF_OPTIONS_FOR_POLYLANG_DIR . 'compat.php' );46 require_once; 49 47 // possibly display a notice, trigger error 50 48 add_action( 'admin_init', array( 'BEA\PB\Compatibility', 'admin_init' ) ); 49 51 50 // stop execution of this file 52 51 return; … … 64 63 65 64 \BEA\ACF_Options_For_Polylang\Main::get_instance(); 65 66 67 68 66 69 } -
acf-options-for-polylang/trunk/classes/helpers.php
r2082004 r2091443 1 <?php namespace BEA\ACF_Options_For_Polylang; 1 <?php 2 3 namespace BEA\ACF_Options_For_Polylang; 2 4 3 5 class Helpers { … … 7 9 * @param $post_id 8 10 * 11 12 13 14 9 15 * @author Maxime CULEA 10 *11 * @since 1.0.412 *13 * @return string14 16 */ 15 17 public static function original_option_id( $post_id ) { 16 // Check if is an object. 17 // Todo user case. 18 // $post_id may be an object 18 19 if ( is_object( $post_id ) ) { 19 // Apply for all cases. 20 switch ( get_class( $post_id ) ) { 21 case 'WP_Term': 22 $post_id = $post_id->taxonomy . '_' . $post_id->term_id; 23 break; 24 case 'WP_Comment': 25 $post_id = 'comment_' . $post_id->comment_ID; 26 break; 27 case 'WP_Post': 28 $post_id = $post_id->ID; 29 break; 20 if ( isset( $post_id->post_type, $post_id->ID ) ) { // post 21 $post_id = $post_id->ID; 22 } elseif ( isset( $post_id->roles, $post_id->ID ) ) { // user 23 $post_id = 'user_' . $post_id->ID; 24 } elseif ( isset( $post_id->taxonomy, $post_id->term_id ) ) { // term 25 $post_id = acf_get_term_post_id( $post_id->taxonomy, $post_id->term_id ); 26 } elseif ( isset( $post_id->comment_ID ) ) { // comment 27 $post_id = 'comment_' . $post_id->comment_ID; 28 } else { // default 29 $post_id = 0; 30 30 } 31 32 33 34 35 31 36 } 32 37 … … 40 45 * @param string $post_id 41 46 * 42 * @ since 1.0.247 * @ 43 48 * @author Maxime CULEA 44 49 * 45 * @ return bool50 * @ 46 51 */ 47 52 public static function is_option_page( $post_id ) { 48 $post_id = Helpers::original_option_id( $post_id );53 $post_id = ::original_option_id( $post_id ); 49 54 if ( false !== strpos( $post_id, 'option' ) ) { 50 55 return true; … … 52 57 53 58 $options_pages = self::get_option_page_ids(); 59 60 61 54 62 55 return ! empty( $options_pages ) && in_array( $post_id, $options_pages);63 return ); 56 64 } 57 65 58 66 /** 59 * Get all registered options pages as array [ post_id => page title ] 67 * Get all registered options pages as array [ menu_slug => post_id ] 68 * 69 * @return array 70 * @author Maxime CULEA 60 71 * 61 72 * @since 1.0.2 62 * @author Maxime CULEA63 *64 * @return array65 73 */ 66 74 public static function get_option_page_ids() { 67 75 return wp_list_pluck( acf_options_page()->get_pages(), 'post_id' ); 68 76 } 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 69 93 } -
acf-options-for-polylang/trunk/classes/main.php
r2082004 r2091443 1 <?php namespace BEA\ACF_Options_For_Polylang; 1 <?php 2 3 namespace BEA\ACF_Options_For_Polylang; 2 4 3 5 class Main { … … 27 29 * Get the current Polylang's locale or the wp's one 28 30 * 31 29 32 * @author Maxime CULEA 30 33 * 31 * @return bool|string32 34 */ 33 35 public function set_current_site_lang() { … … 42 44 * @param $post_id 43 45 * 46 47 48 44 49 * @author Jukra, Maxime CULEA 45 50 * 46 * @since 1.1.247 *48 * @return string49 51 */ 50 52 public function get_default_reference( $reference, $field_name, $post_id ) { … … 73 75 * @param $field 74 76 * 77 75 78 * @author Maxime CULEA 76 79 * 77 * @return mixed|string|void78 80 */ 79 81 public function get_default_value( $value, $post_id, $field ) { … … 87 89 * Activate or deactivate the default value (all languages) for the given post id 88 90 * 89 * @param bool $show_default: whatever to show default for the given post id91 * @param bool : whatever to show default for the given post id 90 92 * @param string $original_post_id : the original post id without lang attributes 91 93 * … … 108 110 // Get from array all the not empty strings 109 111 $is_empty = array_filter( $value, function ( $value_c ) { 110 return ""!== $value_c;112 return !== $value_c; 111 113 } ); 112 114 113 if ( ! empty( $is_empty ) ) { 114 // Not an array of empty values 115 if ( ! empty( $is_empty ) ) { // Not an array of empty values 115 116 return $value; 116 117 } 117 } else { 118 if ( "" !== $value ) { 119 // Not an empty string 118 } elseif ( 'repeater' !== $field['type'] ) { 119 if ( '' !== $value ) { // Not an empty string 120 120 return $value; 121 121 } … … 131 131 132 132 // Get the "All language" value 133 $value = acf_get_ metadata( $original_post_id, $field['name']);133 $value = acf_get_ ); 134 134 135 135 /** … … 148 148 * @param string $original_post_id 149 149 * 150 * @ since 1.0.2150 * @ 151 151 * @author Maxime CULEA 152 152 * 153 * @ return string153 * @ 154 154 */ 155 function set_options_id_lang( $future_post_id, $original_post_id ) {155 function set_options_id_lang( $future_post_id, $original_post_id ) { 156 156 // Only on custom post id option page 157 157 if ( ! Helpers::is_option_page( $original_post_id ) ) { 158 159 160 161 158 162 return $future_post_id; 159 163 } -
acf-options-for-polylang/trunk/classes/requirements.php
r2082004 r2091443 1 <?php namespace BEA\ACF_Options_For_Polylang; 1 <?php 2 3 namespace BEA\ACF_Options_For_Polylang; 2 4 3 5 class Requirements { -
acf-options-for-polylang/trunk/classes/singleton.php
r2082004 r2091443 1 <?php namespace BEA\ACF_Options_For_Polylang; 1 <?php 2 3 namespace BEA\ACF_Options_For_Polylang; 2 4 3 5 trait Singleton { … … 13 15 final public static function get_instance() { 14 16 if ( is_null( self::$instance ) ) { 15 self::$instance = new static ;17 self::$instance = new static; 16 18 } 17 19 … … 31 33 * If you want to have actions send at construct 32 34 */ 33 protected function init() {} 35 protected function init() { 36 } 34 37 35 38 /** … … 38 41 * @return void 39 42 */ 40 final private function __clone() {} 43 final private function __clone() { 44 } 41 45 42 46 /** … … 45 49 * @return void 46 50 */ 47 final private function __wakeup() {} 51 final private function __wakeup() { 52 } 48 53 } -
acf-options-for-polylang/trunk/readme.txt
r2082198 r2091443 1 1 === ACF Options For Polylang === 2 2 Contributors: momo360modena, BeAPI, maximeculea, NicolasKulka 3 Author URI: http ://beapi.fr3 Author URI: http://beapi.fr 4 4 Plugin URL: https://github.com/BeAPI/acf-options-for-polylang 5 5 Requires at Least: 4.7 6 Tested Up To: 4.9.46 Tested Up To: 7 7 Tags: acf, polylang, option, options, options page, advanced custom fields 8 Stable tag: 1.1. 68 Stable tag: 1.1. 9 9 Requires PHP: 5.6 10 11 10 12 11 13 == Description == … … 17 19 We are here to save your life ! Once this plugin is activated, you will be able to set a different value for each language, and if none is set, the "All languages" value will be used as default one. 18 20 19 ***Please refer to [Github](https://github.com/BeAPI/acf-options-for-polylang) for detailed usage instructions and issues.*** 21 # How ? 20 22 21 ## Features 23 This plugin will store a value for each language into database. Then Polylang's languages are used to get the values from the DB. <b>That means at activation, all existing data will not be anymore available, but still in database. You will retrieve it at plugin deactivation.</b> 24 25 Then to set and contribute your option page, simply use the Polylang's language admin flags ui. 26 27 # Features 22 28 23 29 - Almost simple fields (text, textarea, links, etc) 24 30 - Repeater fields (with simple fields) 25 31 26 **How ?** 32 # Who ? 27 33 28 This plugin will store a value for each language into database. Then Polylang's languages are used to get the values from the DB. <b>That means at activation, all existing data will not be anymore available, but still in database. You will retrieve it ad plugin deactivation.</b> 34 Created by [Be API](https://beapi.fr), the French WordPress leader agency since 2009. Based in Paris, we are more than 30 people and always [hiring](https://beapi.workable.com) some fun and talented guys. So we will be pleased to work with you. 29 35 30 Th en to set and contribute your option page, simply use the Polylang's language admin flags ui.36 Th. 31 37 32 == Frequently Asked Questions == 38 To facilitate the process of submitting an issue and quicker answer, we only use Github, so don't use WP.Org support, it will not be considered. 33 39 34 **Requirements** 35 36 * [Advanced Custom Fields](https://www.advancedcustomfields.com/pro) 5.6.0+ 37 * [Polylang](https://polylang.pro/) 38 39 **Installation** 40 == Installation == 40 41 41 42 First activate and configure ACF & Polylang on you site. 42 43 Then activate ACF Options For Polylang to handle ACF Options in setted Polylang's languages. 43 44 44 ***WordPress*** 45 = Requirements = 46 47 - WordPress 4.7+ / Tested up to 5.2 48 - Require PHP 5.6 49 - [Advanced Custom Fields Pro (5.6.0+)](https://www.advancedcustomfields.com/pro) 50 - [Polylang](https://polylang.pro) 51 52 = WordPress = 45 53 46 54 - Download and install using the built-in WordPress plugin installer. … … 49 57 - Nothing more, this plugin is ready to use ! 50 58 51 ***Composer***52 53 - Add repository source : `{ "type": "vcs", "url": "https://github.com/BeAPI/acf-options-for-polylang" }`.54 - Include `"bea/acf-options-for-polylang": "dev-master"` in your composer file for last master's commits or a tag released.55 - Nothing more, this plugin is ready to use !56 57 59 == Changelog == 58 60 59 * 1.1.6 - 19 Mar 2019 60 * FIX [#32](https://github.com/BeAPI/acf-options-for-polylang/issues/32) & [#40](https://github.com/BeAPI/acf-options-for-polylang/issues/40) : fix `get_field()` if an object is provided (WP Term, WP Post, WP Comment) 61 * 1.1.5 - 11 Dec 2018 62 * FIX wrong constant 63 * 1.1.4 - 13 Nov 2018 64 * Refactor by adding the Helpers class 65 * FEATURE [#26](https://github.com/BeAPI/acf-options-for-polylang/issues/26) : allow to precise to show or hide default values for a specific option page 66 * FEATURE [#21](https://github.com/BeAPI/acf-options-for-polylang/pull/21) : handle custom option id 67 * 1.1.3 - 2 Aug 2018 68 * FEATURE [#23](https://github.com/BeAPI/acf-options-for-polylang/pull/23) : requirement to php5.6 whereas namespace are 5.3 69 * 1.1.2 - 31 Jul 2018 70 * FIX [#22](https://github.com/BeAPI/acf-options-for-polylang/pull/22) : error with repeater fields default values 71 * 1.1.1 - 9 Mai 2018 72 * FIX [#15](https://github.com/BeAPI/acf-options-for-polylang/issues/15) : way requirements are checked to trigger on front / admin 73 * 1.1.0 - Mar 2018 74 * True (complet) plugin. 75 * Add check for ACF 5.6. 76 * 1.0.2 - 23 Dec 2017 77 * Refactor and reformat. 78 * Handle all options page and custom post_id. 79 * Now load only if ACF & Polylang are activated. 80 * Load later at plugins loaded. 81 * 1.0.1 - 19 Sep 2016 82 * Plugin update. 83 * 1.0.0 - 8 Mar 2016 84 * Init plugin. 61 = 1.1.7 - 07 May 2019 = 62 - Feature: Add a context-sensitive help to the user on ACF options page (tired of updating the generic options ...) 63 - Improve: object detection from ACF with get_field() 64 - Feature: Add translation POT and french translation 65 - FEATURE [#31](https://github.com/BeAPI/acf-options-for-polylang/issues/31): Brand for wp.org 66 - Test: Test up on WP 5.2 67 - FIX [#41](https://github.com/BeAPI/acf-options-for-polylang/issues/41): fix bug with all language failback and repeater 68 69 = 1.1.6 - 19 Mar 2019 = 70 - FIX [#32](https://github.com/BeAPI/acf-options-for-polylang/issues/32) & [#40](https://github.com/BeAPI/acf-options-for-polylang/issues/40) : fix `get_field()` if an object is provided (WP Term, WP Post, WP Comment) 71 72 = 1.1.5 - 11 Dec 2018 = 73 - FIX wrong constant 74 75 = 1.1.4 - 13 Nov 2018 = 76 - Refactor by adding the Helpers class 77 - FEATURE [#26](https://github.com/BeAPI/acf-options-for-polylang/issues/26) : allow to precise to show or hide default values for a specific option page 78 - FEATURE [#21](https://github.com/BeAPI/acf-options-for-polylang/pull/21) : handle custom option id 79 80 = 1.1.3 - 2 Aug 2018 = 81 - FEATURE [#23](https://github.com/BeAPI/acf-options-for-polylang/pull/23) : requirement to php5.6 whereas namespace are 5.3 82 83 = 1.1.2 - 31 Jul 2018 = 84 - FIX [#22](https://github.com/BeAPI/acf-options-for-polylang/pull/22) : error with repeater fields default values 85 86 = 1.1.1 - 9 Mai 2018 = 87 - FIX [#15](https://github.com/BeAPI/acf-options-for-polylang/issues/15) : way requirements are checked to trigger on front / admin 88 89 = 1.1.0 - Mar 2018 = 90 - True (complet) plugin. 91 - Add check for ACF 5.6. 92 93 = 1.0.2 - 23 Dec 2017 = 94 - Refactor and reformat. 95 - Handle all options page and custom post_id. 96 - Now load only if ACF & Polylang are activated. 97 - Load later at plugins loaded. 98 99 = 1.0.1 - 19 Sep 2016 = 100 - Plugin update. 101 102 = 1.0.0 - 8 Mar 2016 = 103 - Init plugin.
Note: See TracChangeset
for help on using the changeset viewer.