-
-
Save mircobabini/e45563d3f28f28361c40bc9a758a54c2 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
<?php | |
/** | |
* Code for MAINWP DASH | |
* Save information to the table {table_prefix}_mainwp_wp_options once the site is successfully synced | |
* | |
* @param mixed $pWebsite | |
* @param array $information | |
* | |
* @return void | |
*/ | |
function mainwp_save_information( $pWebsite, $information ) { | |
$info_keys = [ | |
'yoast_separator', | |
'wp_blog_public', | |
'smtp_sender_email', | |
'smtp_sender_name', | |
'wp_mail_definition', | |
'google_tracking_id', | |
'wp_siteurl', | |
'wp_admin_email', | |
'wp_timezone_string', | |
]; | |
foreach ( $info_keys as $info_key ) { | |
if ( isset( $information[ $info_key ] ) ) { | |
MainWP_DB::instance()->updateWebsiteOption( | |
$pWebsite, | |
$info_key, | |
$information[ $info_key ] | |
); | |
} | |
} | |
} | |
add_action( 'mainwp_site_synced', 'mainwp_save_information', 10, 2 ); | |
/** | |
* Code for MAINWP CHILD | |
* Add other data to the child data array. | |
* | |
* @param array $information | |
* @param mixed $othersData | |
* | |
* @return mixed | |
*/ | |
function sync_other( $information, $othersData ) { | |
$information['wp_siteurl'] = get_option( 'siteurl' ); | |
$information['wp_admin_email'] = get_option( 'admin_email' ); | |
$information['wp_timezone_string'] = get_option( 'timezone_string' ); | |
$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']; | |
} | |
$wp_mail_definition = new ReflectionFunction( 'wp_mail' ); | |
$information['wp_mail_definition'] = [ | |
'path' => $wp_mail_definition->getFileName(), | |
'start' => $wp_mail_definition->getStartLine() | |
]; | |
// yoast | |
if ( class_exists( 'WPSEO_Option_Titles' ) ) { | |
$separator = get_option( 'wpseo_titles' )['separator']; | |
$separator_labels = WPSEO_Option_Titles::get_instance()->get_separator_options(); | |
$information['yoast_separator'] = $separator_labels[ $separator ]; | |
} | |
// analytics by monsterinsight | |
if ( is_plugin_active( 'google-analytics-for-wordpress/googleanalytics.php' ) ) { | |
$monsterinsights = get_option( 'monsterinsights_site_profile' ); | |
$information['google_tracking_id'] = $monsterinsights['viewname']; | |
} | |
// google tag manager by duracelltomi | |
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']; | |
} | |
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