Last week on the (hopefully) weekly Live Stream, I explored LearnDash Memberships through groups. And while I struggled a bit – I went in totally cold – towards the end I discovered a fantastic integration with WooCommerce Subscriptions that solved one of my problems. That solution allows me to eliminate custom code and lighten my website quite a bit.
Recently LearnDash announced some very exciting news in that they’ve converted/expanded Groups to allow for Memberships (and subscriptions). There’s a strong possibility I will migrate from my currently setup to this, as long as my testing shows it does what I need it to do (spoiler alert: nothing too crazy) and a migration path is clear.
But I also thought this would be a good time to revisit my current stack, seeing as memberships are a year old.
One of the biggest pieces of feedback I’ve gotten on my course videos in recent weeks was that the controls on my videos were hidden. To be honest, I didn’t realize students couldn’t scrub through videos, or rewind – I assumed everything was working! After looking through the LearnDash settings and not finding a global option, I decided to the problem with just a little bit of code.
TL;DR: The Code
So I’ll cut to the quick and give you code first. Read on to learn about it! This is the setting you want:
A few months ago I dug through the LearnDash code for a similar plugin I wrote to convert ACF videos to native LearnDash videos. I figured there was a similar setting for video controls, and I was right. If you use the Chrome inspector, you can see the name of the control in the source.
So I grabbed the name of that form field and fed it into the function I discovered earlier:learndash_update_setting(), which accepts a post ID, the setting name, and the value.
Confirming it worked for a single setting, it’s time to write the loop that would update all settings.
The Loop
I won’t dig into the full mechanics of the loop, but I do want to point out the custom post types I needed to update:
I’m grabbing all posts that are lessons and topics within LearnDash. Then I loop through them all, updating the video controls settings.
This is slightly inelegant because I should really check to see if there is a video on the post before turning on controls, but it worked!
Hooking it in.
Now that we have a working function that will update all posts, we need to figure out where to hook it into WordPress. Honestly, there’s only one smart option for this, and it’s on plugin activation:
This will ensure the code only runs once, when the plugin is enabled.
If you are adding it to your functions.php file or something like that, you should do it at a point where it won’t disrupt end users, so I would choose an admin hook, like admin_init.
I would also make sure it executes once, then comment out the action so it doesn’t run every time you load the admin.
Future Proofing
Now, this only counts for existing posts and not future lessons and topics you might add. I’d recommend toggling the option as you add the rest, but if you really want to make sure you don’t forget, you could repurpose the code to set the option on post save. Something like this will work:
When you take online courses, do you prefer video controls on? I sure do! As a course creator, what reasons do you have for turning them off? Let me know in the comments!
It’s been a crazy month, and I barely blogged, but that doesn’t mean I wasn’t pumping out content. Here’s a roundup of all the video (and other content I put out in May 2019.
You want to build better systems, but you don’t know where to start.
That ends today. The Solo Systems Starter Kit will give you 4 systems every solopreneur needs to run a less chaotic business, the exact tools to create those systems, and automations + AI prompts and skills to get you to a calmer, more reliable business faster.