Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1387287
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 4 years ago.
Improve this questionRecently I met the below code
did_action( 'init' ) && $scripts->add_inline_script( 'lodash', 'window.lodash = _.noConflict();' );
inside the file \wp-includes\script-loader.php
Does anyone knows what does it mean? Especially double ampersand between two commands. I 've never met this syntax in PHP before and I cannot find documentation about this.
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 4 years ago.
Improve this questionRecently I met the below code
did_action( 'init' ) && $scripts->add_inline_script( 'lodash', 'window.lodash = _.noConflict();' );
inside the file \wp-includes\script-loader.php
Does anyone knows what does it mean? Especially double ampersand between two commands. I 've never met this syntax in PHP before and I cannot find documentation about this.
Share Improve this question edited Apr 18, 2020 at 14:54 Nomikos Strigkos asked Apr 18, 2020 at 14:48 Nomikos StrigkosNomikos Strigkos 95 bronze badges 1 |2 Answers
Reset to default 2I think its actually not allowed or discouraged in WP coding standards.
Its is basically saying "If true go ahead".
It's a short form of this:
if ( did_action( 'init' ) ) {
$scripts->add_inline_script( 'lodash', 'window.lodash = _.noConflict();' );
}
You can also think of this as if it's inside brackets of an if statement like this.
$var = false;
if ( $var && $scripts->add_inline_script( '...' ) ) { // As long as $var is false PHP won't execute or check what comes after the `&&`
}
The line itself could be refactored to use AND
instead of &&
as well. This technique is sometimes used to make code "speak" English. Example:
$if_my_value_is_TRUE = TRUE;
$if_my_value_is_TRUE AND print "This get's printed to the screen.";
// The exact same thing with `OR` or `||`
$my_value_is_TRUE = FALSE;
$my_value_is_TRUE OR print "This get's printed to the screen.";
It must be something like :
Do both simultaneously or do nothing
because i find out that if the first command cannot be executed neither the second does
本文标签: functionsphp syntax ampampbetween commands
版权声明:本文标题:functions - php syntax : [ && ] between commands 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744512425a2609959.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
if( did_action('init') ) { do_something(); }
– Nathan Johnson Commented Apr 19, 2020 at 18:20