Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development 1.1.0 #6

Merged
merged 6 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,67 @@
# Ultimate Member - Polylang
Integrates the **Ultimate Member** community plugin with the **Polylang** multilingual plugin.

__Note:__ This is a free extension created for the community. The Ultimate Member team does not provide any support for this extension.
Integrates the **Ultimate Member** community plugin with the **Polylang** multilingual plugin.

## Key features

- Localized permalinks for the Account and User (profile) pages.
- Ability to duplicate Ultimate Member forms for all languages in one click.
- Ability to duplicate Ultimate Member pages for all languages in one click.
- Ability to translate email templates.
- Ability to translate bio (description) field in profile.
- Proper permalinks for the Account and User (profile) pages.

## 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.

### Clone from GitHub
### 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.

### Install from ZIP archive
You can install this plugin from the [ZIP archive](https://drive.google.com/file/d/175PVG6tLK7z1wcrAawFfQdTVIC071Eup/view) as any other plugin. Follow [this instruction](https://wordpress.org/support/article/managing-plugins/#upload-via-wordpress-admin).
### 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).

## How to use
Go to *wp-admin > Ultimate Member > Settings > Email* to translate email templates. Click the "+" icon unter the flag to translate a template for the needed language. The plugin saves translated email templates to locale subfolders in the theme. See details [here](https://docs.ultimatemember.com/article/1335-email-templates).

Go to *wp-admin > Pages* to translate pages Account, Login, Members, Password Reset, Register, User. Click the "+" icon unter the flag to translate a page for the needed language. See details [here](https://docs.ultimatemember.com/article/1449-how-to-translate-plugin#forms).
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.

Go to *wp-admin > Settings > Permalinks* and click the "Save Changes" button to update rewrite rules for the Account and Profile permalinks.
Image - Translate pages.
![Pages](https://github.com/umdevelopera/um-polylang/assets/113178913/40543c1b-d428-4832-9090-d2cc9166b616)

__Note:__ The "Post name" permalink structure is recommended.
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.

### Screenshots:
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 email templates.
![UM Settings, Email (polylang)](https://github.com/umdevelopera/um-polylang/assets/113178913/65d14995-257d-4311-a93a-8f944ea12ba9)
Image - Translate forms.
![Forms](https://github.com/umdevelopera/um-polylang/assets/113178913/76763122-a774-4778-ab2c-748b3e983779)

Image - Translate pages.
![WP Pages (polylang)](https://github.com/umdevelopera/um-polylang/assets/113178913/1329f025-a464-4c52-bf9f-99261fb5e242)
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)

## Related links:
__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.

## Related links

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/

Article: [How to translate plugin](https://docs.ultimatemember.com/article/1449-how-to-translate-plugin#switch)
Article: [How to translate plugin](https://docs.ultimatemember.com/article/1449-how-to-translate-plugin#switch).
301 changes: 301 additions & 0 deletions includes/admin/class-admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,301 @@
<?php
/**
* Admin features.
*
* @package um_ext\um_polylang\admin
*/

namespace um_ext\um_polylang\admin;

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

if ( ! class_exists( 'um_ext\um_polylang\admin\Admin' ) ) {


/**
* Class Admin.
*
* @package um_ext\um_polylang\admin
*/
class Admin {


/**
* Admin constructor.
*/
public function __construct() {
// Notices.
add_action( 'in_admin_header', array( $this, 'notice_create_forms' ) );
add_action( 'in_admin_header', array( $this, 'notice_create_pages' ) );
add_filter( 'um_adm_action_custom_notice_update', array( $this, 'notice_update' ), 10, 2 );

// Create Forms.
add_action( 'um_admin_do_action__um_pll_create_forms', array( $this, 'action_create_forms' ) );

// Create Pages.
add_action( 'um_admin_do_action__um_pll_create_pages', array( $this, 'action_create_pages' ) );

// Translatable post types.
add_filter( 'pll_get_post_types', array( $this, 'pll_get_post_types' ), 10, 2 );

// Settings, Email tab.
$this->settings_email_tab();

// Forms table styles.
add_action( 'admin_footer', array( $this, 'styles' ) );
}


/**
* The "Create Forms" button handler.
*/
public function action_create_forms() {
$args = array(
'fields' => 'ids',
'nopaging' => true,
'post_status' => 'publish',
'post_type' => 'um_form',
);
$posts = get_posts( $args );

UM()->Polylang()->setup()->create_posts( $posts, 'um_form' );

$url = add_query_arg( 'update', 'um_pll_create_forms', admin_url( 'edit.php?post_type=um_form' ) );
exit( wp_safe_redirect( $url ) );
}


/**
* The "Create Pages" button handler.
*/
public function action_create_pages() {
$posts = UM()->config()->permalinks;

UM()->Polylang()->setup()->create_posts( $posts, 'page' );

$url = add_query_arg( 'update', 'um_pll_create_pages', admin_url( 'edit.php?post_type=page' ) );
exit( wp_safe_redirect( $url ) );
}


/**
* Display a notice with the "Create Forms" button.
*
* @return void
*/
public function notice_create_forms() {
$screen = get_current_screen();
if ( ! is_object( $screen ) || 'edit-um_form' !== $screen->id ) {
return;
}

$languages = pll_languages_list();
if ( empty( $languages ) ) {
return;
}

$args = array(
'fields' => 'ids',
'nopaging' => true,
'post_status' => 'publish',
'post_type' => 'um_form',
);
$posts = get_posts( $args );
if ( empty( $posts ) ) {
return;
}

$need_translations = array();
foreach ( $posts as $post => $post_id ) {
$post_translations = pll_get_post_translations( $post_id );
if ( array_diff( $languages, array_keys( $post_translations ) ) ) {
$need_translations[] = $post_id;
break;
}
}

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();
?>

<p>
<?php
// translators: %s: Plugin name.
echo wp_kses(
sprintf( __( '%s needs to create required forms for every language to function correctly.', 'um-polylang' ), UM_PLUGIN_NAME ),
UM()->get_allowed_html( 'admin_notice' )
);
?>
</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();

$notice_data = array(
'class' => 'notice-warning',
'message' => $message,
'dismissible' => true,
);

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


/**
* Display a notice with the "Create Pages" button.
*
* @return void
*/
public function notice_create_pages() {
$screen = get_current_screen();
if ( ! is_object( $screen ) || 'edit-page' !== $screen->id ) {
return;
}

$languages = pll_languages_list();
if ( empty( $languages ) ) {
return;
}

$posts = UM()->config()->permalinks;
if ( empty( $posts ) ) {
return;
}

$need_translations = array();
foreach ( $posts as $post => $post_id ) {
$post_translations = pll_get_post_translations( $post_id );
if ( array_diff( $languages, array_keys( $post_translations ) ) ) {
$need_translations[] = $post_id;
break;
}
}

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

$url = add_query_arg( $url_params );

ob_start();
?>

<p>
<?php
// translators: %s: Plugin name.
echo wp_kses(
sprintf( __( '%s needs to create required pages for every language to function correctly.', 'um-polylang' ), UM_PLUGIN_NAME ),
UM()->get_allowed_html( 'admin_notice' )
);
?>
</p>
<p>
<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();

$notice_data = array(
'class' => 'notice-warning',
'message' => $message,
'dismissible' => true,
);

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


/**
* Display a notice after um_adm_action.
*
* @param array $messages Admin notice messages.
* @param string $update Update action key.
*
* @return array
*/
public function notice_update( $messages, $update ) {

switch ( $update ) {

case 'um_pll_create_forms':
$messages[0]['content'] = __( 'Forms have been duplicated successfully.', 'um-polylang' );
break;

case 'um_pll_create_pages':
$messages[0]['content'] = __( 'Pages have been duplicated successfully.', 'um-polylang' );
break;
}

return $messages;
}


/**
* Filters the list of post types available for translation.
*
* @param string[] $post_types List of post type names (as array keys and values).
* @param bool $is_settings True when displaying the list of custom post types in Polylang settings.
*
* @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 );
}


/**
* Extend settings Email tab.
*
* @return um_ext\um_polylang\admin\Mail()
*/
public function settings_email_tab() {
if ( empty( UM()->classes['um_polylang_admin_mail'] ) ) {
require_once 'class-mail.php';
UM()->classes['um_polylang_admin_mail'] = new Mail();
}
return UM()->classes['um_polylang_admin_mail'];
}


/**
* Fix column width in the "Forms" table.
*/
public function styles() {
$screen = get_current_screen();
if ( ! is_object( $screen ) || 'edit-um_form' === $screen->id ) {
?>
<style type="text/css">
@media screen and (max-width: 1200px) {
.um-admin.post-type-um_form tr > * { padding-left: 5px; padding-right: 5px; }
.um-admin.post-type-um_form .manage-column.column-title { width: 180px; }
.um-admin.post-type-um_form .manage-column.column-id { width: 40px; }
.um-admin.post-type-um_form .manage-column.column-mode { width: 60px; }
.um-admin.post-type-um_form .manage-column.column-is_default { width: 50px; }
.um-admin.post-type-um_form .manage-column.column-shortcode { width: 120px; }
}
</style><?php
}
}
}

}
Loading