Trigger Cutom Function on Child Sites

Hi, @bogdan thanks for the last feedback. Now I have stucked with another issue. All child sites have a function where calculates the folder custom size and saved to the child site database. Now I want to call this function from the main WP dashboard. I can create a rest API and if you guide me how can I call this function. So I can add a custom button on the size listing page or else.

Please advise me.

Thanks,
Subhankar

Hi Subhankar,

Please note that I moved this question to a separate topic so it’s easier to find for other users.

Regarding the process of triggering a custom function on child sites, please review this help document: MainWP Dashboard - Child Synchronization Process Explained - MainWP Documentation

Some time ago we wrote this to explain how and what the sync process does. I believe that this will help.

If you have additional questions, please feel free to ask.

Thanks, @bogdan for your help. But still, I am unable to integrate this feature. Can you give me an example, please?

I need to call a custom function get_database_size();

class FLBuilderCCDiskSpaceReport{
public static function get_database_size() {}
}

So I want to curl call this function. I have used the Postman tool.
So can I do this?

Like the site is :https://www.mistystoyaussies.com/
UserName : Subhankar
Signature is : [confused which can I use here? When I get the $website variable then I can see there are stored 3 different keys , 1. pubkey ; 2. privkey 3. nosslkey] Which can I use in the curl call?

How can I define this type of function in the child site? Can you please give me an example?

Thanks,

I will consult our dev team and let you know as soon as I get some feedback from them.

1 Like

Here is what our dev team said:

// 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, 'my_other_value' => FLBuilderCCDiskSpaceReport::get_database_size() ); // 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'];
        $my_other_value= $information['syncMyData']['my_other_value'];
		apply_filters( 'mainwp_updatewebsiteoptions', false, $website, 'my_site_size', $site_size );
        apply_filters( 'mainwp_updatewebsiteoptions', false, $website, 'my_other_value', $my_other_value);
	}	
}
// show data like this:
function show_my_data( $website ){
    $site_size  = apply_filters( 'mainwp_getwebsiteoptions', false, $website, 'my_site_size' );
	echo $site_size;
    $my_other_value= apply_filters( 'mainwp_getwebsiteoptions', false, $website, 'my_other_value' );
	echo $my_other_value;
}

Thanks for this feedback. But as we discussed I have already this code. But my requirement is now different. I need to call a child site custom function from the main WP dashboard with the custom trigger.

Give you an example:

I have a custom page in the main WP dashboard. I have added a button on this page name “Sync+Update”. Now I want to trigger a hook by clicking this button and call a child site function.

In the child site function, there was added a code where calculate the custom size value with shell scripting. So when I want to recalculate this value I will click the button “Sync+Update”. And this time my child site function will save the value. and this value passes to the main WP which I have done already.

So please check my requirement once. I need a small difference requirement rather than the above feedback.

Thanks,

Hi, @bogdan can you please check once my feedback? I will be very thankful to you if you will say anything.

the ‘my_other_value’ triggers the function

// 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, 'my_other_value' => FLBuilderCCDiskSpaceReport::get_database_size() ); // collect data here.
		} catch ( \Exception $e ) {
			// ok!
		}
	}
	return $information;
}

Tweaks it to the same thing like this:

// 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['triggerMyFunc'] ) && $data['triggerMyFunc'] ) {
		try {
			$information['triggerMyFunc'] = array( 'my_custom_value' => FLBuilderCCDiskSpaceReport::get_database_size() ); // collect data here.
		} catch ( \Exception $e ) {
			// ok!
		}
	}
	return $information;
}
1 Like

yes @bogdan I understand this code so when we sync all sites from the main WP dashboard, call the child function get_database_size(). Is it possible to sync all child site from our custom button?

Hi @bogdan please let me know if you got my point or not.

I will check with the dev team and let you know as soon as I get the update from them.

1 Like

Is there any feedback for me?

I am still waiting for updates from our dev team. Please allow us some time.

1 Like

Is there any update?

The dev team suggested creating a custom button such as:

<button class="ui button green " id="mainwp-sync-sites">Sync Dashboard with Child Sites</button>

and it should trigger the process.

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