Skip to content

Commit

Permalink
Merge pull request #7701 from Automattic/fix/early-translations
Browse files Browse the repository at this point in the history
Prevent early translation loading
  • Loading branch information
m1r0 authored Nov 6, 2024
2 parents c3dd120 + 7cc134a commit 985136d
Show file tree
Hide file tree
Showing 14 changed files with 318 additions and 280 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-early-translations
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fix loading some translations too early which generates a warning on WP 6.7
38 changes: 4 additions & 34 deletions config/psalm/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1789,9 +1789,8 @@
<code>$user_id</code>
<code>$which</code>
</MissingParamType>
<MissingPropertyType occurrences="3">
<MissingPropertyType occurrences="2">
<code>$file</code>
<code>$name</code>
<code>$page_slug</code>
</MissingPropertyType>
<PossiblyFalseArgument occurrences="1">
Expand Down Expand Up @@ -2422,18 +2421,6 @@
<code>get_queried_object()-&gt;ID</code>
<code>get_queried_object()-&gt;post_type</code>
</PossiblyNullPropertyFetch>
<PropertyNotSetInConstructor occurrences="10">
<code>$course</code>
<code>$lesson</code>
<code>$messages</code>
<code>$question</code>
<code>$quiz</code>
<code>WooThemes_Sensei_PostTypes</code>
<code>WooThemes_Sensei_PostTypes</code>
<code>WooThemes_Sensei_PostTypes</code>
<code>WooThemes_Sensei_PostTypes</code>
<code>WooThemes_Sensei_PostTypes</code>
</PropertyNotSetInConstructor>
<RedundantConditionGivenDocblockType occurrences="1">
<code>$post instanceof WP_Post</code>
</RedundantConditionGivenDocblockType>
Expand Down Expand Up @@ -4181,11 +4168,9 @@
<InvalidGlobal occurrences="1">
<code>global $sensei_email_data;</code>
</InvalidGlobal>
<MissingPropertyType occurrences="6">
<code>$heading</code>
<MissingPropertyType occurrences="4">
<code>$learner</code>
<code>$recipient</code>
<code>$subject</code>
<code>$teacher</code>
<code>$template</code>
</MissingPropertyType>
Expand Down Expand Up @@ -4432,8 +4417,7 @@
<code>$post</code>
<code>$post</code>
</ParamNameMismatch>
<PossiblyNullArgument occurrences="2">
<code>get_edit_post_link( $post )</code>
<PossiblyNullArgument occurrences="1">
<code>get_edit_post_link( $post-&gt;ID )</code>
</PossiblyNullArgument>
<PropertyNotSetInConstructor occurrences="4">
Expand Down Expand Up @@ -4970,13 +4954,6 @@
</TypeDoesNotContainType>
</file>
<file src="includes/rest-api/class-sensei-rest-api-course-progress-controller.php">
<InvalidClass occurrences="1">
<code>WP_HTTP</code>
</InvalidClass>
<PossiblyInvalidArrayAssignment occurrences="2">
<code>$result[ $student_id ][ $course_id ]</code>
<code>$result[ $student_id ][ $course_id ]</code>
</PossiblyInvalidArrayAssignment>
<PossiblyNullArgument occurrences="1">
<code>$edit_course_cap</code>
</PossiblyNullArgument>
Expand Down Expand Up @@ -5013,8 +4990,7 @@
<code>WP_HTTP</code>
<code>WP_HTTP</code>
</InvalidClass>
<PossiblyInvalidArrayAssignment occurrences="2">
<code>$result[ $user_id ][ $course_id ]</code>
<PossiblyInvalidArrayAssignment occurrences="1">
<code>$result[ $user_id ][ $course_id ]</code>
</PossiblyInvalidArrayAssignment>
<PossiblyNullArgument occurrences="1">
Expand Down Expand Up @@ -5249,12 +5225,6 @@
</UndefinedPropertyFetch>
</file>
<file src="includes/rest-api/class-sensei-rest-api-question-helpers-trait.php">
<ArgumentTypeCoercion occurrences="1">
<code>$post_args</code>
</ArgumentTypeCoercion>
<InvalidArgument occurrences="1">
<code>$post_args</code>
</InvalidArgument>
<PossibleRawObjectIteration occurrences="1">
<code>$question_categories</code>
</PossibleRawObjectIteration>
Expand Down
36 changes: 22 additions & 14 deletions includes/admin/class-sensei-learner-management.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,27 @@
* @since 1.3.0
*/
class Sensei_Learner_Management {
/**
* Name of the menu/page.
*
* @var string $name
*/
public $name;
/**
* Main plugin file name.
*
* @var string $file
*/
public $file;

/**
* Menu slug name.
*
* @var string $page_slug
*/
public $page_slug;

/**
* Reference to the class responsible for Bulk Learner Actions.
*
* @var Sensei_Learners_Admin_Bulk_Actions_Controller $bulk_actions_controller
*/
public $bulk_actions_controller;

/**
* Per page screen option ID.
*
Expand All @@ -63,7 +60,6 @@ class Sensei_Learner_Management {
* @param string $file Main plugin file name.
*/
public function __construct( $file ) {
$this->name = __( 'Students', 'sensei-lms' );
$this->file = $file;
$this->page_slug = 'sensei_learners';

Expand Down Expand Up @@ -99,6 +95,22 @@ public function __construct( $file ) {
}
}

/**
* Graceful fallback for deprecated properties.
*
* @since $$next-version$$
*
* @param string $key The key to get.
*
* @return mixed
*/
public function __get( $key ) {
if ( 'name' === $key ) {
_doing_it_wrong( __CLASS__ . '->name', 'The "name" property is deprecated. Use get_name() instead.', '$$next-version$$' );

return $this->get_name();
}
}

/**
* Add custom navigation to the admin pages.
Expand Down Expand Up @@ -148,8 +160,8 @@ public function learners_admin_menu() {
if ( current_user_can( 'manage_sensei_grades' ) ) {
$learners_page = add_submenu_page(
'sensei',
$this->name,
$this->name,
$this->get_name(),
$this->get_name(),
'manage_sensei_grades',
$this->page_slug,
array( $this, 'learners_page' )
Expand Down Expand Up @@ -274,7 +286,6 @@ public function load_data_table_files() {
foreach ( $classes_to_load as $class_file ) {
Sensei()->load_class( $class_file );
}

}

/**
Expand Down Expand Up @@ -320,7 +331,6 @@ public function learners_page() {
} else {
require __DIR__ . '/views/html-admin-page-students-main.php';
}

}

/**
Expand All @@ -340,7 +350,6 @@ public function learners_headers( $args = array( 'nav' => 'default' ) ) {
* @hook sensei_learners_after_headers
*/
do_action( 'sensei_learners_after_headers' );

}

/**
Expand Down Expand Up @@ -972,9 +981,8 @@ public function get_url() {
* @return string Name of the menu/page.
*/
public function get_name() {
return $this->name;
return __( 'Students', 'sensei-lms' );
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ class Sensei_Learners_Admin_Bulk_Actions_Controller {
const REMOVE_ENROLMENT = 'remove_enrolment';
const REMOVE_PROGRESS = 'remove_progress';

/**
* The available bulk actions.
*
* @var array|null
*/
private $known_bulk_actions;

/**
* The page slug.
*
Expand Down Expand Up @@ -55,20 +48,13 @@ class Sensei_Learners_Admin_Bulk_Actions_Controller {
*/
private $learner;

/**
* The name of the page
*
* @var string
*/
private $name;

/**
* Get the name of the page.
*
* @return string|void
*/
public function get_name() {
return $this->name;
return __( 'Bulk Student Actions', 'sensei-lms' );
}

/**
Expand Down Expand Up @@ -117,16 +103,9 @@ public function learners_admin_menu() {
public function __construct( $management, $learner ) {
$this->learner_management = $management;
$this->learner = $learner;
$this->name = __( 'Bulk Student Actions', 'sensei-lms' );
$this->page_slug = $management->page_slug;
$this->view = 'sensei_learner_admin';

$this->known_bulk_actions = [
self::ENROL_RESTORE_ENROLMENT => __( 'Add to Course', 'sensei-lms' ),
self::REMOVE_ENROLMENT => __( 'Remove from Course', 'sensei-lms' ),
self::REMOVE_PROGRESS => __( 'Reset Progress', 'sensei-lms' ),
];

if ( is_admin() ) {
$this->register_hooks();
}
Expand Down Expand Up @@ -190,7 +169,11 @@ public function get_learner_management_course_url( $course_id ) {
* @return array
*/
public function get_known_bulk_actions() {
$known_bulk_actions = $this->known_bulk_actions;
$known_bulk_actions = [
self::ENROL_RESTORE_ENROLMENT => __( 'Add to Course', 'sensei-lms' ),
self::REMOVE_ENROLMENT => __( 'Remove from Course', 'sensei-lms' ),
self::REMOVE_PROGRESS => __( 'Reset Progress', 'sensei-lms' ),
];

/**
* Filter the known bulk actions.
Expand Down
Loading

0 comments on commit 985136d

Please sign in to comment.