Skip to content

Commit

Permalink
Prepare version 1.2.0
Browse files Browse the repository at this point in the history
- added the [um_pll_switcher] shortcode.
- make Account Tabs translatable.
- make Profile Tabs translatable.
- fixed the load_textdomain php notice.
  • Loading branch information
umdevelopera committed Feb 9, 2025
1 parent 4d619fc commit bb20604
Show file tree
Hide file tree
Showing 13 changed files with 793 additions and 98 deletions.
67 changes: 56 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ Integrates the **Ultimate Member** plugin with the **Polylang** plugin. Makes Ul

## Key features

- Localized permalinks for the Account and User (profile) pages.
- Ability to duplicate Ultimate Member forms for all languages in one click.
- Language switcher shortcode. Display the Polylang language switcher where you need it.
- Localize permalinks for the Account and User (profile) pages.
- Ability to duplicate Ultimate Member pages for all languages in one click.
- Ability to duplicate Ultimate Member forms for all languages in one click.
- Ability to translate email templates.
- Ability to translate bio (description) field in profile.
- Integration with the [Account tabs](https://github.com/umdevelopera/um-account-tabs) extension. Makes custom account tabs translatable.
- Integration with the [Profile tabs](https://ultimatemember.com/extensions/profile-tabs/) extension. Makes custom profile tabs translatable.

## Installation

Expand All @@ -24,18 +27,42 @@ Once the plugin is cloned, enter your site admin dashboard and go to _wp-admin >

### How to install from ZIP archive

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).
You can install this plugin from the [ZIP archive](https://drive.google.com/file/d/1rj0W6639PMrFQqLfeCZXhoYgRcnCac8d/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 display language switcher

Add the **[um_pll_switcher]** shortcode to the place you need.

Shortcode attributes:
- int `dropdown` Displays languages into a dropdown if set to 1. Defaults to 0.
- int `show_flags` Displays flags if set to 1. Defaults to 1.
- int `show_names` Shows language names if set to 1. Defaults to 1.
- string `display_names_as` Whether to display the language name or its slug. Accepts 'slug' and 'name'. Defaults to 'name'.
- string `item_display` Whether to display languages as a list or inline. Accepts 'list-item' and 'inline'. Defaults to 'inline'.
- string `item_spacing` Whether to preserve or discard whitespace between list items. Accepts 'preserve' and 'discard'. Defaults to 'preserve'.
- int `hide_current` Hides the current language if set to 1. Defaults to 0.
- int `hide_if_no_translation` Hides the link if there is no translation if set to 1. Defaults to 0.

See also [Options](https://polylang.pro/doc/the-language-switcher/#options)

**Screenshots**

Image - Language switcher shortcode in the header template.
![Language switcher shortcode in the header template](https://github.com/user-attachments/assets/b0fa465c-52fc-4eb8-a19d-c330f397da61)

Image - Language switcher in the page header.
![Language switcher in the page header](https://github.com/user-attachments/assets/a39efdb2-183e-44ba-bc1d-3f39892d5004)

### 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)
![WP Pages cr](https://github.com/user-attachments/assets/ef991008-2d5f-4dd7-9514-a5fd0d256dc0)

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.
Go to *wp-admin > Settings > Permalinks* if you need to update rewrite rules for the Account and User page permalinks. Don't change settings on this page, just visit it. WordPress will update rewrite rules.
Note: The "Post name" permalink structure is recommended.

Image - Permalink settings.
Expand All @@ -46,12 +73,12 @@ Image - Permalink settings.
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.

Image - Translate forms.
![Forms](https://github.com/umdevelopera/um-polylang/assets/113178913/76763122-a774-4778-ab2c-748b3e983779)
![UM Forms cr](https://github.com/user-attachments/assets/a6057994-ffd9-41d4-ac47-2436550732ff)

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.

**Choices** are not translatable, this is necessary for the directory search to work correctly. Don't try to translate choices in the field settings! You can use custom functions to translate choices.
See examples:
__Note:__ Choices in the Checkbox, Radio, Dropdown and Multi-Select fields are not translatable. This is necessary for the directory filters to work correctly. Don't try to translate choices in the field settings!
You can use custom functions to translate choices. See examples here:
- [How to translate choices of the Checkbox field](https://gist.github.com/umdevelopera/f7b0e07d5db870c9ce9fc1e513224e45)
- [How to translate choices of the Dropdown field](https://gist.github.com/umdevelopera/bcc8c882ead5914845b489ece73b612d)

Expand All @@ -62,7 +89,25 @@ See examples:
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)
![UM Settings, Email cr](https://github.com/user-attachments/assets/47901a64-ea93-4bdd-b70c-47f0dd3fea08)

### How to translate custom account tabs

This feature is available if you use the [Account tabs](https://github.com/umdevelopera/um-account-tabs) extension.

Go to *wp-admin > Ultimate Member > Account Tabs*. Click the **Create Tabs** button in the notice to duplicate tabs for all languages. Once the tabs are duplicated for each language, you can manually edit the tab title.

Image - Translate account tabs.
![WP, Ultimate Member, Account Tabs (Create Tabs) cr](https://github.com/user-attachments/assets/bd7e22ae-ca3a-4cd4-96d8-6a9e339b1a33)

### How to translate custom profile tabs

This feature is available if you use the [Profile tabs](https://ultimatemember.com/extensions/profile-tabs/) extension.

Go to *wp-admin > Ultimate Member > Profile Tabs*. Click the **Create Tabs** button in the notice to duplicate tabs for all languages. Once the tabs are duplicated for each language, you can manually edit the tab title.

Image - Translate profile tabs.
![WP, Ultimate Member, ProfileTabs (Create Tabs) cr](https://github.com/user-attachments/assets/5db162cd-9c53-4d7f-8081-63f8e31d8105)

## Support

Expand All @@ -75,6 +120,6 @@ Ultimate Member home page: https://ultimatemember.com/

Ultimate Member documentation: https://docs.ultimatemember.com/

Ultimate Member on wordpress.org: https://wordpress.org/plugins/ultimate-member/
Ultimate Member download: https://wordpress.org/plugins/ultimate-member/

Article: [How to translate plugin](https://docs.ultimatemember.com/article/1449-how-to-translate-plugin#switch).
Articles: [How to translate plugin](https://docs.ultimatemember.com/article/1449-how-to-translate-plugin#switch), [The language switcher](https://polylang.pro/doc/the-language-switcher/)
87 changes: 49 additions & 38 deletions includes/admin/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@
*/
class Admin {

const NOTICES = array(
'um_pll_create_forms',
'um_pll_create_pages',
'um_pll_create_account_tabs',
'um_pll_create_profile_tabs',
);

const POST_TYPES = array(
'um_form' => 'um_form',
'um_account_tabs' => 'um_account_tabs',
'um_profile_tabs' => 'um_profile_tabs',
);

/**
* Admin constructor.
Expand Down Expand Up @@ -110,8 +122,11 @@ public function notice_create_forms() {
}

$need_translations = array();
foreach ( $posts as $post => $post_id ) {
if ( $def_lang !== pll_get_post_language( $post_id ) ) {
foreach ( $posts as $post_id ) {
$cur_lang = pll_get_post_language( $post_id );
if ( false === $cur_lang ) {
pll_set_post_language( $post_id, PLL()->pref_lang );
} elseif ( $def_lang !== $cur_lang ) {
continue;
}
$post_translations = pll_get_post_translations( $post_id );
Expand All @@ -121,43 +136,41 @@ public function notice_create_forms() {
}

if ( $need_translations ) {
$url_params = array(
'um_adm_action' => 'um_pll_create_forms',
'_wpnonce' => wp_create_nonce( 'um_pll_create_forms' ),
);

$url = add_query_arg( $url_params );

ob_start();
?>
$url_params = array(
'um_adm_action' => 'um_pll_create_forms',
'_wpnonce' => wp_create_nonce( 'um_pll_create_forms' ),
);

<p>
<?php
// translators: %1$s - plugin name, %2$s - a list of forms.
echo esc_html(
sprintf(
__( '%1$s needs to create required forms for every language to function correctly. Forms that need translation: %2$s', 'um-polylang' ),
UM_PLUGIN_NAME,
implode( ', ', $need_translations )
)
);
?>
</p>
<p>
<a href="<?php echo esc_url( $url ); ?>" class="button button-primary"><?php esc_html_e( 'Create Forms', 'um-polylang' ); ?></a>
<a href="javascript:void(0);" class="button-secondary um_secondary_dismiss"><?php esc_html_e( 'No thanks', 'um-polylang' ); ?></a>
</p>
$url = add_query_arg( $url_params );

ob_start();
?>
<p>
<?php
$message = ob_get_clean();

$notice_data = array(
'class' => 'notice-warning',
'message' => $message,
'dismissible' => true,
// translators: %1$s - plugin name, %2$s - a list of forms.
echo esc_html(
sprintf(
__( '%1$s needs to create required forms for every language to function correctly. Forms that need translation: %2$s', 'um-polylang' ),
UM_PLUGIN_NAME,
implode( ', ', $need_translations )
)
);
?>
</p>
<p>
<a href="<?php echo esc_url( $url ); ?>" class="button button-primary"><?php esc_html_e( 'Create Forms', 'um-polylang' ); ?></a>
<a href="javascript:void(0);" class="button-secondary um_secondary_dismiss"><?php esc_html_e( 'No thanks', 'um-polylang' ); ?></a>
</p>
<?php
$message = ob_get_clean();

UM()->admin()->notices()->add_notice( 'um_pll_create_forms', $notice_data, 20 );
$notice_data = array(
'class' => 'notice-warning',
'message' => $message,
'dismissible' => true,
);

UM()->admin()->notices()->add_notice( 'um_pll_create_forms', $notice_data, 20 );
}
}

Expand Down Expand Up @@ -205,7 +218,6 @@ public function notice_create_pages() {

ob_start();
?>

<p>
<?php
// translators: %1$s - plugin name, %2$s - a list of pages.
Expand All @@ -222,7 +234,6 @@ public function notice_create_pages() {
<a href="<?php echo esc_url( $url ); ?>" class="button button-primary"><?php esc_html_e( 'Create Pages', 'um-polylang' ); ?></a>
<a href="javascript:void(0);" class="button-secondary um_secondary_dismiss"><?php esc_html_e( 'No thanks', 'um-polylang' ); ?></a>
</p>

<?php
$message = ob_get_clean();

Expand Down Expand Up @@ -271,8 +282,8 @@ public function notice_update( $messages, $update ) {
* @return string[] List of post type names.
*/
public function pll_get_post_types( $post_types, $is_settings ) {
$post_types['um_form'] = 'um_form';
return array_unique( $post_types );
$um_post_types = (array) apply_filters( 'um_pll_get_post_types', self::POST_TYPES, $is_settings );
return array_merge( $post_types, $um_post_types );
}


Expand Down
16 changes: 16 additions & 0 deletions includes/core/class-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

namespace um_ext\um_polylang\core;
use um_ext\um_polylang\admin\Admin;

if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand All @@ -31,11 +32,26 @@ public function flush_rewrite_rules() {
}


/**
* Reset hidden admin notices.
*
* @since 1.2.0
*/
public function reset_admin_notices() {
$hidden_notices = get_option( 'um_hidden_admin_notices', array() );
if ( $hidden_notices && is_array( $hidden_notices ) ) {
$hidden_notices = array_diff( $hidden_notices, Admin::NOTICES );
update_option( 'um_hidden_admin_notices', $hidden_notices );
}
}


/**
* Run on plugin activation.
*/
public function run() {
$this->flush_rewrite_rules();
$this->reset_admin_notices();
}

}
86 changes: 86 additions & 0 deletions includes/core/class-shortcodes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
/**
* Add shortcodes.
*/

namespace um_ext\um_polylang\core;

use \PLL_Switcher;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* Add shortcodes.
*
* @package um_ext\um_polylang\core
*/
class Shortcodes extends PLL_Switcher {
const DEFAULTS = array(
'dropdown' => 0, // Display as list and not as dropdown.
'show_flags' => 1, // Don't show flags.
'show_names' => 1, // Show language names.
'display_names_as' => 'name', // Display the language name.
'item_display' => 'inline', // CSS "display" property for list items.
'item_spacing' => 'preserve', // Preserve whitespace between list items.
'force_home' => 0, // Tries to find a translation.
'hide_current' => 0, // Don't hide the current language.
'hide_if_no_translation' => 0, // Don't hide the link if there is no translation.
'admin_render' => 0, // Make the switcher in a frontend context.
'echo' => 0, // Echoes the list.
'raw' => 0, // Build the language switcher.
);

/**
* Class constructor.
*/
public function __construct() {
add_shortcode( 'um_pll_switcher', array( $this, 'um_pll_switcher' ) );
}

/**
* Displays a language switcher.
*
* Shortcode: [um_pll_switcher]
*
* @param array $atts {
* Optional array of arguments.
*
* @type int $dropdown The list is displayed as dropdown if set, defaults to 0.
* @type int $show_flags Displays flags if set to 1, defaults to 1.
* @type int $show_names Shows language names if set to 1, defaults to 1.
* @type string $display_names_as Whether to display the language name or its slug, valid options are 'slug' and 'name', defaults to 'name'.
* @type string $item_display Optional CSS "display" property for list items. Valid options are 'list-item' and 'inline', defaults to 'inline'.
* @type string $item_spacing Whether to preserve or discard whitespace between list items, valid options are 'preserve' and 'discard', defaults to 'preserve'.
* @type int $hide_current Hides the current language if set to 1, defaults to 0.
* @type int $hide_if_no_translation Hides the link if there is no translation if set to 1, defaults to 0.
* }
* @return string|array either the html markup of the switcher or the raw elements to build a custom language switcher
*/
function um_pll_switcher( $atts ) {
$args = shortcode_atts( self::DEFAULTS, $atts );

$output = $this->the_languages( PLL()->links, $args );
if ( empty( $args['dropdown'] ) ) {
if ( ! empty( $args['item_display'] ) ) {
$search = '<li';
$style = ' style="display: ' . $args['item_display'] . ';" ';
$output = str_replace( $search, $search . $style, $output );
}
$output = '<ul class="um-pll-switcher">' . $output . '</ul>';
} else {
if ( ! empty( $args['show_flags'] ) ) {
$lang = UM()->Polylang()->get_current();
$language = PLL()->model->get_language( $lang );
if ( is_object( $language ) ) {
$output = $language->flag . ' ' . $output;
}
}
$output = '<div class="um-pll-switcher">' . $output . '</div>';
}

return $output;
}

}
Loading

0 comments on commit bb20604

Please sign in to comment.