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

Fixes the Course Builder new lesson View link #2663

Merged
merged 6 commits into from
May 28, 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_course-builder-new-lesson-view-link.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
significance: patch
type: fixed
links:
- "#2662"
entry: Fixes broken View link after creating a new lesson using the Course Builder.
2 changes: 2 additions & 0 deletions assets/js/builder/Models/Section.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ define( [ 'Collections/Lessons', 'Models/_Relationships' ], function( Lessons, R
options = options || {};

if ( data instanceof Backbone.Model ) {
data.set( 'status', 'publish' );
data.set( 'parent_section', this.get( 'id' ) );
data.set_parent( this );
} else {
data.status = 'publish';
data.parent_section = this.get( 'id' );
}

Expand Down
17 changes: 17 additions & 0 deletions assets/js/builder/Models/_Utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@ define( [], function() {

},

get_view_post_link: function() {
if ( this.has_temp_id() ) {
return '';
}

if ( this.get( 'permalink' ) ) {
return this.get( 'permalink' );
}

if ( this.get( 'status' ) === 'publish' ) {
return window.llms_builder.home_url + '?p=' + this.get( 'id' );
}

return window.llms_builder.home_url + '?p=' + this.get( 'id' ) + '&preview=true&post_type=' + this.get( 'type' );

},

/**
* Retrieve schema fields defined for the model
*
Expand Down
32 changes: 4 additions & 28 deletions includes/admin/class.llms.admin.builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public static function admin_bar_menu( $wp_admin_bar ) {
wp_admin_bar_appearance_menu( $wp_admin_bar );

}

}

/**
Expand All @@ -93,7 +92,6 @@ protected static function get_autosave_status() {
* @param string $autosave Status of autosave for the current user. Either "yes" or "no".
*/
return apply_filters( 'llms_builder_autosave_enabled', $autosave );

}

/**
Expand Down Expand Up @@ -270,7 +268,6 @@ private static function get_existing_posts( $post_type = '', $search_term = '',
);

return $ret;

}

/**
Expand All @@ -292,7 +289,6 @@ public static function get_existing_posts_where( $where, $wp_query ) {
}

return $where;

}

/**
Expand All @@ -309,7 +305,6 @@ private static function get_template( $template, $vars = array() ) {
extract( $vars );
include 'views/builder/' . $template . '.php';
return ob_get_clean();

}

/**
Expand Down Expand Up @@ -386,7 +381,6 @@ public static function handle_ajax( $request ) {
}

return array();

}

/**
Expand Down Expand Up @@ -417,7 +411,6 @@ private static function handle_post_locking( $course_id ) {

add_filter( 'get_edit_post_link', array( __CLASS__, 'modify_take_over_link' ), 10, 3 );
add_action( 'admin_footer', '_admin_notice_post_locked' );

}

/**
Expand Down Expand Up @@ -496,7 +489,6 @@ public static function heartbeat_received( $res, $data ) {
$res['llms_builder'] = $ret;

return $res;

}

/**
Expand All @@ -513,7 +505,6 @@ public static function heartbeat_received( $res, $data ) {
public static function is_temp_id( $id ) {

return ( ! is_numeric( $id ) && 0 === strpos( $id, 'temp_' ) );

}

/**
Expand All @@ -535,7 +526,6 @@ public static function modify_take_over_link( $link, $post_id, $context ) {
),
admin_url( 'admin.php' )
);

}

/**
Expand Down Expand Up @@ -659,6 +649,7 @@ public static function output() {
)
),
'enable_video_explainer' => true,
'home_url' => home_url(),
)
)
);
Expand All @@ -672,7 +663,6 @@ public static function output() {
<?php
$llms_builder_lazy_load = false;
self::handle_post_locking( $course_id );

}

/**
Expand Down Expand Up @@ -732,7 +722,6 @@ private static function process_detachments( $data ) {
}

return $ret;

}

/**
Expand All @@ -754,7 +743,6 @@ private static function process_trash( $data ) {
}

return $ret;

}

/**
Expand Down Expand Up @@ -818,7 +806,6 @@ private static function process_trash_item( $id ) {
}

return $res;

}

/**
Expand Down Expand Up @@ -857,7 +844,6 @@ private static function process_trash_item_non_post_type( $id ) {

// Success.
return true;

}

/**
Expand Down Expand Up @@ -918,7 +904,6 @@ private static function process_trash_item_post_type( $id, $post_type ) {
}

return true;

}

/**
Expand Down Expand Up @@ -947,7 +932,6 @@ private static function process_updates( $data ) {
}

return $ret;

}

/**
Expand Down Expand Up @@ -993,12 +977,10 @@ public static function update_custom_schemas( $type, $post, $post_data ) {

if ( isset( $field['sanitize_callback'] ) ) {
$val = call_user_func( $field['sanitize_callback'], $post_data[ $attr ] );
} else {
if ( is_array( $post_data[ $attr ] ) ) {
} elseif ( is_array( $post_data[ $attr ] ) ) {
$val = array_map( 'sanitize_text_field', $post_data[ $attr ] );
} else {
$val = sanitize_text_field( $post_data[ $attr ] );
}
} else {
$val = sanitize_text_field( $post_data[ $attr ] );
}

$attr = isset( $field['attribute_prefix'] ) ? $field['attribute_prefix'] . $attr : $attr;
Expand All @@ -1009,7 +991,6 @@ public static function update_custom_schemas( $type, $post, $post_data ) {
}
}
}

}

/**
Expand Down Expand Up @@ -1130,7 +1111,6 @@ private static function update_lessons( $lessons, $section ) {
}

return $ret;

}

/**
Expand Down Expand Up @@ -1234,7 +1214,6 @@ private static function update_questions( $questions, $parent ) {
}

return $res;

}

/**
Expand Down Expand Up @@ -1317,7 +1296,6 @@ private static function update_quiz( $quiz_data, $lesson ) {
}

return $res;

}

/**
Expand Down Expand Up @@ -1380,7 +1358,5 @@ private static function update_section( $section_data, $course_id ) {
}

return $res;

}

}
2 changes: 1 addition & 1 deletion includes/admin/views/builder/lesson.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<# } #>

<# if ( ! data.has_temp_id() ) { #>
<a class="llms-action-icon tip--top-right" data-tip="<?php esc_attr_e( 'View lesson', 'lifterlms' ); ?>" href="{{{ data.get( 'permalink' ) }}}" target="_blank">
<a class="llms-action-icon tip--top-right" data-tip="<?php esc_attr_e( 'View lesson', 'lifterlms' ); ?>" href="{{{ data.get_view_post_link() }}}" target="_blank">
<span class="fa fa-external-link"></span>
<?php esc_html_e( 'View', 'lifterlms' ); ?>
</a>
Expand Down
Loading