Created
January 19, 2022 10:36
-
-
Save ragoand/2e76eb85436d50af5dee20a95bc4aa64 to your computer and use it in GitHub Desktop.
Add MainWP Child info and save
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Code for MAINWP DASH | |
* Save information to the table {table_prefix}_mainwp_wp_options once the site is successfully synced | |
* @param $pWebsite | |
* @param $information | |
* | |
* @return void | |
*/ | |
function mainwp_save_information( $pWebsite, $information ){ | |
if( isset($information['yoast_separator'])) { | |
MainWP_DB::instance()->updateWebsiteOption( $pWebsite, 'yoast_separator', $information['yoast_separator'] ); | |
} | |
if( isset($information['wp_blog_public'])) { | |
MainWP_DB::instance()->updateWebsiteOption( $pWebsite, 'wp_blog_public', $information['wp_blog_public'] ); | |
} | |
if( isset($information['smtp_sender_email'])) { | |
MainWP_DB::instance()->updateWebsiteOption( $pWebsite, 'smtp_sender_email', $information['smtp_sender_email'] ); | |
} | |
if( isset($information['smtp_sender_name'])) { | |
MainWP_DB::instance()->updateWebsiteOption( $pWebsite, 'smtp_sender_name', $information['smtp_sender_name'] ); | |
} | |
if( isset($information['wp_mail_definition'])) { | |
MainWP_DB::instance()->updateWebsiteOption( $pWebsite, 'wp_mail_definition', json_encode($information['wp_mail_definition']) ); | |
} | |
if( isset($information['google_tracking_id'])) { | |
MainWP_DB::instance()->updateWebsiteOption( $pWebsite, 'google_tracking_id', $information['google_tracking_id'] ); | |
} | |
if( isset($information['wp_siteurl'])) { | |
MainWP_DB::instance()->updateWebsiteOption( $pWebsite, 'wp_siteurl', $information['wp_siteurl'] ); | |
} | |
if( isset($information['wp_admin_email'])) { | |
MainWP_DB::instance()->updateWebsiteOption( $pWebsite, 'wp_admin_email', $information['wp_admin_email'] ); | |
} | |
if( isset($information['wp_timezone_string'])) { | |
MainWP_DB::instance()->updateWebsiteOption( $pWebsite, 'wp_timezone_string', $information['wp_timezone_string'] ); | |
} | |
} | |
add_action('mainwp_site_synced', 'mainwp_save_information', 10, 2); | |
/** | |
* Code for MAINWP CHILD | |
* Add other data to the child data array. | |
* @param $information | |
* @param $othersData | |
* | |
* @return mixed | |
*/ | |
function sync_other($information, $othersData) { | |
$separator = get_option('wpseo_titles')['separator']; | |
$separator_labels = WPSEO_Option_Titles::get_instance()->get_separator_options(); | |
$information['yoast_separator'] = $separator_labels[$separator]; | |
$information['wp_blog_public'] = get_option('blog_public'); | |
$c2c_configure_smtp = get_option('c2c_configure_smtp'); | |
if($c2c_configure_smtp){ | |
$information['smtp_sender_email'] = $c2c_configure_smtp['from_email']; | |
$information['smtp_sender_name'] = $c2c_configure_smtp['from_name']; | |
} | |
$details = new ReflectionFunction('wp_mail'); | |
$information['wp_mail_definition'] = [ | |
'path' => $details->getFileName(), | |
'start' => $details->getStartLine() | |
]; | |
if( is_plugin_active('google-analytics-for-wordpress/googleanalytics.php')){ | |
$monsterinsights = get_option('monsterinsights_site_profile'); | |
$information['google_tracking_id'] = $monsterinsights['viewname']; | |
} | |
if( is_plugin_active('duracelltomi-google-tag-manager/duracelltomi-google-tag-manager-for-wordpress.php')){ | |
$gtm4wp_options = get_option('gtm4wp-options'); | |
$information['google_tracking_id'] = $gtm4wp_options['gtm-code']; | |
} | |
$information['wp_siteurl'] = get_option('siteurl'); | |
$information['wp_admin_email'] = get_option('admin_email'); | |
$information['wp_timezone_string'] = get_option('timezone_string'); | |
return $information; | |
} | |
add_filter('mainwp_site_sync_others_data','sync_other', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment