最新消息: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 Use Parameters with a Do_Action Function Within PHP Tags

matteradmin5PV0评论

I'm using a WordPress plugin that allows integration actions to integrate it within a theme. Using GeneratePress' Elements feature, I'm adding the action as a hook. Currently the code I'm using is:

<?php do_action(webcomic_integrate_landing_page);
?>

The action itself has some boolean parameters listed at this website. The one I'm most interested in is webcomic_meta.

How can I incorporate the webcomic_meta parameter (set to false) within the PHP tags for running this action?

I'm using a WordPress plugin that allows integration actions to integrate it within a theme. Using GeneratePress' Elements feature, I'm adding the action as a hook. Currently the code I'm using is:

<?php do_action(webcomic_integrate_landing_page);
?>

The action itself has some boolean parameters listed at this website. The one I'm most interested in is webcomic_meta.

How can I incorporate the webcomic_meta parameter (set to false) within the PHP tags for running this action?

Share Improve this question asked Apr 1, 2019 at 17:48 JustenJusten 132 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

First of all, let's take a look at do_action docs. As we can read there, this is the function that:

Execute functions hooked on a specific action hook.

And that's the way to use it:

do_action( string $tag,  $arg = '' )

So the first param is the tag (or the hook name). And then you can pass $arg (or rather $args).

And how to pass that args?

Well... It depends on action. Some of them take no args. Some of them take only one, and some of them take many args. Here's examples:

// this action takes no args
do_action( 'foo' );

// this action takes one arg
do_action( 'bar', $param );

// and this takes few args:
do_action( 'foobar', $param1, $param2, $param3 );

In your case, webcomic_integrate_landing_page takes only one param, which should be an array (as we can read here):

do_action( 'webcomic_integrate_landing_page', array $args );

So if you want to pass any args in there, here's how:

do_action( 'webcomic_integrate_landing_page', array( 'webcomic_comments' => true, 'webcomic_meta' => false ) );
Post a comment

comment list (0)

  1. No comments so far