3

I am trying to integrate a LMS plugin with a membership plugin.

My goal is to allow all visitors to see courses and even lessons pages, but the corespondant videos would be restricted to members (of course).

Well, I found the LMS Plugin function responsible for displaying the video-HTML portion.

Is there a way to write another function to prevent that function to execute if the user is not a member (I already have the if statement for this ready).

Hiding div video element with CSS would not be a reasonable solution, of course.

And I can’t hack the LMS Plugin code, because it would be difficult to update later. I need to this using my own plugin, or inserting code on the functions.php file.

Thus my question: How to prevent a function execution with another function? Or is there any other way to do this?

EDIT: Well, I just found an add_action( 'lesson_video', array( $this, 'lesson_video' ), 10, 1 ); on the class core file. And there is a do_action( 'lesson_video', $post->ID ); on the php file that displays the content of the lesson. SO, I think I need to hook on this action too with my if statement. How would it be?

NEW EDIT: Well, the function is inside a class. It is like
class LMS_Frontend { public function __construct () {add_action( 'lesson_video', array( $this, 'lesson_video' ), 10, 1 );...}

How to remove this action?

NEW EDIT: Well, I finally did it. The action I was trying to remove was added inside a class, and this class was instantiated by another class.

I did:

global $varUsedWhenMainClassWasInstantiated;

remove_action('lesson_video', array($varUsedWhenMainClassWasInstantiated->classLessonVar, 'custom_lesson_video'));

Hope someone can benefit from this.

  • How is the plugin's function triggered? Is it hooked to an action or filter? – Milo Feb 3 '15 at 21:14
  • Well, I just found an add_action( 'lesson_video', array( $this, 'lesson_video' ), 10, 1 ); on the class core file. And there is a do_action( 'lesson_video', $post->ID ); on the php file that displays the content of the lesson. SO, I think I need to hook on this action too with my if statement. How would it be? – Luis Rock Feb 3 '15 at 23:16
1

Good on you for thinking ahead enough to not just edit the plugin.

Sadly if the plugin author didn't include hooks for you to use it's going to be tough. Maybe talk to the author about the hooks you need and/or make the changes and submit them to the author for implementation.

In some cases it may be possible to extend the plugin class, but this is going to depend on how the plugin is constructed and called. Or if they're using filters or actions you may also be able to unload theirs and write your own version in its place. Without proper hooks though it's still possible they'll make a change that would break your adjustment.

  • PLEASE, see the question again. I have edited it. Tks – Luis Rock Feb 3 '15 at 23:21
  • The same still applies. remove_action( 'lesson_video' ); then re-create the action with your own function. – Joey Yax Feb 3 '15 at 23:38
  • Please, I re-edit the question. – Luis Rock Feb 4 '15 at 0:57
  • 1
    add_action calls a native wp function. Whether it's called from within a class method or function is irrelevant. Since it's being called in the __construct it's firing the moment the class is instantiated. So long as you call remove_action( 'lesson_video' ) after the action is defined it will remove it. Then, you can replace it with your own function independent of the plugin. Also, if they're calling $this->lesson_video() method from within the class without using the action this may not matter anyway. You're best bet is reaching out to the dev or putting together your own plugin. – Joey Yax Feb 4 '15 at 1:10
  • 1
    Ah, yes you're exactly right. You also need to make sure the removal has the same priority as when it was created I believe. Example: gist.github.com/joeyyax/898da5ee2c6c6e42aa7e – Joey Yax Feb 4 '15 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.