Post Views Counter - Version 1.3.3

Version Description

  • Fix: PHP Notice: Trying to get property 'colors' of non-object
  • Fix: PHP Notice: register_rest_route was called incorrectly
Download this release

Release Info

Developer dfactory
Plugin Icon 128x128 Post Views Counter
Version 1.3.3
Comparing to
See all releases

Code changes from version 1.3.2.1 to 1.3.3

includes/columns.php CHANGED
@@ -50,7 +50,7 @@ class Post_Views_Counter_Columns {
50
  '__block_editor_compatible_meta_box' => true
51
  ) );
52
  }
53
-
54
  /**
55
  * Register REST API Gutenberg endpoints.
56
  */
@@ -60,9 +60,10 @@ class Post_Views_Counter_Columns {
60
  'post-views-counter',
61
  '/update-post-views/',
62
  array(
63
- 'methods' => array( 'POST' ),
64
- 'callback' => array( $this, 'gutenberg_update_callback' ),
65
- 'args' => array(
 
66
  'id' => array(
67
  'sanitize_callback' => 'absint',
68
  )
@@ -70,7 +71,25 @@ class Post_Views_Counter_Columns {
70
  )
71
  );
72
  }
73
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  /**
75
  * REST API Callback for Gutenberg endpoint.
76
  *
@@ -96,9 +115,7 @@ class Post_Views_Counter_Columns {
96
  return wp_send_json_error( __( 'You are not allowed to edit this item.', 'post-views-counter' ) );
97
 
98
  // break if views editing is restricted
99
- $restrict = (bool) Post_Views_Counter()->options['general']['restrict_edit_views'];
100
-
101
- if ( $restrict === true && ! current_user_can( apply_filters( 'pvc_restrict_edit_capability', 'manage_options' ) ) )
102
  return wp_send_json_error( __( 'You are not allowed to edit this item.', 'post-views-counter' ) );
103
 
104
  global $wpdb;
50
  '__block_editor_compatible_meta_box' => true
51
  ) );
52
  }
53
+
54
  /**
55
  * Register REST API Gutenberg endpoints.
56
  */
60
  'post-views-counter',
61
  '/update-post-views/',
62
  array(
63
+ 'methods' => array( 'POST' ),
64
+ 'callback' => array( $this, 'gutenberg_update_callback' ),
65
+ 'permission_callback' => array( $this, 'check_rest_route_permissions' ),
66
+ 'args' => array(
67
  'id' => array(
68
  'sanitize_callback' => 'absint',
69
  )
71
  )
72
  );
73
  }
74
+
75
+ /**
76
+ * Check whether user has permissions to perform post views update in Gutenberg editor.
77
+ *
78
+ * @param object $request WP_REST_Request
79
+ * @return bool|WP_Error
80
+ */
81
+ public function check_rest_route_permissions( $request ) {
82
+ // break if current user can't edit this post
83
+ if ( ! current_user_can( 'edit_post', (int) $request->get_param( 'id' ) ) )
84
+ return new WP_Error( 'pvc-user-not-allowed', __( 'You are not allowed to edit this item.', 'post-views-counter' ) );
85
+
86
+ // break if views editing is restricted
87
+ if ( (bool) Post_Views_Counter()->options['general']['restrict_edit_views'] === true && ! current_user_can( apply_filters( 'pvc_restrict_edit_capability', 'manage_options' ) ) )
88
+ return new WP_Error( 'pvc-user-not-allowed', __( 'You are not allowed to edit this item.', 'post-views-counter' ) );
89
+
90
+ return true;
91
+ }
92
+
93
  /**
94
  * REST API Callback for Gutenberg endpoint.
95
  *
115
  return wp_send_json_error( __( 'You are not allowed to edit this item.', 'post-views-counter' ) );
116
 
117
  // break if views editing is restricted
118
+ if ( (bool) Post_Views_Counter()->options['general']['restrict_edit_views'] === true && ! current_user_can( apply_filters( 'pvc_restrict_edit_capability', 'manage_options' ) ) )
 
 
119
  return wp_send_json_error( __( 'You are not allowed to edit this item.', 'post-views-counter' ) );
120
 
121
  global $wpdb;
includes/counter.php CHANGED
@@ -727,8 +727,8 @@ class Post_Views_Counter_Counter {
727
 
728
  /**
729
  * Ensure an ip address is both a valid IP and does not fall within a private network range.
730
- *
731
- * @param $ip
732
  * @return bool
733
  */
734
  public function validate_user_ip( $ip ) {
@@ -740,15 +740,16 @@ class Post_Views_Counter_Counter {
740
 
741
  /**
742
  * Register REST API endpoints.
743
- *
744
  * @return void
745
  */
746
  public function rest_api_init() {
747
  // view post route
748
  register_rest_route( 'post-views-counter', '/view-post/', array(
749
- 'methods' => array( 'GET', 'POST' ),
750
- 'callback' => array( $this, 'check_post_rest_api' ),
751
- 'args' => array(
 
752
  'id' => array(
753
  'default' => 0,
754
  'sanitize_callback' => 'absint'
@@ -772,7 +773,7 @@ class Post_Views_Counter_Counter {
772
 
773
  /**
774
  * Get post views via REST API request.
775
- *
776
  * @param array $request
777
  * @return int
778
  */
@@ -783,7 +784,17 @@ class Post_Views_Counter_Counter {
783
  }
784
 
785
  /**
786
- * Check if a given request has access to get views
 
 
 
 
 
 
 
 
 
 
787
  *
788
  * @param WP_REST_Request $request Full data about the request.
789
  * @return WP_Error|bool
@@ -791,5 +802,4 @@ class Post_Views_Counter_Counter {
791
  public function get_post_views_permissions_check( $request ) {
792
  return (bool) apply_filters( 'pvc_rest_api_get_post_views_check', true, $request );
793
  }
794
-
795
  }
727
 
728
  /**
729
  * Ensure an ip address is both a valid IP and does not fall within a private network range.
730
+ *
731
+ * @param $ip string IP address
732
  * @return bool
733
  */
734
  public function validate_user_ip( $ip ) {
740
 
741
  /**
742
  * Register REST API endpoints.
743
+ *
744
  * @return void
745
  */
746
  public function rest_api_init() {
747
  // view post route
748
  register_rest_route( 'post-views-counter', '/view-post/', array(
749
+ 'methods' => array( 'GET', 'POST' ),
750
+ 'callback' => array( $this, 'check_post_rest_api' ),
751
+ 'permission_callback' => array( $this, 'post_views_permissions_check' ),
752
+ 'args' => array(
753
  'id' => array(
754
  'default' => 0,
755
  'sanitize_callback' => 'absint'
773
 
774
  /**
775
  * Get post views via REST API request.
776
+ *
777
  * @param array $request
778
  * @return int
779
  */
784
  }
785
 
786
  /**
787
+ * Check if a given request has access to get views.
788
+ *
789
+ * @param WP_REST_Request $request Full data about the request.
790
+ * @return WP_Error|bool
791
+ */
792
+ public function post_views_permissions_check( $request ) {
793
+ return (bool) apply_filters( 'pvc_rest_api_post_views_check', true, $request );
794
+ }
795
+
796
+ /**
797
+ * Check if a given request has access to get views.
798
  *
799
  * @param WP_REST_Request $request Full data about the request.
800
  * @return WP_Error|bool
802
  public function get_post_views_permissions_check( $request ) {
803
  return (bool) apply_filters( 'pvc_rest_api_get_post_views_check', true, $request );
804
  }
 
805
  }
includes/dashboard.php CHANGED
@@ -157,12 +157,26 @@ class Post_Views_Counter_Dashboard {
157
  // $now = getdate( current_time( 'timestamp', get_option( 'gmt_offset' ) ) );
158
  $now = getdate( current_time( 'timestamp', get_option( 'gmt_offset' ) ) - 2592000 );
159
 
160
- // get admin color scheme
161
  global $_wp_admin_css_colors;
162
 
163
- $admin_color = get_user_option( 'admin_color' );
164
- $colors = $_wp_admin_css_colors[$admin_color]->colors;
165
- $color = $this->hex2rgb( $colors[2] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
 
167
  // set chart labels
168
  switch ( $period ) {
157
  // $now = getdate( current_time( 'timestamp', get_option( 'gmt_offset' ) ) );
158
  $now = getdate( current_time( 'timestamp', get_option( 'gmt_offset' ) ) - 2592000 );
159
 
160
+ // get color scheme global
161
  global $_wp_admin_css_colors;
162
 
163
+ // set default color;
164
+ $color = array(
165
+ 'r' => 105,
166
+ 'g' => 168,
167
+ 'b' => 187
168
+ );
169
+
170
+ if ( ! empty( $_wp_admin_css_colors ) ) {
171
+ // get current admin color scheme name
172
+ $current_color_scheme = get_user_option( 'admin_color' );
173
+
174
+ if ( empty( $current_color_scheme ) )
175
+ $current_color_scheme = 'fresh';
176
+
177
+ if ( isset( $_wp_admin_css_colors[$current_color_scheme] ) )
178
+ $color = $this->hex2rgb( $_wp_admin_css_colors[$current_color_scheme]->colors[2] );
179
+ }
180
 
181
  // set chart labels
182
  switch ( $period ) {
post-views-counter.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Post Views Counter
4
  Description: Post Views Counter allows you to display how many times a post, page or custom post type had been viewed in a simple, fast and reliable way.
5
- Version: 1.3.2
6
  Author: Digital Factory
7
  Author URI: http://www.dfactory.eu/
8
  Plugin URI: http://www.dfactory.eu/plugins/post-views-counter/
@@ -31,7 +31,7 @@ if ( ! class_exists( 'Post_Views_Counter' ) ) :
31
  * Post Views Counter final class.
32
  *
33
  * @class Post_Views_Counter
34
- * @version 1.3.2
35
  */
36
  final class Post_Views_Counter {
37
 
@@ -84,7 +84,7 @@ if ( ! class_exists( 'Post_Views_Counter' ) ) :
84
  'link_to_post' => true,
85
  'icon_class' => 'dashicons-chart-bar'
86
  ),
87
- 'version' => '1.3.2'
88
  );
89
 
90
  /**
2
  /*
3
  Plugin Name: Post Views Counter
4
  Description: Post Views Counter allows you to display how many times a post, page or custom post type had been viewed in a simple, fast and reliable way.
5
+ Version: 1.3.3
6
  Author: Digital Factory
7
  Author URI: http://www.dfactory.eu/
8
  Plugin URI: http://www.dfactory.eu/plugins/post-views-counter/
31
  * Post Views Counter final class.
32
  *
33
  * @class Post_Views_Counter
34
+ * @version 1.3.3
35
  */
36
  final class Post_Views_Counter {
37
 
84
  'link_to_post' => true,
85
  'icon_class' => 'dashicons-chart-bar'
86
  ),
87
+ 'version' => '1.3.3'
88
  );
89
 
90
  /**
readme.txt CHANGED
@@ -4,8 +4,8 @@ Donate link: http://dfactory.eu/
4
  Tags: counter, hits, posts, postviews, post views, views, count, statistics, stats, analytics, pageviews, tracking
5
  Requires at least: 4.0
6
  Requires PHP: 5.2.4
7
- Tested up to: 5.4.1
8
- Stable tag: 1.3.2.1
9
  License: MIT License
10
  License URI: http://opensource.org/licenses/MIT
11
 
@@ -62,8 +62,9 @@ No questions yet.
62
 
63
  == Changelog ==
64
 
65
- = 1.3.2.1 =
66
- * Fix: ChartJS file missing
 
67
 
68
  = 1.3.2 =
69
  * New: Introducing dashboard widget navigation
@@ -204,6 +205,6 @@ Initial release
204
 
205
  == Upgrade Notice ==
206
 
207
- = 1.3.2 =
208
- * New: Introducing dashboard widget navigation
209
- * New: Counter support for Media (attachments)
4
  Tags: counter, hits, posts, postviews, post views, views, count, statistics, stats, analytics, pageviews, tracking
5
  Requires at least: 4.0
6
  Requires PHP: 5.2.4
7
+ Tested up to: 5.5.3
8
+ Stable tag: 1.3.3
9
  License: MIT License
10
  License URI: http://opensource.org/licenses/MIT
11
 
62
 
63
  == Changelog ==
64
 
65
+ = 1.3.3 =
66
+ * Fix: PHP Notice: Trying to get property 'colors' of non-object
67
+ * Fix: PHP Notice: register_rest_route was called incorrectly
68
 
69
  = 1.3.2 =
70
  * New: Introducing dashboard widget navigation
205
 
206
  == Upgrade Notice ==
207
 
208
+ = 1.3.3 =
209
+ * Fix: PHP Notice: Trying to get property 'colors' of non-object
210
+ * Fix: PHP Notice: register_rest_route was called incorrectly