6

While configuring Ctags to recognize WordPress functions, I came across the noop.php file. Here is an excerpt:

/**
 * @ignore
 */
function add_action() {}

/**
 * @ignore
 */
function did_action() {}

/**
 * @ignore
 */
function do_action_ref_array() {}

Why does this file exist? Can I remove it to let VIM better navigate the code?

2 Answers 2

5

The description on top of the page you have linked gives an explanation:

Create a new file, wp-admin/includes/noop.php, which loads all of the noop functions for load-script|styles.php and is only loaded by those files. DRYs in the process. See #33813.

Additionally there is the trac ticket #33813 linked, which gives some additional insight. You generally shouldn't delete core files so consider noop.php as a necessary file.

1
  • 3
    I don't think this or the comment at the top answers the question fully. This answer focuses on why the file exists, but a lot of people will be wondering why a noop file with noop functions is needed at all. It would be good if a brief explainer of why noop functions are needed in core would complete the answer for a lot of people
    – Tom J Nowell
    May 27, 2020 at 10:08
4

Why noop.php?

Previously noop functions were duplicated across core in multiple places, and an effort was made to co-locate them to avoid this duplication. This was done in https://core.trac.wordpress.org/ticket/33813 as part of an organisation effort.

What Are Noop functions?

Noop, or No Op-eration functions, are useful for testing and mocking. They're also a way to implement the null pattern, of presenting APIs that don't do anything to act as placeholders for ones that do.

Can I remove it to let VIM better navigate the code?

I would not modify core, instead you should tell ctags to ignore that file. This question/answer on stackoverflow will help:

https://stackoverflow.com/questions/7736656/vim-and-ctags-ignoring-certain-files-while-generating-tags

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.