Plugin Directory

Changeset 2798094


Ignore:
Timestamp:
10/13/2022 03:29:38 AM (3 years ago)
Author:
simon_tw
Message:

Add choose post pageview position

Location:
sig-ga4-widget/trunk
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • sig-ga4-widget/trunk/classes/widget.php

    r2795994 r2798094  
    2222            'title' => __( 'Browsing Statistics', 'sig-ga4-widget' ),
    2323            'pageview' => [
    24                 'today' => [    /* translators: %d is today pageviews  */
    25                     'label' => __( 'Today pageviews: %d<br>', 'sig-ga4-widget' ),
     24                'today' => [    /* translators: %s is today pageviews  */
     25                    'label' => __( 'Today pageviews: %s<br>', 'sig-ga4-widget' ),
    2626                    'show' => 'yes',
    2727                    'adjust' => 0
    2828                ],
    29                 'all' => [      /* translators: %d is tatal pageviews  */
    30                     'label' => __( 'Total pageviews: %d<br>', 'sig-ga4-widget' ),
     29                'all' => [      /* translators: %s is tatal pageviews  */
     30                    'label' => __( 'Total pageviews: %s<br>', 'sig-ga4-widget' ),
    3131                    'show' => 'yes',
    3232                    'adjust' => 0
     
    3434            ],
    3535            'visit' => [
    36                 'today' => [    /* translators: %d is today visits  */
    37                     'label' => __( 'Today visits: %d<br>', 'sig-ga4-widget' ),
     36                'today' => [    /* translators: %s is today visits  */
     37                    'label' => __( 'Today visits: %s<br>', 'sig-ga4-widget' ),
    3838                    'show' => '',
    3939                    'adjust' => 0
    4040                ],
    4141                'all' => [
    42                                 /* translators: %d is total visits  */
    43                     'label' => __( 'Total visits: %d<br>', 'sig-ga4-widget' ),
     42                                /* translators: %s is total visits  */
     43                    'label' => __( 'Total visits: %s<br>', 'sig-ga4-widget' ),
    4444                    'show' => '',
    4545                    'adjust' => 0
     
    8686        <p>
    8787            <style type="text/css">
    88             table.siga4w{ width:100%; max-width:500px; border-collapse: collapse;border-spacing: 0;}
     88            table.siga4w{ width:100%; max-width:600px; border-collapse: collapse;border-spacing: 0;}
    8989            table.siga4w td{ border:1px solid #eee;padding: 2px 10px;}
    9090            </style>
     
    9292            <table class="siga4w">
    9393                <tr align="center">
    94                     <td width="60"><label><?php _e( 'Show', 'sig-ga4-widget' ); ?></label></td>
    95                     <td width="150"><label><?php _e( 'Default', 'sig-ga4-widget' ); ?></label></td>
    96                     <td width="200"><label><?php _e( 'Custom label text', 'sig-ga4-widget' ); ?></label></td>
    97                     <td width="*"><label><?php _e( 'Adjust', 'sig-ga4-widget' ); ?></label></td>
     94                    <td width="50"><label><?php _e( 'Show', 'sig-ga4-widget' ); ?></label></td>
     95                    <td width="140"><label><?php _e( 'Default', 'sig-ga4-widget' ); ?></label></td>
     96                    <td width="*"><label><?php _e( 'Custom label text', 'sig-ga4-widget' ); ?></label></td>
     97                    <td width="100"><label><?php _e( 'Adjust', 'sig-ga4-widget' ); ?></label></td>
    9898                </tr>
    9999                <tr align="center">
     
    101101                        <input class="" type="checkbox" value="yes" name="<?php echo $this->get_field_name('pageview_today_show');?>" <?php checked('yes',$instance['pageview_today_show'])?>>
    102102                    </td>
    103                     <td><label><?php echo $this->def_val['pageview_today_label'];?></label></td>
     103                    <td align="left">
     104                        <label><?php echo $this->def_val['pageview_today_label'];?></label>
     105                    </td>
    104106                    <td>
    105107                        <input class="widefat" type="text" name="<?php echo $this->get_field_name('pageview_today_label');?>" value="<?php echo esc_attr($instance['pageview_today_label']); ?>">
    106108                    </td>
    107109                    <td>
    108                         <input class="widefat" type="number" name="<?php echo $this->get_field_name('pageview_today_adjust');?>" value="<?php echo esc_attr($instance['pageview_today_adjust']); ?>">
     110                        <input class="widefat" type="text" name="<?php echo $this->get_field_name('pageview_today_adjust');?>" value="<?php echo esc_attr($instance['pageview_today_adjust']); ?>" onkeyup="value=value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
    109111                    </td>
    110112                </tr>
     
    113115                        <input class="" type="checkbox" value="yes" name="<?php echo $this->get_field_name('pageview_all_show');?>" <?php checked('yes',$instance['pageview_all_show'])?>>
    114116                    </td>
    115                     <td><label><?php echo $this->def_val['pageview_all_label']?></label></td>
     117                    <td align="left">
     118                        <label><?php echo $this->def_val['pageview_all_label']?></label>
     119                    </td>
    116120                    <td>
    117121                        <input class="widefat" type="text" name="<?php echo $this->get_field_name('pageview_all_label');?>" value="<?php echo esc_attr($instance['pageview_all_label']); ?>">
    118122                    </td>
    119123                    <td width="*">
    120                         <input class="widefat" type="number" name="<?php echo $this->get_field_name('pageview_all_adjust');?>" value="<?php echo esc_attr($instance['pageview_all_adjust']); ?>">
     124                        <input class="widefat" type="text" name="<?php echo $this->get_field_name('pageview_all_adjust');?>" value="<?php echo esc_attr($instance['pageview_all_adjust']); ?>" onkeyup="value=value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
    121125                    </td>
    122126                </tr>
     
    125129                        <input class="" type="checkbox" value="yes" name="<?php echo $this->get_field_name('visit_today_show');?>" <?php checked('yes',$instance['visit_today_show'])?>>
    126130                    </td>
    127                     <td><label><?php echo $this->def_val['visit_today_label']?></label></td>
     131                    <td align="left">
     132                        <label><?php echo $this->def_val['visit_today_label']?></label>
     133                    </td>
    128134                    <td>
    129135                        <input class="widefat" type="text" name="<?php echo $this->get_field_name('visit_today_label');?>" value="<?php echo esc_attr($instance['visit_today_label']); ?>">
    130136                    </td>
    131137                    <td width="*">
    132                         <input class="widefat" type="number" name="<?php echo $this->get_field_name('visit_today_adjust');?>" value="<?php echo esc_attr($instance['visit_today_adjust']); ?>">
     138                        <input class="widefat" type="text" name="<?php echo $this->get_field_name('visit_today_adjust');?>" value="<?php echo esc_attr($instance['visit_today_adjust']); ?>" onkeyup="value=value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
    133139                    </td>
    134140                </tr>
     
    137143                        <input class="" type="checkbox" value="yes" name="<?php echo $this->get_field_name('visit_all_show');?>" <?php checked('yes',$instance['visit_all_show'])?>>
    138144                    </td>
    139                     <td><label><?php echo $this->def_val['visit_all_label']?></label></td>
     145                    <td align="left">
     146                        <label><?php echo $this->def_val['visit_all_label']?></label>
     147                    </td>
    140148                    <td>
    141149                        <input class="widefat" type="text" name="<?php echo $this->get_field_name('visit_all_label');?>" value="<?php echo esc_attr($instance['visit_all_label']); ?>">
    142150                    </td>
    143151                    <td width="*">
    144                         <input class="widefat" type="number" name="<?php echo $this->get_field_name('visit_all_adjust');?>" value="<?php echo esc_attr($instance['visit_all_adjust']); ?>">
     152                        <input class="widefat" type="text" name="<?php echo $this->get_field_name('visit_all_adjust');?>" value="<?php echo esc_attr($instance['visit_all_adjust']); ?>" onkeyup="value=value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
    145153                    </td>
    146154                </tr>
     
    173181
    174182        //clear transient
    175         delete_transient('siga4w_get_today_cache');
    176         delete_transient('siga4w_get_all_cache');
     183        siga4w_del_cache();
    177184
    178185        return $instance;
     
    215222            }
    216223
    217             $content .= sprintf( $pageview_today_label, ($nums['pageview_today'] += (int)$pageview_today_adjust) );
     224            $content .= sprintf( $pageview_today_label, number_format($nums['pageview_today'] += (int)$pageview_today_adjust) );
    218225        }
    219226
     
    225232            }
    226233
    227             $content .= sprintf( $pageview_all_label, ($nums['pageview_all'] += (int)$pageview_all_adjust) );
     234            $content .= sprintf( $pageview_all_label, number_format($nums['pageview_all'] += (int)$pageview_all_adjust) );
    228235        }
    229236
     
    235242            }
    236243
    237             $content .= sprintf( $visit_today_label, ($nums['visit_today'] += (int)$visit_today_adjust) );
     244            $content .= sprintf( $visit_today_label, number_format($nums['visit_today'] += (int)$visit_today_adjust) );
    238245        }
    239246
     
    245252            }
    246253
    247             $content .= sprintf( $visit_all_label, ($nums['visit_all'] += (int)$visit_all_adjust) );
     254            $content .= sprintf( $visit_all_label, number_format($nums['visit_all'] += (int)$visit_all_adjust) );
    248255        }
    249256
  • sig-ga4-widget/trunk/inc/helper.php

    r2796009 r2798094  
    131131
    132132/**
     133 *  @since 1.0.1
     134 */
     135function siga4w_del_cache(){
     136    delete_transient('siga4w_get_today_cache');
     137    delete_transient('siga4w_get_all_cache');
     138}
     139
     140/**
    133141 *  Add log
    134142 */
  • sig-ga4-widget/trunk/inc/page_setting.php

    r2795994 r2798094  
    6565                    </table>
    6666
    67                     <h2 class="title"><?php _e( 'Post pageviews', 'sig-ga4-widget' )?></h2>
     67                    <h2 class="title"><?php _e( 'Post pageviews', 'sig-ga4-widget' )?>&nbsp;<span style="font-size: 13px;"><?php _e( '( Notice! Each post will call the api once. )', 'sig-ga4-widget' )?></span></h2>
     68
    6869                    <table class="form-table">
    6970
     
    9293                        </tr>
    9394
     95                        <tr valign="top">
     96                            <th scope="row"><?php _e( 'Position', 'sig-ga4-widget' )?></th>
     97                            <td>
     98                                <?php $post_pv_pos = ( !empty($this->options['post_pv_pos']) ) ? $this->options['post_pv_pos']:''; ?>
     99                                <select size="1" name="<?php echo SIGA4W_OPTION."[post_pv_pos]"?>">
     100                                    <option value="top-left" <?php selected( 'top-left', $post_pv_pos );?>><?php _e( 'Top Left', 'sig-ga4-widget' ); ?>&nbsp;(↖)</option>
     101                                    <option value="top-center" <?php selected( 'top-center', $post_pv_pos );?>><?php _e( 'Top Center', 'sig-ga4-widget' ); ?>&nbsp;(↑)</option>
     102                                    <option value="top-right" <?php selected( 'top-right', $post_pv_pos );?>><?php _e( 'Top Right', 'sig-ga4-widget' ); ?>&nbsp;(↗)</option>
     103                                    <option value="bottom-left" <?php selected( 'bottom-left', $post_pv_pos );?>><?php _e( 'Bottom Left', 'sig-ga4-widget' ); ?>&nbsp;(↙)</option>
     104                                    <option value="bottom-center" <?php selected( 'bottom-center', $post_pv_pos );?>><?php _e( 'Bottom Center', 'sig-ga4-widget' ); ?>&nbsp;(↓)</option>
     105                                    <option value="bottom-right" <?php selected( 'bottom-right', $post_pv_pos );?>><?php _e( 'Bottom Right', 'sig-ga4-widget' ); ?>&nbsp;(↘)</option>
     106                                </select>
     107                            </td>
     108                        </tr>
     109
    94110
    95111                    </table>
     
    109125
    110126                    <h2><?php _e( 'How to setup:', 'sig-ga4-widget' ); ?></h2>
    111                     <ol style="font-size: 15px;">
     127                    <ol>
    112128                        <li>登入 https://console.cloud.google.com/apis/ 。點左側選單<b>「已啟用的API和服務」</b>:啟用「Google Analytics Data API」服務(已啟用過的就不需此步驟)。</li>
    113129                        <li>點左側選單<b>「憑證」</b>:點<b>「+建立憑證」</b> -> 選<b>「服務帳戶」</b>(輸入服務帳戶名稱、服務帳戶ID,並記住該員電子郵件地址,點<b>「建立並繼續」</b>到下一步)。</li>
  • sig-ga4-widget/trunk/inc/page_show.php

    r2795994 r2798094  
    1616            ?>
    1717            <h3><?php _e( 'Current month', 'sig-ga4-widget' ) ?></h3>
    18             <div id="ga4_daily_chart" style="width:100%;height: 250px;background-color: #fff;"><?php
     18            <div id="ga4_daily_chart"><?php
    1919                if( !empty($theMonth['message']) ) echo esc_html($theMonth['message']);
    2020            ?></div>
     
    3535            ?>
    3636            <h3><?php _e( 'Current year' , 'sig-ga4-widget' ) ?></h3>
    37             <div id="ga4_month_chart" style="width:100%;height: 250px;background-color: #fff;"><?php
     37            <div id="ga4_month_chart"><?php
    3838                if( !empty($theYear['message']) ) echo esc_html($theYear['message']);
    3939            ?></div>
     
    8585</div>
    8686
     87<style type="text/css">
     88#ga4_daily_chart, #ga4_month_chart{ width:100%;height: 250px;background-color: #fff;border:1px solid #c3c4c7;margin-bottom: 10px; }
     89</style>
    8790
    8891<script type="text/javascript">
     
    100103    }
    101104?>
    102     new Morris.Line({
     105    new Morris.Area({
    103106        element: 'ga4_daily_chart',
    104107        data: <?php echo json_encode($days); ?>,
     108        behaveLikeLine: true,
    105109        xkey: 'x',
    106110        xLabels: 'day',
     
    109113        },
    110114        ykeys: ['a','b'],
    111         labels: ['Pageviews','Visits'],
    112         fillOpacity: 1.0,
     115        labels: ['<?php _e( 'pageviews', 'sig-ga4-widget' )?>','<?php _e( 'visits', 'sig-ga4-widget' )?>'],
     116        fillOpacity: 0.6,
     117        lineColors: ['#7be3f3','#17a2b8'],
    113118        resize: true
    114119    });
     
    129134
    130135?>
    131     new Morris.Line({
     136    new Morris.Area({
    132137        element: 'ga4_month_chart',
    133138        data: <?php echo json_encode($months); ?>,
     139        behaveLikeLine: true,
    134140        xkey: 'x',
    135141        xLabels: 'month',
     
    138144        },
    139145        ykeys: ['a','b'],
    140         labels: ['Pageview','Visits'],
    141         fillOpacity: 1.0,
     146        labels: ['<?php _e( 'pageviews', 'sig-ga4-widget' )?>','<?php _e( 'visits', 'sig-ga4-widget' )?>'],
     147        fillOpacity: 0.6,
     148        lineColors: ['#7be3f3','#17a2b8'],
    142149        resize: true
    143150    });
  • sig-ga4-widget/trunk/languages/sig-ga4-widget.pot

    r2795994 r2798094  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Sig GA4 Widget 1.0\n"
     5"Project-Id-Version: Sig GA4 Widget 1.0.1\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/sig-ga4-widget\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2022-10-07T11:53:25+08:00\n"
     12"POT-Creation-Date: 2022-10-13T11:04:51+08:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.6.0\n"
     
    4747msgstr ""
    4848
    49 #. translators: %d is today pageviews
     49#. translators: %s is today pageviews
    5050#: classes/widget.php:25
    51 msgid "Today pageviews: %d<br>"
    52 msgstr ""
    53 
    54 #. translators: %d is tatal pageviews
     51msgid "Today pageviews: %s<br>"
     52msgstr ""
     53
     54#. translators: %s is tatal pageviews
    5555#: classes/widget.php:30
    56 msgid "Total pageviews: %d<br>"
    57 msgstr ""
    58 
    59 #. translators: %d is today visits
     56msgid "Total pageviews: %s<br>"
     57msgstr ""
     58
     59#. translators: %s is today visits
    6060#: classes/widget.php:37
    61 msgid "Today visits: %d<br>"
    62 msgstr ""
    63 
    64 #. translators: %d is total visits
     61msgid "Today visits: %s<br>"
     62msgstr ""
     63
     64#. translators: %s is total visits
    6565#: classes/widget.php:43
    66 msgid "Total visits: %d<br>"
     66msgid "Total visits: %s<br>"
    6767msgstr ""
    6868
     
    9191msgstr ""
    9292
    93 #: classes/widget.php:194
     93#: classes/widget.php:201
    9494msgid "No matching record found."
    9595msgstr ""
     
    141141msgstr ""
    142142
    143 #: inc/page_setting.php:71
     143#: inc/page_setting.php:67
     144msgid "( Notice! Each post will call the api once. )"
     145msgstr ""
     146
     147#: inc/page_setting.php:72
    144148msgid "Pageview label text"
    145149msgstr ""
    146150
    147 #: inc/page_setting.php:74
     151#: inc/page_setting.php:75
    148152msgid "Default label"
    149153msgstr ""
    150154
    151 #: inc/page_setting.php:81
     155#: inc/page_setting.php:82
    152156msgid "Show on"
    153157msgstr ""
    154158
    155 #: inc/page_setting.php:107
     159#: inc/page_setting.php:96
     160msgid "Position"
     161msgstr ""
     162
     163#: inc/page_setting.php:100
     164msgid "Top Left"
     165msgstr ""
     166
     167#: inc/page_setting.php:101
     168msgid "Top Center"
     169msgstr ""
     170
     171#: inc/page_setting.php:102
     172msgid "Top Right"
     173msgstr ""
     174
     175#: inc/page_setting.php:103
     176msgid "Bottom Left"
     177msgstr ""
     178
     179#: inc/page_setting.php:104
     180msgid "Bottom Center"
     181msgstr ""
     182
     183#: inc/page_setting.php:105
     184msgid "Bottom Right"
     185msgstr ""
     186
     187#: inc/page_setting.php:123
    156188msgid "Prompt:"
    157189msgstr ""
    158190
    159 #: inc/page_setting.php:108
     191#: inc/page_setting.php:124
    160192msgid "Caution! This plug-in uses the Google Analytics Data API, and there is a daily limit on the number of calls (50,000). If the number of requests exceeds, you may need to pay for it. (You can set the cache time in the settings to avoid exceeding the number of calls)"
    161193msgstr ""
    162194
    163 #: inc/page_setting.php:110
     195#: inc/page_setting.php:126
    164196msgid "How to setup:"
    165197msgstr ""
    166198
    167 #: inc/page_setting.php:116
    168 #: sig-ga4-widget.php:83
     199#: inc/page_setting.php:132
     200#: sig-ga4-widget.php:91
    169201msgid "GA4 widget config"
    170202msgstr ""
    171203
    172 #: inc/page_setting.php:130
     204#: inc/page_setting.php:146
    173205msgid "Are you sure you want to delete this file?"
    174206msgstr ""
     
    200232msgstr ""
    201233
    202 #. translators: %d is post pageviews.
    203 #: sig-ga4-widget.php:41
    204 msgid "Pageviews: %d"
    205 msgstr ""
    206 
    207 #: sig-ga4-widget.php:69
     234#: inc/page_show.php:115
     235#: inc/page_show.php:146
     236msgid "pageviews"
     237msgstr ""
     238
     239#: inc/page_show.php:115
     240#: inc/page_show.php:146
     241msgid "visits"
     242msgstr ""
     243
     244#. translators: %s is post pageviews.
     245#: sig-ga4-widget.php:46
     246msgid "Pageviews: %s"
     247msgstr ""
     248
     249#: sig-ga4-widget.php:77
    208250msgid "Settings"
    209251msgstr ""
    210252
    211 #: sig-ga4-widget.php:82
     253#: sig-ga4-widget.php:90
    212254msgid "GA4 charts"
    213255msgstr ""
    214256
    215 #: sig-ga4-widget.php:138
     257#: sig-ga4-widget.php:104
     258msgid "Please upload the json file and fill in the web property id."
     259msgstr ""
     260
     261#. translators: %1$s is error message, %2$s is status.
     262#: sig-ga4-widget.php:115
     263msgid "Error: %1$s<br>Status: %2$s"
     264msgstr ""
     265
     266#: sig-ga4-widget.php:176
    216267msgid "Only json files are allowed"
    217268msgstr ""
    218269
    219 #: sig-ga4-widget.php:244
     270#: sig-ga4-widget.php:308
    220271msgid "Not allow do this action"
    221272msgstr ""
  • sig-ga4-widget/trunk/readme.txt

    r2795994 r2798094  
    44Requires at least: 5.9
    55Tested up to: 6.0.2
    6 Stable tag: 1.0
     6Stable tag: 1.0.1
    77License: GPLv2 or later
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    1414Show your google analytics 4 visit data on your template widget.
    1515
    16 == Installation ==
     16= Automatic installation =
    1717
    18 This section describes how to install the plugin and get it working.
     181. Login your WordPress admin
     192. Click __Plugins__
     203. Click __Add New__
     214. Search for __Sig GA4 Widget__
     225. Click __Install Now__ under "Sig GA4 Widget"
     236. Activate the plugin
    1924
    20 e.g.
     25= Manual installation =
    2126
    22 1. Upload the plugin files to the `/wp-content/plugins/plugin-name` directory, or install the plugin through the WordPress plugins screen directly.
    23 1. Activate the plugin through the `Plugins` screen in WordPress.
    24 1. Go to `Settings` -> `GA4 widget config` to configure the plugin.
    25 1. Go to `Widget` setup your sidebar widget.
     271. Download the plugin
     282. Extract the contents of the zip file
     293. Upload the contents of the zip file to the `wp-content/plugins/` folder of your WordPress installation
     304. Activate the Sig GA4 Widget plugin from 'Plugins' page.
    2631
    2732== Screenshots ==
     
    3136== Changelog ==
    3237
     38= 1.0.1 =
     39* Add choose post pageview position.
     40
    3341= 1.0 =
    3442* Initial Public Release
  • sig-ga4-widget/trunk/sig-ga4-widget.php

    r2795994 r2798094  
    88Text Domain: sig-ga4-widget
    99Domain Path: /languages/
    10 Version: 1.0
     10Version: 1.0.1
    1111*/
    1212
    13 define( 'SIGA4W_VERSION', '1.0' );
     13define( 'SIGA4W_VERSION', '1.0.1' );
    1414define( 'SIGA4W_OPTION', '_siga4w_setting' );
    1515define( 'SIGA4W_OPTION_GROUP', '_siga4w_setting_group' );
     
    2323require_once( SIGA4W_DIR . '/vendor/autoload.php' );
    2424require_once( SIGA4W_DIR . '/inc/helper.php' );
     25require_once( SIGA4W_DIR . '/inc/upgrade.php' );
    2526
    2627new SIGA4W_init();
     
    3839        $this->options = get_option(SIGA4W_OPTION);
    3940
    40         /* translators: %d is post pageviews. */
    41         $this->def_pv_label = __( 'Pageviews: %d', 'sig-ga4-widget' );
     41        $upgrade = new SIGA4W_upgrade($this->options);
     42        $upgrade->run();
     43
     44
     45        /* translators: %s is post pageviews. */
     46        $this->def_pv_label = __( 'Pageviews: %s', 'sig-ga4-widget' );
    4247
    4348        add_filter( 'plugin_action_links_'.plugin_basename(__FILE__), [ $this , 'add_settings_link' ] );
    4449
     50        add_action( 'wp_enqueue_scripts', [ $this, 'add_wp_enqueues' ] );
     51
    4552        add_action( 'admin_menu', [ $this, 'add_admin_menu' ] );
    4653
    47         add_action( 'admin_enqueue_scripts', [ $this, 'add_enqueues' ] );
     54        add_action( 'admin_enqueue_scripts', [ $this, 'add_admin_enqueues' ] );
    4855
    4956        add_action( 'admin_init', [ $this, 'register_settings_fields' ] );
     
    6067            require_once( SIGA4W_DIR . '/classes/ga4.php' );
    6168        }
     69
    6270    }
    6371
     
    8896     */
    8997    public function cb_page_setting() {
     98
     99        if( empty($this->options['json_key']) or empty($this->options['property_id']) ){
     100
     101            add_settings_error(
     102                'siga4w-settings-notices',
     103                'settings_json_id',
     104                __( 'Please upload the json file and fill in the web property id.', 'sig-ga4-widget' ),
     105                'error'
     106            );
     107
     108        }else{
     109
     110            $test = siga4w_get_data();
     111
     112            if( !empty($test['message']) ){
     113                add_settings_error( 'siga4w-settings-notices', 'settings_test',
     114                    /* translators: %1$s is error message, %2$s is status. */
     115                    sprintf( __( 'Error: %1$s<br>Status: %2$s', 'sig-ga4-widget' ), $test['message'], (!empty($test['status']) ? $test['status']:'') ),
     116                    'error'
     117                );
     118            }
     119        }
     120
    90121        require_once( SIGA4W_DIR . '/inc/page_setting.php' );
    91122    }
     
    103134
    104135    /**
     136     *  Load jquery
     137     */
     138    public function add_wp_enqueues() {
     139        wp_enqueue_script( 'jquery' );
     140    }
     141
     142    /**
    105143     * Add style & script files
    106144     */
    107     public function add_enqueues($hook){
     145    public function add_admin_enqueues($hook){
    108146
    109147        if( in_array( $hook, array( 'settings_page_siga4w_setting', 'toplevel_page_siga4w_page' ) ) ) {
     
    162200            $option['cache_time'] = preg_replace('/[^\d]/', '', $option['cache_time']);
    163201
    164             $option['post_pv_label'] = siga4w_strip_tags($option['post_pv_label']);
    165         }
    166 
    167         delete_transient('siga4w_get_today_cache');
    168         delete_transient('siga4w_get_all_cache');
     202            $option['post_pv_label'] = strip_tags($option['post_pv_label']);
     203            $option['post_pv_pos'] = strip_tags($option['post_pv_pos']);
     204        }
     205
     206        //clear transient
     207        siga4w_del_cache();
    169208
    170209        return $option;
     
    216255    /**
    217256     *  Add pageviews on post content
     257     *  @since 1.0.1 add option:post_pv_pos
    218258     */
    219259    public function add_post_pv($content) {
     
    224264
    225265                $pv_label = ( !empty($this->options['post_pv_label']) ) ? $this->options['post_pv_label'] : $this->def_pv_label;
    226 
    227                 $content = sprintf( $pv_label, $this->get_pageviews() ) . $content;
     266                $pv_label = sprintf( $pv_label, number_format($this->get_pageviews()) );
     267
     268                $pos = ( !empty($this->options['post_pv_pos']) ) ? $this->options['post_pv_pos'] : 'top-left';
     269                $pos = explode('-',$pos);
     270
     271                if( !empty($pos[1]) ){
     272                    switch ($pos[1]){
     273                        case 'center':
     274                            $pv_label = "<div style=\"text-align:center\">{$pv_label}</div>";
     275                        break;
     276                        case 'right':
     277                            $pv_label = "<div style=\"text-align:right\">{$pv_label}</div>";
     278                        break;
     279                        default:
     280                            $pv_label = "<div style=\"text-align:left\">{$pv_label}</div>";
     281                        break;
     282                    }
     283                }else{
     284                    $pv_label = "<div>{$pv_label}</div>";
     285                }
     286
     287                if( isset($pos[0]) && $pos[0] == 'bottom' ){
     288                    $content = $content . $pv_label;
     289                }else{
     290                    $content = $pv_label . $content;
     291                }
    228292            }
    229293        }
Note: See TracChangeset for help on using the changeset viewer.