Last active
August 28, 2023 09:27
-
-
Save N-Molham/ab88aa6ea350fa68d18b184f5bc05cf4 to your computer and use it in GitHub Desktop.
WordPress Developer - How can this code be improved?
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
<?php | |
/** | |
* This code retrieves course data from an external API and displays it in the user's | |
* My Account area. A client has noticed that there's a delay when loading the page. | |
* | |
* 1) What changes would you suggest to reduce or remove that delay? | |
* 2) Is there any other code changes that you would make to improve the code to make it more fexible and maintainable? | |
* | |
* Feel free to | |
*/ | |
public function renderdMyCoursesSection() : void | |
{ | |
if (!$apiUserId = get_user_meta(get_current_user_id(), '_external_api_user_id', true)) { | |
return; | |
} | |
$courses = $this->api()->getCoursesAssignedForUserById($apiUserId); | |
$ssoLink = $this->api()->getSsoLink($apiUserId); | |
?> | |
<h2 style="margin-top: 40px;"><?php _e('My Courses', 'teamyea'); ?></h2> | |
<table> | |
<thead><tr> | |
<th><?php _e('Course Code', 'teamyea'); ?></th> | |
<th><?php _e('Course Title', 'teamyea'); ?></th> | |
<th><?php _e('Completion', 'teamyea'); ?></th> | |
<th><?php _e('Date Completed', 'teamyea'); ?></th> | |
</tr></thead> | |
<tbody> | |
<?php | |
foreach($courses as $course) : | |
?><tr> | |
<td><?php echo __($course['Code']); ?></td> | |
<td><?php echo __($course['Name']); ?></td> | |
<td><?php echo __($course['PercentageComplete']); ?> %</td> | |
<td><?php echo __($course['DateCompleted']); ?></td> | |
</tr> | |
<?php endforeach; | |
?> | |
</tbody> | |
</table> | |
<p><a href="<?php echo $ssoLink ?>" target="_blank" class="button <?php echo $_GET['active_course']; ?>"><?php _e('Course Login', 'teamyea'); ?></a></p> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment