PageRenderTime 26ms CodeModel.GetById 13ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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