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
Add theme compatibility for Module page #2205
Conversation
b7f80e2
to
b5854d1
Compare
@alexsanford Are there more changes coming as per #2205 (comment), or can I go ahead and test? |
@donnapep I will be adding changes to fix that issue. Hopefully today. |
43cc8c0
to
acbb274
Compare
b5854d1
to
2aa12f3
Compare
aa27499
to
2aa12f3
Compare
Important, for example, when a widget needs to check the query and/or globals to determine whether it is on a Module page.
@jom I set up a fix for this. I originally tried resetting the globals ( As a result, I feel that the best solution may be to leave globals set as they are so that the theme renders properly, but to change the globals when rendering a dynamic sidebar. This way, the theme thinks it is rendering a page the whole time (i.e. the dummy page that we set up in code), but the sidebar widgets think that the current query is for a module. I do worry that there may be other places in code where things may need to check if we're on a module page. Currently, the globals are set to the module query for the content, and the widgets. I can't think of another place that may have 3rd-party code that might need to make this check, but let me know if there's somewhere else I should test. |
Looks like there's a problem with the module progress indicator for the Divi theme. If I've completed a lesson in one of the modules, before this change I see the progress indicator styled like so: After this PR (or more likely after #2155), I see an unstyled progress indicator: |
@donnapep Yes, that CSS was broken by this PR. I've put together a solution, but I'm a bit concerned about some of the implications of this issue. The first problem was that the After fixing However when I tried to revert the commit that solved that issue previously, I found that along with using So I did not revert the commit that fixed the widget. Essentially, this is the implication:
My concern is that this could potentially cause really weird issues that are going to be hard to track down, and it may not be obvious that it's a theme incompatibility issue or that adding compatibility to the theme will fix it. |
@@ -1,5 +1,5 @@ | |||
$fontawesome: FontAwesomeSensei, FontAwesome; | |||
.module-archive #main .status, #main .course .module-status { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit concerned about removing the #main
selector. Is this element completely removed? It seems as though it may be safer to leave it in, and then add new selectors that exclude #main
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this element completely removed?
It depends on the theme, but in general, yes.
It seems as though it may be safer to leave it in, and then add new selectors that exclude
#main
.
Hmm. I see what you're getting at, but I don't think this would make any difference, technically. For example, the selector .module-archive #main .status, .module-archive .status
will match the exact same elements as .module-archive .status
.
Removing the #main
selector effectively makes the rules less specific. I.e. they will still match all the elements that would have been matched previously, but they will match other elements as well.
So the potential problem here is not that elements will be missed, but that we will match elements that we don't intend to. The rules are all scoped to .module-archive
or .course
, which gives us some safety. But technically, the possibility exists. We might be able to make the rules more specific, even after removing #main
. Do you think that's worth looking into?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, we'll likely uncover this during testing, if a problem exists.
So this change will break Course Progress by not showing it on the module page at all, and will potentially break third party code. Is that right? If that's the case, it sounds like we may need to rethink this approach and see if we can find an alternative that doesn't cause those side effects. Let's start by seeing if @jom has any ideas. |
Almost 🙂 This will not break Course Progress. I specifically added a fix for this issue that will apply within dynamic sidebars, and so this will not be an issue for widgets. That's the fix in 25a556f. As a contrived example of how this could break, let's say an extension added a filter to function sensei_add_module_course_body_class( $classes ) {
global $post;
if ( is_tax( 'module' ) ) {
$lesson_id = $post->ID;
$course_id = get_post_meta( $lesson_id, '_lesson_course', true );
$classes[] = "module-course-$course_id";
}
return $classes;
}
add_filter( 'body_class', 'sensei_add_module_course_body_class' ); The problem is that because this code runs outside of the module content rendering and outside of a dynamic sidebar, this will have different behaviour for a supported theme and an unsupported theme:
I honestly don't know whether this is actually going to be a problem for our users. It may be purely theoretically. WooCommerce apparently didn't run into it, but I don't know whether that's a good indicator for whether we should worry about it. |
It's been my experience that anything theoretical will come back to bite you in the butt. 😆It seems risky enough to spend some time trying to find a solution, but probably not worth spending more than a day on it. |
After a long chat with @jom about this, we were not able to come up with a good technical solution. The problem, in short, is that we need the global That said, this problem is scoped to the following conditions:
Our proposed solution is to leave this as-is, and ensure that we are communicating the risk appropriately through our theme support documentation. Here are some more things that we could do which may help:
cc @donnapep |
@alexsanford OK, thanks for the investigation, and I like your recommendations. Let's take this on a case-by-case basis if / when it comes up. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work on this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
I chatted with @dbtlr about this, and his suggestion was that adding functions to access the Sensei object (Lesson, Course, etc) would be a better option moving forward, rather than having the specific handling in place for dynamic sidebars. Since this work as-is now, I'm going to merge it in order to unblock further work. However, I've opened an issue (#2233) to discuss the option of adding the functions and removing the dynamic sidebar handling. Let's continue the conversation there. |
Partial solution to #2154
Adds theme compatibility for the Module page. A few notes:
I refactored the request handlers so that each page is handled by a different class. This way
Sensei_Unsupported_Themes
won't get out of hand.The "Dummy Post" may not be immediately clear. It's adapted from WooCommerce. In essence we do the following:
Unlike Add theme compatibility for Course Page #2155, I opted not to use a Renderer class. It simplified the logic, especially because within the handler, we already know that the globals are all set up for rendering the Module template. In the Renderer, we wouldn't necessarily have that context. If we need to render the Module page in other contexts in the future, we can extract the logic then.
Still to do
Testing
Create a few modules with some Lessons and a description.
From the Course page, click on one of the Module titles.
Ensure that the page looks right on themes that support Sensei, and themes that do not support Sensei.
For themes that do not support Sensei, ensure that: