$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>plugins - How to prevent a function execution with another function?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugins - How to prevent a function execution with another function?

matteradmin8PV0评论

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 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 Commented Feb 3, 2015 at 23:16
Add a comment  | 

1 Answer 1

Reset to default 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.

Post a comment

comment list (0)

  1. No comments so far