Skip to content

Commit 011b328

Browse files
move fathom to its own settings page & add tiny logo
1 parent c849cef commit 011b328

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Changelog
2+
==========
3+
4+
5+
6+
#### 1.0.0 - September 10, 2018
7+
8+
Plugin release.

fathom-analytics.php

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,35 +76,49 @@ function fathom_print_js_snippet() {
7676
<?php
7777
}
7878

79-
add_action( 'wp_head', 'fathom_print_js_snippet', 50 );
80-
8179
function fathom_register_settings() {
80+
$fathom_logo_html = sprintf( '<a href="https://usefathom.com/" style="margin-left: 6px;"><img src="%s" width=16 height=16 style="vertical-align: bottom;"></a>', plugins_url( 'fathom.svg', __FILE__ ) );
81+
add_options_page( 'Fathom Analytics', 'Fathom Analytics', 'manage_options', 'fathom-analytics', 'fathom_print_settings_page' );
82+
add_settings_section( 'default', "Fathom Analytics {$fathom_logo_html}", '__return_true', 'fathom-analytics' );
83+
8284
// register option
83-
register_setting( 'general', FATHOM_URL_OPTION_NAME, array( 'type' => 'string' ) );
84-
register_setting( 'general', FATHOM_SITE_ID_OPTION_NAME, array( 'type' => 'string' ) );
85+
register_setting( 'fathom', FATHOM_URL_OPTION_NAME, array( 'type' => 'string' ) );
86+
register_setting( 'fathom', FATHOM_SITE_ID_OPTION_NAME, array( 'type' => 'string' ) );
8587

8688
// register settings fields
87-
$title = __( 'Fathom URL', 'fathom-analytics' );
88-
add_settings_field( FATHOM_URL_OPTION_NAME, $title, 'fathom_print_url_setting_field', 'general' );
89+
$title = __( 'Dashboard URL', 'fathom-analytics' );
90+
add_settings_field( FATHOM_URL_OPTION_NAME, $title, 'fathom_print_url_setting_field', 'fathom-analytics', 'default' );
8991

90-
$title = __( 'Fathom Site ID', 'fathom-analytics' );
91-
add_settings_field( FATHOM_SITE_ID_OPTION_NAME, $title, 'fathom_print_site_id_setting_field', 'general' );
92+
$title = __( 'Site ID', 'fathom-analytics' );
93+
add_settings_field( FATHOM_SITE_ID_OPTION_NAME, $title, 'fathom_print_site_id_setting_field', 'fathom-analytics', 'default' );
94+
}
95+
96+
function fathom_print_settings_page() {
97+
echo '<div class="wrap">';
98+
echo sprintf( '<form method="POST" action="%s">', esc_attr( admin_url( 'options.php' ) ) );
99+
settings_fields( 'fathom' );
100+
do_settings_sections( 'fathom-analytics' );
101+
submit_button();
102+
echo '</form>';
103+
echo '</div>';
92104
}
93105

94106
function fathom_print_url_setting_field( $args = array() ) {
95107
$value = get_option( FATHOM_URL_OPTION_NAME );
96-
$placeholder = 'http://my-stats.usefathom.com/';
108+
$placeholder = 'https://my-stats.usefathom.com/';
97109
echo sprintf( '<input type="text" name="%s" id="%s" class="regular-text" value="%s" placeholder="%s" />', FATHOM_URL_OPTION_NAME, FATHOM_URL_OPTION_NAME, esc_attr( $value ), esc_attr( $placeholder ) );
98110
echo '<p class="description">' . __( 'Enter the full URL to your Fathom instance here.', 'fathom-analytics' ) . '</p>';
99111
}
100112

101113
function fathom_print_site_id_setting_field( $args = array() ) {
102114
$value = get_option( FATHOM_SITE_ID_OPTION_NAME );
103-
$placeholder = 'xx-xx';
104-
echo sprintf( '<input type="text" name="%s" id="%s" class="regular-text" value="%s" placeholder="%s" />', FATHOM_SITE_ID_OPTION_NAME, FATHOM_SITE_ID_OPTION_NAME, esc_attr( $value ), esc_attr( $placeholder ) );
105-
echo '<p class="description">' . __( 'Enter your Fathom site ID here', 'fathom-analytics' ) . '</p>';
115+
$placeholder = 'ABCDEF';
116+
echo sprintf( '<input type="text" name="%s" id="%s" class="small-text" value="%s" placeholder="%s" />', FATHOM_SITE_ID_OPTION_NAME, FATHOM_SITE_ID_OPTION_NAME, esc_attr( $value ), esc_attr( $placeholder ) );
117+
echo '<p class="description">' . __( 'Find your site ID by by clicking the gearwheel in your Fathom dashboard.', 'fathom-analytics' ) . '</p>';
106118
}
107119

120+
add_action( 'wp_head', 'fathom_print_js_snippet', 50 );
121+
108122
if( is_admin() && ! wp_doing_ajax() ) {
109123
add_action( 'admin_menu', 'fathom_register_settings' );
110124
}

fathom.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)