Skip to content

Commit

Permalink
= 4.2.6.4 =
Browse files Browse the repository at this point in the history
~ Tweak: get role.
~ Recipients email.
  • Loading branch information
tungnxt89 committed Mar 21, 2024
1 parent 85785b4 commit 4e7af12
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
4 changes: 2 additions & 2 deletions inc/curds/class-lp-user-curd.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ public function load( &$user ) {
'display_name' => $user_object->display_name,
'date_created' => $user_object->user_registered,
'date_modified' => get_user_meta( $user_id, 'last_update', true ),
'role' => ! empty( $user_object->roles[0] ) ? $user_object->roles[0] : 'student',
'roles' => ! empty( $user_object->roles ) ? $user_object->roles : array( 'student' ),
'role' => array_shift( $user_object->roles),
'roles' => $user_object->roles,
'profile_picture' => get_user_meta( $user_id, '_lp_profile_picture', true ),
'profile_privacy' => get_user_meta( $user_id, '_lp_profile_privacy', true ),
)
Expand Down
47 changes: 33 additions & 14 deletions inc/emails/class-lp-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,10 @@ public function __construct() {
/**
* Init general options
*/
$this->heading = $this->settings->get( 'heading', $this->default_heading );
$this->subject = $this->settings->get( 'subject', $this->default_subject );
$this->enable = $this->settings->get( 'enable', 'no' ) === 'yes';
$this->heading = $this->settings->get( 'heading', $this->default_heading );
$this->subject = $this->settings->get( 'subject', $this->default_subject );
$this->enable = $this->settings->get( 'enable', 'no' ) === 'yes';
$this->recipients = $this->settings->get( 'recipients', '' );

if ( $this->settings->get( 'email_content.format' ) ) {
$this->email_format = ( $this->settings->get( 'email_content.format' ) == 'plain_text' ) ? 'plain' : 'html';
Expand Down Expand Up @@ -594,7 +595,18 @@ public function get_content_text_message(): string {
* @return string|array
*/
public function get_headers() {
return apply_filters( 'learn-press/email-headers', 'Content-Type: ' . $this->get_content_format() . "\r\n", $this->id, $this->object );
$headers = [
'Content-Type: ' . $this->get_content_format() . "\r\n",
];

if ( ! empty( $this->recipients ) ) {
$cc_emails = explode( ',', $this->recipients );
foreach ( $cc_emails as $cc_email ) {
$headers[] = 'Cc: ' . $cc_email;
}
}

return apply_filters( 'learn-press/email-headers', $headers, $this );
}

/**
Expand Down Expand Up @@ -675,7 +687,10 @@ public function get_email_format() {
* @return string
*/
public function apply_style_inline( $content ) {
if ( in_array( $this->get_content_format(), array( 'text/html', 'multipart/alternative' ) ) && class_exists( 'DOMDocument' ) ) {
if ( in_array( $this->get_content_format(), array(
'text/html',
'multipart/alternative'
) ) && class_exists( 'DOMDocument' ) ) {

// get CSS styles
ob_start();
Expand Down Expand Up @@ -749,12 +764,12 @@ public function get_theme_template_file( $template, $template_path = null ) {
* @param string $subject
* @param string $message
* @param string|string[] $headers
* @param array $attachments
* @param array $attachments
*
* @editor tungnx
* @return bool
* @version 1.0.1
*
* @return bool
*/
public function send( $to, string $subject, string $message, $headers, array $attachments ): bool {
$return = false;
Expand Down Expand Up @@ -791,6 +806,7 @@ public function send_email(): bool {
* Variables use for click add to content of Email
*
* @param string $format
*
* @return array
* @author tungnx
* @since 4.1.1
Expand All @@ -808,6 +824,7 @@ public function get_common_variables( string $format = 'plain' ): array {
}

$admin_user = get_user_by( 'email', get_option( 'admin_email' ) );

return apply_filters(
'email_variables_common',
[
Expand Down Expand Up @@ -864,7 +881,7 @@ protected function _default_settings(): array {
array(
'title' => esc_html__( 'Recipient(s)', 'learnpress' ),
'type' => 'text',
'default' => get_option( 'admin_email' ),
'default' => $this->recipients,
'id' => $this->get_field_name( 'recipients' ),
'desc' => esc_html__( 'Separate other recipients with commas.', 'learnpress' ),
),
Expand Down Expand Up @@ -909,9 +926,9 @@ protected function _default_settings(): array {
/**
* Get settings in admin.
*
* @return bool|mixed
* @since 3.0.0
*
* @return bool|mixed
*/
public function get_settings() {
return apply_filters( 'learn-press/email-settings/' . $this->id . '/settings', $this->_default_settings() );
Expand All @@ -920,11 +937,11 @@ public function get_settings() {
/**
* Get instructors to send mail.
*
* @since 3.0.0
*
* @param null $order_id
*
* @return array
* @since 3.0.0
*
*/
public function get_order_instructors( $order_id ) {
if ( ! $order_id ) {
Expand Down Expand Up @@ -982,7 +999,7 @@ public function get_image_header(): string {
* Email header.
*
* @param string $heading
* @param bool $echo
* @param bool $echo
*
* @return string
*/
Expand All @@ -1008,7 +1025,7 @@ public function email_header( string $heading, bool $echo = true ): string {
* Email footer.
*
* @param string $footer_text
* @param bool $echo
* @param bool $echo
*
* @return string
*/
Expand All @@ -1035,9 +1052,11 @@ public function set_receive( string $receive_email ) {

/**
* Method called by background on LP_Background_Single_Email
* @see LP_Background_Single_Email::handle()
*
* @param array $params
*
* @see LP_Background_Single_Email::handle()
*
*/
public function handle( array $params ) {

Expand Down
9 changes: 8 additions & 1 deletion inc/user/abstract-lp-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -1402,8 +1402,15 @@ public function is_completed_all_items( $course_id ) {
return $course_results['completed_items'] >= $course->count_items();
}

/**
* Get role of user.
*
* @return string
* @since 3.0.0
* @version 1.0.1
*/
public function get_role() {
return $this->is_admin() ? 'admin' : ( $this->is_instructor() ? 'instructor' : 'user' );
return $this->get_data( 'role' );
}

/**
Expand Down

0 comments on commit 4e7af12

Please sign in to comment.