Version Description
- NEW: Automatically refresh Instagram access token before it expires
- NOTE: There are limitations to refresh access token for Instagram private accounts! You will need to reauthorize manually after access token expires
- Improved admin notices
Download this release
Release Info
Developer | WPZOOM |
Plugin | Instagram Widget by WPZOOM |
Version | 1.8.0 |
Comparing to | |
See all releases |
Code changes from version 1.7.7 to 1.8.0
- class-wpzoom-instagram-image-uploader.php +1 -1
- class-wpzoom-instagram-widget-api.php +125 -8
- class-wpzoom-instagram-widget-settings.php +29 -11
- instagram-widget-by-wpzoom.php +63 -27
- readme.txt +5 -0
class-wpzoom-instagram-image-uploader.php
CHANGED
@@ -99,7 +99,7 @@ class WPZOOM_Instagram_Image_Uploader {
|
|
99 |
* @return float|int
|
100 |
*/
|
101 |
function get_transient_lifetime() {
|
102 |
-
$options =
|
103 |
|
104 |
$values = array(
|
105 |
'minutes' => MINUTE_IN_SECONDS,
|
99 |
* @return float|int
|
100 |
*/
|
101 |
function get_transient_lifetime() {
|
102 |
+
$options = Wpzoom_Instagram_Widget_Settings::$settings;
|
103 |
|
104 |
$values = array(
|
105 |
'minutes' => MINUTE_IN_SECONDS,
|
class-wpzoom-instagram-widget-api.php
CHANGED
@@ -11,18 +11,21 @@ class Wpzoom_Instagram_Widget_API {
|
|
11 |
* @var Wpzoom_Instagram_Widget_API The reference to *Singleton* instance of this class
|
12 |
*/
|
13 |
private static $instance;
|
|
|
14 |
/**
|
15 |
* Request headers.
|
16 |
*
|
17 |
* @var array
|
18 |
*/
|
19 |
public $headers = array();
|
|
|
20 |
/**
|
21 |
* Errors collector.
|
22 |
*
|
23 |
* @var array|WP_Error
|
24 |
*/
|
25 |
public $errors = array();
|
|
|
26 |
/**
|
27 |
* Instagram Access Token
|
28 |
*
|
@@ -30,8 +33,11 @@ class Wpzoom_Instagram_Widget_API {
|
|
30 |
*/
|
31 |
protected $access_token;
|
32 |
|
|
|
|
|
|
|
33 |
protected function __construct() {
|
34 |
-
$options =
|
35 |
|
36 |
$this->request_type = ! empty( $options['request-type'] ) ? $options['request-type'] : '';
|
37 |
$this->access_token = ! empty( $options['basic-access-token'] ) ? $options['basic-access-token'] : '';
|
@@ -51,6 +57,12 @@ class Wpzoom_Instagram_Widget_API {
|
|
51 |
$this->errors = new WP_Error();
|
52 |
}
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
/**
|
55 |
* Returns the *Singleton* instance of this class.
|
56 |
*
|
@@ -59,14 +71,119 @@ class Wpzoom_Instagram_Widget_API {
|
|
59 |
public static function getInstance() {
|
60 |
if ( null === self::$instance ) {
|
61 |
self::$instance = new self();
|
|
|
62 |
}
|
63 |
|
64 |
return self::$instance;
|
65 |
}
|
66 |
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
delete_transient( 'zoom_instagram_is_configured' );
|
69 |
delete_transient( 'zoom_instagram_user_info' );
|
|
|
|
|
|
|
|
|
|
|
70 |
}
|
71 |
|
72 |
/**
|
@@ -119,7 +236,7 @@ class Wpzoom_Instagram_Widget_API {
|
|
119 |
'https://graph.instagram.com/me/media'
|
120 |
);
|
121 |
|
122 |
-
$response =
|
123 |
|
124 |
if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
|
125 |
set_transient( $transient, wp_json_encode( false ), MINUTE_IN_SECONDS );
|
@@ -410,7 +527,7 @@ class Wpzoom_Instagram_Widget_API {
|
|
410 |
$user = trim( $user );
|
411 |
$url = 'https://instagram.com/' . str_replace( '@', '', $user );
|
412 |
|
413 |
-
$request =
|
414 |
|
415 |
if ( is_wp_error( $request ) || 200 != wp_remote_retrieve_response_code( $request ) ) {
|
416 |
$error_data = $this->get_error( 'response-data-without-token-from-html-invalid-response' );
|
@@ -463,7 +580,7 @@ class Wpzoom_Instagram_Widget_API {
|
|
463 |
$user = trim( $user );
|
464 |
$url = 'https://instagram.com/' . str_replace( '@', '', $user ) . '/?__a=1';
|
465 |
|
466 |
-
$request =
|
467 |
|
468 |
if ( is_wp_error( $request ) || 200 != wp_remote_retrieve_response_code( $request ) ) {
|
469 |
$error_data = $this->get_error( 'response-data-without-token-from-json-invalid-response' );
|
@@ -532,7 +649,7 @@ class Wpzoom_Instagram_Widget_API {
|
|
532 |
'https://graph.instagram.com/me'
|
533 |
);
|
534 |
|
535 |
-
$response =
|
536 |
|
537 |
if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
|
538 |
set_transient( $transient, wp_json_encode( false ), MINUTE_IN_SECONDS );
|
@@ -574,7 +691,7 @@ class Wpzoom_Instagram_Widget_API {
|
|
574 |
function convert_user_info_to_old_structure( $user_info ) {
|
575 |
$converted = new stdClass();
|
576 |
|
577 |
-
$user_info_from_settings =
|
578 |
|
579 |
$avatar = null;
|
580 |
|
@@ -702,7 +819,7 @@ class Wpzoom_Instagram_Widget_API {
|
|
702 |
'https://graph.instagram.com/me'
|
703 |
);
|
704 |
|
705 |
-
$response =
|
706 |
|
707 |
if ( is_wp_error( $response ) ) {
|
708 |
return $response;
|
11 |
* @var Wpzoom_Instagram_Widget_API The reference to *Singleton* instance of this class
|
12 |
*/
|
13 |
private static $instance;
|
14 |
+
|
15 |
/**
|
16 |
* Request headers.
|
17 |
*
|
18 |
* @var array
|
19 |
*/
|
20 |
public $headers = array();
|
21 |
+
|
22 |
/**
|
23 |
* Errors collector.
|
24 |
*
|
25 |
* @var array|WP_Error
|
26 |
*/
|
27 |
public $errors = array();
|
28 |
+
|
29 |
/**
|
30 |
* Instagram Access Token
|
31 |
*
|
33 |
*/
|
34 |
protected $access_token;
|
35 |
|
36 |
+
/**
|
37 |
+
* Class constructor
|
38 |
+
*/
|
39 |
protected function __construct() {
|
40 |
+
$options = Wpzoom_Instagram_Widget_Settings::$settings;
|
41 |
|
42 |
$this->request_type = ! empty( $options['request-type'] ) ? $options['request-type'] : '';
|
43 |
$this->access_token = ! empty( $options['basic-access-token'] ) ? $options['basic-access-token'] : '';
|
57 |
$this->errors = new WP_Error();
|
58 |
}
|
59 |
|
60 |
+
public function init() {
|
61 |
+
add_action( 'init', array( $this, 'set_schedule' ) );
|
62 |
+
add_action( 'wpzoom_instagram_widget_cron_hook', array( $this, 'execute_cron' ) );
|
63 |
+
add_filter( 'cron_schedules', array( $this, 'add_cron_interval' ) );
|
64 |
+
}
|
65 |
+
|
66 |
/**
|
67 |
* Returns the *Singleton* instance of this class.
|
68 |
*
|
71 |
public static function getInstance() {
|
72 |
if ( null === self::$instance ) {
|
73 |
self::$instance = new self();
|
74 |
+
self::$instance->init();
|
75 |
}
|
76 |
|
77 |
return self::$instance;
|
78 |
}
|
79 |
|
80 |
+
/**
|
81 |
+
* Register custom cron intervals
|
82 |
+
*
|
83 |
+
* @since 1.8.0
|
84 |
+
*
|
85 |
+
* @param array $schedules Registered schedules array.
|
86 |
+
* @return array
|
87 |
+
*/
|
88 |
+
public function add_cron_interval( $schedules ) {
|
89 |
+
if ( ! empty( $this->access_token ) ) {
|
90 |
+
$schedules['before_access_token_expires'] = array(
|
91 |
+
'interval' => 5097600, // 59 days.
|
92 |
+
'display' => __( 'Before Access Token Expires', 'instagram-widget-by-wpzoom' ),
|
93 |
+
);
|
94 |
+
}
|
95 |
+
return $schedules;
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Register schedule event
|
100 |
+
*
|
101 |
+
* @return void
|
102 |
+
*/
|
103 |
+
public function set_schedule() {
|
104 |
+
if ( ! empty( $this->access_token ) && ! wp_next_scheduled( 'wpzoom_instagram_widget_cron_hook' ) ) {
|
105 |
+
wp_schedule_event( time(), 'before_access_token_expires', 'wpzoom_instagram_widget_cron_hook' );
|
106 |
+
}
|
107 |
+
}
|
108 |
+
|
109 |
+
/**
|
110 |
+
* Execute cron event
|
111 |
+
*
|
112 |
+
* @return boolean
|
113 |
+
*/
|
114 |
+
public function execute_cron() {
|
115 |
+
global $current_user;
|
116 |
+
|
117 |
+
if ( ! empty( $this->access_token ) ) {
|
118 |
+
$stored_data = Wpzoom_Instagram_Widget_Settings::$settings;
|
119 |
+
$request_url = add_query_arg(
|
120 |
+
array(
|
121 |
+
'grant_type' => 'ig_refresh_token',
|
122 |
+
'access_token' => $this->access_token,
|
123 |
+
),
|
124 |
+
'https://graph.instagram.com/refresh_access_token'
|
125 |
+
);
|
126 |
+
|
127 |
+
$response = wp_safe_remote_get( $request_url, $this->headers );
|
128 |
+
$response_code = wp_remote_retrieve_response_code( $response );
|
129 |
+
|
130 |
+
if ( ! is_wp_error( $response ) ) {
|
131 |
+
$body = wp_remote_retrieve_body( $response );
|
132 |
+
$data = json_decode( $body );
|
133 |
+
}
|
134 |
+
|
135 |
+
if ( 200 === $response_code ) {
|
136 |
+
$date_format = get_option( 'date_format' );
|
137 |
+
$time_format = get_option( 'time_format' );
|
138 |
+
$notice_message = sprintf( __( 'Instagram Access Token was refreshed automatically on %1$s at %2$s', 'instagram-widget-by-wpzoom' ), date( $date_format ), date( $time_format ) );
|
139 |
+
|
140 |
+
$stored_data['basic-access-token'] = $data->access_token;
|
141 |
+
$stored_data['refresh-access-token'] = $notice_message;
|
142 |
+
} else {
|
143 |
+
if ( ! isset( $data->error ) ) {
|
144 |
+
error_log( __( 'Something wrong! Doesn\'t isset $data->error.', 'instagram-widget-by-wpzoom' ) );
|
145 |
+
return false;
|
146 |
+
} else {
|
147 |
+
error_log( $data->error->error_user_msg );
|
148 |
+
}
|
149 |
+
|
150 |
+
$notice_message = '';
|
151 |
+
$user_id = $current_user->ID;
|
152 |
+
$hide_notices_url = wpzoom_instagram_get_notice_dismiss_url();
|
153 |
+
$settings_url = admin_url( 'options-general.php?page=wpzoom-instagram-widget' );
|
154 |
+
|
155 |
+
if ( 190 === $data->error->code ) {
|
156 |
+
// Error validating access token: Session has expired.
|
157 |
+
$notice_message = $data->error->message;
|
158 |
+
$notice_message .= '<a style="text-decoration: none" class="notice-dismiss" href="' . $hide_notices_url . '"></a>';
|
159 |
+
} elseif ( 10 === $data->error->code && ! self::is_access_token_valid( $this->access_token ) ) {
|
160 |
+
// Application does not have permission for this action.
|
161 |
+
// User need to generate new Access Token manually.
|
162 |
+
$notice_message = '<strong>' . __( 'Your Access Token for Instagram Widget has expired!', 'instagram-widget-by-wpzoom' ) . '</strong><br/>';
|
163 |
+
$notice_message .= sprintf( __( 'We cannot update access tokens automatically for Instagram private accounts. You need manually to generate a new access token, reauthorize here: %1$s.', 'instagram-widget-by-wpzoom' ), '<a href="' . esc_url( $settings_url ) . '">' . __( 'Instagram Widget Settings', 'instagram-widget-by-wpzoom' ) . '</a>' ) . ' ';
|
164 |
+
$notice_message .= '<a style="text-decoration: none" class="notice-dismiss" href="' . $hide_notices_url . '"></a>';
|
165 |
+
}
|
166 |
+
|
167 |
+
$stored_data['admin-notice-message'] = $notice_message;
|
168 |
+
|
169 |
+
// Update user meta to display admin notice.
|
170 |
+
update_user_meta( $user_id, 'wpzoom_instagram_admin_notice', false );
|
171 |
+
}
|
172 |
+
|
173 |
+
return update_option( Wpzoom_Instagram_Widget_Settings::$option_name, $stored_data );
|
174 |
+
}
|
175 |
+
|
176 |
+
return false;
|
177 |
+
}
|
178 |
+
|
179 |
+
public static function reset_cache( $sanitized_data ) {
|
180 |
delete_transient( 'zoom_instagram_is_configured' );
|
181 |
delete_transient( 'zoom_instagram_user_info' );
|
182 |
+
|
183 |
+
// Remove schedule hook `wpzoom_instagram_widget_cron_hook`.
|
184 |
+
if ( empty( $sanitized_data['basic-access-token'] ) ) {
|
185 |
+
wp_clear_scheduled_hook( 'wpzoom_instagram_widget_cron_hook' );
|
186 |
+
}
|
187 |
}
|
188 |
|
189 |
/**
|
236 |
'https://graph.instagram.com/me/media'
|
237 |
);
|
238 |
|
239 |
+
$response = wp_safe_remote_get( $request_url, $this->headers );
|
240 |
|
241 |
if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
|
242 |
set_transient( $transient, wp_json_encode( false ), MINUTE_IN_SECONDS );
|
527 |
$user = trim( $user );
|
528 |
$url = 'https://instagram.com/' . str_replace( '@', '', $user );
|
529 |
|
530 |
+
$request = wp_safe_remote_get( $url, $this->headers );
|
531 |
|
532 |
if ( is_wp_error( $request ) || 200 != wp_remote_retrieve_response_code( $request ) ) {
|
533 |
$error_data = $this->get_error( 'response-data-without-token-from-html-invalid-response' );
|
580 |
$user = trim( $user );
|
581 |
$url = 'https://instagram.com/' . str_replace( '@', '', $user ) . '/?__a=1';
|
582 |
|
583 |
+
$request = wp_safe_remote_get( $url, $this->headers );
|
584 |
|
585 |
if ( is_wp_error( $request ) || 200 != wp_remote_retrieve_response_code( $request ) ) {
|
586 |
$error_data = $this->get_error( 'response-data-without-token-from-json-invalid-response' );
|
649 |
'https://graph.instagram.com/me'
|
650 |
);
|
651 |
|
652 |
+
$response = wp_safe_remote_get( $request_url, $this->headers );
|
653 |
|
654 |
if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
|
655 |
set_transient( $transient, wp_json_encode( false ), MINUTE_IN_SECONDS );
|
691 |
function convert_user_info_to_old_structure( $user_info ) {
|
692 |
$converted = new stdClass();
|
693 |
|
694 |
+
$user_info_from_settings = Wpzoom_Instagram_Widget_Settings::$settings;
|
695 |
|
696 |
$avatar = null;
|
697 |
|
819 |
'https://graph.instagram.com/me'
|
820 |
);
|
821 |
|
822 |
+
$response = wp_safe_remote_get( $request_url );
|
823 |
|
824 |
if ( is_wp_error( $response ) ) {
|
825 |
return $response;
|
class-wpzoom-instagram-widget-settings.php
CHANGED
@@ -7,7 +7,25 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
7 |
}
|
8 |
|
9 |
class Wpzoom_Instagram_Widget_Settings {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
public function __construct() {
|
|
|
|
|
11 |
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
|
12 |
add_action( 'admin_init', array( $this, 'settings_init' ) );
|
13 |
|
@@ -171,7 +189,7 @@ class Wpzoom_Instagram_Widget_Settings {
|
|
171 |
}
|
172 |
|
173 |
public function settings_field_basic_access_token_button() {
|
174 |
-
$settings =
|
175 |
|
176 |
$oauth_url = add_query_arg(
|
177 |
array(
|
@@ -202,7 +220,7 @@ class Wpzoom_Instagram_Widget_Settings {
|
|
202 |
}
|
203 |
|
204 |
public function settings_field_transient_lifetime() {
|
205 |
-
$settings =
|
206 |
$lifetime_value = ! empty( $settings['transient-lifetime-value'] ) ? $settings['transient-lifetime-value'] : 1;
|
207 |
$lifetime_type = ! empty( $settings['transient-lifetime-type'] ) ? $settings['transient-lifetime-type'] : 'days';
|
208 |
?>
|
@@ -227,7 +245,7 @@ class Wpzoom_Instagram_Widget_Settings {
|
|
227 |
}
|
228 |
|
229 |
public function settings_field_is_forced_timeout() {
|
230 |
-
$settings =
|
231 |
$is_forced_timeout = ! empty( $settings['is-forced-timeout'] ) ? wp_validate_boolean( $settings['is-forced-timeout'] ) : false;
|
232 |
?>
|
233 |
<input class="regular-text code"
|
@@ -241,7 +259,7 @@ class Wpzoom_Instagram_Widget_Settings {
|
|
241 |
}
|
242 |
|
243 |
public function settings_field_request_timeout() {
|
244 |
-
$settings =
|
245 |
$timeout_value = ! empty( $settings['request-timeout-value'] ) ? $settings['request-timeout-value'] : 15;
|
246 |
?>
|
247 |
<input class="regular-text code"
|
@@ -259,7 +277,7 @@ class Wpzoom_Instagram_Widget_Settings {
|
|
259 |
}
|
260 |
|
261 |
public function settings_field_basic_access_token_input() {
|
262 |
-
$settings =
|
263 |
$basic_access_token = ! empty( $settings['basic-access-token'] ) ? $settings['basic-access-token'] : '';
|
264 |
?>
|
265 |
<input class="regular-text code" id="wpzoom-instagram-widget-settings_basic-access-token"
|
@@ -298,7 +316,7 @@ class Wpzoom_Instagram_Widget_Settings {
|
|
298 |
|
299 |
|
300 |
public function settings_field_username() {
|
301 |
-
$settings =
|
302 |
?>
|
303 |
<input class="regular-text code" id="wpzoom-instagram-widget-settings_username"
|
304 |
name="wpzoom-instagram-widget-settings[username]" value="<?php echo esc_attr( $settings['username'] ); ?>"
|
@@ -317,7 +335,7 @@ class Wpzoom_Instagram_Widget_Settings {
|
|
317 |
}
|
318 |
|
319 |
public function settings_field_request_type() {
|
320 |
-
$settings =
|
321 |
$request_type = empty( $settings['request-type'] ) ? 'with-basic-access-token' : $settings['request-type'];
|
322 |
?>
|
323 |
|
@@ -351,7 +369,7 @@ class Wpzoom_Instagram_Widget_Settings {
|
|
351 |
}
|
352 |
|
353 |
public function settings_field_user_info_fullname() {
|
354 |
-
$settings =
|
355 |
$user_info_fullname = empty( $settings['user-info-fullname'] ) ? '' : $settings['user-info-fullname'];
|
356 |
?>
|
357 |
<input class="code"
|
@@ -363,7 +381,7 @@ class Wpzoom_Instagram_Widget_Settings {
|
|
363 |
}
|
364 |
|
365 |
public function settings_field_user_info_avatar() {
|
366 |
-
$settings =
|
367 |
$user_info_avatar = empty( $settings['user-info-avatar'] ) ? '' : $settings['user-info-avatar'];
|
368 |
?>
|
369 |
<div class="zoom-instagram-user-avatar-media-uploader"
|
@@ -387,7 +405,7 @@ class Wpzoom_Instagram_Widget_Settings {
|
|
387 |
}
|
388 |
|
389 |
public function settings_field_user_info_biography() {
|
390 |
-
$settings =
|
391 |
$user_info_biography = empty( $settings['user-info-biography'] ) ? '' : $settings['user-info-biography'];
|
392 |
?>
|
393 |
<textarea class="code"
|
@@ -491,7 +509,7 @@ class Wpzoom_Instagram_Widget_Settings {
|
|
491 |
$result['user-info-fullname'] = sanitize_text_field( $input['user-info-fullname'] );
|
492 |
$result['user-info-biography'] = sanitize_text_field( $input['user-info-biography'] );
|
493 |
|
494 |
-
Wpzoom_Instagram_Widget_API::reset_cache();
|
495 |
|
496 |
return $result;
|
497 |
}
|
7 |
}
|
8 |
|
9 |
class Wpzoom_Instagram_Widget_Settings {
|
10 |
+
/**
|
11 |
+
* Stores settings options
|
12 |
+
*
|
13 |
+
* @since 1.8.0
|
14 |
+
* @var array
|
15 |
+
*/
|
16 |
+
public static $settings = array();
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Settings option name
|
20 |
+
*
|
21 |
+
* @since 1.8.0
|
22 |
+
* @var string
|
23 |
+
*/
|
24 |
+
public static $option_name = 'wpzoom-instagram-widget-settings';
|
25 |
+
|
26 |
public function __construct() {
|
27 |
+
self::$settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
|
28 |
+
|
29 |
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
|
30 |
add_action( 'admin_init', array( $this, 'settings_init' ) );
|
31 |
|
189 |
}
|
190 |
|
191 |
public function settings_field_basic_access_token_button() {
|
192 |
+
$settings = self::$settings;
|
193 |
|
194 |
$oauth_url = add_query_arg(
|
195 |
array(
|
220 |
}
|
221 |
|
222 |
public function settings_field_transient_lifetime() {
|
223 |
+
$settings = self::$settings;
|
224 |
$lifetime_value = ! empty( $settings['transient-lifetime-value'] ) ? $settings['transient-lifetime-value'] : 1;
|
225 |
$lifetime_type = ! empty( $settings['transient-lifetime-type'] ) ? $settings['transient-lifetime-type'] : 'days';
|
226 |
?>
|
245 |
}
|
246 |
|
247 |
public function settings_field_is_forced_timeout() {
|
248 |
+
$settings = self::$settings;
|
249 |
$is_forced_timeout = ! empty( $settings['is-forced-timeout'] ) ? wp_validate_boolean( $settings['is-forced-timeout'] ) : false;
|
250 |
?>
|
251 |
<input class="regular-text code"
|
259 |
}
|
260 |
|
261 |
public function settings_field_request_timeout() {
|
262 |
+
$settings = self::$settings;
|
263 |
$timeout_value = ! empty( $settings['request-timeout-value'] ) ? $settings['request-timeout-value'] : 15;
|
264 |
?>
|
265 |
<input class="regular-text code"
|
277 |
}
|
278 |
|
279 |
public function settings_field_basic_access_token_input() {
|
280 |
+
$settings = self::$settings;
|
281 |
$basic_access_token = ! empty( $settings['basic-access-token'] ) ? $settings['basic-access-token'] : '';
|
282 |
?>
|
283 |
<input class="regular-text code" id="wpzoom-instagram-widget-settings_basic-access-token"
|
316 |
|
317 |
|
318 |
public function settings_field_username() {
|
319 |
+
$settings = self::$settings;
|
320 |
?>
|
321 |
<input class="regular-text code" id="wpzoom-instagram-widget-settings_username"
|
322 |
name="wpzoom-instagram-widget-settings[username]" value="<?php echo esc_attr( $settings['username'] ); ?>"
|
335 |
}
|
336 |
|
337 |
public function settings_field_request_type() {
|
338 |
+
$settings = self::$settings;
|
339 |
$request_type = empty( $settings['request-type'] ) ? 'with-basic-access-token' : $settings['request-type'];
|
340 |
?>
|
341 |
|
369 |
}
|
370 |
|
371 |
public function settings_field_user_info_fullname() {
|
372 |
+
$settings = self::$settings;
|
373 |
$user_info_fullname = empty( $settings['user-info-fullname'] ) ? '' : $settings['user-info-fullname'];
|
374 |
?>
|
375 |
<input class="code"
|
381 |
}
|
382 |
|
383 |
public function settings_field_user_info_avatar() {
|
384 |
+
$settings = self::$settings;
|
385 |
$user_info_avatar = empty( $settings['user-info-avatar'] ) ? '' : $settings['user-info-avatar'];
|
386 |
?>
|
387 |
<div class="zoom-instagram-user-avatar-media-uploader"
|
405 |
}
|
406 |
|
407 |
public function settings_field_user_info_biography() {
|
408 |
+
$settings = self::$settings;
|
409 |
$user_info_biography = empty( $settings['user-info-biography'] ) ? '' : $settings['user-info-biography'];
|
410 |
?>
|
411 |
<textarea class="code"
|
509 |
$result['user-info-fullname'] = sanitize_text_field( $input['user-info-fullname'] );
|
510 |
$result['user-info-biography'] = sanitize_text_field( $input['user-info-biography'] );
|
511 |
|
512 |
+
Wpzoom_Instagram_Widget_API::reset_cache( $result );
|
513 |
|
514 |
return $result;
|
515 |
}
|
instagram-widget-by-wpzoom.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: WPZOOM Instagram Widget
|
4 |
* Plugin URI: https://www.wpzoom.com/plugins/instagram-widget/
|
5 |
* Description: Simple and lightweight widget for WordPress to display your Instagram feed
|
6 |
-
* Version: 1.
|
7 |
* Author: WPZOOM
|
8 |
* Author URI: https://www.wpzoom.com/
|
9 |
* Text Domain: instagram-widget-by-wpzoom
|
@@ -19,7 +19,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
19 |
}
|
20 |
|
21 |
if ( ! defined( 'WPZOOM_INSTAGRAM_VERSION' ) ) {
|
22 |
-
define( 'WPZOOM_INSTAGRAM_VERSION', '1.
|
23 |
}
|
24 |
|
25 |
require_once plugin_dir_path( __FILE__ ) . 'class-wpzoom-instagram-image-uploader.php';
|
@@ -37,36 +37,51 @@ function zoom_instagram_widget_register() {
|
|
37 |
add_action( 'admin_notices', 'wpzoom_instagram_admin_notice' );
|
38 |
|
39 |
function wpzoom_instagram_admin_notice() {
|
|
|
|
|
40 |
if ( ! current_user_can( 'manage_options' ) ) {
|
41 |
return;
|
42 |
}
|
43 |
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
/* Check that the user hasn't already clicked to ignore the message */
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
}
|
71 |
}
|
72 |
|
@@ -81,6 +96,21 @@ function wpzoom_instagram_ignore_admin_notice() {
|
|
81 |
}
|
82 |
}
|
83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
function wpzoom_instagram_get_default_settings() {
|
86 |
return array(
|
@@ -138,3 +168,9 @@ function wpzoom_instagram_load_plugin_textdomain() {
|
|
138 |
load_plugin_textdomain( 'instagram-widget-by-wpzoom', false, basename( dirname( __FILE__ ) ) . '/languages/' );
|
139 |
}
|
140 |
add_action( 'init', 'wpzoom_instagram_load_plugin_textdomain' );
|
|
|
|
|
|
|
|
|
|
|
|
3 |
* Plugin Name: WPZOOM Instagram Widget
|
4 |
* Plugin URI: https://www.wpzoom.com/plugins/instagram-widget/
|
5 |
* Description: Simple and lightweight widget for WordPress to display your Instagram feed
|
6 |
+
* Version: 1.8.0
|
7 |
* Author: WPZOOM
|
8 |
* Author URI: https://www.wpzoom.com/
|
9 |
* Text Domain: instagram-widget-by-wpzoom
|
19 |
}
|
20 |
|
21 |
if ( ! defined( 'WPZOOM_INSTAGRAM_VERSION' ) ) {
|
22 |
+
define( 'WPZOOM_INSTAGRAM_VERSION', '1.8.0' );
|
23 |
}
|
24 |
|
25 |
require_once plugin_dir_path( __FILE__ ) . 'class-wpzoom-instagram-image-uploader.php';
|
37 |
add_action( 'admin_notices', 'wpzoom_instagram_admin_notice' );
|
38 |
|
39 |
function wpzoom_instagram_admin_notice() {
|
40 |
+
global $current_user, $pagenow;
|
41 |
+
|
42 |
if ( ! current_user_can( 'manage_options' ) ) {
|
43 |
return;
|
44 |
}
|
45 |
|
46 |
+
$options = Wpzoom_Instagram_Widget_Settings::$settings;
|
47 |
+
|
48 |
+
if ( ! isset( $options['basic-access-token'] ) || empty( $options['basic-access-token'] ) ) {
|
49 |
+
$hide_notices_url = wpzoom_instagram_get_notice_dismiss_url();
|
50 |
+
|
51 |
+
$notice_message = '<strong>' . __( 'Please configure Instagram Widget', 'instagram-widget-by-wpzoom' ) . '</strong><br/>';
|
52 |
+
$notice_message .= sprintf( __( 'If you have just installed or updated this plugin, please go to the %1$s and %2$s it with your Instagram account.', 'instagram-widget-by-wpzoom' ), '<a href="options-general.php?page=wpzoom-instagram-widget">' . __( 'Settings page', 'instagram-widget-by-wpzoom' ) . '</a>', '<strong>' . __( 'connect', 'instagram-widget-by-wpzoom' ) . '</strong>' ) . ' ';
|
53 |
+
$notice_message .= __( 'You have to generate Instagram Access Token to allow widget to display your media.', 'instagram-widget-by-wpzoom' );
|
54 |
+
$notice_message .= '<a style="text-decoration: none" class="notice-dismiss" href="' . $hide_notices_url . '"></a>';
|
55 |
+
|
56 |
+
$options['admin-notice-message'] = $notice_message;
|
57 |
+
|
58 |
+
update_option( Wpzoom_Instagram_Widget_Settings::$option_name, $options );
|
59 |
+
}
|
60 |
+
|
61 |
/* Check that the user hasn't already clicked to ignore the message */
|
62 |
+
$user_id = $current_user->ID;
|
63 |
+
if ( ! get_user_meta( $user_id, 'wpzoom_instagram_admin_notice', true ) ) {
|
64 |
+
if ( isset( $options['admin-notice-message'] ) && ! empty( $options['admin-notice-message'] ) ) {
|
65 |
+
echo '<div class="notice-warning notice" style="position:relative"><p>';
|
66 |
+
echo wp_kses_post( $options['admin-notice-message'] );
|
67 |
+
echo '</p></div>';
|
68 |
+
}
|
69 |
+
}
|
70 |
+
|
71 |
+
if ( 'options-general.php' === $pagenow && ( isset( $_GET['page'] ) && 'wpzoom-instagram-widget' === $_GET['page'] ) ) {
|
72 |
+
if ( isset( $options['refresh-access-token'] ) && ! empty( $options['refresh-access-token'] ) ) {
|
73 |
+
// Inform user in settings page when Access Token was refreshed.
|
74 |
+
add_settings_error(
|
75 |
+
'wpzoom-instagram-refresh-access-token',
|
76 |
+
esc_attr( 'wpzoom-instagram-widget-refresh-access-token' ),
|
77 |
+
$options['refresh-access-token'],
|
78 |
+
'info'
|
79 |
+
);
|
80 |
+
|
81 |
+
$options['refresh-access-token'] = '';
|
82 |
+
|
83 |
+
update_option( Wpzoom_Instagram_Widget_Settings::$option_name, $options );
|
84 |
+
}
|
85 |
}
|
86 |
}
|
87 |
|
96 |
}
|
97 |
}
|
98 |
|
99 |
+
function wpzoom_instagram_get_notice_dismiss_url() {
|
100 |
+
/**
|
101 |
+
* Fixed dismiss url
|
102 |
+
*
|
103 |
+
* @since 1.7.5
|
104 |
+
*/
|
105 |
+
$hide_notices_url = html_entity_decode( // to convert &s to normal &, otherwise produces invalid link.
|
106 |
+
add_query_arg(
|
107 |
+
array(
|
108 |
+
'wpzoom_instagram_ignore_admin_notice' => '0',
|
109 |
+
),
|
110 |
+
wpzoom_instagram_get_current_admin_url() ? wpzoom_instagram_get_current_admin_url() : admin_url( 'options-general.php?page=wpzoom-instagram-widget' )
|
111 |
+
)
|
112 |
+
);
|
113 |
+
}
|
114 |
|
115 |
function wpzoom_instagram_get_default_settings() {
|
116 |
return array(
|
168 |
load_plugin_textdomain( 'instagram-widget-by-wpzoom', false, basename( dirname( __FILE__ ) ) . '/languages/' );
|
169 |
}
|
170 |
add_action( 'init', 'wpzoom_instagram_load_plugin_textdomain' );
|
171 |
+
|
172 |
+
register_deactivation_hook( __FILE__, 'wpzoom_instagram_plugin_deactivation' );
|
173 |
+
|
174 |
+
function wpzoom_instagram_plugin_deactivation() {
|
175 |
+
wp_clear_scheduled_hook( 'wpzoom_instagram_widget_cron_hook' );
|
176 |
+
}
|
readme.txt
CHANGED
@@ -67,6 +67,11 @@ Make sure to connect your Instagram account with the plugin. You can do that in
|
|
67 |
|
68 |
== Changelog ==
|
69 |
|
|
|
|
|
|
|
|
|
|
|
70 |
= 1.7.7 =
|
71 |
* Load plugin text domain
|
72 |
* Removed old .pot file from /languages
|
67 |
|
68 |
== Changelog ==
|
69 |
|
70 |
+
= 1.8.0 =
|
71 |
+
* NEW: Automatically refresh Instagram access token before it expires
|
72 |
+
* NOTE: There are limitations to refresh access token for Instagram private accounts! You will need to reauthorize manually after access token expires
|
73 |
+
* Improved admin notices
|
74 |
+
|
75 |
= 1.7.7 =
|
76 |
* Load plugin text domain
|
77 |
* Removed old .pot file from /languages
|