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

Fix i18n loading error #2808

Merged
merged 6 commits into from
Nov 18, 2024
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
5 changes: 5 additions & 0 deletions .changelogs/fix_i18n-loading-error.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
significance: patch
type: fixed
links:
- "#2807"
entry: Fix translations not loading for LifterLMS in WordPress 6.7.
15 changes: 5 additions & 10 deletions includes/integrations/class.llms.integration.bbpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ class LLMS_Integration_BBPress extends LLMS_Abstract_Integration {
*/
protected function configure() {

$this->title = __( 'bbPress', 'lifterlms' );
$this->description = sprintf( __( 'Restrict forums and topics to memberships, add forums to courses, and %1$smore%2$s.', 'lifterlms' ), '<a href="https://lifterlms.com/docs/lifterlms-and-bbpress/" target="_blank">', '</a>' );
add_action( 'init', array( $this, 'set_title_and_description' ) );

if ( $this->is_available() ) {

Expand Down Expand Up @@ -78,7 +77,11 @@ protected function configure() {
add_action( 'llms_content_restricted_by_bbp_course_forum', array( $this, 'handle_course_forum_restriction' ), 10, 1 );

}
}

public function set_title_and_description() {
$this->title = __( 'bbPress', 'lifterlms' );
$this->description = sprintf( __( 'Restrict forums and topics to memberships, add forums to courses, and %1$smore%2$s.', 'lifterlms' ), '<a href="https://lifterlms.com/docs/lifterlms-and-bbpress/" target="_blank">', '</a>' );
}

/**
Expand Down Expand Up @@ -176,7 +179,6 @@ public function engagement_query_args( $query_args, $action, $orig_args ) {
}

return $query_args;

}

/**
Expand Down Expand Up @@ -205,7 +207,6 @@ public function handle_course_forum_restriction( $restriction ) {

llms_add_notice( $msg, 'error' );
llms_redirect_and_exit( get_permalink( $restriction['restriction_id'] ) );

}

/**
Expand Down Expand Up @@ -237,7 +238,6 @@ public function get_course_forum_ids( $course ) {
* @param LLMS_Course $course LifterLMS course object.
*/
return apply_filters( 'llms_bbp_get_course_forum_ids', $ids, $course );

}

/**
Expand Down Expand Up @@ -268,7 +268,6 @@ public function get_forum_course_restrictions( $forum_id ) {
$query = array_map( 'absint', $query );

return $query;

}

/**
Expand Down Expand Up @@ -347,7 +346,6 @@ public function restriction_checks_courses( $results ) {
}

return $results;

}

/**
Expand Down Expand Up @@ -389,7 +387,6 @@ public function restriction_checks_memberships( $results ) {
}

return $results;

}

/**
Expand Down Expand Up @@ -435,7 +432,5 @@ public function save_course_settings( $post_id ) {
update_post_meta( $post_id, '_llms_bbp_forum_ids', $ids );

return $ids;

}

}
21 changes: 6 additions & 15 deletions includes/integrations/class.llms.integration.buddypress.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ class LLMS_Integration_Buddypress extends LLMS_Abstract_Integration {
*/
protected function configure() {

$this->title = __( 'BuddyPress', 'lifterlms' );
$this->description = sprintf( __( 'Add LifterLMS information to user profiles and enable membership restrictions for activity, group, and member directories. %1$sLearn More%2$s.', 'lifterlms' ), '<a href="https://lifterlms.com/docs/lifterlms-and-buddypress/" target="_blank">', '</a>' );
add_action( 'init', array( $this, 'set_title_and_description' ) );

if ( $this->is_available() ) {

Expand All @@ -78,7 +77,11 @@ protected function configure() {
add_filter( 'llms_groups_maybe_hide_dashboard_tab', array( $this, 'return_true_on_bp_my_profile' ) );

}
}

public function set_title_and_description() {
$this->title = __( 'BuddyPress', 'lifterlms' );
$this->description = sprintf( __( 'Add LifterLMS information to user profiles and enable membership restrictions for activity, group, and member directories. %1$sLearn More%2$s.', 'lifterlms' ), '<a href="https://lifterlms.com/docs/lifterlms-and-buddypress/" target="_blank">', '</a>' );
}

/**
Expand Down Expand Up @@ -109,7 +112,6 @@ public function get_integration_settings() {
}

return $settings;

}

/**
Expand Down Expand Up @@ -177,14 +179,13 @@ public function add_profile_nav_items() {
'slug' => $profile_endpoint['endpoint'],
'parent_slug' => $main_nav_slug,
'parent_url' => $parent_url,
'screen_function' => function() use ( $ep_key, $profile_endpoint ) {
'screen_function' => function () use ( $ep_key, $profile_endpoint ) {
$this->endpoint_content( $ep_key, $profile_endpoint['content'] );
},
'user_has_access' => $bp_is_my_profile,
)
);
}

}

/**
Expand Down Expand Up @@ -270,7 +271,6 @@ public function courses_screen() {
add_action( 'bp_template_content', array( $this, 'remove_courses_paginate_links_filter' ), 15 );

bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );

}

/**
Expand Down Expand Up @@ -303,7 +303,6 @@ public function endpoint_content( $ep_key, $ep_template_cb ) {

// This triggers 'bp_template_content' action hook.
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );

}

/**
Expand Down Expand Up @@ -334,7 +333,6 @@ public function enqueue_assets() {
"window.llms.address_info = '" . wp_json_encode( llms_get_countries_address_info() ) . "';"
);
}

}

/**
Expand Down Expand Up @@ -378,7 +376,6 @@ public function modify_courses_paginate_links( $link ) {

$this->current_endpoint_key;
return $this->modify_paginate_links( $link );

}

/**
Expand Down Expand Up @@ -476,7 +473,6 @@ public function modify_paginate_links( $link ) {
}

return $query ? $link . '?' . $query : $link;

}

/**
Expand Down Expand Up @@ -554,7 +550,6 @@ public function restriction_checks( $results ) {
}

return $results;

}

/**
Expand All @@ -574,7 +569,6 @@ private function get_profile_endpoints_options() {
array_keys( $endpoints ),
array_column( $endpoints, 'title' )
);

}

/**
Expand Down Expand Up @@ -606,7 +600,6 @@ private function populate_profile_endpoints() {
* @param array $endpoints Array of endpoint data.
*/
$this->endpoints = apply_filters( 'llms_buddypress_profile_endpoints', $endpoints );

}

/**
Expand Down Expand Up @@ -650,7 +643,5 @@ function ( $endpoint ) {
}

return $endpoints;

}

}
12 changes: 4 additions & 8 deletions includes/privacy/class-llms-privacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public function __construct() {

// Anonymize erased order properties.
add_filter( 'llms_privacy_get_anon_prop_value', array( 'LLMS_Privacy_Erasers', 'anonymize_prop' ), 10, 3 );

}

/**
Expand Down Expand Up @@ -123,7 +122,6 @@ protected static function get_order_data_props( $type ) {
);

return apply_filters( 'llms_privacy_order_data_props', $props, $type );

}

/**
Expand Down Expand Up @@ -185,7 +183,6 @@ public function get_privacy_message() {
* @param string $content Privacy policy content as an html string.
*/
return apply_filters( 'llms_privacy_policy_content', $content );

}

/**
Expand Down Expand Up @@ -243,7 +240,6 @@ protected static function get_student_data_props() {
'last_login' => __( 'Last Login Date', 'lifterlms' ),
)
);

}

/**
Expand Down Expand Up @@ -272,7 +268,6 @@ protected static function get_student_enrollments( $student, $page, $post_type )
'done' => ( ! $enrollments['more'] ),
'results' => $enrollments['results'],
);

}

/**
Expand Down Expand Up @@ -304,7 +299,6 @@ protected static function get_student_orders( $student, $page ) {
'done' => $done,
'orders' => $results,
);

}

/**
Expand All @@ -327,7 +321,9 @@ protected static function get_student_quizzes( $student, $page ) {
)
);
}

}

return new LLMS_Privacy();
function llms_load_privacy() {
return new LLMS_Privacy();
}
add_action( 'init', 'llms_load_privacy' );
37 changes: 0 additions & 37 deletions tests/phpunit/unit-tests/class-llms-test-main-class.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,41 +133,4 @@ public function test_init_session() {

}

/**
* Test plugin localization
*
* @since 3.21.1
* @since 4.9.0 Improve tests.
*
* @return void
*/
public function test_localize() {

$dirs = array(
WP_LANG_DIR . '/lifterlms', // "Safe" directory.
WP_LANG_DIR . '/plugins', // Default language directory.
WP_PLUGIN_DIR . '/lifterlms/languages', // Plugin language directory.
);

foreach ( $dirs as $dir ) {

// Make sure the initial strings work.
$this->assertEquals( 'LifterLMS', __( 'LifterLMS', 'lifterlms' ), $dir );
$this->assertEquals( 'Course', __( 'Course', 'lifterlms' ), $dir );

// Load a language file.
$file = LLMS_Unit_Test_Files::copy_asset( 'lifterlms-en_US.mo', $dir );
$this->llms->localize();

$this->assertEquals( 'BetterLMS', __( 'LifterLMS', 'lifterlms' ), $dir );
$this->assertEquals( 'Module', __( 'Module', 'lifterlms' ), $dir );

// Clean up.
LLMS_Unit_Test_Files::remove( $file );
unload_textdomain( 'lifterlms' );

}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,4 @@ class LLMS_Test_Functions_L10n extends LLMS_UnitTestCase {
public function test_llms_get_locale() {
$this->assertEquals( 'en_US', llms_get_locale() );
}

/**
* Test llms_load_textdomain() as it would be used by a 3rd party.
*
* @since 4.9.0
*
* @see LLMS_Test_Main_Class::test_localize() for coverage with default args against the LifterLMS core plugin.
*
* @return void
*/
public function test_llms_load_textdomain() {

$dirs = array(
WP_LANG_DIR . '/lifterlms', // "Safe" directory.
WP_LANG_DIR . '/plugins', // Default language directory.
WP_PLUGIN_DIR . '/lifterlms-test/i18n', // Plugin language directory.
);

foreach ( $dirs as $dir ) {

// Make sure the initial strings work.
$this->assertEquals( 'LifterLMS', __( 'LifterLMS', 'lifterlms-test' ), $dir );
$this->assertEquals( 'Course', __( 'Course', 'lifterlms-test' ), $dir );

// Load a language file.
$file = LLMS_Unit_Test_Files::copy_asset( 'lifterlms-en_US.mo', $dir, 'lifterlms-test-en_US.mo' );
llms_load_textdomain( 'lifterlms-test', WP_PLUGIN_DIR . '/lifterlms-test', 'i18n' );

$this->assertEquals( 'BetterLMS', __( 'LifterLMS', 'lifterlms-test' ), $dir );
$this->assertEquals( 'Module', __( 'Course', 'lifterlms-test' ), $dir );

// Clean up.
LLMS_Unit_Test_Files::remove( $file );
unload_textdomain( 'lifterlms-test' );

}

}

}
Loading