Support

Account

Home Forums General Issues Access ACF functions from plugin

Solved

Access ACF functions from plugin

  • I’m thinking that there’s something really simple that I’m missing and I’ve gone through as much of the documentation that I could find, but…

    How do I access ACF functions from within my plugin?

    I want to run get_field() and get_fields() (and others) from within my plugin code.

    Umm… how?

  • OK, I answered my own question and I guess I was missing something really simple: just call get_field() from within my plugin code.

    What I was missing was that because the get_field function is defined in a file that was “include”d by the ACF class initialize method, that function is added to the global namespace. It just never occurred to me that get_field might be a global function.

    But I’m really confused about *why* the ACF coders would dump functions like “get_field” into the global namespace. If I ever attempt to load another plugin or theme that does the same thing – declares a ‘get_field’ function into the global namespace – it will trigger a fatal error.

    Isn’t this what namespaces and classes are for?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.