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: course author divi module and added new controls for the module #18

Open
wants to merge 2 commits into
base: php-8x
Choose a base branch
from
Open
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
21 changes: 19 additions & 2 deletions includes/modules/CourseAuthor/CourseAuthor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ class CourseAuthor extends Component {
},
]);

// remove default padding below avatar and name
additionalCss.push([
{
selector: `${wrapper} a`,
declaration: `padding: 0`,
},
])

if (avatar_size) {
additionalCss.push([
{
Expand Down Expand Up @@ -189,14 +197,23 @@ class CourseAuthor extends Component {
]);
}

if( props.avatar_border_radius ) {
additionalCss.push([
{
selector: img_selector,
declaration: `border-radius: ${props.avatar_border_radius}`
},
]);
}

return additionalCss;
}

authorAvatar(props) {
//conditionally render
if (props.profile_picture === "on") {
return (
<div className="tutor-single-course-avatar">
<div className="tutor-single-course-avatar tutor-d-flex">
<a
href={this.props.__author.profile_url}
dangerouslySetInnerHTML={{ __html: props.__author.avatar_url }}
Expand Down Expand Up @@ -228,7 +245,7 @@ class CourseAuthor extends Component {
<Fragment>
<div className="tutor-single-course-meta tutor-meta-top">
<ul>
<li className="tutor-single-course-author-meta">
<li className="tutor-single-course-author-meta tutor-align-center">
{this.authorAvatar(this.props)}
{this.authorName(this.props)}
</li>
Expand Down
64 changes: 63 additions & 1 deletion includes/modules/CourseAuthor/CourseAuthor.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function init() {
);

$author_selector = '%%order_class%% .tutor-single-course-author-meta .tutor-single-course-author-name';
$author_avatar = '%%order_class%% .tutor-single-course-author-meta .tutor-single-course-avatar .tutor-avatar';
$this->advanced_fields = array(
'fonts' => array(
'author_label_text' => array(
Expand All @@ -79,6 +80,16 @@ public function init() {
'tab_slug' => 'advanced',
'toggle_slug' => 'author_name_text',
),

'author_image' => array(
'label' => esc_html__( 'Avatar', 'tutor-lms-divi-modules' ),
'css' => array(
'main' => $author_avatar . ' span',
),
'hide_text_align' => true,
'tab_slug' => 'advanced',
'toggle_slug' => 'author_image',
)
),

'box_shadow' => array(
Expand All @@ -92,7 +103,15 @@ public function init() {
// 'margin_padding' => false,
'text' => false,
'borders' => false,
'background' => false,
'background' => array(
'css' => array(
'main' => $author_avatar . ' span',
),
'settings' => array(
'tab_slug' => 'advanced',
'toggle_slug' => 'author_image'
)
),
'filters' => false,
'animation' => false,
'transform' => false,
Expand Down Expand Up @@ -222,6 +241,23 @@ public function get_fields() {
),
'mobile_options' => true,
),
'avatar_border_radius' => array(
'label' => esc_html__( 'Border Radius', 'tutor-lms-divi-modules' ),
'type' => 'range',
'option_category' => 'layout',
'default_unit' => 'px',
'default' => '100px',
'range_settings' => array(
'min' => '1',
'max' => '100',
'step' => '1',
),
'tab_slug' => 'advanced',
'toggle_slug' => 'author_image',
'show_if' => array(
'profile_picture' => 'on',
),
),
// author avatar settings in advanced tab end
);

Expand Down Expand Up @@ -307,6 +343,18 @@ public function render( $attrs, $content, $render_slug ) {
),
)
);

// remove default padding below avatar and name.
ET_Builder_Element::set_style(
$render_slug,
array(
'selector' => $wrapper . ' a',
'declaration' => sprintf(
'padding: 0;'
),
)
);

if ( '' !== $avatar_size ) {
ET_Builder_Element::set_style(
$render_slug,
Expand Down Expand Up @@ -519,6 +567,20 @@ public function render( $attrs, $content, $render_slug ) {
);
}

// set avatar border radius
if ( '' !== $this->props['avatar_border_radius'] ) {
ET_Builder_Element::set_style(
$render_slug,
array(
'selector' => $img_selector,
'declaration' => sprintf(
'border-radius : %1s',
esc_html( $this->props['avatar_border_radius'] )
)
)
);
}

$output = self::get_content( $this->props );

// Render empty string if no output is generated to avoid unwanted vertical space.
Expand Down
15 changes: 11 additions & 4 deletions includes/templates/course/author.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@

<div class="tutor-single-course-meta tutor-meta-top ">
<ul>
<li class="tutor-single-course-author-meta">
<li class="tutor-single-course-author-meta tutor-align-center">
<?php if ( 'on' === $args['profile_picture'] ) : ?>
<div class="tutor-single-course-avatar">
<a href="<?php echo esc_url( $profile_url ); ?>" target="<?php echo $link == 'new' ? esc_html( '_blank' ) : ''; ?>"> <?php echo tutils()->get_tutor_avatar( $post->post_author ); ?></a>
<div class="tutor-single-course-avatar tutor-d-flex">
<a href="<?php echo esc_url( $profile_url ); ?>" target="<?php echo $link == 'new' ? esc_html( '_blank' ) : ''; ?>" class="tutor-p-0">
<?php
echo wp_kses(
tutor_utils()->get_tutor_avatar( get_the_author_meta( 'ID' ) ),
tutor_utils()->allowed_avatar_tags()
);
?>
</a>
</div>
<?php endif; ?>
<?php if ( 'on' === $args['display_name'] ) : ?>
<div class="tutor-single-course-author-name">
<span><?php _e( 'by', 'tutor-lms-divi-modules' ); ?></span>
<span><?php _e( 'By', 'tutor-lms-divi-modules' ); ?></span>
<a href="<?php echo esc_url( $profile_url ); ?>" target="<?php echo $link == 'new' ? esc_html( '_blank' ) : ''; ?>"><?php echo get_the_author_meta( 'display_name', $post->post_author ); ?></a>
</div>
<?php endif; ?>
Expand Down