Get custom option value from child site

I want to show custom option values from the child site.

I have added multiple sites to the main WP dashboard. So now I want to show the custom option value for each site. I have done the listing but how can I get the option value for each site?

Please advise me.
Thanks,
Subhankar

Hi Subhankar,

Just to be sure, do you want to pull in some value from the child site itself or manually enter values for the child sites in your dashboard?

1 Like

Hi Bogdan,

Thanks for your help. I want to pull some custom option values for the child site from the main WP dashboard.

And where would you display this data? Or what are you planing to do with it?

Yes I have added a custom page under the sites through hook. And also I have listed all connected sites with the $website object where I can get the website object. Now I want to show the custom option value for each website.

Exp: https://nimb.ws/OTQ72b

Code is below:

$connected_websites = MainWP_DB::Instance()->get_connected_websites();

if(!empty($connected_websites)){
         foreach($connected_websites as $connected_website){

              $website   = MainWP_DB::instance()->get_website_by_id( $connected_website['id'] );

// Now I want to option value here. Or you can give me an idea how can I get the value?

         }
}

Hi Subhankar,

I consulted our dev team and they sent me the following input:

// Hook: used in child site.	
add_filter( 'mainwp_site_sync_others_data', 'myhook_sync_others_data', 10, 2 );
function myhook_sync_others_data( $information, $data = array() ){
    if ( isset( $data['syncMyData'] ) && $data['syncMyData'] ) {
		try {
			$information['syncMyData'] = array( 'my_site_size' => 123456 ); // collect data here.
		} catch ( \Exception $e ) {
			// ok!
		}
	}
	return $information;
}
// Hooks: used in dashboard.
add_filter( 'mainwp_sync_others_data', 'myhook_mainwp_sync_others_data', 10, 2 );
function myhook_mainwp_site_synced( $data, $website ) {
	$data['syncMyData'] = true;
	return $data;
}	
add_action( 'mainwp_site_synced', 'myhook_mainwp_site_synced', 10, 2 );
function myhook_mainwp_site_synced( $website, $information = array() ) {
	if (is_array( $information ) && isset( $information['syncMyData'] ) ) {
		$site_size = $information['syncMyData']['my_site_size'];
		apply_filters( 'mainwp_updatewebsiteoptions', false, $website, 'my_site_size', $site_size );
	}	
}
// show data like this:
function show_my_data( $website ){
    $site_size  = apply_filters( 'mainwp_getwebsiteoptions', false, $website, 'my_site_size' );
	echo $site_size;
}
1 Like

Thanks, @bogdan I will try it on Monday and let you know my feedback. Thanks Again.

1 Like

Hi @bogdan Thanks it’s work as expected. Thanks to your dev team and you for this great help.

2 Likes

A post was split to a new topic: Trigger Cutom Function on Child Sites

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.