admin管理员组文章数量:1130349
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.
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.
Share Improve this question edited Feb 4, 2015 at 12:42 Luis Rock asked Feb 3, 2015 at 21:06 Luis RockLuis Rock 1391 silver badge9 bronze badges 2 |1 Answer
Reset to default 1Good 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.
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.
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.
Share Improve this question edited Feb 4, 2015 at 12:42 Luis Rock asked Feb 3, 2015 at 21:06 Luis RockLuis Rock 1391 silver badge9 bronze badges 2- How is the plugin's function triggered? Is it hooked to an action or filter? – Milo Commented Feb 3, 2015 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 ado_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 Commented Feb 3, 2015 at 23:16
1 Answer
Reset to default 1Good 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.
本文标签: pluginsHow to prevent a function execution with another function
版权声明:本文标题:plugins - How to prevent a function execution with another function? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749034083a2306124.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


add_action( 'lesson_video', array( $this, 'lesson_video' ), 10, 1 );on the class core file. And there is ado_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 Commented Feb 3, 2015 at 23:16