Skip to content

Commit ecc84fd

Browse files
committed
Prepare version 1.1.0
- added the Admin class. This class displays admin notices. - added the Setup class. This class creates pages and updates permalinks. - make UM forms translateable - fixed Fatal error that occurs is Polylang can not get needed language - fixed the "Class not found" error - updated documentation
1 parent a05ba9c commit ecc84fd

14 files changed

+999
-289
lines changed

README.md

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,67 @@
11
# Ultimate Member - Polylang
2-
Integrates the **Ultimate Member** community plugin with the **Polylang** multilingual plugin.
32

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

65
## Key features
6+
7+
- Localized permalinks for the Account and User (profile) pages.
8+
- Ability to duplicate Ultimate Member forms for all languages in one click.
9+
- Ability to duplicate Ultimate Member pages for all languages in one click.
710
- Ability to translate email templates.
811
- Ability to translate bio (description) field in profile.
9-
- Proper permalinks for the Account and User (profile) pages.
1012

1113
## Installation
1214

1315
__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.
1416

15-
### Clone from GitHub
17+
### How to install from GitHub
18+
1619
Open git bash, navigate to the **plugins** folder and execute this command:
1720

1821
`git clone --branch=main git@github.com:umdevelopera/um-polylang.git um-polylang`
1922

2023
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.
2124

22-
### Install from ZIP archive
23-
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).
25+
### How to install from ZIP archive
26+
27+
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).
2428

2529
## How to use
26-
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).
2730

28-
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).
31+
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.
2932

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

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

34-
### Screenshots:
38+
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.
3539

36-
Image - Translate email templates.
37-
![UM Settings, Email (polylang)](https://github.com/umdevelopera/um-polylang/assets/113178913/65d14995-257d-4311-a93a-8f944ea12ba9)
40+
Image - Translate forms.
41+
![Forms](https://github.com/umdevelopera/um-polylang/assets/113178913/76763122-a774-4778-ab2c-748b3e983779)
3842

39-
Image - Translate pages.
40-
![WP Pages (polylang)](https://github.com/umdevelopera/um-polylang/assets/113178913/1329f025-a464-4c52-bf9f-99261fb5e242)
43+
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).
44+
45+
Image - Translate emails.
46+
![Email](https://github.com/umdevelopera/um-polylang/assets/113178913/17167ba5-8564-4fe9-ba33-ef69bfb67f57)
47+
48+
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.
4149

4250
Image - Permalink settings.
4351
![WP Settings, Permalink (default)](https://github.com/umdevelopera/um-polylang/assets/113178913/69be91c9-12dd-490c-9145-b163c5beb26d)
4452

45-
## Related links:
53+
__Note:__ The "Post name" permalink structure is recommended.
54+
55+
## Support
56+
57+
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.
58+
59+
## Related links
60+
4661
Ultimate Member home page: https://ultimatemember.com/
4762

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

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

52-
Article: [How to translate plugin](https://docs.ultimatemember.com/article/1449-how-to-translate-plugin#switch)
67+
Article: [How to translate plugin](https://docs.ultimatemember.com/article/1449-how-to-translate-plugin#switch).

includes/admin/class-admin.php

Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
<?php
2+
/**
3+
* Admin features.
4+
*
5+
* @package um_ext\um_polylang\admin
6+
*/
7+
8+
namespace um_ext\um_polylang\admin;
9+
10+
if ( ! defined( 'ABSPATH' ) ) {
11+
exit;
12+
}
13+
14+
if ( ! class_exists( 'um_ext\um_polylang\admin\Admin' ) ) {
15+
16+
17+
/**
18+
* Class Admin.
19+
*
20+
* @package um_ext\um_polylang\admin
21+
*/
22+
class Admin {
23+
24+
25+
/**
26+
* Admin constructor.
27+
*/
28+
public function __construct() {
29+
// Notices.
30+
add_action( 'in_admin_header', array( $this, 'notice_create_forms' ) );
31+
add_action( 'in_admin_header', array( $this, 'notice_create_pages' ) );
32+
add_filter( 'um_adm_action_custom_notice_update', array( $this, 'notice_update' ), 10, 2 );
33+
34+
// Create Forms.
35+
add_action( 'um_admin_do_action__um_pll_create_forms', array( $this, 'action_create_forms' ) );
36+
37+
// Create Pages.
38+
add_action( 'um_admin_do_action__um_pll_create_pages', array( $this, 'action_create_pages' ) );
39+
40+
// Translatable post types.
41+
add_filter( 'pll_get_post_types', array( $this, 'pll_get_post_types' ), 10, 2 );
42+
43+
// Settings, Email tab.
44+
$this->settings_email_tab();
45+
46+
// Forms table styles.
47+
add_action( 'admin_footer', array( $this, 'styles' ) );
48+
}
49+
50+
51+
/**
52+
* The "Create Forms" button handler.
53+
*/
54+
public function action_create_forms() {
55+
$args = array(
56+
'fields' => 'ids',
57+
'nopaging' => true,
58+
'post_status' => 'publish',
59+
'post_type' => 'um_form',
60+
);
61+
$posts = get_posts( $args );
62+
63+
UM()->Polylang()->setup()->create_posts( $posts, 'um_form' );
64+
65+
$url = add_query_arg( 'update', 'um_pll_create_forms', admin_url( 'edit.php?post_type=um_form' ) );
66+
exit( wp_safe_redirect( $url ) );
67+
}
68+
69+
70+
/**
71+
* The "Create Pages" button handler.
72+
*/
73+
public function action_create_pages() {
74+
$posts = UM()->config()->permalinks;
75+
76+
UM()->Polylang()->setup()->create_posts( $posts, 'page' );
77+
78+
$url = add_query_arg( 'update', 'um_pll_create_pages', admin_url( 'edit.php?post_type=page' ) );
79+
exit( wp_safe_redirect( $url ) );
80+
}
81+
82+
83+
/**
84+
* Display a notice with the "Create Forms" button.
85+
*
86+
* @return void
87+
*/
88+
public function notice_create_forms() {
89+
$screen = get_current_screen();
90+
if ( ! is_object( $screen ) || 'edit-um_form' !== $screen->id ) {
91+
return;
92+
}
93+
94+
$languages = pll_languages_list();
95+
if ( empty( $languages ) ) {
96+
return;
97+
}
98+
99+
$args = array(
100+
'fields' => 'ids',
101+
'nopaging' => true,
102+
'post_status' => 'publish',
103+
'post_type' => 'um_form',
104+
);
105+
$posts = get_posts( $args );
106+
if ( empty( $posts ) ) {
107+
return;
108+
}
109+
110+
$need_translations = array();
111+
foreach ( $posts as $post => $post_id ) {
112+
$post_translations = pll_get_post_translations( $post_id );
113+
if ( array_diff( $languages, array_keys( $post_translations ) ) ) {
114+
$need_translations[] = $post_id;
115+
break;
116+
}
117+
}
118+
119+
if ( $need_translations ) {
120+
$url_params = array(
121+
'um_adm_action' => 'um_pll_create_forms',
122+
'_wpnonce' => wp_create_nonce( 'um_pll_create_forms' ),
123+
);
124+
125+
$url = add_query_arg( $url_params );
126+
127+
ob_start();
128+
?>
129+
130+
<p>
131+
<?php
132+
// translators: %s: Plugin name.
133+
echo wp_kses(
134+
sprintf( __( '%s needs to create required forms for every language to function correctly.', 'um-polylang' ), UM_PLUGIN_NAME ),
135+
UM()->get_allowed_html( 'admin_notice' )
136+
);
137+
?>
138+
</p>
139+
<p>
140+
<a href="<?php echo esc_url( $url ); ?>" class="button button-primary"><?php esc_html_e( 'Create Forms', 'um-polylang' ); ?></a>
141+
<a href="javascript:void(0);" class="button-secondary um_secondary_dismiss"><?php esc_html_e( 'No thanks', 'um-polylang' ); ?></a>
142+
</p>
143+
144+
<?php
145+
$message = ob_get_clean();
146+
147+
$notice_data = array(
148+
'class' => 'notice-warning',
149+
'message' => $message,
150+
'dismissible' => true,
151+
);
152+
153+
UM()->admin()->notices()->add_notice( 'um_pll_create_forms', $notice_data, 20 );
154+
}
155+
}
156+
157+
158+
/**
159+
* Display a notice with the "Create Pages" button.
160+
*
161+
* @return void
162+
*/
163+
public function notice_create_pages() {
164+
$screen = get_current_screen();
165+
if ( ! is_object( $screen ) || 'edit-page' !== $screen->id ) {
166+
return;
167+
}
168+
169+
$languages = pll_languages_list();
170+
if ( empty( $languages ) ) {
171+
return;
172+
}
173+
174+
$posts = UM()->config()->permalinks;
175+
if ( empty( $posts ) ) {
176+
return;
177+
}
178+
179+
$need_translations = array();
180+
foreach ( $posts as $post => $post_id ) {
181+
$post_translations = pll_get_post_translations( $post_id );
182+
if ( array_diff( $languages, array_keys( $post_translations ) ) ) {
183+
$need_translations[] = $post_id;
184+
break;
185+
}
186+
}
187+
188+
if ( $need_translations ) {
189+
$url_params = array(
190+
'um_adm_action' => 'um_pll_create_pages',
191+
'_wpnonce' => wp_create_nonce( 'um_pll_create_pages' ),
192+
);
193+
194+
$url = add_query_arg( $url_params );
195+
196+
ob_start();
197+
?>
198+
199+
<p>
200+
<?php
201+
// translators: %s: Plugin name.
202+
echo wp_kses(
203+
sprintf( __( '%s needs to create required pages for every language to function correctly.', 'um-polylang' ), UM_PLUGIN_NAME ),
204+
UM()->get_allowed_html( 'admin_notice' )
205+
);
206+
?>
207+
</p>
208+
<p>
209+
<a href="<?php echo esc_url( $url ); ?>" class="button button-primary"><?php esc_html_e( 'Create Pages', 'um-polylang' ); ?></a>
210+
<a href="javascript:void(0);" class="button-secondary um_secondary_dismiss"><?php esc_html_e( 'No thanks', 'um-polylang' ); ?></a>
211+
</p>
212+
213+
<?php
214+
$message = ob_get_clean();
215+
216+
$notice_data = array(
217+
'class' => 'notice-warning',
218+
'message' => $message,
219+
'dismissible' => true,
220+
);
221+
222+
UM()->admin()->notices()->add_notice( 'um_pll_create_pages', $notice_data, 20 );
223+
}
224+
}
225+
226+
227+
/**
228+
* Display a notice after um_adm_action.
229+
*
230+
* @param array $messages Admin notice messages.
231+
* @param string $update Update action key.
232+
*
233+
* @return array
234+
*/
235+
public function notice_update( $messages, $update ) {
236+
237+
switch ( $update ) {
238+
239+
case 'um_pll_create_forms':
240+
$messages[0]['content'] = __( 'Forms have been duplicated successfully.', 'um-polylang' );
241+
break;
242+
243+
case 'um_pll_create_pages':
244+
$messages[0]['content'] = __( 'Pages have been duplicated successfully.', 'um-polylang' );
245+
break;
246+
}
247+
248+
return $messages;
249+
}
250+
251+
252+
/**
253+
* Filters the list of post types available for translation.
254+
*
255+
* @param string[] $post_types List of post type names (as array keys and values).
256+
* @param bool $is_settings True when displaying the list of custom post types in Polylang settings.
257+
*
258+
* @return string[] List of post type names.
259+
*/
260+
public function pll_get_post_types( $post_types, $is_settings ) {
261+
$post_types['um_form'] = 'um_form';
262+
return array_unique( $post_types );
263+
}
264+
265+
266+
/**
267+
* Extend settings Email tab.
268+
*
269+
* @return um_ext\um_polylang\admin\Mail()
270+
*/
271+
public function settings_email_tab() {
272+
if ( empty( UM()->classes['um_polylang_admin_mail'] ) ) {
273+
require_once 'class-mail.php';
274+
UM()->classes['um_polylang_admin_mail'] = new Mail();
275+
}
276+
return UM()->classes['um_polylang_admin_mail'];
277+
}
278+
279+
280+
/**
281+
* Fix column width in the "Forms" table.
282+
*/
283+
public function styles() {
284+
$screen = get_current_screen();
285+
if ( ! is_object( $screen ) || 'edit-um_form' === $screen->id ) {
286+
?>
287+
<style type="text/css">
288+
@media screen and (max-width: 1200px) {
289+
.um-admin.post-type-um_form tr > * { padding-left: 5px; padding-right: 5px; }
290+
.um-admin.post-type-um_form .manage-column.column-title { width: 180px; }
291+
.um-admin.post-type-um_form .manage-column.column-id { width: 40px; }
292+
.um-admin.post-type-um_form .manage-column.column-mode { width: 60px; }
293+
.um-admin.post-type-um_form .manage-column.column-is_default { width: 50px; }
294+
.um-admin.post-type-um_form .manage-column.column-shortcode { width: 120px; }
295+
}
296+
</style><?php
297+
}
298+
}
299+
}
300+
301+
}

0 commit comments

Comments
 (0)