-
Notifications
You must be signed in to change notification settings - Fork 6
/
instagram-widget-by-wpzoom.php
190 lines (158 loc) · 6.84 KB
/
instagram-widget-by-wpzoom.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
/**
* Plugin Name: WPZOOM Instagram Widget & Block
* Plugin URI: https://www.wpzoom.com/plugins/instagram-widget/
* Description: Instagram Widget is a customizable and responsive plugin, made to help you gain even more followers by showcasing your Instagram feed on your WordPress website.
* Version: 2.2.0
* Author: WPZOOM
* Author URI: https://www.wpzoom.com/
* Text Domain: instagram-widget-by-wpzoom
* Domain Path: /languages
* License: GPLv2 or later
*/
/**
* Exit if accessed directly.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! defined( 'WPZOOM_INSTAGRAM_VERSION' ) ) {
define( 'WPZOOM_INSTAGRAM_VERSION', get_file_data( __FILE__, [ 'Version' ] )[0] ); // phpcs:ignore
}
require_once plugin_dir_path( __FILE__ ) . 'class-wpzoom-instagram-image-uploader.php';
require_once plugin_dir_path( __FILE__ ) . 'class-wpzoom-instagram-widget-settings.php';
require_once plugin_dir_path( __FILE__ ) . 'class-wpzoom-instagram-general-settings.php';
require_once plugin_dir_path( __FILE__ ) . 'class-wpzoom-instagram-widget-api.php';
require_once plugin_dir_path( __FILE__ ) . 'class-wpzoom-instagram-widget-display.php';
require_once plugin_dir_path( __FILE__ ) . 'class-wpzoom-instagram-widget.php';
require_once plugin_dir_path( __FILE__ ) . 'class-wpzoom-instagram-block.php';
require_once plugin_dir_path( __FILE__ ) . 'class-wpzoom-instagram-assets.php';
require_once plugin_dir_path( __FILE__ ) . 'class-wpzoom-instagram-widget-after-setup.php';
//added 6 july 2023
require_once plugin_dir_path( __FILE__ ) . 'class-wpzoom-instagram-email-notification.php';
add_action( 'widgets_init', 'zoom_instagram_widget_register' );
function zoom_instagram_widget_register() {
register_widget( 'Wpzoom_Instagram_Widget' );
}
/* Display a notice that can be dismissed */
// add_action( 'admin_notices', 'wpzoom_instagram_admin_notice' );
function wpzoom_instagram_admin_notice() {
global $current_user, $pagenow;
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$options = WPZOOM_Instagram_Widget_Settings::get_instance()->get_settings();
if ( ! isset( $options['basic-access-token'] ) || empty( $options['basic-access-token'] ) ) {
$hide_notices_url = wpzoom_instagram_get_notice_dismiss_url();
$notice_message = '<strong>' . __( 'Please configure Instagram Widget', 'instagram-widget-by-wpzoom' ) . '</strong><br/>';
$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="edit.php?post_type=wpz-insta_user">' . __( 'Settings page', 'instagram-widget-by-wpzoom' ) . '</a>', '<strong>' . __( 'connect', 'instagram-widget-by-wpzoom' ) . '</strong>' ) . ' ';
$notice_message .= __( 'You have to generate Instagram Access Token to allow widget to display your media.', 'instagram-widget-by-wpzoom' );
$notice_message .= '<a style="text-decoration: none" class="notice-dismiss" href="' . $hide_notices_url . '"></a>';
$options['admin-notice-message'] = $notice_message;
update_option( WPZOOM_Instagram_Widget_Settings::get_instance()->get_option_name(), $options );
}
/* Check that the user hasn't already clicked to ignore the message */
$user_id = $current_user->ID;
if ( ! get_user_meta( $user_id, 'wpzoom_instagram_admin_notice', true ) ) {
if ( isset( $options['admin-notice-message'] ) && ! empty( $options['admin-notice-message'] ) ) {
echo '<div class="notice-warning notice" style="position:relative"><p>';
echo wp_kses_post( $options['admin-notice-message'] );
echo '</p></div>';
}
}
if ( 'options-general.php' === $pagenow && ( isset( $_GET['page'] ) && 'wpzoom-instagram-widget' === $_GET['page'] ) ) {
if ( isset( $options['refresh-access-token'] ) && ! empty( $options['refresh-access-token'] ) ) {
// Inform user in settings page when Access Token was refreshed.
add_settings_error(
'wpzoom-instagram-refresh-access-token',
esc_attr( 'wpzoom-instagram-widget-refresh-access-token' ),
$options['refresh-access-token'],
'info'
);
$options['refresh-access-token'] = '';
update_option( WPZOOM_Instagram_Widget_Settings::get_instance()->get_option_name(), $options );
}
}
}
// add_action( 'admin_init', 'wpzoom_instagram_ignore_admin_notice' );
function wpzoom_instagram_ignore_admin_notice() {
global $current_user;
$user_id = $current_user->ID;
/* If user clicks to ignore the notice, add that to their user meta */
if ( isset( $_GET['wpzoom_instagram_ignore_admin_notice'] ) && '0' == $_GET['wpzoom_instagram_ignore_admin_notice'] ) {
add_user_meta( $user_id, 'wpzoom_instagram_admin_notice', 'true', true );
}
}
function wpzoom_instagram_get_notice_dismiss_url() {
/**
* Fixed dismiss url
*
* @since 1.7.5
*/
$hide_notices_url = html_entity_decode( // to convert &s to normal &, otherwise produces invalid link.
add_query_arg(
array(
'wpzoom_instagram_ignore_admin_notice' => '0',
),
wpzoom_instagram_get_current_admin_url() ? wpzoom_instagram_get_current_admin_url() : admin_url( 'edit.php?post_type=wpz-insta_user' )
)
);
return $hide_notices_url;
}
function wpzoom_instagram_get_default_settings() {
return array(
'access-token' => '',
'basic-access-token' => '',
'request-type' => 'with-basic-access-token',
'username' => '',
'transient-lifetime-value' => 1,
'transient-lifetime-type' => 'days',
'is-forced-timeout' => '',
'request-timeout-value' => 15,
'user-info-avatar' => '',
'user-info-fullname' => '',
'user-info-biography' => '',
'load-css-js' => '',
);
}
add_action(
'init',
function () {
$option_name = 'wpzoom-instagram-transition-between-4_7-4_8-versions';
if ( empty( get_option( $option_name ) ) ) {
update_option( $option_name, true );
delete_transient( 'zoom_instagram_is_configured' );
}
Wpzoom_Instagram_Widget_Display::getInstance()->init();
}
);
/**
* Get current admin page URL.
*
* Returns an empty string if it cannot generate a URL.
*
* @internal
* @since 1.7.5
* @return string
*/
function wpzoom_instagram_get_current_admin_url() {
$uri = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
$uri = preg_replace( '|^.*/wp-admin/|i', '', $uri );
if ( ! $uri ) {
return '';
}
return remove_query_arg( array( '_wpnonce', 'wpzoom_instagram_ignore_admin_notice' ), admin_url( $uri ) );
}
/**
* Load textdomain
*
* @since 1.7.7
*/
function wpzoom_instagram_load_plugin_textdomain() {
load_plugin_textdomain( 'instagram-widget-by-wpzoom', false, basename( dirname( __FILE__ ) ) . '/languages/' );
}
add_action( 'init', 'wpzoom_instagram_load_plugin_textdomain' );
register_deactivation_hook( __FILE__, 'wpzoom_instagram_plugin_deactivation' );
function wpzoom_instagram_plugin_deactivation() {
wp_clear_scheduled_hook( 'wpzoom_instagram_widget_cron_hook' );
}