最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - How to Use Parameters with a Do_Action Function Within PHP Tags

programmeradmin0浏览0评论

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 ) );
发布评论

评论列表(0)

  1. 暂无评论