Support » Plugin: Multiple Domain » hook get_option(‘multiple-domain-domains’)

  • Resolved crmb

    (@crmb)


    hello.
    I tried to hook on the get_option with add_filter('pre_option_multiple-domain-domains'... but it doesn’t seems to work.
    I added the code part in functions.php but the plugin seems to ignore it.
    Will it work only if used in a mu-plugin or something like that?

    (The idea was to manage my very long domains list dynamicaly without using the regular WP backoffice.)

    • This topic was modified 7 months ago by crmb.
    • This topic was modified 7 months ago by crmb.
    • This topic was modified 7 months ago by crmb.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Gustavo Straube

    (@gustavostraube)

    Hello,

    I just ran a test and it seems to be working. I did the following:

    function override_opt_domains($value) {
        return 'cool';
    }
    
    add_filter('pre_option_multiple-domain-domains', 'override_opt_domains');
    
    var_dump(get_option('multiple-domain-domains'));

    It outputs string(4) "cool". If I comment out the add_filter call, it outputs the array with all domain settings, as expected.

    I’m running WordPress 5.1 and the latest version of Multiple Domain. That piece of code was added to the functions.php of **TwentyNineteen** theme.

    crmb

    (@crmb)

    But i am not sure it works during initAttributes();
    I have to try again.

    Plugin Author Gustavo Straube

    (@gustavostraube)

    You’re right. The plugin loads before the filter in functions.php. It’s unexpected, though. According to this, functions.php is supposed to load before. I’ll keep investigating.

    Plugin Author Gustavo Straube

    (@gustavostraube)

    Looking at the official reference, plugins are loaded before themes: https://codex.wordpress.org/Action_Reference#Actions_Run_During_a_Typical_Request. Therefore, I don’t think you can achieve what you want simply using the pre_option_[...] filter. We probably need some way to enable programmatically changes to the list of domains.

    crmb

    (@crmb)

    Thank you.
    I think it may work with the hook in a mu-plugin because they are loaded before regular plugins. But all my code is in the theme right now for convenience, i will go with the programmatically update option value way then.

    Plugin Author Gustavo Straube

    (@gustavostraube)

    You can follow and contribute to this new feature here: https://github.com/straube/multiple-domain/issues/56

    Please check the updates on GitHub. I’m closing this topic for now.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘hook get_option(‘multiple-domain-domains’)’ is closed to new replies.