gglnltcs_print_accounts

The BestWebSoft Google Analytics gglnltcs print accounts function.

Description

gglnltcs_print_accounts( $analytics ); 

Parameters (1)

0. $analytics
The analytics.

Usage

  1. if ( !function_exists( 'gglnltcs_print_accounts' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bestwebsoft-google-analytics/bws-google-analytics.php'; 
  3.  
  4. // The analytics. 
  5. $analytics = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = gglnltcs_print_accounts($analytics); 
  9.  

Defined (1)

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

/bws-google-analytics.php  
  1. function gglnltcs_print_accounts( $analytics ) { 
  2. global $gglnltcs_options; 
  3. $profile_accounts = $accounts_id = array(); 
  4.  
  5. if ( isset( $_POST[ 'gglnltcs_accounts' ] ) && check_admin_referer( plugin_basename( __FILE__ ), 'gglnltcs_nonce_name' ) ) { 
  6. /** Save checkboxes */ 
  7. $settings = $_POST; 
  8. /** prepare data for update_option - unset unwanted $_POST vars and sanitize inpit */ 
  9. unset( $settings['gglnltcs_nonce_name'], $settings['_wp_http_referer'] ); 
  10. $settings['gglnltcs_start_date'] = stripslashes( esc_html( $settings['gglnltcs_start_date'] ) ); 
  11. $settings['gglnltcs_end_date'] = stripslashes( esc_html( $settings['gglnltcs_end_date'] ) ); 
  12. /** end of preparation */ 
  13. $gglnltcs_options['settings'] = $settings; 
  14. update_option( 'gglnltcs_options', $gglnltcs_options ); 
  15. } else if ( isset( $gglnltcs_options['settings'] ) ) { 
  16. /** Get settings from database */ 
  17. $settings = $gglnltcs_options['settings']; 
  18. } else { 
  19. $settings = ''; 
  20. /** Accounts: list 
  21. * https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/accounts/list */ 
  22. try { 
  23. $output = ''; 
  24. $accounts = $analytics->management_accounts->listManagementAccounts(); 
  25. $items = $accounts->getItems(); 
  26. if ( count( $items ) != 0 ) { 
  27. foreach( $items as $account ) { 
  28. $output .= '<option'; 
  29. if ( isset( $settings[ 'gglnltcs-accounts' ] ) && $settings[ 'gglnltcs_accounts' ] == $account->getName() ) { 
  30. $output .= ' selected = "selected">'; 
  31. } else { 
  32. $output .= '>'; 
  33. $output .= $account->getName() . '</option>'; 
  34. $profile_accounts[ $account->getId() ][ 'name' ] = $account->getName(); 
  35. $accounts_id[] = $account->getId(); 
  36. } /** close foreach.*/?> 
  37. <tr> 
  38. <th> 
  39. <h3> 
  40. <label for="gglnltcs-accounts"><?php _e( 'Accounts', 'gglnltcs' ); ?></label> 
  41. </h3> 
  42. </th> 
  43. <td> 
  44. <select id="gglnltcs-accounts" name="gglnltcs_accounts"> 
  45. <?php echo $output; ?> 
  46. </select> 
  47. </td> 
  48. </tr><?php  
  49. } else { 
  50. $func_return = array( $profile_accounts, $settings, $accounts_id ); 
  51. return $func_return; 
  52. } catch ( apiServiceException $e ) { 
  53. echo 'There was an APIerror ' . $e->getCode() . ' : ' . $e->getMessage(); 
  54. } catch ( Exception $e ) {