Page Break Module Not Added In Between Pages

When creating a Unit with multiple pages, the "page_break_module" is not being added in between the different pages. This results in everything being seen as a Single Page, and thus breaks some layouts and functionality.

In our theme we are making a call to

$unit_class	 = new Unit( $unit->ID );
$unit_pages	 = $unit_class->get_number_of_unit_pages();

However, the $unit_pages is being returned as a 1. This is for all new courses and pages. This was working as expected before, and only recently starting creeping up.

In further troubleshooting, we took this function out of the "class.course.unit.php" and implemented it directly into our theme and printed out the $class_names. This is how we were able to determine that for our new pages the "page_break_module" was not being inserted.

function get_number_of_unit_pages( $unit_id = '' ) {
			if ( $unit_id == '' ) {
				    $unit_id = $this->id;
			}

			$module	 = new Unit_Module();
			$modules = $module->get_modules( $unit_id );

			$pages_num = 1;

			foreach ( $modules as $mod ) {
				    $class_name = $mod->module_type;
            echo $class_name.'<br/>';
				    if ( class_exists( $class_name ) ) {
					        $module = new $class_name();

					        if ( $module->name == 'page_break_module' ) {
						            $pages_num++;
					        }
	    }
			}

			return $pages_num;
}

You'll notice that this code is dependent on the 'page_break_module' as well and since the "page_break_module" is not there, it is saying the number of unit pages is 1, rather than the real amount.

Please let me know if any further clarification is needed.

  • Michael Bissett
    • Recruit

    Hey @Susan, hope you're doing well today! :slight_smile:

    I'm not seeing this come up when the Twenty Fourteen theme is in use, does this issue only come up when using this particular theme? What's the theme in question, if I may ask?

    I tried going to your site to see, but it doesn't seem like the DNS records are working properly, as I get this error inside of Google Chrome:

    Error code: DNS_PROBE_FINISHED_NXDOMAIN

    Please advise,
    Michael

    • Susan
      • Site Builder, Child of Zeus

      Michael
      The site is still currently under development and so it is on our development servers which are not available outside our network, this is why you are getting the DNS error. I will confirm tomorrow if I can get this error to occur with a default WP theme. I will also test via the CoursePress theme.

      Thanks

  • Susan
    • Site Builder, Child of Zeus

    Alright, so I am able to duplicate this in TwentyFourteen. Here is the code that we are using:

    while ( have_posts() ) : the_post();
             $course = new Course(get_the_ID());
             $units = $course->get_units();
             $module = new Unit_Module();
             foreach ( $units as $unit ) {
                     $unit_class      = new Unit( $unit->ID );
                     $unit_pages      = $unit_class->get_number_of_unit_pages();
                     $modules = $module->get_modules( $unit->ID );
                     foreach ( $modules as $mod ) {
                             $class_name = $mod->module_type;
                             echo $class_name.'<br/>';
                      }
            }
            /*
            * Include the post format-specific template for the content. If you want to
            * use this in a child theme, then include a file called called content-___.php
            * (where ___ is the post format) and that will be used instead.
            */
            get_template_part( 'content', get_post_format() );
            // Previous/next post navigation.
            twentyfourteen_post_nav();
            // If comments are open or we have at least one comment, load up the comment template.
            if ( comments_open() || get_comments_number() ) {
                    comments_template();
            }
    endwhile;

    I you put this code into the single.php of the TwentyFourteen theme, we are not getting the "page_break_module". It is only showing "text_module" and "video_module". Is there something that we're doing wrong with our call? As I've said in the original explanation, this is only occurring on new courses/pages.

  • Adam Czajczyk
    • Support Gorilla

    Hello Susan,

    I hope you're well!

    I've put your code in my single.php of Twenty Fourteen theme and after that created a new course with 5 different pages. For me your code works almost perfectly fine except it prints out modules names one the first page of the course (the one with course details and description) which is actually unnecessary. Other than this everything else seems to be working as expected (with your code) - course is splitted to 5 pages and pages are not being displayed at once.

    That leads me to the conclusion that there might be some other issue like maybe other non-standard theme customizations or some plugins that interfere with this code (especially the page navigation). I understand that the site is not accessible from outside now so perhaps you could provide us with the theme itself and a full list of plugins installed?

    You may deliver the theme by uploading it to Dropbox or any other similar sevice and sending me a link to download. Please do not put that linke here as this is an open forum and it's very well indexed by Google and other search engines. Use our contact form instead at:

    https://premium.wpmudev.org/contact/

    Be sure to select "I have a different question" from the dropdown menu (as shown on the attached image) and use this line as a message subject:

    Attn: Adam Czajczyk

    Also link back to this forum thread somwhere in the message.

    Cheers,
    Adam

  • Adam Czajczyk
    • Support Gorilla

    Hey Susan,

    I hope you're well today!

    I've received you message, thank you! On my own test setup I've been able to use your code, the same as before, with default (fresh install) themes and CoursePress. However, with your plugins and themes installed I've experienced different behavior: using your Twenty Fourteen theme and plugins from my setup - it worked fine. Using only your plugins and themes finally everything broke down for me.

    Having said that, I think we'll need some help here, so I've notified our 2nd-line support about the issue. Hopefully, they'll be able to perform more extensive tests on this and come up with a solution soon.

    Please keep an eye on this thread for further updates and information!

    Regards,
    Adam

  • Hoang Ngo
    • Code Slayer

    Hi @Susan,

    I hope you are well today.

    This is weird, can you please go to the _postmeta table, and run a query like this, I assumed your post meta table is wp_postmeta.
    select * from wp_postmeta where meta_value='page_break_module';
    And then, please post a screenshot about the result here?

    Thanks!

    Best regards,
    Hoang

  • Susan
    • Site Builder, Child of Zeus

    So I have have attached the screenshot. One thing to note is that there are 7 entries for the page break module, but when running a query to get the number of courses:

    SELECT COUNT(*)
    FROM wp_posts
    WHERE post_type = 'course'
    AND post_status = 'publish'

    I get that there are 44 courses on this subsite.

  • Hoang Ngo
    • Code Slayer

    Hi @Susan,

    I hope you are well today and many thanks for your information.

    One thing to note is that there are 7 entries for the page break module, but when running a query to get the number of courses: I get that there are 44 courses on this subsite.

    This is fine, if your courses' units don't have much page-break module. Also, I think there's some glitch with your database. Can you please send me a database dump, that will help me easier to reproduce the bug.

    For sending, please send me an email to contact@wpmudev.org, with the subject line ATTN: Hoang Ngo, and the content is
    - Link to this thread
    - Attach your database dump there

    Thanks!

    Best regards,
    Hoang

  • Hoang Ngo
    • Code Slayer

    Hi @Susan,

    I hope you are well today and I'm sorry for the delay.

    Firstly, I strongly to recommend you to use this version here https://premium.wpmudev.org/forums/topic/coursepress-pro-user-cant-login#post-884453. This beta version included many fixes.

    Also, as you modified the plugin, can you please let me know which part you modified, so I can help you bring it back to the new version and give you some hooks information, to prevent the re-update progress after each time the plugin updated.

    Best regards,
    Hoang

  • Susan
    • Site Builder, Child of Zeus

    So the piece that I changed was to turn off the emails. So I've added return true at the opening of the coursepress_send_mail() in the functions.php. This was suggested by yourself in this post https://premium.wpmudev.org/forums/topic/ability-to-disable-email-notifications. I would really like for this to be either pluggable or a setting added to allow for the emails to be turned off.

    I also installed the version of CoursePress listed above and the problem is still persisting.

    Thank you

  • Michael Bissett
    • Recruit

    Hey @Susan,

    So the piece that I changed was to turn off the emails. So I've added
    return true
    at the opening of the coursepress_send_mail() in the functions.php. This was suggested by yourself in this post https://premium.wpmudev.org/forums/topic/ability-to-disable-email-notifications. I would really like for this to be either pluggable or a setting added to allow for the emails to be turned off.

    That'd definitely be handy, I can mention that to the developer for you. :slight_smile:

    I also installed the version of CoursePress listed above and the problem is still persisting.

    ...hmm, this is definitely strange. :disappointed:

    I think at this point, we'll want to try reproducing the issue you're running into here in a different way. Could you please try using our Snapshot Pro plugin to make a copy of your site (include everything except the .htaccess & wp-config.php files):

    https://premium.wpmudev.org/project/snapshot/

    And then send it in, as follows:

    - Mark to my attention, the subject line should contain only: ATTN: Michael Bissett
    - Do not include anything else in the subject line, doing so may delay our response due to how email filtering works.
    - Link back to this thread
    - Include the snapshot of your site (you can upload it to a service like Dropbox, and provide the link to that in the email)
    - Include any other relevant information (e.g. the page on your site where you saw this issue in action; seeing as we'd be browsing a copy of your site, we'll want to know where we can look to diagnose this further)

    On the contact form, select "I have a different question", this ensures it comes through and gets assigned to me.

    https://premium.wpmudev.org/contact/

    Thanks a bunch! :slight_smile:

    Kind Regards,
    Michael

  • Predrag Dubajic
    • Support

    Hey @Susan,

    I checked your email and see that Michael has responded to it two days ago but there is no followup to it, could you please reply to him there.

    To quote Michael's message:

    I see that the snapshot in question only has the tables for the subsite, could you send in a snapshot for the main site as well? That'll allow me to have a complete picture of your site here.

    Thank you,
    Predrag

    • Susan
      • Site Builder, Child of Zeus

      So it only pulls in the DB tables for the Network Site. It doesn't include any of the other sub-sites. That should still be sufficient to do the testing. I am currently using Domain Mapping to change the domains of the sub-sites and wonder if that is what is causing the problem with the Snapshot plugin. I have sent a new contact form to Michael. I will include as well the best email to reach me at. As I said in the contact form, I am a developer and the account was purchased by Susan, but all development is done by myself. So emails sent to Susan may not be responded to as she does not always forward them to me.

  • Michael Bissett
    • Recruit

    Hey @Susan,

    I've got the snapshot set up on my site (had to work past a couple of issues, namely the SSO functionality, and the theme itself), but I'm seeing that there's quite a few courses you have available.

    Could you give me an example of a course & and the unit inside the course where I can see this in action?

    Please advise,
    Michael

  • Susan
    • Site Builder, Child of Zeus

    This can basically be accomplished with any course. Currently, our team went and combined them all into a single page in order to get them to display. However, if you go in an modify any course and add an additional page with some more video or file assets, then you will see that the page_break_module is not being created. What should be happening is here similar to the screenshot attached. See how the page titles are on the left side under each Unit Title. Then when selecting the page title on the left, the individual page contents are displayed on the right. However, because the page break module isn't being created then we have to combine all our pages into a single view. This breaks the flow and creates for an ugly UX as sometimes these units may have multiple pages and multiple assets for each page.

    • Susan
      • Site Builder, Child of Zeus

      You'll notice some difference as you are currently looking at Stage and this is Test. However, if I make any edits to Test, then I lose the page_break_module. That is how we discovered the problem in Stage. So, unfortunately, I have to fix this problem and can't just roll test up to Stage. As the problem is there on our test system, but for whatever reason, it's not currently exposing it's nasty head until we add or remove a page from the unit.

  • Michael Bissett
    • Recruit

    Hey @Susan,

    I've been trying to dig into the code here as best as I can, and while it does still seem like there's something with the template code (as I'm able to get those unit pages to display if I switch the theme, or if I use the [course_structure] shortcode inside of the template, instead of your code), I haven't been able to trace down what inside the code is causing a hiccup here. :disappointed:

    I'll need to reach out to our second level support staff again on this one, as this'll require more advanced troubleshooting.

    Kind Regards,
    Michael

    • Adam Czajczyk
      • Support Gorilla

      Hello Susan,

      I hope you're well today!

      This issue is pretty complex as it turned out and as far as I know, the developers are still working on the solution. I sincerely apologize that's taking so long but hopefully either @Michael Bissett or me we'll be able to deliver some good news really soon. We'll keep you informed and updated as soon as possible.

      Thank you very much for your great patience!

      Have a nice day!
      Adam

  • Jude
    • DEV MAN

    Hey @Susan

    Sorry about the extreme delay on this one. This somehow slipped through the gaps. Appreciate the patience.

    Do you still have this issue ? We have released a new version of the plugin, can you update to it ? Our records show you are still on a older version of the plugin.

    Let me know here if you need further assistance. Im keeping a close watch on this thread.

    Cheers
    Jude

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.