-
Notifications
You must be signed in to change notification settings - Fork 135
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
Fix i18n dashboard language strings and allow customizing of permalink slugs #2593
Merged
Merged
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
13bae57
Working version of fixing the admin menu items, and things like the r…
brianhogg 1cab2bf
Undoing changes that aren't required to fix admin menu and notice lan…
brianhogg 8da8c62
Load localize before loading of block settings
brianhogg 48c5e61
WIP: Starting permalink settings with default loading and saved optio…
brianhogg 7b2c0c2
Unload only the given domain not lifterlms each time
brianhogg 2a0e6bc
Refactor to ensure locale set to the site locale when loading permali…
brianhogg 00914b3
Adding courses archive setting
brianhogg 765ee77
Removing old WP < 5.0 code
brianhogg f68970e
Do not use the translations for the courses (single and archive) url …
brianhogg bba738f
Adding remaining always-show slug translation options
brianhogg 4254dee
Adding membership base
brianhogg 139981b
Removing unneeded whitespace
brianhogg 188d03b
Conditionally show archive page and helpful message if course or memb…
brianhogg dfa67c3
Removing locale switch when loading the permalink structure. By this …
brianhogg ed5c66b
Saving permalink settings
brianhogg f9da343
On update, ensure the slug defaults are set in the site language. The…
brianhogg dfbe58a
Formatting fixes
brianhogg 6708b91
PHPCS Fix. May want to ignore this.
brianhogg a1cebbc
Sanitize nonce
brianhogg db1fa28
Merge branch 'dev' into fix/i18n-dashboard-language-and-slugs
brianhogg acb044f
Test for slug editing and menu language display
brianhogg 7b8f705
Fixing typo when saving lesson base slug
brianhogg f866e69
Adding domain to slug field labels
brianhogg 9d4723e
Add option to specify the textdomain, so add-ons can use the locale s…
brianhogg 3a42a84
Fix comment
brianhogg 34cc161
Styling fix
brianhogg 23b1427
Adding plugin and language dirs to switch/restore locale calls
brianhogg 45cb587
Moving permalink load logic into the class itself
brianhogg 507da92
Merge branch 'dev' into fix/i18n-dashboard-language-and-slugs
brianhogg 6b927cf
Removing E2E tests. Due to tests being inter-dependent and race condi…
brianhogg 8626a74
Merge branch 'dev' into fix/i18n-dashboard-language-and-slugs
brianhogg c35516e
Avoid checking for file existence when loading script translations
brianhogg 2d66d35
Adding changelogs
brianhogg 0c360c1
Adding dev changelog
brianhogg 647716d
Removing test that does not appear to reflect reality of loading the …
brianhogg e023c83
Merge branch 'dev' into fix/i18n-dashboard-language-and-slugs
ideadude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
significance: minor | ||
type: added | ||
links: | ||
- "#2429" | ||
- "#2525" | ||
entry: Loads translation files later for compatibility with plugins like Loco | ||
Translate. |
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,5 @@ | ||
significance: patch | ||
type: fixed | ||
links: | ||
- "#2525" | ||
entry: LifterLMS block editor strings now appear in the user's language. |
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,4 @@ | ||
significance: minor | ||
type: added | ||
entry: Adds settings in the Permalinks page to edit the custom post type and | ||
taxonomy slugs. Slugs are saved in the site language on install on update. |
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,5 @@ | ||
significance: patch | ||
type: added | ||
entry: Adds `llms_switch_to_site_locale` and `llms_restore_locale` to help | ||
LifterLMS add-ons switch to the site language when getting translation | ||
strings. |
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,5 @@ | ||
significance: patch | ||
type: fixed | ||
links: | ||
- "#2324" | ||
entry: Fixed user's language setting not honored on backend. |
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,269 @@ | ||
<?php | ||
/** | ||
* LLMS_Admin_Header class file | ||
* | ||
* @package LifterLMS/Admin/Classes | ||
* | ||
* @since [version] | ||
* @version [version] | ||
*/ | ||
|
||
defined( 'ABSPATH' ) || exit; | ||
|
||
/** | ||
* Permalink settings class | ||
*/ | ||
class LLMS_Admin_Permalinks { | ||
|
||
/** | ||
* Permalink settings. | ||
* | ||
* @var array | ||
*/ | ||
private $permalinks = array(); | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @since [version] | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() { | ||
add_action( 'current_screen', array( $this, 'load_on_permalinks_screen' ) ); | ||
} | ||
|
||
/** | ||
* Ensure we're on the permalinks screen. | ||
* | ||
* @since [version] | ||
* | ||
* @return void | ||
*/ | ||
public function load_on_permalinks_screen() { | ||
$screen = get_current_screen(); | ||
|
||
if ( $screen && 'options-permalink' === $screen->id ) { | ||
$this->settings_init(); | ||
$this->settings_save(); | ||
} | ||
} | ||
|
||
/** | ||
* Show the available permalink settings | ||
*/ | ||
public function settings_init() { | ||
add_settings_section( 'lifterlms-permalink', __( 'LifterLMS Permalinks', 'lifterlms' ), array( $this, 'settings' ), 'permalink' ); | ||
|
||
$this->permalinks = llms_get_permalink_structure(); | ||
} | ||
|
||
public function settings() { | ||
?> | ||
<p><?php _e( 'LifterLMS uses custom post types and taxonomies to organize your courses and memberships. You can customize the URLs for these items here.', 'lifterlms' ); ?></p> | ||
|
||
<?php | ||
$course_catalog_id = llms_get_page_id( 'courses' ); | ||
if ( $course_catalog_id && get_post( $course_catalog_id ) ) { | ||
?> | ||
<p> | ||
<?php echo esc_html__( 'Note: The Courses Catalog is currently set to a static page.', 'lifterlms' ); ?> | ||
<a href="<?php echo esc_url( get_edit_post_link( $course_catalog_id ) ); ?>"> | ||
<?php echo esc_html__( 'You can edit the page slug to change its location.', 'lifterlms' ); ?> | ||
</a> | ||
</p> | ||
<?php | ||
} | ||
|
||
$memberships_catalog_id = llms_get_page_id( 'memberships' ); | ||
if ( $memberships_catalog_id && get_post( $memberships_catalog_id ) ) { | ||
?> | ||
<p> | ||
<?php echo esc_html__( 'Note: The Memberships Catalog is currently set to a static page.', 'lifterlms' ); ?> | ||
<a href="<?php echo esc_url( get_edit_post_link( $memberships_catalog_id ) ); ?>"> | ||
<?php echo esc_html__( 'You can edit the page slug to change its location.', 'lifterlms' ); ?> | ||
</a> | ||
</p> | ||
<?php | ||
} | ||
?> | ||
|
||
<table class="form-table" role="presentation"> | ||
<tbody> | ||
<tr> | ||
<th> | ||
<label for="course_base"> | ||
<?php esc_html_e( 'Course Post Type', 'lifterlms' ); ?> | ||
</label> | ||
</th> | ||
<td> | ||
<input name="llms_course_base" id="course_base" type="text" value="<?php echo esc_attr( $this->permalinks['course_base'] ); ?>" class="regular-text code" required> | ||
</td> | ||
</tr> | ||
<?php if ( ! $course_catalog_id || ! get_post( $course_catalog_id ) ) : ?> | ||
<tr> | ||
<th> | ||
<label for="courses_base"> | ||
<?php esc_html_e( 'Course Archive base', 'lifterlms' ); ?> | ||
</label> | ||
</th> | ||
<td> | ||
<input name="llms_courses_base" id="courses_base" type="text" value="<?php echo esc_attr( $this->permalinks['courses_base'] ); ?>" class="regular-text code" required> | ||
</td> | ||
</tr> | ||
<?php endif; ?> | ||
<?php if ( ! $memberships_catalog_id || ! get_post( $memberships_catalog_id ) ) : ?> | ||
<tr> | ||
<th> | ||
<label for="memberships_base"> | ||
<?php esc_html_e( 'Memberships Archive base', 'lifterlms' ); ?> | ||
</label> | ||
</th> | ||
<td> | ||
<input name="llms_memberships_base" id="memberships_base" type="text" value="<?php echo esc_attr( $this->permalinks['memberships_base'] ); ?>" class="regular-text code" required> | ||
</td> | ||
</tr> | ||
<?php endif; ?> | ||
<tr> | ||
<th> | ||
<label for="lesson_base"> | ||
<?php esc_html_e( 'Lesson Post Type', 'lifterlms' ); ?> | ||
</label> | ||
</th> | ||
<td> | ||
<input name="llms_lesson_base" id="lesson_base" type="text" value="<?php echo esc_attr( $this->permalinks['lesson_base'] ); ?>" class="regular-text code" required> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th> | ||
<label for="quiz_base"> | ||
<?php esc_html_e( 'Quiz Post Type', 'lifterlms' ); ?> | ||
</label> | ||
</th> | ||
<td> | ||
<input name="llms_quiz_base" id="quiz_base" type="text" value="<?php echo esc_attr( $this->permalinks['quiz_base'] ); ?>" class="regular-text code" required> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th> | ||
<label for="certificate_template_base"> | ||
<?php esc_html_e( 'Certificate Template Post Type', 'lifterlms' ); ?> | ||
</label> | ||
</th> | ||
<td> | ||
<input name="llms_certificate_template_base" id="certificate_template_base" type="text" value="<?php echo esc_attr( $this->permalinks['certificate_template_base'] ); ?>" class="regular-text code" required> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th> | ||
<label for="certificate_base"> | ||
<?php esc_html_e( 'Earned Certificate Post Type', 'lifterlms' ); ?> | ||
</label> | ||
</th> | ||
<td> | ||
<input name="llms_certificate_base" id="certificate_base" type="text" value="<?php echo esc_attr( $this->permalinks['certificate_base'] ); ?>" class="regular-text code" required> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th> | ||
<label for="course_category_base"> | ||
<?php esc_html_e( 'Course Category base', 'lifterlms' ); ?> | ||
</label> | ||
</th> | ||
<td> | ||
<input name="llms_course_category_base" id="course_category_base" type="text" value="<?php echo esc_attr( $this->permalinks['course_category_base'] ); ?>" class="regular-text code" required> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th> | ||
<label for="course_tag_base"> | ||
<?php esc_html_e( 'Course Tag base', 'lifterlms' ); ?> | ||
</label> | ||
</th> | ||
<td> | ||
<input name="llms_course_tag_base" id="course_tag_base" type="text" value="<?php echo esc_attr( $this->permalinks['course_tag_base'] ); ?>" class="regular-text code" required> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th> | ||
<label for="course_track_base"> | ||
<?php esc_html_e( 'Course Track base', 'lifterlms' ); ?> | ||
</label> | ||
</th> | ||
<td> | ||
<input name="llms_course_track_base" id="course_track_base" type="text" value="<?php echo esc_attr( $this->permalinks['course_track_base'] ); ?>" class="regular-text code" required> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th> | ||
<label for="course_difficulty_base"> | ||
<?php esc_html_e( 'Course Difficulty base', 'lifterlms' ); ?> | ||
</label> | ||
</th> | ||
<td> | ||
<input name="llms_course_difficulty_base" id="course_difficulty_base" type="text" value="<?php echo esc_attr( $this->permalinks['course_difficulty_base'] ); ?>" class="regular-text code" required> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th> | ||
<label for="membership_category_base"> | ||
<?php esc_html_e( 'Membership Category base', 'lifterlms' ); ?> | ||
</label> | ||
</th> | ||
<td> | ||
<input name="llms_membership_category_base" id="membership_category_base" type="text" value="<?php echo esc_attr( $this->permalinks['membership_category_base'] ); ?>" class="regular-text code" required> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th> | ||
<label for="membership_tag_base"> | ||
<?php esc_html_e( 'Membership Tag base', 'lifterlms' ); ?> | ||
</label> | ||
</th> | ||
<td> | ||
<input name="llms_membership_tag_base" id="membership_tag_base" type="text" value="<?php echo esc_attr( $this->permalinks['membership_tag_base'] ); ?>" class="regular-text code" required> | ||
</td> | ||
</tr> | ||
<?php do_action( 'llms_permalink_setting_fields' ); ?> | ||
</tbody> | ||
</table> | ||
|
||
<?php wp_nonce_field( 'llms-permalinks', 'llms-permalinks-nonce' ); ?> | ||
<?php | ||
} | ||
|
||
/** | ||
* Save the permalink settings | ||
*/ | ||
public function settings_save() { | ||
if ( ! is_admin() ) { | ||
return; | ||
} | ||
|
||
if ( isset( $_POST['llms-permalinks-nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['llms-permalinks-nonce'] ), 'llms-permalinks' ) ) { | ||
llms_switch_to_site_locale(); | ||
|
||
$permalinks = llms_get_permalink_structure(); | ||
|
||
$permalinks['course_base'] = isset( $_POST['llms_course_base'] ) ? sanitize_text_field( wp_unslash( $_POST['llms_course_base'] ) ) : $permalinks['course_base']; | ||
$permalinks['courses_base'] = isset( $_POST['llms_courses_base'] ) ? sanitize_text_field( wp_unslash( $_POST['llms_courses_base'] ) ) : $permalinks['courses_base']; | ||
$permalinks['memberships_base'] = isset( $_POST['llms_memberships_base'] ) ? sanitize_text_field( wp_unslash( $_POST['llms_memberships_base'] ) ) : $permalinks['memberships_base']; | ||
$permalinks['lesson_base'] = isset( $_POST['llms_lesson_base'] ) ? sanitize_text_field( wp_unslash( $_POST['llms_lesson_base'] ) ) : $permalinks['lesson_base']; | ||
$permalinks['quiz_base'] = isset( $_POST['llms_quiz_base'] ) ? sanitize_text_field( wp_unslash( $_POST['llms_quiz_base'] ) ) : $permalinks['quiz_base']; | ||
$permalinks['certificate_template_base'] = isset( $_POST['llms_certificate_template_base'] ) ? sanitize_text_field( wp_unslash( $_POST['llms_certificate_template_base'] ) ) : $permalinks['certificate_template_base']; | ||
$permalinks['certificate_base'] = isset( $_POST['llms_certificate_base'] ) ? sanitize_text_field( wp_unslash( $_POST['llms_certificate_base'] ) ) : $permalinks['certificate_base']; | ||
$permalinks['course_category_base'] = isset( $_POST['llms_course_category_base'] ) ? sanitize_text_field( wp_unslash( $_POST['llms_course_category_base'] ) ) : $permalinks['course_category_base']; | ||
$permalinks['course_tag_base'] = isset( $_POST['llms_course_tag_base'] ) ? sanitize_text_field( wp_unslash( $_POST['llms_course_tag_base'] ) ) : $permalinks['course_tag_base']; | ||
$permalinks['course_track_base'] = isset( $_POST['llms_course_track_base'] ) ? sanitize_text_field( wp_unslash( $_POST['llms_course_track_base'] ) ) : $permalinks['course_track_base']; | ||
$permalinks['course_difficulty_base'] = isset( $_POST['llms_course_difficulty_base'] ) ? sanitize_text_field( wp_unslash( $_POST['llms_course_difficulty_base'] ) ) : $permalinks['course_difficulty_base']; | ||
$permalinks['membership_category_base'] = isset( $_POST['llms_membership_category_base'] ) ? sanitize_text_field( wp_unslash( $_POST['llms_membership_category_base'] ) ) : $permalinks['membership_category_base']; | ||
$permalinks['membership_tag_base'] = isset( $_POST['llms_membership_tag_base'] ) ? sanitize_text_field( wp_unslash( $_POST['llms_membership_tag_base'] ) ) : $permalinks['membership_tag_base']; | ||
|
||
llms_set_permalink_structure( $permalinks ); | ||
|
||
llms_restore_locale(); | ||
} | ||
} | ||
} | ||
|
||
return new LLMS_Admin_Permalinks(); |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
register_activation_hook
needs the main plugin filename. Since the class filename is being used here, this would never run. It's been moved into the main plugin file instead so theverify_permalinks
runs on activation.