= ACKNOWLEDGIFY_SCHEMA_VERSION ) { return; } update_option( ACKNOWLEDGIFY_OPTION, Helper::migrate( $settings ) ); Helper::flush_cache(); } /** * Register the option with the Settings API. * * The sanitise callback must be a resolvable callable. This previously * passed the bare string 'acknowledgify_sanitize_settings', which PHP * resolves against the global namespace only; the function lived in * Acknowledgify\Includes, so nothing was ever sanitised. * * @return void */ public static function register_settings() { register_setting( 'acknowledgify_options_group', ACKNOWLEDGIFY_OPTION, array( 'type' => 'array', 'sanitize_callback' => array( Settings::class, 'sanitize_settings' ), 'show_in_rest' => false, ) ); } /** * Register the humans.txt rewrite rule. * * @return void */ public static function add_rewrite_rules() { Humans_Txt::add_rewrite_rules(); } /** * Register our query var. * * @param string[] $vars Public query vars. * @return string[] */ public static function query_vars( $vars ) { return Humans_Txt::query_vars( $vars ); } /** * Auto-insert placement. * * @return void */ public static function footer_output() { Footer_Link::footer_output( 'auto_insert' ); } /** * Shortcode placement. * * @return string */ public static function footer_link_shortcode() { return Footer_Link::get_markup( 'shortcode' ); } /** * First save of the option. * * @param string $option Option name. * @param mixed $value New value. * @return void */ public static function on_option_added( $option, $value ) { Helper::flush_cache(); if ( is_array( $value ) && ! empty( $value['enable_humans_txt'] ) ) { self::schedule_rewrite_flush(); } } /** * Subsequent saves of the option. * * @param mixed $old_value Previous value. * @param mixed $value New value. * @return void */ public static function on_option_updated( $old_value, $value ) { Helper::flush_cache(); $was = ( is_array( $old_value ) && ! empty( $old_value['enable_humans_txt'] ) ) ? 1 : 0; $now = ( is_array( $value ) && ! empty( $value['enable_humans_txt'] ) ) ? 1 : 0; if ( $was !== $now ) { self::schedule_rewrite_flush(); } } /** * Flush rewrite rules once, at the end of this request. * * Deferred to shutdown so the flush happens after the option write has * settled, and so it cannot run more than once per request. This is the * only path other than activation and deactivation that flushes; the rule * itself is registered on every request by add_rewrite_rules(), which is * cheap, but the stored rule set has to be regenerated when the route is * turned on or off. * * @return void */ private static function schedule_rewrite_flush() { static $scheduled = false; if ( $scheduled ) { return; } $scheduled = true; add_action( 'shutdown', 'flush_rewrite_rules' ); } }