subhankara
(Subhankar Acharjee)
May 26, 2021, 3:10pm
1
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
bogdan
(Bogdan Rapaić)
May 27, 2021, 4:10pm
2
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
subhankara
(Subhankar Acharjee)
May 27, 2021, 4:37pm
3
Hi Bogdan,
Thanks for your help. I want to pull some custom option values for the child site from the main WP dashboard.
bogdan
(Bogdan Rapaić)
May 27, 2021, 4:39pm
4
And where would you display this data? Or what are you planing to do with it?
subhankara
(Subhankar Acharjee)
May 27, 2021, 4:41pm
5
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: Screenshot-cc1.accunet.us-2021.05.27-22_21_04.png - Nimbus Capture
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?
}
}
bogdan
(Bogdan Rapaić)
May 28, 2021, 3:09pm
6
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
subhankara
(Subhankar Acharjee)
May 28, 2021, 3:51pm
7
Thanks, @bogdan I will try it on Monday and let you know my feedback. Thanks Again.
1 Like
subhankara
(Subhankar Acharjee)
May 31, 2021, 2:03pm
8
Hi @bogdan Thanks it’s work as expected. Thanks to your dev team and you for this great help.
2 Likes
bogdan
(Bogdan Rapaić)
Split this topic
June 1, 2021, 4:09pm
9
system
(system)
Closed
July 1, 2021, 4:10pm
10
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.