• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Yoast SEO a2z

Yoast SEO a2z

WordPress SEO a2z

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / WPSEO_Option::__construct() – Add all the actions and filters for the option.

You appear to be a bot. Output may be restricted

Description

Add all the actions and filters for the option.

Usage

WPSEO_Option::__construct();

Parameters

Returns

void

Source

File name: wordpress-seo/inc/options/class-wpseo-option.php


Lines:

1 to 73 of 73
  protected function __construct() {

    /* Add filters which get applied to the get_options() results. */
    $this->add_default_filters(); // Return defaults if option not set.
    $this->add_option_filters(); // Merge with defaults if option *is* set.

    if ( $this->multisite_only !== true ) {
      
/**
 * The option validation routines remove the default filters to prevent failing
 * to insert an option if it's new. Let's add them back afterwards.
 */
      add_action( 'add_option', [ $this, 'add_default_filters_if_same_option' ] ); // Adding back after INSERT.

      add_action( 'update_option', [ $this, 'add_default_filters_if_same_option' ] );

      add_filter( 'pre_update_option', [ $this, 'add_default_filters_if_not_changed' ], PHP_INT_MAX, 3 );

      // Refills the cache when the option has been updated.
      add_action( 'update_option_' . $this->option_name, [ 'WPSEO_Options', 'clear_cache' ], 10 );
    }
    elseif ( is_multisite() ) {
      /*
			 * The option validation routines remove the default filters to prevent failing
			 * to insert an option if it's new. Let's add them back afterwards.
			 *
			 * For site_options, this method is not foolproof as these actions are not fired
			 * on an insert/update failure. Please use the WPSEO_Options::update_site_option() method
			 * for updating site options to make sure the filters are in place.
			 */
      add_action( 'add_site_option_' . $this->option_name, [ $this, 'add_default_filters' ] );
      add_action( 'update_site_option_' . $this->option_name, [ $this, 'add_default_filters' ] );
      add_filter( 'pre_update_site_option_' . $this->option_name, [ $this, 'add_default_filters_if_not_changed' ], PHP_INT_MAX, 3 );

      // Refills the cache when the option has been updated.
      add_action( 'update_site_option_' . $this->option_name, [ 'WPSEO_Options', 'clear_cache' ], 1, 0 );
    }

    /*
		 * Make sure the option will always get validated, independently of register_setting()
		 * (only available on back-end).
		 */
    add_filter( 'sanitize_option_' . $this->option_name, [ $this, 'validate' ] );

    // Flushes the rewrite rules when option is updated.
    add_action( 'update_option_' . $this->option_name, [ 'WPSEO_Utils', 'clear_rewrites' ] );

    /* Register our option for the admin pages */
    add_action( 'admin_init', [ $this, 'register_setting' ] )  <;

    /* Set option group name if not given */
    if ( ! isset( $this->group_name ) || $this->group_name === '' ) {
      $this->group_name = 'yoast_' . $this->option_name . '_options';
    }

    /* Translate some defaults as early as possible - textdomain is loaded in init on priority 1. */
    if ( method_exists( $this, 'translate_defaults' ) ) {
      add_action( 'init', [ $this, 'translate_defaults' ], 2 );
    }

    
/**
 * Enrich defaults once custom post types and taxonomies have been registered
 * which is normally done on the init action.
 *
 * @todo [JRF/testers] Verify that none of the options which are only available after
 * enrichment are used before the enriching.
 */
    if ( method_exists( $this, 'enrich_defaults' ) ) {
      add_action( 'init', [ $this, 'enrich_defaults' ], 99 );
    }
  }
 

 View on GitHub View on Trac

Published: 27th November 2019 | Last updated: 11th August 2023

Primary Sidebar

Information

Function name: WPSEO_Option::__construct
Class ref: WPSEO_Option
Plugin ref: Yoast SEO
Version: 20.13
Sourcefile: inc/options/class-wpseo-option.php
File ref: inc/options/class-wpseo-option.php
Deprecated?: No
API Letters: C,O,W

Footer

Yoast SEO a2z
Yoast SEO a2z
WordPress SEO a2z
WordPress 6.3.1
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  wordpress-seo.wp-a2z.org
© Copyright Yoast SEO a2z 2017-2023. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites