/wp-content/plugins/google-analytics-for-wordpress/includes/admin/pages/settings.php

https://bitbucket.org/carloskikea/helpet · PHP · 199 lines · 103 code · 26 blank · 70 comment · 21 complexity · ac848563bf8e78ced29804a5d6d8b61e MD5 · raw file

  1. <?php
  2. /**
  3. * Settings class.
  4. *
  5. * @since 6.0.0
  6. *
  7. * @package MonsterInsights
  8. * @subpackage Settings
  9. * @author Chris Christoff
  10. */
  11. // Exit if accessed directly
  12. if ( ! defined( 'ABSPATH' ) ) {
  13. exit;
  14. }
  15. function monsterinsights_is_settings_page() {
  16. $current_screen = get_current_screen();
  17. global $admin_page_hooks;
  18. if ( ! is_object( $current_screen ) || empty( $current_screen->id ) || empty( $admin_page_hooks ) ) {
  19. return false;
  20. }
  21. $settings_page = false;
  22. if ( ! empty( $admin_page_hooks['monsterinsights_settings'] ) && $current_screen->id === $admin_page_hooks['monsterinsights_settings'] ) {
  23. $settings_page = true;
  24. }
  25. if ( ! empty( $admin_page_hooks['monsterinsights_reports'] ) && $current_screen->id === $admin_page_hooks['monsterinsights_reports'] ) {
  26. $settings_page = true;
  27. }
  28. if ( $current_screen->id === 'toplevel_page_monsterinsights_settings' ) {
  29. $settings_page = true;
  30. }
  31. if ( $current_screen->id === 'insights_page_monsterinsights_settings' ) {
  32. $settings_page = true;
  33. }
  34. if ( $current_screen->id === 'insights_page_monsterinsights_tracking' ) {
  35. $settings_page = true;
  36. }
  37. if ( ! empty( $current_screen->base ) && strpos( $current_screen->base, 'monsterinsights_network' ) !== false ) {
  38. $settings_page = true;
  39. }
  40. return $settings_page;
  41. }
  42. /**
  43. * Callback to output the MonsterInsights settings page.
  44. *
  45. * @since 6.0.0
  46. * @access public
  47. *
  48. * @return void
  49. */
  50. function monsterinsights_settings_page() {
  51. /**
  52. * Developer Alert:
  53. *
  54. * Per the README, this is considered an internal hook and should
  55. * not be used by other developers. This hook's behavior may be modified
  56. * or the hook may be removed at any time, without warning.
  57. */
  58. do_action( 'monsterinsights_head' );
  59. ?>
  60. <?php echo monsterinsights_ublock_notice(); ?>
  61. <!-- Tabs -->
  62. <h1 id="monsterinsights-settings-page-main-nav" class="monsterinsights-main-nav-container monsterinsights-nav-container" data-container="#monsterinsights-settings-pages">
  63. <a class="monsterinsights-main-nav-item monsterinsights-nav-item monsterinsights-spacing-item" href="#">&nbsp;</a>
  64. <a class="monsterinsights-main-nav-item monsterinsights-nav-item monsterinsights-active" href="#monsterinsights-main-tab-general" title="<?php echo esc_attr( __( 'General', 'google-analytics-for-wordpress' ) ); ?>">
  65. <?php echo esc_html__( 'General', 'google-analytics-for-wordpress' ); ?>
  66. </a>
  67. <a class="monsterinsights-main-nav-item monsterinsights-nav-item" href="<?php echo admin_url('admin.php?page=monsterinsights_tracking#monsterinsights-main-tab-tracking?monsterinsights-sub-tab-engagement');?>" title="<?php echo esc_attr( __( 'Tracking', 'google-analytics-for-wordpress' ) ); ?>">
  68. <?php echo esc_html__( 'Tracking', 'google-analytics-for-wordpress' ); ?>
  69. </a>
  70. </h1>
  71. <!-- Tab Panels -->
  72. <div id="monsterinsights-settings-pages" class="monsterinsights-main-nav-tabs monsterinsights-nav-tabs wrap" data-navigation="#monsterinsights-settings-page-main-nav">
  73. <h1 class="monsterinsights-hideme"></h1><!-- so wp notices are below the nav bar -->
  74. <div id="monsterinsights-main-tab-general" class="monsterinsights-main-nav-tab monsterinsights-nav-tab monsterinsights-active">
  75. <?php monsterinsights_settings_general_tab(); ?>
  76. </div>
  77. </div>
  78. <?php
  79. }
  80. /**
  81. * Saves Settings
  82. *
  83. * @since 6.0.0
  84. * @access public
  85. *
  86. * @return null Return early if not fixing the broken migration
  87. */
  88. function monsterinsights_save_general_settings_page() {
  89. if ( ! monsterinsights_is_settings_page() ) {
  90. return;
  91. }
  92. // Check if user pressed the 'Update' button and nonce is valid
  93. if ( ! isset( $_POST['monsterinsights-settings-submit'] ) ) {
  94. return;
  95. }
  96. if ( ! wp_verify_nonce( $_POST['monsterinsights-settings-nonce'], 'monsterinsights-settings-nonce' ) ) {
  97. return;
  98. }
  99. if ( ! current_user_can( 'monsterinsights_save_settings' ) ) {
  100. return;
  101. }
  102. if ( ! empty( $_POST['monsterinsights_settings_tab'] ) && $_POST['monsterinsights_settings_tab'] === 'general' ) {
  103. /**
  104. * Developer Alert:
  105. *
  106. * Per the README, this is considered an internal hook and should
  107. * not be used by other developers. This hook's behavior may be modified
  108. * or the hook may be removed at any time, without warning.
  109. */
  110. do_action( 'monsterinsights_settings_save_general' );
  111. }
  112. }
  113. add_action( 'current_screen', 'monsterinsights_save_general_settings_page' );
  114. /**
  115. * Outputs a WordPress style notification to tell the user settings were saved
  116. *
  117. * @since 6.0.0
  118. * @access public
  119. *
  120. * @return void
  121. */
  122. function monsterinsights_updated_settings() {
  123. echo monsterinsights_get_message( 'success', esc_html__( 'Settings saved successfully.', 'google-analytics-for-wordpress' ) );
  124. }
  125. /**
  126. * Outputs a WordPress style notification to tell the user their UA code was bad.
  127. *
  128. * @since 6.0.3
  129. * @access public
  130. *
  131. * @return void
  132. */
  133. function monsterinsights_invalid_ua_code() {
  134. echo monsterinsights_get_message( 'error', esc_html__( 'Invalid UA code.', 'google-analytics-for-wordpress' ) );
  135. }
  136. /**
  137. * Outputs a checkbox for settings.
  138. *
  139. * Do not use this in other plugins. We may remove this at any time
  140. * without forwarning and without consideration for backwards compatibility.
  141. *
  142. * This is to be considered a private function, for MonsterInsights use only.
  143. *
  144. * @since 6.0.0
  145. * @access public
  146. *
  147. * @return void
  148. */
  149. function monsterinsights_make_checkbox( $option_id, $title = '', $description = '' ) {
  150. $option_value = monsterinsights_get_option( $option_id, 0 );
  151. $option_class = str_replace( '_', '-', $option_id );
  152. ob_start();
  153. ?>
  154. <tr id="monsterinsights-input-<?php echo esc_attr( $option_class ); ?>">
  155. <?php if ( !empty ( $title ) ) { ?>
  156. <th scope="row">
  157. <label for="monsterinsights-<?php echo esc_attr( $option_class ); ?>"><?php echo $title; ?></label>
  158. </th>
  159. <?php } ?>
  160. <td>
  161. <input type="checkbox" id="monsterinsights-<?php echo esc_attr( $option_class ); ?>" name="<?php echo esc_attr( $option_id ); ?>" <?php checked( $option_value, 1 ); ?> />
  162. <?php if ( ! empty ( $description ) ) { ?>
  163. <p class="description">
  164. <?php echo $description; ?>
  165. </p>
  166. <?php } ?>
  167. </td>
  168. </tr>
  169. <?php
  170. $input_field = ob_get_contents();
  171. ob_end_clean();
  172. return $input_field;
  173. }