Changeset 2798094
- Timestamp:
- 10/13/2022 03:29:38 AM (3 years ago)
- Location:
- sig-ga4-widget/trunk
- Files:
-
- 3 added
- 7 edited
-
classes/widget.php (modified) (13 diffs)
-
inc/helper.php (modified) (1 diff)
-
inc/page_setting.php (modified) (3 diffs)
-
inc/page_show.php (modified) (7 diffs)
-
inc/upgrade.php (added)
-
languages/sig-ga4-widget-zh_TW.mo (added)
-
languages/sig-ga4-widget-zh_TW.po (added)
-
languages/sig-ga4-widget.pot (modified) (6 diffs)
-
readme.txt (modified) (3 diffs)
-
sig-ga4-widget.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sig-ga4-widget/trunk/classes/widget.php
r2795994 r2798094 22 22 'title' => __( 'Browsing Statistics', 'sig-ga4-widget' ), 23 23 'pageview' => [ 24 'today' => [ /* translators: % dis 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' ), 26 26 'show' => 'yes', 27 27 'adjust' => 0 28 28 ], 29 'all' => [ /* translators: % dis 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' ), 31 31 'show' => 'yes', 32 32 'adjust' => 0 … … 34 34 ], 35 35 'visit' => [ 36 'today' => [ /* translators: % dis 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' ), 38 38 'show' => '', 39 39 'adjust' => 0 40 40 ], 41 41 'all' => [ 42 /* translators: % dis 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' ), 44 44 'show' => '', 45 45 'adjust' => 0 … … 86 86 <p> 87 87 <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;} 89 89 table.siga4w td{ border:1px solid #eee;padding: 2px 10px;} 90 90 </style> … … 92 92 <table class="siga4w"> 93 93 <tr align="center"> 94 <td width=" 60"><label><?php _e( 'Show', 'sig-ga4-widget' ); ?></label></td>95 <td width="1 50"><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> 98 98 </tr> 99 99 <tr align="center"> … … 101 101 <input class="" type="checkbox" value="yes" name="<?php echo $this->get_field_name('pageview_today_show');?>" <?php checked('yes',$instance['pageview_today_show'])?>> 102 102 </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> 104 106 <td> 105 107 <input class="widefat" type="text" name="<?php echo $this->get_field_name('pageview_today_label');?>" value="<?php echo esc_attr($instance['pageview_today_label']); ?>"> 106 108 </td> 107 109 <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,''))"> 109 111 </td> 110 112 </tr> … … 113 115 <input class="" type="checkbox" value="yes" name="<?php echo $this->get_field_name('pageview_all_show');?>" <?php checked('yes',$instance['pageview_all_show'])?>> 114 116 </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> 116 120 <td> 117 121 <input class="widefat" type="text" name="<?php echo $this->get_field_name('pageview_all_label');?>" value="<?php echo esc_attr($instance['pageview_all_label']); ?>"> 118 122 </td> 119 123 <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,''))"> 121 125 </td> 122 126 </tr> … … 125 129 <input class="" type="checkbox" value="yes" name="<?php echo $this->get_field_name('visit_today_show');?>" <?php checked('yes',$instance['visit_today_show'])?>> 126 130 </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> 128 134 <td> 129 135 <input class="widefat" type="text" name="<?php echo $this->get_field_name('visit_today_label');?>" value="<?php echo esc_attr($instance['visit_today_label']); ?>"> 130 136 </td> 131 137 <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,''))"> 133 139 </td> 134 140 </tr> … … 137 143 <input class="" type="checkbox" value="yes" name="<?php echo $this->get_field_name('visit_all_show');?>" <?php checked('yes',$instance['visit_all_show'])?>> 138 144 </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> 140 148 <td> 141 149 <input class="widefat" type="text" name="<?php echo $this->get_field_name('visit_all_label');?>" value="<?php echo esc_attr($instance['visit_all_label']); ?>"> 142 150 </td> 143 151 <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,''))"> 145 153 </td> 146 154 </tr> … … 173 181 174 182 //clear transient 175 delete_transient('siga4w_get_today_cache'); 176 delete_transient('siga4w_get_all_cache'); 183 siga4w_del_cache(); 177 184 178 185 return $instance; … … 215 222 } 216 223 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) ); 218 225 } 219 226 … … 225 232 } 226 233 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) ); 228 235 } 229 236 … … 235 242 } 236 243 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) ); 238 245 } 239 246 … … 245 252 } 246 253 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) ); 248 255 } 249 256 -
sig-ga4-widget/trunk/inc/helper.php
r2796009 r2798094 131 131 132 132 /** 133 * @since 1.0.1 134 */ 135 function siga4w_del_cache(){ 136 delete_transient('siga4w_get_today_cache'); 137 delete_transient('siga4w_get_all_cache'); 138 } 139 140 /** 133 141 * Add log 134 142 */ -
sig-ga4-widget/trunk/inc/page_setting.php
r2795994 r2798094 65 65 </table> 66 66 67 <h2 class="title"><?php _e( 'Post pageviews', 'sig-ga4-widget' )?></h2> 67 <h2 class="title"><?php _e( 'Post pageviews', 'sig-ga4-widget' )?> <span style="font-size: 13px;"><?php _e( '( Notice! Each post will call the api once. )', 'sig-ga4-widget' )?></span></h2> 68 68 69 <table class="form-table"> 69 70 … … 92 93 </tr> 93 94 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' ); ?> (↖)</option> 101 <option value="top-center" <?php selected( 'top-center', $post_pv_pos );?>><?php _e( 'Top Center', 'sig-ga4-widget' ); ?> (↑)</option> 102 <option value="top-right" <?php selected( 'top-right', $post_pv_pos );?>><?php _e( 'Top Right', 'sig-ga4-widget' ); ?> (↗)</option> 103 <option value="bottom-left" <?php selected( 'bottom-left', $post_pv_pos );?>><?php _e( 'Bottom Left', 'sig-ga4-widget' ); ?> (↙)</option> 104 <option value="bottom-center" <?php selected( 'bottom-center', $post_pv_pos );?>><?php _e( 'Bottom Center', 'sig-ga4-widget' ); ?> (↓)</option> 105 <option value="bottom-right" <?php selected( 'bottom-right', $post_pv_pos );?>><?php _e( 'Bottom Right', 'sig-ga4-widget' ); ?> (↘)</option> 106 </select> 107 </td> 108 </tr> 109 94 110 95 111 </table> … … 109 125 110 126 <h2><?php _e( 'How to setup:', 'sig-ga4-widget' ); ?></h2> 111 <ol style="font-size: 15px;">127 <ol> 112 128 <li>登入 https://console.cloud.google.com/apis/ 。點左側選單<b>「已啟用的API和服務」</b>:啟用「Google Analytics Data API」服務(已啟用過的就不需此步驟)。</li> 113 129 <li>點左側選單<b>「憑證」</b>:點<b>「+建立憑證」</b> -> 選<b>「服務帳戶」</b>(輸入服務帳戶名稱、服務帳戶ID,並記住該員電子郵件地址,點<b>「建立並繼續」</b>到下一步)。</li> -
sig-ga4-widget/trunk/inc/page_show.php
r2795994 r2798094 16 16 ?> 17 17 <h3><?php _e( 'Current month', 'sig-ga4-widget' ) ?></h3> 18 <div id="ga4_daily_chart" style="width:100%;height: 250px;background-color: #fff;"><?php18 <div id="ga4_daily_chart"><?php 19 19 if( !empty($theMonth['message']) ) echo esc_html($theMonth['message']); 20 20 ?></div> … … 35 35 ?> 36 36 <h3><?php _e( 'Current year' , 'sig-ga4-widget' ) ?></h3> 37 <div id="ga4_month_chart" style="width:100%;height: 250px;background-color: #fff;"><?php37 <div id="ga4_month_chart"><?php 38 38 if( !empty($theYear['message']) ) echo esc_html($theYear['message']); 39 39 ?></div> … … 85 85 </div> 86 86 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> 87 90 88 91 <script type="text/javascript"> … … 100 103 } 101 104 ?> 102 new Morris. Line({105 new Morris.Area({ 103 106 element: 'ga4_daily_chart', 104 107 data: <?php echo json_encode($days); ?>, 108 behaveLikeLine: true, 105 109 xkey: 'x', 106 110 xLabels: 'day', … … 109 113 }, 110 114 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'], 113 118 resize: true 114 119 }); … … 129 134 130 135 ?> 131 new Morris. Line({136 new Morris.Area({ 132 137 element: 'ga4_month_chart', 133 138 data: <?php echo json_encode($months); ?>, 139 behaveLikeLine: true, 134 140 xkey: 'x', 135 141 xLabels: 'month', … … 138 144 }, 139 145 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'], 142 149 resize: true 143 150 }); -
sig-ga4-widget/trunk/languages/sig-ga4-widget.pot
r2795994 r2798094 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Sig GA4 Widget 1.0 \n"5 "Project-Id-Version: Sig GA4 Widget 1.0.1\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/sig-ga4-widget\n" 7 7 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" … … 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "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" 13 13 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 14 "X-Generator: WP-CLI 2.6.0\n" … … 47 47 msgstr "" 48 48 49 #. translators: % dis today pageviews49 #. translators: %s is today pageviews 50 50 #: classes/widget.php:25 51 msgid "Today pageviews: % d<br>"52 msgstr "" 53 54 #. translators: % dis tatal pageviews51 msgid "Today pageviews: %s<br>" 52 msgstr "" 53 54 #. translators: %s is tatal pageviews 55 55 #: classes/widget.php:30 56 msgid "Total pageviews: % d<br>"57 msgstr "" 58 59 #. translators: % dis today visits56 msgid "Total pageviews: %s<br>" 57 msgstr "" 58 59 #. translators: %s is today visits 60 60 #: classes/widget.php:37 61 msgid "Today visits: % d<br>"62 msgstr "" 63 64 #. translators: % dis total visits61 msgid "Today visits: %s<br>" 62 msgstr "" 63 64 #. translators: %s is total visits 65 65 #: classes/widget.php:43 66 msgid "Total visits: % d<br>"66 msgid "Total visits: %s<br>" 67 67 msgstr "" 68 68 … … 91 91 msgstr "" 92 92 93 #: classes/widget.php: 19493 #: classes/widget.php:201 94 94 msgid "No matching record found." 95 95 msgstr "" … … 141 141 msgstr "" 142 142 143 #: inc/page_setting.php:71 143 #: inc/page_setting.php:67 144 msgid "( Notice! Each post will call the api once. )" 145 msgstr "" 146 147 #: inc/page_setting.php:72 144 148 msgid "Pageview label text" 145 149 msgstr "" 146 150 147 #: inc/page_setting.php:7 4151 #: inc/page_setting.php:75 148 152 msgid "Default label" 149 153 msgstr "" 150 154 151 #: inc/page_setting.php:8 1155 #: inc/page_setting.php:82 152 156 msgid "Show on" 153 157 msgstr "" 154 158 155 #: inc/page_setting.php:107 159 #: inc/page_setting.php:96 160 msgid "Position" 161 msgstr "" 162 163 #: inc/page_setting.php:100 164 msgid "Top Left" 165 msgstr "" 166 167 #: inc/page_setting.php:101 168 msgid "Top Center" 169 msgstr "" 170 171 #: inc/page_setting.php:102 172 msgid "Top Right" 173 msgstr "" 174 175 #: inc/page_setting.php:103 176 msgid "Bottom Left" 177 msgstr "" 178 179 #: inc/page_setting.php:104 180 msgid "Bottom Center" 181 msgstr "" 182 183 #: inc/page_setting.php:105 184 msgid "Bottom Right" 185 msgstr "" 186 187 #: inc/page_setting.php:123 156 188 msgid "Prompt:" 157 189 msgstr "" 158 190 159 #: inc/page_setting.php:1 08191 #: inc/page_setting.php:124 160 192 msgid "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)" 161 193 msgstr "" 162 194 163 #: inc/page_setting.php:1 10195 #: inc/page_setting.php:126 164 196 msgid "How to setup:" 165 197 msgstr "" 166 198 167 #: inc/page_setting.php:1 16168 #: sig-ga4-widget.php: 83199 #: inc/page_setting.php:132 200 #: sig-ga4-widget.php:91 169 201 msgid "GA4 widget config" 170 202 msgstr "" 171 203 172 #: inc/page_setting.php:1 30204 #: inc/page_setting.php:146 173 205 msgid "Are you sure you want to delete this file?" 174 206 msgstr "" … … 200 232 msgstr "" 201 233 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 236 msgid "pageviews" 237 msgstr "" 238 239 #: inc/page_show.php:115 240 #: inc/page_show.php:146 241 msgid "visits" 242 msgstr "" 243 244 #. translators: %s is post pageviews. 245 #: sig-ga4-widget.php:46 246 msgid "Pageviews: %s" 247 msgstr "" 248 249 #: sig-ga4-widget.php:77 208 250 msgid "Settings" 209 251 msgstr "" 210 252 211 #: sig-ga4-widget.php: 82253 #: sig-ga4-widget.php:90 212 254 msgid "GA4 charts" 213 255 msgstr "" 214 256 215 #: sig-ga4-widget.php:138 257 #: sig-ga4-widget.php:104 258 msgid "Please upload the json file and fill in the web property id." 259 msgstr "" 260 261 #. translators: %1$s is error message, %2$s is status. 262 #: sig-ga4-widget.php:115 263 msgid "Error: %1$s<br>Status: %2$s" 264 msgstr "" 265 266 #: sig-ga4-widget.php:176 216 267 msgid "Only json files are allowed" 217 268 msgstr "" 218 269 219 #: sig-ga4-widget.php: 244270 #: sig-ga4-widget.php:308 220 271 msgid "Not allow do this action" 221 272 msgstr "" -
sig-ga4-widget/trunk/readme.txt
r2795994 r2798094 4 4 Requires at least: 5.9 5 5 Tested up to: 6.0.2 6 Stable tag: 1.0 6 Stable tag: 1.0.1 7 7 License: GPLv2 or later 8 8 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 14 14 Show your google analytics 4 visit data on your template widget. 15 15 16 = = Installation ==16 = Automatic installation = 17 17 18 This section describes how to install the plugin and get it working. 18 1. Login your WordPress admin 19 2. Click __Plugins__ 20 3. Click __Add New__ 21 4. Search for __Sig GA4 Widget__ 22 5. Click __Install Now__ under "Sig GA4 Widget" 23 6. Activate the plugin 19 24 20 e.g. 25 = Manual installation = 21 26 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.27 1. Download the plugin 28 2. Extract the contents of the zip file 29 3. Upload the contents of the zip file to the `wp-content/plugins/` folder of your WordPress installation 30 4. Activate the Sig GA4 Widget plugin from 'Plugins' page. 26 31 27 32 == Screenshots == … … 31 36 == Changelog == 32 37 38 = 1.0.1 = 39 * Add choose post pageview position. 40 33 41 = 1.0 = 34 42 * Initial Public Release -
sig-ga4-widget/trunk/sig-ga4-widget.php
r2795994 r2798094 8 8 Text Domain: sig-ga4-widget 9 9 Domain Path: /languages/ 10 Version: 1.0 10 Version: 1.0.1 11 11 */ 12 12 13 define( 'SIGA4W_VERSION', '1.0 ' );13 define( 'SIGA4W_VERSION', '1.0.1' ); 14 14 define( 'SIGA4W_OPTION', '_siga4w_setting' ); 15 15 define( 'SIGA4W_OPTION_GROUP', '_siga4w_setting_group' ); … … 23 23 require_once( SIGA4W_DIR . '/vendor/autoload.php' ); 24 24 require_once( SIGA4W_DIR . '/inc/helper.php' ); 25 require_once( SIGA4W_DIR . '/inc/upgrade.php' ); 25 26 26 27 new SIGA4W_init(); … … 38 39 $this->options = get_option(SIGA4W_OPTION); 39 40 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' ); 42 47 43 48 add_filter( 'plugin_action_links_'.plugin_basename(__FILE__), [ $this , 'add_settings_link' ] ); 44 49 50 add_action( 'wp_enqueue_scripts', [ $this, 'add_wp_enqueues' ] ); 51 45 52 add_action( 'admin_menu', [ $this, 'add_admin_menu' ] ); 46 53 47 add_action( 'admin_enqueue_scripts', [ $this, 'add_ enqueues' ] );54 add_action( 'admin_enqueue_scripts', [ $this, 'add_admin_enqueues' ] ); 48 55 49 56 add_action( 'admin_init', [ $this, 'register_settings_fields' ] ); … … 60 67 require_once( SIGA4W_DIR . '/classes/ga4.php' ); 61 68 } 69 62 70 } 63 71 … … 88 96 */ 89 97 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 90 121 require_once( SIGA4W_DIR . '/inc/page_setting.php' ); 91 122 } … … 103 134 104 135 /** 136 * Load jquery 137 */ 138 public function add_wp_enqueues() { 139 wp_enqueue_script( 'jquery' ); 140 } 141 142 /** 105 143 * Add style & script files 106 144 */ 107 public function add_ enqueues($hook){145 public function add_admin_enqueues($hook){ 108 146 109 147 if( in_array( $hook, array( 'settings_page_siga4w_setting', 'toplevel_page_siga4w_page' ) ) ) { … … 162 200 $option['cache_time'] = preg_replace('/[^\d]/', '', $option['cache_time']); 163 201 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(); 169 208 170 209 return $option; … … 216 255 /** 217 256 * Add pageviews on post content 257 * @since 1.0.1 add option:post_pv_pos 218 258 */ 219 259 public function add_post_pv($content) { … … 224 264 225 265 $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 } 228 292 } 229 293 }
Note: See TracChangeset
for help on using the changeset viewer.