o = $o; add_action( 'admin_menu', array( $this, 'admin_menu' ) ); add_action( 'admin_init', array( $this, 'admin_init' ) ); } /** * WordPress 'admin_menu' hook, it is the right place to add menu item. * @return void */ public function admin_menu() { add_options_page( __('Google Analytics Head plugin options', 'analytics-head' ), PLUGIN_NAME, 'manage_options', OPTION_SLUG, array( $this, 'view_admin_page' ) ); } /** * This method is used for sanitizing options passed by * a WordPress form * @param * @return */ public function sanitize_options( $o ) { if ( !isset( $o['google_id'] ) ) { $o['google_id'] = ''; } if ( $o['google_id'] != '' ) { $t = preg_match('([U][A][-][0-9]{1,16}[-][0-9]{1,4})', $o['google_id'], $r ); if ( $t > 0 ) { $o['google_id'] = $r[0]; } else { $o['google_id'] = ''; } } if ( !isset( $o['hide-in_admin_panel'] ) ) { $o['hide-in_admin_panel'] = 0; } if ( !isset( $o['hide-for_logged_users'] ) ) { $o['hide-for_logged_users'] = 0; } if ( !isset( $o['move-to_footer'] ) ) { $o['move-to_footer'] = 0; } if ( !isset( $o['use_hooks'] ) ) { $o['use_hooks'] = 0; } if ( !isset( $o['add-plugin_info'] ) ) { $o['add-plugin_info'] = 0; } $o['version'] = PLUGIN_VERSION; return $o; } /** * WordPress 'admin_init' hook, it is the right place to register * settings/sections/fields etc for options page * @return void * */ public function admin_init() { register_setting( OPTION_GROUP, OPTION_NAME, array( $this, 'sanitize_options' ) ); add_settings_section( OPTION_GENERAL, __('General settings', 'analytics-head' ), array( $this, 'print_general_info_cb' ), OPTION_SLUG ); add_settings_field( 'google_id', __('', 'analytics-head' ), array( $this, 'google_id_cb' ), OPTION_SLUG, OPTION_GENERAL ); add_settings_field( 'hide-in_admin_panel', __('Hiding', 'analytics-head' ), array( $this, 'hide_in_admin_panel_cb' ), OPTION_SLUG, OPTION_GENERAL ); add_settings_field( 'hide-for_logged_users', '', array( $this, 'hide_for_logged_users_cb' ), OPTION_SLUG, OPTION_GENERAL ); add_settings_field( 'move-to_footer', __('Move code', 'analytics-head' ), array( $this, 'move_to_footer_cb' ), OPTION_SLUG, OPTION_GENERAL ); add_settings_section( OPTION_DEVELOPER, __('Developer settings', 'analytics-head' ), array( $this, 'print_developer_info_cb' ), OPTION_SLUG ); add_settings_field( 'use_hooks', '', array( $this, 'use_hooks_cb' ), OPTION_SLUG, OPTION_DEVELOPER ); add_settings_field( 'add-plugin_info', '', array( $this, 'add_plugin_info_cb' ), OPTION_SLUG, OPTION_DEVELOPER ); } /** * This method will get options and view it on plugin-options page * @return void */ public function view_admin_page() { global $current_user; # and view the options page ?>

Ɓukasz Nowicki. '; printf( __('You fill thankful? You may buy me a beer if you wish :)', 'analytics-head' ), 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W3U784F7TV6J4' ); ?>

', isset( $this->o->data['google_id'] ) ? esc_attr( $this->o->data['google_id']) : '' ); echo '

' . __( 'Something like UA-XXXXXXXX-X, where X-es are digits. It is your personal Google Analytics code provided by Google.', 'analytics-head' ) . '

'; } /** * View hide-in_admin_panel option callback * @return void */ public function hide_in_admin_panel_cb() { printf( '', ( isset( $this->o->data['hide-in_admin_panel'] ) && ( $this->o->data['hide-in_admin_panel'] == '1' ) ) ? ' checked' : '' ); } /** * View hide-for_logged_users option callback * @return void */ public function hide_for_logged_users_cb() { printf( '', ( isset( $this->o->data['hide-for_logged_users'] ) && ( $this->o->data['hide-for_logged_users'] == '1' ) ) ? ' checked' : '' ); } /** * View move-to_footer option callback * @return void */ public function move_to_footer_cb() { printf( '', ( isset( $this->o->data['move-to_footer'] ) && ( $this->o->data['move-to_footer'] == '1' ) ) ? ' checked' : '' ); } /** * View use_hooks callback * @return void */ public function use_hooks_cb() { printf( '', ( isset( $this->o->data['use_hooks'] ) && ( $this->o->data['use_hooks'] == '1' ) ) ? ' checked' : '' ); } /** * View use_hooks callback * @return void */ public function add_plugin_info_cb() { printf( '', ( isset( $this->o->data['add-plugin_info'] ) && ( $this->o->data['add-plugin_info'] == '1' ) ) ? ' checked' : '' ); } } # EOF