updated_option WordPress hook details – WORDPRESS ACTION HOOKS

Today, We want to share with you updated_option WordPress hook details – WORDPRESS ACTION HOOKS.In this post we will show you updated_option WordPress hook details , hear for UPDATED_OPTION in WORDPRESS ACTION HOOKS we will give you demo and example for implement.In this post, we will learn about wordpress get_option serialized with an example.

updated_option WordPress hook details – WORDPRESS ACTION HOOKS

There are the Following The simple About updated_option WordPress hook details – WORDPRESS ACTION HOOKS Full Information With Example and source code.

As I will cover this Post with live Working example to develop WordPress hook detect that option value has changed, so the some major files and Directory structures for this example is following below.

Read Also:  Angular 6 Smart Table with Sorting Searching and Pagination

Example 1: UPDATED_OPTION in WORDPRESS ACTION HOOKS

public function hook_gsf_server(){
  //Update Blog Settings
  add_action( 'updated_option', array( $this, 'action_update_site_option'), 10, 3 ); 
}

function action_update_site_option( $option_name, $old_value, $option_value ) { 
      $blog_details = get_wp_shop_details();
      $url = "https://www.your_domain_name.com/admin/api/shop_information_hook";
      $request = wp_remote_post($url, array(
      'headers'     => array('Content-Type' => 'application/json; charset=utf-8'),
      'body'        => json_encode($blog_details),
      'method'      => 'POST',
      'data_format' => 'body',
      ));

      if( is_wp_error( $request ) ) {
      return false; 
      }

      remove_action( 'updated_option', array( $this, 'action_update_site_option' ), 10, 3 );
}

Example 2: WordPress Hook After Options Page Save

To run the hook, copy the example below.

Read Also:  SQL LEFT OUTER JOIN overview and examples

run the action

do_action( 'update_option', $array ); 

The following example is for adding a hook callback.

define the update_option callback

function action_update_option( $array ) { 
    // make here action magic happen here... 
}; 

add the action

add_action( 'update_option', 'action_update_option', 10, 1 ); 

To remove a hook callback, use the example below.

remove/delete the action

 
remove_action( 'update_option', 'action_update_option', 10, 1 ); 

The dynamic portion of the hook name, $option, refers to the option name.

add_action( 'update_option_(option)', 'action_function_name_7854', 10, 3 );
function action_function_name_7854( $old_value, $value, $option ){
	// action...
}

Where is the hook used (in the core of WordPress)

add_action( 'update_option_page_on_front', 'update_home_siteurl', 10, 2 );
add_action( 'update_option_home', 'update_home_siteurl', 10, 2 );
add_action( 'update_option_siteurl', 'update_home_siteurl', 10, 2 );
add_action( 'update_option_blog_public', 'update_blog_public', 10, 2 );
add_action( 'update_option_new_admin_email', 'update_option_new_admin_email', 10, 2 );
add_action( 'update_option_admin_email', 'wp_site_admin_email_change_notification', 10, 3 );

Web Programming Tutorials Example with Demo

Read :

Read Also:  how to make a button link to another page in html?

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about update_option () in wordpress.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  PHP Multidimensional Array Searching multiple values
  2. Read Also:  Get minimum key value of array in PHP
  3. Read Also:  Wordpress Plugin uninstall hook - register_uninstall_hook()
  4. Read Also:  Simple VueJS Tree Menu Expandable
  5. Read Also:  Remove Html tags from string PHP - PHP strip_tags() Function
  6. Read Also:  vue js Accessing Complex Nested JSON objects
  7. Read Also:  jQuery toggleClass addClass removeClass Examples
  8. Read Also:  Laravel Email Verification Script Example
  9. Read Also:  Remove Html tags from string PHP - PHP strip_tags() Function
  10. Read Also:  Get minimum key value of array in PHP
CLOSEX