-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
adb7029
commit 6dd1453
Showing
11 changed files
with
275 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Ultimate Member - Polylang | ||
|
||
Integrates the **Ultimate Member** community plugin with the **Polylang** multilingual plugin. | ||
Integrates the **Ultimate Member** plugin with the **Polylang** plugin. Makes Ultimate Member multilingual. | ||
|
||
## Key features | ||
|
||
|
@@ -12,49 +12,55 @@ Integrates the **Ultimate Member** community plugin with the **Polylang** multil | |
|
||
## Installation | ||
|
||
__Note:__ This plugin requires the [Ultimate Member](https://wordpress.org/plugins/ultimate-member/) and [Polylang](https://uk.wordpress.org/plugins/polylang/) plugins to be installed first. | ||
__Note:__ This plugin requires the [Ultimate Member](https://wordpress.org/plugins/ultimate-member/) and [Polylang](https://wordpress.org/plugins/polylang/) plugins to be installed first. | ||
|
||
### How to install from GitHub | ||
|
||
Open git bash, navigate to the **plugins** folder and execute this command: | ||
|
||
`git clone --branch=main [email protected]:umdevelopera/um-polylang.git um-polylang` | ||
|
||
Once the plugin is cloned, enter your site admin dashboard and go to _wp-admin > Plugins > Installed Plugins_. Find the "Ultimate Member - Polylang" plugin and click the "Activate" link. | ||
Once the plugin is cloned, enter your site admin dashboard and go to _wp-admin > Plugins > Installed Plugins_. Find the **Ultimate Member - Polylang** plugin and click the **Activate** link. | ||
|
||
### How to install from ZIP archive | ||
|
||
You can install this plugin from the [ZIP archive](https://drive.google.com/file/d/1Lpgu5b-6CLkjK0Ik24CBB836aIcRcmaj/view) as any other plugin. Follow [this instruction](https://wordpress.org/support/article/managing-plugins/#upload-via-wordpress-admin). | ||
You can install this plugin from the [ZIP archive](https://drive.google.com/file/d/17n3Kr05_B_edsGY7An7xu85TZ7H5gbOT/view?usp=sharing) as any other plugin. Follow [this instruction](https://wordpress.org/support/article/managing-plugins/#upload-via-wordpress-admin). | ||
|
||
## How to use | ||
|
||
### How to translate pages | ||
|
||
Go to *wp-admin > Pages* to translate Ultimate Member pages. Click the **Create Pages** button in the notice to duplicate Ultimate Member pages for all languages. Or click the "+" icon unter the flag to duplicate each page manually. | ||
|
||
Image - Translate pages. | ||
![Pages](https://github.com/umdevelopera/um-polylang/assets/113178913/40543c1b-d428-4832-9090-d2cc9166b616) | ||
|
||
Go to *wp-admin > Settings > Permalinks* and click the **Save Changes** button if you need to update rewrite rules for the Account and User page permalinks. | ||
Note: The "Post name" permalink structure is recommended. | ||
|
||
Image - Permalink settings. | ||
![WP Settings, Permalink (default)](https://github.com/umdevelopera/um-polylang/assets/113178913/69be91c9-12dd-490c-9145-b163c5beb26d) | ||
|
||
### How to translate forms | ||
|
||
Go to *wp-admin > Ultimate Member > Forms* to translate Ultimate Member forms. Click the **Create Forms** button in the notice to duplicate Ultimate Member forms for all languages. Or click the "+" icon unter the flag to duplicate each form manually. | ||
|
||
Once forms for languages are created you can open these forms and translate fields. You have to translate a **Label** for custom fields. You also can translate **Placeholder** and **Help Text** if needed. | ||
|
||
Image - Translate forms. | ||
![Forms](https://github.com/umdevelopera/um-polylang/assets/113178913/76763122-a774-4778-ab2c-748b3e983779) | ||
|
||
### How to translate E-mails | ||
|
||
Go to *wp-admin > Ultimate Member > Settings > Email* to translate email templates. Click the "+" icon unter the flag to translate a template for the language. The plugin saves translated email templates to locale subfolders in the theme, see [Email Templates](https://docs.ultimatemember.com/article/1335-email-templates). | ||
|
||
Image - Translate emails. | ||
![Email](https://github.com/umdevelopera/um-polylang/assets/113178913/17167ba5-8564-4fe9-ba33-ef69bfb67f57) | ||
|
||
Go to *wp-admin > Settings > Permalinks* and click the "Save Changes" button if you need to update rewrite rules for the Account and Profile permalinks. | ||
|
||
Image - Permalink settings. | ||
![WP Settings, Permalink (default)](https://github.com/umdevelopera/um-polylang/assets/113178913/69be91c9-12dd-490c-9145-b163c5beb26d) | ||
|
||
__Note:__ The "Post name" permalink structure is recommended. | ||
|
||
## Support | ||
|
||
This is a free extension created for the community. The Ultimate Member team does not provide support for this extension. Open new [issue](https://github.com/umdevelopera/um-polylang/issues) if you face a problem. | ||
This is a free extension created for the community. The Ultimate Member team does not provide support for this extension. | ||
Open new [issue](https://github.com/umdevelopera/um-polylang/issues) if you are facing a problem or have a suggestion. | ||
|
||
## Related links | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
<?php | ||
/** | ||
* Create translated posts and forms | ||
* | ||
* @package um_ext\um_polylang\core | ||
*/ | ||
|
||
namespace um_ext\um_polylang\core; | ||
|
||
if ( ! defined( 'ABSPATH' ) ) { | ||
exit; | ||
} | ||
|
||
/** | ||
* Create translated pages and forms | ||
* | ||
* @package um_ext\um_polylang\core | ||
*/ | ||
class Posts { | ||
|
||
public function __construct() { | ||
add_action( 'pll_save_post', array( $this, 'pll_save_post' ), 20, 3 ); | ||
} | ||
|
||
|
||
/** | ||
* Create pages and forms for languages. | ||
* | ||
* @since 1.1.0 | ||
* | ||
* @param array $posts An array of posts to duplicate. | ||
* @param string $post_type Post type. | ||
* | ||
* @return array Information about posts. | ||
*/ | ||
public function create_posts( $posts, $post_type ) { | ||
|
||
$languages = pll_languages_list(); | ||
if ( empty( $languages ) || empty( $posts ) ) { | ||
return; | ||
} | ||
$def_lang = pll_default_language(); | ||
|
||
$posts_translations = array(); | ||
foreach( $posts as $post => $post_id ) { | ||
$cur_lang = PLL()->model->post->get_language( $post_id ); | ||
if ( false === $cur_lang ) { | ||
PLL()->model->post->set_language( $post_id, PLL()->pref_lang ); | ||
} | ||
if ( $def_lang !== $cur_lang->get_prop( 'slug' ) ) { | ||
continue; | ||
} | ||
|
||
$translations = pll_get_post_translations( $post_id ); | ||
$untranslated = array_diff( $languages, array_keys( $translations ) ); | ||
|
||
if ( $untranslated ) { | ||
$postdata = get_post( $post_id, ARRAY_A ); | ||
$postmeta = get_post_meta( $post_id ); | ||
|
||
foreach ( $untranslated as $lang ) { | ||
$tr_arr = $postdata; | ||
$tr_arr['ID'] = null; | ||
$tr_arr['post_date'] = null; | ||
$tr_arr['post_date_gmt'] = null; | ||
$tr_arr['post_name'] = $tr_arr['post_name'] . '-' . $lang; | ||
$tr_arr['post_title'] = $tr_arr['post_title'] . " ($lang)"; | ||
|
||
// Polylang need the 'new_lang' parameter to set a proper language. | ||
$_GET['new_lang'] = $lang; | ||
$tr_id = wp_insert_post( $tr_arr ); | ||
unset( $_GET['new_lang'] ); | ||
|
||
// Duplicate postmeta. | ||
foreach ( $postmeta as $key => $value ) { | ||
if ( '_um_core' === $key ) { | ||
continue; | ||
} | ||
$meta_value = maybe_unserialize( $value[0] ); | ||
update_post_meta( $tr_id, $key, $meta_value ); | ||
} | ||
update_post_meta( $tr_id, '_icl_lang_duplicate_of', $post_id ); | ||
|
||
$translations[ $lang ] = $tr_id; | ||
do_action( 'um_polylang_create_posts', $tr_id, $post_id, $lang, $post_type ); | ||
} | ||
PLL()->model->post->save_translations( $post_id, $translations ); | ||
} | ||
|
||
$posts_translations[ $post ] = $translations; | ||
} | ||
UM()->rewrite()->reset_rules(); | ||
|
||
return $posts_translations; | ||
} | ||
|
||
|
||
/** | ||
* Synchronizes post fields in the page or form translation. | ||
* | ||
* Hook `pll_save_post` fires after the post language and translations are saved. | ||
* | ||
* @see \PLL_CRUD_Posts::save_post() | ||
* | ||
* @since 1.1.1 | ||
* | ||
* @param int $tr_id Post id. | ||
* @param WP_Post $post Post object. | ||
* @param int[] $translations Post translations. | ||
* | ||
* @return void | ||
*/ | ||
public function pll_save_post( $tr_id, $post, $translations ) { | ||
global $wpdb; | ||
|
||
if ( | ||
is_a( $post, 'WP_Post' ) && 'auto-draft' === $post->post_status | ||
&& PLL()->model->post->current_user_can_synchronize( $tr_id ) | ||
&& isset( $GLOBALS['pagenow'], $_GET['from_post'], $_GET['new_lang'] ) && 'post-new.php' === $GLOBALS['pagenow'] | ||
) { | ||
check_admin_referer( 'new-post-translation' ); | ||
|
||
$lang = sanitize_key( $_GET['new_lang'] ); | ||
$post_id = absint( $_GET['from_post'] ); | ||
$original = get_post( $post_id ); | ||
|
||
if ( empty( $original ) ) { | ||
return; | ||
} | ||
|
||
if ( 'um_form' === $original->post_type | ||
|| ( 'page' === $original->post_type && in_array( $post_id, UM()->config()->permalinks, true ) ) | ||
) { | ||
|
||
// Duplicate content. | ||
$wpdb->update( | ||
$wpdb->posts, | ||
array( | ||
'post_content' => $original->post_content, | ||
'post_title' => $original->post_title . " ($lang)", | ||
), | ||
array( | ||
'ID' => $tr_id, | ||
) | ||
); | ||
|
||
// Duplicate postmeta. | ||
$postmeta = get_post_meta( $post_id ); | ||
foreach ( $postmeta as $key => $value ) { | ||
if ( '_um_core' === $key ) { | ||
continue; | ||
} | ||
$meta_value = maybe_unserialize( $value[0] ); | ||
update_post_meta( $tr_id, $key, $meta_value ); | ||
} | ||
update_post_meta( $tr_id, '_icl_lang_duplicate_of', $post_id ); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.