/includes/admin/pages/network-settings.php

  1. <?php 
  2. /** 
  3. * Network class. 
  4. * 
  5. * @since 6.0.0 
  6. * 
  7. * @package MonsterInsights 
  8. * @subpackage network 
  9. * @author Chris Christoff 
  10. */ 
  11.  
  12. // Exit if accessed directly 
  13. if ( ! defined( 'ABSPATH' ) ) { 
  14. exit; 
  15.  
  16. /** 
  17. * Callback to output the MonsterInsights network page. 
  18. * 
  19. * @since 6.0.0 
  20. * @access public 
  21. * 
  22. * @return void 
  23. */ 
  24. function monsterinsights_network_page() { 
  25. /**  
  26. * Developer Alert: 
  27. * 
  28. * Per the README, this is considered an internal hook and should 
  29. * not be used by other developers. This hook's behavior may be modified 
  30. * or the hook may be removed at any time, without warning. 
  31. */ 
  32. do_action( 'monsterinsights_head' ); 
  33. $network_license = get_site_option( 'monsterinsights_license' ); 
  34. $license_key = ! empty( $network_license['key'] ) ? esc_attr( $network_license['key'] ) : ''; 
  35. $license_key_type = ! empty( $network_license['type'] ) ? esc_html( $network_license['type'] ) : ''; 
  36. $network_ua_code = get_site_option('monsterinsights_network_manual_ua_code', false ); 
  37. ?> 
  38. <?php echo monsterinsights_ublock_notice(); ?> 
  39. <div id="monsterinsights-settings" class="wrap"> 
  40. <div id="monsterinsights-settings-pages" class="monsterinsights-main-nav-tabs monsterinsights-nav-tabs wrap" data-navigation="#monsterinsights-network-settings-page-main-nav"> 
  41. <div id="monsterinsights-main-tab-general" class="monsterinsights-main-nav-tab monsterinsights-nav-tab monsterinsights-active"> 
  42. <div id="monsterinsights-network-settings-general"> 
  43. <?php  
  44. // Output any notices now 
  45. /**  
  46. * Developer Alert: 
  47. * 
  48. * Per the README, this is considered an internal hook and should 
  49. * not be used by other developers. This hook's behavior may be modified 
  50. * or the hook may be removed at any time, without warning. 
  51. */ 
  52. do_action( 'monsterinsights_network_settings_general_tab_notice' ); 
  53. ?> 
  54. <h1><?php esc_html_e( 'Network Settings', 'google-analytics-for-wordpress'); ?></h1> 
  55. <p><?php esc_html_e( 'Activate your MonsterInsights license key on this panel to hide the license key settings and addon pages for subsites.', 'google-analytics-for-wordpress'); ?></p> 
  56. <table class="form-table"> 
  57. <tbody> 
  58. <?php if ( monsterinsights_is_pro_version() ) : ?> 
  59. <tr id="monsterinsights-settings-key-box"> 
  60. <th scope="row"> 
  61. <label for="monsterinsights-settings-key"><?php esc_html_e( 'License Key', 'google-analytics-for-wordpress' ); ?></label> 
  62. </th> 
  63. <td> 
  64. <form id="monsterinsights-settings-verify-key" method="post"> 
  65. <input type="password" name="monsterinsights-license-key" id="monsterinsights-settings-key" value="<?php echo esc_attr( $license_key ); ?>" /> 
  66. <?php wp_nonce_field( 'monsterinsights-key-nonce', 'monsterinsights-key-nonce' ); ?> 
  67. <?php submit_button( esc_html__( 'Verify Key', 'google-analytics-for-wordpress' ), 'button-action', 'monsterinsights-verify-submit', false ); ?> 
  68. <?php submit_button( esc_html__( 'Deactivate Key', 'google-analytics-for-wordpress' ), 'button-danger', 'monsterinsights-deactivate-submit', false ); ?> 
  69. <p class="description"><?php esc_html_e( 'License key to enable automatic updates for MonsterInsights Pro & addons. Deactivate your license if you want to use it on another WordPress site.', 'google-analytics-for-wordpress' ); ?></p> 
  70. </form> 
  71. </td> 
  72. </tr> 
  73. <?php endif; ?> 
  74. <?php if ( ! empty( $license_key_type ) && monsterinsights_is_pro_version() ) : ?> 
  75. <tr id="monsterinsights-settings-key-type-box"> 
  76. <th scope="row"> 
  77. <label for="monsterinsights-settings-key-type"><?php esc_html_e( 'License Key Type', 'google-analytics-for-wordpress' ); ?></label> 
  78. </th> 
  79. <td> 
  80. <form id="monsterinsights-settings-key-type" method="post"> 
  81. <span class="monsterinsights-license-type"><?php printf( esc_html__( 'Your license key type for this site is %s.', 'google-analytics-for-wordpress' ), '<strong>' . $license_key_type . '</strong>' ); ?> 
  82. <input type="hidden" name="monsterinsights-license-key" value="<?php echo esc_attr( $license_key ); ?>" /> 
  83. <?php wp_nonce_field( 'monsterinsights-key-nonce', 'monsterinsights-key-nonce' ); ?> 
  84. <?php submit_button( esc_html__( 'Refresh Key', 'google-analytics-for-wordpress' ), 'button-action', 'monsterinsights-refresh-submit', false ); ?> 
  85. <p class="description"><?php esc_html_e( 'Your license key type (handles updates and Addons). Click refresh if your license has been upgraded or the type is incorrect.', 'google-analytics-for-wordpress' ); ?></p> 
  86. </form> 
  87. </td> 
  88. </tr> 
  89. <?php endif; ?> 
  90. <tr> 
  91. <form id="monsterinsights-network-general-tab" method="post"> 
  92. <th scope="row"> 
  93. <label for="monsterinsights-google-ua"><?php esc_html_e( 'Network UA code', 'google-analytics-for-wordpress' ); ?></label> 
  94. </th> 
  95. <td> 
  96. <input type="text" id="monsterinsights-network-ua-code" name="network_manual_ua_code" value="<?php echo $network_ua_code; ?>" /><?php submit_button( esc_html__( 'Save Network UA code', 'google-analytics-for-wordpress' ), 'button-action', 'monsterinsights-network-settings-submit', false ); ?> 
  97. <p class="description"><?php esc_html_e( 'This is the default UA code to use for subsites of a network (can be overriden at the single site level).', 'google-analytics-for-wordpress' ); ?></p> 
  98. <?php wp_nonce_field( 'monsterinsights-network-settings-nonce', 'monsterinsights-network-settings-nonce' ); ?> 
  99.  
  100. </td> 
  101. </form> 
  102. </tr> 
  103. </tbody> 
  104. </table> 
  105. </div> 
  106. </div> 
  107. </div> 
  108. </div> 
  109. <?php 
  110.  
  111. /** 
  112. * Callback for saving the general settings tab. 
  113. * 
  114. * @since 6.1.0 
  115. * @access public 
  116. * 
  117. * @return void 
  118. */ 
  119. function monsterinsights_network_settings_save_general() { 
  120.  
  121. // Check if user pressed the 'Update' button and nonce is valid 
  122. if ( ! isset( $_POST['monsterinsights-network-settings-submit'] ) ) { 
  123. return; 
  124.  
  125. if ( ! wp_verify_nonce( $_POST['monsterinsights-network-settings-nonce'], 'monsterinsights-network-settings-nonce' ) ) { 
  126. return; 
  127.  
  128. if ( ! current_user_can( 'monsterinsights_save_settings' ) ) { 
  129. return; 
  130.  
  131. $throw_notice = false; 
  132. $network_manual_ua_code = isset( $_POST['network_manual_ua_code'] ) ? $_POST['network_manual_ua_code'] : ''; 
  133. $network_manual_ua_code = monsterinsights_is_valid_ua( $network_manual_ua_code ); // also sanitizes the string 
  134.  
  135. if ( $network_manual_ua_code ) { 
  136. update_site_option( 'monsterinsights_network_manual_ua_code', $network_manual_ua_code ); 
  137. } else { 
  138. if ( empty ( $network_manual_ua_code ) && isset( $_POST['network_manual_ua_code'] ) ) { 
  139. $throw_notice = true; 
  140. update_site_option( 'monsterinsights_network_manual_ua_code', '' ); 
  141.  
  142. // Output an admin notice so the user knows what happened 
  143. if ( $throw_notice ) { 
  144. add_action( 'monsterinsights_network_settings_general_tab_notice', 'monsterinsights_invalid_ua_code' ); 
  145. } else { 
  146. add_action( 'monsterinsights_network_settings_general_tab_notice', 'monsterinsights_updated_settings' ); 
  147. add_action( 'admin_init', 'monsterinsights_network_settings_save_general', 11 ); 
.