monsterinsights_import_settings

The Google Analytics for WordPress by MonsterInsights monsterinsights import settings function.

Description

monsterinsights_import_settings(); 

Usage

  1. if ( !function_exists( 'monsterinsights_import_settings' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-analytics-for-wordpress-by-monsterinsights/includes/admin/pages/tools.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = monsterinsights_import_settings(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/admin/pages/tools.php  
  1. function monsterinsights_import_settings() { 
  2.  
  3. if ( !isset( $_POST['monsterinsights_action'] ) || empty( $_POST['monsterinsights_action'] ) ) { 
  4. return; 
  5.  
  6. if ( ! current_user_can( 'monsterinsights_save_settings' ) ) { 
  7. return; 
  8.  
  9. if ( $_POST['monsterinsights_action'] !== 'monsterinsights_import_settings' ) { 
  10. return; 
  11.  
  12. if ( !wp_verify_nonce( $_POST['monsterinsights_import_settings'], 'monsterinsights_import_settings' ) ) { 
  13. return; 
  14.  
  15. $extension = explode( '.', $_FILES['import_file']['name'] ); 
  16. $extension = end( $extension ); 
  17.  
  18. if ( $extension != 'json' ) { 
  19. wp_die( __( 'Please upload a valid .json file', 'google-analytics-for-wordpress' ) ); 
  20.  
  21. $import_file = $_FILES['import_file']['tmp_name']; 
  22.  
  23. if ( empty( $import_file ) ) { 
  24. wp_die( __( 'Please upload a file to import', 'google-analytics-for-wordpress' ) ); 
  25.  
  26. $file = file_get_contents( $import_file ); 
  27. if ( empty( $file ) ) { 
  28. wp_die( __( 'Please upload a real settings export file to import', 'google-analytics-for-wordpress' ) ); 
  29.  
  30. // Retrieve the settings from the file and convert the json object to an array. 
  31. $new_settings = json_decode( wp_json_encode( json_decode( $file ) ), true ); 
  32. $settings = monsterinsights_get_options(); 
  33. $exclude = array(  
  34. 'analytics_profile',  
  35. 'analytics_profile_code',  
  36. 'analytics_profile_name',  
  37. 'oauth_version',  
  38. 'cron_last_run',  
  39. 'monsterinsights_oauth_status',  
  40. ); 
  41.  
  42. foreach ( $exclude as $e ) { 
  43. if ( ! empty( $new_settings[ $e ] ) ) { 
  44. unset( $new_settings[ $e ] ); 
  45.  
  46. if ( ! is_super_admin() ) { 
  47. if ( ! empty( $new_settings[ 'custom_code' ] ) ) { 
  48. unset( $new_settings[ 'custom_code' ] ); 
  49.  
  50. foreach ( $exclude as $e ) { 
  51. if ( ! empty( $settings[ $e ] ) ) { 
  52. $new_settings = $settings[ $e ]; 
  53.  
  54. global $monsterinsights_settings; 
  55. $monsterinsights_settings = $new_settings; 
  56.  
  57. update_option( monsterinsights_get_option_name(), $new_settings ); 
  58. wp_safe_redirect( admin_url( 'admin.php?page=monsterinsights_tools&action=import&result=success#monsterinsights-main-tab-settings' ) ); exit;