My custom functions in “functions.php” doesn’t work.

Normally, you can add code snippets for your custom functions into functions.php which is placed in your theme or child theme folder. But in case you select “mu-plugins” (ip-geo-block-mu.php) as “Validation timing” in “Validation rule settings” section, your code for this plugin in functions.php would be failed to work as you expected.

Validation timing

This restriction is originated from the excution order described in Action Reference where you can find muplugins_loaded action hook is triggered far before after_setup_theme which is the timing of your functions.php to be parsed.

Action Reference

Then what’t the solution?

Installing “drop-in.php”

If there is a special file named drop-in.php in your Geolocation API folder which might be one the of following locations:

  1. /wp-content/ip-geo-api/
  2. /wp-content/uploads/ip-geo-api/
  3. /wp-content/plugins/ip-geo-block/ip-geo-api/

You can find a sample for drop-in.php in /wp-content/plugins/ip-geo-block/drop-in-sample.php. So you can copy it into your Geolocation API folder and rename it as drop-in.php.

drop-in.php

Note that even in case of multisite, drop-in.php is the only one file for all sites and will be called on each site. So if you want each site to behave differently, you should add some code like follows:

<?php
/**
 * Drop-in for IP Geo Block custom filters
 *
 * @package   IP_Geo_Block
 * @link      https://www.ipgeoblock.com/codex/#filter-hooks
 * @example   Use `IP_Geo_Block::add_filter()` instead of `add_filter()`.
 */
if ( ! class_exists( 'IP_Geo_Block' ) ) {
    die;
}

$components = parse_url( site_url() );

switch ( $components['host'] ) {
    case 'example.com':
      if ( 0 === strpos( $components['path'], '/subdir1' ) ) {
          // here is code snippet for sub directory 1
      }

      elseif ( 0 === strpos( $components['path'], '/subdir2' ) ) {
          // here is code snippet for sub directory 2
      }
      break;

    case 'subdomain1.example.com':
      // here is code snippet for sub domain 1
      break;

    default:
      // here is code snippet for default
      break;
}
NOTE: All your custom functions in functions.php doesn't need to be put together into drop-in.php but functions related to only this plugin such as Filter hooks for this plugin.

See also