Shortcodes Ultimate - Version 5.12.5

Version Description

Download this release

Release Info

Developer gn_themes
Plugin Icon 128x128 Shortcodes Ultimate
Version 5.12.5
Comparing to
See all releases

Code changes from version 5.12.3 to 5.12.5

Files changed (160) hide show
  1. admin/class-shortcodes-ultimate-admin-about.php +0 -0
  2. admin/class-shortcodes-ultimate-admin-addons.php +0 -120
  3. admin/class-shortcodes-ultimate-admin-pro-features.php +139 -153
  4. admin/class-shortcodes-ultimate-admin-settings.php +0 -0
  5. admin/class-shortcodes-ultimate-admin-top-level.php +0 -0
  6. admin/class-shortcodes-ultimate-admin.php +0 -0
  7. admin/class-shortcodes-ultimate-notice-rate.php +38 -44
  8. admin/class-shortcodes-ultimate-notice-unsafe-features.php +0 -0
  9. admin/class-shortcodes-ultimate-notice.php +0 -0
  10. admin/class-shortcodes-ultimate-widget.php +0 -0
  11. admin/css/admin.css +1 -1
  12. admin/css/generator.css +1 -1
  13. admin/images/addons/bundle.png +0 -0
  14. admin/images/addons/extra.png +0 -0
  15. admin/images/addons/maker.png +0 -0
  16. admin/images/addons/skins.png +0 -0
  17. admin/images/pages/about/check.svg +0 -0
  18. admin/images/pages/about/poster.jpg +0 -0
  19. admin/images/plugin-icon.svg +0 -0
  20. admin/images/pro-features/icon-banner.png +0 -0
  21. admin/images/pro-features/icon-generator.png +0 -0
  22. admin/images/pro-features/screenshots/content_slider.png +0 -0
  23. admin/images/pro-features/screenshots/exit_popup.png +0 -0
  24. admin/images/pro-features/screenshots/icon.png +0 -0
  25. admin/images/pro-features/screenshots/icon_panel.png +0 -0
  26. admin/images/pro-features/screenshots/icon_text.png +0 -0
  27. admin/images/pro-features/screenshots/member.png +0 -0
  28. admin/images/pro-features/screenshots/panel.png +0 -0
  29. admin/images/pro-features/screenshots/photo_panel.png +0 -0
  30. admin/images/pro-features/screenshots/pricing_table.png +0 -0
  31. admin/images/pro-features/screenshots/progress_bar.png +0 -0
  32. admin/images/pro-features/screenshots/progress_pie.png +0 -0
  33. admin/images/pro-features/screenshots/section.png +0 -0
  34. admin/images/pro-features/screenshots/shadow.png +0 -0
  35. admin/images/pro-features/screenshots/splash.png +0 -0
  36. admin/images/pro-features/screenshots/testimonial.png +0 -0
  37. admin/images/search.png +0 -0
  38. admin/images/shortcodes/_default.svg +0 -0
  39. admin/images/shortcodes/accordion.svg +0 -0
  40. admin/images/shortcodes/animate.svg +0 -0
  41. admin/images/shortcodes/audio.svg +0 -0
  42. admin/images/shortcodes/box.svg +0 -0
  43. admin/images/shortcodes/button.svg +0 -0
  44. admin/images/shortcodes/carousel.svg +0 -0
  45. admin/images/shortcodes/column.svg +0 -0
  46. admin/images/shortcodes/content_slide.svg +1 -0
  47. admin/images/shortcodes/content_slider.svg +1 -0
  48. admin/images/shortcodes/custom_gallery.svg +0 -0
  49. admin/images/shortcodes/dailymotion.svg +0 -0
  50. admin/images/shortcodes/display-posts.svg +0 -0
  51. admin/images/shortcodes/divider.svg +0 -0
  52. admin/images/shortcodes/document.svg +0 -0
  53. admin/images/shortcodes/dropcap.svg +0 -0
  54. admin/images/shortcodes/dummy_image.svg +0 -0
  55. admin/images/shortcodes/dummy_text.svg +0 -0
  56. admin/images/shortcodes/exit_popup.svg +1 -0
  57. admin/images/shortcodes/expand.svg +0 -0
  58. admin/images/shortcodes/feed.svg +0 -0
  59. admin/images/shortcodes/gmap.svg +0 -0
  60. admin/images/shortcodes/guests.svg +0 -0
  61. admin/images/shortcodes/heading.svg +0 -0
  62. admin/images/shortcodes/highlight.svg +0 -0
  63. admin/images/shortcodes/icon.svg +1 -0
  64. admin/images/shortcodes/icon_panel.svg +1 -0
  65. admin/images/shortcodes/icon_text.svg +1 -0
  66. admin/images/shortcodes/image_carousel.svg +0 -0
  67. admin/images/shortcodes/label.svg +0 -0
  68. admin/images/shortcodes/lightbox.svg +0 -0
  69. admin/images/shortcodes/lightbox_content.svg +0 -0
  70. admin/images/shortcodes/list.svg +0 -0
  71. admin/images/shortcodes/member.svg +1 -0
  72. admin/images/shortcodes/members.svg +0 -0
  73. admin/images/shortcodes/menu.svg +0 -0
  74. admin/images/shortcodes/meta.svg +0 -0
  75. admin/images/shortcodes/note.svg +0 -0
  76. admin/images/shortcodes/panel.svg +1 -0
  77. admin/images/shortcodes/permalink.svg +0 -0
  78. admin/images/shortcodes/photo_panel.svg +1 -0
  79. admin/images/shortcodes/plan.svg +1 -0
  80. admin/images/shortcodes/post.svg +0 -0
  81. admin/images/shortcodes/posts.svg +0 -0
  82. admin/images/shortcodes/pricing_table.svg +1 -0
  83. admin/images/shortcodes/private.svg +0 -0
  84. admin/images/shortcodes/progress_bar.svg +1 -0
  85. admin/images/shortcodes/progress_pie.svg +1 -0
  86. admin/images/shortcodes/pullquote.svg +0 -0
  87. admin/images/shortcodes/qrcode.svg +0 -0
  88. admin/images/shortcodes/quote.svg +0 -0
  89. admin/images/shortcodes/row.svg +0 -0
  90. admin/images/shortcodes/scheduler.svg +0 -0
  91. admin/images/shortcodes/section.svg +1 -0
  92. admin/images/shortcodes/service.svg +0 -0
  93. admin/images/shortcodes/shadow.svg +1 -0
  94. admin/images/shortcodes/siblings.svg +0 -0
  95. admin/images/shortcodes/slider.svg +0 -0
  96. admin/images/shortcodes/spacer.svg +0 -0
  97. admin/images/shortcodes/splash.svg +1 -0
  98. admin/images/shortcodes/spoiler.svg +0 -0
  99. admin/images/shortcodes/subpages.svg +0 -0
  100. admin/images/shortcodes/tab.svg +0 -0
  101. admin/images/shortcodes/table.svg +0 -0
  102. admin/images/shortcodes/tabs.svg +0 -0
  103. admin/images/shortcodes/template.svg +0 -0
  104. admin/images/shortcodes/testimonial.svg +1 -0
  105. admin/images/shortcodes/tooltip.svg +0 -0
  106. admin/images/shortcodes/user.svg +0 -0
  107. admin/images/shortcodes/video.svg +0 -0
  108. admin/images/shortcodes/vimeo.svg +0 -0
  109. admin/images/shortcodes/youtube.svg +0 -0
  110. admin/images/shortcodes/youtube_advanced.svg +0 -0
  111. admin/images/spinner.gif +0 -0
  112. admin/js/about/index.js +0 -0
  113. admin/js/about/index.js.map +0 -0
  114. admin/partials/help/addons.php +0 -0
  115. admin/partials/help/settings.php +0 -0
  116. admin/partials/help/sidebar.php +0 -0
  117. admin/partials/notices/pro.php +4 -0
  118. admin/partials/notices/rate.php +0 -0
  119. admin/partials/notices/unsafe-features.php +0 -0
  120. admin/partials/pages/about.php +98 -75
  121. admin/partials/pages/addons.php +0 -39
  122. admin/partials/pages/settings.php +4 -0
  123. admin/partials/pro-features/generator.php +10 -10
  124. admin/partials/settings/fields/checkbox-group.php +0 -0
  125. admin/partials/settings/fields/checkbox.php +0 -0
  126. admin/partials/settings/fields/css.php +0 -0
  127. admin/partials/settings/fields/text.php +0 -0
  128. admin/partials/settings/sections/advanced.php +0 -0
  129. admin/partials/settings/sections/general.php +0 -0
  130. admin/partials/tabs.php +0 -0
  131. admin/partials/widget/form.php +0 -0
  132. changelog.txt +5 -0
  133. credits.txt +0 -0
  134. freemius/LICENSE.txt +674 -0
  135. freemius/assets/css/admin/account.css +1 -0
  136. freemius/assets/css/admin/add-ons.css +1 -0
  137. freemius/assets/css/admin/affiliation.css +1 -0
  138. freemius/assets/css/admin/checkout.css +1 -0
  139. freemius/assets/css/admin/clone-resolution.css +1 -0
  140. freemius/assets/css/admin/common.css +1 -0
  141. freemius/assets/css/admin/connect.css +1 -0
  142. freemius/assets/css/admin/debug.css +1 -0
  143. freemius/assets/css/admin/dialog-boxes.css +1 -0
  144. freemius/assets/css/admin/gdpr-optin-notice.css +1 -0
  145. freemius/assets/css/admin/index.php +3 -0
  146. freemius/assets/css/admin/plugins.css +1 -0
  147. freemius/assets/css/customizer.css +1 -0
  148. freemius/assets/css/index.php +3 -0
  149. freemius/assets/img/index.php +3 -0
  150. freemius/assets/img/plugin-icon.png +0 -0
  151. freemius/assets/img/shortcodes-ultimate.png +0 -0
  152. freemius/assets/img/theme-icon.png +0 -0
  153. freemius/assets/index.php +3 -0
  154. freemius/assets/js/index.php +3 -0
  155. freemius/assets/js/nojquery.ba-postmessage.js +140 -0
  156. freemius/assets/js/nojquery.ba-postmessage.min.js +12 -0
  157. freemius/assets/js/postmessage.js +135 -0
  158. freemius/config.php +391 -0
  159. freemius/includes/class-freemius-abstract.php +538 -0
  160. freemius/includes/class-freemius.php +20572 -0
admin/class-shortcodes-ultimate-admin-about.php CHANGED
File without changes
admin/class-shortcodes-ultimate-admin-addons.php DELETED
@@ -1,120 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * The Add-ons menu component.
5
- *
6
- * @since 5.0.0
7
- *
8
- * @package Shortcodes_Ultimate
9
- * @subpackage Shortcodes_Ultimate/admin
10
- */
11
- final class Shortcodes_Ultimate_Admin_Addons extends Shortcodes_Ultimate_Admin {
12
-
13
- /**
14
- * Add menu page.
15
- *
16
- * @since 5.0.0
17
- */
18
- public function add_menu_pages() {
19
-
20
- /**
21
- * Submenu: Add-ons
22
- * admin.php?page=shortcodes-ultimate-addons
23
- */
24
- $this->add_submenu_page(
25
- rtrim( $this->plugin_prefix, '-_' ),
26
- __( 'Add-ons', 'shortcodes-ultimate' ),
27
- sprintf(
28
- '<span style="color:#2afd39">&#9733; %s</span>',
29
- __( 'Add-ons', 'shortcodes-ultimate' )
30
- ),
31
- $this->get_capability(),
32
- $this->plugin_prefix . 'addons',
33
- array( $this, 'the_menu_page' )
34
- );
35
-
36
- }
37
-
38
-
39
- /**
40
- * Add help tabs and set help sidebar at Add-ons page.
41
- *
42
- * @since 5.0.0
43
- * @param WP_Screen $screen WP_Screen instance.
44
- */
45
- public function add_help_tabs( $screen ) {
46
-
47
- if ( ! $this->is_component_page() ) {
48
- return;
49
- }
50
-
51
- $screen->add_help_tab(
52
- array(
53
- 'id' => 'shortcodes-ultimate-addons',
54
- 'title' => __( 'Add-ons', 'shortcodes-ultimate' ),
55
- 'content' => $this->get_template( 'admin/partials/help/addons' ),
56
- )
57
- );
58
-
59
- $screen->set_help_sidebar( $this->get_template( 'admin/partials/help/sidebar' ) );
60
-
61
- }
62
-
63
-
64
- /**
65
- * Enqueue JavaScript(s) and Stylesheet(s) for the component.
66
- *
67
- * @since 5.0.0
68
- */
69
- public function enqueue_scripts() {
70
-
71
- if ( ! $this->is_component_page() ) {
72
- return;
73
- }
74
-
75
- wp_enqueue_style(
76
- 'shortcodes-ultimate-admin',
77
- plugins_url( 'css/admin.css', __FILE__ ),
78
- false,
79
- filemtime( plugin_dir_path( __FILE__ ) . 'css/admin.css' )
80
- );
81
-
82
- }
83
-
84
- /**
85
- * Retrieve the collection of plugin add-ons.
86
- *
87
- * @since 5.0.0
88
- * @access private
89
- * @return array The plugin add-ons collection.
90
- */
91
- public function get_addons() {
92
-
93
- $addons = (array) su_get_config( 'addons', array() );
94
-
95
- foreach ( $addons as $index => $addon ) {
96
-
97
- $addon_id = sanitize_key( $addons[ $index ]['id'] );
98
- $addons[ $index ]['image'] = plugins_url( "images/addons/{$addon_id}.png", __FILE__ );
99
-
100
- }
101
-
102
- return $addons;
103
-
104
- }
105
-
106
- public function get_addon_permalink( $addon ) {
107
-
108
- $utm = array( 'admin-menu', 'add-ons', 'wp-dashboard' );
109
-
110
- // phpcs:disable
111
- if ( isset( $_GET['from-generator'] ) ) {
112
- $utm[0] = 'generator';
113
- }
114
- // phpcs:enable
115
-
116
- return su_get_utm_link( $addon['permalink'], $utm );
117
-
118
- }
119
-
120
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/class-shortcodes-ultimate-admin-pro-features.php CHANGED
@@ -1,155 +1,141 @@
1
  <?php
2
 
3
- class Shortcodes_Ultimate_Admin_Pro_Features {
4
-
5
- public function __construct() {}
6
-
7
- public function register_shortcodes() {
8
-
9
- if ( did_action( 'su/extra/ready' ) ) {
10
- return;
11
- }
12
-
13
- foreach ( $this->get_shortcodes() as $shortcode ) {
14
-
15
- su_add_shortcode(
16
- wp_parse_args(
17
- $shortcode,
18
- array(
19
- 'group' => 'extra',
20
- 'image' => $this->get_image_url( 'icon-available-shortcodes.png' ),
21
- 'icon' => $this->get_image_url( 'icon-generator.png' ),
22
- 'desc' => '',
23
- 'callback' => '__return_empty_string',
24
- 'atts' => array(),
25
- 'generator_callback' => array( $this, 'generator_callback' ),
26
- )
27
- )
28
- );
29
-
30
- }
31
-
32
- }
33
-
34
- public function register_group( $groups ) {
35
-
36
- if ( did_action( 'su/extra/ready' ) ) {
37
- return $groups;
38
- }
39
-
40
- $groups['extra'] = _x( 'PRO Shortcodes', 'Custom shortcodes group name', 'shortcodes-ultimate' );
41
-
42
- return $groups;
43
-
44
- }
45
-
46
- public function generator_callback( $shortcode ) {
47
- su_partial(
48
- 'admin/partials/pro-features/generator.php',
49
- array(
50
- 'shortcode' => $shortcode,
51
- 'image_url' => $this->get_image_url(),
52
- )
53
- );
54
- }
55
-
56
- public function get_image_url( $path = '' ) {
57
- return plugin_dir_url( __FILE__ ) . 'images/pro-features/' . $path;
58
- }
59
-
60
- private function get_shortcodes() {
61
-
62
- return array(
63
- array(
64
- 'id' => 'splash',
65
- 'name' => __( 'Splash screen', 'shortcodes-ultimate' ),
66
- ),
67
- array(
68
- 'id' => 'exit_popup',
69
- 'name' => __( 'Exit popup', 'shortcodes-ultimate' ),
70
- ),
71
- array(
72
- 'id' => 'panel',
73
- 'name' => __( 'Panel', 'shortcodes-ultimate' ),
74
- ),
75
- array(
76
- 'id' => 'photo_panel',
77
- 'name' => __( 'Photo panel', 'shortcodes-ultimate' ),
78
- ),
79
- array(
80
- 'id' => 'icon_panel',
81
- 'name' => __( 'Icon panel', 'shortcodes-ultimate' ),
82
- ),
83
- array(
84
- 'id' => 'icon_text',
85
- 'name' => __( 'Text with icon', 'shortcodes-ultimate' ),
86
- ),
87
- array(
88
- 'id' => 'progress_pie',
89
- 'name' => __( 'Progress pie', 'shortcodes-ultimate' ),
90
- ),
91
- array(
92
- 'id' => 'progress_bar',
93
- 'name' => __( 'Progress bar', 'shortcodes-ultimate' ),
94
- ),
95
- array(
96
- 'id' => 'member',
97
- 'name' => __( 'Member', 'shortcodes-ultimate' ),
98
- ),
99
- array(
100
- 'id' => 'section',
101
- 'name' => __( 'Section', 'shortcodes-ultimate' ),
102
- ),
103
- array(
104
- 'id' => 'pricing_table',
105
- 'name' => __( 'Pricing table', 'shortcodes-ultimate' ),
106
- ),
107
- array(
108
- 'id' => 'testimonial',
109
- 'name' => __( 'Testimonial', 'shortcodes-ultimate' ),
110
- ),
111
- array(
112
- 'id' => 'icon',
113
- 'name' => __( 'Icon', 'shortcodes-ultimate' ),
114
- ),
115
- array(
116
- 'id' => 'content_slider',
117
- 'name' => __( 'Content slider', 'shortcodes-ultimate' ),
118
- ),
119
- array(
120
- 'id' => 'shadow',
121
- 'name' => __( 'Shadow', 'shortcodes-ultimate' ),
122
- ),
123
- );
124
-
125
- }
126
-
127
- public function add_generator_cta( $shortcodes ) {
128
-
129
- if ( did_action( 'su/skins/ready' ) ) {
130
- return $shortcodes;
131
- }
132
-
133
- $cta = sprintf(
134
- '<span>%1$s</span><br><a href="%3$s" target="_blank" class="button">%2$s &rarr;</a>',
135
- sprintf(
136
- // translators: %s will be replaced with add-on name (Additional Skins)
137
- __( 'Get more styles for this shortcode with the %s add-on', 'shortcodes-ultimate' ),
138
- '<nobr>' . __( 'Additional Skins', 'shortcodes-ultimate' ) . '</nobr>'
139
- ),
140
- __( 'Details & Pricing', 'shortcodes-ultimate' ),
141
- 'https://getshortcodes.com/add-ons/additional-skins/'
142
- );
143
-
144
- foreach ( array( 'heading', 'tabs', 'tab', 'accordion', 'spoiler', 'quote' ) as $shortcode ) {
145
-
146
- unset( $shortcodes[ $shortcode ]['note'] );
147
- $shortcodes[ $shortcode ]['generator_cta'] = $cta;
148
-
149
- }
150
-
151
- return $shortcodes;
152
-
153
- }
154
-
155
- }
1
  <?php
2
 
3
+ class Shortcodes_Ultimate_Admin_Pro_Features
4
+ {
5
+ public function __construct()
6
+ {
7
+ }
8
+
9
+ public function register_shortcodes()
10
+ {
11
+ if ( did_action( 'su/extra/ready' ) ) {
12
+ return;
13
+ }
14
+ foreach ( $this->get_shortcodes() as $shortcode ) {
15
+ su_add_shortcode( wp_parse_args( $shortcode, array(
16
+ 'group' => 'extra',
17
+ 'image' => $this->get_image_url( 'icon-available-shortcodes.png' ),
18
+ 'icon' => $this->get_image_url( 'icon-generator.png' ),
19
+ 'desc' => '',
20
+ 'callback' => '__return_empty_string',
21
+ 'atts' => array(),
22
+ 'generator_callback' => array( $this, 'generator_callback' ),
23
+ ) ) );
24
+ }
25
+ }
26
+
27
+ public function register_group( $groups )
28
+ {
29
+ if ( did_action( 'su/extra/ready' ) ) {
30
+ return $groups;
31
+ }
32
+ $groups['extra'] = _x( 'Pro Shortcodes', 'Custom shortcodes group name', 'shortcodes-ultimate' );
33
+ return $groups;
34
+ }
35
+
36
+ public function generator_callback( $shortcode )
37
+ {
38
+ su_partial( 'admin/partials/pro-features/generator.php', array(
39
+ 'shortcode' => $shortcode,
40
+ 'image_url' => $this->get_image_url(),
41
+ ) );
42
+ }
43
+
44
+ public function get_image_url( $path = '' )
45
+ {
46
+ return plugin_dir_url( __FILE__ ) . 'images/pro-features/' . $path;
47
+ }
48
+
49
+ private function get_shortcodes()
50
+ {
51
+ return array(
52
+ array(
53
+ 'id' => 'splash',
54
+ 'name' => __( 'Splash screen', 'shortcodes-ultimate' ),
55
+ ),
56
+ array(
57
+ 'id' => 'exit_popup',
58
+ 'name' => __( 'Exit popup', 'shortcodes-ultimate' ),
59
+ ),
60
+ array(
61
+ 'id' => 'panel',
62
+ 'name' => __( 'Panel', 'shortcodes-ultimate' ),
63
+ ),
64
+ array(
65
+ 'id' => 'photo_panel',
66
+ 'name' => __( 'Photo panel', 'shortcodes-ultimate' ),
67
+ ),
68
+ array(
69
+ 'id' => 'icon_panel',
70
+ 'name' => __( 'Icon panel', 'shortcodes-ultimate' ),
71
+ ),
72
+ array(
73
+ 'id' => 'icon_text',
74
+ 'name' => __( 'Text with icon', 'shortcodes-ultimate' ),
75
+ ),
76
+ array(
77
+ 'id' => 'progress_pie',
78
+ 'name' => __( 'Progress pie', 'shortcodes-ultimate' ),
79
+ ),
80
+ array(
81
+ 'id' => 'progress_bar',
82
+ 'name' => __( 'Progress bar', 'shortcodes-ultimate' ),
83
+ ),
84
+ array(
85
+ 'id' => 'member',
86
+ 'name' => __( 'Member', 'shortcodes-ultimate' ),
87
+ ),
88
+ array(
89
+ 'id' => 'section',
90
+ 'name' => __( 'Section', 'shortcodes-ultimate' ),
91
+ ),
92
+ array(
93
+ 'id' => 'pricing_table',
94
+ 'name' => __( 'Pricing table', 'shortcodes-ultimate' ),
95
+ ),
96
+ array(
97
+ 'id' => 'testimonial',
98
+ 'name' => __( 'Testimonial', 'shortcodes-ultimate' ),
99
+ ),
100
+ array(
101
+ 'id' => 'icon',
102
+ 'name' => __( 'Icon', 'shortcodes-ultimate' ),
103
+ ),
104
+ array(
105
+ 'id' => 'content_slider',
106
+ 'name' => __( 'Content slider', 'shortcodes-ultimate' ),
107
+ ),
108
+ array(
109
+ 'id' => 'shadow',
110
+ 'name' => __( 'Shadow', 'shortcodes-ultimate' ),
111
+ )
112
+ );
113
+ }
114
+
115
+ public function add_generator_cta( $shortcodes )
116
+ {
117
+ if ( did_action( 'su/skins/ready' ) || su_fs()->can_use_premium_code() ) {
118
+ return $shortcodes;
119
+ }
120
+ $cta = sprintf(
121
+ '<span>%1$s</span><br><a href="%3$s" target="_blank" class="button">%2$s &rarr;</a>',
122
+ // translators: please keep the original markup with <nobr> tags
123
+ __( 'Get more styles for this shortcode with the <nobr>PRO version</nobr>', 'shortcodes-ultimate' ),
124
+ __( 'Upgrade to PRO', 'shortcodes-ultimate' ),
125
+ esc_attr( su_get_utm_link( 'https://getshortcodes.com/pricing/', array( 'wp-admin', 'generator', 'style' ) ) )
126
+ );
127
+ foreach ( array(
128
+ 'heading',
129
+ 'tabs',
130
+ 'tab',
131
+ 'accordion',
132
+ 'spoiler',
133
+ 'quote'
134
+ ) as $shortcode ) {
135
+ unset( $shortcodes[$shortcode]['note'] );
136
+ $shortcodes[$shortcode]['generator_cta'] = $cta;
137
+ }
138
+ return $shortcodes;
139
+ }
140
+
141
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/class-shortcodes-ultimate-admin-settings.php CHANGED
File without changes
admin/class-shortcodes-ultimate-admin-top-level.php CHANGED
File without changes
admin/class-shortcodes-ultimate-admin.php CHANGED
File without changes
admin/class-shortcodes-ultimate-notice-rate.php CHANGED
@@ -8,47 +8,41 @@
8
  * @package Shortcodes_Ultimate
9
  * @subpackage Shortcodes_Ultimate/admin
10
  */
11
- final class Shortcodes_Ultimate_Notice_Rate extends Shortcodes_Ultimate_Notice {
12
-
13
- /**
14
- * Initialize the class and set its properties.
15
- *
16
- * @since 5.0.0
17
- */
18
- public function __construct( $notice_id, $template_file ) {
19
-
20
- parent::__construct( $notice_id, $template_file );
21
-
22
- $this->defer_delay = 3 * DAY_IN_SECONDS;
23
- $this->first_time_delay = 7 * DAY_IN_SECONDS;
24
-
25
- }
26
-
27
- /**
28
- * Display the notice.
29
- *
30
- * @since 5.0.0
31
- */
32
- public function display_notice() {
33
-
34
- // Make sure this is the Plugins screen
35
- if ( $this->get_current_screen_id() !== 'plugins' ) {
36
- return;
37
- }
38
-
39
- // Check user capability
40
- if ( ! $this->current_user_can_view() ) {
41
- return;
42
- }
43
-
44
- // Make sure the notice is not dismissed
45
- if ( $this->is_dismissed() ) {
46
- return;
47
- }
48
-
49
- // Display the notice
50
- $this->include_template();
51
-
52
- }
53
-
54
- }
8
  * @package Shortcodes_Ultimate
9
  * @subpackage Shortcodes_Ultimate/admin
10
  */
11
+ final class Shortcodes_Ultimate_Notice_Rate extends Shortcodes_Ultimate_Notice
12
+ {
13
+ /**
14
+ * Initialize the class and set its properties.
15
+ *
16
+ * @since 5.0.0
17
+ */
18
+ public function __construct( $notice_id, $template_file )
19
+ {
20
+ parent::__construct( $notice_id, $template_file );
21
+ $this->defer_delay = 3 * DAY_IN_SECONDS;
22
+ $this->first_time_delay = 7 * DAY_IN_SECONDS;
23
+ }
24
+
25
+ /**
26
+ * Display the notice.
27
+ *
28
+ * @since 5.0.0
29
+ */
30
+ public function display_notice()
31
+ {
32
+ // Make sure this is the Plugins screen
33
+ if ( $this->get_current_screen_id() !== 'plugins' ) {
34
+ return;
35
+ }
36
+ // Check user capability
37
+ if ( !$this->current_user_can_view() ) {
38
+ return;
39
+ }
40
+ // Make sure the notice is not dismissed
41
+ if ( $this->is_dismissed() ) {
42
+ return;
43
+ }
44
+ // Display the notice
45
+ $this->include_template();
46
+ }
47
+
48
+ }
 
 
 
 
 
 
admin/class-shortcodes-ultimate-notice-unsafe-features.php CHANGED
File without changes
admin/class-shortcodes-ultimate-notice.php CHANGED
File without changes
admin/class-shortcodes-ultimate-widget.php CHANGED
File without changes
admin/css/admin.css CHANGED
@@ -1 +1 @@
1
- .su-admin-u-hidden{display:none}.su-admin-c-button{display:inline-block;padding:7px 15px;border-radius:3px;background:#0073d7;color:#fff;text-align:center;text-decoration:none;text-transform:uppercase;text-shadow:0 1px 2px #004581;font-weight:600;font-size:.85rem;cursor:pointer}.su-admin-c-button:hover{background:#2688dd;color:#fff;text-decoration:none}.su-admin-c-button:active,.su-admin-c-button:focus{background:#0056a1;color:#fff;text-decoration:none}body.toplevel_page_shortcodes-ultimate{background:#fff}body.toplevel_page_shortcodes-ultimate .notice,body.toplevel_page_shortcodes-ultimate .updated{display:none!important}.su-admin-about{margin:60px auto;padding-right:10px}@media screen and (min-width:783px){.su-admin-about{margin:100px auto;padding-right:20px}}.su-admin-about-page-header{margin:0 auto;max-width:540px;text-align:center}.su-admin-about-page-header img{width:64px;height:64px}.su-admin-about-page-header h1{margin:25px 0 10px;padding:0;font-weight:700;font-size:1.45rem}.su-admin-about-page-header p{margin:0;font-size:.9rem}@media only screen and (min-width:783px){.su-admin-about-page-header img{width:84px;height:84px}.su-admin-about-page-header h1{margin:30px 0 10px;font-size:2rem}.su-admin-about-page-header p{font-size:1rem}}.su-admin-about-getting-started{margin:30px auto 0;max-width:960px}.su-admin-about-getting-started-video{position:relative;padding-top:56.25%;background:#f5f5f5}@-webkit-keyframes su-admin-about-getting-started-video-loading{0%{opacity:1}60%{opacity:1}80%{opacity:0}100%{opacity:1}}@keyframes su-admin-about-getting-started-video-loading{0%{opacity:1}60%{opacity:1}80%{opacity:0}100%{opacity:1}}.su-admin-about-getting-started-video-loading{-webkit-animation:su-admin-about-getting-started-video-loading 2s infinite;animation:su-admin-about-getting-started-video-loading 2s infinite}.su-admin-about-getting-started-video-button,.su-admin-about-getting-started-video-iframe{position:absolute;top:0;right:0;bottom:0;left:0;width:100%;height:100%}.su-admin-about-getting-started-video-button{display:flex;align-items:center;flex-direction:column;justify-content:center;margin:0;padding:0;border:none;border-radius:3px;background:#ccc url(../images/pages/about/poster.jpg) no-repeat;background-size:cover;color:inherit;font-size:100%;font-family:inherit;cursor:pointer;-webkit-appearance:none;-moz-appearance:none}.su-admin-about-getting-started-video-button.su-admin-u-hidden{display:none}.su-admin-about-getting-started-video-button svg{width:64px;height:64px;color:#0073d7;transition:-webkit-transform .4s ease;transition:transform .4s ease;transition:transform .4s ease,-webkit-transform .4s ease;-webkit-transform:scale(1);transform:scale(1)}.su-admin-about-getting-started-video-button:active svg,.su-admin-about-getting-started-video-button:focus svg,.su-admin-about-getting-started-video-button:hover svg{-webkit-transform:scale(1.2);transform:scale(1.2)}.su-admin-about-getting-started-video-button span{margin-top:20px;color:#000;text-shadow:0 1px 3px #fff;font-weight:500;font-size:.9rem}.su-admin-about-getting-started p{margin:1rem 0 0}@media only screen and (min-width:783px){.su-admin-about-getting-started{margin:80px auto 0}.su-admin-about-getting-started-video-button span{font-size:1rem}.su-admin-about-getting-started-video-button svg{width:80px;height:80px}}.su-admin-about-popular{margin-top:60px}.su-admin-about-popular h2{margin:0;text-align:center;text-transform:capitalize;font-weight:700;font-size:1.45rem}.su-admin-about-popular p{margin:15px auto 0;max-width:540px;text-align:center;font-size:.9rem}.su-admin-about-popular-grid{margin:40px auto 0;max-width:400px}.su-admin-about-popular-item{display:flex;align-items:flex-start;margin:0 0 25px}.su-admin-about-popular-item-icon{flex:0 0 auto;margin-right:15px;background:#fff}.su-admin-about-popular-item-title{display:block;margin-bottom:5px;text-transform:capitalize;font-weight:700;font-size:1rem;line-height:24px}.su-admin-about-popular-item-description{color:#777}.su-admin-about-popular-bottom{margin-top:20px;text-align:center}.su-admin-about-popular-bottom .button{display:inline-flex;align-items:center;padding:.4rem 1.2rem;font-weight:500;font-size:.9rem;text-transform:uppercase}.su-admin-about-popular-bottom svg{margin:-2px 0 0 7.4px}@media only screen and (min-width:783px){.su-admin-about-popular{margin-top:100px}.su-admin-about-popular h2{font-size:2rem}.su-admin-about-popular p{margin-top:20px;font-size:1rem}.su-admin-about-popular-grid{display:flex;flex-wrap:wrap;justify-content:space-between;margin:60px auto 0;max-width:640px}.su-admin-about-popular-item{flex:0 0 45%;margin:0 0 35px}}.su-admin-about-upgrade{position:relative;margin:60px -10px 0;padding:35px 20px 23px;max-width:800px;background:linear-gradient(to bottom,#282828,#000);color:#fff}.su-admin-about-upgrade::before{position:absolute;top:0;right:0;left:0;display:block;width:100%;height:5px;background-image:linear-gradient(45deg,#d268f8 0,#d268f8 12.5%,#f868b2 12.5%,#f868b2 25%,#f88a68 25%,#f88a68 37.5%,#f8f568 37.5%,#f8f568 50%,#8ef868 50%,#8ef868 62.5%,#68f8ae 62.5%,#68f8ae 75%,#68d6f8 75%,#68d6f8 87.5%,#686af8 87.5%,#686af8 100%);content:''}.su-admin-about-upgrade-features{flex:0 0 64%}.su-admin-about-upgrade-features h2{margin:0;color:#fff;font-weight:700;font-size:1.45rem}.su-admin-about-upgrade-features ul{display:grid;margin:30px 0 0;grid-template-columns:repeat(auto-fit,minmax(215px,1fr));grid-gap:10px 20px}.su-admin-about-upgrade-features li{position:relative;box-sizing:border-box;margin:0;padding:0 0 0 22px;font-size:.9rem;line-height:1.5}.su-admin-about-upgrade-features li::before{position:absolute;top:0;left:0;display:block;width:12px;height:1.35rem;background:0 50% url(../images/pages/about/check.svg) no-repeat;content:''}.su-admin-about-upgrade-widget{display:flex;flex:0 0 30%;flex-direction:column;justify-content:center;margin-top:35px}.su-admin-about-upgrade-widget-price{display:flex;justify-content:center;margin-bottom:35px}.su-admin-about-upgrade-widget-price-currency,.su-admin-about-upgrade-widget-price-decimal{color:#ddd;font-weight:500;font-size:25px;line-height:.75}.su-admin-about-upgrade-widget-price-integer{margin:0 5px 0 2px;font-weight:700;font-size:65px;line-height:.7}.su-admin-about-upgrade-widget-price-dec-per{display:flex;align-self:stretch;flex-direction:column;justify-content:space-between}.su-admin-about-upgrade-widget-price-period{color:#a2a2a2;font-size:15px;line-height:.75}.su-admin-about-upgrade-widget-button{display:block;padding:15px;font-size:1rem;line-height:1.5}@media only screen and (min-width:783px){.su-admin-about-upgrade{display:flex;justify-content:space-between;margin:100px auto 0;padding:50px 40px;border-radius:5px}.su-admin-about-upgrade::before{border-top-left-radius:5px;border-top-right-radius:5px}.su-admin-about-upgrade-features h2{font-size:1.65rem}.su-admin-about-upgrade-widget{margin:0}}.su-admin-about-help{margin-top:100px}.su-admin-about-help h2{margin:0;text-align:center;text-transform:capitalize;font-weight:700;font-size:1.45rem}@media only screen and (min-width:783px){.su-admin-about-help h2{font-size:2rem}}.su-admin-about-help-menu{display:flex;justify-content:center;margin-top:40px}.su-admin-about-help-menu ul{margin:0}.su-admin-about-help-menu li{margin:0}.su-admin-about-help-menu li+li{margin-top:10px}.su-admin-about-help-menu a{position:relative;display:block;padding-left:30px;text-decoration:none;font-weight:500;font-size:1rem;line-height:1.5}.su-admin-about-help-menu a:active,.su-admin-about-help-menu a:focus,.su-admin-about-help-menu a:hover{text-decoration:underline}.su-admin-about-help-menu svg{position:absolute;top:.225rem;left:0;width:1.1rem;height:1.1rem;color:#333}.su-admin-about-help-menu em{padding:.15rem .3rem;border-radius:3px;background:#f1f1f1;color:#000;font-weight:700;font-style:normal;font-size:.8rem;line-height:1}@media only screen and (min-width:783px){.su-admin-about-help-menu ul{display:flex}.su-admin-about-help-menu li{flex:0 1 auto}.su-admin-about-help-menu li+li{margin:0 0 0 40px}}.su-admin-addons .notice{display:none!important}.su-admin-addons-list{display:flex;flex-wrap:wrap;margin-top:22px}.su-admin-addons-item{position:relative;flex:0 0 300px;box-sizing:border-box;margin:0 22px 22px 0;padding:33px 22px;max-width:100%;border-radius:5px;background:#fff;background:linear-gradient(to bottom,#fff 0,#fff 30%,#f7f7f7 100%);box-shadow:0 1px 2px rgba(0,0,0,.1);transition:box-shadow .2s ease,-webkit-transform .2s ease;transition:transform .2s ease,box-shadow .2s ease;transition:transform .2s ease,box-shadow .2s ease,-webkit-transform .2s ease}.su-admin-addons-item:hover{background:#fff;box-shadow:0 0 12px rgba(0,0,0,.15);-webkit-transform:scale(1.03);transform:scale(1.03)}.su-admin-addons-item:hover .su-admin-addons-item-image{-webkit-transform:scale(1.05);transform:scale(1.05)}.su-admin-addons-item-content{text-align:center}.su-admin-addons-item-image{margin:0 0 22px;padding:0;width:80px;height:80px;border:none;transition:-webkit-transform .2s ease;transition:transform .2s ease;transition:transform .2s ease,-webkit-transform .2s ease;-o-object-fit:cover;object-fit:cover}.su-admin-addons-item-title{margin:0 0 11px;color:#0073aa;font-size:1.05rem;line-height:1}.su-admin-addons-item-description{margin:0 0 22px;color:#777;font-size:.9rem;line-height:1.2}.su-admin-addons-item-overlay{position:absolute;top:0;right:0;bottom:0;left:0;left:0;width:100%;height:100%;text-indent:-999%}.su-admin-settings-page-title{display:flex;align-items:center}.su-admin-settings-page-title img{margin-right:13px}.su-admin-settings-form{max-width:800px}.su-admin-settings-form .CodeMirror{height:auto;border:1px solid #7e8993}.su-admin-settings-form .CodeMirror-scroll{min-height:100px;max-height:80vh}.su-admin-settings-form details{margin:20px 0}.su-admin-settings-form summary{font-weight:600;cursor:pointer}.su-admin-settings-form details>article{margin-top:20px}.su-admin-settings-form p.description{margin-top:10px}.su-admin-settings-bottom-menu li{position:relative;display:inline-block;margin:0}.su-admin-settings-bottom-menu li+li{margin-left:32px}.su-admin-settings-bottom-menu li+li::before{position:absolute;top:20%;left:-15px;display:block;height:70%;border-left:1px solid #ccd0d4;content:''}
1
+ .su-admin-u-hidden{display:none}.su-admin-c-button{display:inline-block;padding:7px 15px;border-radius:3px;background:#0073d7;color:#fff;text-align:center;text-decoration:none;text-transform:uppercase;text-shadow:0 1px 2px #004581;font-weight:600;font-size:.85rem;cursor:pointer}.su-admin-c-button:hover{background:#2688dd;color:#fff;text-decoration:none}.su-admin-c-button:active,.su-admin-c-button:focus{background:#0056a1;color:#fff;text-decoration:none}.su-admin-c-notice-pro{margin:-10px -12px 12px -10px;padding:20px;background:#fff8c7;box-shadow:0 1px 10px rgba(148,128,0,.4)}.su-admin-c-notice-pro p{margin:0;font-weight:500;font-size:.95rem}.su-admin-c-notice-pro p+p{margin:15px 0 0}.su-admin-c-notice-pro .button{text-transform:uppercase;font-weight:700}@media screen and (min-width:783px){.su-admin-c-notice-pro{display:flex;align-items:center;justify-content:space-between;margin:-10px -20px 12px -22px;padding:15px 20px}.su-admin-c-notice-pro p+p{margin:0 0 0 20px}.su-admin-c-notice-pro .button{padding:5px 15px}}body.toplevel_page_shortcodes-ultimate{background:#fff}body.toplevel_page_shortcodes-ultimate .notice,body.toplevel_page_shortcodes-ultimate .updated{display:none!important}.su-admin-about{margin:60px auto;padding-right:10px}@media screen and (min-width:783px){.su-admin-about{margin:100px auto;padding-right:20px}}.su-admin-about-page-header{margin:0 auto;max-width:540px;text-align:center}.su-admin-about-page-header img{width:64px;height:64px}.su-admin-about-page-header h1{margin:25px 0 10px;padding:0;font-weight:700;font-size:1.45rem}.su-admin-about-page-header p{margin:0;font-size:.9rem}@media only screen and (min-width:783px){.su-admin-about-page-header img{width:84px;height:84px}.su-admin-about-page-header h1{margin:30px 0 10px;font-size:2rem}.su-admin-about-page-header p{font-size:1rem}}.su-admin-about-getting-started{margin:30px auto 0;max-width:960px}.su-admin-about-getting-started-video{position:relative;padding-top:56.25%;background:#f5f5f5}@-webkit-keyframes su-admin-about-getting-started-video-loading{0%{opacity:1}60%{opacity:1}80%{opacity:0}100%{opacity:1}}@keyframes su-admin-about-getting-started-video-loading{0%{opacity:1}60%{opacity:1}80%{opacity:0}100%{opacity:1}}.su-admin-about-getting-started-video-loading{-webkit-animation:su-admin-about-getting-started-video-loading 2s infinite;animation:su-admin-about-getting-started-video-loading 2s infinite}.su-admin-about-getting-started-video-button,.su-admin-about-getting-started-video-iframe{position:absolute;top:0;right:0;bottom:0;left:0;width:100%;height:100%}.su-admin-about-getting-started-video-button{display:flex;align-items:center;flex-direction:column;justify-content:center;margin:0;padding:0;border:none;border-radius:3px;background:#ccc url(../images/pages/about/poster.jpg) no-repeat;background-size:cover;color:inherit;font-size:100%;font-family:inherit;cursor:pointer;-webkit-appearance:none;-moz-appearance:none}.su-admin-about-getting-started-video-button.su-admin-u-hidden{display:none}.su-admin-about-getting-started-video-button svg{width:64px;height:64px;color:#0073d7;transition:-webkit-transform .4s ease;transition:transform .4s ease;transition:transform .4s ease,-webkit-transform .4s ease;-webkit-transform:scale(1);transform:scale(1)}.su-admin-about-getting-started-video-button:active svg,.su-admin-about-getting-started-video-button:focus svg,.su-admin-about-getting-started-video-button:hover svg{-webkit-transform:scale(1.2);transform:scale(1.2)}.su-admin-about-getting-started-video-button span{margin-top:20px;color:#000;text-shadow:0 1px 3px #fff;font-weight:500;font-size:.9rem}.su-admin-about-getting-started p{margin:1rem 0 0}@media only screen and (min-width:783px){.su-admin-about-getting-started{margin:80px auto 0}.su-admin-about-getting-started-video-button span{font-size:1rem}.su-admin-about-getting-started-video-button svg{width:80px;height:80px}}.su-admin-about-popular{margin-top:60px}.su-admin-about-popular h2{margin:0;text-align:center;text-transform:capitalize;font-weight:700;font-size:1.45rem}.su-admin-about-popular p{margin:15px auto 0;max-width:540px;text-align:center;font-size:.9rem}.su-admin-about-popular-grid{margin:40px auto 0;max-width:400px}.su-admin-about-popular-item{display:flex;align-items:flex-start;margin:0 0 25px}.su-admin-about-popular-item-icon{flex:0 0 auto;margin-right:15px;background:#fff}.su-admin-about-popular-item-title{display:block;margin-bottom:5px;text-transform:capitalize;font-weight:700;font-size:1rem;line-height:24px}.su-admin-about-popular-item-description{color:#777}.su-admin-about-popular-bottom{margin-top:20px;text-align:center}.su-admin-about-popular-bottom .button{display:inline-flex;align-items:center;padding:.4rem 1.2rem;text-transform:uppercase;font-weight:500;font-size:.9rem}.su-admin-about-popular-bottom svg{margin:-2px 0 0 7.4px}@media only screen and (min-width:783px){.su-admin-about-popular{margin-top:100px}.su-admin-about-popular h2{font-size:2rem}.su-admin-about-popular p{margin-top:20px;font-size:1rem}.su-admin-about-popular-grid{display:flex;flex-wrap:wrap;justify-content:space-between;margin:60px auto 0;max-width:640px}.su-admin-about-popular-item{flex:0 0 45%;margin:0 0 35px}}.su-admin-about-upgrade{position:relative;margin:60px -10px 0;padding:40px 25px 30px;max-width:800px;background:linear-gradient(to bottom,#282828,#000);color:#fff}.su-admin-about-upgrade::before{position:absolute;top:0;right:0;left:0;display:block;width:100%;height:5px;background-image:linear-gradient(45deg,#d268f8 0,#d268f8 12.5%,#f868b2 12.5%,#f868b2 25%,#f88a68 25%,#f88a68 37.5%,#f8f568 37.5%,#f8f568 50%,#8ef868 50%,#8ef868 62.5%,#68f8ae 62.5%,#68f8ae 75%,#68d6f8 75%,#68d6f8 87.5%,#686af8 87.5%,#686af8 100%);content:''}.su-admin-about-upgrade-features{flex:0 0 64%}.su-admin-about-upgrade-features h2{margin:0;color:#fff;text-align:center;font-weight:700;font-size:1.65rem}.su-admin-about-upgrade-features-list{display:flex;justify-content:center}.su-admin-about-upgrade-features-list ul{margin:30px 0 0}.su-admin-about-upgrade-features-list li{position:relative;box-sizing:border-box;margin:0;padding:0 0 0 22px;font-size:.9rem;line-height:1.5}.su-admin-about-upgrade-features-list li::before{position:absolute;top:0;left:0;display:block;width:12px;height:1.35rem;background:0 50% url(../images/pages/about/check.svg) no-repeat;content:''}.su-admin-about-upgrade-features-list li+li{margin-top:5px}.su-admin-about-upgrade-buy{display:flex;flex:0 0 30%;flex-direction:column;justify-content:center;margin-top:35px}.su-admin-about-upgrade-buy-pricing{margin-bottom:25px;text-align:center}.su-admin-about-upgrade-buy-pricing-price{display:flex;justify-content:center}.su-admin-about-upgrade-buy-pricing-currency{color:#ddd;font-weight:500;font-size:25px;line-height:1}.su-admin-about-upgrade-buy-pricing-value{margin:0 5px 0 2px;vertical-align:top;font-weight:700;font-size:65px;line-height:.7}.su-admin-about-upgrade-buy-pricing-period{margin-top:10px;color:#a2a2a2;font-size:.8rem}.su-admin-about-upgrade-buy-button{display:block;padding:15px;font-size:1rem;line-height:1.5}@media only screen and (min-width:783px){.su-admin-about-upgrade{display:flex;justify-content:space-between;margin:100px auto 0;padding:50px 40px;border-radius:5px}.su-admin-about-upgrade::before{border-top-left-radius:5px;border-top-right-radius:5px}.su-admin-about-upgrade-features h2{font-size:1.65rem;text-align:left}.su-admin-about-upgrade-features-list{display:block}.su-admin-about-upgrade-features-list ul{display:grid;grid-template-columns:repeat(auto-fit,minmax(215px,1fr));grid-gap:10px 20px}.su-admin-about-upgrade-features-list li+li{margin-top:0}.su-admin-about-upgrade-buy{margin:0}}.su-admin-about-help{margin-top:100px}.su-admin-about-help h2{margin:0;text-align:center;text-transform:capitalize;font-weight:700;font-size:1.45rem}@media only screen and (min-width:783px){.su-admin-about-help h2{font-size:2rem}}.su-admin-about-help-menu{display:flex;justify-content:center;margin-top:40px}.su-admin-about-help-menu ul{margin:0}.su-admin-about-help-menu li{margin:0}.su-admin-about-help-menu li+li{margin-top:10px}.su-admin-about-help-menu a{position:relative;display:block;padding-left:30px;text-decoration:none;font-weight:500;font-size:1rem;line-height:1.5}.su-admin-about-help-menu a:active,.su-admin-about-help-menu a:focus,.su-admin-about-help-menu a:hover{text-decoration:underline}.su-admin-about-help-menu svg{position:absolute;top:.225rem;left:0;width:1.1rem;height:1.1rem;color:#333}.su-admin-about-help-menu em{padding:.15rem .3rem;border-radius:3px;background:#f1f1f1;color:#000;font-weight:700;font-style:normal;font-size:.8rem;line-height:1}@media only screen and (min-width:783px){.su-admin-about-help-menu ul{display:flex}.su-admin-about-help-menu li{flex:0 1 auto}.su-admin-about-help-menu li+li{margin:0 0 0 40px}}.su-admin-settings-page-title{display:flex!important;align-items:center}.su-admin-settings-page-title img{margin-right:13px}.su-admin-settings-form{max-width:800px}.su-admin-settings-form .CodeMirror{height:auto;border:1px solid #7e8993}.su-admin-settings-form .CodeMirror-scroll{min-height:100px;max-height:80vh}.su-admin-settings-form details{margin:20px 0}.su-admin-settings-form summary{font-weight:600;cursor:pointer}.su-admin-settings-form details>article{margin-top:20px}.su-admin-settings-form p.description{margin-top:10px}.su-admin-settings-bottom-menu li{position:relative;display:inline-block;margin:0}.su-admin-settings-bottom-menu li+li{margin-left:32px}.su-admin-settings-bottom-menu li+li::before{position:absolute;top:20%;left:-15px;display:block;height:70%;border-left:1px solid #ccd0d4;content:''}
admin/css/generator.css CHANGED
@@ -1 +1 @@
1
- .su-generator-clearfix:after,.su-generator-clearfix:before{display:table;content:' '}.su-generator-clearfix:after{clear:both}.su-generator-clear{height:0;clear:both;overflow:hidden}.su-generator-hidden{display:none!important}.su-generator-loading{min-height:60px;background:50% 50% url(../images/spinner.gif) no-repeat!important}.su-generator-loading *{visibility:hidden}.su-generator-button img{margin:-1px 2px 0 -5px;vertical-align:middle}.wp-media-buttons .su-generator-button img{margin:-1px -1px 0 -4px;vertical-align:middle}#su-generator-wrap{display:none}#su-generator{position:relative;width:85%;max-width:1000px;margin:60px auto;padding:20px;background:#fff;box-shadow:0 2px 25px #000;transition:max-width .2s}#su-generator.su-generator-narrow{max-width:500px}#su-generator-tools{margin:0 20px 20px 0}#su-generator-tools span{display:inline-block;width:1px;height:1em;margin:0 .5em;border-right:1px dotted #555;vertical-align:middle}#su-generator-tools a{text-decoration:none}#su-generator-tools a.su-add-ons{display:inline-block;padding:3px 8px;background:#ff562d;color:#fff;font-weight:700;border-radius:3px;border:1px solid #f2522b;text-shadow:1px 1px 1px #a6381d}#su-generator-tools a.su-add-ons:active,#su-generator-tools a.su-add-ons:focus,#su-generator-tools a.su-add-ons:hover{background:#ff7857}#su-generator-search{width:100%;margin-bottom:5px;padding:10px 10px 10px 42px;background:5px 50% url(../images/search.png) no-repeat;font-size:1.3em}#su-generator-search-pro-tip{margin:0 0 30px 0;color:#999;font-style:italic;text-align:right;font-size:.9em}#su-generator-filter{margin:0 -20px;padding:14px 20px;border-top:1px solid #ccc;border-bottom:1px solid #ccc;background:#eee;color:#555;text-align:center;line-height:24px}#su-generator-filter a,#su-generator-filter strong{display:inline-block;margin:0 1em;line-height:1}#su-generator-filter a{border-bottom:1px dotted #ccc;text-decoration:none}#su-generator-choices{margin-top:20px;text-align:left}#su-generator-choices>span{position:relative;display:block;width:20%;height:28px;min-width:130px;padding:0 5px 0 30px;float:left;overflow:hidden;box-sizing:border-box;border-bottom:1px dotted #e5e5e5;color:#222;vertical-align:top;text-align:left;line-height:28px;cursor:pointer}#su-generator-choices span:hover{border-bottom:1px solid #333;background:#333;color:#fff}#su-generator-choices span img{position:absolute;top:7px;left:7px;width:14px;height:14px}#su-generator-choices span i{position:absolute;top:1px;left:1px;display:block;width:26px;height:26px;color:#888;text-align:center;font-size:14px;line-height:26px}#su-generator-choices span:hover i{color:#fff}.su-generator-choice-first{outline:1px solid #09f;box-shadow:0 0 3px rgba(30,140,190,.8)}#su-generator-breadcrumbs{margin:0 -20px;padding:14px 20px;border-top:1px solid #ccc;border-bottom:1px solid #ccc;background:#eee;color:#555;line-height:24px}#su-generator-breadcrumbs span{margin-right:1em;font-weight:700}#su-generator-breadcrumbs small{color:#bbb;font-weight:400;font-size:.9em}.su-generator-note{position:relative;margin:0 -20px;padding:5px 20px;background:#ffffb8;border-bottom:1px solid #ccc;color:#333;line-height:18px}.su-generator-note-content{min-height:20px;margin-left:35px}.su-generator-note p{margin:10px 0}.su-generator-note a{text-decoration:underline}.su-generator-note i{position:absolute;top:15px;left:20px;display:block;width:1em;height:1em;color:#555;text-align:left;font-size:20px;line-height:1em}.su-generator-cta{position:relative;margin:0 -20px;padding:15px 20px;background:#e0efff;border-bottom:1px solid #ccc;color:#222}.su-generator-cta-content{display:flex;align-items:center;justify-content:space-between;line-height:21px}.su-generator-cta-content span{font-size:.9rem}.su-generator-cta-content .button{font-size:.9rem;margin-left:20px}.su-generator-cta-content nobr{white-space:nowrap;font-weight:700}#su-generator-settings .su-generator-attr-container{margin:0 -20px;padding:1.5em 20px;border-bottom:1px solid #ccc;box-shadow:0 1px 3px rgba(0,0,0,.1)}#su-generator-settings h5{text-transform:capitalize;font-weight:700}#su-generator-preview h5,#su-generator-settings h5{margin:0 0 15px 0;font-size:1em}.su-generator-attr-desc{margin-top:15px;color:#aaa;font-style:italic;line-height:1.6}.su-generator-attr-desc b{color:#999}.su-generator-px-units{position:relative;margin-right:15px}.su-generator-px-units:before{position:absolute;right:-18px;bottom:3px;display:block;width:15px;color:#999;content:'px';text-align:left;font-size:.9em}.su-generator-attr-desc b.su-generator-set-value{border-bottom:1px dotted #999;cursor:pointer}.su-generator-attr-desc b.su-generator-set-value:hover{border-bottom:1px dotted #333;color:#333}#su-generator-settings input[type=number],#su-generator-settings input[type=text],#su-generator-settings select,#su-generator-settings textarea{width:100%;height:auto;padding:10px}.su-generator-field-actions{padding-top:10px}.su-generator-field-actions .button,.su-generator-field-actions span{margin-right:5px}.su-generator-field-actions img{margin:0 6px 0 -4px;vertical-align:middle}.su-generator-icon-picker{height:0;margin:0 -20px;padding:0 20px;overflow:hidden;background:#eee;line-height:24px;transition:all .2s}.su-generator-icon-picker.su-generator-icon-picker-visible{height:auto;margin:1em -20px 0 -20px;padding:14px 20px;overflow:visible;border-top:1px solid #ccc;border-bottom:1px solid #ccc}.su-generator-icon-picker input{margin-bottom:15px}.su-generator-icon-picker i{display:block;width:24px;height:24px;margin-left:2px;float:left;color:#555;text-align:center;font-size:14px;line-height:24px;cursor:pointer}.su-generator-icon-picker i:hover{color:#000;font-size:24px}.su-generator-shadow-picker-field{position:relative;display:inline-block;width:22%;padding-right:3%;vertical-align:top}.su-generator-shadow-picker-field small{display:block;color:#ccc;line-height:1.35;margin-top:.75em}.su-generator-shadow-picker-field input{text-align:right}.su-generator-shadow-picker-field.su-generator-shadow-picker-color{width:25%;padding-right:0}.su-generator-shadow-picker-field.su-generator-shadow-picker-color input{text-align:left}.su-generator-shadow-picker-color{position:relative}.su-generator-shadow-picker-color-wheel{position:absolute;top:100%;right:0;z-index:9999;display:none;border:1px solid #aaa;border-radius:50%;background:#fff;box-shadow:0 2px 5px #ccc}.su-generator-border-picker-field{position:relative;display:inline-block;width:30%;padding-right:3%}.su-generator-border-picker-field small{display:block;color:#ccc}.su-generator-border-picker-field input{text-align:right}.su-generator-border-picker-field.su-generator-border-picker-color{width:34%;padding-right:0}.su-generator-border-picker-field.su-generator-border-picker-color input{text-align:left}.su-generator-border-picker-color{position:relative}.su-generator-border-picker-color-wheel{position:absolute;top:100%;right:0;z-index:9999;display:none;border:1px solid #aaa;border-radius:50%;background:#fff;box-shadow:0 2px 5px #ccc}.su-generator-range-picker .slider{width:420px;margin:10px 0 0 0!important;padding:0;float:left}.su-generator-range-picker .slider>.dragger{background:#fff!important}.su-generator-range-picker .slider:hover>.dragger{background:#fff!important;box-shadow:0 0 0 5px rgba(33,117,155,.5)}.su-generator-range-picker .slider>.dragger.dragging{background:#ccc!important;box-shadow:0 0 0 5px rgba(33,117,155,.5)}.su-generator-range-picker .slider>.track{height:12px!important;border:1px solid #ccc!important;background:#fff!important}.su-generator-range-picker input{width:60px!important;float:right;text-align:center}.su-generator-switch{display:inline-block;width:100%;font-weight:700;cursor:pointer}.su-generator-switch span{display:none;padding:10px;border-radius:3px}.su-generator-switch-yes span.su-generator-yes{display:block;background:#e0ffe0;color:#0c0}.su-generator-switch-no span.su-generator-no{display:block;background:#f5f5f5;color:#777}.su-generator-select-color{position:relative;display:inline-block;width:100%}.su-generator-select-color-wheel{position:absolute;top:100%;left:0;z-index:9999;display:none;border:1px solid #aaa;border-radius:50%;background:#fff;box-shadow:0 2px 5px #ccc}.su-generator-isp{margin-bottom:15px}.su-generator-isp-source{height:0;margin:0 -20px;padding:0 20px;overflow:hidden;background:#eee;color:#555;opacity:0;transition:opacity .2s}.su-generator-isp-source.su-generator-isp-source-open{height:auto;margin:20px -20px 0;padding:14px 20px;border-top:1px solid #ccc;border-bottom:1px solid #ccc;opacity:1}.su-generator-isp-images{margin-top:1em;overflow:auto}.su-generator-isp-images span{position:relative;display:block;width:84px;height:84px;margin:5px 5px 5px 0;float:left;border:3px solid #fff;border-radius:50%;background:#fff;box-shadow:0 1px 2px #999}.su-generator-isp-images span.ui-sortable-helper,.su-generator-isp-images span:hover{box-shadow:0 1px 6px #777}.su-generator-isp-images img{display:block;width:100%;height:100%;margin:0;padding:0;border:none;border-radius:50%}.su-generator-isp-images span i{position:absolute;top:-3px;right:-3px;display:none;width:16px;height:16px;border-radius:50%;background:#fff;color:#f03;text-align:center;font-size:12px;line-height:16px;cursor:pointer}.su-generator-isp-images span:hover i{display:block}.su-generator-isp-images span i:hover{background:#f03;color:#fff}.su-generator-isp-categories,.su-generator-isp-taxonomies,.su-generator-isp-terms{margin-top:15px}#su-generator-preview{display:none;margin:0 -20px;padding:1.5em 20px;overflow:hidden;border-bottom:1px solid #ccc}#su-generator-preview .su-column{outline:1px dotted #ccc}.su-generator-actions{margin:0 -20px -20px;padding:1.5em 15px;background:#eee}.su-generator-actions>.button{margin:0 5px}.su-generator-actions .button i{margin:0 5px 0 -3px}.su-generator-presets{position:relative}.su-generator-presets>.button{cursor:default}.su-gp-popup{position:absolute;right:0;bottom:0;display:none;min-width:160px;max-width:500px;border:1px solid #aaa;border-radius:5px;background:#fff}.su-gp-head{margin-bottom:10px;padding:10px;border-bottom:1px dotted #ccc}.su-gp-head .button{display:block;text-align:center}.su-gp-list{margin:5px 0}.su-gp-list b{display:block;padding:5px 10px;color:#aaa;font-weight:400;font-style:italic}.su-gp-list span{position:relative;display:block;padding:5px 10px;overflow:hidden;color:#21759b;cursor:pointer}.su-gp-list span:nth-child(odd){background:#f8f8f8}.su-gp-list span:hover{background:#eee;color:#d54e21}.su-gp-list span em{margin-right:32px;white-space:nowrap;font-style:normal}.su-gp-list span i{position:absolute;top:50%;right:10px;display:block;width:20px;height:20px;margin-top:-10px;border-radius:50%;color:#999;text-align:center;font-weight:400;font-size:12px;line-height:20px}.su-gp-list span i:hover{background:#f03;color:#fff}.su-generator-mfp.mfp-bg{z-index:101000!important}.su-generator-mfp.mfp-wrap{z-index:101001!important}.su-generator-mfp.mfp-wrap .mfp-preloader{z-index:101002!important}.su-generator-mfp.mfp-wrap .mfp-content{z-index:101003!important}.su-generator-mfp.mfp-wrap button.mfp-arrow,.su-generator-mfp.mfp-wrap button.mfp-close{z-index:101004!important}#su-generator-preview .su-image-carousel-align-full{margin-left:-1.5em;margin-right:-1.5em;max-width:calc(100% + 3em)!important}.su-generator-extra-banner{margin-bottom:-20px;padding-top:20px;text-align:center}.su-generator-extra-banner-message{padding:15px;background:#f0f0f0;border-left:4px solid #999;color:#000;margin:0 0 2rem;font-size:.9rem;text-align:left}.su-generator-extra-banner-icon{width:80px;height:80px;margin:0 0 1.75rem}.su-generator-extra-banner-title{margin:0 0 .75rem;font-size:1.5rem;font-weight:700;color:#333}.su-generator-extra-banner-description{margin:0 0 1.75rem;font-size:.95rem;color:#555}.su-generator-extra-banner-action{margin:0 0 2rem}.su-generator-extra-banner-action>a.button{padding:12px 24px;font-weight:700;font-size:.9rem;height:auto;border-radius:5px;line-height:1}.su-generator-extra-banner-screenshot img{display:block;width:100%}
1
+ .su-generator-clearfix:after,.su-generator-clearfix:before{display:table;content:' '}.su-generator-clearfix:after{clear:both}.su-generator-clear{height:0;clear:both;overflow:hidden}.su-generator-hidden{display:none!important}.su-generator-loading{min-height:60px;background:50% 50% url(../images/spinner.gif) no-repeat!important}.su-generator-loading *{visibility:hidden}.su-generator-button img{margin:-1px 2px 0 -5px;vertical-align:middle}.wp-media-buttons .su-generator-button img{margin:-1px -1px 0 -4px;vertical-align:middle}#su-generator-wrap{display:none}#su-generator{position:relative;width:85%;max-width:1000px;margin:60px auto;padding:20px;background:#fff;box-shadow:0 2px 25px #000;transition:max-width .2s}#su-generator.su-generator-narrow{max-width:500px}#su-generator-tools{margin:0 20px 20px 0}#su-generator-tools span{display:inline-block;width:1px;height:1em;margin:0 .5em;border-right:1px dotted #555;vertical-align:middle}#su-generator-tools a{text-decoration:none}#su-generator-tools a.su-add-ons{display:inline-block;padding:3px 8px;background:#ff562d;color:#fff;font-weight:700;border-radius:3px;border:1px solid #f2522b;text-shadow:1px 1px 1px #a6381d}#su-generator-tools a.su-add-ons:active,#su-generator-tools a.su-add-ons:focus,#su-generator-tools a.su-add-ons:hover{background:#ff7857}#su-generator-search{width:100%;margin-bottom:5px;padding:10px 10px 10px 42px;background:5px 50% url(../images/search.png) no-repeat;font-size:1.3em}#su-generator-search-pro-tip{margin:0 0 30px 0;color:#999;font-style:italic;text-align:right;font-size:.9em}#su-generator-filter{margin:0 -20px;padding:14px 20px;border-top:1px solid #ccc;border-bottom:1px solid #ccc;background:#eee;color:#555;text-align:center;line-height:24px}#su-generator-filter a,#su-generator-filter strong{display:inline-block;margin:0 1em;line-height:1}#su-generator-filter a{border-bottom:1px dotted #ccc;text-decoration:none}#su-generator-choices{margin-top:20px;text-align:left}#su-generator-choices>span{position:relative;display:block;width:20%;height:28px;min-width:130px;padding:0 5px 0 30px;float:left;overflow:hidden;box-sizing:border-box;border-bottom:1px dotted #e5e5e5;color:#222;vertical-align:top;text-align:left;line-height:28px;cursor:pointer}#su-generator-choices span:hover{border-bottom:1px solid #333;background:#333;color:#fff}#su-generator-choices span img{position:absolute;top:7px;left:7px;width:14px;height:14px}#su-generator-choices span i{position:absolute;top:1px;left:1px;display:block;width:26px;height:26px;color:#888;text-align:center;font-size:14px;line-height:26px}#su-generator-choices span:hover i{color:#fff}.su-generator-choice-first{outline:1px solid #09f;box-shadow:0 0 3px rgba(30,140,190,.8)}#su-generator-breadcrumbs{margin:0 -20px;padding:14px 20px;border-top:1px solid #ccc;border-bottom:1px solid #ccc;background:#eee;color:#555;line-height:24px}#su-generator-breadcrumbs span{margin-right:1em;font-weight:700}#su-generator-breadcrumbs small{color:#bbb;font-weight:400;font-size:.9em}.su-generator-note{position:relative;margin:0 -20px;padding:5px 20px;background:#ffffb8;border-bottom:1px solid #ccc;color:#333;line-height:18px}.su-generator-note-content{min-height:20px;margin-left:35px}.su-generator-note p{margin:10px 0}.su-generator-note a{text-decoration:underline}.su-generator-note i{position:absolute;top:15px;left:20px;display:block;width:1em;height:1em;color:#555;text-align:left;font-size:20px;line-height:1em}.su-generator-cta{position:relative;margin:0 -20px;padding:15px 20px;background:#e0efff;border-bottom:1px solid #ccc;color:#222}.su-generator-cta-content{display:flex;align-items:center;justify-content:space-between;line-height:21px}.su-generator-cta-content span{font-size:.9rem}.su-generator-cta-content .button{font-size:.9rem;margin-left:20px}.su-generator-cta-content nobr{white-space:nowrap;font-weight:700}#su-generator-settings .su-generator-attr-container{margin:0 -20px;padding:1.5em 20px;border-bottom:1px solid #ccc;box-shadow:0 1px 3px rgba(0,0,0,.1)}#su-generator-settings h5{text-transform:capitalize;font-weight:700}#su-generator-preview h5,#su-generator-settings h5{margin:0 0 15px 0;font-size:1em}.su-generator-attr-desc{margin-top:15px;color:#aaa;font-style:italic;line-height:1.6}.su-generator-attr-desc b{color:#999}.su-generator-px-units{position:relative;margin-right:15px}.su-generator-px-units:before{position:absolute;right:-18px;bottom:3px;display:block;width:15px;color:#999;content:'px';text-align:left;font-size:.9em}.su-generator-attr-desc b.su-generator-set-value{border-bottom:1px dotted #999;cursor:pointer}.su-generator-attr-desc b.su-generator-set-value:hover{border-bottom:1px dotted #333;color:#333}#su-generator-settings input[type=number],#su-generator-settings input[type=text],#su-generator-settings select,#su-generator-settings textarea{width:100%;height:auto;padding:10px}.su-generator-field-actions{padding-top:10px}.su-generator-field-actions .button,.su-generator-field-actions span{margin-right:5px}.su-generator-field-actions img{margin:0 6px 0 -4px;vertical-align:middle}.su-generator-icon-picker{height:0;margin:0 -20px;padding:0 20px;overflow:hidden;background:#eee;line-height:24px;transition:all .2s}.su-generator-icon-picker.su-generator-icon-picker-visible{height:auto;margin:1em -20px 0 -20px;padding:14px 20px;overflow:visible;border-top:1px solid #ccc;border-bottom:1px solid #ccc}.su-generator-icon-picker input{margin-bottom:15px}.su-generator-icon-picker i{display:block;width:24px;height:24px;margin-left:2px;float:left;color:#555;text-align:center;font-size:14px;line-height:24px;cursor:pointer}.su-generator-icon-picker i:hover{color:#000;font-size:24px}.su-generator-shadow-picker-field{position:relative;display:inline-block;width:22%;padding-right:3%;vertical-align:top}.su-generator-shadow-picker-field small{display:block;color:#ccc;line-height:1.35;margin-top:.75em}.su-generator-shadow-picker-field input{text-align:right}.su-generator-shadow-picker-field.su-generator-shadow-picker-color{width:25%;padding-right:0}.su-generator-shadow-picker-field.su-generator-shadow-picker-color input{text-align:left}.su-generator-shadow-picker-color{position:relative}.su-generator-shadow-picker-color-wheel{position:absolute;top:100%;right:0;z-index:9999;display:none;border:1px solid #aaa;border-radius:50%;background:#fff;box-shadow:0 2px 5px #ccc}.su-generator-border-picker-field{position:relative;display:inline-block;width:30%;padding-right:3%}.su-generator-border-picker-field small{display:block;color:#ccc}.su-generator-border-picker-field input{text-align:right}.su-generator-border-picker-field.su-generator-border-picker-color{width:34%;padding-right:0}.su-generator-border-picker-field.su-generator-border-picker-color input{text-align:left}.su-generator-border-picker-color{position:relative}.su-generator-border-picker-color-wheel{position:absolute;top:100%;right:0;z-index:9999;display:none;border:1px solid #aaa;border-radius:50%;background:#fff;box-shadow:0 2px 5px #ccc}.su-generator-range-picker .slider{width:420px;margin:10px 0 0 0!important;padding:0;float:left}.su-generator-range-picker .slider>.dragger{background:#fff!important}.su-generator-range-picker .slider:hover>.dragger{background:#fff!important;box-shadow:0 0 0 5px rgba(33,117,155,.5)}.su-generator-range-picker .slider>.dragger.dragging{background:#ccc!important;box-shadow:0 0 0 5px rgba(33,117,155,.5)}.su-generator-range-picker .slider>.track{height:12px!important;border:1px solid #ccc!important;background:#fff!important}.su-generator-range-picker input{width:60px!important;float:right;text-align:center}.su-generator-switch{display:inline-block;width:100%;font-weight:700;cursor:pointer}.su-generator-switch span{display:none;padding:10px;border-radius:3px}.su-generator-switch-yes span.su-generator-yes{display:block;background:#e0ffe0;color:#0c0}.su-generator-switch-no span.su-generator-no{display:block;background:#f5f5f5;color:#777}.su-generator-select-color{position:relative;display:inline-block;width:100%}.su-generator-select-color-wheel{position:absolute;top:100%;left:0;z-index:9999;display:none;border:1px solid #aaa;border-radius:50%;background:#fff;box-shadow:0 2px 5px #ccc}.su-generator-isp{margin-bottom:15px}.su-generator-isp-source{height:0;margin:0 -20px;padding:0 20px;overflow:hidden;background:#eee;color:#555;opacity:0;transition:opacity .2s}.su-generator-isp-source.su-generator-isp-source-open{height:auto;margin:20px -20px 0;padding:14px 20px;border-top:1px solid #ccc;border-bottom:1px solid #ccc;opacity:1}.su-generator-isp-images{margin-top:1em;overflow:auto}.su-generator-isp-images span{position:relative;display:block;width:84px;height:84px;margin:5px 5px 5px 0;float:left;border:3px solid #fff;border-radius:50%;background:#fff;box-shadow:0 1px 2px #999}.su-generator-isp-images span.ui-sortable-helper,.su-generator-isp-images span:hover{box-shadow:0 1px 6px #777}.su-generator-isp-images img{display:block;width:100%;height:100%;margin:0;padding:0;border:none;border-radius:50%}.su-generator-isp-images span i{position:absolute;top:-3px;right:-3px;display:none;width:16px;height:16px;border-radius:50%;background:#fff;color:#f03;text-align:center;font-size:12px;line-height:16px;cursor:pointer}.su-generator-isp-images span:hover i{display:block}.su-generator-isp-images span i:hover{background:#f03;color:#fff}.su-generator-isp-categories,.su-generator-isp-taxonomies,.su-generator-isp-terms{margin-top:15px}#su-generator-preview{display:none;margin:0 -20px;padding:1.5em 20px;overflow:hidden;border-bottom:1px solid #ccc}#su-generator-preview .su-column{outline:1px dotted #ccc}.su-generator-actions{margin:0 -20px -20px;padding:1.5em 15px;background:#eee}.su-generator-actions>.button{margin:0 5px}.su-generator-actions .button i{margin:0 5px 0 -3px}.su-generator-presets{position:relative}.su-generator-presets>.button{cursor:default}.su-gp-popup{position:absolute;right:0;bottom:0;display:none;min-width:160px;max-width:500px;border:1px solid #aaa;border-radius:5px;background:#fff}.su-gp-head{margin-bottom:10px;padding:10px;border-bottom:1px dotted #ccc}.su-gp-head .button{display:block;text-align:center}.su-gp-list{margin:5px 0}.su-gp-list b{display:block;padding:5px 10px;color:#aaa;font-weight:400;font-style:italic}.su-gp-list span{position:relative;display:block;padding:5px 10px;overflow:hidden;color:#21759b;cursor:pointer}.su-gp-list span:nth-child(odd){background:#f8f8f8}.su-gp-list span:hover{background:#eee;color:#d54e21}.su-gp-list span em{margin-right:32px;white-space:nowrap;font-style:normal}.su-gp-list span i{position:absolute;top:50%;right:10px;display:block;width:20px;height:20px;margin-top:-10px;border-radius:50%;color:#999;text-align:center;font-weight:400;font-size:12px;line-height:20px}.su-gp-list span i:hover{background:#f03;color:#fff}.su-generator-mfp.mfp-bg{z-index:101000!important}.su-generator-mfp.mfp-wrap{z-index:101001!important}.su-generator-mfp.mfp-wrap .mfp-preloader{z-index:101002!important}.su-generator-mfp.mfp-wrap .mfp-content{z-index:101003!important}.su-generator-mfp.mfp-wrap button.mfp-arrow,.su-generator-mfp.mfp-wrap button.mfp-close{z-index:101004!important}#su-generator-preview .su-image-carousel-align-full{margin-left:-1.5em;margin-right:-1.5em;max-width:calc(100% + 3em)!important}.su-generator-pro-features-banner{margin:60px 0 -20px;text-align:center}.su-generator-pro-features-banner-icon{width:80px;height:80px;margin:0 0 1.75rem}.su-generator-pro-features-banner-title{margin:0 0 .75rem;font-size:1.5rem;font-weight:700;color:#333}.su-generator-pro-features-banner-description{margin:0 0 1.75rem;font-size:.95rem;color:#555}.su-generator-pro-features-banner-action{margin:0 0 2rem}.su-generator-pro-features-banner-action>a.button{padding:12px 24px;font-weight:700;font-size:.9rem;height:auto;border-radius:5px;line-height:1}.su-generator-pro-features-banner-screenshot img{display:block;width:100%}
admin/images/addons/bundle.png DELETED
Binary file
admin/images/addons/extra.png DELETED
Binary file
admin/images/addons/maker.png DELETED
Binary file
admin/images/addons/skins.png DELETED
Binary file
admin/images/pages/about/check.svg CHANGED
File without changes
admin/images/pages/about/poster.jpg CHANGED
File without changes
admin/images/plugin-icon.svg CHANGED
File without changes
admin/images/pro-features/icon-banner.png CHANGED
Binary file
admin/images/pro-features/icon-generator.png CHANGED
Binary file
admin/images/pro-features/screenshots/content_slider.png CHANGED
File without changes
admin/images/pro-features/screenshots/exit_popup.png CHANGED
File without changes
admin/images/pro-features/screenshots/icon.png CHANGED
File without changes
admin/images/pro-features/screenshots/icon_panel.png CHANGED
File without changes
admin/images/pro-features/screenshots/icon_text.png CHANGED
File without changes
admin/images/pro-features/screenshots/member.png CHANGED
File without changes
admin/images/pro-features/screenshots/panel.png CHANGED
File without changes
admin/images/pro-features/screenshots/photo_panel.png CHANGED
File without changes
admin/images/pro-features/screenshots/pricing_table.png CHANGED
File without changes
admin/images/pro-features/screenshots/progress_bar.png CHANGED
File without changes
admin/images/pro-features/screenshots/progress_pie.png CHANGED
File without changes
admin/images/pro-features/screenshots/section.png CHANGED
File without changes
admin/images/pro-features/screenshots/shadow.png CHANGED
File without changes
admin/images/pro-features/screenshots/splash.png CHANGED
File without changes
admin/images/pro-features/screenshots/testimonial.png CHANGED
File without changes
admin/images/search.png CHANGED
File without changes
admin/images/shortcodes/_default.svg CHANGED
File without changes
admin/images/shortcodes/accordion.svg CHANGED
File without changes
admin/images/shortcodes/animate.svg CHANGED
File without changes
admin/images/shortcodes/audio.svg CHANGED
File without changes
admin/images/shortcodes/box.svg CHANGED
File without changes
admin/images/shortcodes/button.svg CHANGED
File without changes
admin/images/shortcodes/carousel.svg CHANGED
File without changes
admin/images/shortcodes/column.svg CHANGED
File without changes
admin/images/shortcodes/content_slide.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="m16.957 19h-14.01c-1.095 0-1.995-.901-1.995-1.995v-14.01c0-1.102.893-1.995 1.995-1.995h14.01c1.102 0 1.995.893 1.995 1.995v14.01c0 1.094-.901 1.995-1.995 1.995zm-.005-16h-14v14h14zm-3.286 11.773h-7.429c-.58 0-1.058-.478-1.058-1.058v-7.43c0-.584.474-1.058 1.058-1.058h7.429c.585 0 1.058.474 1.058 1.058v7.43c0 .58-.477 1.058-1.058 1.058zm-.957-7.53h-5.515v5.514h5.515z" fill="#da2525" fill-rule="nonzero"/></svg>
admin/images/shortcodes/content_slider.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="m17.005 19h-14.01c-1.094 0-1.995-.901-1.995-1.995v-14.01c0-1.102.893-1.995 1.995-1.995h14.01c1.102 0 1.995.893 1.995 1.995v14.01c0 1.094-.9 1.995-1.995 1.995zm-14.005-4.227v2.227h14v-14h-14v2.227h5.715c.584 0 1.058.474 1.058 1.058v7.43c0 .58-.478 1.057-1.058 1.058zm14-9.546v2.016h-2.757v5.514h2.757v2.016h-3.715c-.58-.001-1.058-.478-1.058-1.058v-7.43c0-.584.474-1.058 1.058-1.058zm-9.243 7.53v-5.514h-4.757v5.514z" fill="#da2525" fill-rule="nonzero"/></svg>
admin/images/shortcodes/custom_gallery.svg CHANGED
File without changes
admin/images/shortcodes/dailymotion.svg CHANGED
File without changes
admin/images/shortcodes/display-posts.svg CHANGED
File without changes
admin/images/shortcodes/divider.svg CHANGED
File without changes
admin/images/shortcodes/document.svg CHANGED
File without changes
admin/images/shortcodes/dropcap.svg CHANGED
File without changes
admin/images/shortcodes/dummy_image.svg CHANGED
File without changes
admin/images/shortcodes/dummy_text.svg CHANGED
File without changes
admin/images/shortcodes/exit_popup.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="m1.9 1.9h16.2c.494 0 .9.406.9.9v14.4c0 .494-.406.9-.9.9h-16.2c-.494 0-.9-.406-.9-.9v-14.4c0-.494.406-.9.9-.9zm15.3 6.3h-14.4v8.1h14.4zm-4.5-3.6v1.8h3.6v-1.8z" fill="#da2525" fill-rule="nonzero"/></svg>
admin/images/shortcodes/expand.svg CHANGED
File without changes
admin/images/shortcodes/feed.svg CHANGED
File without changes
admin/images/shortcodes/gmap.svg CHANGED
File without changes
admin/images/shortcodes/guests.svg CHANGED
File without changes
admin/images/shortcodes/heading.svg CHANGED
File without changes
admin/images/shortcodes/highlight.svg CHANGED
File without changes
admin/images/shortcodes/icon.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="m10 0 2.858 6.919 7.142.72-5.375 4.997 1.555 7.364-6.18-3.831-6.18 3.831 1.555-7.364-5.375-4.997 7.142-.72zm0 4.651 1.632 3.949 4.076.411-3.068 2.852.888 4.204-3.528-2.187-3.528 2.187.888-4.204-3.068-2.852 4.076-.411z" fill="#da2525"/></svg>
admin/images/shortcodes/icon_panel.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="m17.001 19h-14c-.553 0-1-.448-1-1v-16c0-.552.447-1 1-1h14c.552 0 1 .448 1 1v16c0 .552-.448 1-1 1zm-1-5h-12v3h12zm0-11h-12v9h12zm-6 1.8c1.379 0 2.5 1.12 2.5 2.5s-1.121 2.5-2.5 2.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5z" fill="#da2525" fill-rule="nonzero"/></svg>
admin/images/shortcodes/icon_text.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="m16 16h-6.667v-2.4h6.667zm4-4.8h-10.667v-2.4h10.667zm-16.667-7.2c1.84 0 3.334 1.494 3.334 3.333 0 1.84-1.494 3.334-3.334 3.334-1.839 0-3.333-1.494-3.333-3.334 0-1.839 1.494-3.333 3.333-3.333zm16.667 2.4h-10.667v-2.4h10.667z" fill="#da2525" fill-rule="nonzero"/></svg>
admin/images/shortcodes/image_carousel.svg CHANGED
File without changes
admin/images/shortcodes/label.svg CHANGED
File without changes
admin/images/shortcodes/lightbox.svg CHANGED
File without changes
admin/images/shortcodes/lightbox_content.svg CHANGED
File without changes
admin/images/shortcodes/list.svg CHANGED
File without changes
admin/images/shortcodes/member.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="m1 2.995c0-1.102.893-1.995 1.995-1.995h14.01c1.102 0 1.995.893 1.995 1.995v14.01c0 1.094-.901 1.995-1.995 1.995h-14.01c-1.094 0-1.995-.901-1.995-1.995v-14.01zm2 .005v14h14v-14zm2.972 13.18c-.615-.266-1.202-.594-1.751-.978 1.287-1.995 3.506-3.203 5.881-3.202 2.4 0 4.517 1.207 5.778 3.047-.539.399-1.116.742-1.724 1.025-.939-1.301-2.449-2.073-4.054-2.072-1.715 0-3.23.864-4.13 2.18zm4.028-5.18c-1.92 0-3.5-1.58-3.5-3.5s1.58-3.5 3.5-3.5 3.5 1.58 3.5 3.5-1.58 3.5-3.5 3.5zm0-2c.823 0 1.5-.677 1.5-1.5s-.677-1.5-1.5-1.5-1.5.677-1.5 1.5.677 1.5 1.5 1.5z" fill="#da2525" fill-rule="nonzero"/></svg>
admin/images/shortcodes/members.svg CHANGED
File without changes
admin/images/shortcodes/menu.svg CHANGED
File without changes
admin/images/shortcodes/meta.svg CHANGED
File without changes
admin/images/shortcodes/note.svg CHANGED
File without changes
admin/images/shortcodes/panel.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="m17.111 19h-14.222c-.488 0-.889-.406-.889-.9v-16.2c0-.494.401-.9.889-.9h14.222c.488 0 .889.406.889.9v16.2c0 .494-.401.9-.889.9zm-.889-1.8v-14.4h-12.444v14.4zm-9.778-11.7h7.112v1.8h-7.112zm0 3.6h7.112v1.8h-7.112zm0 3.6h4.445v1.8h-4.445z" fill="#da2525" fill-rule="nonzero"/></svg>
admin/images/shortcodes/permalink.svg CHANGED
File without changes
admin/images/shortcodes/photo_panel.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="m17 19h-14c-.552 0-1-.448-1-1v-16c0-.552.448-1 1-1h14c.552 0 1 .448 1 1v16c0 .552-.448 1-1 1zm-1-5h-12v3h12zm-2.538-2h2.538v-9h-12v9s4.75-5.344 4.75-5.344zm-7.087 0h4.75l-2.375-2.744zm7.125-8c.828 0 1.5.672 1.5 1.5s-.672 1.5-1.5 1.5-1.5-.672-1.5-1.5.672-1.5 1.5-1.5z" fill="#da2525" fill-rule="nonzero"/></svg>
admin/images/shortcodes/plan.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="m9.984 17.222v-14.444h-6.222v14.444zm1.778-1.778h4.444v-10.888h-4.444zm-8.838 3.556c-.246 0-.481-.098-.654-.271-.174-.174-.272-.41-.271-.655.003-3.157.014-15.296.014-15.296s-.007-.464-.015-.918c-.004-.227.084-.446.243-.608.159-.161.376-.252.604-.252h8.033c.485 0 .879.393.879.878.001.448.001.9.001.9h5.337c.488 0 .889.401.889.889v12.666c0 .488-.401.889-.889.889h-5.334s-.004.451-.009.898c-.004.487-.401.88-.889.88z" fill="#da2525" fill-rule="nonzero"/></svg>
admin/images/shortcodes/post.svg CHANGED
File without changes
admin/images/shortcodes/posts.svg CHANGED
File without changes
admin/images/shortcodes/pricing_table.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="m12.7 17.222v-14.444h-5.4v14.444zm1.8-1.778h2.7v-10.888h-2.7zm-9 0v-10.888h-2.7v10.888zm-3.6-12.666h3.629s-.007-.464-.015-.918c-.004-.227.085-.446.246-.608.161-.161.381-.252.611-.252h7.234c.491 0 .89.393.89.878v.9h3.605c.494 0 .9.401.9.889v12.666c0 .488-.406.889-.9.889h-3.601s-.004.451-.009.898c-.004.487-.406.88-.9.88h-7.158c-.51 0-.926-.404-.937-.907-.008-.439-.017-.871-.017-.871h-3.578c-.494 0-.9-.401-.9-.889v-12.666c0-.488.406-.889.9-.889z" fill="#da2525" fill-rule="nonzero"/></svg>
admin/images/shortcodes/private.svg CHANGED
File without changes
admin/images/shortcodes/progress_bar.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="m2 5v10h16v-10zm-1-2h18c.549 0 1 .451 1 1v12c0 .549-.451 1-1 1h-18c-.549 0-1-.451-1-1v-12c0-.549.451-1 1-1zm3 4h8v6h-8z" fill="#da2525" fill-rule="nonzero"/></svg>
admin/images/shortcodes/progress_pie.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="m8.2 1.19v2.716c-2.636.777-4.563 3.217-4.563 6.104 0 3.512 2.851 6.363 6.363 6.363 1.699 0 3.243-.667 4.384-1.753l2.351 1.357c-1.649 1.86-4.056 3.033-6.735 3.033-4.967 0-9-4.033-9-9 0-4.351 3.094-7.985 7.2-8.82zm3.6 0c4.106.835 7.2 4.469 7.2 8.82 0 .996-.162 1.955-.462 2.851l-2.352-1.358c.116-.479.177-.979.177-1.493 0-2.887-1.927-5.327-4.563-6.104z" fill="#da2525"/></svg>
admin/images/shortcodes/pullquote.svg CHANGED
File without changes
admin/images/shortcodes/qrcode.svg CHANGED
File without changes
admin/images/shortcodes/quote.svg CHANGED
File without changes
admin/images/shortcodes/row.svg CHANGED
File without changes
admin/images/shortcodes/scheduler.svg CHANGED
File without changes
admin/images/shortcodes/section.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="m17.222 6.4h-14.444v7.2h14.444zm-2.778-1.8v-1.8h-8.888v1.8zm0 10.8h-8.888v1.8h8.888zm-10.666 2.7v-2.729s-1.464.007-1.918.015c-.227.004-.446-.085-.608-.246-.161-.161-.252-.381-.252-.611v-9.034c0-.491.393-.89.878-.89.448-.001 1.9-.001 1.9-.001v-2.704c0-.494.401-.9.889-.9h10.666c.488 0 .889.406.889.9v2.701s1.451.004 1.898.009c.487.004.88.406.88.9v8.958c0 .51-.404.926-.907.936-.439.009-1.871.018-1.871.018v2.678c0 .494-.401.9-.889.9h-10.666c-.488 0-.889-.406-.889-.9z" fill="#da2525" fill-rule="nonzero"/></svg>
admin/images/shortcodes/service.svg CHANGED
File without changes
admin/images/shortcodes/shadow.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="m17.005 19h-10.01c-1.094 0-1.995-.901-1.995-1.995v-.005h12v-12h.005c1.102 0 1.995.893 1.995 1.995v10.01c0 1.094-.9 1.995-1.995 1.995zm-4-4h-10.01c-1.094 0-1.995-.901-1.995-1.995v-10.01c0-1.102.893-1.995 1.995-1.995h10.01c1.102 0 1.995.893 1.995 1.995v10.01c0 1.094-.9 1.995-1.995 1.995zm-.005-12h-10v10h10z" fill="#da2525" fill-rule="nonzero"/></svg>
admin/images/shortcodes/siblings.svg CHANGED
File without changes
admin/images/shortcodes/slider.svg CHANGED
File without changes
admin/images/shortcodes/spacer.svg CHANGED
File without changes
admin/images/shortcodes/splash.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="m1.9 1.9h16.2c.494 0 .9.406.9.9v14.4c0 .494-.406.9-.9.9h-16.2c-.494 0-.9-.406-.9-.9v-14.4c0-.494.406-.9.9-.9zm15.3 7.2h-14.4v7.2h14.4zm0-1.8v-3.6h-14.4v3.6zm-4.5-2.7h3.6v1.8h-3.6z" fill="#da2525" fill-rule="nonzero"/></svg>
admin/images/shortcodes/spoiler.svg CHANGED
File without changes
admin/images/shortcodes/subpages.svg CHANGED
File without changes
admin/images/shortcodes/tab.svg CHANGED
File without changes
admin/images/shortcodes/table.svg CHANGED
File without changes
admin/images/shortcodes/tabs.svg CHANGED
File without changes
admin/images/shortcodes/template.svg CHANGED
File without changes
admin/images/shortcodes/testimonial.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="m5.01 15.769-4.01 3.231v-17.077c0-.51.403-.923.9-.923h16.2c.497 0 .9.413.9.923v12.923c0 .51-.403.923-.9.923zm-2.21-.567 1.587-1.279h12.813v-11.077h-14.4zm7.216-3.402-3.023-3.102c-.791-.811-.791-2.126 0-2.937s2.073-.811 2.864 0l.159.164.16-.164c.79-.811 2.072-.811 2.863 0s.791 2.126 0 2.937l-3.024 3.101z" fill="#da2525" fill-rule="nonzero"/></svg>
admin/images/shortcodes/tooltip.svg CHANGED
File without changes
admin/images/shortcodes/user.svg CHANGED
File without changes
admin/images/shortcodes/video.svg CHANGED
File without changes
admin/images/shortcodes/vimeo.svg CHANGED
File without changes
admin/images/shortcodes/youtube.svg CHANGED
File without changes
admin/images/shortcodes/youtube_advanced.svg CHANGED
File without changes
admin/images/spinner.gif CHANGED
File without changes
admin/js/about/index.js CHANGED
File without changes
admin/js/about/index.js.map CHANGED
File without changes
admin/partials/help/addons.php CHANGED
File without changes
admin/partials/help/settings.php CHANGED
File without changes
admin/partials/help/sidebar.php CHANGED
File without changes
admin/partials/notices/pro.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <div class="su-admin-c-notice-pro">
2
+ <p><?php esc_html_e( 'You are using the Free version of Shortcodes Ultimate. Upgrade to PRO to get even more awesome features.', 'shortcodes-ultimate' ); ?></p>
3
+ <p><a href="<?php echo esc_attr( esc_attr( su_get_utm_link( 'https://getshortcodes.com/pricing/', array( 'wp-admin', 'pro-notice', $data['page'] ) ) ) ); ?>" class="button button-primary"><?php esc_html_e( 'Upgrade to PRO', 'shortcodes-ultimate' ); ?> &rarr;</a></p>
4
+ </div>
admin/partials/notices/rate.php CHANGED
File without changes
admin/partials/notices/unsafe-features.php CHANGED
File without changes
admin/partials/pages/about.php CHANGED
@@ -1,90 +1,113 @@
1
  <?php defined( 'ABSPATH' ) || exit; ?>
2
 
3
- <div class="su-admin-about wrap">
4
 
5
- <div class="su-admin-about-page-header">
6
- <img src="<?php echo esc_attr( plugins_url( '../../images/plugin-icon.svg', __FILE__ ) ); ?>" alt="" width="72" height="72">
7
- <h1>
8
- <?php // translators: %s will be replaced with "Shortcodes Ultimate" ?>
9
- <?php echo esc_html( sprintf( __( 'Welcome to %s', 'shortcodes-ultimate' ), 'Shortcodes&nbsp;Ultimate' ) ); ?>
10
- </h1>
11
- <p><?php esc_html_e( 'The most powerful shortcode plugin for WordPress' ); ?></p>
12
- </div>
13
 
14
- <div class="su-admin-about-getting-started">
15
- <div class="su-admin-about-getting-started-video su-admin-about-getting-started-video-loading" id="su-admin-about-getting-started-video">
16
- <button class="su-admin-about-getting-started-video-button su-admin-u-hidden" id="su-admin-about-getting-started-video-button">
17
- <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg"><path fill="currentcolor" d="m16 0c8.831 0 16 7.169 16 16s-7.169 16-16 16-16-7.169-16-16 7.169-16 16-16zm-4 20.5c0 .501.273.962.712 1.203s.974.224 1.397-.045c2.049-1.304 5.128-3.263 7.072-4.5.396-.252.635-.689.635-1.158s-.239-.906-.635-1.158c-1.944-1.237-5.023-3.196-7.072-4.5-.423-.269-.958-.286-1.397-.045s-.712.702-.712 1.203z"/></svg>
18
- <span><?php esc_html_e( 'See the plugin in action', 'shortcodes-ultimate' ); ?></span>
19
- </button>
20
- <iframe class="su-admin-about-getting-started-video-iframe su-admin-u-hidden" id="su-admin-about-getting-started-video-iframe" src="https://player.vimeo.com/video/507942335?color=0073D7&title=0&byline=0&portrait=0&dnt=1" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
 
 
21
  </div>
22
- </div>
23
 
24
- <div class="su-admin-about-popular">
25
- <h2><?php esc_html_e( 'Shortcodes', 'shortcodes-ultimate' ); ?></h2>
26
- <p><?php esc_html_e( 'The plugin includes over 60 amazing shortcodes', 'shortcodes-ultimate' ); ?></p>
27
- <ul class="su-admin-about-popular-grid">
28
- <?php foreach ( su_get_config( 'popular-shortcodes' ) as $shortcode ) : ?>
29
- <li class="su-admin-about-popular-item">
30
- <img class="su-admin-about-popular-item-icon" src="<?php echo esc_attr( su_get_plugin_url() . $shortcode['icon'] ); ?>" alt="<?php echo esc_attr( sprintf( '%s: %s', __( 'Shortcode icon', 'shortcodes-ultimate' ), $shortcode['title'] ) ); ?>" width="24" height="24">
31
- <span class="su-admin-about-popular-item-text">
32
- <span class="su-admin-about-popular-item-title"><?php echo esc_html( $shortcode['title'] ); ?></span>
33
- <span class="su-admin-about-popular-item-description"><?php echo esc_html( $shortcode['description'] ); ?></span>
34
- </span>
35
- </li>
36
- <?php endforeach; ?>
37
- </ul>
38
- <div class="su-admin-about-popular-bottom">
39
- <a href="https://getshortcodes.com/docs-category/shortcodes/" class="button" target="_blank"><?php esc_html_e( 'View all shortcodes', 'shortcodes-ultimate' ); ?> <svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="16" height="16" fill="none" stroke="currentcolor" stroke-linecap="round" stroke-linejoin="round" stroke-width="3"><path d="M14 9 L3 9 3 29 23 29 23 18 M18 4 L28 4 28 14 M28 4 L14 18" /></svg></a>
40
  </div>
41
- </div>
42
 
43
- <div class="su-admin-about-upgrade">
44
- <div class="su-admin-about-upgrade-features">
45
- <h2><?php esc_html_e( 'Premium Add-ons', 'shortcodes-ultimate' ); ?></h2>
46
- <ul>
47
- <li><?php esc_html_e( 'Parallax Section shortcode', 'shortcodes-ultimate' ); ?></li>
48
- <li><?php esc_html_e( 'Custom PHP shortcodes', 'shortcodes-ultimate' ); ?></li>
49
- <li><?php esc_html_e( 'Content Slider shortcode', 'shortcodes-ultimate' ); ?></li>
50
- <li><?php esc_html_e( 'Personal email support', 'shortcodes-ultimate' ); ?></li>
51
- <li><?php esc_html_e( 'Testimonail shortcode', 'shortcodes-ultimate' ); ?></li>
52
- <li><?php esc_html_e( '24 styles for Heading', 'shortcodes-ultimate' ); ?></li>
53
- <li><?php esc_html_e( 'Progress Bar shortcode', 'shortcodes-ultimate' ); ?></li>
54
- <li><?php esc_html_e( '14 styles for Spoiler', 'shortcodes-ultimate' ); ?></li>
55
- <li><?php esc_html_e( 'Exit Popup shortcode', 'shortcodes-ultimate' ); ?></li>
56
- <li><?php esc_html_e( '13 styles for Tabs', 'shortcodes-ultimate' ); ?></li>
57
  </ul>
 
 
 
58
  </div>
59
- <div class="su-admin-about-upgrade-widget">
60
- <a href="<?php echo esc_attr( admin_url( 'admin.php?page=shortcodes-ultimate-addons' ) ); ?>" class="su-admin-about-upgrade-widget-button su-admin-c-button"><?php esc_html_e( 'Browse Add-ons', 'shortcodes-ultimate' ); ?></a>
61
- </div>
62
- </div>
63
 
64
- <div class="su-admin-about-help">
65
- <h2><?php esc_html_e( 'Get help', 'shortcodes-ultimate' ); ?></h2>
66
- <div class="su-admin-about-help-menu">
67
- <ul>
68
- <li>
69
- <a href="https://getshortcodes.com/docs/" target="_blank">
70
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="18" height="18" fill="none" stroke="currentcolor" stroke-linecap="round" stroke-linejoin="round" stroke-width="3"><path d="M16 7 C16 7 9 1 2 6 L2 28 C9 23 16 28 16 28 16 28 23 23 30 28 L30 6 C23 1 16 7 16 7 Z M16 7 L16 28"/></svg>
71
- <?php esc_html_e( 'Plugin documentation', 'shortcodes-ultimate' ); ?>
72
- </a>
73
- </li>
74
- <li>
75
- <a href="https://wordpress.org/support/plugin/shortcodes-ultimate/" target="_blank">
76
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="18" height="18" fill="none" stroke="currentcolor" stroke-linecap="round" stroke-linejoin="round" stroke-width="3"><path d="M2 4 L30 4 30 22 16 22 8 29 8 22 2 22 Z"/></svg>
77
- <?php esc_html_e( 'Community support forum', 'shortcodes-ultimate' ); ?>
78
- </a>
79
- </li>
80
- <li>
81
- <a href="https://getshortcodes.com/support/open-support-ticket/" target="_blank">
82
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="18" height="18" fill="none" stroke="currentcolor" stroke-linecap="round" stroke-linejoin="round" stroke-width="3"><path d="M2 26 L30 26 30 6 2 6 Z M2 6 L16 16 30 6"/></svg>
83
- <?php esc_html_e( 'Premium support', 'shortcodes-ultimate' ); ?>
84
- </a>
85
- </li>
86
- </ul>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  </div>
 
88
  </div>
89
 
90
  </div>
1
  <?php defined( 'ABSPATH' ) || exit; ?>
2
 
3
+ <div class="su-admin-about-wrap wrap">
4
 
5
+ <?php if ( ! su_fs()->can_use_premium_code() && ! su_has_active_addons() ) : ?>
6
+ <?php su_partial( 'admin/partials/notices/pro.php', array( 'page' => 'about' ) ); ?>
7
+ <?php endif; ?>
8
+
9
+ <div class="su-admin-about">
 
 
 
10
 
11
+ <div class="su-admin-about-page-header">
12
+ <div>
13
+ <img src="<?php echo esc_attr( plugins_url( '../../images/plugin-icon.svg', __FILE__ ) ); ?>" alt="" width="72" height="72">
14
+ </div>
15
+ <h1>
16
+ <?php // translators: %s will be replaced with "Shortcodes Ultimate" ?>
17
+ <?php echo esc_html( sprintf( __( 'Welcome to %s', 'shortcodes-ultimate' ), 'Shortcodes&nbsp;Ultimate' ) ); ?>
18
+ </h1>
19
+ <p><?php esc_html_e( 'The most powerful shortcode plugin for WordPress', 'shortcodes-ultimate' ); ?></p>
20
  </div>
 
21
 
22
+ <div class="su-admin-about-getting-started">
23
+ <div class="su-admin-about-getting-started-video su-admin-about-getting-started-video-loading" id="su-admin-about-getting-started-video">
24
+ <button class="su-admin-about-getting-started-video-button su-admin-u-hidden" id="su-admin-about-getting-started-video-button">
25
+ <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg"><path fill="currentcolor" d="m16 0c8.831 0 16 7.169 16 16s-7.169 16-16 16-16-7.169-16-16 7.169-16 16-16zm-4 20.5c0 .501.273.962.712 1.203s.974.224 1.397-.045c2.049-1.304 5.128-3.263 7.072-4.5.396-.252.635-.689.635-1.158s-.239-.906-.635-1.158c-1.944-1.237-5.023-3.196-7.072-4.5-.423-.269-.958-.286-1.397-.045s-.712.702-.712 1.203z"/></svg>
26
+ <span><?php esc_html_e( 'See the plugin in action', 'shortcodes-ultimate' ); ?></span>
27
+ </button>
28
+ <iframe class="su-admin-about-getting-started-video-iframe su-admin-u-hidden" id="su-admin-about-getting-started-video-iframe" src="https://player.vimeo.com/video/507942335?color=0073D7&title=0&byline=0&portrait=0&dnt=1" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
29
+ </div>
 
 
 
 
 
 
 
 
30
  </div>
 
31
 
32
+ <div class="su-admin-about-popular">
33
+ <h2><?php esc_html_e( 'Shortcodes', 'shortcodes-ultimate' ); ?></h2>
34
+ <p><?php esc_html_e( 'The plugin includes over 60 amazing shortcodes', 'shortcodes-ultimate' ); ?></p>
35
+ <ul class="su-admin-about-popular-grid">
36
+ <?php foreach ( su_get_config( 'popular-shortcodes' ) as $shortcode ) : ?>
37
+ <li class="su-admin-about-popular-item">
38
+ <img class="su-admin-about-popular-item-icon" src="<?php echo esc_attr( su_get_plugin_url() . $shortcode['icon'] ); ?>" alt="<?php echo esc_attr( sprintf( '%s: %s', __( 'Shortcode icon', 'shortcodes-ultimate' ), $shortcode['title'] ) ); ?>" width="24" height="24">
39
+ <span class="su-admin-about-popular-item-text">
40
+ <span class="su-admin-about-popular-item-title"><?php echo esc_html( $shortcode['title'] ); ?></span>
41
+ <span class="su-admin-about-popular-item-description"><?php echo esc_html( $shortcode['description'] ); ?></span>
42
+ </span>
43
+ </li>
44
+ <?php endforeach; ?>
 
45
  </ul>
46
+ <div class="su-admin-about-popular-bottom">
47
+ <a href="https://getshortcodes.com/docs-category/shortcodes/" class="button" target="_blank"><?php esc_html_e( 'View all shortcodes', 'shortcodes-ultimate' ); ?> <svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="16" height="16" fill="none" stroke="currentcolor" stroke-linecap="round" stroke-linejoin="round" stroke-width="3"><path d="M14 9 L3 9 3 29 23 29 23 18 M18 4 L28 4 28 14 M28 4 L14 18" /></svg></a>
48
+ </div>
49
  </div>
 
 
 
 
50
 
51
+ <?php if ( su_fs()->is_not_paying() ) : ?>
52
+
53
+ <div class="su-admin-about-upgrade">
54
+ <div class="su-admin-about-upgrade-features">
55
+ <h2><?php esc_html_e( 'Upgrade to PRO', 'shortcodes-ultimate' ); ?></h2>
56
+ <div class="su-admin-about-upgrade-features-list">
57
+ <ul>
58
+ <li><?php esc_html_e( 'Parallax Section shortcode', 'shortcodes-ultimate' ); ?></li>
59
+ <li><?php esc_html_e( 'Custom PHP shortcodes', 'shortcodes-ultimate' ); ?></li>
60
+ <li><?php esc_html_e( 'Content Slider shortcode', 'shortcodes-ultimate' ); ?></li>
61
+ <li><?php esc_html_e( 'Personal email support', 'shortcodes-ultimate' ); ?></li>
62
+ <li><?php esc_html_e( 'Testimonail shortcode', 'shortcodes-ultimate' ); ?></li>
63
+ <li><?php esc_html_e( '24 styles for Heading', 'shortcodes-ultimate' ); ?></li>
64
+ <li><?php esc_html_e( 'Progress Bar shortcode', 'shortcodes-ultimate' ); ?></li>
65
+ <li><?php esc_html_e( '14 styles for Spoiler', 'shortcodes-ultimate' ); ?></li>
66
+ <li><?php esc_html_e( 'Exit Popup shortcode', 'shortcodes-ultimate' ); ?></li>
67
+ <li><?php esc_html_e( '13 styles for Tabs', 'shortcodes-ultimate' ); ?></li>
68
+ </ul>
69
+ </div>
70
+ </div>
71
+ <div class="su-admin-about-upgrade-buy">
72
+ <div class="su-admin-about-upgrade-buy-pricing">
73
+ <div class="su-admin-about-upgrade-buy-pricing-price">
74
+ <span class="su-admin-about-upgrade-buy-pricing-currency">$</span>
75
+ <span class="su-admin-about-upgrade-buy-pricing-value">39</span>
76
+ </div>
77
+ <div class="su-admin-about-upgrade-buy-pricing-period"><?php esc_html_e( 'per year', 'shortcodes-ultimate' ); ?></div>
78
+ </div>
79
+ <a href="<?php echo esc_attr( esc_attr( su_get_utm_link( 'https://getshortcodes.com/pricing/', array( 'wp-admin', 'about', 'upgrade' ) ) ) ); ?>" class="su-admin-about-upgrade-buy-button su-admin-c-button"><?php esc_html_e( 'Upgrade to PRO', 'shortcodes-ultimate' ); ?> &rarr;</a>
80
+ </div>
81
+ </div>
82
+
83
+ <?php endif; ?>
84
+
85
+ <div class="su-admin-about-help">
86
+ <h2><?php esc_html_e( 'Get help', 'shortcodes-ultimate' ); ?></h2>
87
+ <div class="su-admin-about-help-menu">
88
+ <ul>
89
+ <li>
90
+ <a href="https://getshortcodes.com/docs/" target="_blank">
91
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="18" height="18" fill="none" stroke="currentcolor" stroke-linecap="round" stroke-linejoin="round" stroke-width="3"><path d="M16 7 C16 7 9 1 2 6 L2 28 C9 23 16 28 16 28 16 28 23 23 30 28 L30 6 C23 1 16 7 16 7 Z M16 7 L16 28"/></svg>
92
+ <?php esc_html_e( 'Plugin documentation', 'shortcodes-ultimate' ); ?>
93
+ </a>
94
+ </li>
95
+ <li>
96
+ <a href="https://wordpress.org/support/plugin/shortcodes-ultimate/" target="_blank">
97
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="18" height="18" fill="none" stroke="currentcolor" stroke-linecap="round" stroke-linejoin="round" stroke-width="3"><path d="M2 4 L30 4 30 22 16 22 8 29 8 22 2 22 Z"/></svg>
98
+ <?php esc_html_e( 'Community support forum', 'shortcodes-ultimate' ); ?>
99
+ </a>
100
+ </li>
101
+ <li>
102
+ <a href="https://getshortcodes.com/support/open-support-ticket/" target="_blank">
103
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="18" height="18" fill="none" stroke="currentcolor" stroke-linecap="round" stroke-linejoin="round" stroke-width="3"><path d="M2 26 L30 26 30 6 2 6 Z M2 6 L16 16 30 6"/></svg>
104
+ <?php esc_html_e( 'Premium support', 'shortcodes-ultimate' ); ?>
105
+ </a>
106
+ </li>
107
+ </ul>
108
+ </div>
109
  </div>
110
+
111
  </div>
112
 
113
  </div>
admin/partials/pages/addons.php DELETED
@@ -1,39 +0,0 @@
1
- <?php defined( 'ABSPATH' ) || exit; ?>
2
-
3
- <?php $addons = $this->get_addons(); ?>
4
-
5
- <div id="su_admin_addons" class="wrap su-admin-addons wp-clearfix">
6
-
7
- <h1><?php $this->the_page_title(); ?></h1>
8
-
9
- <div class="su-admin-addons-list">
10
-
11
- <?php if ( empty( $addons ) ) : ?>
12
-
13
- <p>
14
- <a href="https://getshortcodes.com/add-ons/" target="_blank" class="button button-primary"><?php esc_html_e( 'Premium Add-ons', 'shortcodes-ultimate' ); ?> →</a>
15
- </p>
16
-
17
- <?php else : ?>
18
-
19
- <?php foreach ( $addons as $addon ) : ?>
20
-
21
- <div class="su-admin-addons-item">
22
- <div class="su-admin-addons-item-content">
23
- <img src="<?php echo esc_attr( $addon['image'] ); ?>" alt="" class="su-admin-addons-item-image">
24
- <h2 class="su-admin-addons-item-title"><?php echo esc_html( $addon['title'] ); ?></h2>
25
- <p class="su-admin-addons-item-description"><?php echo esc_html( $addon['description'] ); ?></p>
26
- <div class="su-admin-addons-item-action" aria-hidden="true">
27
- <span class="button"><?php esc_html_e( 'Learn more', 'shortcodes-ultimate' ); ?></span>
28
- </div>
29
- </div>
30
- <a href="<?php echo esc_attr( $this->get_addon_permalink( $addon ) ); ?>" target="_blank" rel="noopener" class="su-admin-addons-item-overlay"><?php esc_html_e( 'Learn more about', 'shortcodes-ultimate' ); ?> <?php echo esc_html( $addon['title'] ); ?></a>
31
- </div>
32
-
33
- <?php endforeach; ?>
34
-
35
- <?php endif; ?>
36
-
37
- </div>
38
-
39
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/partials/pages/settings.php CHANGED
@@ -2,6 +2,10 @@
2
 
3
  <div class="su-admin-settings wrap">
4
 
 
 
 
 
5
  <h1 class="su-admin-settings-page-title">
6
  <img src="<?php echo esc_attr( su_get_plugin_url() . 'admin/images/plugin-icon.svg' ); ?>" alt="" width="36" height="36">
7
  <?php esc_html_e( 'Shortcodes Ultimate Settings', 'shortcodes-ultimate' ); ?>
2
 
3
  <div class="su-admin-settings wrap">
4
 
5
+ <?php if ( ! su_fs()->can_use_premium_code() && ! su_has_active_addons() ) : ?>
6
+ <?php su_partial( 'admin/partials/notices/pro.php', array( 'page' => 'settings' ) ); ?>
7
+ <?php endif; ?>
8
+
9
  <h1 class="su-admin-settings-page-title">
10
  <img src="<?php echo esc_attr( su_get_plugin_url() . 'admin/images/plugin-icon.svg' ); ?>" alt="" width="36" height="36">
11
  <?php esc_html_e( 'Shortcodes Ultimate Settings', 'shortcodes-ultimate' ); ?>
admin/partials/pro-features/generator.php CHANGED
@@ -6,17 +6,17 @@
6
  <div class="su-generator-clear"></div>
7
  </div>
8
 
9
- <div class="su-generator-extra-banner">
10
- <div class="su-generator-extra-banner-message">
11
- <?php esc_html_e( 'This shortcode is available with the Extra Shortcodes add-on', 'shortcodes-ultimate' ); ?>
12
- </div>
13
- <img src="<?php echo esc_attr( $data['image_url'] . 'icon-banner.png' ); ?>" class="su-generator-extra-banner-icon">
14
- <h3 class="su-generator-extra-banner-title"><?php esc_html_e( 'Extra Shortcodes', 'shortcodes-ultimate' ); ?></h3>
15
- <p class="su-generator-extra-banner-description"><?php esc_html_e( 'This add-on extends Shortcodes Ultimate with 15 new shortcodes. Parallax sections, responsive content slider, pricing tables and more', 'shortcodes-ultimate' ); ?></p>
16
- <p class="su-generator-extra-banner-action">
17
- <a href="<?php echo esc_attr( su_get_utm_link( 'https://getshortcodes.com/add-ons/extra-shortcodes/', array( 'generator', 'extra-shortcode', 'wp-dashboard' ) ) ); ?>" target="_blank" class="button button-primary"><?php esc_html_e( 'Details & Pricing', 'shortcodes-ultimate' ); ?> &rarr;</a>
18
  </p>
19
- <div class="su-generator-extra-banner-screenshot">
20
  <img src="<?php echo esc_attr( $data['image_url'] . 'screenshots/' . $data['shortcode']['id'] . '.png' ); ?>">
21
  </div>
22
  </div>
6
  <div class="su-generator-clear"></div>
7
  </div>
8
 
9
+ <div class="su-generator-pro-features-banner">
10
+ <img src="<?php echo esc_attr( $data['image_url'] . 'icon-banner.png' ); ?>" class="su-generator-pro-features-banner-icon">
11
+ <h3 class="su-generator-pro-features-banner-title"><?php esc_html_e( 'Shortcodes Ultimate PRO', 'shortcodes-ultimate' ); ?></h3>
12
+ <p class="su-generator-pro-features-banner-description">
13
+ <?php // translators: %s - shortcode name ?>
14
+ <?php printf( esc_html( __( 'This shortcode is available in the Pro version. Upgrade now to get 15 additional shortcodes, including %s and others', 'shortcodes-ultimate' ) ), '<strong style="text-transform:capitalize">' . esc_html( $data['shortcode']['name'] ) . '</strong>' ); ?>
15
+ </p>
16
+ <p class="su-generator-pro-features-banner-action">
17
+ <a href="<?php echo esc_attr( esc_attr( su_get_utm_link( 'https://getshortcodes.com/pricing/', array( 'wp-admin', 'generator', 'shortcode' ) ) ) ); ?>" target="_blank" class="button button-primary"><?php esc_html_e( 'Details & Pricing', 'shortcodes-ultimate' ); ?> &rarr;</a>
18
  </p>
19
+ <div class="su-generator-pro-features-banner-screenshot">
20
  <img src="<?php echo esc_attr( $data['image_url'] . 'screenshots/' . $data['shortcode']['id'] . '.png' ); ?>">
21
  </div>
22
  </div>
admin/partials/settings/fields/checkbox-group.php CHANGED
File without changes
admin/partials/settings/fields/checkbox.php CHANGED
File without changes
admin/partials/settings/fields/css.php CHANGED
File without changes
admin/partials/settings/fields/text.php CHANGED
File without changes
admin/partials/settings/sections/advanced.php CHANGED
File without changes
admin/partials/settings/sections/general.php CHANGED
File without changes
admin/partials/tabs.php CHANGED
File without changes
admin/partials/widget/form.php CHANGED
File without changes
changelog.txt CHANGED
@@ -1,3 +1,8 @@
 
 
 
 
 
1
  ### 5.12.2
2
 
3
  * Fixed issue with Shortcode Generator Presets, introduced in the previous update
1
+ ### 5.12.3
2
+
3
+ * Tested compatibility with WordPress 6.1
4
+
5
+
6
  ### 5.12.2
7
 
8
  * Fixed issue with Shortcode Generator Presets, introduced in the previous update
credits.txt CHANGED
File without changes
freemius/LICENSE.txt ADDED
@@ -0,0 +1,674 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+ Preamble
9
+
10
+ The GNU General Public License is a free, copyleft license for
11
+ software and other kinds of works.
12
+
13
+ The licenses for most software and other practical works are designed
14
+ to take away your freedom to share and change the works. By contrast,
15
+ the GNU General Public License is intended to guarantee your freedom to
16
+ share and change all versions of a program--to make sure it remains free
17
+ software for all its users. We, the Free Software Foundation, use the
18
+ GNU General Public License for most of our software; it applies also to
19
+ any other work released this way by its authors. You can apply it to
20
+ your programs, too.
21
+
22
+ When we speak of free software, we are referring to freedom, not
23
+ price. Our General Public Licenses are designed to make sure that you
24
+ have the freedom to distribute copies of free software (and charge for
25
+ them if you wish), that you receive source code or can get it if you
26
+ want it, that you can change the software or use pieces of it in new
27
+ free programs, and that you know you can do these things.
28
+
29
+ To protect your rights, we need to prevent others from denying you
30
+ these rights or asking you to surrender the rights. Therefore, you have
31
+ certain responsibilities if you distribute copies of the software, or if
32
+ you modify it: responsibilities to respect the freedom of others.
33
+
34
+ For example, if you distribute copies of such a program, whether
35
+ gratis or for a fee, you must pass on to the recipients the same
36
+ freedoms that you received. You must make sure that they, too, receive
37
+ or can get the source code. And you must show them these terms so they
38
+ know their rights.
39
+
40
+ Developers that use the GNU GPL protect your rights with two steps:
41
+ (1) assert copyright on the software, and (2) offer you this License
42
+ giving you legal permission to copy, distribute and/or modify it.
43
+
44
+ For the developers' and authors' protection, the GPL clearly explains
45
+ that there is no warranty for this free software. For both users' and
46
+ authors' sake, the GPL requires that modified versions be marked as
47
+ changed, so that their problems will not be attributed erroneously to
48
+ authors of previous versions.
49
+
50
+ Some devices are designed to deny users access to install or run
51
+ modified versions of the software inside them, although the manufacturer
52
+ can do so. This is fundamentally incompatible with the aim of
53
+ protecting users' freedom to change the software. The systematic
54
+ pattern of such abuse occurs in the area of products for individuals to
55
+ use, which is precisely where it is most unacceptable. Therefore, we
56
+ have designed this version of the GPL to prohibit the practice for those
57
+ products. If such problems arise substantially in other domains, we
58
+ stand ready to extend this provision to those domains in future versions
59
+ of the GPL, as needed to protect the freedom of users.
60
+
61
+ Finally, every program is threatened constantly by software patents.
62
+ States should not allow patents to restrict development and use of
63
+ software on general-purpose computers, but in those that do, we wish to
64
+ avoid the special danger that patents applied to a free program could
65
+ make it effectively proprietary. To prevent this, the GPL assures that
66
+ patents cannot be used to render the program non-free.
67
+
68
+ The precise terms and conditions for copying, distribution and
69
+ modification follow.
70
+
71
+ TERMS AND CONDITIONS
72
+
73
+ 0. Definitions.
74
+
75
+ "This License" refers to version 3 of the GNU General Public License.
76
+
77
+ "Copyright" also means copyright-like laws that apply to other kinds of
78
+ works, such as semiconductor masks.
79
+
80
+ "The Program" refers to any copyrightable work licensed under this
81
+ License. Each licensee is addressed as "you". "Licensees" and
82
+ "recipients" may be individuals or organizations.
83
+
84
+ To "modify" a work means to copy from or adapt all or part of the work
85
+ in a fashion requiring copyright permission, other than the making of an
86
+ exact copy. The resulting work is called a "modified version" of the
87
+ earlier work or a work "based on" the earlier work.
88
+
89
+ A "covered work" means either the unmodified Program or a work based
90
+ on the Program.
91
+
92
+ To "propagate" a work means to do anything with it that, without
93
+ permission, would make you directly or secondarily liable for
94
+ infringement under applicable copyright law, except executing it on a
95
+ computer or modifying a private copy. Propagation includes copying,
96
+ distribution (with or without modification), making available to the
97
+ public, and in some countries other activities as well.
98
+
99
+ To "convey" a work means any kind of propagation that enables other
100
+ parties to make or receive copies. Mere interaction with a user through
101
+ a computer network, with no transfer of a copy, is not conveying.
102
+
103
+ An interactive user interface displays "Appropriate Legal Notices"
104
+ to the extent that it includes a convenient and prominently visible
105
+ feature that (1) displays an appropriate copyright notice, and (2)
106
+ tells the user that there is no warranty for the work (except to the
107
+ extent that warranties are provided), that licensees may convey the
108
+ work under this License, and how to view a copy of this License. If
109
+ the interface presents a list of user commands or options, such as a
110
+ menu, a prominent item in the list meets this criterion.
111
+
112
+ 1. Source Code.
113
+
114
+ The "source code" for a work means the preferred form of the work
115
+ for making modifications to it. "Object code" means any non-source
116
+ form of a work.
117
+
118
+ A "Standard Interface" means an interface that either is an official
119
+ standard defined by a recognized standards body, or, in the case of
120
+ interfaces specified for a particular programming language, one that
121
+ is widely used among developers working in that language.
122
+
123
+ The "System Libraries" of an executable work include anything, other
124
+ than the work as a whole, that (a) is included in the normal form of
125
+ packaging a Major Component, but which is not part of that Major
126
+ Component, and (b) serves only to enable use of the work with that
127
+ Major Component, or to implement a Standard Interface for which an
128
+ implementation is available to the public in source code form. A
129
+ "Major Component", in this context, means a major essential component
130
+ (kernel, window system, and so on) of the specific operating system
131
+ (if any) on which the executable work runs, or a compiler used to
132
+ produce the work, or an object code interpreter used to run it.
133
+
134
+ The "Corresponding Source" for a work in object code form means all
135
+ the source code needed to generate, install, and (for an executable
136
+ work) run the object code and to modify the work, including scripts to
137
+ control those activities. However, it does not include the work's
138
+ System Libraries, or general-purpose tools or generally available free
139
+ programs which are used unmodified in performing those activities but
140
+ which are not part of the work. For example, Corresponding Source
141
+ includes interface definition files associated with source files for
142
+ the work, and the source code for shared libraries and dynamically
143
+ linked subprograms that the work is specifically designed to require,
144
+ such as by intimate data communication or control flow between those
145
+ subprograms and other parts of the work.
146
+
147
+ The Corresponding Source need not include anything that users
148
+ can regenerate automatically from other parts of the Corresponding
149
+ Source.
150
+
151
+ The Corresponding Source for a work in source code form is that
152
+ same work.
153
+
154
+ 2. Basic Permissions.
155
+
156
+ All rights granted under this License are granted for the term of
157
+ copyright on the Program, and are irrevocable provided the stated
158
+ conditions are met. This License explicitly affirms your unlimited
159
+ permission to run the unmodified Program. The output from running a
160
+ covered work is covered by this License only if the output, given its
161
+ content, constitutes a covered work. This License acknowledges your
162
+ rights of fair use or other equivalent, as provided by copyright law.
163
+
164
+ You may make, run and propagate covered works that you do not
165
+ convey, without conditions so long as your license otherwise remains
166
+ in force. You may convey covered works to others for the sole purpose
167
+ of having them make modifications exclusively for you, or provide you
168
+ with facilities for running those works, provided that you comply with
169
+ the terms of this License in conveying all material for which you do
170
+ not control copyright. Those thus making or running the covered works
171
+ for you must do so exclusively on your behalf, under your direction
172
+ and control, on terms that prohibit them from making any copies of
173
+ your copyrighted material outside their relationship with you.
174
+
175
+ Conveying under any other circumstances is permitted solely under
176
+ the conditions stated below. Sublicensing is not allowed; section 10
177
+ makes it unnecessary.
178
+
179
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
+
181
+ No covered work shall be deemed part of an effective technological
182
+ measure under any applicable law fulfilling obligations under article
183
+ 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184
+ similar laws prohibiting or restricting circumvention of such
185
+ measures.
186
+
187
+ When you convey a covered work, you waive any legal power to forbid
188
+ circumvention of technological measures to the extent such circumvention
189
+ is effected by exercising rights under this License with respect to
190
+ the covered work, and you disclaim any intention to limit operation or
191
+ modification of the work as a means of enforcing, against the work's
192
+ users, your or third parties' legal rights to forbid circumvention of
193
+ technological measures.
194
+
195
+ 4. Conveying Verbatim Copies.
196
+
197
+ You may convey verbatim copies of the Program's source code as you
198
+ receive it, in any medium, provided that you conspicuously and
199
+ appropriately publish on each copy an appropriate copyright notice;
200
+ keep intact all notices stating that this License and any
201
+ non-permissive terms added in accord with section 7 apply to the code;
202
+ keep intact all notices of the absence of any warranty; and give all
203
+ recipients a copy of this License along with the Program.
204
+
205
+ You may charge any price or no price for each copy that you convey,
206
+ and you may offer support or warranty protection for a fee.
207
+
208
+ 5. Conveying Modified Source Versions.
209
+
210
+ You may convey a work based on the Program, or the modifications to
211
+ produce it from the Program, in the form of source code under the
212
+ terms of section 4, provided that you also meet all of these conditions:
213
+
214
+ a) The work must carry prominent notices stating that you modified
215
+ it, and giving a relevant date.
216
+
217
+ b) The work must carry prominent notices stating that it is
218
+ released under this License and any conditions added under section
219
+ 7. This requirement modifies the requirement in section 4 to
220
+ "keep intact all notices".
221
+
222
+ c) You must license the entire work, as a whole, under this
223
+ License to anyone who comes into possession of a copy. This
224
+ License will therefore apply, along with any applicable section 7
225
+ additional terms, to the whole of the work, and all its parts,
226
+ regardless of how they are packaged. This License gives no
227
+ permission to license the work in any other way, but it does not
228
+ invalidate such permission if you have separately received it.
229
+
230
+ d) If the work has interactive user interfaces, each must display
231
+ Appropriate Legal Notices; however, if the Program has interactive
232
+ interfaces that do not display Appropriate Legal Notices, your
233
+ work need not make them do so.
234
+
235
+ A compilation of a covered work with other separate and independent
236
+ works, which are not by their nature extensions of the covered work,
237
+ and which are not combined with it such as to form a larger program,
238
+ in or on a volume of a storage or distribution medium, is called an
239
+ "aggregate" if the compilation and its resulting copyright are not
240
+ used to limit the access or legal rights of the compilation's users
241
+ beyond what the individual works permit. Inclusion of a covered work
242
+ in an aggregate does not cause this License to apply to the other
243
+ parts of the aggregate.
244
+
245
+ 6. Conveying Non-Source Forms.
246
+
247
+ You may convey a covered work in object code form under the terms
248
+ of sections 4 and 5, provided that you also convey the
249
+ machine-readable Corresponding Source under the terms of this License,
250
+ in one of these ways:
251
+
252
+ a) Convey the object code in, or embodied in, a physical product
253
+ (including a physical distribution medium), accompanied by the
254
+ Corresponding Source fixed on a durable physical medium
255
+ customarily used for software interchange.
256
+
257
+ b) Convey the object code in, or embodied in, a physical product
258
+ (including a physical distribution medium), accompanied by a
259
+ written offer, valid for at least three years and valid for as
260
+ long as you offer spare parts or customer support for that product
261
+ model, to give anyone who possesses the object code either (1) a
262
+ copy of the Corresponding Source for all the software in the
263
+ product that is covered by this License, on a durable physical
264
+ medium customarily used for software interchange, for a price no
265
+ more than your reasonable cost of physically performing this
266
+ conveying of source, or (2) access to copy the
267
+ Corresponding Source from a network server at no charge.
268
+
269
+ c) Convey individual copies of the object code with a copy of the
270
+ written offer to provide the Corresponding Source. This
271
+ alternative is allowed only occasionally and noncommercially, and
272
+ only if you received the object code with such an offer, in accord
273
+ with subsection 6b.
274
+
275
+ d) Convey the object code by offering access from a designated
276
+ place (gratis or for a charge), and offer equivalent access to the
277
+ Corresponding Source in the same way through the same place at no
278
+ further charge. You need not require recipients to copy the
279
+ Corresponding Source along with the object code. If the place to
280
+ copy the object code is a network server, the Corresponding Source
281
+ may be on a different server (operated by you or a third party)
282
+ that supports equivalent copying facilities, provided you maintain
283
+ clear directions next to the object code saying where to find the
284
+ Corresponding Source. Regardless of what server hosts the
285
+ Corresponding Source, you remain obligated to ensure that it is
286
+ available for as long as needed to satisfy these requirements.
287
+
288
+ e) Convey the object code using peer-to-peer transmission, provided
289
+ you inform other peers where the object code and Corresponding
290
+ Source of the work are being offered to the general public at no
291
+ charge under subsection 6d.
292
+
293
+ A separable portion of the object code, whose source code is excluded
294
+ from the Corresponding Source as a System Library, need not be
295
+ included in conveying the object code work.
296
+
297
+ A "User Product" is either (1) a "consumer product", which means any
298
+ tangible personal property which is normally used for personal, family,
299
+ or household purposes, or (2) anything designed or sold for incorporation
300
+ into a dwelling. In determining whether a product is a consumer product,
301
+ doubtful cases shall be resolved in favor of coverage. For a particular
302
+ product received by a particular user, "normally used" refers to a
303
+ typical or common use of that class of product, regardless of the status
304
+ of the particular user or of the way in which the particular user
305
+ actually uses, or expects or is expected to use, the product. A product
306
+ is a consumer product regardless of whether the product has substantial
307
+ commercial, industrial or non-consumer uses, unless such uses represent
308
+ the only significant mode of use of the product.
309
+
310
+ "Installation Information" for a User Product means any methods,
311
+ procedures, authorization keys, or other information required to install
312
+ and execute modified versions of a covered work in that User Product from
313
+ a modified version of its Corresponding Source. The information must
314
+ suffice to ensure that the continued functioning of the modified object
315
+ code is in no case prevented or interfered with solely because
316
+ modification has been made.
317
+
318
+ If you convey an object code work under this section in, or with, or
319
+ specifically for use in, a User Product, and the conveying occurs as
320
+ part of a transaction in which the right of possession and use of the
321
+ User Product is transferred to the recipient in perpetuity or for a
322
+ fixed term (regardless of how the transaction is characterized), the
323
+ Corresponding Source conveyed under this section must be accompanied
324
+ by the Installation Information. But this requirement does not apply
325
+ if neither you nor any third party retains the ability to install
326
+ modified object code on the User Product (for example, the work has
327
+ been installed in ROM).
328
+
329
+ The requirement to provide Installation Information does not include a
330
+ requirement to continue to provide support service, warranty, or updates
331
+ for a work that has been modified or installed by the recipient, or for
332
+ the User Product in which it has been modified or installed. Access to a
333
+ network may be denied when the modification itself materially and
334
+ adversely affects the operation of the network or violates the rules and
335
+ protocols for communication across the network.
336
+
337
+ Corresponding Source conveyed, and Installation Information provided,
338
+ in accord with this section must be in a format that is publicly
339
+ documented (and with an implementation available to the public in
340
+ source code form), and must require no special password or key for
341
+ unpacking, reading or copying.
342
+
343
+ 7. Additional Terms.
344
+
345
+ "Additional permissions" are terms that supplement the terms of this
346
+ License by making exceptions from one or more of its conditions.
347
+ Additional permissions that are applicable to the entire Program shall
348
+ be treated as though they were included in this License, to the extent
349
+ that they are valid under applicable law. If additional permissions
350
+ apply only to part of the Program, that part may be used separately
351
+ under those permissions, but the entire Program remains governed by
352
+ this License without regard to the additional permissions.
353
+
354
+ When you convey a copy of a covered work, you may at your option
355
+ remove any additional permissions from that copy, or from any part of
356
+ it. (Additional permissions may be written to require their own
357
+ removal in certain cases when you modify the work.) You may place
358
+ additional permissions on material, added by you to a covered work,
359
+ for which you have or can give appropriate copyright permission.
360
+
361
+ Notwithstanding any other provision of this License, for material you
362
+ add to a covered work, you may (if authorized by the copyright holders of
363
+ that material) supplement the terms of this License with terms:
364
+
365
+ a) Disclaiming warranty or limiting liability differently from the
366
+ terms of sections 15 and 16 of this License; or
367
+
368
+ b) Requiring preservation of specified reasonable legal notices or
369
+ author attributions in that material or in the Appropriate Legal
370
+ Notices displayed by works containing it; or
371
+
372
+ c) Prohibiting misrepresentation of the origin of that material, or
373
+ requiring that modified versions of such material be marked in
374
+ reasonable ways as different from the original version; or
375
+
376
+ d) Limiting the use for publicity purposes of names of licensors or
377
+ authors of the material; or
378
+
379
+ e) Declining to grant rights under trademark law for use of some
380
+ trade names, trademarks, or service marks; or
381
+
382
+ f) Requiring indemnification of licensors and authors of that
383
+ material by anyone who conveys the material (or modified versions of
384
+ it) with contractual assumptions of liability to the recipient, for
385
+ any liability that these contractual assumptions directly impose on
386
+ those licensors and authors.
387
+
388
+ All other non-permissive additional terms are considered "further
389
+ restrictions" within the meaning of section 10. If the Program as you
390
+ received it, or any part of it, contains a notice stating that it is
391
+ governed by this License along with a term that is a further
392
+ restriction, you may remove that term. If a license document contains
393
+ a further restriction but permits relicensing or conveying under this
394
+ License, you may add to a covered work material governed by the terms
395
+ of that license document, provided that the further restriction does
396
+ not survive such relicensing or conveying.
397
+
398
+ If you add terms to a covered work in accord with this section, you
399
+ must place, in the relevant source files, a statement of the
400
+ additional terms that apply to those files, or a notice indicating
401
+ where to find the applicable terms.
402
+
403
+ Additional terms, permissive or non-permissive, may be stated in the
404
+ form of a separately written license, or stated as exceptions;
405
+ the above requirements apply either way.
406
+
407
+ 8. Termination.
408
+
409
+ You may not propagate or modify a covered work except as expressly
410
+ provided under this License. Any attempt otherwise to propagate or
411
+ modify it is void, and will automatically terminate your rights under
412
+ this License (including any patent licenses granted under the third
413
+ paragraph of section 11).
414
+
415
+ However, if you cease all violation of this License, then your
416
+ license from a particular copyright holder is reinstated (a)
417
+ provisionally, unless and until the copyright holder explicitly and
418
+ finally terminates your license, and (b) permanently, if the copyright
419
+ holder fails to notify you of the violation by some reasonable means
420
+ prior to 60 days after the cessation.
421
+
422
+ Moreover, your license from a particular copyright holder is
423
+ reinstated permanently if the copyright holder notifies you of the
424
+ violation by some reasonable means, this is the first time you have
425
+ received notice of violation of this License (for any work) from that
426
+ copyright holder, and you cure the violation prior to 30 days after
427
+ your receipt of the notice.
428
+
429
+ Termination of your rights under this section does not terminate the
430
+ licenses of parties who have received copies or rights from you under
431
+ this License. If your rights have been terminated and not permanently
432
+ reinstated, you do not qualify to receive new licenses for the same
433
+ material under section 10.
434
+
435
+ 9. Acceptance Not Required for Having Copies.
436
+
437
+ You are not required to accept this License in order to receive or
438
+ run a copy of the Program. Ancillary propagation of a covered work
439
+ occurring solely as a consequence of using peer-to-peer transmission
440
+ to receive a copy likewise does not require acceptance. However,
441
+ nothing other than this License grants you permission to propagate or
442
+ modify any covered work. These actions infringe copyright if you do
443
+ not accept this License. Therefore, by modifying or propagating a
444
+ covered work, you indicate your acceptance of this License to do so.
445
+
446
+ 10. Automatic Licensing of Downstream Recipients.
447
+
448
+ Each time you convey a covered work, the recipient automatically
449
+ receives a license from the original licensors, to run, modify and
450
+ propagate that work, subject to this License. You are not responsible
451
+ for enforcing compliance by third parties with this License.
452
+
453
+ An "entity transaction" is a transaction transferring control of an
454
+ organization, or substantially all assets of one, or subdividing an
455
+ organization, or merging organizations. If propagation of a covered
456
+ work results from an entity transaction, each party to that
457
+ transaction who receives a copy of the work also receives whatever
458
+ licenses to the work the party's predecessor in interest had or could
459
+ give under the previous paragraph, plus a right to possession of the
460
+ Corresponding Source of the work from the predecessor in interest, if
461
+ the predecessor has it or can get it with reasonable efforts.
462
+
463
+ You may not impose any further restrictions on the exercise of the
464
+ rights granted or affirmed under this License. For example, you may
465
+ not impose a license fee, royalty, or other charge for exercise of
466
+ rights granted under this License, and you may not initiate litigation
467
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
468
+ any patent claim is infringed by making, using, selling, offering for
469
+ sale, or importing the Program or any portion of it.
470
+
471
+ 11. Patents.
472
+
473
+ A "contributor" is a copyright holder who authorizes use under this
474
+ License of the Program or a work on which the Program is based. The
475
+ work thus licensed is called the contributor's "contributor version".
476
+
477
+ A contributor's "essential patent claims" are all patent claims
478
+ owned or controlled by the contributor, whether already acquired or
479
+ hereafter acquired, that would be infringed by some manner, permitted
480
+ by this License, of making, using, or selling its contributor version,
481
+ but do not include claims that would be infringed only as a
482
+ consequence of further modification of the contributor version. For
483
+ purposes of this definition, "control" includes the right to grant
484
+ patent sublicenses in a manner consistent with the requirements of
485
+ this License.
486
+
487
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
488
+ patent license under the contributor's essential patent claims, to
489
+ make, use, sell, offer for sale, import and otherwise run, modify and
490
+ propagate the contents of its contributor version.
491
+
492
+ In the following three paragraphs, a "patent license" is any express
493
+ agreement or commitment, however denominated, not to enforce a patent
494
+ (such as an express permission to practice a patent or covenant not to
495
+ sue for patent infringement). To "grant" such a patent license to a
496
+ party means to make such an agreement or commitment not to enforce a
497
+ patent against the party.
498
+
499
+ If you convey a covered work, knowingly relying on a patent license,
500
+ and the Corresponding Source of the work is not available for anyone
501
+ to copy, free of charge and under the terms of this License, through a
502
+ publicly available network server or other readily accessible means,
503
+ then you must either (1) cause the Corresponding Source to be so
504
+ available, or (2) arrange to deprive yourself of the benefit of the
505
+ patent license for this particular work, or (3) arrange, in a manner
506
+ consistent with the requirements of this License, to extend the patent
507
+ license to downstream recipients. "Knowingly relying" means you have
508
+ actual knowledge that, but for the patent license, your conveying the
509
+ covered work in a country, or your recipient's use of the covered work
510
+ in a country, would infringe one or more identifiable patents in that
511
+ country that you have reason to believe are valid.
512
+
513
+ If, pursuant to or in connection with a single transaction or
514
+ arrangement, you convey, or propagate by procuring conveyance of, a
515
+ covered work, and grant a patent license to some of the parties
516
+ receiving the covered work authorizing them to use, propagate, modify
517
+ or convey a specific copy of the covered work, then the patent license
518
+ you grant is automatically extended to all recipients of the covered
519
+ work and works based on it.
520
+
521
+ A patent license is "discriminatory" if it does not include within
522
+ the scope of its coverage, prohibits the exercise of, or is
523
+ conditioned on the non-exercise of one or more of the rights that are
524
+ specifically granted under this License. You may not convey a covered
525
+ work if you are a party to an arrangement with a third party that is
526
+ in the business of distributing software, under which you make payment
527
+ to the third party based on the extent of your activity of conveying
528
+ the work, and under which the third party grants, to any of the
529
+ parties who would receive the covered work from you, a discriminatory
530
+ patent license (a) in connection with copies of the covered work
531
+ conveyed by you (or copies made from those copies), or (b) primarily
532
+ for and in connection with specific products or compilations that
533
+ contain the covered work, unless you entered into that arrangement,
534
+ or that patent license was granted, prior to 28 March 2007.
535
+
536
+ Nothing in this License shall be construed as excluding or limiting
537
+ any implied license or other defenses to infringement that may
538
+ otherwise be available to you under applicable patent law.
539
+
540
+ 12. No Surrender of Others' Freedom.
541
+
542
+ If conditions are imposed on you (whether by court order, agreement or
543
+ otherwise) that contradict the conditions of this License, they do not
544
+ excuse you from the conditions of this License. If you cannot convey a
545
+ covered work so as to satisfy simultaneously your obligations under this
546
+ License and any other pertinent obligations, then as a consequence you may
547
+ not convey it at all. For example, if you agree to terms that obligate you
548
+ to collect a royalty for further conveying from those to whom you convey
549
+ the Program, the only way you could satisfy both those terms and this
550
+ License would be to refrain entirely from conveying the Program.
551
+
552
+ 13. Use with the GNU Affero General Public License.
553
+
554
+ Notwithstanding any other provision of this License, you have
555
+ permission to link or combine any covered work with a work licensed
556
+ under version 3 of the GNU Affero General Public License into a single
557
+ combined work, and to convey the resulting work. The terms of this
558
+ License will continue to apply to the part which is the covered work,
559
+ but the special requirements of the GNU Affero General Public License,
560
+ section 13, concerning interaction through a network will apply to the
561
+ combination as such.
562
+
563
+ 14. Revised Versions of this License.
564
+
565
+ The Free Software Foundation may publish revised and/or new versions of
566
+ the GNU General Public License from time to time. Such new versions will
567
+ be similar in spirit to the present version, but may differ in detail to
568
+ address new problems or concerns.
569
+
570
+ Each version is given a distinguishing version number. If the
571
+ Program specifies that a certain numbered version of the GNU General
572
+ Public License "or any later version" applies to it, you have the
573
+ option of following the terms and conditions either of that numbered
574
+ version or of any later version published by the Free Software
575
+ Foundation. If the Program does not specify a version number of the
576
+ GNU General Public License, you may choose any version ever published
577
+ by the Free Software Foundation.
578
+
579
+ If the Program specifies that a proxy can decide which future
580
+ versions of the GNU General Public License can be used, that proxy's
581
+ public statement of acceptance of a version permanently authorizes you
582
+ to choose that version for the Program.
583
+
584
+ Later license versions may give you additional or different
585
+ permissions. However, no additional obligations are imposed on any
586
+ author or copyright holder as a result of your choosing to follow a
587
+ later version.
588
+
589
+ 15. Disclaimer of Warranty.
590
+
591
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592
+ APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594
+ OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597
+ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598
+ ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
+
600
+ 16. Limitation of Liability.
601
+
602
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610
+ SUCH DAMAGES.
611
+
612
+ 17. Interpretation of Sections 15 and 16.
613
+
614
+ If the disclaimer of warranty and limitation of liability provided
615
+ above cannot be given local legal effect according to their terms,
616
+ reviewing courts shall apply local law that most closely approximates
617
+ an absolute waiver of all civil liability in connection with the
618
+ Program, unless a warranty or assumption of liability accompanies a
619
+ copy of the Program in return for a fee.
620
+
621
+ END OF TERMS AND CONDITIONS
622
+
623
+ How to Apply These Terms to Your New Programs
624
+
625
+ If you develop a new program, and you want it to be of the greatest
626
+ possible use to the public, the best way to achieve this is to make it
627
+ free software which everyone can redistribute and change under these terms.
628
+
629
+ To do so, attach the following notices to the program. It is safest
630
+ to attach them to the start of each source file to most effectively
631
+ state the exclusion of warranty; and each file should have at least
632
+ the "copyright" line and a pointer to where the full notice is found.
633
+
634
+ {one line to give the program's name and a brief idea of what it does.}
635
+ Copyright (C) {year} {name of author}
636
+
637
+ This program is free software: you can redistribute it and/or modify
638
+ it under the terms of the GNU General Public License as published by
639
+ the Free Software Foundation, either version 3 of the License, or
640
+ (at your option) any later version.
641
+
642
+ This program is distributed in the hope that it will be useful,
643
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
644
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645
+ GNU General Public License for more details.
646
+
647
+ You should have received a copy of the GNU General Public License
648
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
649
+
650
+ Also add information on how to contact you by electronic and paper mail.
651
+
652
+ If the program does terminal interaction, make it output a short
653
+ notice like this when it starts in an interactive mode:
654
+
655
+ {project} Copyright (C) {year} {fullname}
656
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657
+ This is free software, and you are welcome to redistribute it
658
+ under certain conditions; type `show c' for details.
659
+
660
+ The hypothetical commands `show w' and `show c' should show the appropriate
661
+ parts of the General Public License. Of course, your program's commands
662
+ might be different; for a GUI interface, you would use an "about box".
663
+
664
+ You should also get your employer (if you work as a programmer) or school,
665
+ if any, to sign a "copyright disclaimer" for the program, if necessary.
666
+ For more information on this, and how to apply and follow the GNU GPL, see
667
+ <http://www.gnu.org/licenses/>.
668
+
669
+ The GNU General Public License does not permit incorporating your program
670
+ into proprietary programs. If your program is a subroutine library, you
671
+ may consider it more useful to permit linking proprietary applications with
672
+ the library. If this is what you want to do, use the GNU Lesser General
673
+ Public License instead of this License. But first, please read
674
+ <http://www.gnu.org/philosophy/why-not-lgpl.html>.
freemius/assets/css/admin/account.css ADDED
@@ -0,0 +1 @@
 
1
+ label.fs-tag,span.fs-tag{background:#ffba00;color:#fff;display:inline-block;border-radius:3px;padding:5px;font-size:11px;line-height:11px;vertical-align:baseline}label.fs-tag.fs-warn,span.fs-tag.fs-warn{background:#ffba00}label.fs-tag.fs-info,span.fs-tag.fs-info{background:#00a0d2}label.fs-tag.fs-success,span.fs-tag.fs-success{background:#46b450}label.fs-tag.fs-error,span.fs-tag.fs-error{background:#dc3232}.fs-notice[data-id=license_not_whitelabeled].success,.fs-notice[data-id=license_whitelabeled].success{color:inherit;border-left-color:#00a0d2}.fs-notice[data-id=license_not_whitelabeled].success label.fs-plugin-title,.fs-notice[data-id=license_whitelabeled].success label.fs-plugin-title{display:none}#fs_account .postbox,#fs_account .widefat{max-width:800px}#fs_account h3{font-size:1.3em;padding:12px 15px;margin:0 0 12px 0;line-height:1.4;border-bottom:1px solid #f1f1f1}#fs_account h3 .dashicons{width:26px;height:26px;font-size:1.3em}#fs_account i.dashicons{font-size:1.2em;height:1.2em;width:1.2em}#fs_account .dashicons{vertical-align:middle}#fs_account .fs-header-actions{position:absolute;top:17px;right:15px;font-size:.9em}#fs_account .fs-header-actions ul{margin:0}#fs_account .fs-header-actions li{float:left}#fs_account .fs-header-actions li form{display:inline-block}#fs_account .fs-header-actions li a{text-decoration:none}#fs_account_details .button-group{float:right}.rtl #fs_account .fs-header-actions{left:15px;right:auto}.fs-key-value-table{width:100%}.fs-key-value-table form{display:inline-block}.fs-key-value-table tr td:first-child{text-align:right}.fs-key-value-table tr td:first-child nobr{font-weight:bold}.fs-key-value-table tr td:first-child form{display:block}.fs-key-value-table tr td.fs-right{text-align:right}.fs-key-value-table tr.fs-odd{background:#ebebeb}.fs-key-value-table td,.fs-key-value-table th{padding:10px}.fs-key-value-table code{line-height:28px}.fs-key-value-table var,.fs-key-value-table code,.fs-key-value-table input[type=text]{color:#0073aa;font-size:16px;background:none}.fs-key-value-table input[type=text]{width:100%;font-weight:bold}.fs-field-beta_program label{margin-left:7px}label.fs-tag{background:#ffba00;color:#fff;display:inline-block;border-radius:3px;padding:5px;font-size:11px;line-height:11px;vertical-align:baseline}label.fs-tag.fs-warn{background:#ffba00}label.fs-tag.fs-success{background:#46b450}label.fs-tag.fs-error{background:#dc3232}#fs_sites .fs-scrollable-table .fs-table-body{max-height:200px;overflow:auto;border:1px solid #e5e5e5}#fs_sites .fs-scrollable-table .fs-table-body>table.widefat{border:none !important}#fs_sites .fs-scrollable-table .fs-main-column{width:100%}#fs_sites .fs-scrollable-table .fs-site-details td:first-of-type{text-align:right;color:gray;width:1px}#fs_sites .fs-scrollable-table .fs-site-details td:last-of-type{text-align:right}#fs_sites .fs-scrollable-table .fs-install-details table tr td{width:1px;white-space:nowrap}#fs_sites .fs-scrollable-table .fs-install-details table tr td:last-of-type{width:auto}#fs_addons h3{border:none;margin-bottom:0;padding:4px 5px}#fs_addons td{vertical-align:middle}#fs_addons thead{white-space:nowrap}#fs_addons td:first-child,#fs_addons th:first-child{text-align:left;font-weight:bold}#fs_addons td:last-child,#fs_addons th:last-child{text-align:right}#fs_addons th{font-weight:bold}#fs_billing_address{width:100%}#fs_billing_address tr td{width:50%;padding:5px}#fs_billing_address tr:first-of-type td{padding-top:0}#fs_billing_address span{font-weight:bold}#fs_billing_address input,#fs_billing_address select{display:block;width:100%;margin-top:5px}#fs_billing_address input::-moz-placeholder,#fs_billing_address select::-moz-placeholder{color:transparent;opacity:1}#fs_billing_address input:-ms-input-placeholder,#fs_billing_address select:-ms-input-placeholder{color:transparent}#fs_billing_address input::-webkit-input-placeholder,#fs_billing_address select::-webkit-input-placeholder{color:transparent}#fs_billing_address input.fs-read-mode,#fs_billing_address select.fs-read-mode{border-color:transparent;color:#777;border-bottom:1px dashed #ccc;padding-left:0;background:none}#fs_billing_address.fs-read-mode td span{display:none}#fs_billing_address.fs-read-mode input,#fs_billing_address.fs-read-mode select{border-color:transparent;color:#777;border-bottom:1px dashed #ccc;padding-left:0;background:none}#fs_billing_address.fs-read-mode input::-moz-placeholder,#fs_billing_address.fs-read-mode select::-moz-placeholder{color:#ccc;opacity:1}#fs_billing_address.fs-read-mode input:-ms-input-placeholder,#fs_billing_address.fs-read-mode select:-ms-input-placeholder{color:#ccc}#fs_billing_address.fs-read-mode input::-webkit-input-placeholder,#fs_billing_address.fs-read-mode select::-webkit-input-placeholder{color:#ccc}#fs_billing_address button{display:block;width:100%}@media screen and (max-width: 639px){#fs_account .fs-header-actions{position:static;padding:0 15px 12px 15px;margin:0 0 12px 0}#fs_account .fs-header-actions li{float:none;display:inline-block}#fs_account #fs_account_details{display:block}#fs_account #fs_account_details tbody,#fs_account #fs_account_details tr,#fs_account #fs_account_details td,#fs_account #fs_account_details th{display:block}#fs_account #fs_account_details tr td:first-child{text-align:left}#fs_account #fs_account_details tr td:nth-child(2){padding:0 12px}#fs_account #fs_account_details tr td:nth-child(2) code{margin:0;padding:0}#fs_account #fs_account_details tr td:nth-child(2) label{margin-left:0}#fs_account #fs_account_details tr td:nth-child(3){text-align:left}#fs_account #fs_account_details tr.fs-field-plan td:nth-child(2) .button-group{float:none;margin:12px 0}}
freemius/assets/css/admin/add-ons.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-badge{position:absolute;top:10px;right:0;background:#71ae00;color:#fff;text-transform:uppercase;padding:5px 10px;-moz-border-radius:3px 0 0 3px;-webkit-border-radius:3px 0 0 3px;border-radius:3px 0 0 3px;font-weight:bold;border-right:0;-moz-box-shadow:0 2px 1px -1px rgba(0,0,0,.3);-webkit-box-shadow:0 2px 1px -1px rgba(0,0,0,.3);box-shadow:0 2px 1px -1px rgba(0,0,0,.3)}#fs_addons .fs-cards-list{list-style:none}#fs_addons .fs-cards-list .fs-card{float:left;height:152px;width:310px;padding:0;margin:0 0 30px 30px;font-size:14px;list-style:none;border:1px solid #ddd;cursor:pointer;position:relative}#fs_addons .fs-cards-list .fs-card .fs-overlay{position:absolute;left:0;right:0;bottom:0;top:0;z-index:9}#fs_addons .fs-cards-list .fs-card .fs-inner{background-color:#fff;overflow:hidden;height:100%;position:relative}#fs_addons .fs-cards-list .fs-card .fs-inner>ul{-moz-transition:all,.15s;-o-transition:all,.15s;-ms-transition:all,.15s;-webkit-transition:all,.15s;transition:all,.15s;left:0;right:0;top:0;position:absolute}#fs_addons .fs-cards-list .fs-card .fs-inner>ul>li{list-style:none;line-height:18px;padding:0 15px;width:100%;display:block;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-card-banner{padding:0;margin:0;line-height:0;display:block;height:100px;background-repeat:repeat-x;background-size:100% 100%;-moz-transition:all,.15s;-o-transition:all,.15s;-ms-transition:all,.15s;-webkit-transition:all,.15s;transition:all,.15s}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-card-banner .fs-badge.fs-installed-addon-badge{font-size:1.02em;line-height:1.3em}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-title{margin:10px 0 0 0;height:18px;overflow:hidden;color:#000;white-space:nowrap;text-overflow:ellipsis;font-weight:bold}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-offer{font-size:.9em}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-description{background-color:#f9f9f9;padding:10px 15px 100px 15px;border-top:1px solid #eee;margin:0 0 10px 0;color:#777}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-tag{position:absolute;top:10px;right:0px;background:#adff2f;display:block;padding:2px 10px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,.3);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,.3);box-shadow:1px 1px 1px rgba(0,0,0,.3);text-transform:uppercase;font-size:.9em;font-weight:bold}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-cta .button,#fs_addons .fs-cards-list .fs-card .fs-inner .fs-cta .button-group{position:absolute;top:112px;right:10px}@media screen and (min-width: 960px){#fs_addons .fs-cards-list .fs-card:hover .fs-overlay{border:2px solid #29abe1;margin-left:-1px;margin-top:-1px}#fs_addons .fs-cards-list .fs-card:hover .fs-inner ul{top:-100px}#fs_addons .fs-cards-list .fs-card:hover .fs-inner .fs-title,#fs_addons .fs-cards-list .fs-card:hover .fs-inner .fs-offer{color:#29abe1}}#TB_window,#TB_window iframe{width:821px !important}#plugin-information .fyi{width:266px !important}#plugin-information #section-holder{margin-right:299px}#plugin-information #section-description h2,#plugin-information #section-description h3,#plugin-information #section-description p,#plugin-information #section-description b,#plugin-information #section-description i,#plugin-information #section-description blockquote,#plugin-information #section-description li,#plugin-information #section-description ul,#plugin-information #section-description ol{clear:none}#plugin-information #section-description iframe{max-width:100%}#plugin-information #section-description .fs-selling-points{padding-bottom:10px;border-bottom:1px solid #ddd}#plugin-information #section-description .fs-selling-points ul{margin:0}#plugin-information #section-description .fs-selling-points ul li{padding:0;list-style:none outside none}#plugin-information #section-description .fs-selling-points ul li i.dashicons{color:#71ae00;font-size:3em;vertical-align:middle;line-height:30px;float:left;margin:0 0 0 -15px}#plugin-information #section-description .fs-selling-points ul li h3{margin:1em 30px !important}#plugin-information #section-description .fs-screenshots:after{content:"";display:table;clear:both}#plugin-information #section-description .fs-screenshots ul{list-style:none;margin:0}#plugin-information #section-description .fs-screenshots ul li{width:225px;height:225px;float:left;margin-bottom:20px;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}#plugin-information #section-description .fs-screenshots ul li a{display:block;width:100%;height:100%;border:1px solid;-moz-box-shadow:1px 1px 1px rgba(0,0,0,.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,.2);box-shadow:1px 1px 1px rgba(0,0,0,.2);background-size:cover}#plugin-information #section-description .fs-screenshots ul li.odd{margin-right:20px}#plugin-information .plugin-information-pricing{margin:-16px;border-bottom:1px solid #ddd}#plugin-information .plugin-information-pricing .fs-plan h3{margin-top:0;padding:20px;font-size:16px}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper{border-bottom:1px solid #ddd}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab{cursor:pointer;position:relative;padding:0 10px;font-size:.9em}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab label{text-transform:uppercase;color:green;background:#adff2f;position:absolute;left:-1px;right:-1px;bottom:100%;border:1px solid #006400;padding:2px;text-align:center;font-size:.9em;line-height:1em}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab.nav-tab-active{cursor:default;background:#fffeec;border-bottom-color:#fffeec}#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle h3{background:#fffeec;margin:0;padding-bottom:0;color:#0073aa}#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle .nav-tab-wrapper,#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle .fs-billing-frequency{display:none}#plugin-information .plugin-information-pricing .fs-plan .fs-pricing-body{background:#fffeec;padding:20px}#plugin-information .plugin-information-pricing .fs-plan .button{width:100%;text-align:center;font-weight:bold;text-transform:uppercase;font-size:1.1em}#plugin-information .plugin-information-pricing .fs-plan label{white-space:nowrap}#plugin-information .plugin-information-pricing .fs-plan var{font-style:normal}#plugin-information .plugin-information-pricing .fs-plan .fs-billing-frequency,#plugin-information .plugin-information-pricing .fs-plan .fs-annual-discount{text-align:center;display:block;font-weight:bold;margin-bottom:10px;text-transform:uppercase;background:#f3f3f3;padding:2px;border:1px solid #ccc}#plugin-information .plugin-information-pricing .fs-plan .fs-annual-discount{text-transform:none;color:green;background:#adff2f}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms{font-size:.9em}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms i{float:left;margin:0 0 0 -15px}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms li{margin:10px 0 0 0}#plugin-information #section-features .fs-features{margin:-20px -26px}#plugin-information #section-features table{width:100%;border-spacing:0;border-collapse:separate}#plugin-information #section-features table thead th{padding:10px 0}#plugin-information #section-features table thead .fs-price{color:#71ae00;font-weight:normal;display:block;text-align:center}#plugin-information #section-features table tbody td{border-top:1px solid #ccc;padding:10px 0;text-align:center;width:100px;color:#71ae00}#plugin-information #section-features table tbody td:first-child{text-align:left;width:auto;color:inherit;padding-left:26px}#plugin-information #section-features table tbody tr.fs-odd td{background:#fefefe}#plugin-information #section-features .dashicons-yes{width:30px;height:30px;font-size:30px}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .button-group .button,#plugin-information .fs-dropdown .button-group .button{position:relative;width:auto;top:0;right:0}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .button-group .button:focus,#plugin-information .fs-dropdown .button-group .button:focus{z-index:10}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .button-group .fs-dropdown-arrow,#plugin-information .fs-dropdown .button-group .fs-dropdown-arrow{border-top:6px solid #fff;border-right:4px solid transparent;border-left:4px solid transparent;top:12px;position:relative}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown.active:not(.up) .button:not(.fs-dropdown-arrow-button),#plugin-information .fs-dropdown.active:not(.up) .button:not(.fs-dropdown-arrow-button){border-bottom-left-radius:0}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown.active:not(.up) .fs-dropdown-arrow-button,#plugin-information .fs-dropdown.active:not(.up) .fs-dropdown-arrow-button{border-bottom-right-radius:0}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown.active.up .button:not(.fs-dropdown-arrow-button),#plugin-information .fs-dropdown.active.up .button:not(.fs-dropdown-arrow-button){border-top-left-radius:0}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown.active.up .fs-dropdown-arrow-button,#plugin-information .fs-dropdown.active.up .fs-dropdown-arrow-button{border-top-right-radius:0}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .fs-dropdown-list,#plugin-information .fs-dropdown .fs-dropdown-list{position:absolute;right:-1px;top:100%;margin-left:auto;padding:3px 0;border:1px solid #bfbfbf;background-color:#fff;z-index:1;width:230px;text-align:left;-moz-box-shadow:0px 2px 4px -1px rgba(0,0,0,.2),0px 4px 5px 0px rgba(0,0,0,.14),0px 1px 10px 0px rgba(0,0,0,.12);-webkit-box-shadow:0px 2px 4px -1px rgba(0,0,0,.2),0px 4px 5px 0px rgba(0,0,0,.14),0px 1px 10px 0px rgba(0,0,0,.12);box-shadow:0px 2px 4px -1px rgba(0,0,0,.2),0px 4px 5px 0px rgba(0,0,0,.14),0px 1px 10px 0px rgba(0,0,0,.12)}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .fs-dropdown-list li,#plugin-information .fs-dropdown .fs-dropdown-list li{margin:0}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .fs-dropdown-list li a,#plugin-information .fs-dropdown .fs-dropdown-list li a{display:block;padding:5px 10px;text-decoration:none;text-shadow:none}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .fs-dropdown-list li:hover,#plugin-information .fs-dropdown .fs-dropdown-list li:hover{background-color:#0074a3;color:#fff}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .fs-dropdown-list li:hover a,#plugin-information .fs-dropdown .fs-dropdown-list li:hover a{color:#fff}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown:not(.up) .fs-dropdown-list,#plugin-information .fs-dropdown:not(.up) .fs-dropdown-list{-moz-border-radius:3px 0 3px 3px;-webkit-border-radius:3px 0 3px 3px;border-radius:3px 0 3px 3px}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown.up .fs-dropdown-list,#plugin-information .fs-dropdown.up .fs-dropdown-list{-moz-border-radius:3px 3px 0 3px;-webkit-border-radius:3px 3px 0 3px;border-radius:3px 3px 0 3px}#plugin-information .fs-dropdown .button-group{width:100%}#plugin-information .fs-dropdown .button-group .button{float:none;font-size:14px;font-weight:normal;text-transform:none}#plugin-information .fs-dropdown .fs-dropdown-list{margin-top:1px}#plugin-information .fs-dropdown.up .fs-dropdown-list{top:auto;bottom:100%;margin-bottom:2px}#plugin-information.wp-core-ui .fs-pricing-body .fs-dropdown .button-group{text-align:center;display:table}#plugin-information.wp-core-ui .fs-pricing-body .fs-dropdown .button-group .button{display:table-cell}#plugin-information.wp-core-ui .fs-pricing-body .fs-dropdown .button-group .button:not(.fs-dropdown-arrow-button){left:1px;width:100%}#plugin-information-footer>.button,#plugin-information-footer .fs-dropdown{position:relative;top:3px}#plugin-information-footer>.button.left,#plugin-information-footer .fs-dropdown.left{float:left}#plugin-information-footer>.right,#plugin-information-footer .fs-dropdown{float:right}@media screen and (max-width: 961px){#fs_addons .fs-cards-list .fs-card{height:265px}}
freemius/assets/css/admin/affiliation.css ADDED
@@ -0,0 +1 @@
 
1
+ #fs_affiliation_content_wrapper #messages{margin-top:25px}#fs_affiliation_content_wrapper h3{font-size:24px;padding:0;margin-left:0}#fs_affiliation_content_wrapper ul li{-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;list-style-type:none}#fs_affiliation_content_wrapper ul li:before{content:"✓";margin-right:10px;font-weight:bold}#fs_affiliation_content_wrapper p:not(.description),#fs_affiliation_content_wrapper li,#fs_affiliation_content_wrapper label{font-size:16px !important;line-height:26px !important}#fs_affiliation_content_wrapper .button{margin-top:20px;margin-bottom:7px;line-height:35px;height:40px;font-size:16px}#fs_affiliation_content_wrapper .button#cancel_button{margin-right:5px}#fs_affiliation_content_wrapper form .input-container{margin-bottom:15px}#fs_affiliation_content_wrapper form .input-container .input-label{font-weight:bold;display:block;width:100%}#fs_affiliation_content_wrapper form .input-container.input-container-text label,#fs_affiliation_content_wrapper form .input-container.input-container-text input,#fs_affiliation_content_wrapper form .input-container.input-container-text textarea{display:block}#fs_affiliation_content_wrapper form .input-container #add_domain,#fs_affiliation_content_wrapper form .input-container .remove-domain{text-decoration:none;display:inline-block;margin-top:3px}#fs_affiliation_content_wrapper form .input-container #add_domain:focus,#fs_affiliation_content_wrapper form .input-container .remove-domain:focus{box-shadow:none}#fs_affiliation_content_wrapper form .input-container #add_domain.disabled,#fs_affiliation_content_wrapper form .input-container .remove-domain.disabled{color:#aaa;cursor:default}#fs_affiliation_content_wrapper form #extra_domains_container .description{margin-top:0;position:relative;top:-4px}#fs_affiliation_content_wrapper form #extra_domains_container .extra-domain-input-container{margin-bottom:15px}#fs_affiliation_content_wrapper form #extra_domains_container .extra-domain-input-container .domain{display:inline-block;margin-right:5px}#fs_affiliation_content_wrapper form #extra_domains_container .extra-domain-input-container .domain:last-of-type{margin-bottom:0}
freemius/assets/css/admin/checkout.css ADDED
@@ -0,0 +1 @@
 
1
+ @media screen and (max-width: 782px){#wpbody-content{padding-bottom:0 !important}}
freemius/assets/css/admin/clone-resolution.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-notice[data-id^=clone_resolution_options_notice]{padding:0;color:inherit !important}.fs-notice[data-id^=clone_resolution_options_notice] .fs-notice-body{padding:0;margin-bottom:0}.fs-notice[data-id^=clone_resolution_options_notice] .fs-notice-header{padding:5px 10px}.fs-notice[data-id^=clone_resolution_options_notice] ol{margin-top:0;margin-bottom:0}.fs-notice[data-id^=clone_resolution_options_notice] .fs-clone-resolution-options-container{display:flex;flex-direction:row;padding:0 10px 10px}@media(max-width: 750px){.fs-notice[data-id^=clone_resolution_options_notice] .fs-clone-resolution-options-container{flex-direction:column}}.fs-notice[data-id^=clone_resolution_options_notice] .fs-clone-resolution-option{border:1px solid #ccc;padding:10px 10px 15px 10px;flex:auto;margin:5px}.fs-notice[data-id^=clone_resolution_options_notice] .fs-clone-resolution-option:first-child{margin-left:0}.fs-notice[data-id^=clone_resolution_options_notice] .fs-clone-resolution-option:last-child{margin-right:0}.fs-notice[data-id^=clone_resolution_options_notice] .fs-clone-resolution-option strong{font-size:1.2em;padding:2px;line-height:1.5em}.fs-notice[data-id^=clone_resolution_options_notice] a{text-decoration:none}.fs-notice[data-id^=clone_resolution_options_notice] .button{margin-right:10px}.rtl .fs-notice[data-id^=clone_resolution_options_notice] .button{margin-right:0;margin-left:10px}.fs-notice[data-id^=clone_resolution_options_notice] .fs-clone-documentation-container{padding:0 10px 15px}.fs-notice[data-id=temporary_duplicate_notice] #fs_clone_resolution_error_message{border:1px solid #d3135a;background:#fee;color:#d3135a;padding:10px}.fs-notice[data-id=temporary_duplicate_notice] ol{margin-top:0}
freemius/assets/css/admin/common.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-badge{position:absolute;top:10px;right:0;background:#71ae00;color:#fff;text-transform:uppercase;padding:5px 10px;-moz-border-radius:3px 0 0 3px;-webkit-border-radius:3px 0 0 3px;border-radius:3px 0 0 3px;font-weight:bold;border-right:0;-moz-box-shadow:0 2px 1px -1px rgba(0,0,0,.3);-webkit-box-shadow:0 2px 1px -1px rgba(0,0,0,.3);box-shadow:0 2px 1px -1px rgba(0,0,0,.3)}.theme-browser .theme .fs-premium-theme-badge-container{position:absolute;right:0;top:0}.theme-browser .theme .fs-premium-theme-badge-container .fs-badge{position:relative;top:0;margin-top:10px;text-align:center}.theme-browser .theme .fs-premium-theme-badge-container .fs-badge.fs-premium-theme-badge{font-size:1.1em}.theme-browser .theme .fs-premium-theme-badge-container .fs-badge.fs-beta-theme-badge{background:#00a0d2}.fs-switch{position:relative;display:inline-block;color:#ccc;text-shadow:0 1px 1px rgba(255,255,255,.8);height:18px;padding:6px 6px 5px 6px;border:1px solid #ccc;border:1px solid rgba(0,0,0,.2);background:#ececec;box-shadow:0 0 4px rgba(0,0,0,.1),inset 0 1px 3px 0 rgba(0,0,0,.1);cursor:pointer}.fs-switch span{display:inline-block;width:35px;text-transform:uppercase}.fs-switch .fs-toggle{position:absolute;top:1px;width:37px;height:25px;border:1px solid #ccc;border:1px solid rgba(0,0,0,.3);border-radius:4px;background:#fff;background-color:#fff;background-image:-webkit-gradient(linear, left top, left bottom, color-stop(0, #ececec), color-stop(1, #fff));background-image:-webkit-linear-gradient(top, #ececec, #fff);background-image:-moz-linear-gradient(top, #ececec, #fff);background-image:-ms-linear-gradient(top, #ececec, #fff);background-image:-o-linear-gradient(top, #ececec, #fff);background-image:linear-gradient(top, bottom, #ececec, #fff);box-shadow:inset 0 1px 0 0 rgba(255,255,255,.5);z-index:999;-moz-transition:.4s cubic-bezier(0.54, 1.6, 0.5, 1);-o-transition:.4s cubic-bezier(0.54, 1.6, 0.5, 1);-ms-transition:.4s cubic-bezier(0.54, 1.6, 0.5, 1);-webkit-transition:.4s cubic-bezier(0.54, 1.6, 0.5, 1);transition:.4s cubic-bezier(0.54, 1.6, 0.5, 1)}.fs-switch.fs-off .fs-toggle{left:2%}.fs-switch.fs-on .fs-toggle{left:54%}.fs-switch.fs-round{top:8px;padding:4px 25px;-moz-border-radius:24px;-webkit-border-radius:24px;border-radius:24px}.fs-switch.fs-round .fs-toggle{top:0;width:24px;height:24px;-moz-border-radius:24px;-webkit-border-radius:24px;border-radius:24px}.fs-switch.fs-round.fs-off .fs-toggle{left:-1px}.fs-switch.fs-round.fs-on{background:#0085ba}.fs-switch.fs-round.fs-on .fs-toggle{left:25px}.fs-switch.fs-small.fs-round{padding:1px 19px}.fs-switch.fs-small.fs-round .fs-toggle{top:0;width:18px;height:18px;-moz-border-radius:18px;-webkit-border-radius:18px;border-radius:18px}.fs-switch.fs-small.fs-round.fs-on .fs-toggle{left:19px}body.fs-loading,body.fs-loading *{cursor:wait !important}#fs_frame{line-height:0;font-size:0}.fs-full-size-wrapper{margin:40px 0 -65px -20px}@media(max-width: 600px){.fs-full-size-wrapper{margin:0 0 -65px -10px}}.fs-notice{position:relative}.fs-notice.fs-has-title{margin-bottom:30px !important}.fs-notice.success{color:green}.fs-notice.promotion{border-color:#00a0d2 !important;background-color:#f2fcff !important}.fs-notice .fs-notice-body{margin:.5em 0;padding:2px}.fs-notice .fs-close{cursor:pointer;color:#aaa;float:right}.fs-notice .fs-close:hover{color:#666}.fs-notice .fs-close>*{margin-top:7px;display:inline-block}.fs-notice label.fs-plugin-title{background:rgba(0,0,0,.3);color:#fff;padding:2px 10px;position:absolute;top:100%;bottom:auto;right:auto;-moz-border-radius:0 0 3px 3px;-webkit-border-radius:0 0 3px 3px;border-radius:0 0 3px 3px;left:10px;font-size:12px;font-weight:bold;cursor:auto}div.fs-notice.updated,div.fs-notice.success,div.fs-notice.promotion{display:block !important}.rtl .fs-notice .fs-close{float:left}.fs-secure-notice{position:fixed;top:32px;left:160px;right:0;background:#ebfdeb;padding:10px 20px;color:green;z-index:9999;-moz-box-shadow:0 2px 2px rgba(6,113,6,.3);-webkit-box-shadow:0 2px 2px rgba(6,113,6,.3);box-shadow:0 2px 2px rgba(6,113,6,.3);opacity:.95;filter:alpha(opacity=95)}.fs-secure-notice:hover{opacity:1;filter:alpha(opacity=100)}.fs-secure-notice a.fs-security-proof{color:green;text-decoration:none}@media screen and (max-width: 960px){.fs-secure-notice{left:36px}}@media screen and (max-width: 600px){.fs-secure-notice{display:none}}@media screen and (max-width: 1250px){#fs_promo_tab{display:none}}@media screen and (max-width: 782px){.fs-secure-notice{left:0;top:46px;text-align:center}}span.fs-submenu-item.fs-sub:before{content:"↳";padding:0 5px}.rtl span.fs-submenu-item.fs-sub:before{content:"↲"}.fs-submenu-item.pricing.upgrade-mode{color:#adff2f}.fs-submenu-item.pricing.trial-mode{color:#83e2ff}#adminmenu .update-plugins.fs-trial{background-color:#00b9eb}.fs-ajax-spinner{border:0;width:20px;height:20px;margin-right:5px;vertical-align:sub;display:inline-block;background:url("/wp-admin/images/wpspin_light-2x.gif");background-size:contain;margin-bottom:-2px}.wrap.fs-section h2{text-align:left}.plugins p.fs-upgrade-notice{border:0;background-color:#d54e21;padding:10px;color:#f9f9f9;margin-top:10px}
freemius/assets/css/admin/connect.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-tooltip-trigger{position:relative}.fs-tooltip-trigger:not(a){cursor:help}.fs-tooltip-trigger .dashicons{float:none !important}.fs-tooltip-trigger .fs-tooltip{opacity:0;visibility:hidden;-moz-transition:opacity .3s ease-in-out;-o-transition:opacity .3s ease-in-out;-ms-transition:opacity .3s ease-in-out;-webkit-transition:opacity .3s ease-in-out;transition:opacity .3s ease-in-out;position:absolute;background:rgba(0,0,0,.8);color:#fff !important;font-family:"arial",serif;font-size:12px;padding:10px;z-index:999999;bottom:100%;margin-bottom:5px;left:-17px;right:0;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,.2);box-shadow:1px 1px 1px rgba(0,0,0,.2);line-height:1.3em;font-weight:bold;text-align:left;text-transform:none !important}.rtl .fs-tooltip-trigger .fs-tooltip{text-align:right;left:auto;right:-17px}.fs-tooltip-trigger .fs-tooltip::after{content:" ";display:block;width:0;height:0;border-style:solid;border-width:5px 5px 0 5px;border-color:rgba(0,0,0,.8) transparent transparent transparent;position:absolute;top:100%;left:21px}.rtl .fs-tooltip-trigger .fs-tooltip::after{right:21px;left:auto}.fs-tooltip-trigger:hover .fs-tooltip{visibility:visible;opacity:1}#fs_connect{width:484px;margin:60px auto 20px auto}#fs_connect a{color:inherit}#fs_connect a:not(.button){text-decoration:underline}#fs_connect .fs-box-container{box-shadow:0 1px 2px rgba(0,0,0,.3);border-radius:3px;overflow:hidden;padding-top:40px;background:#f0f0f1}@media screen and (max-width: 483px){#fs_connect{width:auto;margin:30px 0 0 -10px}#fs_connect .fs-box-container{-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none}}#fs_connect .fs-content{background:#fff;padding:30px 20px}#fs_connect .fs-content .fs-error{background:snow;color:#d3135a;border:1px solid #d3135a;-moz-box-shadow:0 1px 1px 0 rgba(0,0,0,.1);-webkit-box-shadow:0 1px 1px 0 rgba(0,0,0,.1);box-shadow:0 1px 1px 0 rgba(0,0,0,.1);text-align:center;padding:5px;margin-bottom:10px}#fs_connect .fs-content h2{line-height:1.5em}#fs_connect .fs-content p{margin:0;padding:0;font-size:1.2em}#fs_connect .fs-license-key-container{position:relative;width:280px;margin:10px auto 0 auto}#fs_connect .fs-license-key-container input{width:100%}#fs_connect .fs-license-key-container .dashicons{position:absolute;top:5px;right:5px}#fs_connect.require-license-key .fs-content{padding-bottom:10px}#fs_connect.require-license-key .fs-actions{border-top:none}#fs_connect.require-license-key .fs-sites-list-container td{cursor:pointer}#fs_connect #delegate_to_site_admins{margin-right:15px;float:right;height:26px;vertical-align:middle;line-height:37px;font-weight:bold;border-bottom:1px dashed;text-decoration:none}#fs_connect #delegate_to_site_admins.rtl{margin-left:15px;margin-right:0}#fs_connect .fs-actions{padding:10px 20px;background:#fff;border-width:1px 0;border-style:solid;border-color:#f1f1f1}#fs_connect .fs-actions .button{padding:0 10px 1px;line-height:35px;height:37px;font-size:16px;margin-bottom:0}#fs_connect .fs-actions .button .dashicons{font-size:37px;margin-left:-8px;margin-right:12px}#fs_connect .fs-actions .button.button-primary{padding-right:15px;padding-left:15px}#fs_connect .fs-actions .button.button-primary:after{content:" ➜"}#fs_connect .fs-actions .button.button-primary.fs-loading:after{content:""}#fs_connect .fs-actions .button.button-secondary{float:right}#fs_connect.fs-anonymous-disabled .fs-actions .button.button-primary{width:100%}#fs_connect .fs-permissions{padding:10px 20px;background:#fff;-moz-transition:background .5s ease;-o-transition:background .5s ease;-ms-transition:background .5s ease;-webkit-transition:background .5s ease;transition:background .5s ease}#fs_connect .fs-permissions .fs-license-sync-disclaimer{text-align:center;margin-top:0}#fs_connect .fs-permissions>.fs-trigger{font-size:.9em;text-decoration:none;text-align:center;display:block}#fs_connect .fs-permissions>.fs-trigger .fs-arrow::after{content:"→";width:20px;display:inline-block}#fs_connect .fs-permissions.fs-open>.fs-trigger .fs-arrow::after{content:"↓" !important}#fs_connect .fs-permissions ul li{padding-left:0;padding-right:0}@media screen and (max-width: 483px){#fs_connect .fs-permissions ul{height:auto;margin:20px}}#fs_connect .fs-freemium-licensing{padding:8px;background:#777;color:#fff}#fs_connect .fs-freemium-licensing p{text-align:center;display:block;margin:0;padding:0}#fs_connect .fs-freemium-licensing a{color:inherit;text-decoration:underline}#fs_connect .fs-header{padding:0;line-height:0;height:0;position:relative}#fs_connect .fs-header .fs-site-icon,#fs_connect .fs-header .fs-connect-logo{position:absolute;top:-8px;border-radius:50%}#fs_connect .fs-header .fs-site-icon{left:152px}#fs_connect .fs-header .fs-connect-logo{right:152px}#fs_connect .fs-header .fs-site-icon,#fs_connect .fs-header img,#fs_connect .fs-header object{width:50px;height:50px;border-radius:50%}#fs_connect .fs-header .fs-plugin-icon{position:absolute;overflow:hidden;top:-23px;left:50%;margin-left:-44px;border-radius:50%;z-index:1}#fs_connect .fs-header .fs-plugin-icon,#fs_connect .fs-header .fs-plugin-icon img{width:80px;height:80px}#fs_connect .fs-header .dashicons-wordpress-alt{font-size:40px;background:#01749a;color:#fff;width:40px;height:40px;padding:5px;border-radius:50%}#fs_connect .fs-header .dashicons-plus{position:absolute;top:50%;font-size:30px;margin-top:-10px;color:#bbb}#fs_connect .fs-header .dashicons-plus.fs-first{left:28%}#fs_connect .fs-header .dashicons-plus.fs-second{left:65%}#fs_connect .fs-header .fs-plugin-icon,#fs_connect .fs-header .fs-connect-logo,#fs_connect .fs-header .fs-site-icon{border:1px solid #efefef;padding:3px;background:#fff}#fs_connect .fs-terms{text-align:center;font-size:.85em;padding:10px 5px}#fs_connect .fs-terms,#fs_connect .fs-terms a{color:#999}#fs_connect .fs-terms a{text-decoration:none}.fs-multisite-options-container{margin-top:20px;border:1px solid #ccc;padding:5px}.fs-multisite-options-container a{text-decoration:none}.fs-multisite-options-container a:focus{box-shadow:none}.fs-multisite-options-container a.selected{font-weight:bold}.fs-multisite-options-container.fs-apply-on-all-sites{border:0 none;padding:0}.fs-multisite-options-container.fs-apply-on-all-sites .fs-all-sites-options{border-spacing:0}.fs-multisite-options-container.fs-apply-on-all-sites .fs-all-sites-options td:not(:first-child){display:none}.fs-multisite-options-container .fs-sites-list-container{display:none;overflow:auto}.fs-multisite-options-container .fs-sites-list-container table td{border-top:1px solid #ccc;padding:4px 2px}#fs_marketing_optin{display:none;margin-top:10px;border:1px solid #ccc;padding:10px;line-height:1.5em}#fs_marketing_optin .fs-message{display:block;margin-bottom:5px;font-size:1.05em;font-weight:600}#fs_marketing_optin.error{border:1px solid #d3135a;background:#fee}#fs_marketing_optin.error .fs-message{color:#d3135a}#fs_marketing_optin .fs-input-container{margin-top:5px}#fs_marketing_optin .fs-input-container label{margin-top:5px;display:block}#fs_marketing_optin .fs-input-container label input{float:left;margin:1px 0 0 0}#fs_marketing_optin .fs-input-container label:first-child{display:block;margin-bottom:2px}#fs_marketing_optin .fs-input-label{display:block;margin-left:20px}#fs_marketing_optin .fs-input-label .underlined{text-decoration:underline}.rtl #fs_marketing_optin .fs-input-container label input{float:right}.rtl #fs_marketing_optin .fs-input-label{margin-left:0;margin-right:20px}.rtl #fs_connect{border-radius:3px}.rtl #fs_connect .fs-actions{padding:10px 20px;background:#c0c7ca}.rtl #fs_connect .fs-actions .button .dashicons{font-size:37px;margin-left:-8px;margin-right:12px}.rtl #fs_connect .fs-actions .button.button-primary:after{content:" »"}.rtl #fs_connect .fs-actions .button.button-primary.fs-loading:after{content:""}.rtl #fs_connect .fs-actions .button.button-secondary{float:left}.rtl #fs_connect .fs-header .fs-site-icon{right:20px;left:auto}.rtl #fs_connect .fs-header .fs-connect-logo{right:auto;left:20px}.rtl #fs_connect .fs-permissions>.fs-trigger .fs-arrow::after{content:"←"}#fs_theme_connect_wrapper{position:fixed;top:0;height:100%;width:100%;z-index:99990;background:rgba(0,0,0,.75);text-align:center;overflow-y:auto}#fs_theme_connect_wrapper:before{content:"";display:inline-block;vertical-align:middle;height:100%}#fs_theme_connect_wrapper>button.close{color:#fff;cursor:pointer;height:40px;width:40px;position:absolute;right:0;border:0;background-color:transparent;top:32px}#fs_theme_connect_wrapper #fs_connect{top:0;text-align:left;display:inline-block;vertical-align:middle;margin-top:0;margin-bottom:20px}#fs_theme_connect_wrapper #fs_connect .fs-terms,#fs_theme_connect_wrapper #fs_connect .fs-terms a{color:#c5c5c5}.wp-pointer-content #fs_connect{margin:0;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none}.fs-opt-in-pointer .wp-pointer-content{padding:0}.fs-opt-in-pointer.wp-pointer-top .wp-pointer-arrow{border-bottom-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-top .wp-pointer-arrow-inner{border-bottom-color:#fafafa}.fs-opt-in-pointer.wp-pointer-bottom .wp-pointer-arrow{border-top-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-bottom .wp-pointer-arrow-inner{border-top-color:#fafafa}.fs-opt-in-pointer.wp-pointer-left .wp-pointer-arrow{border-right-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-left .wp-pointer-arrow-inner{border-right-color:#fafafa}.fs-opt-in-pointer.wp-pointer-right .wp-pointer-arrow{border-left-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-right .wp-pointer-arrow-inner{border-left-color:#fafafa}#license_issues_link{display:block;text-align:center;font-size:.9em;margin-top:10px}.fs-tooltip-trigger{position:relative}.fs-tooltip-trigger:not(a){cursor:help}.fs-tooltip-trigger .dashicons{float:none !important}.fs-tooltip-trigger .fs-tooltip{opacity:0;visibility:hidden;-moz-transition:opacity .3s ease-in-out;-o-transition:opacity .3s ease-in-out;-ms-transition:opacity .3s ease-in-out;-webkit-transition:opacity .3s ease-in-out;transition:opacity .3s ease-in-out;position:absolute;background:rgba(0,0,0,.8);color:#fff !important;font-family:"arial",serif;font-size:12px;padding:10px;z-index:999999;bottom:100%;margin-bottom:5px;left:-17px;right:0;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,.2);box-shadow:1px 1px 1px rgba(0,0,0,.2);line-height:1.3em;font-weight:bold;text-align:left;text-transform:none !important}.rtl .fs-tooltip-trigger .fs-tooltip{text-align:right;left:auto;right:-17px}.fs-tooltip-trigger .fs-tooltip::after{content:" ";display:block;width:0;height:0;border-style:solid;border-width:5px 5px 0 5px;border-color:rgba(0,0,0,.8) transparent transparent transparent;position:absolute;top:100%;left:21px}.rtl .fs-tooltip-trigger .fs-tooltip::after{right:21px;left:auto}.fs-tooltip-trigger:hover .fs-tooltip{visibility:visible;opacity:1}.fs-permissions .fs-permission.fs-disabled{color:#aaa}.fs-permissions .fs-permission.fs-disabled .fs-permission-description span{color:#aaa}.fs-permissions .fs-permission .fs-switch-feedback{position:absolute;right:15px;top:52px}.fs-permissions ul{height:0;overflow:hidden;margin:0}.fs-permissions ul li{padding:17px 15px;margin:0;position:relative}.fs-permissions ul li>i.dashicons{float:left;font-size:30px;width:30px;height:30px;padding:5px}.fs-permissions ul li .fs-switch{float:right}.fs-permissions ul li .fs-permission-description{margin-left:55px}.fs-permissions ul li .fs-permission-description span{font-size:14px;font-weight:500;color:#23282d}.fs-permissions ul li .fs-permission-description .fs-tooltip{font-size:13px;font-weight:bold}.fs-permissions ul li .fs-permission-description .fs-tooltip-trigger .dashicons{margin:-1px 2px 0 2px}.fs-permissions ul li .fs-permission-description p{margin:2px 0 0 0}.fs-permissions.fs-open{background:#fff}.fs-permissions.fs-open ul{overflow:initial;height:auto;margin:20px 0 10px 0}.fs-permissions .fs-switch-feedback .fs-ajax-spinner{margin-right:10px}.fs-permissions .fs-switch-feedback.success{color:#71ae00}.rtl .fs-permissions .fs-switch-feedback{right:auto;left:15px}.rtl .fs-permissions .fs-switch-feedback .fs-ajax-spinner{margin-left:10px;margin-right:0}.rtl .fs-permissions ul li .fs-permission-description{margin-right:55px;margin-left:0}.rtl .fs-permissions ul li .fs-switch{float:left}.rtl .fs-permissions ul li i.dashicons{float:right}
freemius/assets/css/admin/debug.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-switch-label{font-size:20px;line-height:31px;margin:0 5px}#fs_log_book table{font-family:Consolas,Monaco,monospace;font-size:12px}#fs_log_book table th{color:#ccc}#fs_log_book table tr{background:#232525}#fs_log_book table tr.alternate{background:#2b2b2b}#fs_log_book table tr td.fs-col--logger{color:#5a7435}#fs_log_book table tr td.fs-col--type{color:#ffc861}#fs_log_book table tr td.fs-col--function{color:#a7b7b1;font-weight:bold}#fs_log_book table tr td.fs-col--message,#fs_log_book table tr td.fs-col--message a{color:#9a73ac !important}#fs_log_book table tr td.fs-col--file{color:#d07922}#fs_log_book table tr td.fs-col--timestamp{color:#6596be}
freemius/assets/css/admin/dialog-boxes.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-modal{position:fixed;overflow:auto;height:100%;width:100%;top:0;z-index:100000;display:none;background:rgba(0,0,0,.6)}@media(min-width: 961px){.fs-modal{padding-left:160px}.rtl .fs-modal{padding-left:0;padding-right:160px}}.fs-modal .dashicons{vertical-align:middle}.fs-modal .fs-modal-dialog{background:transparent;position:absolute;left:50%;margin-left:-298px;padding-bottom:30px;top:-100%;z-index:100001;width:596px}@media(max-width: 650px){.fs-modal .fs-modal-dialog{margin-left:-50%;box-sizing:border-box;padding-left:10px;padding-right:10px;width:100%}.fs-modal .fs-modal-dialog .fs-modal-panel>h3>strong{font-size:1.3em}}.fs-modal.active{display:block}.fs-modal.active:before{display:block}.fs-modal.active .fs-modal-dialog{top:10%}.fs-modal.fs-success .fs-modal-header{border-bottom-color:#46b450}.fs-modal.fs-success .fs-modal-body{background-color:#f7fff7}.fs-modal.fs-warn .fs-modal-header{border-bottom-color:#ffb900}.fs-modal.fs-warn .fs-modal-body{background-color:#fff8e5}.fs-modal.fs-error .fs-modal-header{border-bottom-color:#dc3232}.fs-modal.fs-error .fs-modal-body{background-color:#ffeaea}.fs-modal .fs-modal-body,.fs-modal .fs-modal-footer{border:0;background:#fefefe;padding:20px}.fs-modal .fs-modal-header{border-bottom:#eee solid 1px;background:#fbfbfb;padding:15px 20px;position:relative;margin-bottom:-10px}.fs-modal .fs-modal-header h4{margin:0;padding:0;text-transform:uppercase;font-size:1.2em;font-weight:bold;color:#cacaca;text-shadow:1px 1px 1px #fff;letter-spacing:.6px;-webkit-font-smoothing:antialiased}.fs-modal .fs-modal-header .fs-close{position:absolute;right:10px;top:12px;cursor:pointer;color:#bbb;-moz-border-radius:20px;-webkit-border-radius:20px;border-radius:20px;padding:3px;-moz-transition:all .2s ease-in-out;-o-transition:all .2s ease-in-out;-ms-transition:all .2s ease-in-out;-webkit-transition:all .2s ease-in-out;transition:all .2s ease-in-out}.fs-modal .fs-modal-header .fs-close:hover{color:#fff;background:#aaa}.fs-modal .fs-modal-header .fs-close .dashicons,.fs-modal .fs-modal-header .fs-close:hover .dashicons{text-decoration:none}.fs-modal .fs-modal-body{border-bottom:0}.fs-modal .fs-modal-body p{font-size:14px}.fs-modal .fs-modal-body h2{font-size:20px;line-height:1.5em}.fs-modal .fs-modal-body>div{margin-top:10px}.fs-modal .fs-modal-body>div h2{font-weight:bold;font-size:20px;margin-top:0}.fs-modal .fs-modal-footer{border-top:#eee solid 1px;text-align:right}.fs-modal .fs-modal-footer>.button{margin:0 7px}.fs-modal .fs-modal-footer>.button:last-of-type{margin:0}.fs-modal .fs-modal-panel>.notice.inline{margin:0;display:none}.fs-modal .fs-modal-panel:not(.active){display:none}.rtl .fs-modal .fs-modal-header .fs-close{right:auto;left:20px}.rtl .fs-modal .fs-modal-footer{text-align:left}body.has-fs-modal{overflow:hidden}.fs-modal.fs-modal-deactivation-feedback .reason-input,.fs-modal.fs-modal-deactivation-feedback .internal-message{margin:3px 0 3px 22px}.fs-modal.fs-modal-deactivation-feedback .reason-input input,.fs-modal.fs-modal-deactivation-feedback .reason-input textarea,.fs-modal.fs-modal-deactivation-feedback .internal-message input,.fs-modal.fs-modal-deactivation-feedback .internal-message textarea{width:100%}.fs-modal.fs-modal-deactivation-feedback li.reason.has-internal-message .internal-message{border:1px solid #ccc;padding:7px;display:none}@media(max-width: 650px){.fs-modal.fs-modal-deactivation-feedback li.reason li.reason{margin-bottom:10px}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason .reason-input,.fs-modal.fs-modal-deactivation-feedback li.reason li.reason .internal-message{margin-left:29px}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason label{display:table}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason label>span{display:table-cell;font-size:1.3em}}.fs-modal.fs-modal-deactivation-feedback .anonymous-feedback-label,.fs-modal.fs-modal-deactivation-feedback .feedback-from-snooze-label{float:left;line-height:30px}.rtl .fs-modal.fs-modal-deactivation-feedback .anonymous-feedback-label,.rtl .fs-modal.fs-modal-deactivation-feedback .feedback-from-snooze-label{float:right}.fs-modal.fs-modal-deactivation-feedback .fs-modal-panel{margin-top:0 !important}.fs-modal.fs-modal-deactivation-feedback .fs-modal-panel h3{margin-top:0;line-height:1.5em}#the-list .deactivate>.fs-slug{display:none}.fs-modal.fs-modal-subscription-cancellation .fs-price-increase-warning{color:red;font-weight:bold;padding:0 25px;margin-bottom:0}.fs-modal.fs-modal-subscription-cancellation ul.subscription-actions label input{float:left;top:5px;position:relative}.rtl .fs-modal.fs-modal-subscription-cancellation ul.subscription-actions label input{float:right}.fs-modal.fs-modal-subscription-cancellation ul.subscription-actions label span{display:block;margin-left:24px}.rtl .fs-modal.fs-modal-subscription-cancellation ul.subscription-actions label span{margin-left:0;margin-right:24px}.fs-modal.fs-modal-license-activation .fs-modal-body input.fs-license-key{width:100%}.fs-license-options-container table,.fs-license-options-container table select,.fs-license-options-container table .fs-available-license-key{width:100%}.fs-license-options-container table td:first-child{width:1%}.fs-license-options-container table .fs-other-license-key-container label{position:relative;top:6px;float:left;margin-right:5px}.fs-license-options-container table .fs-other-license-key-container div{overflow:hidden;width:auto;height:30px;display:block;top:2px;position:relative}.fs-license-options-container table .fs-other-license-key-container div input{margin:0}.fs-sites-list-container td{cursor:pointer}.fs-modal.fs-modal-user-change .fs-modal-body input#fs_other_email_address{width:100%}.fs-user-change-options-container table{width:100%;border-collapse:collapse}.fs-user-change-options-container table tr{display:block;margin-bottom:2px}.fs-user-change-options-container table .fs-email-address-container td{display:inline-block}.fs-user-change-options-container table .fs-email-address-container input[type=radio]{margin-bottom:0;margin-top:0}.fs-user-change-options-container table .fs-other-email-address-container{width:100%}.fs-user-change-options-container table .fs-other-email-address-container>div{display:table;width:100%}.fs-user-change-options-container table .fs-other-email-address-container>div label,.fs-user-change-options-container table .fs-other-email-address-container>div>div{display:table-cell}.fs-user-change-options-container table .fs-other-email-address-container>div label{width:1%;padding-left:3px;padding-right:3px}.fs-user-change-options-container table .fs-other-email-address-container>div>div{width:auto}.fs-user-change-options-container table .fs-other-email-address-container>div>div input{width:100%}.fs-modal.fs-modal-developer-license-debug-mode .fs-modal-body input.fs-license-or-user-key{width:100%}.fs-multisite-options-container{margin-top:20px;border:1px solid #ccc;padding:5px}.fs-multisite-options-container a{text-decoration:none}.fs-multisite-options-container a:focus{box-shadow:none}.fs-multisite-options-container a.selected{font-weight:bold}.fs-multisite-options-container.fs-apply-on-all-sites{border:0 none;padding:0}.fs-multisite-options-container.fs-apply-on-all-sites .fs-all-sites-options{border-spacing:0}.fs-multisite-options-container.fs-apply-on-all-sites .fs-all-sites-options td:not(:first-child){display:none}.fs-multisite-options-container .fs-sites-list-container{display:none;overflow:auto}.fs-multisite-options-container .fs-sites-list-container table td{border-top:1px solid #ccc;padding:4px 2px}.fs-modal.fs-modal-license-key-resend .email-address-container{overflow:hidden;padding-right:2px}.fs-modal.fs-modal-license-key-resend.fs-freemium input.email-address{width:300px}.fs-modal.fs-modal-license-key-resend.fs-freemium label{display:block;margin-bottom:10px}.fs-modal.fs-modal-license-key-resend.fs-premium input.email-address{width:100%}.fs-modal.fs-modal-license-key-resend.fs-premium .button-container{float:right;margin-left:7px}@media(max-width: 650px){.fs-modal.fs-modal-license-key-resend.fs-premium .button-container{margin-top:2px}}.rtl .fs-modal.fs-modal-license-key-resend .fs-modal-body .input-container>.email-address-container{padding-left:2px;padding-right:0}.rtl .fs-modal.fs-modal-license-key-resend .fs-modal-body .button-container{float:left;margin-right:7px;margin-left:0}a.show-license-resend-modal{margin-top:4px;display:inline-block}.fs-modal.fs-modal-email-address-update .fs-modal-body input[type=text]{width:100%}.fs-modal.fs-modal-email-address-update p{margin-bottom:0}.fs-modal.fs-modal-email-address-update ul{margin:1em .5em}.fs-modal.fs-modal-email-address-update ul li label span{float:left;margin-top:0}.fs-modal.fs-modal-email-address-update ul li label span:last-child{display:block;float:none;margin-left:20px}.fs-ajax-loader{position:relative;width:170px;height:20px;margin:auto}.fs-ajax-loader .fs-ajax-loader-bar{position:absolute;top:0;background-color:#0074a3;width:20px;height:20px;-webkit-animation-name:bounce_ajaxLoader;-moz-animation-name:bounce_ajaxLoader;-ms-animation-name:bounce_ajaxLoader;-o-animation-name:bounce_ajaxLoader;animation-name:bounce_ajaxLoader;-webkit-animation-duration:1.5s;-moz-animation-duration:1.5s;-ms-animation-duration:1.5s;-o-animation-duration:1.5s;animation-duration:1.5s;animation-iteration-count:infinite;-o-animation-iteration-count:infinite;-ms-animation-iteration-count:infinite;-webkit-animation-iteration-count:infinite;-moz-animation-iteration-count:infinite;-webkit-animation-direction:normal;-moz-animation-direction:normal;-ms-animation-direction:normal;-o-animation-direction:normal;animation-direction:normal;-moz-transform:.3;-o-transform:.3;-ms-transform:.3;-webkit-transform:.3;transform:.3}.fs-ajax-loader .fs-ajax-loader-bar-1{left:0px;animation-delay:0.6s;-o-animation-delay:0.6s;-ms-animation-delay:0.6s;-webkit-animation-delay:0.6s;-moz-animation-delay:0.6s}.fs-ajax-loader .fs-ajax-loader-bar-2{left:19px;animation-delay:0.75s;-o-animation-delay:0.75s;-ms-animation-delay:0.75s;-webkit-animation-delay:0.75s;-moz-animation-delay:0.75s}.fs-ajax-loader .fs-ajax-loader-bar-3{left:38px;animation-delay:0.9s;-o-animation-delay:0.9s;-ms-animation-delay:0.9s;-webkit-animation-delay:0.9s;-moz-animation-delay:0.9s}.fs-ajax-loader .fs-ajax-loader-bar-4{left:57px;animation-delay:1.05s;-o-animation-delay:1.05s;-ms-animation-delay:1.05s;-webkit-animation-delay:1.05s;-moz-animation-delay:1.05s}.fs-ajax-loader .fs-ajax-loader-bar-5{left:76px;animation-delay:1.2s;-o-animation-delay:1.2s;-ms-animation-delay:1.2s;-webkit-animation-delay:1.2s;-moz-animation-delay:1.2s}.fs-ajax-loader .fs-ajax-loader-bar-6{left:95px;animation-delay:1.35s;-o-animation-delay:1.35s;-ms-animation-delay:1.35s;-webkit-animation-delay:1.35s;-moz-animation-delay:1.35s}.fs-ajax-loader .fs-ajax-loader-bar-7{left:114px;animation-delay:1.5s;-o-animation-delay:1.5s;-ms-animation-delay:1.5s;-webkit-animation-delay:1.5s;-moz-animation-delay:1.5s}.fs-ajax-loader .fs-ajax-loader-bar-8{left:133px;animation-delay:1.65s;-o-animation-delay:1.65s;-ms-animation-delay:1.65s;-webkit-animation-delay:1.65s;-moz-animation-delay:1.65s}@-moz-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-ms-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-o-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-webkit-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}.fs-modal-auto-install #request-filesystem-credentials-form h2,.fs-modal-auto-install #request-filesystem-credentials-form .request-filesystem-credentials-action-buttons{display:none}.fs-modal-auto-install #request-filesystem-credentials-form input[type=password],.fs-modal-auto-install #request-filesystem-credentials-form input[type=email],.fs-modal-auto-install #request-filesystem-credentials-form input[type=text]{-webkit-appearance:none;padding:10px 10px 5px 10px;width:300px;max-width:100%}.fs-modal-auto-install #request-filesystem-credentials-form>div,.fs-modal-auto-install #request-filesystem-credentials-form label,.fs-modal-auto-install #request-filesystem-credentials-form fieldset{width:300px;max-width:100%;margin:0 auto;display:block}.button-primary.warn{box-shadow:0 1px 0 #d2593c;text-shadow:0 -1px 1px #d2593c,1px 0 1px #d2593c,0 1px 1px #d2593c,-1px 0 1px #d2593c;background:#f56a48;border-color:#ec6544 #d2593c #d2593c}.button-primary.warn:hover{background:#fd6d4a;border-color:#d2593c}.button-primary.warn:focus{box-shadow:0 1px 0 #dd6041,0 0 2px 1px #e4a796}.button-primary.warn:active{background:#dd6041;border-color:#d2593c;box-shadow:inset 0 2px 0 #d2593c}.button-primary.warn.disabled{color:#f5b3a1 !important;background:#e76444 !important;border-color:#d85e40 !important;text-shadow:0 -1px 0 rgba(0,0,0,.1) !important}
freemius/assets/css/admin/gdpr-optin-notice.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-notice[data-id^=gdpr_optin_actions] .underlined{text-decoration:underline}.fs-notice[data-id^=gdpr_optin_actions] ul .button,.fs-notice[data-id^=gdpr_optin_actions] ul .action-description{vertical-align:middle}.fs-notice[data-id^=gdpr_optin_actions] ul .action-description{display:inline-block;margin-left:3px}
freemius/assets/css/admin/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
freemius/assets/css/admin/plugins.css ADDED
@@ -0,0 +1 @@
 
1
+ label.fs-tag,span.fs-tag{background:#ffba00;color:#fff;display:inline-block;border-radius:3px;padding:5px;font-size:11px;line-height:11px;vertical-align:baseline}label.fs-tag.fs-warn,span.fs-tag.fs-warn{background:#ffba00}label.fs-tag.fs-info,span.fs-tag.fs-info{background:#00a0d2}label.fs-tag.fs-success,span.fs-tag.fs-success{background:#46b450}label.fs-tag.fs-error,span.fs-tag.fs-error{background:#dc3232}.wp-list-table.plugins .plugin-title span.fs-tag{display:inline-block;margin-left:5px;line-height:10px}
freemius/assets/css/customizer.css ADDED
@@ -0,0 +1 @@
 
1
+ #fs_customizer_upsell .fs-customizer-plan{padding:10px 20px 20px 20px;border-radius:3px;background:#fff}#fs_customizer_upsell .fs-customizer-plan h2{position:relative;margin:0;line-height:2em;text-transform:uppercase}#fs_customizer_upsell .fs-customizer-plan h2 .button-link{top:-2px}#fs_customizer_upsell .fs-feature{position:relative}#fs_customizer_upsell .dashicons-yes{color:#0085ba;font-size:2em;vertical-align:bottom;margin-left:-7px;margin-right:10px}.rtl #fs_customizer_upsell .dashicons-yes{margin-left:10px;margin-right:-7px}#fs_customizer_upsell .dashicons-editor-help{color:#bbb;cursor:help}#fs_customizer_upsell .dashicons-editor-help .fs-feature-desc{opacity:0;visibility:hidden;-moz-transition:opacity .3s ease-in-out;-o-transition:opacity .3s ease-in-out;-ms-transition:opacity .3s ease-in-out;-webkit-transition:opacity .3s ease-in-out;transition:opacity .3s ease-in-out;position:absolute;background:#000;color:#fff;font-family:"arial",serif;font-size:12px;padding:10px;z-index:999999;bottom:100%;margin-bottom:5px;left:0;right:0;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,.2);box-shadow:1px 1px 1px rgba(0,0,0,.2);line-height:1.3em;font-weight:bold;text-align:left}.rtl #fs_customizer_upsell .dashicons-editor-help .fs-feature-desc{text-align:right}#fs_customizer_upsell .dashicons-editor-help .fs-feature-desc::after{content:" ";display:block;width:0;height:0;border-style:solid;border-width:5px 5px 0 5px;border-color:#000 transparent transparent transparent;position:absolute;top:100%;left:21px}.rtl #fs_customizer_upsell .dashicons-editor-help .fs-feature-desc::after{right:21px;left:auto}#fs_customizer_upsell .dashicons-editor-help:hover .fs-feature-desc{visibility:visible;opacity:1}#fs_customizer_upsell .button-primary{display:block;text-align:center;margin-top:10px}#fs_customizer_support{display:block !important}#fs_customizer_support .button{float:right}#fs_customizer_support .button-group{width:100%;display:block;margin-top:10px}#fs_customizer_support .button-group .button{float:none;width:50%;text-align:center}#customize-theme-controls #accordion-section-freemius_upsell{border-top:1px solid #0085ba !important;border-bottom:1px solid #0085ba !important}#customize-theme-controls #accordion-section-freemius_upsell h3.accordion-section-title{color:#fff;background-color:#0085ba;border-left:4px solid #0085ba;transition:.15s background-color ease-in-out,.15s border-color ease-in-out;outline:none;border-bottom:none !important}#customize-theme-controls #accordion-section-freemius_upsell h3.accordion-section-title:hover{background-color:#008ec2;border-left-color:#0073aa}#customize-theme-controls #accordion-section-freemius_upsell h3.accordion-section-title:after{color:#fff}#customize-theme-controls #accordion-section-freemius_upsell .rtl h3.accordion-section-title{border-left:none;border-right:4px solid #0085ba}#customize-theme-controls #accordion-section-freemius_upsell .rtl h3.accordion-section-title:hover{border-right-color:#0073aa}
freemius/assets/css/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
freemius/assets/img/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
freemius/assets/img/plugin-icon.png ADDED
Binary file
freemius/assets/img/shortcodes-ultimate.png ADDED
Binary file
freemius/assets/img/theme-icon.png ADDED
Binary file
freemius/assets/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
freemius/assets/js/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
freemius/assets/js/nojquery.ba-postmessage.js ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * jQuery postMessage - v0.5 - 9/11/2009
3
+ * http://benalman.com/projects/jquery-postmessage-plugin/
4
+ *
5
+ * Copyright (c) 2009 "Cowboy" Ben Alman
6
+ * Dual licensed under the MIT and GPL licenses.
7
+ * http://benalman.com/about/license/
8
+ *
9
+ * Non-jQuery fork by Jeff Lee
10
+ *
11
+ * This fork consists of the following changes:
12
+ * 1. Basic code cleanup and restructuring, for legibility.
13
+ * 2. The `postMessage` and `receiveMessage` functions can be bound arbitrarily,
14
+ * in terms of both function names and object scope. Scope is specified by
15
+ * the the "this" context of NoJQueryPostMessageMixin();
16
+ * 3. I've removed the check for Opera 9.64, which used `$.browser`. There were
17
+ * at least three different GitHub users requesting the removal of this
18
+ * "Opera sniff" on the original project's Issues page, so I figured this
19
+ * would be a relatively safe change.
20
+ * 4. `postMessage` no longer uses `$.param` to serialize messages that are not
21
+ * strings. I actually prefer this structure anyway. `receiveMessage` does
22
+ * not implement a corresponding deserialization step, and as such it seems
23
+ * cleaner and more symmetric to leave both data serialization and
24
+ * deserialization to the client.
25
+ * 5. The use of `$.isFunction` is replaced by a functionally-identical check.
26
+ * 6. The `$:nomunge` YUI option is no longer necessary.
27
+ */
28
+
29
+ function NoJQueryPostMessageMixin(postBinding, receiveBinding) {
30
+
31
+ var setMessageCallback, unsetMessageCallback, currentMsgCallback,
32
+ intervalId, lastHash, cacheBust = 1;
33
+
34
+ if (window.postMessage) {
35
+
36
+ if (window.addEventListener) {
37
+ setMessageCallback = function(callback) {
38
+ window.addEventListener('message', callback, false);
39
+ }
40
+
41
+ unsetMessageCallback = function(callback) {
42
+ window.removeEventListener('message', callback, false);
43
+ }
44
+ } else {
45
+ setMessageCallback = function(callback) {
46
+ window.attachEvent('onmessage', callback);
47
+ }
48
+
49
+ unsetMessageCallback = function(callback) {
50
+ window.detachEvent('onmessage', callback);
51
+ }
52
+ }
53
+
54
+ this[postBinding] = function(message, targetUrl, target) {
55
+ if (!targetUrl) {
56
+ return;
57
+ }
58
+
59
+ // The browser supports window.postMessage, so call it with a targetOrigin
60
+ // set appropriately, based on the targetUrl parameter.
61
+ target.postMessage( message, targetUrl.replace( /([^:]+:\/\/[^\/]+).*/, '$1' ) );
62
+ }
63
+
64
+ // Since the browser supports window.postMessage, the callback will be
65
+ // bound to the actual event associated with window.postMessage.
66
+ this[receiveBinding] = function(callback, sourceOrigin, delay) {
67
+ // Unbind an existing callback if it exists.
68
+ if (currentMsgCallback) {
69
+ unsetMessageCallback(currentMsgCallback);
70
+ currentMsgCallback = null;
71
+ }
72
+
73
+ if (!callback) {
74
+ return false;
75
+ }
76
+
77
+ // Bind the callback. A reference to the callback is stored for ease of
78
+ // unbinding.
79
+ currentMsgCallback = setMessageCallback(function(e) {
80
+ switch(Object.prototype.toString.call(sourceOrigin)) {
81
+ case '[object String]':
82
+ if (sourceOrigin !== e.origin) {
83
+ return false;
84
+ }
85
+ break;
86
+ case '[object Function]':
87
+ if (sourceOrigin(e.origin)) {
88
+ return false;
89
+ }
90
+ break;
91
+ }
92
+
93
+ callback(e);
94
+ });
95
+ };
96
+
97
+ } else {
98
+
99
+ this[postBinding] = function(message, targetUrl, target) {
100
+ if (!targetUrl) {
101
+ return;
102
+ }
103
+
104
+ // The browser does not support window.postMessage, so set the location
105
+ // of the target to targetUrl#message. A bit ugly, but it works! A cache
106
+ // bust parameter is added to ensure that repeat messages trigger the
107
+ // callback.
108
+ target.location = targetUrl.replace( /#.*$/, '' ) + '#' + (+new Date) + (cacheBust++) + '&' + message;
109
+ }
110
+
111
+ // Since the browser sucks, a polling loop will be started, and the
112
+ // callback will be called whenever the location.hash changes.
113
+ this[receiveBinding] = function(callback, sourceOrigin, delay) {
114
+ if (intervalId) {
115
+ clearInterval(intervalId);
116
+ intervalId = null;
117
+ }
118
+
119
+ if (callback) {
120
+ delay = typeof sourceOrigin === 'number'
121
+ ? sourceOrigin
122
+ : typeof delay === 'number'
123
+ ? delay
124
+ : 100;
125
+
126
+ intervalId = setInterval(function(){
127
+ var hash = document.location.hash,
128
+ re = /^#?\d+&/;
129
+ if ( hash !== lastHash && re.test( hash ) ) {
130
+ lastHash = hash;
131
+ callback({ data: hash.replace( re, '' ) });
132
+ }
133
+ }, delay );
134
+ }
135
+ };
136
+
137
+ }
138
+
139
+ return this;
140
+ }
freemius/assets/js/nojquery.ba-postmessage.min.js ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * nojquery-postmessage by Jeff Lee
3
+ * a non-jQuery fork of:
4
+ *
5
+ * jQuery postMessage - v0.5 - 9/11/2009
6
+ * http://benalman.com/projects/jquery-postmessage-plugin/
7
+ *
8
+ * Copyright (c) 2009 "Cowboy" Ben Alman
9
+ * Dual licensed under the MIT and GPL licenses.
10
+ * http://benalman.com/about/license/
11
+ */
12
+ function NoJQueryPostMessageMixin(g,a){var b,h,e,d,f,c=1;if(window.postMessage){if(window.addEventListener){b=function(i){window.addEventListener("message",i,false)};h=function(i){window.removeEventListener("message",i,false)}}else{b=function(i){window.attachEvent("onmessage",i)};h=function(i){window.detachEvent("onmessage",i)}}this[g]=function(i,k,j){if(!k){return}j.postMessage(i,k.replace(/([^:]+:\/\/[^\/]+).*/,"$1"))};this[a]=function(k,j,i){if(e){h(e);e=null}if(!k){return false}e=b(function(l){switch(Object.prototype.toString.call(j)){case"[object String]":if(j!==l.origin){return false}break;case"[object Function]":if(j(l.origin)){return false}break}k(l)})}}else{this[g]=function(i,k,j){if(!k){return}j.location=k.replace(/#.*$/,"")+"#"+(+new Date)+(c++)+"&"+i};this[a]=function(k,j,i){if(d){clearInterval(d);d=null}if(k){i=typeof j==="number"?j:typeof i==="number"?i:100;d=setInterval(function(){var m=document.location.hash,l=/^#?\d+&/;if(m!==f&&l.test(m)){f=m;k({data:m.replace(l,"")})}},i)}}}return this};
freemius/assets/js/postmessage.js ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function ($, undef) {
2
+ var global = this;
3
+
4
+ // Namespace.
5
+ global.FS = global.FS || {};
6
+
7
+ global.FS.PostMessage = function ()
8
+ {
9
+ var
10
+ _is_child = false,
11
+ _postman = new NoJQueryPostMessageMixin('postMessage', 'receiveMessage'),
12
+ _callbacks = {},
13
+ _base_url,
14
+ _parent_url = decodeURIComponent(document.location.hash.replace(/^#/, '')),
15
+ _parent_subdomain = _parent_url.substring(0, _parent_url.indexOf('/', ('https://' === _parent_url.substring(0, ('https://').length)) ? 8 : 7)),
16
+ _init = function () {
17
+ _postman.receiveMessage(function (e) {
18
+ var data = JSON.parse(e.data);
19
+
20
+ if (_callbacks[data.type]) {
21
+ for (var i = 0; i < _callbacks[data.type].length; i++) {
22
+ // Execute type callbacks.
23
+ _callbacks[data.type][i](data.data);
24
+ }
25
+ }
26
+ }, _base_url);
27
+ },
28
+ _hasParent = ('' !== _parent_url),
29
+ $window = $(window),
30
+ $html = $('html');
31
+
32
+ return {
33
+ init : function (url, iframes)
34
+ {
35
+ _base_url = url;
36
+ _init();
37
+
38
+ // Automatically receive forward messages.
39
+ FS.PostMessage.receiveOnce('forward', function (data){
40
+ window.location = data.url;
41
+ });
42
+
43
+ iframes = iframes || [];
44
+
45
+ if (iframes.length > 0) {
46
+ $window.on('scroll', function () {
47
+ for (var i = 0; i < iframes.length; i++) {
48
+ FS.PostMessage.postScroll(iframes[i]);
49
+ }
50
+ });
51
+ }
52
+ },
53
+ init_child : function ()
54
+ {
55
+ this.init(_parent_subdomain);
56
+
57
+ _is_child = true;
58
+
59
+ // Post height of a child right after window is loaded.
60
+ $(window).bind('load', function () {
61
+ FS.PostMessage.postHeight();
62
+
63
+ // Post message that window was loaded.
64
+ FS.PostMessage.post('loaded');
65
+ });
66
+ },
67
+ hasParent : function ()
68
+ {
69
+ return _hasParent;
70
+ },
71
+ postHeight : function (diff, wrapper) {
72
+ diff = diff || 0;
73
+ wrapper = wrapper || '#wrap_section';
74
+ this.post('height', {
75
+ height: diff + $(wrapper).outerHeight(true)
76
+ });
77
+ },
78
+ postScroll : function (iframe) {
79
+ this.post('scroll', {
80
+ top: $window.scrollTop(),
81
+ height: ($window.height() - parseFloat($html.css('paddingTop')) - parseFloat($html.css('marginTop')))
82
+ }, iframe);
83
+ },
84
+ post : function (type, data, iframe)
85
+ {
86
+ console.debug('PostMessage.post', type);
87
+
88
+ if (iframe)
89
+ {
90
+ // Post to iframe.
91
+ _postman.postMessage(JSON.stringify({
92
+ type: type,
93
+ data: data
94
+ }), iframe.src, iframe.contentWindow);
95
+ }
96
+ else {
97
+ // Post to parent.
98
+ _postman.postMessage(JSON.stringify({
99
+ type: type,
100
+ data: data
101
+ }), _parent_url, window.parent);
102
+ }
103
+ },
104
+ receive: function (type, callback)
105
+ {
106
+ console.debug('PostMessage.receive', type);
107
+
108
+ if (undef === _callbacks[type])
109
+ _callbacks[type] = [];
110
+
111
+ _callbacks[type].push(callback);
112
+ },
113
+ receiveOnce: function (type, callback)
114
+ {
115
+ if (this.is_set(type))
116
+ return;
117
+
118
+ this.receive(type, callback);
119
+ },
120
+ // Check if any callbacks assigned to a specified message type.
121
+ is_set: function (type)
122
+ {
123
+ return (undef != _callbacks[type]);
124
+ },
125
+ parent_url: function ()
126
+ {
127
+ return _parent_url;
128
+ },
129
+ parent_subdomain: function ()
130
+ {
131
+ return _parent_subdomain;
132
+ }
133
+ };
134
+ }();
135
+ })(jQuery);
freemius/config.php ADDED
@@ -0,0 +1,391 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ if ( ! defined( 'WP_FS__SLUG' ) ) {
14
+ define( 'WP_FS__SLUG', 'freemius' );
15
+ }
16
+ if ( ! defined( 'WP_FS__DEV_MODE' ) ) {
17
+ define( 'WP_FS__DEV_MODE', false );
18
+ }
19
+
20
+ #--------------------------------------------------------------------------------
21
+ #region API Connectivity Issues Simulation
22
+ #--------------------------------------------------------------------------------
23
+
24
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY' ) ) {
25
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY', false );
26
+ }
27
+ if ( ! defined( 'WP_FS__SIMULATE_NO_CURL' ) ) {
28
+ define( 'WP_FS__SIMULATE_NO_CURL', false );
29
+ }
30
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE' ) ) {
31
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', false );
32
+ }
33
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL' ) ) {
34
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', false );
35
+ }
36
+ if ( WP_FS__SIMULATE_NO_CURL ) {
37
+ define( 'FS_SDK__SIMULATE_NO_CURL', true );
38
+ }
39
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE ) {
40
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', true );
41
+ }
42
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL ) {
43
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', true );
44
+ }
45
+
46
+ #endregion
47
+
48
+ if ( ! defined( 'WP_FS__SIMULATE_FREEMIUS_OFF' ) ) {
49
+ define( 'WP_FS__SIMULATE_FREEMIUS_OFF', false );
50
+ }
51
+
52
+ if ( ! defined( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES' ) ) {
53
+ /**
54
+ * @since 1.1.7.3
55
+ * @author Vova Feldman (@svovaf)
56
+ *
57
+ * I'm not sure if shared servers periodically change IP, or the subdomain of the
58
+ * admin dashboard. Also, I've seen sites that have strange loop of switching
59
+ * between domains on a daily basis. Therefore, to eliminate the risk of
60
+ * multiple unwanted connectivity test pings, temporary ignore domain or
61
+ * server IP changes.
62
+ */
63
+ define( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES', false );
64
+ }
65
+
66
+ /**
67
+ * If your dev environment supports custom public network IP setup
68
+ * like VVV, please update WP_FS__LOCALHOST_IP with your public IP
69
+ * and uncomment it during dev.
70
+ */
71
+ if ( ! defined( 'WP_FS__LOCALHOST_IP' ) ) {
72
+ // VVV default public network IP.
73
+ define( 'WP_FS__VVV_DEFAULT_PUBLIC_IP', '192.168.50.4' );
74
+
75
+ // define( 'WP_FS__LOCALHOST_IP', WP_FS__VVV_DEFAULT_PUBLIC_IP );
76
+ }
77
+
78
+ /**
79
+ * If true and running with secret key, the opt-in process
80
+ * will skip the email activation process which is invoked
81
+ * when the email of the context user already exist in Freemius
82
+ * database (as a security precaution, to prevent sharing user
83
+ * secret with unauthorized entity).
84
+ *
85
+ * IMPORTANT:
86
+ * AS A SECURITY PRECAUTION, WE VALIDATE THE TIMESTAMP OF THE OPT-IN REQUEST.
87
+ * THEREFORE, MAKE SURE THAT WHEN USING THIS PARAMETER,YOUR TESTING ENVIRONMENT'S
88
+ * CLOCK IS SYNCED.
89
+ */
90
+ if ( ! defined( 'WP_FS__SKIP_EMAIL_ACTIVATION' ) ) {
91
+ define( 'WP_FS__SKIP_EMAIL_ACTIVATION', false );
92
+ }
93
+
94
+
95
+ #--------------------------------------------------------------------------------
96
+ #region Directories
97
+ #--------------------------------------------------------------------------------
98
+
99
+ if ( ! defined( 'WP_FS__DIR' ) ) {
100
+ define( 'WP_FS__DIR', dirname( __FILE__ ) );
101
+ }
102
+ if ( ! defined( 'WP_FS__DIR_INCLUDES' ) ) {
103
+ define( 'WP_FS__DIR_INCLUDES', WP_FS__DIR . '/includes' );
104
+ }
105
+ if ( ! defined( 'WP_FS__DIR_TEMPLATES' ) ) {
106
+ define( 'WP_FS__DIR_TEMPLATES', WP_FS__DIR . '/templates' );
107
+ }
108
+ if ( ! defined( 'WP_FS__DIR_ASSETS' ) ) {
109
+ define( 'WP_FS__DIR_ASSETS', WP_FS__DIR . '/assets' );
110
+ }
111
+ if ( ! defined( 'WP_FS__DIR_CSS' ) ) {
112
+ define( 'WP_FS__DIR_CSS', WP_FS__DIR_ASSETS . '/css' );
113
+ }
114
+ if ( ! defined( 'WP_FS__DIR_JS' ) ) {
115
+ define( 'WP_FS__DIR_JS', WP_FS__DIR_ASSETS . '/js' );
116
+ }
117
+ if ( ! defined( 'WP_FS__DIR_IMG' ) ) {
118
+ define( 'WP_FS__DIR_IMG', WP_FS__DIR_ASSETS . '/img' );
119
+ }
120
+ if ( ! defined( 'WP_FS__DIR_SDK' ) ) {
121
+ define( 'WP_FS__DIR_SDK', WP_FS__DIR_INCLUDES . '/sdk' );
122
+ }
123
+
124
+ #endregion
125
+
126
+ /**
127
+ * Domain / URL / Address
128
+ */
129
+ define( 'WP_FS__ROOT_DOMAIN_PRODUCTION', 'freemius.com' );
130
+ define( 'WP_FS__DOMAIN_PRODUCTION', 'wp.freemius.com' );
131
+ define( 'WP_FS__ADDRESS_PRODUCTION', 'https://' . WP_FS__DOMAIN_PRODUCTION );
132
+
133
+ if ( ! defined( 'WP_FS__DOMAIN_LOCALHOST' ) ) {
134
+ define( 'WP_FS__DOMAIN_LOCALHOST', 'wp.freemius' );
135
+ }
136
+ if ( ! defined( 'WP_FS__ADDRESS_LOCALHOST' ) ) {
137
+ define( 'WP_FS__ADDRESS_LOCALHOST', 'http://' . WP_FS__DOMAIN_LOCALHOST . ':8080' );
138
+ }
139
+
140
+ if ( ! defined( 'WP_FS__TESTING_DOMAIN' ) ) {
141
+ define( 'WP_FS__TESTING_DOMAIN', 'fswp' );
142
+ }
143
+
144
+ #--------------------------------------------------------------------------------
145
+ #region HTTP
146
+ #--------------------------------------------------------------------------------
147
+
148
+ if ( ! defined( 'WP_FS__IS_HTTP_REQUEST' ) ) {
149
+ define( 'WP_FS__IS_HTTP_REQUEST', isset( $_SERVER['HTTP_HOST'] ) );
150
+ }
151
+
152
+ if ( ! defined( 'WP_FS__IS_HTTPS' ) ) {
153
+ define( 'WP_FS__IS_HTTPS', ( WP_FS__IS_HTTP_REQUEST &&
154
+ // Checks if CloudFlare's HTTPS (Flexible SSL support).
155
+ isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) &&
156
+ 'https' === strtolower( $_SERVER['HTTP_X_FORWARDED_PROTO'] )
157
+ ) ||
158
+ // Check if HTTPS request.
159
+ ( isset( $_SERVER['HTTPS'] ) && 'on' == $_SERVER['HTTPS'] ) ||
160
+ ( isset( $_SERVER['SERVER_PORT'] ) && 443 == $_SERVER['SERVER_PORT'] )
161
+ );
162
+ }
163
+
164
+ if ( ! defined( 'WP_FS__IS_POST_REQUEST' ) ) {
165
+ define( 'WP_FS__IS_POST_REQUEST', ( WP_FS__IS_HTTP_REQUEST &&
166
+ strtoupper( $_SERVER['REQUEST_METHOD'] ) == 'POST' ) );
167
+ }
168
+
169
+ if ( ! defined( 'WP_FS__REMOTE_ADDR' ) ) {
170
+ define( 'WP_FS__REMOTE_ADDR', fs_get_ip() );
171
+ }
172
+
173
+ if ( ! defined( 'WP_FS__IS_LOCALHOST' ) ) {
174
+ if ( defined( 'WP_FS__LOCALHOST_IP' ) ) {
175
+ define( 'WP_FS__IS_LOCALHOST', ( WP_FS__LOCALHOST_IP === WP_FS__REMOTE_ADDR ) );
176
+ } else {
177
+ define( 'WP_FS__IS_LOCALHOST', WP_FS__IS_HTTP_REQUEST &&
178
+ is_string( WP_FS__REMOTE_ADDR ) &&
179
+ ( substr( WP_FS__REMOTE_ADDR, 0, 4 ) === '127.' ||
180
+ WP_FS__REMOTE_ADDR === '::1' )
181
+ );
182
+ }
183
+ }
184
+
185
+ if ( ! defined( 'WP_FS__IS_LOCALHOST_FOR_SERVER' ) ) {
186
+ define( 'WP_FS__IS_LOCALHOST_FOR_SERVER', ( ! WP_FS__IS_HTTP_REQUEST ||
187
+ false !== strpos( $_SERVER['HTTP_HOST'], 'localhost' ) ) );
188
+ }
189
+
190
+ #endregion
191
+
192
+ if ( ! defined( 'WP_FS__IS_PRODUCTION_MODE' ) ) {
193
+ // By default, run with Freemius production servers.
194
+ define( 'WP_FS__IS_PRODUCTION_MODE', true );
195
+ }
196
+
197
+ if ( ! defined( 'WP_FS__ADDRESS' ) ) {
198
+ define( 'WP_FS__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? WP_FS__ADDRESS_PRODUCTION : WP_FS__ADDRESS_LOCALHOST ) );
199
+ }
200
+
201
+
202
+ #--------------------------------------------------------------------------------
203
+ #region API
204
+ #--------------------------------------------------------------------------------
205
+
206
+ if ( ! defined( 'WP_FS__API_ADDRESS_LOCALHOST' ) ) {
207
+ define( 'WP_FS__API_ADDRESS_LOCALHOST', 'http://api.freemius-local.com:8080' );
208
+ }
209
+ if ( ! defined( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST' ) ) {
210
+ define( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST', 'http://sandbox-api.freemius:8080' );
211
+ }
212
+
213
+ // Set API address for local testing.
214
+ if ( ! WP_FS__IS_PRODUCTION_MODE ) {
215
+ if ( ! defined( 'FS_API__ADDRESS' ) ) {
216
+ define( 'FS_API__ADDRESS', WP_FS__API_ADDRESS_LOCALHOST );
217
+ }
218
+ if ( ! defined( 'FS_API__SANDBOX_ADDRESS' ) ) {
219
+ define( 'FS_API__SANDBOX_ADDRESS', WP_FS__API_SANDBOX_ADDRESS_LOCALHOST );
220
+ }
221
+ }
222
+
223
+ #endregion
224
+
225
+ #--------------------------------------------------------------------------------
226
+ #region Checkout
227
+ #--------------------------------------------------------------------------------
228
+
229
+ if ( ! defined( 'FS_CHECKOUT__ADDRESS_PRODUCTION' ) ) {
230
+ define( 'FS_CHECKOUT__ADDRESS_PRODUCTION', 'https://checkout.freemius.com' );
231
+ }
232
+
233
+ if ( ! defined( 'FS_CHECKOUT__ADDRESS_LOCALHOST' ) ) {
234
+ define( 'FS_CHECKOUT__ADDRESS_LOCALHOST', 'http://checkout.freemius-local.com:8080' );
235
+ }
236
+
237
+ if ( ! defined( 'FS_CHECKOUT__ADDRESS' ) ) {
238
+ define( 'FS_CHECKOUT__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? FS_CHECKOUT__ADDRESS_PRODUCTION : FS_CHECKOUT__ADDRESS_LOCALHOST ) );
239
+ }
240
+
241
+ #endregion
242
+
243
+ define( 'WP_FS___OPTION_PREFIX', 'fs' . ( WP_FS__IS_PRODUCTION_MODE ? '' : '_dbg' ) . '_' );
244
+
245
+ if ( ! defined( 'WP_FS__ACCOUNTS_OPTION_NAME' ) ) {
246
+ define( 'WP_FS__ACCOUNTS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'accounts' );
247
+ }
248
+ if ( ! defined( 'WP_FS__API_CACHE_OPTION_NAME' ) ) {
249
+ define( 'WP_FS__API_CACHE_OPTION_NAME', WP_FS___OPTION_PREFIX . 'api_cache' );
250
+ }
251
+ if ( ! defined( 'WP_FS__GDPR_OPTION_NAME' ) ) {
252
+ define( 'WP_FS__GDPR_OPTION_NAME', WP_FS___OPTION_PREFIX . 'gdpr' );
253
+ }
254
+ define( 'WP_FS__OPTIONS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'options' );
255
+
256
+ /**
257
+ * Module types
258
+ *
259
+ * @since 1.2.2
260
+ */
261
+ define( 'WP_FS__MODULE_TYPE_PLUGIN', 'plugin' );
262
+ define( 'WP_FS__MODULE_TYPE_THEME', 'theme' );
263
+
264
+ /**
265
+ * Billing Frequencies
266
+ */
267
+ define( 'WP_FS__PERIOD_ANNUALLY', 'annual' );
268
+ define( 'WP_FS__PERIOD_MONTHLY', 'monthly' );
269
+ define( 'WP_FS__PERIOD_LIFETIME', 'lifetime' );
270
+
271
+ /**
272
+ * Plans
273
+ */
274
+ define( 'WP_FS__PLAN_DEFAULT_PAID', false );
275
+ define( 'WP_FS__PLAN_FREE', 'free' );
276
+ define( 'WP_FS__PLAN_TRIAL', 'trial' );
277
+
278
+ /**
279
+ * Times in seconds
280
+ */
281
+ if ( ! defined( 'WP_FS__TIME_5_MIN_IN_SEC' ) ) {
282
+ define( 'WP_FS__TIME_5_MIN_IN_SEC', 300 );
283
+ }
284
+ if ( ! defined( 'WP_FS__TIME_10_MIN_IN_SEC' ) ) {
285
+ define( 'WP_FS__TIME_10_MIN_IN_SEC', 600 );
286
+ }
287
+ // define( 'WP_FS__TIME_15_MIN_IN_SEC', 900 );
288
+ if ( ! defined( 'WP_FS__TIME_12_HOURS_IN_SEC' ) ) {
289
+ define( 'WP_FS__TIME_12_HOURS_IN_SEC', 43200 );
290
+ }
291
+ if ( ! defined( 'WP_FS__TIME_24_HOURS_IN_SEC' ) ) {
292
+ define( 'WP_FS__TIME_24_HOURS_IN_SEC', WP_FS__TIME_12_HOURS_IN_SEC * 2 );
293
+ }
294
+ if ( ! defined( 'WP_FS__TIME_WEEK_IN_SEC' ) ) {
295
+ define( 'WP_FS__TIME_WEEK_IN_SEC', 7 * WP_FS__TIME_24_HOURS_IN_SEC );
296
+ }
297
+
298
+ #--------------------------------------------------------------------------------
299
+ #region Debugging
300
+ #--------------------------------------------------------------------------------
301
+
302
+ if ( ! defined( 'WP_FS__DEBUG_SDK' ) ) {
303
+ $debug_mode = get_option( 'fs_debug_mode', null );
304
+
305
+ if ( $debug_mode === null ) {
306
+ $debug_mode = false;
307
+ add_option( 'fs_debug_mode', $debug_mode );
308
+ }
309
+
310
+ define( 'WP_FS__DEBUG_SDK', is_numeric( $debug_mode ) ? ( 0 < $debug_mode ) : WP_FS__DEV_MODE );
311
+ }
312
+
313
+ if ( ! defined( 'WP_FS__ECHO_DEBUG_SDK' ) ) {
314
+ define( 'WP_FS__ECHO_DEBUG_SDK', WP_FS__DEV_MODE && ! empty( $_GET['fs_dbg_echo'] ) );
315
+ }
316
+ if ( ! defined( 'WP_FS__LOG_DATETIME_FORMAT' ) ) {
317
+ define( 'WP_FS__LOG_DATETIME_FORMAT', 'Y-m-d H:i:s' );
318
+ }
319
+ if ( ! defined( 'FS_API__LOGGER_ON' ) ) {
320
+ define( 'FS_API__LOGGER_ON', WP_FS__DEBUG_SDK );
321
+ }
322
+
323
+ if ( WP_FS__ECHO_DEBUG_SDK ) {
324
+ error_reporting( E_ALL );
325
+ }
326
+
327
+ #endregion
328
+
329
+ if ( ! defined( 'WP_FS__SCRIPT_START_TIME' ) ) {
330
+ define( 'WP_FS__SCRIPT_START_TIME', time() );
331
+ }
332
+ if ( ! defined( 'WP_FS__DEFAULT_PRIORITY' ) ) {
333
+ define( 'WP_FS__DEFAULT_PRIORITY', 10 );
334
+ }
335
+ if ( ! defined( 'WP_FS__LOWEST_PRIORITY' ) ) {
336
+ define( 'WP_FS__LOWEST_PRIORITY', 999999999 );
337
+ }
338
+
339
+ #--------------------------------------------------------------------------------
340
+ #region Multisite Network
341
+ #--------------------------------------------------------------------------------
342
+
343
+ /**
344
+ * Do not use this define directly, it will have the wrong value
345
+ * during plugin uninstall/deletion when the inclusion of the plugin
346
+ * is triggered due to registration with register_uninstall_hook().
347
+ *
348
+ * Instead, use fs_is_network_admin().
349
+ *
350
+ * @author Vova Feldman (@svovaf)
351
+ */
352
+ if ( ! defined( 'WP_FS__IS_NETWORK_ADMIN' ) ) {
353
+ define( 'WP_FS__IS_NETWORK_ADMIN',
354
+ is_multisite() &&
355
+ ( is_network_admin() ||
356
+ ( ( defined( 'DOING_AJAX' ) && DOING_AJAX &&
357
+ ( isset( $_REQUEST['_fs_network_admin'] ) && 'true' === $_REQUEST['_fs_network_admin'] /*||
358
+ ( ! empty( $_REQUEST['action'] ) && 'delete-plugin' === $_REQUEST['action'] )*/ )
359
+ ) ||
360
+ // Plugin uninstall.
361
+ defined( 'WP_UNINSTALL_PLUGIN' ) )
362
+ )
363
+ );
364
+ }
365
+
366
+ /**
367
+ * Do not use this define directly, it will have the wrong value
368
+ * during plugin uninstall/deletion when the inclusion of the plugin
369
+ * is triggered due to registration with register_uninstall_hook().
370
+ *
371
+ * Instead, use fs_is_blog_admin().
372
+ *
373
+ * @author Vova Feldman (@svovaf)
374
+ */
375
+ if ( ! defined( 'WP_FS__IS_BLOG_ADMIN' ) ) {
376
+ define( 'WP_FS__IS_BLOG_ADMIN', is_blog_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['_fs_blog_admin'] ) ) );
377
+ }
378
+
379
+ if ( ! defined( 'WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED' ) ) {
380
+ // Set to true to show network level settings even if delegated to site admins.
381
+ define( 'WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED', false );
382
+ }
383
+
384
+ #endregion
385
+
386
+ if ( ! defined( 'WP_FS__DEMO_MODE' ) ) {
387
+ define( 'WP_FS__DEMO_MODE', false );
388
+ }
389
+ if ( ! defined( 'FS_SDK__SSLVERIFY' ) ) {
390
+ define( 'FS_SDK__SSLVERIFY', false );
391
+ }
freemius/includes/class-freemius-abstract.php ADDED
@@ -0,0 +1,538 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+
14
+ /**
15
+ * - Each instance of Freemius class represents a single plugin
16
+ * install by a single user (the installer of the plugin).
17
+ *
18
+ * - Each website can only have one install of the same plugin.
19
+ *
20
+ * - Install entity is only created after a user connects his account with Freemius.
21
+ *
22
+ * Class Freemius_Abstract
23
+ */
24
+ abstract class Freemius_Abstract {
25
+
26
+ #----------------------------------------------------------------------------------
27
+ #region Identity
28
+ #----------------------------------------------------------------------------------
29
+
30
+ /**
31
+ * Check if user has connected his account (opted-in).
32
+ *
33
+ * Note:
34
+ * If the user opted-in and opted-out on a later stage,
35
+ * this will still return true. If you want to check if the
36
+ * user is currently opted-in, use:
37
+ * `$fs->is_registered() && $fs->is_tracking_allowed()`
38
+ *
39
+ * @since 1.0.1
40
+ *
41
+ * @param bool $ignore_anonymous_state Since 2.5.1
42
+ *
43
+ * @return bool
44
+ */
45
+ abstract function is_registered( $ignore_anonymous_state = false );
46
+
47
+ /**
48
+ * Check if the user skipped connecting the account with Freemius.
49
+ *
50
+ * @since 1.0.7
51
+ *
52
+ * @return bool
53
+ */
54
+ abstract function is_anonymous();
55
+
56
+ /**
57
+ * Check if the user currently in activation mode.
58
+ *
59
+ * @since 1.0.7
60
+ *
61
+ * @return bool
62
+ */
63
+ abstract function is_activation_mode();
64
+
65
+ #endregion
66
+
67
+ #----------------------------------------------------------------------------------
68
+ #region Module Type
69
+ #----------------------------------------------------------------------------------
70
+
71
+ /**
72
+ * Checks if the plugin's type is "plugin". The other type is "theme".
73
+ *
74
+ * @author Leo Fajardo (@leorw)
75
+ * @since 1.2.2
76
+ *
77
+ * @return bool
78
+ */
79
+ abstract function is_plugin();
80
+
81
+ /**
82
+ * Checks if the module type is "theme". The other type is "plugin".
83
+ *
84
+ * @author Leo Fajardo (@leorw)
85
+ * @since 1.2.2
86
+ *
87
+ * @return bool
88
+ */
89
+ function is_theme() {
90
+ return ( ! $this->is_plugin() );
91
+ }
92
+
93
+ #endregion
94
+
95
+ #----------------------------------------------------------------------------------
96
+ #region Permissions
97
+ #----------------------------------------------------------------------------------
98
+
99
+ /**
100
+ * Check if plugin must be WordPress.org compliant.
101
+ *
102
+ * @since 1.0.7
103
+ *
104
+ * @return bool
105
+ */
106
+ abstract function is_org_repo_compliant();
107
+
108
+ /**
109
+ * Check if plugin is allowed to install executable files.
110
+ *
111
+ * @author Vova Feldman (@svovaf)
112
+ * @since 1.0.5
113
+ *
114
+ * @return bool
115
+ */
116
+ function is_allowed_to_install() {
117
+ return ( $this->is_premium() || ! $this->is_org_repo_compliant() );
118
+ }
119
+
120
+ #endregion
121
+
122
+ /**
123
+ * Check if user in trial or in free plan (not paying).
124
+ *
125
+ * @author Vova Feldman (@svovaf)
126
+ * @since 1.0.4
127
+ *
128
+ * @return bool
129
+ */
130
+ function is_not_paying() {
131
+ return ( $this->is_trial() || $this->is_free_plan() );
132
+ }
133
+
134
+ /**
135
+ * Check if the user has an activated and valid paid license on current plugin's install.
136
+ *
137
+ * @since 1.0.9
138
+ *
139
+ * @return bool
140
+ */
141
+ abstract function is_paying();
142
+
143
+ /**
144
+ * Check if the user is paying or in trial.
145
+ *
146
+ * @since 1.0.9
147
+ *
148
+ * @return bool
149
+ */
150
+ function is_paying_or_trial() {
151
+ return ( $this->is_paying() || $this->is_trial() );
152
+ }
153
+
154
+ /**
155
+ * Check if user in a trial or have feature enabled license.
156
+ *
157
+ * @author Vova Feldman (@svovaf)
158
+ * @since 1.1.7
159
+ *
160
+ * @return bool
161
+ */
162
+ abstract function can_use_premium_code();
163
+
164
+ #----------------------------------------------------------------------------------
165
+ #region Premium Only
166
+ #----------------------------------------------------------------------------------
167
+
168
+ /**
169
+ * All logic wrapped in methods with "__premium_only()" suffix will be only
170
+ * included in the premium code.
171
+ *
172
+ * Example:
173
+ * if ( freemius()->is__premium_only() ) {
174
+ * ...
175
+ * }
176
+ */
177
+
178
+ /**
179
+ * Returns true when running premium plugin code.
180
+ *
181
+ * @since 1.0.9
182
+ *
183
+ * @return bool
184
+ */
185
+ function is__premium_only() {
186
+ return $this->is_premium();
187
+ }
188
+
189
+ /**
190
+ * Check if the user has an activated and valid paid license on current plugin's install.
191
+ *
192
+ * @since 1.0.9
193
+ *
194
+ * @return bool
195
+ *
196
+ */
197
+ function is_paying__premium_only() {
198
+ return ( $this->is__premium_only() && $this->is_paying() );
199
+ }
200
+
201
+ /**
202
+ * All code wrapped in this statement will be only included in the premium code.
203
+ *
204
+ * @since 1.0.9
205
+ *
206
+ * @param string $plan Plan name.
207
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
208
+ *
209
+ * @return bool
210
+ */
211
+ function is_plan__premium_only( $plan, $exact = false ) {
212
+ return ( $this->is_premium() && $this->is_plan( $plan, $exact ) );
213
+ }
214
+
215
+ /**
216
+ * Check if plan matches active license' plan or active trial license' plan.
217
+ *
218
+ * All code wrapped in this statement will be only included in the premium code.
219
+ *
220
+ * @since 1.0.9
221
+ *
222
+ * @param string $plan Plan name.
223
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
224
+ *
225
+ * @return bool
226
+ */
227
+ function is_plan_or_trial__premium_only( $plan, $exact = false ) {
228
+ return ( $this->is_premium() && $this->is_plan_or_trial( $plan, $exact ) );
229
+ }
230
+
231
+ /**
232
+ * Check if the user is paying or in trial.
233
+ *
234
+ * All code wrapped in this statement will be only included in the premium code.
235
+ *
236
+ * @since 1.0.9
237
+ *
238
+ * @return bool
239
+ */
240
+ function is_paying_or_trial__premium_only() {
241
+ return $this->is_premium() && $this->is_paying_or_trial();
242
+ }
243
+
244
+ /**
245
+ * Check if the user has an activated and valid paid license on current plugin's install.
246
+ *
247
+ * @since 1.0.4
248
+ *
249
+ * @return bool
250
+ *
251
+ * @deprecated Method name is confusing since it's not clear from the name the code will be removed.
252
+ * @using Alias to is_paying__premium_only()
253
+ */
254
+ function is_paying__fs__() {
255
+ return $this->is_paying__premium_only();
256
+ }
257
+
258
+ /**
259
+ * Check if user in a trial or have feature enabled license.
260
+ *
261
+ * All code wrapped in this statement will be only included in the premium code.
262
+ *
263
+ * @author Vova Feldman (@svovaf)
264
+ * @since 1.1.9
265
+ *
266
+ * @return bool
267
+ */
268
+ function can_use_premium_code__premium_only() {
269
+ return $this->is_premium() && $this->can_use_premium_code();
270
+ }
271
+
272
+ #endregion
273
+
274
+ #----------------------------------------------------------------------------------
275
+ #region Trial
276
+ #----------------------------------------------------------------------------------
277
+
278
+ /**
279
+ * Check if the user in a trial.
280
+ *
281
+ * @since 1.0.3
282
+ *
283
+ * @return bool
284
+ */
285
+ abstract function is_trial();
286
+
287
+ /**
288
+ * Check if trial already utilized.
289
+ *
290
+ * @since 1.0.9
291
+ *
292
+ * @return bool
293
+ */
294
+ abstract function is_trial_utilized();
295
+
296
+ #endregion
297
+
298
+ #----------------------------------------------------------------------------------
299
+ #region Plans
300
+ #----------------------------------------------------------------------------------
301
+
302
+ /**
303
+ * Check if the user is on the free plan of the product.
304
+ *
305
+ * @since 1.0.4
306
+ *
307
+ * @return bool
308
+ */
309
+ abstract function is_free_plan();
310
+
311
+ /**
312
+ * @since 1.0.2
313
+ *
314
+ * @param string $plan Plan name.
315
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
316
+ *
317
+ * @return bool
318
+ */
319
+ abstract function is_plan( $plan, $exact = false );
320
+
321
+ /**
322
+ * Check if plan based on trial. If not in trial mode, should return false.
323
+ *
324
+ * @since 1.0.9
325
+ *
326
+ * @param string $plan Plan name.
327
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
328
+ *
329
+ * @return bool
330
+ */
331
+ abstract function is_trial_plan( $plan, $exact = false );
332
+
333
+ /**
334
+ * Check if plan matches active license' plan or active trial license' plan.
335
+ *
336
+ * @since 1.0.9
337
+ *
338
+ * @param string $plan Plan name.
339
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
340
+ *
341
+ * @return bool
342
+ */
343
+ function is_plan_or_trial( $plan, $exact = false ) {
344
+ return $this->is_plan( $plan, $exact ) ||
345
+ $this->is_trial_plan( $plan, $exact );
346
+ }
347
+
348
+ /**
349
+ * Check if plugin has any paid plans.
350
+ *
351
+ * @author Vova Feldman (@svovaf)
352
+ * @since 1.0.7
353
+ *
354
+ * @return bool
355
+ */
356
+ abstract function has_paid_plan();
357
+
358
+ /**
359
+ * Check if plugin has any free plan, or is it premium only.
360
+ *
361
+ * Note: If no plans configured, assume plugin is free.
362
+ *
363
+ * @author Vova Feldman (@svovaf)
364
+ * @since 1.0.7
365
+ *
366
+ * @return bool
367
+ */
368
+ abstract function has_free_plan();
369
+
370
+ /**
371
+ * Check if plugin is premium only (no free plans).
372
+ *
373
+ * NOTE: is__premium_only() is very different method, don't get confused.
374
+ *
375
+ * @author Vova Feldman (@svovaf)
376
+ * @since 1.1.9
377
+ *
378
+ * @return bool
379
+ */
380
+ abstract function is_only_premium();
381
+
382
+ /**
383
+ * Check if module has a premium code version.
384
+ *
385
+ * Serviceware module might be freemium without any
386
+ * premium code version, where the paid features
387
+ * are all part of the service.
388
+ *
389
+ * @author Vova Feldman (@svovaf)
390
+ * @since 1.2.1.6
391
+ *
392
+ * @return bool
393
+ */
394
+ abstract function has_premium_version();
395
+
396
+ /**
397
+ * Check if module has any release on Freemius,
398
+ * or all plugin's code is on WordPress.org (Serviceware).
399
+ *
400
+ * @return bool
401
+ */
402
+ function has_release_on_freemius() {
403
+ return ! $this->is_org_repo_compliant() ||
404
+ $this->has_premium_version();
405
+ }
406
+
407
+ /**
408
+ * Checks if it's a freemium plugin.
409
+ *
410
+ * @author Vova Feldman (@svovaf)
411
+ * @since 1.1.9
412
+ *
413
+ * @return bool
414
+ */
415
+ function is_freemium() {
416
+ return $this->has_paid_plan() &&
417
+ $this->has_free_plan();
418
+ }
419
+
420
+ /**
421
+ * Check if module has only one plan.
422
+ *
423
+ * @author Vova Feldman (@svovaf)
424
+ * @since 1.2.1.7
425
+ *
426
+ * @return bool
427
+ */
428
+ abstract function is_single_plan();
429
+
430
+ #endregion
431
+
432
+ /**
433
+ * Check if running payments in sandbox mode.
434
+ *
435
+ * @since 1.0.4
436
+ *
437
+ * @return bool
438
+ */
439
+ abstract function is_payments_sandbox();
440
+
441
+ /**
442
+ * Check if running test vs. live plugin.
443
+ *
444
+ * @since 1.0.5
445
+ *
446
+ * @return bool
447
+ */
448
+ abstract function is_live();
449
+
450
+ /**
451
+ * Check if running premium plugin code.
452
+ *
453
+ * @since 1.0.5
454
+ *
455
+ * @return bool
456
+ */
457
+ abstract function is_premium();
458
+
459
+ /**
460
+ * Get upgrade URL.
461
+ *
462
+ * @author Vova Feldman (@svovaf)
463
+ * @since 1.0.2
464
+ *
465
+ * @param string $period Billing cycle.
466
+ *
467
+ * @return string
468
+ */
469
+ abstract function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY );
470
+
471
+ /**
472
+ * Check if Freemius was first added in a plugin update.
473
+ *
474
+ * @author Vova Feldman (@svovaf)
475
+ * @since 1.1.5
476
+ *
477
+ * @return bool
478
+ */
479
+ function is_plugin_update() {
480
+ return ! $this->is_plugin_new_install();
481
+ }
482
+
483
+ /**
484
+ * Check if Freemius was part of the plugin when the user installed it first.
485
+ *
486
+ * @author Vova Feldman (@svovaf)
487
+ * @since 1.1.5
488
+ *
489
+ * @return bool
490
+ */
491
+ abstract function is_plugin_new_install();
492
+
493
+ #----------------------------------------------------------------------------------
494
+ #region Marketing
495
+ #----------------------------------------------------------------------------------
496
+
497
+ /**
498
+ * Check if current user purchased any other plugins before.
499
+ *
500
+ * @author Vova Feldman (@svovaf)
501
+ * @since 1.0.9
502
+ *
503
+ * @return bool
504
+ */
505
+ abstract function has_purchased_before();
506
+
507
+ /**
508
+ * Check if current user classified as an agency.
509
+ *
510
+ * @author Vova Feldman (@svovaf)
511
+ * @since 1.0.9
512
+ *
513
+ * @return bool
514
+ */
515
+ abstract function is_agency();
516
+
517
+ /**
518
+ * Check if current user classified as a developer.
519
+ *
520
+ * @author Vova Feldman (@svovaf)
521
+ * @since 1.0.9
522
+ *
523
+ * @return bool
524
+ */
525
+ abstract function is_developer();
526
+
527
+ /**
528
+ * Check if current user classified as a business.
529
+ *
530
+ * @author Vova Feldman (@svovaf)
531
+ * @since 1.0.9
532
+ *
533
+ * @return bool
534
+ */
535
+ abstract function is_business();
536
+
537
+ #endregion
538
+ }
freemius/includes/class-freemius.php ADDED
@@ -0,0 +1,26468 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.3
7
+ */
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+ // "final class"
13
+ class Freemius extends Freemius_Abstract {
14
+ /**
15
+ * SDK Version
16
+ *
17
+ * @var string
18
+ */
19
+ public $version = WP_FS__SDK_VERSION;
20
+
21
+ #region Plugin Info
22
+
23
+ /**
24
+ * @since 1.0.1
25
+ *
26
+ * @var string
27
+ */
28
+ private $_slug;
29
+
30
+ /**
31
+ * @since 1.0.0
32
+ *
33
+ * @var string
34
+ */
35
+ private $_plugin_basename;
36
+ /**
37
+ * @since 2.2.1
38
+ *
39
+ * @var string
40
+ */
41
+ private $_premium_plugin_basename;
42
+ /**
43
+ * @since 1.0.0
44
+ *
45
+ * @var string
46
+ */
47
+ private $_free_plugin_basename;
48
+ /**
49
+ * @since 1.0.0
50
+ *
51
+ * @var string
52
+ */
53
+ private $_plugin_dir_path;
54
+ /**
55
+ * @since 1.0.0
56
+ *
57
+ * @var string
58
+ */
59
+ private $_plugin_dir_name;
60
+ /**
61
+ * @since 1.0.0
62
+ *
63
+ * @var string
64
+ */
65
+ private $_plugin_main_file_path;
66
+ /**
67
+ * @var string[]
68
+ */
69
+ private $_plugin_data;
70
+ /**
71
+ * @since 1.0.9
72
+ *
73
+ * @var string
74
+ */
75
+ private $_plugin_name;
76
+ /**
77
+ * @since 1.2.2
78
+ *
79
+ * @var string
80
+ */
81
+ private $_module_type;
82
+
83
+ #endregion Plugin Info
84
+
85
+ /**
86
+ * @since 1.0.9
87
+ *
88
+ * @var bool If false, don't turn Freemius on.
89
+ */
90
+ private $_is_on;
91
+
92
+ /**
93
+ * @since 1.1.3
94
+ *
95
+ * @var bool If false, don't turn Freemius on.
96
+ */
97
+ private $_is_anonymous;
98
+
99
+ /**
100
+ * @since 1.0.9
101
+ * @var bool If false, issues with connectivity to Freemius API.
102
+ */
103
+ private $_has_api_connection;
104
+
105
+ /**
106
+ * @since 1.0.9
107
+ * @since 2.0.0 Default to true since we need the property during the instance construction, prior to the dynamic_init() execution.
108
+ * @var bool Hints the SDK if plugin can support anonymous mode (if skip connect is visible).
109
+ */
110
+ private $_enable_anonymous = true;
111
+
112
+ /**
113
+ * @since 1.1.7.5
114
+ * @var bool Hints the SDK if plugin should run in anonymous mode (only adds feedback form).
115
+ */
116
+ private $_anonymous_mode;
117
+
118
+ /**
119
+ * @since 1.1.9
120
+ * @var bool Hints the SDK if plugin have any free plans.
121
+ */
122
+ private $_is_premium_only;
123
+
124
+ /**
125
+ * @since 1.2.1.6
126
+ * @var bool Hints the SDK if plugin have premium code version at all.
127
+ */
128
+ private $_has_premium_version;
129
+
130
+ /**
131
+ * @since 1.2.1.6
132
+ * @var bool Hints the SDK if plugin should ignore pending mode by simulating a skip.
133
+ */
134
+ private $_ignore_pending_mode;
135
+
136
+ /**
137
+ * @since 1.0.8
138
+ * @var bool Hints the SDK if the plugin has any paid plans.
139
+ */
140
+ private $_has_paid_plans;
141
+
142
+ /**
143
+ * @since 1.2.1.5
144
+ * @var int Hints the SDK if the plugin offers a trial period. If negative, no trial, if zero - has a trial but
145
+ * without a specified period, if positive - the number of trial days.
146
+ */
147
+ private $_trial_days = - 1;
148
+
149
+ /**
150
+ * @since 1.2.1.5
151
+ * @var bool Hints the SDK if the trial requires a payment method or not.
152
+ */
153
+ private $_is_trial_require_payment = false;
154
+
155
+ /**
156
+ * @since 1.0.7
157
+ * @var bool Hints the SDK if the plugin is WordPress.org compliant.
158
+ */
159
+ private $_is_org_compliant;
160
+
161
+ /**
162
+ * @since 1.0.7
163
+ * @var bool Hints the SDK if the plugin is has add-ons.
164
+ */
165
+ private $_has_addons;
166
+
167
+ /**
168
+ * @since 2.4.5
169
+ * @var string Navigation type: 'menu' or 'tabs'.
170
+ */
171
+ private $_navigation;
172
+
173
+ const NAVIGATION_MENU = 'menu';
174
+ const NAVIGATION_TABS = 'tabs';
175
+
176
+ /**
177
+ * @since 1.1.6
178
+ * @var string[]bool.
179
+ */
180
+ private $_permissions;
181
+
182
+ /**
183
+ * @var FS_Storage
184
+ */
185
+ private $_storage;
186
+
187
+ /**
188
+ * @since 1.2.2.7
189
+ * @var FS_Cache_Manager
190
+ */
191
+ private $_cache;
192
+
193
+ /**
194
+ * @since 1.0.0
195
+ *
196
+ * @var FS_Logger
197
+ */
198
+ private $_logger;
199
+ /**
200
+ * @since 1.0.4
201
+ *
202
+ * @var FS_Plugin
203
+ */
204
+ private $_plugin = false;
205
+ /**
206
+ * @since 1.0.4
207
+ *
208
+ * @var FS_Plugin|false
209
+ */
210
+ private $_parent_plugin = false;
211
+ /**
212
+ * @since 1.1.1
213
+ *
214
+ * @var Freemius
215
+ */
216
+ private $_parent = false;
217
+ /**
218
+ * @since 1.0.1
219
+ *
220
+ * @var FS_User
221
+ */
222
+ private $_user = false;
223
+ /**
224
+ * @since 1.0.1
225
+ *
226
+ * @var FS_Site
227
+ */
228
+ private $_site = false;
229
+ /**
230
+ * @since 1.0.1
231
+ *
232
+ * @var FS_Plugin_License
233
+ */
234
+ private $_license;
235
+ /**
236
+ * @since 1.0.2
237
+ *
238
+ * @var FS_Plugin_Plan[]
239
+ */
240
+ private $_plans = false;
241
+ /**
242
+ * @var FS_Plugin_License[]
243
+ * @since 1.0.5
244
+ */
245
+ private $_licenses = false;
246
+
247
+ /**
248
+ * @since 1.0.1
249
+ *
250
+ * @var FS_Admin_Menu_Manager
251
+ */
252
+ private $_menu;
253
+
254
+ /**
255
+ * @var FS_Admin_Notices
256
+ */
257
+ private $_admin_notices;
258
+
259
+ /**
260
+ * @since 1.1.6
261
+ *
262
+ * @var FS_Admin_Notices
263
+ */
264
+ private static $_global_admin_notices;
265
+
266
+ /**
267
+ * @var FS_Logger
268
+ * @since 1.0.0
269
+ */
270
+ private static $_static_logger;
271
+
272
+ /**
273
+ * @var FS_Options
274
+ * @since 1.0.2
275
+ */
276
+ private static $_accounts;
277
+
278
+ /**
279
+ * @since 1.2.2
280
+ *
281
+ * @var number
282
+ */
283
+ private $_module_id;
284
+
285
+ /**
286
+ * @var Freemius[]
287
+ */
288
+ private static $_instances = array();
289
+
290
+ /**
291
+ * @since 1.2.3
292
+ *
293
+ * @var FS_Affiliate
294
+ */
295
+ private $affiliate = null;
296
+
297
+ /**
298
+ * @since 1.2.3
299
+ *
300
+ * @var FS_AffiliateTerms
301
+ */
302
+ private $plugin_affiliate_terms = null;
303
+
304
+ /**
305
+ * @since 1.2.3
306
+ *
307
+ * @var FS_AffiliateTerms
308
+ */
309
+ private $custom_affiliate_terms = null;
310
+
311
+ /**
312
+ * @since 2.0.0
313
+ *
314
+ * @var bool
315
+ */
316
+ private $_is_multisite_integrated;
317
+
318
+ /**
319
+ * @since 2.0.0
320
+ *
321
+ * @var bool True if the current request is for a network admin screen and the plugin is network active.
322
+ */
323
+ private $_is_network_active;
324
+
325
+ /**
326
+ * @since 2.0.0
327
+ *
328
+ * @var int|null The original blog ID the plugin was loaded with.
329
+ */
330
+ private $_blog_id = null;
331
+
332
+ /**
333
+ * @since 2.0.0
334
+ *
335
+ * @var int|null The current execution context. When true, run on network context. When int, run on the specified blog context.
336
+ */
337
+ private $_context_is_network_or_blog_id = null;
338
+
339
+ /**
340
+ * @since 2.0.0
341
+ *
342
+ * @var string
343
+ */
344
+ private $_dynamically_added_top_level_page_hook_name = '';
345
+
346
+ /**
347
+ * @author Leo Fajardo (@leorw)
348
+ * @since 2.3.1
349
+ *
350
+ * @var bool
351
+ */
352
+ private $is_whitelabeled;
353
+
354
+ /**
355
+ * @author Leo Fajardo (@leorw)
356
+ * @since 2.4.0
357
+ *
358
+ * @var bool
359
+ */
360
+ private $_is_bundle_license_auto_activation_enabled = false;
361
+
362
+ #region Uninstall Reasons IDs
363
+
364
+ const REASON_NO_LONGER_NEEDED = 1;
365
+ const REASON_FOUND_A_BETTER_PLUGIN = 2;
366
+ const REASON_NEEDED_FOR_A_SHORT_PERIOD = 3;
367
+ const REASON_BROKE_MY_SITE = 4;
368
+ const REASON_SUDDENLY_STOPPED_WORKING = 5;
369
+ const REASON_CANT_PAY_ANYMORE = 6;
370
+ const REASON_OTHER = 7;
371
+ const REASON_DIDNT_WORK = 8;
372
+ const REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION = 9;
373
+ const REASON_COULDNT_MAKE_IT_WORK = 10;
374
+ const REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE = 11;
375
+ const REASON_NOT_WORKING = 12;
376
+ const REASON_NOT_WHAT_I_WAS_LOOKING_FOR = 13;
377
+ const REASON_DIDNT_WORK_AS_EXPECTED = 14;
378
+ const REASON_TEMPORARY_DEACTIVATION = 15;
379
+
380
+ #endregion
381
+
382
+ /**
383
+ * @author Leo Fajardo (@leorw)
384
+ * @since 2.3.1
385
+ *
386
+ * @var boolean|null
387
+ */
388
+ private $_use_external_pricing = null;
389
+ /**
390
+ * @author Leo Fajardo (@leorw)
391
+ * @since 2.4.2
392
+ *
393
+ * @var string|null
394
+ */
395
+ private $_pricing_js_path = null;
396
+
397
+ const VERSION_MAX_CHARS = 16;
398
+ const LANGUAGE_MAX_CHARS = 8;
399
+
400
+ /* Ctor
401
+ ------------------------------------------------------------------------------------------------------------------*/
402
+
403
+ /**
404
+ * Main singleton instance.
405
+ *
406
+ * @author Vova Feldman (@svovaf)
407
+ * @since 1.0.0
408
+ *
409
+ * @param number $module_id
410
+ * @param string|bool $slug
411
+ * @param bool $is_init Since 1.2.1 Is initiation sequence.
412
+ */
413
+ private function __construct( $module_id, $slug = false, $is_init = false ) {
414
+ $main_file = false;
415
+
416
+ if ( $is_init && is_numeric( $module_id ) && is_string( $slug ) ) {
417
+ $main_file = $this->store_id_slug_type_path_map( $module_id, $slug );
418
+ }
419
+
420
+ $this->_module_id = $module_id;
421
+ $this->_slug = $this->get_slug();
422
+ $this->_module_type = $this->get_module_type();
423
+
424
+ $this->_blog_id = is_multisite() ? get_current_blog_id() : null;
425
+
426
+ $this->_storage = FS_Storage::instance( $this->_module_type, $this->_slug );
427
+
428
+ $this->_cache = FS_Cache_Manager::get_manager( WP_FS___OPTION_PREFIX . "cache_{$module_id}" );
429
+
430
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $this->get_unique_affix(), WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
431
+
432
+ $this->_plugin_main_file_path = $this->_find_caller_plugin_file( $is_init, $main_file );
433
+ $this->_plugin_dir_path = plugin_dir_path( $this->_plugin_main_file_path );
434
+ $this->_plugin_basename = $this->get_plugin_basename();
435
+ $this->_free_plugin_basename = str_replace( '-premium/', '/', $this->_plugin_basename );
436
+
437
+ $this->_is_multisite_integrated = (
438
+ defined( "WP_FS__PRODUCT_{$module_id}_MULTISITE" ) &&
439
+ ( true === constant( "WP_FS__PRODUCT_{$module_id}_MULTISITE" ) )
440
+ );
441
+
442
+ $this->_is_network_active = (
443
+ is_multisite() &&
444
+ $this->_is_multisite_integrated &&
445
+ // Themes are always network activated, but the ACTUAL activation is per site.
446
+ $this->is_plugin() &&
447
+ (
448
+ is_plugin_active_for_network( $this->_plugin_basename ) ||
449
+ // Plugin network level activation or uninstall.
450
+ ( fs_is_network_admin() && is_plugin_inactive( $this->_plugin_basename ) )
451
+ )
452
+ );
453
+
454
+ $this->_storage->set_network_active(
455
+ $this->_is_network_active,
456
+ $this->is_delegated_connection()
457
+ );
458
+
459
+ if ( ! isset( $this->_storage->is_network_activated ) ) {
460
+ $this->_storage->is_network_activated = $this->_is_network_active;
461
+ }
462
+
463
+ if ( $this->_storage->is_network_activated != $this->_is_network_active ) {
464
+ // Update last activation level.
465
+ $this->_storage->is_network_activated = $this->_is_network_active;
466
+
467
+ $this->maybe_adjust_storage();
468
+ }
469
+
470
+ #region Migration
471
+
472
+ if ( is_multisite() ) {
473
+ /**
474
+ * If the install_timestamp exists on the site level but doesn't exist on the
475
+ * network level storage, it means that we need to process the storage with migration.
476
+ *
477
+ * The code in this `if` scope will only be executed once and only for the first site that will execute it because once we migrate the storage data, install_timestamp will be already set in the network level storage.
478
+ *
479
+ * @author Vova Feldman (@svovaf)
480
+ * @since 2.0.0
481
+ */
482
+ if ( false === $this->_storage->get( 'install_timestamp', false, true ) &&
483
+ false !== $this->_storage->get( 'install_timestamp', false, false )
484
+ ) {
485
+ // Initiate storage migration.
486
+ $this->_storage->migrate_to_network();
487
+
488
+ // Migrate module cache to network level storage.
489
+ $this->_cache->migrate_to_network();
490
+ }
491
+ }
492
+
493
+ #endregion
494
+
495
+ $base_name_split = explode( '/', $this->_plugin_basename );
496
+ $this->_plugin_dir_name = $base_name_split[0];
497
+
498
+ if ( $this->_logger->is_on() ) {
499
+ $this->_logger->info( 'plugin_main_file_path = ' . $this->_plugin_main_file_path );
500
+ $this->_logger->info( 'plugin_dir_path = ' . $this->_plugin_dir_path );
501
+ $this->_logger->info( 'plugin_basename = ' . $this->_plugin_basename );
502
+ $this->_logger->info( 'free_plugin_basename = ' . $this->_free_plugin_basename );
503
+ $this->_logger->info( 'plugin_dir_name = ' . $this->_plugin_dir_name );
504
+ }
505
+
506
+ // Remember link between file to slug.
507
+ $this->store_file_slug_map();
508
+
509
+ // Store plugin's initial install timestamp.
510
+ if ( ! isset( $this->_storage->install_timestamp ) ) {
511
+ $this->_storage->install_timestamp = WP_FS__SCRIPT_START_TIME;
512
+ }
513
+
514
+ if ( ! is_object( $this->_plugin ) ) {
515
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->get();
516
+ }
517
+
518
+ $this->_admin_notices = FS_Admin_Notices::instance(
519
+ $this->_slug . ( $this->is_theme() ? ':theme' : '' ),
520
+ /**
521
+ * Ensure that the admin notice will always have a title by using the stored plugin title if available and
522
+ * retrieving the title via the "get_plugin_name" method if there is no stored plugin title available.
523
+ *
524
+ * @author Leo Fajardo (@leorw)
525
+ * @since 1.2.2
526
+ */
527
+ ( is_object( $this->_plugin ) && isset( $this->_plugin->title ) ?
528
+ $this->_plugin->title :
529
+ $this->get_plugin_name()
530
+ ),
531
+ $this->get_unique_affix()
532
+ );
533
+
534
+ if ( 'true' === fs_request_get( 'fs_clear_api_cache' ) ||
535
+ fs_request_is_action( 'restart_freemius' )
536
+ ) {
537
+ FS_Api::clear_cache();
538
+ $this->_cache->clear();
539
+ }
540
+
541
+ $this->register_constructor_hooks();
542
+
543
+ /**
544
+ * Starting from version 2.0.0, `FS_Site` entities no longer have the `plan` property and have `plan_id`
545
+ * instead. This should be called before calling `_load_account()`, otherwise, `$this->_site` will not be
546
+ * loaded in `_load_account` for versions of SDK starting from 2.0.0.
547
+ *
548
+ * @author Leo Fajardo (@leorw)
549
+ */
550
+ self::migrate_install_plan_to_plan_id( $this->_storage );
551
+
552
+ $this->_load_account();
553
+
554
+ $this->_version_updates_handler();
555
+ }
556
+
557
+ /**
558
+ * @author Leo Fajardo (@leorw)
559
+ * @since 2.3.0
560
+ */
561
+ private function maybe_adjust_storage() {
562
+ $install_timestamp = null;
563
+ $prev_is_premium = null;
564
+
565
+ $options_to_update = array();
566
+
567
+ $is_network_admin = fs_is_network_admin();
568
+
569
+ $network_install_timestamp = $this->_storage->get( 'install_timestamp', null, true );
570
+
571
+ if ( ! $is_network_admin ) {
572
+ if ( is_null( $network_install_timestamp ) ) {
573
+ // Plugin was not network-activated before.
574
+ return;
575
+ }
576
+
577
+ if ( is_null( $this->_storage->get( 'install_timestamp', null, false ) ) ) {
578
+ // Set the `install_timestamp` only if it's not yet set.
579
+ $install_timestamp = $network_install_timestamp;
580
+ }
581
+
582
+ $prev_is_premium = $this->_storage->get( 'prev_is_premium', null, true );
583
+ } else {
584
+ $current_wp_user = self::_get_current_wp_user();
585
+ $current_fs_user = self::_get_user_by_email( $current_wp_user->user_email );
586
+ $network_user_info = array();
587
+
588
+ $skips_count = 0;
589
+
590
+ $sites = self::get_sites();
591
+ $sites_count = count( $sites );
592
+
593
+ $blog_id_2_install_map = array();
594
+
595
+ $is_first_non_ignored_blog = true;
596
+
597
+ foreach ( $sites as $site ) {
598
+ $blog_id = self::get_site_blog_id( $site );
599
+
600
+ $blog_install_timestamp = $this->_storage->get( 'install_timestamp', null, $blog_id );
601
+
602
+ if ( is_null( $blog_install_timestamp ) ) {
603
+ // Plugin has not been installed on this blog.
604
+ continue;
605
+ }
606
+
607
+ $is_earlier_install = (
608
+ ! is_null( $install_timestamp ) &&
609
+ $blog_install_timestamp < $install_timestamp
610
+ );
611
+
612
+ $install = $this->get_install_by_blog_id( $blog_id );
613
+
614
+ $update_network_user_info = false;
615
+
616
+ if ( ! is_object( $install ) ) {
617
+ if ( ! $this->_storage->get( 'is_anonymous', false, $blog_id ) ) {
618
+ // The opt-in decision (whether to skip or opt in) is yet to be made.
619
+ continue;
620
+ }
621
+
622
+ $skips_count ++;
623
+ } else {
624
+ $blog_id_2_install_map[ $blog_id ] = $install;
625
+
626
+ if ( empty( $network_user_info ) ) {
627
+ // Set the network user info for the 1st time. Choose any user information whether or not it is for the current WP user.
628
+ $update_network_user_info = true;
629
+ }
630
+
631
+ if ( ! $update_network_user_info &&
632
+ is_object( $current_fs_user ) &&
633
+ $network_user_info['user_id'] != $current_fs_user->id &&
634
+ $install->user_id == $current_fs_user->id
635
+ ) {
636
+ // If an install that is owned by the current WP user is found, use its user information instead.
637
+ $update_network_user_info = true;
638
+ }
639
+
640
+ if ( ! $update_network_user_info &&
641
+ $is_earlier_install &&
642
+ ( ! is_object( $current_fs_user ) || $current_fs_user->id == $install->user_id )
643
+ ) {
644
+ // Update to the earliest install info if there's no install found so far that is owned by the current WP user; OR only if the found install is owned by the current WP user.
645
+ $update_network_user_info = true;
646
+ }
647
+ }
648
+
649
+ if ( $update_network_user_info ) {
650
+ $network_user_info = array(
651
+ 'user_id' => $install->user_id,
652
+ 'blog_id' => $blog_id
653
+ );
654
+ }
655
+
656
+ $site_prev_is_premium = $this->_storage->get( 'prev_is_premium', null, $blog_id );
657
+
658
+ if ( $is_first_non_ignored_blog ) {
659
+ $prev_is_premium = $site_prev_is_premium;
660
+
661
+ if ( is_null( $network_install_timestamp ) ) {
662
+ $install_timestamp = $blog_install_timestamp;
663
+ }
664
+
665
+ $is_first_non_ignored_blog = false;
666
+
667
+ continue;
668
+ }
669
+
670
+ if ( ! is_null( $prev_is_premium ) && $prev_is_premium !== $site_prev_is_premium ) {
671
+ // If a different `$site_prev_is_premium` value is found, do not include the option in the collection of options to update.
672
+ $prev_is_premium = null;
673
+ }
674
+
675
+ if ( $is_earlier_install ) {
676
+ // If an earlier install timestamp is found.
677
+ $install_timestamp = $blog_install_timestamp;
678
+ }
679
+ }
680
+
681
+ $installs_count = count( $blog_id_2_install_map );
682
+
683
+ if ( $sites_count === ( $installs_count + $skips_count ) ) {
684
+ if ( ! empty( $network_user_info ) ) {
685
+ $options_to_update['network_user_id'] = $network_user_info['user_id'];
686
+ $options_to_update['network_install_blog_id'] = $network_user_info['blog_id'];
687
+
688
+ foreach ( $blog_id_2_install_map as $blog_id => $install ) {
689
+ if ( $install->user_id == $network_user_info['user_id'] ) {
690
+ continue;
691
+ }
692
+
693
+ $this->_storage->store( 'is_delegated_connection', true, $blog_id );
694
+ }
695
+ }
696
+
697
+ if ( $sites_count === $skips_count ) {
698
+ /**
699
+ * Assume network-level skipping as the intended action if all actions identified were only
700
+ * skipping of the connection (i.e., no opt-ins and delegated connections so far).
701
+ */
702
+ $options_to_update['is_anonymous_ms'] = true;
703
+ } else if ( $sites_count === $installs_count ) {
704
+ /**
705
+ * Assume network-level opt-in as the intended action if all actions identified were only opt-ins
706
+ * (i.e., no delegation and skipping of the connections so far).
707
+ */
708
+ $options_to_update['is_network_connected'] = true;
709
+ }
710
+ }
711
+ }
712
+
713
+ if ( ! is_null( $install_timestamp ) ) {
714
+ $options_to_update['install_timestamp'] = $install_timestamp;
715
+ }
716
+
717
+ if ( ! is_null( $prev_is_premium ) ) {
718
+ $options_to_update['prev_is_premium'] = $prev_is_premium;
719
+ }
720
+
721
+ if ( ! empty( $options_to_update ) ) {
722
+ $this->adjust_storage( $options_to_update, $is_network_admin );
723
+ }
724
+ }
725
+
726
+ /**
727
+ * @author Leo Fajardo (@leorw)
728
+ * @since 2.3.0
729
+ *
730
+ * @param array $options
731
+ * @param bool $is_network_admin
732
+ */
733
+ private function adjust_storage( $options, $is_network_admin ) {
734
+ foreach ( $options as $name => $value ) {
735
+ $this->_storage->store( $name, $value, $is_network_admin ? true : null );
736
+ }
737
+ }
738
+
739
+ /**
740
+ * Checks whether this module has a settings menu.
741
+ *
742
+ * @author Leo Fajardo (@leorw)
743
+ * @since 1.2.2
744
+ *
745
+ * @return bool
746
+ */
747
+ function has_settings_menu() {
748
+ return ( $this->_is_network_active && fs_is_network_admin() ) ?
749
+ $this->_menu->has_network_menu() :
750
+ $this->_menu->has_menu();
751
+ }
752
+
753
+ /**
754
+ * If `true` the opt-in should be shown as a modal dialog box on the themes.php page. WordPress.org themes guidelines prohibit from redirecting the user from the themes.php page after activating a theme.
755
+ *
756
+ * @author Vova Feldman (@svovaf)
757
+ * @since 2.4.5
758
+ *
759
+ * @return bool
760
+ */
761
+ function show_opt_in_on_themes_page() {
762
+ if ( ! $this->is_free_wp_org_theme() ) {
763
+ return false;
764
+ }
765
+
766
+ if ( ! $this->has_settings_menu() ) {
767
+ return true;
768
+ }
769
+
770
+ return $this->show_settings_with_tabs();
771
+ }
772
+
773
+ /**
774
+ * If `true` the opt-in should be shown on the product's main setting page.
775
+ *
776
+ * @author Vova Feldman (@svovaf)
777
+ * @since 2.4.5
778
+ *
779
+ * @return bool
780
+ *
781
+ * @uses show_opt_in_on_themes_page();
782
+ */
783
+ function show_opt_in_on_setting_page() {
784
+ return ! $this->show_opt_in_on_themes_page();
785
+ }
786
+
787
+ /**
788
+ * If `true` the settings should be shown using tabs.
789
+ *
790
+ * @author Vova Feldman (@svovaf)
791
+ * @since 2.4.5
792
+ *
793
+ * @return bool
794
+ */
795
+ function show_settings_with_tabs() {
796
+ return ( self::NAVIGATION_TABS === $this->_navigation );
797
+ }
798
+
799
+ /**
800
+ * Check if the context module is free wp.org theme.
801
+ *
802
+ * This method is helpful because:
803
+ * 1. wp.org themes are limited to a single submenu item,
804
+ * and sub-submenu items are most likely not allowed (never verified).
805
+ * 2. wp.org themes are not allowed to redirect the user
806
+ * after the theme activation, therefore, the agreed UX
807
+ * is showing the opt-in as a modal dialog box after
808
+ * activation (approved by @otto42, @emiluzelac, @greenshady, @grapplerulrich).
809
+ *
810
+ * @author Vova Feldman (@svovaf)
811
+ * @since 1.2.2.7
812
+ *
813
+ * @return bool
814
+ */
815
+ function is_free_wp_org_theme() {
816
+ return (
817
+ $this->is_theme() &&
818
+ $this->is_org_repo_compliant() &&
819
+ ! $this->is_premium()
820
+ );
821
+ }
822
+
823
+ /**
824
+ * Checks whether this a submenu item is visible.
825
+ *
826
+ * @author Vova Feldman (@svovaf)
827
+ * @since 1.2.2.6
828
+ * @since 1.2.2.7 Even if the menu item was specified to be hidden, when it is the context page, then show the submenu item so the user will have the right context page.
829
+ *
830
+ * @param string $slug
831
+ * @param bool $is_tabs_visibility_check This is used to decide if the associated tab should be shown or hidden.
832
+ *
833
+ * @return bool
834
+ */
835
+ function is_submenu_item_visible( $slug, $is_tabs_visibility_check = false ) {
836
+ if ( $this->is_admin_page( $slug ) ) {
837
+ /**
838
+ * It is the current context page, so show the submenu item
839
+ * so the user will have the right context page, even if it
840
+ * was set to hidden.
841
+ */
842
+ return true;
843
+ }
844
+
845
+ if ( ! $this->has_settings_menu() ) {
846
+ // No menu settings at all.
847
+ return false;
848
+ }
849
+
850
+ if (
851
+ ! $is_tabs_visibility_check &&
852
+ $this->is_org_repo_compliant() &&
853
+ $this->show_settings_with_tabs()
854
+ ) {
855
+ /**
856
+ * wp.org themes are limited to a single submenu item, and
857
+ * sub-submenu items are most likely not allowed (never verified).
858
+ */
859
+ return false;
860
+ }
861
+
862
+ return $this->_menu->is_submenu_item_visible( $slug );
863
+ }
864
+
865
+ /**
866
+ * Check if a Freemius page should be accessible via the UI.
867
+ *
868
+ * @author Vova Feldman (@svovaf)
869
+ * @since 1.2.2.7
870
+ *
871
+ * @param string $slug
872
+ *
873
+ * @return bool
874
+ */
875
+ function is_page_visible( $slug ) {
876
+ if ( $this->is_admin_page( $slug ) ) {
877
+ return true;
878
+ }
879
+
880
+ return $this->_menu->is_submenu_item_visible( $slug, true, true );
881
+ }
882
+
883
+ /**
884
+ * @author Vova Feldman (@svovaf)
885
+ * @since 1.0.9
886
+ */
887
+ private function _version_updates_handler() {
888
+ if ( ! isset( $this->_storage->sdk_version ) || $this->_storage->sdk_version != $this->version ) {
889
+ // Freemius version upgrade mode.
890
+ $this->_storage->sdk_last_version = $this->_storage->sdk_version;
891
+ $this->_storage->sdk_version = $this->version;
892
+
893
+ if ( empty( $this->_storage->sdk_last_version ) ||
894
+ version_compare( $this->_storage->sdk_last_version, $this->version, '<' )
895
+ ) {
896
+ $this->_storage->sdk_upgrade_mode = true;
897
+ $this->_storage->sdk_downgrade_mode = false;
898
+ } else {
899
+ $this->_storage->sdk_downgrade_mode = true;
900
+ $this->_storage->sdk_upgrade_mode = false;
901
+
902
+ }
903
+
904
+ $this->do_action( 'sdk_version_update', $this->_storage->sdk_last_version, $this->version );
905
+ }
906
+
907
+ $plugin_version = $this->get_plugin_version();
908
+ if ( ! isset( $this->_storage->plugin_version ) || $this->_storage->plugin_version != $plugin_version ) {
909
+ // Plugin version upgrade mode.
910
+ $this->_storage->plugin_last_version = $this->_storage->plugin_version;
911
+ $this->_storage->plugin_version = $plugin_version;
912
+
913
+ if ( empty( $this->_storage->plugin_last_version ) ||
914
+ version_compare( $this->_storage->plugin_last_version, $plugin_version, '<' )
915
+ ) {
916
+ $this->_storage->plugin_upgrade_mode = true;
917
+ $this->_storage->plugin_downgrade_mode = false;
918
+ } else {
919
+ $this->_storage->plugin_downgrade_mode = true;
920
+ $this->_storage->plugin_upgrade_mode = false;
921
+ }
922
+
923
+ if ( ! empty( $this->_storage->plugin_last_version ) ) {
924
+ // Different version of the plugin was installed before, therefore it's an update.
925
+ $this->_storage->is_plugin_new_install = false;
926
+ }
927
+
928
+ $this->do_action( 'plugin_version_update', $this->_storage->plugin_last_version, $plugin_version );
929
+ }
930
+ }
931
+
932
+ #--------------------------------------------------------------------------------
933
+ #region Data Migration on SDK Update
934
+ #--------------------------------------------------------------------------------
935
+
936
+ /**
937
+ * @author Vova Feldman (@svovaf)
938
+ * @since 1.1.5
939
+ *
940
+ * @param string $sdk_prev_version
941
+ * @param string $sdk_version
942
+ */
943
+ function _sdk_version_update( $sdk_prev_version, $sdk_version ) {
944
+ if ( empty( $sdk_prev_version ) ) {
945
+ return;
946
+ }
947
+
948
+ if (
949
+ version_compare( $sdk_prev_version, '2.5.1', '<' ) &&
950
+ version_compare( $sdk_version, '2.5.1', '>=' )
951
+ ) {
952
+ if ( $this->is_registered( true ) ) {
953
+ /**
954
+ * Migrate to new permissions layer.
955
+ */
956
+ require_once WP_FS__DIR_INCLUDES . '/supplements/fs-migration-2.5.1.php';
957
+
958
+ $install_by_blog_id = is_multisite() ?
959
+ $this->get_blog_install_map() :
960
+ array( 0 => $this->_site );
961
+
962
+ fs_migrate_251( $this, $install_by_blog_id );
963
+ }
964
+ }
965
+ }
966
+
967
+ /**
968
+ * @author Leo Fajardo (@leorw)
969
+ * @since 2.0.0
970
+ *
971
+ * @param \FS_Storage $storage
972
+ * @param bool|int|null $blog_id
973
+ */
974
+ private static function migrate_install_plan_to_plan_id( FS_Storage $storage, $blog_id = null ) {
975
+ if ( empty( $storage->sdk_version ) ) {
976
+ // New installation of the plugin, no need to upgrade.
977
+ return;
978
+ }
979
+
980
+ if ( ! version_compare( $storage->sdk_version, '2.0.0', '<' ) ) {
981
+ // Previous version is >= 2.0.0, so no need to migrate.
982
+ return;
983
+ }
984
+
985
+ // Alias.
986
+ $module_type = $storage->get_module_type();
987
+ $module_slug = $storage->get_module_slug();
988
+
989
+ $installs = self::get_all_sites( $module_type, $blog_id );
990
+ $install = isset( $installs[ $module_slug ] ) ? $installs[ $module_slug ] : null;
991
+
992
+ if ( ! is_object( $install ) ) {
993
+ return;
994
+ }
995
+
996
+ if ( isset( $install->plan ) && is_object( $install->plan ) ) {
997
+ if ( isset( $install->plan->id ) && ! empty( $install->plan->id ) ) {
998
+ $install->plan_id = self::_decrypt( $install->plan->id );
999
+ }
1000
+
1001
+ unset( $install->plan );
1002
+
1003
+ $installs[ $module_slug ] = clone $install;
1004
+
1005
+ self::set_account_option_by_module(
1006
+ $module_type,
1007
+ 'sites',
1008
+ $installs,
1009
+ true,
1010
+ $blog_id
1011
+ );
1012
+ }
1013
+ }
1014
+
1015
+ /**
1016
+ * @author Vova Feldman (@svovaf)
1017
+ * @since 1.2.2.7
1018
+ *
1019
+ * @param string $plugin_prev_version
1020
+ * @param string $plugin_version
1021
+ */
1022
+ function _after_version_update( $plugin_prev_version, $plugin_version ) {
1023
+ if ( $this->is_theme() ) {
1024
+ // Expire the cache of the previous tabs since the theme may
1025
+ // have setting updates.
1026
+ $this->_cache->expire( 'tabs' );
1027
+ $this->_cache->expire( 'tabs_stylesheets' );
1028
+ }
1029
+ }
1030
+
1031
+ /**
1032
+ * A special migration logic for the $_accounts, executed for all the plugins in the system:
1033
+ * - Moves some data to the network level storage.
1034
+ * - If the plugin's connection was skipped for all sites, set the plugin as if it was network skipped.
1035
+ * - If the plugin's connection was ignored for all sites, don't do anything in terms of the network connection.
1036
+ * - If the plugin was connected to all sites by the same super-admin, set the plugin as if was network opted-in for all sites.
1037
+ * - If there's at least one site that was connected by a super-admin, find the "main super-admin" (the one that installed the majority of the plugin installs) and set the plugin as if was network activated with the main super-admin, set all the sites that were skipped or opted-in with a different user to delegated mode. Then, prompt the currently logged super-admin to choose what to do with the ignored sites.
1038
+ * - If there are any sites in the network which the connection decision was not yet taken for, set this plugin into network activation mode so a super-admin can choose what to do with the rest of the sites.
1039
+ *
1040
+ * @author Vova Feldman (@svovaf)
1041
+ * @since 2.0.0
1042
+ */
1043
+ private static function migrate_accounts_to_network() {
1044
+ $sites = self::get_sites();
1045
+ $sites_count = count( $sites );
1046
+ $connection_status = array();
1047
+ $plugin_slugs = array();
1048
+ foreach ( $sites as $site ) {
1049
+ $blog_id = self::get_site_blog_id( $site );
1050
+
1051
+ self::$_accounts->migrate_to_network( $blog_id );
1052
+
1053
+ /**
1054
+ * Build a list of all Freemius powered plugins slugs.
1055
+ */
1056
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array(), $blog_id );
1057
+ foreach ( $id_slug_type_path_map as $module_id => $data ) {
1058
+ if ( WP_FS__MODULE_TYPE_PLUGIN === $data['type'] ) {
1059
+ $plugin_slugs[ $data['slug'] ] = true;
1060
+ }
1061
+ }
1062
+
1063
+ $installs = self::get_account_option( 'sites', WP_FS__MODULE_TYPE_PLUGIN, $blog_id );
1064
+
1065
+ if ( is_array( $installs ) ) {
1066
+ foreach ( $installs as $slug => $install ) {
1067
+ if ( ! isset( $connection_status[ $slug ] ) ) {
1068
+ $connection_status[ $slug ] = array();
1069
+ }
1070
+
1071
+ if ( is_object( $install ) &&
1072
+ FS_Site::is_valid_id( $install->id ) &&
1073
+ FS_User::is_valid_id( $install->user_id )
1074
+ ) {
1075
+ $connection_status[ $slug ][ $blog_id ] = $install->user_id;
1076
+ }
1077
+ }
1078
+ }
1079
+ }
1080
+
1081
+ foreach ( $plugin_slugs as $slug => $true ) {
1082
+ if ( ! isset( $connection_status[ $slug ] ) ) {
1083
+ $connection_status[ $slug ] = array();
1084
+ }
1085
+
1086
+ foreach ( $sites as $site ) {
1087
+ $blog_id = self::get_site_blog_id( $site );
1088
+
1089
+ if ( isset( $connection_status[ $slug ][ $blog_id ] ) ) {
1090
+ continue;
1091
+ }
1092
+
1093
+ $storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $slug );
1094
+
1095
+ $is_anonymous = $storage->get( 'is_anonymous', null, $blog_id );
1096
+
1097
+ if ( ! is_null( $is_anonymous ) ) {
1098
+ // Since 1.1.3 is_anonymous is an array.
1099
+ if ( is_array( $is_anonymous ) && isset( $is_anonymous['is'] ) ) {
1100
+ $is_anonymous = $is_anonymous['is'];
1101
+ }
1102
+
1103
+ if ( is_bool( $is_anonymous ) && true === $is_anonymous ) {
1104
+ $connection_status[ $slug ][ $blog_id ] = 'skipped';
1105
+ }
1106
+ }
1107
+
1108
+ if ( ! isset( $connection_status[ $slug ][ $blog_id ] ) ) {
1109
+ $connection_status[ $slug ][ $blog_id ] = 'ignored';
1110
+ }
1111
+ }
1112
+ }
1113
+
1114
+ $super_admins = array();
1115
+
1116
+ foreach ( $connection_status as $slug => $blogs_status ) {
1117
+ $skips = 0;
1118
+ $ignores = 0;
1119
+ $connections = 0;
1120
+ $opted_in_users = array();
1121
+ $opted_in_super_admins = array();
1122
+
1123
+ $storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $slug );
1124
+
1125
+ foreach ( $blogs_status as $blog_id => $status_or_user_id ) {
1126
+ if ( 'skipped' === $status_or_user_id ) {
1127
+ $skips ++;
1128
+ } else if ( 'ignored' === $status_or_user_id ) {
1129
+ $ignores ++;
1130
+ } else if ( FS_User::is_valid_id( $status_or_user_id ) ) {
1131
+ $connections ++;
1132
+
1133
+ if ( ! isset( $opted_in_users[ $status_or_user_id ] ) ) {
1134
+ $opted_in_users[ $status_or_user_id ] = array();
1135
+ }
1136
+
1137
+ $opted_in_users[ $status_or_user_id ][] = $blog_id;
1138
+
1139
+ if ( isset( $super_admins[ $status_or_user_id ] ) ||
1140
+ self::is_super_admin( $status_or_user_id )
1141
+ ) {
1142
+ // Cache super-admin data.
1143
+ $super_admins[ $status_or_user_id ] = true;
1144
+
1145
+ // Remember opted-in super-admins for the plugin.
1146
+ $opted_in_super_admins[ $status_or_user_id ] = true;
1147
+ }
1148
+ }
1149
+ }
1150
+
1151
+ $main_super_admin_user_id = null;
1152
+ $all_migrated = false;
1153
+ if ( $sites_count == $skips ) {
1154
+ // All sites were skipped -> network skip by copying the anonymous mode from any of the sites.
1155
+ $storage->is_anonymous_ms = $storage->is_anonymous;
1156
+
1157
+ $all_migrated = true;
1158
+ } else if ( $sites_count == $ignores ) {
1159
+ // Don't do anything, still in activation mode.
1160
+
1161
+ $all_migrated = true;
1162
+ } else if ( 0 < count( $opted_in_super_admins ) ) {
1163
+ // Find the super-admin with the majority of installs.
1164
+ $max_installs_by_super_admin = 0;
1165
+ foreach ( $opted_in_super_admins as $user_id => $true ) {
1166
+ $installs_count = count( $opted_in_users[ $user_id ] );
1167
+
1168
+ if ( $installs_count > $max_installs_by_super_admin ) {
1169
+ $max_installs_by_super_admin = $installs_count;
1170
+ $main_super_admin_user_id = $user_id;
1171
+ }
1172
+ }
1173
+
1174
+ if ( $sites_count == $connections && 1 == count( $opted_in_super_admins ) ) {
1175
+ // Super-admin opted-in for all sites in the network.
1176
+ $storage->is_network_connected = true;
1177
+
1178
+ $all_migrated = true;
1179
+ }
1180
+
1181
+ // Store network user.
1182
+ $storage->network_user_id = $main_super_admin_user_id;
1183
+
1184
+ $storage->network_install_blog_id = ( $sites_count == $connections ) ?
1185
+ // Since all sites are opted-in, associating with the main site.
1186
+ get_current_blog_id() :
1187
+ // Associating with the 1st found opted-in site.
1188
+ $opted_in_users[ $main_super_admin_user_id ][0];
1189
+
1190
+ /**
1191
+ * Make sure we migrate the plan ID of the network install, otherwise, if after the migration
1192
+ * the 1st page that will be loaded is the network level WP Admin and $storage->network_install_blog_id
1193
+ * is different than the main site of the network, the $this->_site will not be set since the plan_id
1194
+ * will be empty.
1195
+ */
1196
+ $storage->migrate_to_network();
1197
+ self::migrate_install_plan_to_plan_id( $storage, $storage->network_install_blog_id );
1198
+ } else {
1199
+ // At least one opt-in. All the opt-in were created by a non-super-admin.
1200
+ if ( 0 == $ignores ) {
1201
+ // All sites were opted-in or skipped, all by non-super-admin. So delegate all.
1202
+ $storage->store( 'is_delegated_connection', true, true );
1203
+
1204
+ $all_migrated = true;
1205
+ }
1206
+ }
1207
+
1208
+ if ( ! $all_migrated ) {
1209
+ /**
1210
+ * Delegate all sites that were:
1211
+ * 1) Opted-in by a user that is NOT the main-super-admin.
1212
+ * 2) Skipped and non of the sites was opted-in by a super-admin. If any site was opted-in by a super-admin, there will be a main-super-admin, and we consider the skip as if it was done by that user.
1213
+ */
1214
+ foreach ( $blogs_status as $blog_id => $status_or_user_id ) {
1215
+ if ( $status_or_user_id == $main_super_admin_user_id ) {
1216
+ continue;
1217
+ }
1218
+
1219
+ if ( FS_User::is_valid_id( $status_or_user_id ) ||
1220
+ ( 'skipped' === $status_or_user_id && is_null( $main_super_admin_user_id ) )
1221
+ ) {
1222
+ $storage->store( 'is_delegated_connection', true, $blog_id );
1223
+ }
1224
+ }
1225
+ }
1226
+
1227
+
1228
+ if ( ( $connections + $skips > 0 ) ) {
1229
+ if ( $ignores > 0 ) {
1230
+ /**
1231
+ * If admin already opted-in or skipped in any of the network sites, and also
1232
+ * have sites which the connection decision was not yet taken, set this plugin
1233
+ * into network activation mode so the super-admin can choose what to do with
1234
+ * the rest of the sites.
1235
+ */
1236
+ self::set_network_upgrade_mode( $storage );
1237
+ }
1238
+ }
1239
+ }
1240
+ }
1241
+
1242
+ /**
1243
+ * Set a module into network upgrade mode.
1244
+ *
1245
+ * @author Vova Feldman (@svovaf)
1246
+ * @since 2.0.0
1247
+ *
1248
+ * @param \FS_Storage $storage
1249
+ *
1250
+ * @return bool
1251
+ */
1252
+ private static function set_network_upgrade_mode( FS_Storage $storage ) {
1253
+ return $storage->is_network_activation = true;
1254
+ }
1255
+
1256
+ /**
1257
+ * Will return true after upgrading to the SDK with the network level integration,
1258
+ * when the super-admin involvement is required regarding the rest of the sites.
1259
+ *
1260
+ * @author Vova Feldman (@svovaf)
1261
+ * @since 2.0.0
1262
+ *
1263
+ * @return bool
1264
+ */
1265
+ function is_network_upgrade_mode() {
1266
+ return $this->_storage->get( 'is_network_activation' );
1267
+ }
1268
+
1269
+ /**
1270
+ * Clear flag after the upgrade mode completion.
1271
+ *
1272
+ * @author Vova Feldman (@svovaf)
1273
+ * @since 2.0.0
1274
+ *
1275
+ * @return bool True if network activation was on and now completed.
1276
+ */
1277
+ private function network_upgrade_mode_completed() {
1278
+ if ( fs_is_network_admin() && $this->is_network_upgrade_mode() ) {
1279
+ $this->_storage->remove( 'is_network_activation' );
1280
+
1281
+ return true;
1282
+ }
1283
+
1284
+ return false;
1285
+ }
1286
+
1287
+ #endregion
1288
+
1289
+ /**
1290
+ * This action is connected to the 'plugins_loaded' hook and helps to determine
1291
+ * if this is a new plugin installation or a plugin update.
1292
+ *
1293
+ * There are 3 different use-cases:
1294
+ * 1) New plugin installation right with Freemius:
1295
+ * 1.1 _activate_plugin_event_hook() will be executed first
1296
+ * 1.2 Since $this->_storage->is_plugin_new_install is not set,
1297
+ * and $this->_storage->plugin_last_version is not set,
1298
+ * $this->_storage->is_plugin_new_install will be set to TRUE.
1299
+ * 1.3 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
1300
+ * be already set to TRUE.
1301
+ *
1302
+ * 2) Plugin update, didn't have Freemius before, and now have the SDK:
1303
+ * 2.1 _activate_plugin_event_hook() will not be executed, because
1304
+ * the activation hook do NOT fires on updates since WP 3.1.
1305
+ * 2.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
1306
+ * be empty, therefore, it will be set to FALSE.
1307
+ *
1308
+ * 3) Plugin update, had Freemius in prev version as well:
1309
+ * 3.1 _version_updates_handler() will be executed 1st, since FS was installed
1310
+ * before, $this->_storage->plugin_last_version will NOT be empty,
1311
+ * therefore, $this->_storage->is_plugin_new_install will be set to FALSE.
1312
+ * 3.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install is
1313
+ * already set, therefore, it will not be modified.
1314
+ *
1315
+ * Use-case #3 is backward compatible, #3.1 will be executed since 1.0.9.
1316
+ *
1317
+ * NOTE:
1318
+ * The only fallback of this mechanism is if an admin updates a plugin based on use-case #2,
1319
+ * and then, the next immediate PageView is the plugin's main settings page, it will not
1320
+ * show the opt-in right away. The reason it will happen is because Freemius execution
1321
+ * will be turned off till the plugin is fully loaded at least once
1322
+ * (till $this->_storage->was_plugin_loaded is TRUE).
1323
+ *
1324
+ * @author Vova Feldman (@svovaf)
1325
+ * @since 1.1.9
1326
+ *
1327
+ */
1328
+ function _plugins_loaded() {
1329
+ // Update flag that plugin was loaded with Freemius at least once.
1330
+ $this->_storage->was_plugin_loaded = true;
1331
+
1332
+ /**
1333
+ * Bug fix - only set to false when it's a plugin, due to the
1334
+ * execution sequence of the theme hooks and our methods, if
1335
+ * this will be set for themes, Freemius will always assume
1336
+ * it's a theme update.
1337
+ *
1338
+ * @author Vova Feldman (@svovaf)
1339
+ * @since 1.2.2.2
1340
+ */
1341
+ if ( $this->is_plugin() &&
1342
+ ! isset( $this->_storage->is_plugin_new_install )
1343
+ ) {
1344
+ $this->_storage->is_plugin_new_install = (
1345
+ ! is_plugin_active( $this->_plugin_basename ) &&
1346
+ empty( $this->_storage->plugin_last_version )
1347
+ );
1348
+ }
1349
+ }
1350
+
1351
+ /**
1352
+ * Opens the support forum subemenu item in a new browser page.
1353
+ *
1354
+ * @author Vova Feldman (@svovaf)
1355
+ * @since 2.1.4
1356
+ */
1357
+ static function _open_support_forum_in_new_page() {
1358
+ ?>
1359
+ <script type="text/javascript">
1360
+ (function ($) {
1361
+ $('.fs-submenu-item.wp-support-forum').parent().attr( { target: '_blank', rel: 'noopener noreferrer' } );
1362
+ })(jQuery);
1363
+ </script>
1364
+ <?php
1365
+ }
1366
+
1367
+ /**
1368
+ * @author Vova Feldman (@svovaf)
1369
+ * @since 1.0.9
1370
+ */
1371
+ private function register_constructor_hooks() {
1372
+ $this->_logger->entrance();
1373
+
1374
+ if ( is_admin() ) {
1375
+ add_action( 'admin_init', array( &$this, '_hook_action_links_and_register_account_hooks' ) );
1376
+
1377
+ if ( $this->is_plugin() ) {
1378
+ if ( self::is_plugin_install_page() && true !== fs_request_get_bool( 'fs_allow_updater_and_dialog' ) ) {
1379
+ /**
1380
+ * Unless the `fs_allow_updater_and_dialog` URL param exists and its value is `true`, make
1381
+ * Freemius-related updates unavailable on the "Add Plugins" admin page (/plugin-install.php)
1382
+ * so that they won't interfere with the .org plugins' functionalities on that page (e.g.
1383
+ * updating of a .org plugin).
1384
+ */
1385
+ add_filter( 'site_transient_update_plugins', array( 'Freemius', '_remove_fs_updates_from_plugin_install_page' ), 10, 2 );
1386
+ } else if ( self::is_plugins_page() || self::is_updates_page() ) {
1387
+ /**
1388
+ * On the "Plugins" and "Updates" admin pages, if there are premium or non–org-compliant plugins, modify their details dialog URLs (add a Freemius-specific param) so that the SDK can determine if the plugin information dialog should show information from Freemius.
1389
+ *
1390
+ * @author Leo Fajardo (@leorw)
1391
+ * @since 2.2.3
1392
+ */
1393
+ add_action( 'admin_footer', array( 'Freemius', '_prepend_fs_allow_updater_and_dialog_flag_url_param' ) );
1394
+ }
1395
+
1396
+ $plugin_dir = dirname( $this->_plugin_dir_path ) . '/';
1397
+
1398
+ /**
1399
+ * @since 1.2.2
1400
+ *
1401
+ * Hook to both free and premium version activations to support
1402
+ * auto deactivation on the other version activation.
1403
+ */
1404
+ register_activation_hook(
1405
+ $plugin_dir . $this->_free_plugin_basename,
1406
+ array( &$this, '_activate_plugin_event_hook' )
1407
+ );
1408
+
1409
+ register_activation_hook(
1410
+ $plugin_dir . $this->premium_plugin_basename(),
1411
+ array( &$this, '_activate_plugin_event_hook' )
1412
+ );
1413
+ } else {
1414
+ add_action( 'after_switch_theme', array( &$this, '_activate_theme_event_hook' ), 10, 2 );
1415
+
1416
+ add_action( 'admin_footer', array( &$this, '_style_premium_theme' ) );
1417
+ }
1418
+
1419
+ /**
1420
+ * Part of the mechanism to identify new plugin install vs. plugin update.
1421
+ *
1422
+ * @author Vova Feldman (@svovaf)
1423
+ * @since 1.1.9
1424
+ */
1425
+ if ( empty( $this->_storage->was_plugin_loaded ) ) {
1426
+ /**
1427
+ * During the plugin activation (not theme), 'plugins_loaded' will be already executed
1428
+ * when the logic gets here since the activation logic first add the activate plugins,
1429
+ * then triggers 'plugins_loaded', and only then include the code of the plugin that
1430
+ * is activated. Which means that _plugins_loaded() will NOT be executed during the
1431
+ * plugin activation, and that IS intentional.
1432
+ *
1433
+ * @author Vova Feldman (@svovaf)
1434
+ */
1435
+ if ( $this->is_plugin() &&
1436
+ $this->is_activation_mode( false ) &&
1437
+ 0 == did_action( 'plugins_loaded' )
1438
+ ) {
1439
+ add_action( 'plugins_loaded', array( &$this, '_plugins_loaded' ) );
1440
+ } else {
1441
+ // If was activated before, then it was already loaded before.
1442
+ $this->_plugins_loaded();
1443
+ }
1444
+ }
1445
+
1446
+ if ( ! self::is_ajax() ) {
1447
+ if ( ! $this->is_addon() ) {
1448
+ add_action( 'init', array( &$this, '_add_default_submenu_items' ), WP_FS__LOWEST_PRIORITY );
1449
+ }
1450
+ }
1451
+
1452
+ if ( $this->_storage->handle_gdpr_admin_notice ) {
1453
+ add_action( 'init', array( &$this, '_maybe_show_gdpr_admin_notice' ) );
1454
+ }
1455
+
1456
+ add_action( 'init', array( &$this, '_maybe_add_gdpr_optin_ajax_handler') );
1457
+ add_action( 'init', array( &$this, '_maybe_add_pricing_ajax_handler' ) );
1458
+ }
1459
+
1460
+ if ( $this->is_plugin() ) {
1461
+ if ( version_compare( $GLOBALS['wp_version'], '5.1', '<' ) ) {
1462
+ add_action( 'wpmu_new_blog', array( $this, '_after_new_blog_callback' ), 10, 6 );
1463
+ } else {
1464
+ add_action( 'wp_initialize_site', array( $this, '_after_wp_initialize_site_callback' ), 11, 2 );
1465
+ }
1466
+
1467
+ register_deactivation_hook( $this->_plugin_main_file_path, array( &$this, '_deactivate_plugin_hook' ) );
1468
+ }
1469
+
1470
+ if ( is_multisite() ) {
1471
+ add_action( 'deactivate_blog', array( &$this, '_after_site_deactivated_callback' ) );
1472
+ add_action( 'archive_blog', array( &$this, '_after_site_deactivated_callback' ) );
1473
+ add_action( 'make_spam_blog', array( &$this, '_after_site_deactivated_callback' ) );
1474
+
1475
+ if ( version_compare( $GLOBALS['wp_version'], '5.1', '<' ) ) {
1476
+ add_action( 'deleted_blog', array( $this, '_after_site_deleted_callback' ), 10, 2 );
1477
+ } else {
1478
+ add_action( 'wp_delete_site', array( $this, '_after_wpsite_deleted_callback' ) );
1479
+ }
1480
+
1481
+ add_action( 'activate_blog', array( &$this, '_after_site_reactivated_callback' ) );
1482
+ add_action( 'unarchive_blog', array( &$this, '_after_site_reactivated_callback' ) );
1483
+ add_action( 'make_ham_blog', array( &$this, '_after_site_reactivated_callback' ) );
1484
+ }
1485
+
1486
+ if ( $this->is_theme() &&
1487
+ self::is_customizer() &&
1488
+ $this->apply_filters( 'show_customizer_upsell', true )
1489
+ ) {
1490
+ // Register customizer upsell.
1491
+ add_action( 'customize_register', array( &$this, '_customizer_register' ) );
1492
+ }
1493
+
1494
+ add_action( 'admin_init', array( &$this, '_redirect_on_clicked_menu_link' ), WP_FS__LOWEST_PRIORITY );
1495
+
1496
+ if ( $this->is_theme() && ! $this->is_migration() ) {
1497
+ add_action( 'admin_init', array( &$this, '_add_tracking_links' ) );
1498
+ }
1499
+
1500
+ add_action( 'admin_init', array( &$this, '_add_license_activation' ) );
1501
+ add_action( 'admin_init', array( &$this, '_add_premium_version_upgrade_selection' ) );
1502
+ add_action( 'admin_init', array( &$this, '_add_beta_mode_update_handler' ) );
1503
+ add_action( 'admin_init', array( &$this, '_add_user_change_option' ) );
1504
+ add_action( 'admin_init', array( &$this, '_add_email_address_update_option' ) );
1505
+
1506
+ $this->add_ajax_action( 'update_billing', array( &$this, '_update_billing_ajax_action' ) );
1507
+ $this->add_ajax_action( 'start_trial', array( &$this, '_start_trial_ajax_action' ) );
1508
+ $this->add_ajax_action( 'set_data_debug_mode', array( &$this, '_set_data_debug_mode' ) );
1509
+ $this->add_ajax_action( 'toggle_whitelabel_mode', array( &$this, '_toggle_whitelabel_mode_ajax_handler' ) );
1510
+
1511
+ if ( $this->_is_network_active && fs_is_network_admin() ) {
1512
+ $this->add_ajax_action( 'network_activate', array( &$this, '_network_activate_ajax_action' ) );
1513
+ }
1514
+
1515
+ $this->add_ajax_action( 'install_premium_version', array(
1516
+ &$this,
1517
+ '_install_premium_version_ajax_action'
1518
+ ) );
1519
+
1520
+ $this->add_ajax_action( 'submit_affiliate_application', array( &$this, '_submit_affiliate_application' ) );
1521
+
1522
+ $this->add_action( 'after_plans_sync', array( &$this, '_check_for_trial_plans' ) );
1523
+
1524
+ $this->add_action( 'sdk_version_update', array( &$this, '_sdk_version_update' ), WP_FS__DEFAULT_PRIORITY, 2 );
1525
+
1526
+ $this->add_action(
1527
+ 'plugin_version_update',
1528
+ array( &$this, '_after_version_update' ),
1529
+ WP_FS__DEFAULT_PRIORITY,
1530
+ 2
1531
+ );
1532
+ $this->add_filter( 'after_code_type_change', array( &$this, '_after_code_type_change' ) );
1533
+
1534
+ add_action( 'admin_init', array( &$this, '_add_trial_notice' ) );
1535
+ add_action( 'admin_init', array( &$this, '_add_affiliate_program_notice' ) );
1536
+ add_action( 'admin_enqueue_scripts', array( &$this, '_enqueue_common_css' ) );
1537
+
1538
+ /**
1539
+ * Handle request to reset anonymous mode for `get_reconnect_url()`.
1540
+ *
1541
+ * @author Vova Feldman (@svovaf)
1542
+ * @since 1.2.1.5
1543
+ */
1544
+ if ( fs_request_is_action( 'reset_anonymous_mode' ) &&
1545
+ $this->get_unique_affix() === fs_request_get( 'fs_unique_affix' )
1546
+ ) {
1547
+ add_action( 'admin_init', array( &$this, 'connect_again' ) );
1548
+ }
1549
+ }
1550
+
1551
+ /**
1552
+ * Register the required hooks right after the settings parse is completed.
1553
+ *
1554
+ * @author Vova Feldman (@svovaf)
1555
+ * @since 2.3.1
1556
+ */
1557
+ private function register_after_settings_parse_hooks() {
1558
+ if ( is_admin() &&
1559
+ $this->is_theme() &&
1560
+ $this->is_premium() &&
1561
+ ! $this->has_active_valid_license()
1562
+ ) {
1563
+ $this->add_ajax_action(
1564
+ 'delete_theme_update_data',
1565
+ array( &$this, '_delete_theme_update_data_action' )
1566
+ );
1567
+ }
1568
+
1569
+ if ( $this->show_settings_with_tabs() ) {
1570
+ /**
1571
+ * Include the required hooks to capture the theme settings' page tabs
1572
+ * and cache them.
1573
+ *
1574
+ * @author Vova Feldman (@svovaf)
1575
+ * @since 1.2.2.7
1576
+ */
1577
+ if ( ! $this->_cache->has_valid( 'tabs' ) ) {
1578
+ add_action( 'admin_footer', array( &$this, '_tabs_capture' ) );
1579
+ // Add license activation AJAX callback.
1580
+ $this->add_ajax_action( 'store_tabs', array( &$this, '_store_tabs_ajax_action' ) );
1581
+
1582
+ add_action( 'admin_enqueue_scripts', array( &$this, '_store_tabs_styles' ), 9999999 );
1583
+ }
1584
+
1585
+ add_action(
1586
+ 'admin_footer',
1587
+ array( &$this, '_add_freemius_tabs' ),
1588
+ /**
1589
+ * The tabs JS code must be executed after the tabs capture logic (_tabs_capture()).
1590
+ * That's why the priority is 11 while the tabs capture logic is added
1591
+ * with priority 10.
1592
+ *
1593
+ * @author Vova Feldman (@svovaf)
1594
+ */
1595
+ 11
1596
+ );
1597
+ }
1598
+
1599
+ if ( ! self::is_ajax() ) {
1600
+ if ( ! $this->is_addon() || $this->is_only_premium() ) {
1601
+ add_action(
1602
+ ( $this->_is_network_active && fs_is_network_admin() ? 'network_' : '' ) . 'admin_menu',
1603
+ array( &$this, '_prepare_admin_menu' ),
1604
+ WP_FS__LOWEST_PRIORITY
1605
+ );
1606
+ }
1607
+ }
1608
+ }
1609
+
1610
+ /**
1611
+ * Makes Freemius-related updates unavailable on the "Add Plugins" admin page (/plugin-install.php) so that
1612
+ * they won't interfere with the .org plugins' functionalities on that page (e.g. updating of a .org plugin).
1613
+ *
1614
+ * @author Leo Fajardo (@leorw)
1615
+ * @since 2.2.3
1616
+ *
1617
+ * @param object $updates
1618
+ * @param string|null $transient
1619
+ *
1620
+ * @return object
1621
+ */
1622
+ static function _remove_fs_updates_from_plugin_install_page( $updates, $transient = null ) {
1623
+ if ( is_object( $updates ) && isset( $updates->response ) ) {
1624
+ foreach ( $updates->response as $file => $plugin ) {
1625
+ if ( isset( $plugin->package ) && false !== strpos( $plugin->package, 'api.freemius' ) ) {
1626
+ unset( $updates->response[ $file ] );
1627
+ }
1628
+ }
1629
+ }
1630
+
1631
+ return $updates;
1632
+ }
1633
+
1634
+ /**
1635
+ * Prepends the `fs_allow_updater_and_dialog` param to the plugin information URLs to tell the SDK to handle
1636
+ * the information that is shown on the plugin details dialog that is shown when the relevant link is clicked.
1637
+ *
1638
+ * @author Leo Fajardo (@leorw)
1639
+ * @since 2.2.3
1640
+ *
1641
+ * @return string
1642
+ */
1643
+ static function _prepend_fs_allow_updater_and_dialog_flag_url_param() {
1644
+ $slug_basename_map = array();
1645
+ foreach ( self::$_instances as $instance ) {
1646
+ if ( ! $instance->is_plugin() ) {
1647
+ continue;
1648
+ }
1649
+
1650
+ $slug_basename_map[ $instance->get_slug() ] = $instance->premium_plugin_basename();
1651
+ }
1652
+ ?>
1653
+ <script type="text/javascript">
1654
+ (function( $ ) {
1655
+ var slugBasenameMap = <?php echo json_encode( $slug_basename_map ) ?>;
1656
+ for ( var slug in slugBasenameMap ) {
1657
+ var basename = slugBasenameMap[ slug ];
1658
+
1659
+ // Try to get the plugin rows if on the "Plugins" page.
1660
+ var $pluginRows = $( '.wp-list-table.plugins tr[data-plugin="' + basename + '"]');
1661
+
1662
+ if ( 0 === $pluginRows.length ) {
1663
+ // Try to get the plugin rows if on the "Updates" page.
1664
+ var $pluginCheckbox = $( '#update-plugins-table input[type="checkbox"][value="' + basename + '"]' );
1665
+ if ( 0 !== $pluginCheckbox.length ) {
1666
+ $pluginRows = $pluginCheckbox.parents( 'tr:first' );
1667
+ }
1668
+ }
1669
+
1670
+ if ( 0 === $pluginRows.length ) {
1671
+ // No plugin rows found.
1672
+ continue;
1673
+ }
1674
+
1675
+ // Find the "View details" links and add the `fs_allow_updater_and_dialog` param to the URL.
1676
+ $pluginRows.find( 'a[href*="plugin-install.php?tab=plugin-information"]' ).each(function() {
1677
+ var $this = $( this ),
1678
+ href = $this.attr( 'href' ).replace( '?tab=', '?fs_allow_updater_and_dialog=true&tab=');
1679
+
1680
+ $this.attr( 'href', href );
1681
+ });
1682
+ }
1683
+ })( jQuery );
1684
+ </script>
1685
+ <?php
1686
+ }
1687
+
1688
+ /**
1689
+ * @author Leo Fajardo (@leorw)
1690
+ * @since 2.3.0
1691
+ */
1692
+ static function _maybe_add_beta_label_styles() {
1693
+ $has_any_beta_version = false;
1694
+
1695
+ foreach ( self::$_instances as $instance ) {
1696
+ if ( $instance->is_beta() ) {
1697
+ $has_any_beta_version = true;
1698
+ break;
1699
+ }
1700
+ }
1701
+
1702
+ if ( $has_any_beta_version ) {
1703
+ fs_enqueue_local_style( 'fs_plugins', '/admin/plugins.css' );
1704
+ }
1705
+ }
1706
+
1707
+ /**
1708
+ * @author Leo Fajardo (@leorw)
1709
+ * @since 2.3.0
1710
+ */
1711
+ static function _maybe_add_beta_label_to_plugins_and_handle_confirmation() {
1712
+ $beta_data = array();
1713
+
1714
+ foreach ( self::$_instances as $instance ) {
1715
+ if ( ! $instance->is_premium() ) {
1716
+ continue;
1717
+ }
1718
+
1719
+ /**
1720
+ * If there's an available beta version update, a confirmation message will be shown when the
1721
+ * "Update now" link on the "Plugins" or "Themes" page is clicked.
1722
+ */
1723
+ $has_beta_update = $instance->has_beta_update();
1724
+
1725
+ $is_beta = (
1726
+ // The "Beta" label is added separately for themes.
1727
+ $instance->is_plugin() &&
1728
+ $instance->is_beta()
1729
+ );
1730
+
1731
+ if ( ! $is_beta && ! $has_beta_update ) {
1732
+ continue;
1733
+ }
1734
+
1735
+ $beta_data[ $instance->get_plugin_basename() ] = array( 'is_installed_version_beta' => $is_beta );
1736
+
1737
+ if ( ! $has_beta_update ) {
1738
+ continue;
1739
+ }
1740
+
1741
+ $beta_data[ $instance->get_plugin_basename() ]['beta_version_update_confirmation_message'] = sprintf(
1742
+ '%s %s',
1743
+ sprintf(
1744
+ fs_esc_attr_inline(
1745
+ 'An update to a Beta version will replace your installed version of %s with the latest Beta release - use with caution, and not on production sites. You have been warned.',
1746
+ 'beta-version-update-caution',
1747
+ $instance->get_slug()
1748
+ ),
1749
+ $instance->get_plugin_title()
1750
+ ),
1751
+ fs_esc_attr_inline( 'Would you like to proceed with the update?', 'update-confirmation', $instance->get_slug() )
1752
+ );
1753
+ }
1754
+
1755
+ if ( empty( $beta_data ) ) {
1756
+ return;
1757
+ }
1758
+ ?>
1759
+ <script type="text/javascript">
1760
+ ( function( $ ) {
1761
+ var betaData = <?php echo json_encode( $beta_data ) ?>;
1762
+
1763
+ for ( var pluginBasename in betaData ) {
1764
+ if ( ! betaData.hasOwnProperty( pluginBasename ) ) {
1765
+ continue;
1766
+ }
1767
+
1768
+ if ( ! betaData[ pluginBasename ].is_installed_version_beta ) {
1769
+ continue;
1770
+ }
1771
+
1772
+ var $parentContainer = $( '.wp-list-table.plugins tr[data-plugin="' + pluginBasename + '"]' );
1773
+ if ( 0 === $parentContainer.length ) {
1774
+ continue;
1775
+ }
1776
+
1777
+ $parentContainer.find( '.plugin-title > strong:first-child').append(
1778
+ '<span class="fs-tag fs-info"><?php fs_esc_js_echo_inline( 'Beta', 'beta' ) ?></span>'
1779
+ );
1780
+ }
1781
+
1782
+ setTimeout( function() {
1783
+ // Wait a little bit before adding the event handler, otherwise, it will be overridden by the core WP logic.
1784
+ $( '.plugins .update-message .update-link, .themes .theme .update-message' ).on( 'click', function() {
1785
+ var $parentContainer = $( this ).parents( 'tr:first' );
1786
+ pluginBasename = ( 0 !== $parentContainer.length ) ?
1787
+ $parentContainer.data( 'plugin' ) :
1788
+ $( this ).parents( '.theme:first' ).data( 'slug' );
1789
+
1790
+ if (
1791
+ betaData[ pluginBasename ] &&
1792
+ betaData[ pluginBasename ].beta_version_update_confirmation_message &&
1793
+ ! confirm( betaData[ pluginBasename ].beta_version_update_confirmation_message )
1794
+ ) {
1795
+ return false;
1796
+ }
1797
+ } );
1798
+ }, 20 );
1799
+ } )( jQuery );
1800
+ </script>
1801
+ <?php
1802
+ }
1803
+
1804
+ /**
1805
+ * Keeping the uninstall hook registered for free or premium plugin version may result to a fatal error that
1806
+ * could happen when a user tries to uninstall either version while one of them is still active. Uninstalling a
1807
+ * plugin will trigger inclusion of the free or premium version and if one of them is active during the
1808
+ * uninstallation, a fatal error may occur in case the plugin's class or functions are already defined.
1809
+ *
1810
+ * @author Leo Fajardo (@leorw)
1811
+ *
1812
+ * @since 1.2.0
1813
+ */
1814
+ private function unregister_uninstall_hook() {
1815
+ $uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
1816
+ unset( $uninstallable_plugins[ $this->_free_plugin_basename ] );
1817
+ unset( $uninstallable_plugins[ $this->premium_plugin_basename() ] );
1818
+
1819
+ update_option( 'uninstall_plugins', $uninstallable_plugins );
1820
+ }
1821
+
1822
+ /**
1823
+ * @since 1.2.0 Invalidate module's main file cache, otherwise, FS_Plugin_Updater will not fetch updates.
1824
+ *
1825
+ * @param bool $store_prev_path
1826
+ */
1827
+ private function clear_module_main_file_cache( $store_prev_path = true ) {
1828
+ if ( ! isset( $this->_storage->plugin_main_file ) ||
1829
+ empty( $this->_storage->plugin_main_file->path )
1830
+ ) {
1831
+ return;
1832
+ }
1833
+
1834
+ if ( ! $store_prev_path ) {
1835
+ /**
1836
+ * Storing the previous path is not needed when clearing the cache after an SDK version update since
1837
+ * the main purpose of the cache clearing in that event is to correct a wrong plugin main file path
1838
+ * which causes data mix-up between plugins (e.g. titles and versions of an add-on and its parent plugin).
1839
+ *
1840
+ * @author Leo Fajardo (@leorw)
1841
+ * @since 2.2.1
1842
+ */
1843
+ unset( $this->_storage->plugin_main_file->path );
1844
+ } else {
1845
+ $plugin_main_file = clone $this->_storage->plugin_main_file;
1846
+
1847
+ // Store cached path (2nd layer cache).
1848
+ $plugin_main_file->prev_path = $plugin_main_file->path;
1849
+
1850
+ // Clear cached path.
1851
+ unset( $plugin_main_file->path );
1852
+
1853
+ $this->_storage->plugin_main_file = $plugin_main_file;
1854
+ }
1855
+
1856
+ /**
1857
+ * Clear global cached path.
1858
+ *
1859
+ * @author Leo Fajardo (@leorw)
1860
+ * @since 1.2.2
1861
+ */
1862
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map' );
1863
+ unset( $id_slug_type_path_map[ $this->_module_id ]['path'] );
1864
+ self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
1865
+ }
1866
+
1867
+ /**
1868
+ * @author Leo Fajardo (@leorw)
1869
+ * @since 2.0.0
1870
+ */
1871
+ function _hook_action_links_and_register_account_hooks() {
1872
+ if ( $this->is_migration() ) {
1873
+ return;
1874
+ }
1875
+
1876
+ if (
1877
+ ( self::is_plugins_page() && $this->is_plugin() ) ||
1878
+ ( self::is_themes_page() && $this->is_theme() ) ||
1879
+ fs_request_is_action_secure( $this->get_unique_affix() . '_reconnect' )
1880
+ ) {
1881
+ $this->_add_tracking_links();
1882
+ }
1883
+
1884
+ if ( self::is_plugins_page() && $this->is_plugin() ) {
1885
+ $this->hook_plugin_action_links();
1886
+ }
1887
+
1888
+ $this->_register_account_hooks();
1889
+ }
1890
+
1891
+ /**
1892
+ * @author Vova Feldman (@svovaf)
1893
+ * @since 1.0.9
1894
+ */
1895
+ private function _register_account_hooks() {
1896
+ if ( ! is_admin() ) {
1897
+ return;
1898
+ }
1899
+
1900
+ /**
1901
+ * Always show the deactivation feedback form since we added
1902
+ * automatic free version deactivation upon premium code activation.
1903
+ *
1904
+ * @since 1.2.1.6
1905
+ */
1906
+ $this->add_ajax_action(
1907
+ 'submit_uninstall_reason',
1908
+ array( &$this, '_submit_uninstall_reason_action' )
1909
+ );
1910
+
1911
+ $this->add_ajax_action(
1912
+ 'cancel_subscription_or_trial',
1913
+ array( &$this, 'cancel_subscription_or_trial_ajax_action' )
1914
+ );
1915
+
1916
+ if ( ! $this->is_addon() || $this->is_parent_plugin_installed() ) {
1917
+ if ( ( $this->is_plugin() && self::is_plugins_page() ) ||
1918
+ ( $this->is_theme() && self::is_themes_page() )
1919
+ ) {
1920
+ add_action( 'admin_footer', array( &$this, '_add_deactivation_feedback_dialog_box' ) );
1921
+ }
1922
+ }
1923
+ }
1924
+
1925
+ /**
1926
+ * Leverage backtrace to find caller plugin file path.
1927
+ *
1928
+ * @param bool $is_init Is initiation sequence.
1929
+ * @param string $main_file Since 2.5.0 expects the module's main file path to potentially purge the cached path.
1930
+ *
1931
+ * @return string
1932
+ * @since 1.0.6
1933
+ *
1934
+ * @author Vova Feldman (@svovaf)
1935
+ */
1936
+ private function _find_caller_plugin_file( $is_init = false, $main_file = '' ) {
1937
+ // Try to load the cached value of the file path.
1938
+ if ( isset( $this->_storage->plugin_main_file ) ) {
1939
+ $plugin_main_file = $this->_storage->plugin_main_file;
1940
+ if ( ! empty( $plugin_main_file->path ) ) {
1941
+ $absolute_path = $this->get_absolute_path( $plugin_main_file->path );
1942
+ if ( file_exists( $absolute_path ) ) {
1943
+ if ( $is_init && $absolute_path !== $this->get_absolute_path( $main_file ) ) {
1944
+ // Update cached path if not matching the actual path.
1945
+ $plugin_main_file->path = $main_file;
1946
+ $this->_storage->plugin_main_file = $plugin_main_file;
1947
+ }
1948
+
1949
+ return $absolute_path;
1950
+ }
1951
+ }
1952
+ }
1953
+
1954
+ /**
1955
+ * @since 1.2.1
1956
+ *
1957
+ * `clear_module_main_file_cache()` is clearing the plugin's cached path on
1958
+ * deactivation. Therefore, if any plugin/theme was initiating `Freemius`
1959
+ * with that plugin's slug, it was overriding the empty plugin path with a wrong path.
1960
+ *
1961
+ * So, we've added a special mechanism with a 2nd layer of cache that uses `prev_path`
1962
+ * when the class instantiator isn't the module.
1963
+ */
1964
+ if ( ! $is_init ) {
1965
+ // Fetch prev path cache.
1966
+ if ( isset( $this->_storage->plugin_main_file ) &&
1967
+ ! empty( $this->_storage->plugin_main_file->prev_path )
1968
+ ) {
1969
+ $absolute_path = $this->get_absolute_path( $this->_storage->plugin_main_file->prev_path );
1970
+ if ( file_exists( $absolute_path ) ) {
1971
+ return $absolute_path;
1972
+ }
1973
+ }
1974
+
1975
+ wp_die(
1976
+ $this->get_text_inline( 'Freemius SDK couldn\'t find the plugin\'s main file. Please contact sdk@freemius.com with the current error.', 'failed-finding-main-path' ) .
1977
+ " Module: {$this->_slug}; SDK: " . WP_FS__SDK_VERSION . ";",
1978
+ $this->get_text_inline( 'Error', 'error' ),
1979
+ array( 'back_link' => true )
1980
+ );
1981
+ }
1982
+
1983
+ /**
1984
+ * @since 1.2.1
1985
+ *
1986
+ * Only the original instantiator that calls dynamic_init can modify the module's path.
1987
+ */
1988
+ // Find caller module.
1989
+ $this->_storage->plugin_main_file = (object) array(
1990
+ 'path' => $main_file,
1991
+ );
1992
+
1993
+ return $this->get_absolute_path( $main_file );
1994
+ }
1995
+
1996
+ /**
1997
+ * @author Leo Fajardo (@leorw)
1998
+ * @since 1.2.3
1999
+ *
2000
+ * @param string $path
2001
+ *
2002
+ * @return string
2003
+ */
2004
+ private function get_relative_path( $path ) {
2005
+ $module_root_dir = $this->get_module_root_dir_path();
2006
+ if ( 0 === strpos( $path, $module_root_dir ) ) {
2007
+ $path = substr( $path, strlen( $module_root_dir ) );
2008
+ }
2009
+
2010
+ return $path;
2011
+ }
2012
+
2013
+ /**
2014
+ * @author Leo Fajardo (@leorw)
2015
+ * @since 1.2.3
2016
+ *
2017
+ * @param string $path
2018
+ * @param string|bool $module_type
2019
+ *
2020
+ * @return string
2021
+ */
2022
+ private function get_absolute_path( $path, $module_type = false ) {
2023
+ $module_root_dir = $this->get_module_root_dir_path( $module_type );
2024
+ if ( 0 !== strpos( $path, $module_root_dir ) ) {
2025
+ $path = fs_normalize_path( $module_root_dir . $path );
2026
+ }
2027
+
2028
+ return $path;
2029
+ }
2030
+
2031
+ /**
2032
+ * @author Leo Fajardo (@leorw)
2033
+ * @since 1.2.3
2034
+ *
2035
+ * @param string|bool $module_type
2036
+ *
2037
+ * @return string
2038
+ */
2039
+ private function get_module_root_dir_path( $module_type = false ) {
2040
+ $is_plugin = empty( $module_type ) ?
2041
+ $this->is_plugin() :
2042
+ ( WP_FS__MODULE_TYPE_PLUGIN === $module_type );
2043
+
2044
+ return fs_normalize_path( trailingslashit( $is_plugin ?
2045
+ WP_PLUGIN_DIR :
2046
+ get_theme_root( get_stylesheet() ) ) );
2047
+ }
2048
+
2049
+ /**
2050
+ * @author Leo Fajardo (@leorw)
2051
+ *
2052
+ * @param number $module_id
2053
+ * @param string $slug
2054
+ *
2055
+ * @return string Since 2.5.0 return the module's main file path.
2056
+ *
2057
+ * @since 1.2.2
2058
+ */
2059
+ private function store_id_slug_type_path_map( $module_id, $slug ) {
2060
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
2061
+
2062
+ $store_option = false;
2063
+
2064
+ if ( ! isset( $id_slug_type_path_map[ $module_id ] ) ) {
2065
+ $id_slug_type_path_map[ $module_id ] = array(
2066
+ 'slug' => $slug
2067
+ );
2068
+
2069
+ $store_option = true;
2070
+ } else if (
2071
+ isset( $id_slug_type_path_map[ $module_id ]['slug'] ) &&
2072
+ $slug !== $id_slug_type_path_map[ $module_id ]['slug']
2073
+ ) {
2074
+ $id_slug_type_path_map[ $module_id ]['slug'] = $slug;
2075
+ $store_option = true;
2076
+ }
2077
+
2078
+ $find_caller = empty( $id_slug_type_path_map[ $module_id ]['path'] );
2079
+
2080
+ if ( ! $find_caller ) {
2081
+ /**
2082
+ * This verification is for cases when suddenly the same module
2083
+ * is installed but with a different folder name.
2084
+ *
2085
+ * @author Vova Feldman (@svovaf)
2086
+ * @since 1.2.3
2087
+ */
2088
+ $find_caller = ! file_exists( $this->get_absolute_path(
2089
+ $id_slug_type_path_map[ $module_id ]['path'],
2090
+ $id_slug_type_path_map[ $module_id ]['type']
2091
+ ) );
2092
+ }
2093
+
2094
+ foreach ( $id_slug_type_path_map as $id => $data ) {
2095
+ if ( empty( $id ) ) {
2096
+ // Remove maps with empty module ID.
2097
+ unset( $id_slug_type_path_map[ $id ] );
2098
+ $store_option = true;
2099
+ continue;
2100
+ }
2101
+
2102
+ /**
2103
+ * If the module's main file path is identical to the main file path of another module then it means that the cached path of the current module or the other one with the same path is wrong, and therefore, we need to recalculate those paths.
2104
+ *
2105
+ * @author Vova Feldman (@svovaf)
2106
+ * @since 2.5.0
2107
+ */
2108
+ if ( ! $find_caller ) {
2109
+ if ( $id == $module_id ) {
2110
+ continue;
2111
+ }
2112
+
2113
+ if (
2114
+ isset( $data['path'] ) &&
2115
+ $data['path'] === $id_slug_type_path_map[ $module_id ]['path']
2116
+ ) {
2117
+ $find_caller = true;
2118
+ }
2119
+ }
2120
+ }
2121
+
2122
+ if ( $find_caller ) {
2123
+ $caller_main_file_and_type = $this->get_caller_main_file_and_type( $module_id );
2124
+
2125
+ $id_slug_type_path_map[ $module_id ]['type'] = $caller_main_file_and_type->module_type;
2126
+ $id_slug_type_path_map[ $module_id ]['path'] = $caller_main_file_and_type->path;
2127
+
2128
+ $store_option = true;
2129
+ }
2130
+
2131
+ if ( $store_option ) {
2132
+ self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
2133
+ }
2134
+
2135
+ return $id_slug_type_path_map[ $module_id ]['path'];
2136
+ }
2137
+
2138
+ /**
2139
+ * Identifies the caller type: plugin or theme.
2140
+ *
2141
+ * @author Leo Fajardo (@leorw)
2142
+ * @since 1.2.2
2143
+ *
2144
+ * @author Vova Feldman (@svovaf)
2145
+ * @since 1.2.2.3 Find the earliest module in the call stack that calls to the SDK. This fix is for cases when
2146
+ * add-ons are relying on loading the SDK from the parent module, and also allows themes including the
2147
+ * SDK an internal file instead of directly from functions.php.
2148
+ * @since 1.2.1.7 Knows how to handle cases when an add-on includes the parent module logic.
2149
+ *
2150
+ * @param number $module_id @since 2.5.0
2151
+ */
2152
+ private function get_caller_main_file_and_type( $module_id ) {
2153
+ self::require_plugin_essentials();
2154
+
2155
+ $all_plugins = fs_get_plugins( true );
2156
+ $all_plugins_paths = array();
2157
+
2158
+ // Get active plugin's main files real full names (might be symlinks).
2159
+ foreach ( $all_plugins as $relative_path => $data ) {
2160
+ if ( false === strpos( fs_normalize_path( $relative_path ), '/' ) ) {
2161
+ /**
2162
+ * Ignore plugins that don't have a folder (e.g. Hello Dolly) since they
2163
+ * can't really include the SDK.
2164
+ *
2165
+ * @author Vova Feldman
2166
+ * @since 1.2.1.7
2167
+ */
2168
+ continue;
2169
+ }
2170
+
2171
+ $all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
2172
+ }
2173
+
2174
+ $caller_file_candidate = false;
2175
+ $caller_map = array();
2176
+ $module_type = WP_FS__MODULE_TYPE_PLUGIN;
2177
+ $themes_dir = fs_normalize_path( get_theme_root( get_stylesheet() ) );
2178
+ $plugin_dir_to_skip = false;
2179
+
2180
+ for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
2181
+ if ( empty( $bt[ $i ]['file'] ) ) {
2182
+ continue;
2183
+ }
2184
+
2185
+ if ( $i > 1 && ! empty( $bt[ $i - 1 ]['file'] ) && $bt[ $i ]['file'] === $bt[ $i - 1 ]['file'] ) {
2186
+ // If file same as the prev file in the stack, skip it.
2187
+ continue;
2188
+ }
2189
+
2190
+ if ( ! empty( $bt[ $i ]['function'] ) && in_array( $bt[ $i ]['function'], array(
2191
+ 'do_action',
2192
+ 'apply_filter',
2193
+ // The string split is stupid, but otherwise, theme check
2194
+ // throws info notices.
2195
+ 'requir' . 'e_once',
2196
+ 'requir' . 'e',
2197
+ 'includ' . 'e_once',
2198
+ 'includ' . 'e',
2199
+ 'install_and_activate_plugin',
2200
+ 'try_activate_plugin',
2201
+ 'activate_plugin'
2202
+ ) )
2203
+ ) {
2204
+ if ( 'activate_plugin' === $bt[ $i ]['function'] ) {
2205
+ /**
2206
+ * Store the directory of the activator plugin so that any other file that starts with it
2207
+ * cannot be mistakenly chosen as a candidate caller file.
2208
+ *
2209
+ * @author Leo Fajardo
2210
+ *
2211
+ * @since 2.3.0
2212
+ */
2213
+ $caller_file_path = fs_normalize_path( $bt[ $i ]['file'] );
2214
+
2215
+ foreach ( $all_plugins_paths as $plugin_path ) {
2216
+ $plugin_dir = fs_normalize_path( dirname( $plugin_path ) . '/' );
2217
+ if ( false !== strpos( $caller_file_path, $plugin_dir ) ) {
2218
+ $plugin_dir_to_skip = $plugin_dir;
2219
+
2220
+ break;
2221
+ }
2222
+ }
2223
+ }
2224
+
2225
+ // Ignore call stack hooks and files inclusion.
2226
+ continue;
2227
+ }
2228
+
2229
+ $caller_file_path = fs_normalize_path( $bt[ $i ]['file'] );
2230
+
2231
+ if ( ! empty( $plugin_dir_to_skip ) ) {
2232
+ /**
2233
+ * Skip if it's an activator plugin file to avoid mistakenly choosing it as a candidate caller file.
2234
+ *
2235
+ * @author Leo Fajardo
2236
+ *
2237
+ * @since 2.3.0
2238
+ */
2239
+ if ( 0 === strpos( $caller_file_path, $plugin_dir_to_skip ) ) {
2240
+ continue;
2241
+ }
2242
+ }
2243
+
2244
+ if ( 'functions.php' === basename( $caller_file_path ) ) {
2245
+ /**
2246
+ * 1. Assumes that theme's starting execution file is functions.php.
2247
+ * 2. This complex logic fixes symlink issues (e.g. with Vargant).
2248
+ *
2249
+ * @author Vova Feldman (@svovaf)
2250
+ * @since 1.2.2.5
2251
+ */
2252
+
2253
+ if ( $caller_file_path == fs_normalize_path( realpath( trailingslashit( $themes_dir ) . basename( dirname( $caller_file_path ) ) . '/' . basename( $caller_file_path ) ) ) ) {
2254
+ $module_type = WP_FS__MODULE_TYPE_THEME;
2255
+
2256
+ /**
2257
+ * Relative path of the theme, e.g.:
2258
+ * `my-theme/functions.php`
2259
+ *
2260
+ * @author Leo Fajardo (@leorw)
2261
+ */
2262
+ $caller_file_candidate = basename( dirname( $caller_file_path ) ) .
2263
+ '/' .
2264
+ basename( $caller_file_path );
2265
+
2266
+ continue;
2267
+ }
2268
+ }
2269
+
2270
+ $caller_file_hash = md5( $caller_file_path );
2271
+
2272
+ if ( ! isset( $caller_map[ $caller_file_hash ] ) ) {
2273
+ foreach ( $all_plugins_paths as $plugin_path ) {
2274
+ if ( empty( $plugin_path ) ) {
2275
+ continue;
2276
+ }
2277
+
2278
+ if ( false !== strpos( $caller_file_path, fs_normalize_path( dirname( $plugin_path ) . '/' ) ) ) {
2279
+ $caller_map[ $caller_file_hash ] = fs_normalize_path( $plugin_path );
2280
+ break;
2281
+ }
2282
+ }
2283
+ }
2284
+
2285
+ if ( isset( $caller_map[ $caller_file_hash ] ) ) {
2286
+ $module_type = WP_FS__MODULE_TYPE_PLUGIN;
2287
+ $caller_file_candidate = plugin_basename( $caller_map[ $caller_file_hash ] );
2288
+ }
2289
+ }
2290
+
2291
+ $caller_main_file_and_type = (object) array(
2292
+ 'module_type' => $module_type,
2293
+ 'path' => $caller_file_candidate
2294
+ );
2295
+
2296
+ return apply_filters( "fs_{$module_id}_caller_main_file_and_type", $caller_main_file_and_type );
2297
+ }
2298
+
2299
+ #----------------------------------------------------------------------------------
2300
+ #region Deactivation Feedback Form
2301
+ #----------------------------------------------------------------------------------
2302
+
2303
+ /**
2304
+ * Displays a confirmation and feedback dialog box when the user clicks on the "Deactivate" link on the plugins
2305
+ * page.
2306
+ *
2307
+ * @author Vova Feldman (@svovaf)
2308
+ * @author Leo Fajardo (@leorw)
2309
+ *
2310
+ * @since 1.1.2
2311
+ */
2312
+ function _add_deactivation_feedback_dialog_box() {
2313
+ if (
2314
+ $this->is_clone() ||
2315
+ ( is_object( $this->_site ) && ! $this->is_registered() )
2316
+ ) {
2317
+ return;
2318
+ }
2319
+
2320
+ $subscription_cancellation_dialog_box_template_params = $this->apply_filters( 'show_deactivation_subscription_cancellation', true ) ?
2321
+ $this->_get_subscription_cancellation_dialog_box_template_params() :
2322
+ array();
2323
+
2324
+ /**
2325
+ * @since 2.3.0 Developers can optionally hide the deactivation feedback form using the 'show_deactivation_feedback_form' filter.
2326
+ */
2327
+ $show_deactivation_feedback_form = ! self::is_deactivation_snoozed();
2328
+ if ( $this->has_filter( 'show_deactivation_feedback_form' ) ) {
2329
+ $show_deactivation_feedback_form = $this->apply_filters( 'show_deactivation_feedback_form', true );
2330
+ } else if ( $this->is_addon() ) {
2331
+ /**
2332
+ * If the add-on's 'show_deactivation_feedback_form' is not set, try to inherit the value from the parent.
2333
+ */
2334
+ $show_deactivation_feedback_form = $this->get_parent_instance()->apply_filters( 'show_deactivation_feedback_form', true );
2335
+ }
2336
+
2337
+ $uninstall_confirmation_message = $this->apply_filters( 'uninstall_confirmation_message', '' );
2338
+
2339
+ if (
2340
+ empty( $subscription_cancellation_dialog_box_template_params ) &&
2341
+ ! $show_deactivation_feedback_form &&
2342
+ empty( $uninstall_confirmation_message )
2343
+ ) {
2344
+ return;
2345
+ }
2346
+
2347
+ $vars = array( 'id' => $this->_module_id );
2348
+
2349
+ if ( $show_deactivation_feedback_form ) {
2350
+ /* Check the type of user:
2351
+ * 1. Long-term (long-term)
2352
+ * 2. Non-registered and non-anonymous short-term (non-registered-and-non-anonymous-short-term).
2353
+ * 3. Short-term (short-term)
2354
+ */
2355
+ $is_long_term_user = true;
2356
+
2357
+ // Check if the site is at least 2 days old.
2358
+ $time_installed = $this->_storage->install_timestamp;
2359
+
2360
+ // Difference in seconds.
2361
+ $date_diff = time() - $time_installed;
2362
+
2363
+ // Convert seconds to days.
2364
+ $date_diff_days = floor( $date_diff / ( 60 * 60 * 24 ) );
2365
+
2366
+ if ( $date_diff_days < 2 ) {
2367
+ $is_long_term_user = false;
2368
+ }
2369
+
2370
+ $is_long_term_user = $this->apply_filters( 'is_long_term_user', $is_long_term_user );
2371
+
2372
+ if ( $is_long_term_user ) {
2373
+ $user_type = 'long-term';
2374
+ } else {
2375
+ if ( ! $this->is_registered() && ! $this->is_anonymous() ) {
2376
+ $user_type = 'non-registered-and-non-anonymous-short-term';
2377
+ } else {
2378
+ $user_type = 'short-term';
2379
+ }
2380
+ }
2381
+
2382
+ $uninstall_reasons = $this->_get_uninstall_reasons( $user_type );
2383
+
2384
+ $vars['reasons'] = $uninstall_reasons;
2385
+ }
2386
+
2387
+ $vars['subscription_cancellation_dialog_box_template_params'] = &$subscription_cancellation_dialog_box_template_params;
2388
+ $vars['show_deactivation_feedback_form'] = $show_deactivation_feedback_form;
2389
+ $vars['uninstall_confirmation_message'] = $uninstall_confirmation_message;
2390
+
2391
+ /**
2392
+ * Load the HTML template for the deactivation feedback dialog box.
2393
+ *
2394
+ * @todo Deactivation form core functions should be loaded only once! Otherwise, when there are multiple Freemius powered plugins the same code is loaded multiple times. The only thing that should be loaded differently is the various deactivation reasons object based on the state of the plugin.
2395
+ */
2396
+ fs_require_template( 'forms/deactivation/form.php', $vars );
2397
+ }
2398
+
2399
+ /**
2400
+ * @author Leo Fajardo (@leorw)
2401
+ * @since 1.1.2
2402
+ *
2403
+ * @param string $user_type
2404
+ *
2405
+ * @return array The uninstall reasons for the specified user type.
2406
+ */
2407
+ function _get_uninstall_reasons( $user_type = 'long-term' ) {
2408
+ $module_type = $this->_module_type;
2409
+
2410
+ $internal_message_template_var = array(
2411
+ 'id' => $this->_module_id
2412
+ );
2413
+
2414
+ $plan = $this->get_plan();
2415
+
2416
+ if ( $this->is_registered() && is_object( $plan ) && $plan->has_technical_support() ) {
2417
+ $contact_support_template = fs_get_template( 'forms/deactivation/contact.php', $internal_message_template_var );
2418
+ } else {
2419
+ $contact_support_template = '';
2420
+ }
2421
+
2422
+ $reason_found_better_plugin = array(
2423
+ 'id' => self::REASON_FOUND_A_BETTER_PLUGIN,
2424
+ 'text' => sprintf( $this->get_text_inline( 'I found a better %s', 'reason-found-a-better-plugin' ), $module_type ),
2425
+ 'input_type' => 'textfield',
2426
+ 'input_placeholder' => sprintf( $this->get_text_inline( "What's the %s's name?", 'placeholder-plugin-name' ), $module_type ),
2427
+ );
2428
+
2429
+ $reason_temporary_deactivation = array(
2430
+ 'id' => self::REASON_TEMPORARY_DEACTIVATION,
2431
+ 'text' => sprintf(
2432
+ $this->get_text_inline( "It's a temporary %s - I'm troubleshooting an issue", 'reason-temporary-x' ),
2433
+ strtolower( $this->is_plugin() ?
2434
+ $this->get_text_inline( 'Deactivation', 'deactivation' ) :
2435
+ $this->get_text_inline( 'Theme Switch', 'theme-switch' )
2436
+ )
2437
+ ),
2438
+ 'input_type' => '',
2439
+ 'input_placeholder' => ''
2440
+ );
2441
+
2442
+ $reason_other = array(
2443
+ 'id' => self::REASON_OTHER,
2444
+ 'text' => $this->get_text_inline( 'Other', 'reason-other' ),
2445
+ 'input_type' => 'textfield',
2446
+ 'input_placeholder' => ''
2447
+ );
2448
+
2449
+ $long_term_user_reasons = array(
2450
+ array(
2451
+ 'id' => self::REASON_NO_LONGER_NEEDED,
2452
+ 'text' => sprintf( $this->get_text_inline( 'I no longer need the %s', 'reason-no-longer-needed' ), $module_type ),
2453
+ 'input_type' => '',
2454
+ 'input_placeholder' => ''
2455
+ ),
2456
+ $reason_found_better_plugin,
2457
+ array(
2458
+ 'id' => self::REASON_NEEDED_FOR_A_SHORT_PERIOD,
2459
+ 'text' => sprintf( $this->get_text_inline( 'I only needed the %s for a short period', 'reason-needed-for-a-short-period' ), $module_type ),
2460
+ 'input_type' => '',
2461
+ 'input_placeholder' => ''
2462
+ ),
2463
+ array(
2464
+ 'id' => self::REASON_BROKE_MY_SITE,
2465
+ 'text' => sprintf( $this->get_text_inline( 'The %s broke my site', 'reason-broke-my-site' ), $module_type ),
2466
+ 'input_type' => '',
2467
+ 'input_placeholder' => '',
2468
+ 'internal_message' => $contact_support_template
2469
+ ),
2470
+ array(
2471
+ 'id' => self::REASON_SUDDENLY_STOPPED_WORKING,
2472
+ 'text' => sprintf( $this->get_text_inline( 'The %s suddenly stopped working', 'reason-suddenly-stopped-working' ), $module_type ),
2473
+ 'input_type' => '',
2474
+ 'input_placeholder' => '',
2475
+ 'internal_message' => $contact_support_template
2476
+ )
2477
+ );
2478
+
2479
+ if ( $this->is_paying() ) {
2480
+ $long_term_user_reasons[] = array(
2481
+ 'id' => self::REASON_CANT_PAY_ANYMORE,
2482
+ 'text' => $this->get_text_inline( "I can't pay for it anymore", 'reason-cant-pay-anymore' ),
2483
+ 'input_type' => 'textfield',
2484
+ 'input_placeholder' => $this->get_text_inline( 'What price would you feel comfortable paying?', 'placeholder-comfortable-price' )
2485
+ );
2486
+ }
2487
+
2488
+ $reason_dont_share_info = array(
2489
+ 'id' => self::REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION,
2490
+ 'text' => $this->get_text_inline( "I don't like to share my information with you", 'reason-dont-like-to-share-my-information' ),
2491
+ 'input_type' => '',
2492
+ 'input_placeholder' => ''
2493
+ );
2494
+
2495
+ /**
2496
+ * If the current user has selected the "don't share data" reason in the deactivation feedback modal, inform the
2497
+ * user by showing additional message that he doesn't have to share data and can just choose to skip the opt-in
2498
+ * (the Skip button is included in the message to show). This message will only be shown if anonymous mode is
2499
+ * enabled and the user's account is currently not in pending activation state (similar to the way the Skip
2500
+ * button in the opt-in form is shown/hidden).
2501
+ */
2502
+ if ( $this->is_enable_anonymous() && ! $this->is_pending_activation() ) {
2503
+ $reason_dont_share_info['internal_message'] = fs_get_template( 'forms/deactivation/retry-skip.php', $internal_message_template_var );
2504
+ }
2505
+
2506
+ $uninstall_reasons = array(
2507
+ 'long-term' => $long_term_user_reasons,
2508
+ 'non-registered-and-non-anonymous-short-term' => array(
2509
+ array(
2510
+ 'id' => self::REASON_DIDNT_WORK,
2511
+ 'text' => sprintf( $this->get_text_inline( "The %s didn't work", 'reason-didnt-work' ), $module_type ),
2512
+ 'input_type' => '',
2513
+ 'input_placeholder' => ''
2514
+ ),
2515
+ $reason_dont_share_info,
2516
+ $reason_found_better_plugin
2517
+ ),
2518
+ 'short-term' => array(
2519
+ array(
2520
+ 'id' => self::REASON_COULDNT_MAKE_IT_WORK,
2521
+ 'text' => $this->get_text_inline( "I couldn't understand how to make it work", 'reason-couldnt-make-it-work' ),
2522
+ 'input_type' => '',
2523
+ 'input_placeholder' => '',
2524
+ 'internal_message' => $contact_support_template
2525
+ ),
2526
+ $reason_found_better_plugin,
2527
+ array(
2528
+ 'id' => self::REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE,
2529
+ 'text' => sprintf( $this->get_text_inline( "The %s is great, but I need specific feature that you don't support", 'reason-great-but-need-specific-feature' ), $module_type ),
2530
+ 'input_type' => 'textarea',
2531
+ 'input_placeholder' => $this->get_text_inline( 'What feature?', 'placeholder-feature' )
2532
+ ),
2533
+ array(
2534
+ 'id' => self::REASON_NOT_WORKING,
2535
+ 'text' => sprintf( $this->get_text_inline( 'The %s is not working', 'reason-not-working' ), $module_type ),
2536
+ 'input_type' => 'textarea',
2537
+ 'input_placeholder' => $this->get_text_inline( "Kindly share what didn't work so we can fix it for future users...", 'placeholder-share-what-didnt-work' )
2538
+ ),
2539
+ array(
2540
+ 'id' => self::REASON_NOT_WHAT_I_WAS_LOOKING_FOR,
2541
+ 'text' => $this->get_text_inline( "It's not what I was looking for", 'reason-not-what-i-was-looking-for' ),
2542
+ 'input_type' => 'textarea',
2543
+ 'input_placeholder' => $this->get_text_inline( "What you've been looking for?", 'placeholder-what-youve-been-looking-for' )
2544
+ ),
2545
+ array(
2546
+ 'id' => self::REASON_DIDNT_WORK_AS_EXPECTED,
2547
+ 'text' => sprintf( $this->get_text_inline( "The %s didn't work as expected", 'reason-didnt-work-as-expected' ), $module_type ),
2548
+ 'input_type' => 'textarea',
2549
+ 'input_placeholder' => $this->get_text_inline( 'What did you expect?', 'placeholder-what-did-you-expect' )
2550
+ )
2551
+ )
2552
+ );
2553
+
2554
+ // Randomize the reasons for the current user type.
2555
+ shuffle( $uninstall_reasons[ $user_type ] );
2556
+
2557
+ // Keep the following reasons as the last items in the list.
2558
+ $uninstall_reasons[ $user_type ][] = $reason_temporary_deactivation;
2559
+ $uninstall_reasons[ $user_type ][] = $reason_other;
2560
+
2561
+ $uninstall_reasons = $this->apply_filters( 'uninstall_reasons', $uninstall_reasons );
2562
+
2563
+ return $uninstall_reasons[ $user_type ];
2564
+ }
2565
+
2566
+ /**
2567
+ * Called after the user has submitted his reason for deactivating the plugin.
2568
+ *
2569
+ * @author Leo Fajardo (@leorw)
2570
+ * @since 1.1.2
2571
+ */
2572
+ function _submit_uninstall_reason_action() {
2573
+ $this->_logger->entrance();
2574
+
2575
+ $this->check_ajax_referer( 'submit_uninstall_reason' );
2576
+
2577
+ $reason_id = fs_request_get( 'reason_id' );
2578
+
2579
+ // Check if the given reason ID is an unsigned integer.
2580
+ if ( ! ctype_digit( $reason_id ) ) {
2581
+ exit;
2582
+ }
2583
+
2584
+ $reason_info = trim( fs_request_get( 'reason_info', '' ) );
2585
+ if ( ! empty( $reason_info ) ) {
2586
+ $reason_info = substr( $reason_info, 0, 128 );
2587
+ }
2588
+
2589
+ $reason = (object) array(
2590
+ 'id' => $reason_id,
2591
+ 'info' => $reason_info,
2592
+ 'is_anonymous' => fs_request_get_bool( 'is_anonymous' )
2593
+ );
2594
+
2595
+ $this->_storage->store( 'uninstall_reason', $reason );
2596
+
2597
+ if ( self::REASON_TEMPORARY_DEACTIVATION == $reason->id ) {
2598
+ $snooze_period = fs_request_get( 'snooze_period' );
2599
+
2600
+ if ( is_numeric( $snooze_period ) && 0 < $snooze_period ) {
2601
+ self::snooze_deactivation_form( (int) $snooze_period );
2602
+ }
2603
+ }
2604
+
2605
+ /**
2606
+ * If the module type is "theme", trigger the uninstall event here (on theme deactivation) since themes do
2607
+ * not support uninstall hook.
2608
+ *
2609
+ * @author Leo Fajardo (@leorw)
2610
+ * @since 1.2.2
2611
+ */
2612
+ if ( $this->is_theme() ) {
2613
+ if ( $this->is_premium() && ! $this->has_active_valid_license() ) {
2614
+ FS_Plugin_Updater::instance( $this )->delete_update_data();
2615
+ }
2616
+
2617
+ $this->_uninstall_plugin_event( false );
2618
+ $this->remove_sdk_reference();
2619
+ }
2620
+
2621
+ // Print '1' for successful operation.
2622
+ echo 1;
2623
+ exit;
2624
+ }
2625
+
2626
+ #--------------------------------------------------------------------------------
2627
+ #region Deactivation Feedback Snoozing
2628
+ #--------------------------------------------------------------------------------
2629
+
2630
+ /**
2631
+ * @author Vova Feldman (@svovaf)
2632
+ * @since 2.4.3
2633
+ *
2634
+ * @param int $period
2635
+ *
2636
+ * @return bool True if the value was set, false otherwise.
2637
+ */
2638
+ private static function snooze_deactivation_form( $period ) {
2639
+ return ( 0 < $period && self::reset_deactivation_snoozing( $period ) );
2640
+ }
2641
+
2642
+ /**
2643
+ * Check if deactivation feedback form is snoozed.
2644
+ *
2645
+ * @author Vova Feldman (@svovaf)
2646
+ * @since 2.4.3
2647
+ *
2648
+ * @return bool
2649
+ */
2650
+ static function is_deactivation_snoozed() {
2651
+ $is_snoozed = ( ! is_multisite() || fs_is_network_admin() ) ?
2652
+ get_transient( 'fs_snooze_period' ) :
2653
+ get_site_transient( 'fs_snooze_period' );
2654
+
2655
+
2656
+ return ( 'true' === $is_snoozed );
2657
+ }
2658
+
2659
+ /**
2660
+ * Reset deactivation snoozing. When `$period` is `0` will stop deactivation snoozing by deleting the transients. Otherwise, will set the transients for the selected period.
2661
+ *
2662
+ * @param int $period Period in seconds.
2663
+ *
2664
+ * @author Vova Feldman (@svovaf)
2665
+ * @since 2.4.3
2666
+ */
2667
+ private static function reset_deactivation_snoozing( $period = 0 ) {
2668
+ $value = ( 0 === $period ) ? null : 'true';
2669
+
2670
+ if ( ! is_multisite() || fs_is_network_admin() ) {
2671
+ return set_transient( 'fs_snooze_period', $value, $period );
2672
+ } else {
2673
+ return set_site_transient( 'fs_snooze_period', $value, $period );
2674
+ }
2675
+ }
2676
+
2677
+ /**
2678
+ * The deactivation snooze expiration UNIX timestamp (in sec).
2679
+ *
2680
+ * @author Vova Feldman (@svovaf)
2681
+ * @since 2.4.3
2682
+ *
2683
+ * @return int
2684
+ */
2685
+ static function deactivation_snooze_expires_at() {
2686
+ return ( ! is_multisite() || fs_is_network_admin() ) ?
2687
+ (int) get_option( '_transient_timeout_fs_snooze_period' ) :
2688
+ (int) get_site_option( '_site_transient_timeout_fs_snooze_period' );
2689
+ }
2690
+
2691
+ #endregion
2692
+
2693
+ /**
2694
+ * @author Leo Fajardo (@leorw)
2695
+ * @since 2.1.4
2696
+ */
2697
+ function cancel_subscription_or_trial_ajax_action() {
2698
+ $this->_logger->entrance();
2699
+
2700
+ $this->check_ajax_referer( 'cancel_subscription_or_trial' );
2701
+
2702
+ $result = $this->cancel_subscription_or_trial( fs_request_get( 'plugin_id', $this->get_id() ), false );
2703
+
2704
+ if ( $this->is_api_error( $result ) ) {
2705
+ $this->shoot_ajax_failure( $result->error->message );
2706
+ }
2707
+
2708
+ $this->shoot_ajax_success();
2709
+ }
2710
+
2711
+ /**
2712
+ * @author Leo Fajardo (@leorw)
2713
+ * @since 2.1.4
2714
+ *
2715
+ * @param number $plugin_id
2716
+ *
2717
+ * @return object
2718
+ */
2719
+ private function cancel_subscription_or_trial( $plugin_id ) {
2720
+ $fs = null;
2721
+ if ( $plugin_id == $this->get_id() ) {
2722
+ $fs = $this;
2723
+ } else if ( $this->is_addon_activated( $plugin_id ) ) {
2724
+ $fs = self::get_instance_by_id( $plugin_id );
2725
+ }
2726
+
2727
+ $result = null;
2728
+
2729
+ if ( ! is_null( $fs ) ) {
2730
+ $result = $fs->is_paid_trial() ?
2731
+ $fs->_cancel_trial() :
2732
+ $fs->_downgrade_site();
2733
+ }
2734
+
2735
+ return $result;
2736
+ }
2737
+
2738
+ /**
2739
+ * @author Leo Fajardo (@leorw)
2740
+ * @since 2.0.2
2741
+ */
2742
+ function _delete_theme_update_data_action() {
2743
+ FS_Plugin_Updater::instance( $this )->delete_update_data();
2744
+ }
2745
+
2746
+ #endregion
2747
+
2748
+ #----------------------------------------------------------------------------------
2749
+ #region Instance
2750
+ #----------------------------------------------------------------------------------
2751
+
2752
+ /**
2753
+ * Main singleton instance.
2754
+ *
2755
+ * @author Vova Feldman (@svovaf)
2756
+ * @since 1.0.0
2757
+ *
2758
+ * @param number $module_id
2759
+ * @param string|bool $slug
2760
+ * @param bool $is_init Is initiation sequence.
2761
+ *
2762
+ * @return Freemius|false
2763
+ */
2764
+ static function instance( $module_id, $slug = false, $is_init = false ) {
2765
+ if ( empty( $module_id ) ) {
2766
+ return false;
2767
+ }
2768
+
2769
+ /**
2770
+ * Load the essential static data prior to initiating FS_Plugin_Manager since there's an essential MS network migration logic that needs to be executed prior to the initiation.
2771
+ */
2772
+ self::_load_required_static();
2773
+
2774
+ if ( ! is_numeric( $module_id ) ) {
2775
+ if ( ! $is_init && true === $slug ) {
2776
+ $is_init = true;
2777
+ }
2778
+
2779
+ $slug = $module_id;
2780
+
2781
+ $module = FS_Plugin_Manager::instance( $slug )->get();
2782
+
2783
+ if ( is_object( $module ) ) {
2784
+ $module_id = $module->id;
2785
+ }
2786
+ }
2787
+
2788
+ $key = 'm_' . $module_id;
2789
+
2790
+ if ( ! isset( self::$_instances[ $key ] ) ) {
2791
+ self::$_instances[ $key ] = new Freemius( $module_id, $slug, $is_init );
2792
+ }
2793
+
2794
+ return self::$_instances[ $key ];
2795
+ }
2796
+
2797
+ /**
2798
+ * @author Vova Feldman (@svovaf)
2799
+ * @since 1.0.6
2800
+ *
2801
+ * @param number $addon_id
2802
+ *
2803
+ * @return bool
2804
+ */
2805
+ private static function has_instance( $addon_id ) {
2806
+ return isset( self::$_instances[ 'm_' . $addon_id ] );
2807
+ }
2808
+
2809
+ /**
2810
+ * @author Leo Fajardo (@leorw)
2811
+ * @since 1.2.2
2812
+ *
2813
+ * @param string|number $id_or_slug
2814
+ * @param string $module_type
2815
+ *
2816
+ * @return number|false
2817
+ */
2818
+ private static function get_module_id( $id_or_slug, $module_type = WP_FS__MODULE_TYPE_PLUGIN ) {
2819
+ if ( is_numeric( $id_or_slug ) ) {
2820
+ return $id_or_slug;
2821
+ }
2822
+
2823
+ foreach ( self::$_instances as $instance ) {
2824
+ // Also check the module type since there can be a plugin and a theme with the same slug.
2825
+ if ( ( $module_type === $instance->get_module_type() ) && ( $id_or_slug === $instance->get_slug() ) ) {
2826
+ return $instance->get_id();
2827
+ }
2828
+ }
2829
+
2830
+ return false;
2831
+ }
2832
+
2833
+ /**
2834
+ * @author Vova Feldman (@svovaf)
2835
+ * @since 1.0.6
2836
+ *
2837
+ * @param number $id
2838
+ *
2839
+ * @return false|Freemius
2840
+ */
2841
+ static function get_instance_by_id( $id ) {
2842
+ return isset ( self::$_instances[ 'm_' . $id ] ) ?
2843
+ self::$_instances[ 'm_' . $id ] :
2844
+ false;
2845
+ }
2846
+
2847
+ /**
2848
+ *
2849
+ * @author Vova Feldman (@svovaf)
2850
+ * @since 1.0.1
2851
+ *
2852
+ * @param string $plugin_file
2853
+ * @param string $module_type
2854
+ *
2855
+ * @return false|Freemius
2856
+ */
2857
+ static function get_instance_by_file( $plugin_file, $module_type = WP_FS__MODULE_TYPE_PLUGIN ) {
2858
+ $slug = self::find_slug_by_basename( $plugin_file );
2859
+
2860
+ return ( false !== $slug ) ?
2861
+ self::instance( self::get_module_id( $slug, $module_type ) ) :
2862
+ false;
2863
+ }
2864
+
2865
+ /**
2866
+ * @author Vova Feldman (@svovaf)
2867
+ * @since 1.0.6
2868
+ *
2869
+ * @return false|Freemius
2870
+ */
2871
+ function get_parent_instance() {
2872
+ return self::get_instance_by_id( $this->_plugin->parent_plugin_id );
2873
+ }
2874
+
2875
+ /**
2876
+ * @author Vova Feldman (@svovaf)
2877
+ * @since 1.0.6
2878
+ *
2879
+ * @param string|number $id_or_slug
2880
+ *
2881
+ * @return false|Freemius
2882
+ */
2883
+ function get_addon_instance( $id_or_slug ) {
2884
+ $addon_id = self::get_module_id( $id_or_slug );
2885
+
2886
+ return self::instance( $addon_id );
2887
+ }
2888
+
2889
+ /**
2890
+ * @return Freemius[]
2891
+ */
2892
+ static function _get_all_instances() {
2893
+ return self::$_instances;
2894
+ }
2895
+
2896
+ #endregion ------------------------------------------------------------------
2897
+
2898
+ /**
2899
+ * @author Vova Feldman (@svovaf)
2900
+ * @since 1.0.6
2901
+ *
2902
+ * @return bool
2903
+ */
2904
+ function is_parent_plugin_installed() {
2905
+ $is_active = self::has_instance( $this->_plugin->parent_plugin_id );
2906
+
2907
+ if ( $is_active ) {
2908
+ return true;
2909
+ }
2910
+
2911
+ /**
2912
+ * Parent module might be a theme. If that's the case, the add-on's FS
2913
+ * instance will be loaded prior to the theme's FS instance, therefore,
2914
+ * we need to check if it's active with a "look ahead".
2915
+ *
2916
+ * @author Vova Feldman
2917
+ * @since 1.2.2.3
2918
+ */
2919
+ global $fs_active_plugins;
2920
+ if ( is_object( $fs_active_plugins ) && is_array( $fs_active_plugins->plugins ) ) {
2921
+ $active_theme = wp_get_theme();
2922
+
2923
+ foreach ( $fs_active_plugins->plugins as $sdk => $module ) {
2924
+ if ( WP_FS__MODULE_TYPE_THEME === $module->type ) {
2925
+ if ( $module->plugin_path == $active_theme->get_stylesheet() ) {
2926
+ // Parent module is a theme and it's currently active.
2927
+ return true;
2928
+ }
2929
+ }
2930
+ }
2931
+ }
2932
+
2933
+ return false;
2934
+ }
2935
+
2936
+ /**
2937
+ * Check if add-on parent plugin in activation mode.
2938
+ *
2939
+ * @author Vova Feldman (@svovaf)
2940
+ * @since 1.0.7
2941
+ *
2942
+ * @return bool
2943
+ */
2944
+ function is_parent_in_activation() {
2945
+ $parent_fs = $this->get_parent_instance();
2946
+ if ( ! is_object( $parent_fs ) ) {
2947
+ return false;
2948
+ }
2949
+
2950
+ return ( $parent_fs->is_activation_mode() );
2951
+ }
2952
+
2953
+ /**
2954
+ * Is plugin in activation mode.
2955
+ *
2956
+ * @author Vova Feldman (@svovaf)
2957
+ * @since 1.0.7
2958
+ *
2959
+ * @param bool $and_on
2960
+ *
2961
+ * @return bool
2962
+ */
2963
+ function is_activation_mode( $and_on = true ) {
2964
+ return fs_is_network_admin() ?
2965
+ $this->is_network_activation_mode( $and_on ) :
2966
+ $this->is_site_activation_mode( $and_on );
2967
+ }
2968
+
2969
+ /**
2970
+ * Is plugin in activation mode.
2971
+ *
2972
+ * @author Vova Feldman (@svovaf)
2973
+ * @since 1.0.7
2974
+ *
2975
+ * @param bool $and_on
2976
+ *
2977
+ * @return bool
2978
+ */
2979
+ function is_site_activation_mode( $and_on = true ) {
2980
+ return (
2981
+ ( $this->is_on() || ! $and_on ) &&
2982
+ (
2983
+ ( $this->is_premium() && true === $this->_storage->require_license_activation ) ||
2984
+ (
2985
+ ( ! $this->is_registered() ||
2986
+ ( $this->is_only_premium() && ! $this->has_features_enabled_license() ) ) &&
2987
+ ( ! $this->is_enable_anonymous() ||
2988
+ ( ! $this->is_anonymous() && ! $this->is_pending_activation() ) )
2989
+ )
2990
+ )
2991
+ );
2992
+ }
2993
+
2994
+ /**
2995
+ * Checks if the SDK in network activation mode.
2996
+ *
2997
+ * @author Leo Fajardo (@leorw)
2998
+ * @since 2.0.0
2999
+ *
3000
+ * @param bool $and_on
3001
+ *
3002
+ * @return bool
3003
+ */
3004
+ private function is_network_activation_mode( $and_on = true ) {
3005
+ if ( ! $this->_is_network_active ) {
3006
+ // Not network activated.
3007
+ return false;
3008
+ }
3009
+
3010
+ if ( $this->is_network_upgrade_mode() ) {
3011
+ // Special flag to enforce network activation mode to decide what to do with the sites that are not yet opted-in nor skipped.
3012
+ return true;
3013
+ }
3014
+
3015
+ if ( ! $this->is_site_activation_mode( $and_on ) ) {
3016
+ // Whether the context is single site or the network, if the plugin is no longer in activation mode then it is not in network activation mode as well.
3017
+ return false;
3018
+ }
3019
+
3020
+ if ( $this->is_network_delegated_connection() ) {
3021
+ // Super-admin delegated the connection to the site admins -> not activation mode.
3022
+ return false;
3023
+ }
3024
+
3025
+ if ( $this->is_network_anonymous() && true !== $this->_storage->require_license_activation ) {
3026
+ // Super-admin skipped the connection network wide -> not activation mode.
3027
+ return false;
3028
+ }
3029
+
3030
+ if ( $this->is_network_registered() ) {
3031
+ // Super-admin connected at least one site -> not activation mode.
3032
+ return false;
3033
+ }
3034
+
3035
+ return true;
3036
+ }
3037
+
3038
+ /**
3039
+ * Check if current page is the opt-in/pending-activation page.
3040
+ *
3041
+ * @author Vova Feldman (@svovaf)
3042
+ * @since 1.2.1.7
3043
+ *
3044
+ * @return bool
3045
+ */
3046
+ function is_activation_page() {
3047
+ if ( $this->_menu->is_activation_page( $this->show_opt_in_on_themes_page() ) ) {
3048
+ return true;
3049
+ }
3050
+
3051
+ if ( ! $this->is_activation_mode() ) {
3052
+ return false;
3053
+ }
3054
+
3055
+ // Check if current page is matching the activation page.
3056
+ return $this->is_matching_url( $this->get_activation_url() );
3057
+ }
3058
+
3059
+ /**
3060
+ * Check if URL path's are matching and that all querystring
3061
+ * arguments of the $sub_url exist in the $url with the same values.
3062
+ *
3063
+ * WARNING:
3064
+ * 1. This method doesn't check if the sub/domain are matching.
3065
+ * 2. Ignore case sensitivity.
3066
+ *
3067
+ * @author Vova Feldman (@svovaf)
3068
+ * @since 1.2.1.7
3069
+ *
3070
+ * @param string $sub_url
3071
+ * @param string $url If argument is not set, check if the sub_url matching the current's page URL.
3072
+ *
3073
+ * @return bool
3074
+ */
3075
+ private function is_matching_url( $sub_url, $url = '' ) {
3076
+ if ( empty( $url ) ) {
3077
+ $url = $_SERVER['REQUEST_URI'];
3078
+ }
3079
+
3080
+ $url = strtolower( $url );
3081
+ $sub_url = strtolower( $sub_url );
3082
+
3083
+ if ( parse_url( $sub_url, PHP_URL_PATH ) !== parse_url( $url, PHP_URL_PATH ) ) {
3084
+ // Different path - DO NOT OVERRIDE PAGE.
3085
+ return false;
3086
+ }
3087
+
3088
+ $url_params = array();
3089
+ parse_str( parse_url( $url, PHP_URL_QUERY ), $url_params );
3090
+
3091
+ $sub_url_params = array();
3092
+ parse_str( parse_url( $sub_url, PHP_URL_QUERY ), $sub_url_params );
3093
+
3094
+ foreach ( $sub_url_params as $key => $val ) {
3095
+ if ( ! isset( $url_params[ $key ] ) || $val != $url_params[ $key ] ) {
3096
+ // Not matching query string - DO NOT OVERRIDE PAGE.
3097
+ return false;
3098
+ }
3099
+ }
3100
+
3101
+ return true;
3102
+ }
3103
+
3104
+ /**
3105
+ * Get the basenames of all active plugins for specific blog. Including network activated plugins.
3106
+ *
3107
+ * @author Vova Feldman (@svovaf)
3108
+ * @since 2.0.0
3109
+ *
3110
+ * @param int $blog_id
3111
+ *
3112
+ * @return string[]
3113
+ */
3114
+ private static function get_active_plugins_basenames( $blog_id = 0 ) {
3115
+ if ( is_multisite() && $blog_id > 0 ) {
3116
+ $active_basenames = get_blog_option( $blog_id, 'active_plugins' );
3117
+ } else {
3118
+ $active_basenames = get_option( 'active_plugins' );
3119
+ }
3120
+
3121
+ if ( ! is_array( $active_basenames ) ) {
3122
+ $active_basenames = array();
3123
+ }
3124
+
3125
+ if ( is_multisite() ) {
3126
+ $network_active_basenames = get_site_option( 'active_sitewide_plugins' );
3127
+
3128
+ if ( is_array( $network_active_basenames ) && ! empty( $network_active_basenames ) ) {
3129
+ $active_basenames = array_merge( $active_basenames, array_keys( $network_active_basenames ) );
3130
+ }
3131
+ }
3132
+
3133
+ return $active_basenames;
3134
+ }
3135
+
3136
+ /**
3137
+ * @author Leo Fajardo (@leorw)
3138
+ * @since 2.3.0
3139
+ *
3140
+ * @param int $blog_id
3141
+ *
3142
+ * @return array
3143
+ */
3144
+ static function get_active_plugins_directories_map( $blog_id = 0 ) {
3145
+ $active_basenames = self::get_active_plugins_basenames( $blog_id );
3146
+
3147
+ $map = array();
3148
+
3149
+ foreach ( $active_basenames as $active_basename ) {
3150
+ $active_basename = fs_normalize_path( $active_basename );
3151
+
3152
+ if ( false === strpos( $active_basename, '/' ) ) {
3153
+ continue;
3154
+ }
3155
+
3156
+ $map[ dirname( $active_basename ) ] = true;
3157
+ }
3158
+
3159
+ return $map;
3160
+ }
3161
+
3162
+ /**
3163
+ * Get collection of all active plugins. Including network activated plugins.
3164
+ *
3165
+ * @author Vova Feldman (@svovaf)
3166
+ * @since 1.0.9
3167
+ *
3168
+ * @param int $blog_id Since 2.0.0
3169
+ *
3170
+ * @return array[string]array
3171
+ */
3172
+ private static function get_active_plugins( $blog_id = 0 ) {
3173
+ self::require_plugin_essentials();
3174
+
3175
+ $active_plugin = array();
3176
+ $all_plugins = fs_get_plugins();
3177
+ $active_plugins_basenames = self::get_active_plugins_basenames( $blog_id );
3178
+
3179
+ foreach ( $active_plugins_basenames as $plugin_basename ) {
3180
+ $active_plugin[ $plugin_basename ] = $all_plugins[ $plugin_basename ];
3181
+ }
3182
+
3183
+ return $active_plugin;
3184
+ }
3185
+
3186
+ /**
3187
+ * Get collection of all site active plugins for a specified blog.
3188
+ *
3189
+ * @author Vova Feldman (@svovaf)
3190
+ * @since 2.0.0
3191
+ *
3192
+ * @param int $blog_id
3193
+ *
3194
+ * @return array[string]array
3195
+ */
3196
+ private static function get_site_active_plugins( $blog_id = 0 ) {
3197
+ $active_basenames = ( is_multisite() && $blog_id > 0 ) ?
3198
+ get_blog_option( $blog_id, 'active_plugins' ) :
3199
+ get_option( 'active_plugins' );
3200
+
3201
+ $active = array();
3202
+
3203
+ if ( ! is_array( $active_basenames ) ) {
3204
+ return $active;
3205
+ }
3206
+
3207
+ foreach ( $active_basenames as $basename ) {
3208
+ $active[ $basename ] = array(
3209
+ 'is_active' => true,
3210
+ 'Version' => '1.0', // Dummy version.
3211
+ 'slug' => self::get_plugin_slug( $basename ),
3212
+ );
3213
+ }
3214
+
3215
+ return $active;
3216
+ }
3217
+
3218
+ /**
3219
+ * Get collection of all plugins with their activation status for a specified blog.
3220
+ *
3221
+ * @author Vova Feldman (@svovaf)
3222
+ * @since 1.1.8
3223
+ *
3224
+ * @param int $blog_id Since 2.0.0
3225
+ *
3226
+ * @return array Key is the plugin file path and the value is an array of the plugin data.
3227
+ */
3228
+ private static function get_all_plugins( $blog_id = 0 ) {
3229
+ self::require_plugin_essentials();
3230
+
3231
+ $all_plugins = fs_get_plugins();
3232
+
3233
+ $active_plugins_basenames = self::get_active_plugins_basenames( $blog_id );
3234
+
3235
+ foreach ( $all_plugins as $basename => &$data ) {
3236
+ // By default set to inactive (next foreach update the active plugins).
3237
+ $data['is_active'] = false;
3238
+ // Enrich with plugin slug.
3239
+ $data['slug'] = self::get_plugin_slug( $basename );
3240
+ }
3241
+
3242
+ // Flag active plugins.
3243
+ foreach ( $active_plugins_basenames as $basename ) {
3244
+ if ( isset( $all_plugins[ $basename ] ) ) {
3245
+ $all_plugins[ $basename ]['is_active'] = true;
3246
+ }
3247
+ }
3248
+
3249
+ return $all_plugins;
3250
+ }
3251
+
3252
+ /**
3253
+ * Get collection of all plugins and if they are network level activated.
3254
+ *
3255
+ * @author Vova Feldman (@svovaf)
3256
+ * @since 2.0.0
3257
+ *
3258
+ * @return array Key is the plugin basename and the value is an array of the plugin data.
3259
+ */
3260
+ private static function get_network_plugins() {
3261
+ self::require_plugin_essentials();
3262
+
3263
+ $all_plugins = fs_get_plugins();
3264
+
3265
+ $network_active_basenames = is_multisite() ?
3266
+ get_site_option( 'active_sitewide_plugins' ) :
3267
+ array();
3268
+
3269
+ foreach ( $all_plugins as $basename => &$data ) {
3270
+ // By default set to inactive (next foreach update the active plugins).
3271
+ $data['is_active'] = false;
3272
+ // Enrich with plugin slug.
3273
+ $data['slug'] = self::get_plugin_slug( $basename );
3274
+ }
3275
+
3276
+ // Flag active plugins.
3277
+ foreach ( $network_active_basenames as $basename ) {
3278
+ if ( isset( $all_plugins[ $basename ] ) ) {
3279
+ $all_plugins[ $basename ]['is_active'] = true;
3280
+ }
3281
+ }
3282
+
3283
+ return $all_plugins;
3284
+ }
3285
+
3286
+ /**
3287
+ * Cached result of get_site_transient( 'update_plugins' )
3288
+ *
3289
+ * @author Vova Feldman (@svovaf)
3290
+ * @since 1.1.8
3291
+ *
3292
+ * @var object
3293
+ */
3294
+ private static $_plugins_info;
3295
+
3296
+ /**
3297
+ * Helper function to get specified plugin's slug.
3298
+ *
3299
+ * @author Vova Feldman (@svovaf)
3300
+ * @since 1.1.8
3301
+ *
3302
+ * @param $basename
3303
+ *
3304
+ * @return string
3305
+ */
3306
+ private static function get_plugin_slug( $basename ) {
3307
+ if ( ! isset( self::$_plugins_info ) ) {
3308
+ self::$_plugins_info = get_site_transient( 'update_plugins' );
3309
+ }
3310
+
3311
+ $slug = '';
3312
+
3313
+ if ( is_object( self::$_plugins_info ) ) {
3314
+ if ( isset( self::$_plugins_info->no_update ) &&
3315
+ isset( self::$_plugins_info->no_update[ $basename ] ) &&
3316
+ ! empty( self::$_plugins_info->no_update[ $basename ]->slug )
3317
+ ) {
3318
+ $slug = self::$_plugins_info->no_update[ $basename ]->slug;
3319
+ } else if ( isset( self::$_plugins_info->response ) &&
3320
+ isset( self::$_plugins_info->response[ $basename ] ) &&
3321
+ ! empty( self::$_plugins_info->response[ $basename ]->slug )
3322
+ ) {
3323
+ $slug = self::$_plugins_info->response[ $basename ]->slug;
3324
+ }
3325
+ }
3326
+
3327
+ if ( empty( $slug ) ) {
3328
+ // Try to find slug from FS data.
3329
+ $slug = self::find_slug_by_basename( $basename );
3330
+ }
3331
+
3332
+ if ( empty( $slug ) ) {
3333
+ // Fallback to plugin's folder name.
3334
+ $slug = dirname( $basename );
3335
+ }
3336
+
3337
+ return $slug;
3338
+ }
3339
+
3340
+ private static $_statics_loaded = false;
3341
+
3342
+ /**
3343
+ * Load static resources.
3344
+ *
3345
+ * @author Vova Feldman (@svovaf)
3346
+ * @since 1.0.1
3347
+ */
3348
+ private static function _load_required_static() {
3349
+ if ( self::$_statics_loaded ) {
3350
+ return;
3351
+ }
3352
+
3353
+ self::$_static_logger = FS_Logger::get_logger( WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
3354
+
3355
+ self::$_static_logger->entrance();
3356
+
3357
+ self::$_accounts = FS_Options::instance( WP_FS__ACCOUNTS_OPTION_NAME, true );
3358
+
3359
+ if ( is_multisite() ) {
3360
+ $has_skipped_migration = (
3361
+ // 'id_slug_type_path_map' - was never stored on older versions, therefore, not exists on the site level.
3362
+ null === self::$_accounts->get_option( 'id_slug_type_path_map', null, false ) &&
3363
+ // 'file_slug_map' stored on the site level, so it was running an SDK version before it was integrated with MS-network.
3364
+ null !== self::$_accounts->get_option( 'file_slug_map', null, false )
3365
+ );
3366
+
3367
+ /**
3368
+ * If the file_slug_map exists on the site level but doesn't exist on the
3369
+ * network level storage, it means that we need to process the storage with migration.
3370
+ *
3371
+ * The code in this `if` scope will only be executed once and only for the first site that will execute it because once we migrate the storage data, file_slug_map will be already set in the network level storage.
3372
+ *
3373
+ * @author Vova Feldman (@svovaf)
3374
+ * @since 2.0.0
3375
+ */
3376
+ if (
3377
+ ( $has_skipped_migration && true !== self::$_accounts->get_option( 'ms_migration_complete', false, true ) ) ||
3378
+ ( null === self::$_accounts->get_option( 'file_slug_map', null, true ) &&
3379
+ null !== self::$_accounts->get_option( 'file_slug_map', null, false ) )
3380
+ ) {
3381
+ self::migrate_options_to_network();
3382
+ }
3383
+ }
3384
+
3385
+ self::$_global_admin_notices = FS_Admin_Notices::instance( 'global' );
3386
+
3387
+ if ( ! WP_FS__DEMO_MODE ) {
3388
+ add_action( ( fs_is_network_admin() ? 'network_' : '' ) . 'admin_menu', array(
3389
+ 'Freemius',
3390
+ '_add_debug_section'
3391
+ ) );
3392
+ }
3393
+
3394
+ add_action( "wp_ajax_fs_toggle_debug_mode", array( 'Freemius', '_toggle_debug_mode' ) );
3395
+
3396
+ self::add_ajax_action_static( 'get_debug_log', array( 'Freemius', '_get_debug_log' ) );
3397
+
3398
+ self::add_ajax_action_static( 'get_db_option', array( 'Freemius', '_get_db_option' ) );
3399
+
3400
+ self::add_ajax_action_static( 'set_db_option', array( 'Freemius', '_set_db_option' ) );
3401
+
3402
+ if ( 0 == did_action( 'plugins_loaded' ) ) {
3403
+ add_action( 'plugins_loaded', array( 'Freemius', '_load_textdomain' ), 1 );
3404
+ }
3405
+
3406
+ $clone_manager = FS_Clone_Manager::instance();
3407
+ add_action( 'init', array( $clone_manager, '_init' ) );
3408
+
3409
+ add_action( 'admin_footer', array( 'Freemius', '_open_support_forum_in_new_page' ) );
3410
+
3411
+ if ( self::is_plugins_page() || self::is_themes_page() ) {
3412
+ add_action( 'admin_print_footer_scripts', array( 'Freemius', '_maybe_add_beta_label_styles' ), 9 );
3413
+
3414
+ /**
3415
+ * Specifically use this hook so that the JS event handlers will work properly on the "Themes"
3416
+ * page.
3417
+ *
3418
+ * @author Leo Fajardo (@leorw)
3419
+ * @since 2.3.0
3420
+ */
3421
+ add_action( 'admin_footer-' . self::get_current_page(), array( 'Freemius', '_maybe_add_beta_label_to_plugins_and_handle_confirmation') );
3422
+ }
3423
+
3424
+ self::$_statics_loaded = true;
3425
+ }
3426
+
3427
+ #--------------------------------------------------------------------------------
3428
+ #region Clone
3429
+ #--------------------------------------------------------------------------------
3430
+
3431
+ /**
3432
+ * @author Leo Fajardo (@leorw)
3433
+ * @since 2.5.0
3434
+ *
3435
+ * @return bool
3436
+ */
3437
+ private function is_unresolved_clone() {
3438
+ if ( ! $this->is_clone() ) {
3439
+ return false;
3440
+ }
3441
+
3442
+ return FS_Clone_Manager::instance()->has_temporary_duplicate_mode_expired();
3443
+ }
3444
+
3445
+ /**
3446
+ * @author Leo Fajardo (@leorw)
3447
+ * @since 2.5.0
3448
+ */
3449
+ function is_clone() {
3450
+ if ( ! is_object( $this->_site ) ) {
3451
+ return false;
3452
+ }
3453
+
3454
+ $blog_id = null;
3455
+
3456
+ if (
3457
+ fs_is_network_admin() &&
3458
+ FS_Site::is_valid_id( $this->_storage->network_install_blog_id )
3459
+ ) {
3460
+ // Ensure that we're comparing the network install's URL with the relevant subsite's URL.
3461
+ $blog_id = $this->_storage->network_install_blog_id;
3462
+ }
3463
+
3464
+ return (
3465
+ trailingslashit( fs_strip_url_protocol( $this->_site->url ) ) !==
3466
+ self::get_unfiltered_site_url( $blog_id, true, true )
3467
+ );
3468
+ }
3469
+
3470
+ /**
3471
+ * @author Leo Fajardo (@leorw)
3472
+ * @since 2.5.0
3473
+ *
3474
+ * @param int|null $blog_id
3475
+ * @param bool $strip_protocol
3476
+ * @param bool $add_trailing_slash
3477
+ *
3478
+ * @return string
3479
+ */
3480
+ static function get_unfiltered_site_url( $blog_id = null, $strip_protocol = false, $add_trailing_slash = false ) {
3481
+ global $wp_filter;
3482
+
3483
+ $site_url_filters = array(
3484
+ 'site_url' => null,
3485
+ 'pre_option_siteurl' => null,
3486
+ 'default_option_siteurl' => null,
3487
+ 'option_siteurl' => null,
3488
+ );
3489
+
3490
+ // Detach all URL-related filters to get the actual site's URL (stripped of potential manipulations by multilingual plugins).
3491
+ foreach ( $site_url_filters as $hook_name => $site_url_filter ) {
3492
+ if ( ! empty( $wp_filter[ $hook_name ] ) ) {
3493
+ $site_url_filters[ $hook_name ] = $wp_filter[ $hook_name ];
3494
+ unset( $wp_filter[ $hook_name ] );
3495
+ }
3496
+ }
3497
+
3498
+ $url = get_site_url( $blog_id );
3499
+
3500
+ // Re-attach the filters back.
3501
+ foreach ( $site_url_filters as $hook_name => $site_url_filter ) {
3502
+ if ( ! empty( $site_url_filter ) ) {
3503
+ $wp_filter[ $hook_name ] = $site_url_filter;
3504
+ }
3505
+ }
3506
+
3507
+ if ( $strip_protocol ) {
3508
+ $url = fs_strip_url_protocol( $url );
3509
+ }
3510
+
3511
+ if ( $add_trailing_slash ) {
3512
+ $url = trailingslashit( $url );
3513
+ }
3514
+
3515
+ return $url;
3516
+ }
3517
+
3518
+ /**
3519
+ * @author Leo Fajardo (@leorw)
3520
+ * @since 2.5.0
3521
+ *
3522
+ * @param number $site_id
3523
+ */
3524
+ function fetch_install_by_id( $site_id ) {
3525
+ return $this->get_current_or_network_user_api_scope()->get( "/installs/{$site_id}.json" );
3526
+ }
3527
+
3528
+ /**
3529
+ * @author Leo Fajardo (@leorw)
3530
+ * @since 2.5.0
3531
+ *
3532
+ * @return string|object|bool
3533
+ */
3534
+ function _handle_long_term_duplicate() {
3535
+ $this->_logger->entrance();
3536
+
3537
+ $this->delete_current_install( false );
3538
+
3539
+ $license_key = false;
3540
+
3541
+ if (
3542
+ is_object( $this->_license ) &&
3543
+ ! $this->_license->is_utilized(
3544
+ ( WP_FS__IS_LOCALHOST_FOR_SERVER || FS_Site::is_localhost_by_address( self::get_unfiltered_site_url() ) )
3545
+ )
3546
+ ) {
3547
+ $license_key = $this->_license->secret_key;
3548
+ }
3549
+
3550
+ return $this->opt_in(
3551
+ false,
3552
+ false,
3553
+ false,
3554
+ $license_key,
3555
+ false,
3556
+ false,
3557
+ false,
3558
+ null,
3559
+ array(),
3560
+ false
3561
+ );
3562
+ }
3563
+
3564
+ #endregion
3565
+
3566
+ /**
3567
+ * @author Leo Fajardo (@leorw)
3568
+ *
3569
+ * @since 2.1.3
3570
+ */
3571
+ private static function migrate_options_to_network() {
3572
+ self::migrate_accounts_to_network();
3573
+
3574
+ // Migrate API options from site level to network level.
3575
+ $api_network_options = FS_Option_Manager::get_manager( WP_FS__OPTIONS_OPTION_NAME, true, true );
3576
+ $api_network_options->migrate_to_network();
3577
+
3578
+ // Migrate API cache to network level storage.
3579
+ FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME )->migrate_to_network();
3580
+
3581
+ self::$_accounts->set_option( 'ms_migration_complete', true, true );
3582
+ }
3583
+
3584
+ #----------------------------------------------------------------------------------
3585
+ #region Localization
3586
+ #----------------------------------------------------------------------------------
3587
+
3588
+ /**
3589
+ * Load framework's text domain.
3590
+ *
3591
+ * @author Vova Feldman (@svovaf)
3592
+ * @since 1.2.1
3593
+ */
3594
+ static function _load_textdomain() {
3595
+ if ( ! is_admin() ) {
3596
+ return;
3597
+ }
3598
+
3599
+ global $fs_active_plugins;
3600
+
3601
+ // Works both for plugins and themes.
3602
+ load_plugin_textdomain(
3603
+ 'freemius',
3604
+ false,
3605
+ $fs_active_plugins->newest->sdk_path . '/languages/'
3606
+ );
3607
+ }
3608
+
3609
+ #endregion
3610
+
3611
+ #----------------------------------------------------------------------------------
3612
+ #region Debugging
3613
+ #----------------------------------------------------------------------------------
3614
+
3615
+ /**
3616
+ * @author Vova Feldman (@svovaf)
3617
+ * @since 1.0.8
3618
+ */
3619
+ static function _add_debug_section() {
3620
+ if ( ! is_super_admin() ) {
3621
+ // Add debug page only for super-admins.
3622
+ return;
3623
+ }
3624
+
3625
+ self::$_static_logger->entrance();
3626
+
3627
+ $title = sprintf( '%s [v.%s]', fs_text_inline( 'Freemius Debug' ), WP_FS__SDK_VERSION );
3628
+
3629
+ if ( WP_FS__DEV_MODE ) {
3630
+ // Add top-level debug menu item.
3631
+ $hook = FS_Admin_Menu_Manager::add_page(
3632
+ $title,
3633
+ $title,
3634
+ 'manage_options',
3635
+ 'freemius',
3636
+ array( 'Freemius', '_debug_page_render' )
3637
+ );
3638
+ } else {
3639
+ // Add hidden debug page.
3640
+ $hook = FS_Admin_Menu_Manager::add_subpage(
3641
+ null,
3642
+ $title,
3643
+ $title,
3644
+ 'manage_options',
3645
+ 'freemius',
3646
+ array( 'Freemius', '_debug_page_render' )
3647
+ );
3648
+ }
3649
+
3650
+ if ( ! empty( $hook ) ) {
3651
+ add_action( "load-$hook", array( 'Freemius', '_debug_page_actions' ) );
3652
+ }
3653
+ }
3654
+
3655
+ /**
3656
+ * @author Vova Feldman (@svovaf)
3657
+ * @since 1.1.7.3
3658
+ */
3659
+ static function _toggle_debug_mode() {
3660
+ check_admin_referer( 'fs_toggle_debug_mode' );
3661
+
3662
+ if ( ! is_super_admin() ) {
3663
+ return;
3664
+ }
3665
+
3666
+ $is_on = fs_request_get( 'is_on', false, 'post' );
3667
+
3668
+ if ( fs_request_is_post() && in_array( $is_on, array( 0, 1 ) ) ) {
3669
+ update_option( 'fs_debug_mode', $is_on );
3670
+
3671
+ // Turn on/off storage logging.
3672
+ FS_Logger::_set_storage_logging( ( 1 == $is_on ) );
3673
+ }
3674
+
3675
+ exit;
3676
+ }
3677
+
3678
+ /**
3679
+ * @author Vova Feldman (@svovaf)
3680
+ * @since 1.2.1.6
3681
+ */
3682
+ static function _get_debug_log() {
3683
+ check_admin_referer( 'fs_get_debug_log' );
3684
+
3685
+ if ( ! is_super_admin() ) {
3686
+ return;
3687
+ }
3688
+
3689
+ $limit = min( ! empty( $_POST['limit'] ) ? absint( $_POST['limit'] ) : 200, 200 );
3690
+ $offset = min( ! empty( $_POST['offset'] ) ? absint( $_POST['offset'] ) : 200, 200 );
3691
+
3692
+ $logs = FS_Logger::load_db_logs(
3693
+ fs_request_get( 'filters', false, 'post' ),
3694
+ $limit,
3695
+ $offset
3696
+ );
3697
+
3698
+ self::shoot_ajax_success( $logs );
3699
+ }
3700
+
3701
+ /**
3702
+ * @author Vova Feldman (@svovaf)
3703
+ * @since 1.2.1.7
3704
+ */
3705
+ static function _get_db_option() {
3706
+ check_admin_referer( 'fs_get_db_option' );
3707
+
3708
+ $option_name = fs_request_get( 'option_name' );
3709
+
3710
+ if ( ! is_super_admin() ||
3711
+ ! fs_starts_with( $option_name, 'fs_' )
3712
+ ) {
3713
+ self::shoot_ajax_failure();
3714
+ }
3715
+
3716
+ $value = get_option( $option_name );
3717
+
3718
+ $result = array(
3719
+ 'name' => $option_name,
3720
+ );
3721
+
3722
+ if ( false !== $value ) {
3723
+ if ( ! is_string( $value ) ) {
3724
+ $value = json_encode( $value );
3725
+ }
3726
+
3727
+ $result['value'] = $value;
3728
+ }
3729
+
3730
+ self::shoot_ajax_success( $result );
3731
+ }
3732
+
3733
+ /**
3734
+ * @author Vova Feldman (@svovaf)
3735
+ * @since 1.2.1.7
3736
+ */
3737
+ static function _set_db_option() {
3738
+ check_admin_referer( 'fs_set_db_option' );
3739
+
3740
+ $option_name = fs_request_get( 'option_name' );
3741
+
3742
+ if ( ! is_super_admin() ||
3743
+ ! fs_starts_with( $option_name, 'fs_' )
3744
+ ) {
3745
+ self::shoot_ajax_failure();
3746
+ }
3747
+
3748
+ $option_value = fs_request_get( 'option_value' );
3749
+
3750
+ if ( ! empty( $option_value ) ) {
3751
+ update_option( $option_name, $option_value );
3752
+ }
3753
+
3754
+ self::shoot_ajax_success();
3755
+ }
3756
+
3757
+ /**
3758
+ * @author Vova Feldman (@svovaf)
3759
+ * @since 1.0.8
3760
+ */
3761
+ static function _debug_page_actions() {
3762
+ self::_clean_admin_content_section();
3763
+
3764
+ if ( fs_request_is_action( 'restart_freemius' ) ) {
3765
+ check_admin_referer( 'restart_freemius' );
3766
+
3767
+ if ( ! is_multisite() ) {
3768
+ // Clear accounts data.
3769
+ self::$_accounts->clear( null, true );
3770
+ } else {
3771
+ $sites = self::get_sites();
3772
+ foreach ( $sites as $site ) {
3773
+ $blog_id = self::get_site_blog_id( $site );
3774
+ self::$_accounts->clear( $blog_id, true );
3775
+ }
3776
+
3777
+ // Clear network level storage.
3778
+ self::$_accounts->clear( true, true );
3779
+ }
3780
+
3781
+ // Clear SDK reference cache.
3782
+ delete_option( 'fs_active_plugins' );
3783
+ } else if ( fs_request_is_action( 'clear_updates_data' ) ) {
3784
+ check_admin_referer( 'clear_updates_data' );
3785
+
3786
+ if ( ! is_multisite() ) {
3787
+ set_site_transient( 'update_plugins', null );
3788
+ set_site_transient( 'update_themes', null );
3789
+ } else {
3790
+ $current_blog_id = get_current_blog_id();
3791
+
3792
+ $sites = self::get_sites();
3793
+ foreach ( $sites as $site ) {
3794
+ switch_to_blog( self::get_site_blog_id( $site ) );
3795
+
3796
+ set_site_transient( 'update_plugins', null );
3797
+ set_site_transient( 'update_themes', null );
3798
+ }
3799
+
3800
+ switch_to_blog( $current_blog_id );
3801
+ }
3802
+ } else if ( fs_request_is_action( 'reset_deactivation_snoozing' ) ) {
3803
+ check_admin_referer( 'reset_deactivation_snoozing' );
3804
+
3805
+ self::reset_deactivation_snoozing();
3806
+ } else if ( fs_request_is_action( 'simulate_trial' ) ) {
3807
+ check_admin_referer( 'simulate_trial' );
3808
+
3809
+ $fs = freemius( fs_request_get( 'module_id' ) );
3810
+
3811
+ // Update SDK install to at least 24 hours before.
3812
+ $fs->_storage->install_timestamp = ( time() - WP_FS__TIME_24_HOURS_IN_SEC );
3813
+ // Unset the trial shown timestamp.
3814
+ unset( $fs->_storage->trial_promotion_shown );
3815
+ } else if ( fs_request_is_action( 'simulate_network_upgrade' ) ) {
3816
+ check_admin_referer( 'simulate_network_upgrade' );
3817
+
3818
+ $fs = freemius( fs_request_get( 'module_id' ) );
3819
+
3820
+ self::set_network_upgrade_mode( $fs->_storage );
3821
+ } else if ( fs_request_is_action( 'delete_install' ) ) {
3822
+ check_admin_referer( 'delete_install' );
3823
+
3824
+ self::_delete_site_by_slug(
3825
+ fs_request_get( 'slug' ),
3826
+ fs_request_get( 'module_type' ),
3827
+ true,
3828
+ fs_request_get( 'blog_id', null )
3829
+ );
3830
+ } else if ( fs_request_is_action( 'delete_user' ) ) {
3831
+ check_admin_referer( 'delete_user' );
3832
+
3833
+ self::delete_user( fs_request_get( 'user_id' ) );
3834
+ } else if ( fs_request_is_action( 'download_logs' ) ) {
3835
+ check_admin_referer( 'download_logs' );
3836
+
3837
+ $download_url = FS_Logger::download_db_logs(
3838
+ fs_request_get( 'filters', false, 'post' )
3839
+ );
3840
+
3841
+ if ( false === $download_url ) {
3842
+ wp_die( 'Oops... there was an error while generating the logs download file. Please try again and if it doesn\'t work contact support@freemius.com.' );
3843
+ }
3844
+
3845
+ fs_redirect( $download_url );
3846
+ } else if ( fs_request_is_action( 'migrate_options_to_network' ) ) {
3847
+ check_admin_referer( 'migrate_options_to_network' );
3848
+
3849
+ self::migrate_options_to_network();
3850
+ }
3851
+ }
3852
+
3853
+ /**
3854
+ * @author Leo Fajardo (@leorw)
3855
+ * @since 2.5.0
3856
+ *
3857
+ * @return array
3858
+ */
3859
+ static function get_all_modules_sites() {
3860
+ self::$_static_logger->entrance();
3861
+
3862
+ $sites_by_type = array(
3863
+ WP_FS__MODULE_TYPE_PLUGIN => array(),
3864
+ WP_FS__MODULE_TYPE_THEME => array(),
3865
+ );
3866
+
3867
+ $module_types = array_keys( $sites_by_type );
3868
+
3869
+ if ( ! is_multisite() ) {
3870
+ foreach ( $module_types as $type ) {
3871
+ $sites_by_type[ $type ] = self::get_all_sites( $type );
3872
+
3873
+ foreach ( $sites_by_type[ $type ] as $slug => $install ) {
3874
+ $sites_by_type[ $type ][ $slug ] = array( $install );
3875
+ }
3876
+ }
3877
+ } else {
3878
+ $sites = self::get_sites();
3879
+
3880
+ foreach ( $sites as $site ) {
3881
+ $blog_id = self::get_site_blog_id( $site );
3882
+
3883
+ foreach ( $module_types as $type ) {
3884
+ $installs = self::get_all_sites( $type, $blog_id );
3885
+
3886
+ foreach ( $installs as $slug => $install ) {
3887
+ if ( ! isset( $sites_by_type[ $type ][ $slug ] ) ) {
3888
+ $sites_by_type[ $type ][ $slug ] = array();
3889
+ }
3890
+
3891
+ $install->blog_id = $blog_id;
3892
+
3893
+ $sites_by_type[ $type ][ $slug ][] = $install;
3894
+ }
3895
+
3896
+ }
3897
+ }
3898
+ }
3899
+
3900
+ return $sites_by_type;
3901
+ }
3902
+
3903
+ /**
3904
+ * @author Vova Feldman (@svovaf)
3905
+ * @since 1.0.8
3906
+ */
3907
+ static function _debug_page_render() {
3908
+ self::$_static_logger->entrance();
3909
+
3910
+ $all_modules_sites = self::get_all_modules_sites();
3911
+
3912
+ $licenses_by_module_type = self::get_all_licenses_by_module_type();
3913
+
3914
+ $vars = array(
3915
+ 'plugin_sites' => $all_modules_sites[ WP_FS__MODULE_TYPE_PLUGIN ],
3916
+ 'theme_sites' => $all_modules_sites[ WP_FS__MODULE_TYPE_THEME ],
3917
+ 'users' => self::get_all_users(),
3918
+ 'addons' => self::get_all_addons(),
3919
+ 'account_addons' => self::get_all_account_addons(),
3920
+ 'plugin_licenses' => $licenses_by_module_type[ WP_FS__MODULE_TYPE_PLUGIN ],
3921
+ 'theme_licenses' => $licenses_by_module_type[ WP_FS__MODULE_TYPE_THEME ]
3922
+ );
3923
+
3924
+ fs_enqueue_local_style( 'fs_debug', '/admin/debug.css' );
3925
+ fs_require_once_template( 'debug.php', $vars );
3926
+ }
3927
+
3928
+ #endregion
3929
+
3930
+ #----------------------------------------------------------------------------------
3931
+ #region Connectivity Issues
3932
+ #----------------------------------------------------------------------------------
3933
+
3934
+ /**
3935
+ * Check if Freemius should be turned on for the current plugin install.
3936
+ *
3937
+ * Note:
3938
+ * $this->_is_on is updated in has_api_connectivity()
3939
+ *
3940
+ * @author Vova Feldman (@svovaf)
3941
+ * @since 1.0.9
3942
+ *
3943
+ * @return bool
3944
+ */
3945
+ function is_on() {
3946
+ self::$_static_logger->entrance();
3947
+
3948
+ if ( is_object( $this->_site ) && ! $this->is_registered() ) {
3949
+ return false;
3950
+ }
3951
+
3952
+ if ( isset( $this->_is_on ) ) {
3953
+ return $this->_is_on;
3954
+ }
3955
+
3956
+ // If already installed or pending then sure it's on :)
3957
+ if ( $this->is_registered() || $this->is_pending_activation() ) {
3958
+ $this->_is_on = true;
3959
+
3960
+ return true;
3961
+ }
3962
+
3963
+ return false;
3964
+ }
3965
+
3966
+ /**
3967
+ * @author Vova Feldman (@svovaf)
3968
+ * @since 1.1.7.3
3969
+ *
3970
+ * @param bool $flush_if_no_connectivity
3971
+ *
3972
+ * @return bool
3973
+ */
3974
+ private function should_run_connectivity_test( $flush_if_no_connectivity = false ) {
3975
+ if ( ! isset( $this->_storage->connectivity_test ) ) {
3976
+ // Connectivity test was never executed, or cache was cleared.
3977
+ return true;
3978
+ }
3979
+
3980
+ if ( WP_FS__PING_API_ON_IP_OR_HOST_CHANGES ) {
3981
+ if ( WP_FS__IS_HTTP_REQUEST ) {
3982
+ if ( $_SERVER['HTTP_HOST'] != $this->_storage->connectivity_test['host'] ) {
3983
+ // Domain changed.
3984
+ return true;
3985
+ }
3986
+
3987
+ if ( WP_FS__REMOTE_ADDR != $this->_storage->connectivity_test['server_ip'] ) {
3988
+ // Server IP changed.
3989
+ return true;
3990
+ }
3991
+ }
3992
+ }
3993
+
3994
+ if ( $this->_storage->connectivity_test['is_connected'] &&
3995
+ $this->_storage->connectivity_test['is_active']
3996
+ ) {
3997
+ // API connected and Freemius is active - no need to run connectivity check.
3998
+ return false;
3999
+ }
4000
+
4001
+ if ( $flush_if_no_connectivity ) {
4002
+ /**
4003
+ * If explicitly asked to flush when no connectivity - do it only
4004
+ * if at least 10 sec passed from the last API connectivity test.
4005
+ */
4006
+ return ( isset( $this->_storage->connectivity_test['timestamp'] ) &&
4007
+ ( WP_FS__SCRIPT_START_TIME - $this->_storage->connectivity_test['timestamp'] ) > 10 );
4008
+ }
4009
+
4010
+ /**
4011
+ * @since 1.1.7 Don't check for connectivity on plugin downgrade.
4012
+ */
4013
+ $version = $this->get_plugin_version();
4014
+ if ( version_compare( $version, $this->_storage->connectivity_test['version'], '>' ) ) {
4015
+ // If it's a plugin version upgrade and Freemius is off or no connectivity, run connectivity test.
4016
+ return true;
4017
+ }
4018
+
4019
+ return false;
4020
+ }
4021
+
4022
+ /**
4023
+ * @author Vova Feldman (@svovaf)
4024
+ * @since 1.1.7.4
4025
+ *
4026
+ * @param int|null $blog_id Since 2.0.0.
4027
+ * @param bool $is_gdpr_test Since 2.0.2. Perform only the GDPR test.
4028
+ *
4029
+ * @return object|false
4030
+ */
4031
+ private function ping( $blog_id = null, $is_gdpr_test = false ) {
4032
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY ) {
4033
+ return false;
4034
+ }
4035
+
4036
+ $version = $this->get_plugin_version();
4037
+
4038
+ $is_update = $this->apply_filters( 'is_plugin_update', $this->is_plugin_update() );
4039
+
4040
+ $params = array(
4041
+ 'is_update' => json_encode( $is_update ),
4042
+ 'version' => $version,
4043
+ 'sdk' => $this->version,
4044
+ 'is_admin' => json_encode( is_admin() ),
4045
+ 'is_ajax' => json_encode( self::is_ajax() ),
4046
+ 'is_cron' => json_encode( self::is_cron() ),
4047
+ 'is_gdpr_test' => $is_gdpr_test,
4048
+ 'is_http' => json_encode( WP_FS__IS_HTTP_REQUEST ),
4049
+ );
4050
+
4051
+ if ( is_multisite() && function_exists( 'get_network' ) ) {
4052
+ $params['network_uid'] = $this->get_anonymous_network_id();
4053
+ }
4054
+
4055
+ return $this->get_api_plugin_scope()->ping(
4056
+ $this->get_anonymous_id( $blog_id ),
4057
+ $params
4058
+ );
4059
+ }
4060
+
4061
+ /**
4062
+ * Check if there's any connectivity issue to Freemius API.
4063
+ *
4064
+ * @author Vova Feldman (@svovaf)
4065
+ * @since 1.0.9
4066
+ *
4067
+ * @param bool $flush_if_no_connectivity
4068
+ *
4069
+ * @return bool
4070
+ */
4071
+ function has_api_connectivity( $flush_if_no_connectivity = false ) {
4072
+ $this->_logger->entrance();
4073
+
4074
+ if ( isset( $this->_has_api_connection ) && ( $this->_has_api_connection || ! $flush_if_no_connectivity ) ) {
4075
+ return $this->_has_api_connection;
4076
+ }
4077
+
4078
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY &&
4079
+ isset( $this->_storage->connectivity_test ) &&
4080
+ true === $this->_storage->connectivity_test['is_connected']
4081
+ ) {
4082
+ unset( $this->_storage->connectivity_test );
4083
+ }
4084
+
4085
+ if ( ! $this->should_run_connectivity_test( $flush_if_no_connectivity ) ) {
4086
+ $this->_has_api_connection = $this->_storage->connectivity_test['is_connected'];
4087
+ /**
4088
+ * @since 1.1.6 During dev mode, if there's connectivity - turn Freemius on regardless the configuration.
4089
+ *
4090
+ * @since 1.2.1.5 If the user running the premium version then ignore the 'is_active' flag and turn Freemius on to enable license key activation.
4091
+ */
4092
+ $this->_is_on = $this->_storage->connectivity_test['is_active'] ||
4093
+ $this->is_premium() ||
4094
+ ( WP_FS__DEV_MODE && $this->_has_api_connection && ! WP_FS__SIMULATE_FREEMIUS_OFF );
4095
+
4096
+ return $this->_has_api_connection;
4097
+ }
4098
+
4099
+ $pong = $this->ping();
4100
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
4101
+
4102
+ if ( ! $is_connected ) {
4103
+ // API failure.
4104
+ $this->_add_connectivity_issue_message( $pong );
4105
+ }
4106
+
4107
+ if ( $is_connected ) {
4108
+ FS_GDPR_Manager::instance()->store_is_required( $pong->is_gdpr_required );
4109
+ }
4110
+
4111
+ $this->store_connectivity_info( $pong, $is_connected );
4112
+
4113
+ return $this->_has_api_connection;
4114
+ }
4115
+
4116
+ /**
4117
+ * @author Vova Feldman (@svovaf)
4118
+ * @since 1.1.7.4
4119
+ *
4120
+ * @param object $pong
4121
+ * @param bool $is_connected
4122
+ */
4123
+ private function store_connectivity_info( $pong, $is_connected ) {
4124
+ $this->_logger->entrance();
4125
+
4126
+ $version = $this->get_plugin_version();
4127
+
4128
+ if ( ! $is_connected || WP_FS__SIMULATE_FREEMIUS_OFF ) {
4129
+ $is_active = false;
4130
+ } else {
4131
+ $is_active = ( isset( $pong->is_active ) && true == $pong->is_active );
4132
+ }
4133
+
4134
+ $is_active = $this->apply_filters(
4135
+ 'is_on',
4136
+ $is_active,
4137
+ $this->is_plugin_update(),
4138
+ $version
4139
+ );
4140
+
4141
+ $this->_storage->connectivity_test = array(
4142
+ 'is_connected' => $is_connected,
4143
+ 'host' => $_SERVER['HTTP_HOST'],
4144
+ 'server_ip' => WP_FS__REMOTE_ADDR,
4145
+ 'is_active' => $is_active,
4146
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
4147
+ // Last version with connectivity attempt.
4148
+ 'version' => $version,
4149
+ );
4150
+
4151
+ $this->_has_api_connection = $is_connected;
4152
+ $this->_is_on = $is_active || ( WP_FS__DEV_MODE && $is_connected && ! WP_FS__SIMULATE_FREEMIUS_OFF );
4153
+ }
4154
+
4155
+ /**
4156
+ * Force turning Freemius on.
4157
+ *
4158
+ * @author Vova Feldman (@svovaf)
4159
+ * @since 1.1.8.1
4160
+ *
4161
+ * @return bool TRUE if successfully turned on.
4162
+ */
4163
+ private function turn_on() {
4164
+ $this->_logger->entrance();
4165
+
4166
+ if ( $this->is_on() || ! isset( $this->_storage->connectivity_test['is_active'] ) ) {
4167
+ return false;
4168
+ }
4169
+
4170
+ $updated_connectivity = $this->_storage->connectivity_test;
4171
+ $updated_connectivity['is_active'] = true;
4172
+ $updated_connectivity['timestamp'] = WP_FS__SCRIPT_START_TIME;
4173
+ $this->_storage->connectivity_test = $updated_connectivity;
4174
+
4175
+ $this->_is_on = true;
4176
+
4177
+ return true;
4178
+ }
4179
+
4180
+ /**
4181
+ * Anonymous and unique site identifier (Hash).
4182
+ *
4183
+ * @author Vova Feldman (@svovaf)
4184
+ * @since 1.1.0
4185
+ *
4186
+ * @param null|int $blog_id Since 2.0.0
4187
+ *
4188
+ * @return string
4189
+ */
4190
+ function get_anonymous_id( $blog_id = null ) {
4191
+ $unique_id = self::$_accounts->get_option( 'unique_id', null, $blog_id );
4192
+
4193
+ if ( empty( $unique_id ) || ! is_string( $unique_id ) ) {
4194
+ $key = self::get_unfiltered_site_url( $blog_id, true );
4195
+
4196
+ $secure_auth = defined( 'SECURE_AUTH_KEY' ) ? SECURE_AUTH_KEY : '';
4197
+ if ( empty( $secure_auth ) ||
4198
+ false !== strpos( $secure_auth, ' ' ) ||
4199
+ 'put your unique phrase here' === $secure_auth
4200
+ ) {
4201
+ // Protect against default auth key.
4202
+ $secure_auth = md5( microtime() );
4203
+ }
4204
+
4205
+ /**
4206
+ * Base the unique identifier on the WP secure authentication key. Which
4207
+ * turns the key into a secret anonymous identifier. This will help us
4208
+ * to avoid duplicate installs generation on the backend upon opt-in.
4209
+ *
4210
+ * @author Vova Feldman (@svovaf)
4211
+ * @since 1.2.3
4212
+ */
4213
+ $unique_id = md5( $key . $secure_auth );
4214
+
4215
+ self::$_accounts->set_option( 'unique_id', $unique_id, true, $blog_id );
4216
+ }
4217
+
4218
+ $this->_logger->departure( $unique_id );
4219
+
4220
+ return $unique_id;
4221
+ }
4222
+
4223
+ /**
4224
+ * Returns anonymous network ID.
4225
+ *
4226
+ * @since 2.4.3
4227
+ *
4228
+ * @return string
4229
+ */
4230
+ function get_anonymous_network_id() {
4231
+ return $this->get_anonymous_id( get_network()->site_id );
4232
+ }
4233
+
4234
+ /**
4235
+ * @author Vova Feldman (@svovaf)
4236
+ * @since 1.1.7.4
4237
+ *
4238
+ * @return \WP_User
4239
+ */
4240
+ static function _get_current_wp_user() {
4241
+ self::require_pluggable_essentials();
4242
+ self::wp_cookie_constants();
4243
+
4244
+ return wp_get_current_user();
4245
+ }
4246
+
4247
+ /**
4248
+ * Define cookie constants which are required by Freemius::_get_current_wp_user() since
4249
+ * it uses wp_get_current_user() which needs the cookie constants set. When a plugin
4250
+ * is network activated the cookie constants are only configured after the network
4251
+ * plugins activation, therefore, if we don't define those constants WP will throw
4252
+ * PHP warnings/notices.
4253
+ *
4254
+ * @author Vova Feldman (@svovaf)
4255
+ * @since 2.1.1
4256
+ */
4257
+ private static function wp_cookie_constants() {
4258
+ if ( defined( 'LOGGED_IN_COOKIE' ) &&
4259
+ ( defined( 'AUTH_COOKIE' ) || defined( 'SECURE_AUTH_COOKIE' ) )
4260
+ ) {
4261
+ return;
4262
+ }
4263
+
4264
+ /**
4265
+ * Used to guarantee unique hash cookies
4266
+ *
4267
+ * @since 1.5.0
4268
+ */
4269
+ if ( ! defined( 'COOKIEHASH' ) ) {
4270
+ $siteurl = get_site_option( 'siteurl' );
4271
+ if ( $siteurl ) {
4272
+ define( 'COOKIEHASH', md5( $siteurl ) );
4273
+ } else {
4274
+ define( 'COOKIEHASH', '' );
4275
+ }
4276
+ }
4277
+
4278
+ if ( ! defined( 'LOGGED_IN_COOKIE' ) ) {
4279
+ define( 'LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH );
4280
+ }
4281
+
4282
+ /**
4283
+ * @since 2.5.0
4284
+ */
4285
+ if ( ! defined( 'AUTH_COOKIE' ) ) {
4286
+ define( 'AUTH_COOKIE', 'wordpress_' . COOKIEHASH );
4287
+ }
4288
+
4289
+ /**
4290
+ * @since 2.6.0
4291
+ */
4292
+ if ( ! defined( 'SECURE_AUTH_COOKIE' ) ) {
4293
+ define( 'SECURE_AUTH_COOKIE', 'wordpress_sec_' . COOKIEHASH );
4294
+ }
4295
+ }
4296
+
4297
+ /**
4298
+ * @author Vova Feldman (@svovaf)
4299
+ * @since 2.1.0
4300
+ *
4301
+ * @return int
4302
+ */
4303
+ static function get_current_wp_user_id() {
4304
+ $wp_user = self::_get_current_wp_user();
4305
+
4306
+ return $wp_user->ID;
4307
+ }
4308
+
4309
+ /**
4310
+ * @author Vova Feldman (@svovaf)
4311
+ * @since 1.2.1.7
4312
+ *
4313
+ * @param string $email
4314
+ *
4315
+ * @return bool
4316
+ */
4317
+ static function is_valid_email( $email ) {
4318
+ if ( false === filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
4319
+ return false;
4320
+ }
4321
+
4322
+ $parts = explode( '@', $email );
4323
+
4324
+ if ( 2 !== count( $parts ) || empty( $parts[1] ) ) {
4325
+ return false;
4326
+ }
4327
+
4328
+ $blacklist = array(
4329
+ 'admin.',
4330
+ 'webmaster.',
4331
+ 'localhost.',
4332
+ 'dev.',
4333
+ 'development.',
4334
+ 'test.',
4335
+ 'stage.',
4336
+ 'staging.',
4337
+ );
4338
+
4339
+ // Make sure domain is not one of the blacklisted.
4340
+ foreach ( $blacklist as $invalid ) {
4341
+ if ( 0 === strpos( $parts[1], $invalid ) ) {
4342
+ return false;
4343
+ }
4344
+ }
4345
+
4346
+ // Get the UTF encoded domain name.
4347
+ $domain = idn_to_ascii( $parts[1] ) . '.';
4348
+
4349
+ return ( checkdnsrr( $domain, 'MX' ) || checkdnsrr( $domain, 'A' ) );
4350
+ }
4351
+
4352
+ /**
4353
+ * Generate API connectivity issue message.
4354
+ *
4355
+ * @author Vova Feldman (@svovaf)
4356
+ * @since 1.0.9
4357
+ *
4358
+ * @param mixed $api_result
4359
+ * @param bool $is_first_failure
4360
+ */
4361
+ function _add_connectivity_issue_message( $api_result, $is_first_failure = true ) {
4362
+ if ( ! $this->is_premium() && $this->_enable_anonymous ) {
4363
+ // Don't add message if it's the free version and can run anonymously.
4364
+ return;
4365
+ }
4366
+
4367
+ if ( ! function_exists( 'wp_nonce_url' ) ) {
4368
+ require_once ABSPATH . 'wp-includes/functions.php';
4369
+ }
4370
+
4371
+ $current_user = self::_get_current_wp_user();
4372
+ // $admin_email = get_option( 'admin_email' );
4373
+ $admin_email = $current_user->user_email;
4374
+
4375
+ // Aliases.
4376
+ $deactivate_plugin_title = $this->esc_html_inline( 'That\'s exhausting, please deactivate', 'deactivate-plugin-title' );
4377
+ $deactivate_plugin_desc = $this->esc_html_inline( 'We feel your frustration and sincerely apologize for the inconvenience. Hope to see you again in the future.', 'deactivate-plugin-desc' );
4378
+ $install_previous_title = $this->esc_html_inline( 'Let\'s try your previous version', 'install-previous-title' );
4379
+ $install_previous_desc = $this->esc_html_inline( 'Uninstall this version and install the previous one.', 'install-previous-desc' );
4380
+ $fix_issue_title = $this->esc_html_inline( 'Yes - I\'m giving you a chance to fix it', 'fix-issue-title' );
4381
+ $fix_issue_desc = $this->esc_html_inline( 'We will do our best to whitelist your server and resolve this issue ASAP. You will get a follow-up email to %s once we have an update.', 'fix-issue-desc' );
4382
+ /* translators: %s: product title (e.g. "Awesome Plugin" requires access to...) */
4383
+ $x_requires_access_to_api = $this->esc_html_inline( '%s requires access to our API.', 'x-requires-access-to-api' );
4384
+ $sysadmin_title = $this->esc_html_inline( 'I\'m a system administrator', 'sysadmin-title' );
4385
+ $happy_to_resolve_issue_asap = $this->esc_html_inline( 'We are sure it\'s an issue on our side and more than happy to resolve it for you ASAP if you give us a chance.', 'happy-to-resolve-issue-asap' );
4386
+
4387
+ if ( $this->is_premium() ) {
4388
+ /* translators: This string is optionally prepended to 'plugin requires access to our API.' */
4389
+ $x_requires_access_to_api = $this->esc_html_inline( 'For automatic delivery of security & feature updates,', 'requires-api-for' ) . ' ' . $x_requires_access_to_api;
4390
+ }
4391
+
4392
+ $message = false;
4393
+ if ( is_object( $api_result ) &&
4394
+ isset( $api_result->error ) &&
4395
+ isset( $api_result->error->code )
4396
+ ) {
4397
+ switch ( $api_result->error->code ) {
4398
+ case 'curl_missing':
4399
+ $missing_methods = '';
4400
+ if ( is_array( $api_result->missing_methods ) &&
4401
+ ! empty( $api_result->missing_methods )
4402
+ ) {
4403
+ foreach ( $api_result->missing_methods as $m ) {
4404
+ if ( 'curl_version' === $m ) {
4405
+ continue;
4406
+ }
4407
+
4408
+ if ( ! empty( $missing_methods ) ) {
4409
+ $missing_methods .= ', ';
4410
+ }
4411
+
4412
+ $missing_methods .= sprintf( '<code>%s</code>', $m );
4413
+ }
4414
+
4415
+ if ( ! empty( $missing_methods ) ) {
4416
+ $missing_methods = sprintf(
4417
+ '<br><br><b>%s</b> %s',
4418
+ $this->esc_html_inline( 'Disabled method(s):', 'curl-disabled-methods' ),
4419
+ $missing_methods
4420
+ );
4421
+ }
4422
+ }
4423
+
4424
+ $message = sprintf(
4425
+ $x_requires_access_to_api . ' ' .
4426
+ $this->esc_html_inline( 'We use PHP cURL library for the API calls, which is a very common library and usually installed and activated out of the box. Unfortunately, cURL is not activated (or disabled) on your server.', 'curl-missing-message' ) . ' ' .
4427
+ $missing_methods .
4428
+ ' %s',
4429
+ '<b>' . $this->get_plugin_name() . '</b>',
4430
+ sprintf(
4431
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
4432
+ sprintf(
4433
+ '<a class="fs-resolve" data-type="curl" href="#"><b>%s</b></a>%s',
4434
+ $this->get_text_inline( 'I don\'t know what is cURL or how to install it, help me!', 'curl-missing-no-clue-title' ),
4435
+ ' - ' . sprintf(
4436
+ $this->get_text_inline( 'We\'ll make sure to contact your hosting company and resolve the issue. You will get a follow-up email to %s once we have an update.', 'curl-missing-no-clue-desc' ),
4437
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
4438
+ )
4439
+ ),
4440
+ sprintf(
4441
+ '<b>%s</b> - %s',
4442
+ $sysadmin_title,
4443
+ esc_html( sprintf( $this->get_text_inline( 'Great, please install cURL and enable it in your php.ini file. In addition, search for the \'disable_functions\' directive in your php.ini file and remove any disabled methods starting with \'curl_\'. To make sure it was successfully activated, use \'phpinfo()\'. Once activated, deactivate the %s and reactivate it back again.', 'curl-missing-sysadmin-desc' ), $this->get_module_label( true ) ) )
4444
+ ),
4445
+ sprintf(
4446
+ '<a href="%s"><b>%s</b></a> - %s',
4447
+ wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=all&amp;paged=1&amp;s=', 'deactivate-plugin_' . $this->_plugin_basename ),
4448
+ $deactivate_plugin_title,
4449
+ $deactivate_plugin_desc
4450
+ )
4451
+ )
4452
+ );
4453
+ break;
4454
+ case 'cloudflare_ddos_protection':
4455
+ $message = sprintf(
4456
+ $x_requires_access_to_api . ' ' .
4457
+ $this->esc_html_inline( 'From unknown reason, CloudFlare, the firewall we use, blocks the connection.', 'cloudflare-blocks-connection-message' ) . ' ' .
4458
+ $happy_to_resolve_issue_asap .
4459
+ ' %s',
4460
+ '<b>' . $this->get_plugin_name() . '</b>',
4461
+ sprintf(
4462
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
4463
+ sprintf(
4464
+ '<a class="fs-resolve" data-type="cloudflare" href="#"><b>%s</b></a>%s',
4465
+ $fix_issue_title,
4466
+ ' - ' . sprintf(
4467
+ $fix_issue_desc,
4468
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
4469
+ )
4470
+ ),
4471
+ sprintf(
4472
+ '<a href="%s" target="_blank" rel="noopener noreferrer"><b>%s</b></a> - %s',
4473
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
4474
+ $install_previous_title,
4475
+ $install_previous_desc
4476
+ ),
4477
+ sprintf(
4478
+ '<a href="%s"><b>%s</b></a> - %s',
4479
+ wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=all&amp;paged=1&amp;s=' . '', 'deactivate-plugin_' . $this->_plugin_basename ),
4480
+ $deactivate_plugin_title,
4481
+ $deactivate_plugin_desc
4482
+ )
4483
+ )
4484
+ );
4485
+ break;
4486
+ case 'squid_cache_block':
4487
+ $message = sprintf(
4488
+ $x_requires_access_to_api . ' ' .
4489
+ $this->esc_html_inline( 'It looks like your server is using Squid ACL (access control lists), which blocks the connection.', 'squid-blocks-connection-message' ) .
4490
+ ' %s',
4491
+ '<b>' . $this->get_plugin_name() . '</b>',
4492
+ sprintf(
4493
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
4494
+ sprintf(
4495
+ '<a class="fs-resolve" data-type="squid" href="#"><b>%s</b></a> - %s',
4496
+ $this->esc_html_inline( 'I don\'t know what is Squid or ACL, help me!', 'squid-no-clue-title' ),
4497
+ sprintf(
4498
+ $this->esc_html_inline( 'We\'ll make sure to contact your hosting company and resolve the issue. You will get a follow-up email to %s once we have an update.', 'squid-no-clue-desc' ),
4499
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
4500
+ )
4501
+ ),
4502
+ sprintf(
4503
+ '<b>%s</b> - %s',
4504
+ $sysadmin_title,
4505
+ sprintf(
4506
+ $this->esc_html_inline( 'Great, please whitelist the following domains: %s. Once you are done, deactivate the %s and activate it again.', 'squid-sysadmin-desc' ),
4507
+ // We use a filter since the plugin might require additional API connectivity.
4508
+ '<b>' . implode( ', ', $this->apply_filters( 'api_domains', array(
4509
+ 'api.freemius.com',
4510
+ 'wp.freemius.com'
4511
+ ) ) ) . '</b>',
4512
+ $this->_module_type
4513
+ )
4514
+ ),
4515
+ sprintf(
4516
+ '<a href="%s"><b>%s</b></a> - %s',
4517
+ wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=all&amp;paged=1&amp;s=', 'deactivate-plugin_' . $this->_plugin_basename ),
4518
+ $deactivate_plugin_title,
4519
+ $deactivate_plugin_desc
4520
+ )
4521
+ )
4522
+ );
4523
+ break;
4524
+ // default:
4525
+ // $message = $this->get_text_inline( 'connectivity-test-fails-message' );
4526
+ // break;
4527
+ }
4528
+ }
4529
+
4530
+ $message_id = 'failed_connect_api';
4531
+ $type = 'error';
4532
+
4533
+ $connectivity_test_fails_message = $this->esc_html_inline( 'From unknown reason, the API connectivity test failed.', 'connectivity-test-fails-message' );
4534
+
4535
+ if ( false === $message ) {
4536
+ if ( $is_first_failure ) {
4537
+ // First attempt failed.
4538
+ $message = sprintf(
4539
+ $x_requires_access_to_api . ' ' .
4540
+ $connectivity_test_fails_message . ' ' .
4541
+ $this->esc_html_inline( 'It\'s probably a temporary issue on our end. Just to be sure, with your permission, would it be o.k to run another connectivity test?', 'connectivity-test-maybe-temporary' ) . '<br><br>' .
4542
+ '%s',
4543
+ '<b>' . $this->get_plugin_name() . '</b>',
4544
+ sprintf(
4545
+ '<div id="fs_firewall_issue_options">%s %s</div>',
4546
+ sprintf(
4547
+ '<a class="button button-primary fs-resolve" data-type="retry_ping" href="#">%s</a>',
4548
+ $this->get_text_inline( 'Yes - do your thing', 'yes-do-your-thing' )
4549
+ ),
4550
+ sprintf(
4551
+ '<a href="%s" class="button">%s</a>',
4552
+ wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=all&amp;paged=1&amp;s=', 'deactivate-plugin_' . $this->_plugin_basename ),
4553
+ $this->get_text_inline( 'No - just deactivate', 'no-deactivate' )
4554
+ )
4555
+ )
4556
+ );
4557
+
4558
+ $message_id = 'failed_connect_api_first';
4559
+ $type = 'promotion';
4560
+ } else {
4561
+ // Second connectivity attempt failed.
4562
+ $message = sprintf(
4563
+ $x_requires_access_to_api . ' ' .
4564
+ $connectivity_test_fails_message . ' ' .
4565
+ $happy_to_resolve_issue_asap .
4566
+ ' %s',
4567
+ '<b>' . $this->get_plugin_name() . '</b>',
4568
+ sprintf(
4569
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
4570
+ sprintf(
4571
+ '<a class="fs-resolve" data-type="general" href="#"><b>%s</b></a>%s',
4572
+ $fix_issue_title,
4573
+ ' - ' . sprintf(
4574
+ $fix_issue_desc,
4575
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
4576
+ )
4577
+ ),
4578
+ sprintf(
4579
+ '<a href="%s" target="_blank" rel="noopener noreferrer"><b>%s</b></a> - %s',
4580
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
4581
+ $install_previous_title,
4582
+ $install_previous_desc
4583
+ ),
4584
+ sprintf(
4585
+ '<a href="%s"><b>%s</b></a> - %s',
4586
+ wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=all&amp;paged=1&amp;s=', 'deactivate-plugin_' . $this->_plugin_basename ),
4587
+ $deactivate_plugin_title,
4588
+ $deactivate_plugin_desc
4589
+ )
4590
+ )
4591
+ );
4592
+ }
4593
+ }
4594
+
4595
+ $this->_admin_notices->add_sticky(
4596
+ $message,
4597
+ $message_id,
4598
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
4599
+ $type
4600
+ );
4601
+ }
4602
+
4603
+ /**
4604
+ * Handle user request to resolve connectivity issue.
4605
+ * This method will send an email to Freemius API technical staff for resolution.
4606
+ * The email will contain server's info and installed plugins (might be caching issue).
4607
+ *
4608
+ * @author Vova Feldman (@svovaf)
4609
+ * @since 1.0.9
4610
+ */
4611
+ function _email_about_firewall_issue() {
4612
+ check_admin_referer( 'fs_resolve_firewall_issues' );
4613
+
4614
+ if ( ! current_user_can( is_multisite() ? 'manage_options' : 'activate_plugins' ) ) {
4615
+ return;
4616
+ }
4617
+
4618
+ $this->_admin_notices->remove_sticky( 'failed_connect_api' );
4619
+
4620
+ $pong = $this->ping();
4621
+
4622
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
4623
+
4624
+ if ( $is_connected ) {
4625
+ FS_GDPR_Manager::instance()->store_is_required( $pong->is_gdpr_required );
4626
+
4627
+ $this->store_connectivity_info( $pong, $is_connected );
4628
+
4629
+ echo $this->get_after_plugin_activation_redirect_url();
4630
+ exit;
4631
+ }
4632
+
4633
+ $current_user = self::_get_current_wp_user();
4634
+ $admin_email = $current_user->user_email;
4635
+
4636
+ $error_type = fs_request_get( 'error_type', 'general' );
4637
+
4638
+ switch ( $error_type ) {
4639
+ case 'squid':
4640
+ $title = 'Squid ACL Blocking Issue';
4641
+ break;
4642
+ case 'cloudflare':
4643
+ $title = 'CloudFlare Blocking Issue';
4644
+ break;
4645
+ default:
4646
+ $title = 'API Connectivity Issue';
4647
+ break;
4648
+ }
4649
+
4650
+ $custom_email_sections = array();
4651
+
4652
+ // Add 'API Error' custom email section.
4653
+ $custom_email_sections['api_error'] = array(
4654
+ 'title' => 'API Error',
4655
+ 'rows' => array(
4656
+ 'ping' => array(
4657
+ 'API Error',
4658
+ is_string( $pong ) ? htmlentities( $pong ) : json_encode( $pong )
4659
+ ),
4660
+ )
4661
+ );
4662
+
4663
+ // Send email with technical details to resolve API connectivity issues.
4664
+ $this->send_email(
4665
+ 'api@freemius.com', // recipient
4666
+ $title . ' [' . $this->get_plugin_name() . ']', // subject
4667
+ $custom_email_sections,
4668
+ array( "Reply-To: $admin_email <$admin_email>" ) // headers
4669
+ );
4670
+
4671
+ $this->_admin_notices->add_sticky(
4672
+ sprintf(
4673
+ $this->get_text_inline( 'Thank for giving us the chance to fix it! A message was just sent to our technical staff. We will get back to you as soon as we have an update to %s. Appreciate your patience.', 'fix-request-sent-message' ),
4674
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
4675
+ ),
4676
+ 'server_details_sent'
4677
+ );
4678
+
4679
+ // Action was taken, tell that API connectivity troubleshooting should be off now.
4680
+
4681
+ echo "1";
4682
+ exit;
4683
+ }
4684
+
4685
+ /**
4686
+ * Handle connectivity test retry approved by the user.
4687
+ *
4688
+ * @author Vova Feldman (@svovaf)
4689
+ * @since 1.1.7.4
4690
+ */
4691
+ function _retry_connectivity_test() {
4692
+ check_admin_referer( 'fs_retry_connectivity_test' );
4693
+
4694
+ if ( ! current_user_can( is_multisite() ? 'manage_options' : 'activate_plugins' ) ) {
4695
+ return;
4696
+ }
4697
+
4698
+ $this->_admin_notices->remove_sticky( 'failed_connect_api_first' );
4699
+
4700
+ $pong = $this->ping();
4701
+
4702
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
4703
+
4704
+ if ( $is_connected ) {
4705
+ FS_GDPR_Manager::instance()->store_is_required( $pong->is_gdpr_required );
4706
+
4707
+ $this->store_connectivity_info( $pong, $is_connected );
4708
+
4709
+ echo $this->get_after_plugin_activation_redirect_url();
4710
+ } else {
4711
+ // Add connectivity issue message after 2nd failed attempt.
4712
+ $this->_add_connectivity_issue_message( $pong, false );
4713
+
4714
+ echo "1";
4715
+ }
4716
+
4717
+ exit;
4718
+ }
4719
+
4720
+ static function _add_firewall_issues_javascript() {
4721
+ $params = array();
4722
+ fs_require_once_template( 'firewall-issues-js.php', $params );
4723
+ }
4724
+
4725
+ #endregion
4726
+
4727
+ #----------------------------------------------------------------------------------
4728
+ #region Email
4729
+ #----------------------------------------------------------------------------------
4730
+
4731
+ /**
4732
+ * Generates and sends an HTML email with customizable sections.
4733
+ *
4734
+ * @author Leo Fajardo (@leorw)
4735
+ * @since 1.1.2
4736
+ *
4737
+ * @param string $to_address
4738
+ * @param string $subject
4739
+ * @param array $sections
4740
+ * @param array $headers
4741
+ *
4742
+ * @return bool Whether the email contents were sent successfully.
4743
+ */
4744
+ private function send_email(
4745
+ $to_address,
4746
+ $subject,
4747
+ $sections = array(),
4748
+ $headers = array()
4749
+ ) {
4750
+ $default_sections = $this->get_email_sections();
4751
+
4752
+ // Insert new sections or replace the default email sections.
4753
+ if ( is_array( $sections ) && ! empty( $sections ) ) {
4754
+ foreach ( $sections as $section_id => $custom_section ) {
4755
+ if ( ! isset( $default_sections[ $section_id ] ) ) {
4756
+ // If the section does not exist, add it.
4757
+ $default_sections[ $section_id ] = $custom_section;
4758
+ } else {
4759
+ // If the section already exists, override it.
4760
+ $current_section = $default_sections[ $section_id ];
4761
+
4762
+ // Replace the current section's title if a custom section title exists.
4763
+ if ( isset( $custom_section['title'] ) ) {
4764
+ $current_section['title'] = $custom_section['title'];
4765
+ }
4766
+
4767
+ // Insert new rows under the current section or replace the default rows.
4768
+ if ( isset( $custom_section['rows'] ) && is_array( $custom_section['rows'] ) && ! empty( $custom_section['rows'] ) ) {
4769
+ foreach ( $custom_section['rows'] as $row_id => $row ) {
4770
+ $current_section['rows'][ $row_id ] = $row;
4771
+ }
4772
+ }
4773
+
4774
+ $default_sections[ $section_id ] = $current_section;
4775
+ }
4776
+ }
4777
+ }
4778
+
4779
+ $vars = array( 'sections' => $default_sections );
4780
+ $message = fs_get_template( 'email.php', $vars );
4781
+
4782
+ // Set the type of email to HTML.
4783
+ $headers[] = 'Content-type: text/html; charset=UTF-8';
4784
+
4785
+ $header_string = implode( "\r\n", $headers );
4786
+
4787
+ return wp_mail(
4788
+ $to_address,
4789
+ $subject,
4790
+ $message,
4791
+ $header_string
4792
+ );
4793
+ }
4794
+
4795
+ /**
4796
+ * Generates the data for the sections of the email content.
4797
+ *
4798
+ * @author Leo Fajardo (@leorw)
4799
+ * @since 1.1.2
4800
+ *
4801
+ * @return array
4802
+ */
4803
+ private function get_email_sections() {
4804
+ // Retrieve the current user's information so that we can get the user's email, first name, and last name below.
4805
+ $current_user = self::_get_current_wp_user();
4806
+
4807
+ // Retrieve the cURL version information so that we can get the version number below.
4808
+ $curl_version_information = curl_version();
4809
+
4810
+ $active_plugin = self::get_active_plugins();
4811
+
4812
+ // Generate the list of active plugins separated by new line.
4813
+ $active_plugin_string = '';
4814
+ foreach ( $active_plugin as $plugin ) {
4815
+ $active_plugin_string .= sprintf(
4816
+ '<a href="%s">%s</a> [v%s]<br>',
4817
+ $plugin['PluginURI'],
4818
+ $plugin['Name'],
4819
+ $plugin['Version']
4820
+ );
4821
+ }
4822
+
4823
+ $server_ip = WP_FS__REMOTE_ADDR;
4824
+
4825
+ // Add PHP info for deeper investigation.
4826
+ ob_start();
4827
+ phpinfo();
4828
+ $php_info = ob_get_clean();
4829
+
4830
+ $api_domain = substr( FS_API__ADDRESS, strpos( FS_API__ADDRESS, ':' ) + 3 );
4831
+
4832
+ // Generate the default email sections.
4833
+ $sections = array(
4834
+ 'sdk' => array(
4835
+ 'title' => 'SDK',
4836
+ 'rows' => array(
4837
+ 'fs_version' => array( 'FS Version', $this->version ),
4838
+ 'curl_version' => array( 'cURL Version', $curl_version_information['version'] )
4839
+ )
4840
+ ),
4841
+ 'plugin' => array(
4842
+ 'title' => ucfirst( $this->get_module_type() ),
4843
+ 'rows' => array(
4844
+ 'name' => array( 'Name', $this->get_plugin_name() ),
4845
+ 'version' => array( 'Version', $this->get_plugin_version() )
4846
+ )
4847
+ ),
4848
+ 'api' => array(
4849
+ 'title' => 'API Subdomain',
4850
+ 'rows' => array(
4851
+ 'dns' => array(
4852
+ 'DNS_CNAME',
4853
+ function_exists( 'dns_get_record' ) ?
4854
+ var_export( dns_get_record( $api_domain, DNS_CNAME ), true ) :
4855
+ 'dns_get_record() disabled/blocked'
4856
+ ),
4857
+ 'ip' => array(
4858
+ 'IP',
4859
+ function_exists( 'gethostbyname' ) ?
4860
+ gethostbyname( $api_domain ) :
4861
+ 'gethostbyname() disabled/blocked'
4862
+ ),
4863
+ ),
4864
+ ),
4865
+ 'site' => array(
4866
+ 'title' => 'Site',
4867
+ 'rows' => array(
4868
+ 'unique_id' => array( 'Unique ID', $this->get_anonymous_id() ),
4869
+ 'address' => array( 'Address', site_url() ),
4870
+ 'host' => array(
4871
+ 'HTTP_HOST',
4872
+ ( ! empty( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '' )
4873
+ ),
4874
+ 'hosting' => array(
4875
+ 'Hosting Company' => fs_request_has( 'hosting_company' ) ?
4876
+ fs_request_get( 'hosting_company' ) :
4877
+ 'Unknown',
4878
+ ),
4879
+ 'server_addr' => array(
4880
+ 'SERVER_ADDR',
4881
+ '<a href="http://www.projecthoneypot.org/ip_' . $server_ip . '">' . $server_ip . '</a>'
4882
+ )
4883
+ )
4884
+ ),
4885
+ 'user' => array(
4886
+ 'title' => 'User',
4887
+ 'rows' => array(
4888
+ 'email' => array( 'Email', $current_user->user_email ),
4889
+ 'first' => array( 'First', $current_user->user_firstname ),
4890
+ 'last' => array( 'Last', $current_user->user_lastname )
4891
+ )
4892
+ ),
4893
+ 'plugins' => array(
4894
+ 'title' => 'Plugins',
4895
+ 'rows' => array(
4896
+ 'active_plugins' => array( 'Active Plugins', $active_plugin_string )
4897
+ )
4898
+ ),
4899
+ 'php_info' => array(
4900
+ 'title' => 'PHP Info',
4901
+ 'rows' => array(
4902
+ 'info' => array( $php_info )
4903
+ ),
4904
+ )
4905
+ );
4906
+
4907
+ // Allow the sections to be modified by other code.
4908
+ $sections = $this->apply_filters( 'email_template_sections', $sections );
4909
+
4910
+ return $sections;
4911
+ }
4912
+
4913
+ #endregion
4914
+
4915
+ #----------------------------------------------------------------------------------
4916
+ #region Initialization
4917
+ #----------------------------------------------------------------------------------
4918
+
4919
+ /**
4920
+ * Init plugin's Freemius instance.
4921
+ *
4922
+ * @author Vova Feldman (@svovaf)
4923
+ * @since 1.0.1
4924
+ *
4925
+ * @param number $id
4926
+ * @param string $public_key
4927
+ * @param bool $is_live
4928
+ * @param bool $is_premium
4929
+ */
4930
+ function init( $id, $public_key, $is_live = true, $is_premium = true ) {
4931
+ $this->_logger->entrance();
4932
+
4933
+ $this->dynamic_init( array(
4934
+ 'id' => $id,
4935
+ 'public_key' => $public_key,
4936
+ 'is_live' => $is_live,
4937
+ 'is_premium' => $is_premium,
4938
+ ) );
4939
+ }
4940
+
4941
+ /**
4942
+ * Dynamic initiator, originally created to support initiation
4943
+ * with parent_id for add-ons.
4944
+ *
4945
+ * @author Vova Feldman (@svovaf)
4946
+ * @since 1.0.6
4947
+ *
4948
+ * @param array $plugin_info
4949
+ *
4950
+ * @throws Freemius_Exception
4951
+ */
4952
+ function dynamic_init( array $plugin_info ) {
4953
+ $this->_logger->entrance();
4954
+
4955
+ $this->parse_settings( $plugin_info );
4956
+
4957
+ $this->register_after_settings_parse_hooks();
4958
+
4959
+ if ( $this->should_stop_execution() ) {
4960
+ return;
4961
+ }
4962
+
4963
+ if ( ! $this->is_registered() ) {
4964
+ if ( $this->is_anonymous() ) {
4965
+ // If user skipped, no need to test connectivity.
4966
+ $this->_has_api_connection = true;
4967
+ $this->_is_on = true;
4968
+ } else {
4969
+ if ( ! $this->has_api_connectivity() ) {
4970
+ if ( $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) ||
4971
+ $this->_admin_notices->has_sticky( 'failed_connect_api' )
4972
+ ) {
4973
+ if ( ! $this->_enable_anonymous || $this->is_premium() ) {
4974
+ // If anonymous mode is disabled, add firewall admin-notice message.
4975
+ add_action( 'admin_footer', array( 'Freemius', '_add_firewall_issues_javascript' ) );
4976
+
4977
+ $ajax_action_suffix = $this->_slug . ( $this->is_theme() ? ':theme' : '' );
4978
+ add_action( "wp_ajax_fs_resolve_firewall_issues_{$ajax_action_suffix}", array(
4979
+ &$this,
4980
+ '_email_about_firewall_issue'
4981
+ ) );
4982
+
4983
+ add_action( "wp_ajax_fs_retry_connectivity_test_{$ajax_action_suffix}", array(
4984
+ &$this,
4985
+ '_retry_connectivity_test'
4986
+ ) );
4987
+
4988
+ /**
4989
+ * Currently the admin notice manager relies on the module's type and slug. The new AJAX actions manager uses module IDs, hence, consider to replace the if block above with the commented code below after adjusting the admin notices manager to work with module IDs.
4990
+ *
4991
+ * @author Vova Feldman (@svovaf)
4992
+ * @since 2.0.0
4993
+ */
4994
+ /*$this->add_ajax_action( 'resolve_firewall_issues', array(
4995
+ &$this,
4996
+ '_email_about_firewall_issue'
4997
+ ) );
4998
+
4999
+ $this->add_ajax_action( 'retry_connectivity_test', array(
5000
+ &$this,
5001
+ '_retry_connectivity_test'
5002
+ ) );*/
5003
+ }
5004
+ }
5005
+
5006
+ return;
5007
+ } else {
5008
+ $this->_admin_notices->remove_sticky( array(
5009
+ 'failed_connect_api_first',
5010
+ 'failed_connect_api',
5011
+ ) );
5012
+
5013
+ if ( $this->_anonymous_mode ) {
5014
+ // Simulate anonymous mode.
5015
+ $this->_is_anonymous = true;
5016
+ }
5017
+ }
5018
+ }
5019
+ }
5020
+
5021
+ /**
5022
+ * This should be executed even if Freemius is off for the core module,
5023
+ * otherwise, the add-ons dialog box won't work properly. This is especially
5024
+ * relevant when the developer decided to turn FS off for existing users.
5025
+ *
5026
+ * @author Vova Feldman (@svovaf)
5027
+ */
5028
+ if ( $this->is_user_in_admin() &&
5029
+ 'plugin-information' === fs_request_get( 'tab', false ) &&
5030
+ $this->should_use_freemius_updater_and_dialog() &&
5031
+ (
5032
+ ( $this->is_addon() && $this->get_slug() == fs_request_get( 'plugin', false ) ) ||
5033
+ ( $this->has_addons() && $this->get_id() == fs_request_get( 'parent_plugin_id', false ) )
5034
+ )
5035
+ ) {
5036
+ require_once WP_FS__DIR_INCLUDES . '/fs-plugin-info-dialog.php';
5037
+
5038
+ new FS_Plugin_Info_Dialog( $this->is_addon() ? $this->get_parent_instance() : $this );
5039
+ }
5040
+
5041
+ // Check if Freemius is on for the current plugin.
5042
+ // This MUST be executed after all the plugin variables has been loaded.
5043
+ if ( ! $this->is_registered() && ! $this->is_on() ) {
5044
+ return;
5045
+ }
5046
+
5047
+ if ( $this->has_api_connectivity() ) {
5048
+ if ( self::is_cron() ) {
5049
+ $this->hook_callback_to_sync_cron();
5050
+ } else if ( $this->is_user_in_admin() ) {
5051
+ /**
5052
+ * Schedule daily data sync cron if:
5053
+ *
5054
+ * 1. User opted-in (for tracking).
5055
+ * 2. If skipped, but later upgraded (opted-in via upgrade).
5056
+ *
5057
+ * @author Vova Feldman (@svovaf)
5058
+ * @since 1.1.7.3
5059
+ *
5060
+ */
5061
+ if ( $this->is_registered() && $this->is_tracking_allowed() ) {
5062
+ $this->maybe_schedule_sync_cron();
5063
+ }
5064
+
5065
+ /**
5066
+ * Check if requested for manual blocking background sync.
5067
+ */
5068
+ if ( fs_request_has( 'background_sync' ) ) {
5069
+ self::require_pluggable_essentials();
5070
+ self::wp_cookie_constants();
5071
+
5072
+ $this->run_manual_sync();
5073
+ }
5074
+ }
5075
+ }
5076
+
5077
+ if ( $this->is_registered() ) {
5078
+ FS_Clone_Manager::instance()->maybe_resolve_new_subsite_install_automatically( $this );
5079
+
5080
+ $this->hook_callback_to_install_sync();
5081
+ }
5082
+
5083
+ if ( $this->is_addon() ) {
5084
+ if ( $this->is_parent_plugin_installed() ) {
5085
+ // Link to parent FS.
5086
+ $this->_parent = self::get_instance_by_id( $this->_plugin->parent_plugin_id );
5087
+
5088
+ // Get parent plugin reference.
5089
+ $this->_parent_plugin = $this->_parent->get_plugin();
5090
+ }
5091
+ }
5092
+
5093
+ if ( $this->is_user_in_admin() ) {
5094
+ if ( $this->is_registered() && fs_request_has( 'purchase_completed' ) ) {
5095
+ $this->_admin_notices->add_sticky(
5096
+ sprintf(
5097
+ /* translators: %s: License type (e.g. you have a professional license) */
5098
+ $this->get_text_inline( 'You have purchased a %s license.', 'you-have-x-license' ),
5099
+ fs_request_get( 'purchased_plan' )
5100
+ ) .
5101
+ sprintf(
5102
+ $this->get_text_inline(" The %s's %sdownload link%s, license key, and installation instructions have been sent to %s. If you can't find the email after 5 min, please check your spam box.", 'post-purchase-email-sent-message' ),
5103
+ $this->get_module_label( true ),
5104
+ ( FS_Plugin::is_valid_id( $this->get_bundle_id() ) ? "products' " : '' ),
5105
+ ( FS_Plugin::is_valid_id( $this->get_bundle_id() ) ? 's' : '' ),
5106
+ sprintf(
5107
+ '<strong>%s</strong>',
5108
+ fs_request_get( 'purchase_email' )
5109
+ )
5110
+ ),
5111
+ 'plan_purchased',
5112
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
5113
+ );
5114
+ }
5115
+
5116
+ if ( $this->is_addon() ) {
5117
+ if ( ! $this->is_parent_plugin_installed() ) {
5118
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
5119
+
5120
+ if ( isset( $plugin_info['parent'] ) ) {
5121
+ $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
5122
+ }
5123
+
5124
+ $this->_admin_notices->add(
5125
+ ( ! empty( $parent_name ) ?
5126
+ sprintf( $this->get_text_x_inline( '%s cannot run without %s.', 'addonX cannot run without pluginY', 'addon-x-cannot-run-without-y' ), $this->get_plugin_name(), $parent_name ) :
5127
+ sprintf( $this->get_text_x_inline( '%s cannot run without the plugin.', 'addonX cannot run...', 'addon-x-cannot-run-without-parent' ), $this->get_plugin_name() )
5128
+ ),
5129
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
5130
+ 'error'
5131
+ );
5132
+
5133
+ return;
5134
+ } else {
5135
+ $is_network_admin = fs_is_network_admin();
5136
+
5137
+ if ( ! $this->_parent->is_registered() && $this->is_registered() ) {
5138
+ // If add-on activated and parent not, automatically install parent for the user.
5139
+ $this->activate_parent_account( $this->_parent );
5140
+ } else if (
5141
+ $this->_parent->is_registered() &&
5142
+ ! $this->is_registered() &&
5143
+ /**
5144
+ * If not registered for add-on and the following conditions for the add-on are met, activate add-on account.
5145
+ * * Network active and in network admin - network activate add-on account.
5146
+ * * Network active and not in network admin - activate add-on account for the current blog.
5147
+ * * Not network active and not in network admin - activate add-on account for the current blog.
5148
+ *
5149
+ * If not registered for add-on, not network active, and in network admin, do not handle the add-on activation.
5150
+ *
5151
+ * @author Leo Fajardo (@leorw)
5152
+ * @since 2.3.0
5153
+ */
5154
+ ( $this->is_network_active() || ! $is_network_admin )
5155
+ ) {
5156
+ $premium_license = null;
5157
+
5158
+ if (
5159
+ ! $this->has_free_plan() &&
5160
+ $this->is_bundle_license_auto_activation_enabled() &&
5161
+ $this->_parent->is_activated_with_bundle_license()
5162
+ ) {
5163
+ /**
5164
+ * If the add-on has no free plan, try to activate the account only when there's a bundle license.
5165
+ *
5166
+ * @author Leo Fajardo (@leorw)
5167
+ * @since 2.4.0
5168
+ */
5169
+ $bundle_license = $this->get_active_parent_license( $this->_parent->_get_license()->secret_key, false );
5170
+
5171
+ if (
5172
+ is_object( $bundle_license ) &&
5173
+ ! empty( $bundle_license->products ) &&
5174
+ in_array( $this->get_id(), $bundle_license->products )
5175
+ ) {
5176
+ $premium_license = $bundle_license;
5177
+ }
5178
+ }
5179
+
5180
+ if ( $this->has_free_plan() || is_object( $premium_license) ) {
5181
+ // If parent plugin activated, automatically install add-on for the user.
5182
+ $this->_activate_addon_account(
5183
+ $this->_parent,
5184
+ ( $this->is_network_active() && $is_network_admin ) ?
5185
+ true :
5186
+ get_current_blog_id(),
5187
+ $premium_license
5188
+ );
5189
+ }
5190
+ }
5191
+
5192
+ // @todo This should be only executed on activation. It should be migrated to register_activation_hook() together with other activation related logic.
5193
+ if ( $this->is_premium() ) {
5194
+ // Remove add-on download admin-notice.
5195
+ $this->_parent->_admin_notices->remove_sticky( array(
5196
+ 'addon_plan_upgraded_' . $this->_slug,
5197
+ 'no_addon_license_' . $this->_slug,
5198
+ ) );
5199
+ }
5200
+
5201
+ // $this->deactivate_premium_only_addon_without_license();
5202
+ }
5203
+ }
5204
+
5205
+ add_action( 'admin_init', array( &$this, '_admin_init_action' ) );
5206
+
5207
+ // if ( $this->is_registered() ||
5208
+ // $this->is_anonymous() ||
5209
+ // $this->is_pending_activation()
5210
+ // ) {
5211
+ // $this->_init_admin();
5212
+ // }
5213
+ }
5214
+
5215
+ /**
5216
+ * Should be called outside `$this->is_user_in_admin()` scope
5217
+ * because the updater has some logic that needs to be executed
5218
+ * during AJAX calls.
5219
+ *
5220
+ * Currently, we need to hook to the `http_request_host_is_external` filter.
5221
+ * In the future, there might be additional logic added.
5222
+ *
5223
+ * @author Vova Feldman
5224
+ * @since 1.2.1.6
5225
+ */
5226
+ if (
5227
+ $this->should_use_freemius_updater_and_dialog() &&
5228
+ (
5229
+ $this->is_premium() ||
5230
+ /**
5231
+ * If not premium but the premium version is installed, also instantiate the updater so that the
5232
+ * plugin information dialog of the premium version will have the information from the server.
5233
+ *
5234
+ * @author Leo Fajardo (@leorw)
5235
+ * @since 2.2.3
5236
+ */
5237
+ ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->premium_plugin_basename() ) ) )
5238
+ ) &&
5239
+ $this->has_release_on_freemius() &&
5240
+ ( ! $this->is_unresolved_clone() )
5241
+ ) {
5242
+ FS_Plugin_Updater::instance( $this );
5243
+ }
5244
+
5245
+ $this->do_action( 'initiated' );
5246
+
5247
+ if ( $this->_storage->prev_is_premium !== $this->_plugin->is_premium ) {
5248
+ if ( isset( $this->_storage->prev_is_premium ) ) {
5249
+ $this->apply_filters(
5250
+ 'after_code_type_change',
5251
+ // New code type.
5252
+ $this->_plugin->is_premium
5253
+ );
5254
+ } else {
5255
+ // Set for code type for the first time.
5256
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
5257
+ }
5258
+ }
5259
+
5260
+ if ( ! $this->is_addon() ) {
5261
+ if ( $this->is_registered() ) {
5262
+ // Fix for upgrade from versions < 1.0.9.
5263
+ if ( ! isset( $this->_storage->activation_timestamp ) ) {
5264
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
5265
+ }
5266
+
5267
+ $this->do_action( 'after_init_plugin_registered' );
5268
+ } else if ( $this->is_anonymous() ) {
5269
+ $this->do_action( 'after_init_plugin_anonymous' );
5270
+ } else if ( $this->is_pending_activation() ) {
5271
+ $this->do_action( 'after_init_plugin_pending_activations' );
5272
+ }
5273
+ } else {
5274
+ if ( $this->is_registered() ) {
5275
+ $this->do_action( 'after_init_addon_registered' );
5276
+ } else if ( $this->is_anonymous() ) {
5277
+ $this->do_action( 'after_init_addon_anonymous' );
5278
+ } else if ( $this->is_pending_activation() ) {
5279
+ $this->do_action( 'after_init_addon_pending_activations' );
5280
+ }
5281
+ }
5282
+ }
5283
+
5284
+ /**
5285
+ * @author Leo Fajardo (@leorw)
5286
+ * @since 2.2.3
5287
+ *
5288
+ * @return bool
5289
+ */
5290
+ private function should_use_freemius_updater_and_dialog() {
5291
+ return (
5292
+ /**
5293
+ * Allow updater and dialog when the `fs_allow_updater_and_dialog` URL query param exists and has `true`
5294
+ * value, or when the current page is not the "Add Plugins" page (/plugin-install.php) and the `action`
5295
+ * URL query param doesn't exist or its value is not `install-plugin` so that there will be no conflicts
5296
+ * with the .org plugins' functionalities (e.g. installation from the "Add Plugins" page and viewing
5297
+ * plugin details from .org).
5298
+ */
5299
+ ( true === fs_request_get_bool( 'fs_allow_updater_and_dialog' ) ) ||
5300
+ (
5301
+ ! self::is_plugin_install_page() &&
5302
+ // Disallow updater and dialog when installing a plugin, otherwise .org "add-on" plugins will be affected.
5303
+ ( 'install-plugin' !== fs_request_get( 'action' ) )
5304
+ )
5305
+ );
5306
+ }
5307
+
5308
+ /**
5309
+ * @param string[] $permissions
5310
+ * @param bool $is_enabled
5311
+ * @param int|null $blog_id
5312
+ *
5313
+ * @return true|object `true` on success, API error object on failure.
5314
+ */
5315
+ private function update_site_permissions( array $permissions, $is_enabled, $blog_id = null ) {
5316
+ $this->_logger->entrance();
5317
+
5318
+ $params = array(
5319
+ 'permissions' => implode( ',', $permissions ),
5320
+ 'is_enabled' => $is_enabled,
5321
+ );
5322
+
5323
+ $current_blog_id = get_current_blog_id();
5324
+ $is_blog_switched = false;
5325
+ if ( is_numeric( $blog_id ) && $current_blog_id != $blog_id ) {
5326
+ $is_blog_switched = $this->switch_to_blog( $blog_id );
5327
+ }
5328
+
5329
+ $result = $this->api_site_call( '/permissions.json', 'put', $params );
5330
+
5331
+ if ( $is_blog_switched ) {
5332
+ $this->switch_to_blog( $current_blog_id );
5333
+ }
5334
+
5335
+ if (
5336
+ ! $this->is_api_result_object( $result ) ||
5337
+ ! isset( $result->install_id )
5338
+ ) {
5339
+ $this->_logger->api_error( $result );
5340
+
5341
+ return $result;
5342
+ }
5343
+
5344
+ return true;
5345
+ }
5346
+
5347
+ /**
5348
+ * @param string[] $permissions
5349
+ * @param bool $is_enabled
5350
+ * @param bool $has_site_delegated_connection
5351
+ *
5352
+ * @return true|object `true` on success, API error object on failure.
5353
+ */
5354
+ private function update_network_permissions(
5355
+ array $permissions,
5356
+ $is_enabled,
5357
+ &$has_site_delegated_connection
5358
+ ) {
5359
+ $this->_logger->entrance();
5360
+
5361
+ $install_id_2_blog_id = array();
5362
+ $install_by_blog_id = $this->get_blog_install_map();
5363
+
5364
+ $has_site_delegated_connection = false;
5365
+
5366
+ foreach ( $install_by_blog_id as $blog_id => $install ) {
5367
+ if ( $this->is_site_delegated_connection( $blog_id ) ) {
5368
+ // Only update permissions of non-delegated installs.
5369
+ $has_site_delegated_connection = true;
5370
+ continue;
5371
+ }
5372
+
5373
+ $install_id_2_blog_id[ $install->id ] = $blog_id;
5374
+ }
5375
+
5376
+ if ( empty( $install_id_2_blog_id ) ) {
5377
+ return true;
5378
+ }
5379
+
5380
+ $params = array(
5381
+ 'permissions' => implode( ',', $permissions ),
5382
+ 'is_enabled' => $is_enabled,
5383
+ 'install_ids' => implode( ',', array_keys( $install_id_2_blog_id ) ),
5384
+ );
5385
+
5386
+ // Send update to FS.
5387
+ $result = $this->get_current_or_network_user_api_scope()->call(
5388
+ "/plugins/{$this->_module_id}/installs/permissions.json",
5389
+ 'put',
5390
+ $params
5391
+ );
5392
+
5393
+ if ( ! $this->is_api_result_object( $result, 'installs_metadata' ) ) {
5394
+ $this->_logger->api_error( $result );
5395
+
5396
+ return $result;
5397
+ }
5398
+
5399
+ return true;
5400
+ }
5401
+
5402
+ /**
5403
+ * @param mixed $result
5404
+ *
5405
+ * @return string
5406
+ */
5407
+ private function get_api_error_message( $result ) {
5408
+ $error_message = sprintf( $this->get_text_inline( 'There was an unexpected API error while processing your request. Please try again in a few minutes and if it still doesn\'t work, contact the %s\'s author with the following:',
5409
+ 'unexpected-api-error' ), $this->_module_type ) . ' ';
5410
+
5411
+ if (
5412
+ $this->is_api_error( $result ) &&
5413
+ isset( $result->error )
5414
+ ) {
5415
+ $code = empty( $result->error->code ) ? '' : " Code: {$result->error->code}";
5416
+
5417
+ $error_message .= "<b>{$result->error->message}{$code}</b>";
5418
+ } else {
5419
+ $error_message .= var_export( $result, true );
5420
+ }
5421
+
5422
+ return $error_message;
5423
+ }
5424
+
5425
+ /**
5426
+ * @author Vova Feldman (@svovaf)
5427
+ * @since 2.5.1
5428
+ */
5429
+ function _toggle_permission_tracking_callback() {
5430
+ $this->_logger->entrance();
5431
+
5432
+ $this->check_ajax_referer( 'toggle_permission_tracking' );
5433
+
5434
+ if ( ! $this->is_registered( true ) ) {
5435
+ self::shoot_ajax_failure( 'User never opted-in.' );
5436
+ }
5437
+
5438
+ $is_enabled = fs_request_get_bool( 'is_enabled' );
5439
+ $permissions = fs_request_get( 'permissions' );
5440
+
5441
+ if ( ! is_string( $permissions ) ) {
5442
+ self::shoot_ajax_failure( 'The permissions param must be a string.' );
5443
+ }
5444
+
5445
+ $permissions = explode( ',', $permissions );
5446
+
5447
+ $result = $this->toggle_permission_tracking( $permissions, $is_enabled );
5448
+
5449
+ if ( true !== $result ) {
5450
+ self::shoot_ajax_failure( $this->get_api_error_message( $result ) );
5451
+ }
5452
+
5453
+ self::shoot_ajax_success();
5454
+ }
5455
+
5456
+ /**
5457
+ * @param string[] $permissions
5458
+ * @param bool $is_enabled
5459
+ * @param int|null $blog_id
5460
+ *
5461
+ * @return bool|mixed `true` if updated successfully or no update is needed.
5462
+ */
5463
+ private function toggle_permission_tracking( $permissions, $is_enabled, $blog_id = null ) {
5464
+ if ( ! $this->is_registered( true ) ) {
5465
+ // User never opted-in.
5466
+ return false;
5467
+ }
5468
+
5469
+ // Check if permissions are already set as needed.
5470
+ if ( FS_Permission_Manager::instance( $this )->are_permissions( $permissions, $is_enabled, $blog_id ) ) {
5471
+ /**
5472
+ * Note:
5473
+ * When running on the network admin, there's no need to iterate through all the installs individually since network opt-in permissions are managed for ALL non-delegated installs through a single option (per permission) on the network-level storage.
5474
+ */
5475
+ return true;
5476
+ }
5477
+
5478
+ $api_managed_permissions = array_intersect(
5479
+ $permissions,
5480
+ FS_Permission_Manager::get_api_managed_permission_ids()
5481
+ );
5482
+
5483
+ if (
5484
+ in_array( FS_Permission_Manager::PERMISSION_ESSENTIALS, $permissions ) &&
5485
+ ! in_array( FS_Permission_Manager::PERMISSION_SITE, $permissions )
5486
+ ) {
5487
+ $api_managed_permissions[] = FS_Permission_Manager::PERMISSION_SITE;
5488
+ }
5489
+
5490
+ if ( ! empty( $api_managed_permissions ) ) {
5491
+ $has_site_delegated_connection = false;
5492
+
5493
+ if (
5494
+ ! $is_enabled &&
5495
+ ! in_array( FS_Permission_Manager::PERMISSION_EXTENSIONS, $api_managed_permissions ) &&
5496
+ false === FS_Permission_Manager::instance( $this )->is_extensions_tracking_allowed( $blog_id )
5497
+ ) {
5498
+ /**
5499
+ * If we are turning off a permission and the extensions permission is off too, enrich the permissions update request to also turn off extensions tracking, as currently when opting in with extensions tracking disabled the extensions tracking is off but the API isn't aware of it.
5500
+ *
5501
+ * @todo Remove this entire `if` after implementing granular opt-in that also sends the permissions to the API when opting in.
5502
+ */
5503
+ $api_managed_permissions[] = FS_Permission_Manager::PERMISSION_EXTENSIONS;
5504
+ }
5505
+
5506
+ if ( is_null( $blog_id ) && fs_is_network_admin() ) {
5507
+ $result = $this->update_network_permissions(
5508
+ $api_managed_permissions,
5509
+ $is_enabled,
5510
+ $has_site_delegated_connection
5511
+ );
5512
+ } else {
5513
+ $result = $this->update_site_permissions(
5514
+ $api_managed_permissions,
5515
+ $is_enabled,
5516
+ $blog_id
5517
+ );
5518
+ }
5519
+
5520
+ if ( true !== $result ) {
5521
+ return $result;
5522
+ }
5523
+
5524
+ if ( in_array( FS_Permission_Manager::PERMISSION_SITE, $api_managed_permissions ) ) {
5525
+ if ( $is_enabled ) {
5526
+ $this->schedule_sync_cron();
5527
+ } else {
5528
+ $this->clear_sync_cron( ! $has_site_delegated_connection );
5529
+ }
5530
+ }
5531
+
5532
+ if ( in_array( FS_Permission_Manager::PERMISSION_USER, $api_managed_permissions ) ) {
5533
+ $this->toggle_user_permission( $is_enabled, $blog_id );
5534
+ }
5535
+ }
5536
+
5537
+ $this->update_tracking_permissions(
5538
+ $permissions,
5539
+ $is_enabled,
5540
+ $blog_id
5541
+ );
5542
+
5543
+ return true;
5544
+ }
5545
+
5546
+ /**
5547
+ * @param bool $is_enabled
5548
+ * @param int|null $blog_id
5549
+ */
5550
+ private function toggle_user_permission( $is_enabled, $blog_id = null ) {
5551
+ $network_or_blog_ids = is_numeric( $blog_id ) ?
5552
+ $blog_id :
5553
+ fs_is_network_admin();
5554
+
5555
+ if ( $is_enabled ) {
5556
+ $this->reset_anonymous_mode( $network_or_blog_ids );
5557
+ } else {
5558
+ $this->skip_connection( $network_or_blog_ids );
5559
+ }
5560
+ }
5561
+
5562
+ /**
5563
+ * Opt-in back into usage tracking.
5564
+ *
5565
+ * Note: This will only work if the user opted-in previously.
5566
+ *
5567
+ * Returns:
5568
+ * 1. FALSE - If the user never opted-in.
5569
+ * 2. TRUE - If successfully opted-in back to usage tracking.
5570
+ * 3. object - API result on failure.
5571
+ *
5572
+ * @author Leo Fajardo (@leorw)
5573
+ * @since 1.2.1.5
5574
+ *
5575
+ * @bool $is_enabled
5576
+ *
5577
+ * @return bool|object
5578
+ */
5579
+ private function toggle_site_tracking( $is_enabled, $blog_id = null ) {
5580
+ $this->_logger->entrance();
5581
+
5582
+ return $this->toggle_permission_tracking(
5583
+ FS_Permission_Manager::instance( $this )->get_site_tracking_permission_names(),
5584
+ $is_enabled,
5585
+ $blog_id
5586
+ );
5587
+ }
5588
+
5589
+ /**
5590
+ * If user opted-in and later disabled usage-tracking,
5591
+ * re-allow tracking for licensing and updates.
5592
+ *
5593
+ * @author Leo Fajardo (@leorw)
5594
+ * @since 1.2.1.5
5595
+ *
5596
+ * @param bool $is_context_single_site
5597
+ */
5598
+ private function reconnect_locally( $is_context_single_site = false ) {
5599
+ $this->_logger->entrance();
5600
+
5601
+ if ( ! $this->is_registered() ) {
5602
+ return;
5603
+ }
5604
+
5605
+ if ( ! fs_is_network_admin() || $is_context_single_site ) {
5606
+ if ( $this->is_tracking_prohibited() ) {
5607
+ FS_Permission_Manager::instance( $this )->update_site_tracking( true );
5608
+ }
5609
+ } else {
5610
+ $installs_map = $this->get_blog_install_map();
5611
+ foreach ( $installs_map as $blog_id => $install ) {
5612
+ /**
5613
+ * @var FS_Site $install
5614
+ */
5615
+ if ( ! $this->is_tracking_allowed( $blog_id, $install ) ) {
5616
+ FS_Permission_Manager::instance( $this )->update_site_tracking( true, $blog_id );
5617
+ }
5618
+ }
5619
+ }
5620
+ }
5621
+
5622
+ /**
5623
+ * Update permission tracking flags. When updating in a network context, in addition to updating the network-level flags, also update the permissions on the site-level for all non-delegated sites.
5624
+ *
5625
+ * @param string[] $permissions
5626
+ * @param bool $is_enabled
5627
+ * @param int|null $blog_id
5628
+ *
5629
+ * @return array
5630
+ */
5631
+ private function update_tracking_permissions( $permissions, $is_enabled, $blog_id = null ) {
5632
+ // Alias.
5633
+ $permission_manager = FS_Permission_Manager::instance( $this );
5634
+
5635
+ $network_or_blog_ids = is_numeric( $blog_id ) ?
5636
+ $blog_id :
5637
+ fs_is_network_admin();
5638
+
5639
+ if ( true === $network_or_blog_ids ) {
5640
+ // Update the permission for all non-delegated sub-sites.
5641
+ $blog_ids = $this->get_non_delegated_blog_ids();
5642
+
5643
+ // Add the network-level to the array, to update the permission on the network-level storage.
5644
+ array_unshift( $blog_ids, null );
5645
+ }
5646
+ else
5647
+ {
5648
+ if ( false === $network_or_blog_ids ) {
5649
+ $network_or_blog_ids = null;
5650
+ }
5651
+
5652
+ $blog_ids = is_array( $network_or_blog_ids ) ?
5653
+ $network_or_blog_ids :
5654
+ array( $network_or_blog_ids );
5655
+ }
5656
+
5657
+ $result = array();
5658
+ foreach ( $permissions as $permission ) {
5659
+ $permission = trim( $permission );
5660
+ $is_permission_supported = true;
5661
+
5662
+ foreach ( $blog_ids as $id ) {
5663
+ $is_permission_supported = $permission_manager->update_permission_tracking_flag(
5664
+ $permission,
5665
+ $is_enabled,
5666
+ $id
5667
+ );
5668
+ }
5669
+
5670
+ if ( ! $is_permission_supported ) {
5671
+ $permission = 'no_match';
5672
+ }
5673
+
5674
+ $result[ $permission ] = $is_enabled;
5675
+ }
5676
+
5677
+ return $result;
5678
+ }
5679
+
5680
+ /**
5681
+ * Parse plugin's settings (as defined by the plugin dev).
5682
+ *
5683
+ * @author Vova Feldman (@svovaf)
5684
+ * @since 1.1.7.3
5685
+ *
5686
+ * @param array $plugin_info
5687
+ *
5688
+ * @throws \Freemius_Exception
5689
+ */
5690
+ private function parse_settings( &$plugin_info ) {
5691
+ $this->_logger->entrance();
5692
+
5693
+ $id = $this->get_numeric_option( $plugin_info, 'id', false );
5694
+ $public_key = $this->get_option( $plugin_info, 'public_key', false );
5695
+ $secret_key = $this->get_option( $plugin_info, 'secret_key', null );
5696
+ $parent_id = $this->get_numeric_option( $plugin_info, 'parent_id', null );
5697
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
5698
+
5699
+ /**
5700
+ * @author Vova Feldman (@svovaf)
5701
+ * @since 1.1.9 Try to pull secret key from external config.
5702
+ */
5703
+ if ( is_null( $secret_key ) && defined( "WP_FS__{$this->_slug}_SECRET_KEY" ) ) {
5704
+ $secret_key = constant( "WP_FS__{$this->_slug}_SECRET_KEY" );
5705
+ }
5706
+
5707
+ if ( isset( $plugin_info['parent'] ) ) {
5708
+ $parent_id = $this->get_numeric_option( $plugin_info['parent'], 'id', null );
5709
+ // $parent_slug = $this->get_option( $plugin_info['parent'], 'slug', null );
5710
+ // $parent_public_key = $this->get_option( $plugin_info['parent'], 'public_key', null );
5711
+ // $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
5712
+ }
5713
+
5714
+ if ( false === $id ) {
5715
+ throw new Freemius_Exception( array(
5716
+ 'error' => array(
5717
+ 'type' => 'ParameterNotSet',
5718
+ 'message' => 'Plugin id parameter is not set.',
5719
+ 'code' => 'plugin_id_not_set',
5720
+ 'http' => 500,
5721
+ )
5722
+ ) );
5723
+ }
5724
+ if ( false === $public_key ) {
5725
+ throw new Freemius_Exception( array(
5726
+ 'error' => array(
5727
+ 'type' => 'ParameterNotSet',
5728
+ 'message' => 'Plugin public_key parameter is not set.',
5729
+ 'code' => 'plugin_public_key_not_set',
5730
+ 'http' => 500,
5731
+ )
5732
+ ) );
5733
+ }
5734
+
5735
+ $plugin = ( $this->_plugin instanceof FS_Plugin ) ?
5736
+ $this->_plugin :
5737
+ new FS_Plugin();
5738
+
5739
+ $premium_suffix = $this->get_option( $plugin_info, 'premium_suffix', '(Premium)' );
5740
+
5741
+ $plugin->update( array(
5742
+ 'id' => $id,
5743
+ 'type' => $this->get_option( $plugin_info, 'type', $this->_module_type ),
5744
+ 'public_key' => $public_key,
5745
+ 'slug' => $this->_slug,
5746
+ 'premium_slug' => $this->get_option( $plugin_info, 'premium_slug', "{$this->_slug}-premium" ),
5747
+ 'parent_plugin_id' => $parent_id,
5748
+ 'version' => $this->get_plugin_version(),
5749
+ 'title' => $this->get_plugin_name( $premium_suffix ),
5750
+ 'file' => $this->_plugin_basename,
5751
+ 'is_premium' => $this->get_bool_option( $plugin_info, 'is_premium', true ),
5752
+ 'premium_suffix' => $premium_suffix,
5753
+ 'is_live' => $this->get_bool_option( $plugin_info, 'is_live', true ),
5754
+ 'affiliate_moderation' => $this->get_option( $plugin_info, 'has_affiliation' ),
5755
+ 'bundle_id' => $this->get_option( $plugin_info, 'bundle_id', null ),
5756
+ 'bundle_public_key' => $this->get_option( $plugin_info, 'bundle_public_key', null ),
5757
+ ) );
5758
+
5759
+ if ( $plugin->is_updated() ) {
5760
+ // Update plugin details.
5761
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->store( $plugin );
5762
+ }
5763
+ // Set the secret key after storing the plugin, we don't want to store the key in the storage.
5764
+ $this->_plugin->secret_key = $secret_key;
5765
+
5766
+ /**
5767
+ * If the product is network integrated and activated and the current view is in the network level Admin dashboard, if the product's network-level menu located differently from the sub-site level, then use the network menu details (when set).
5768
+ *
5769
+ * @author Vova Feldman
5770
+ * @since 2.4.5
5771
+ */
5772
+ if ( $this->is_network_active() && fs_is_network_admin() ) {
5773
+ if ( isset( $plugin_info['menu_network'] ) &&
5774
+ is_array( $plugin_info['menu_network'] ) &&
5775
+ ! empty( $plugin_info['menu_network'] )
5776
+ ) {
5777
+ $plugin_info['menu'] = $plugin_info['menu_network'];
5778
+ }
5779
+ }
5780
+
5781
+ if ( ! isset( $plugin_info['menu'] ) ) {
5782
+ $plugin_info['menu'] = array();
5783
+
5784
+ if ( ! empty( $this->_storage->sdk_last_version ) &&
5785
+ version_compare( $this->_storage->sdk_last_version, '1.1.2', '<=' )
5786
+ ) {
5787
+ // Backward compatibility to 1.1.2
5788
+ $plugin_info['menu']['slug'] = isset( $plugin_info['menu_slug'] ) ?
5789
+ $plugin_info['menu_slug'] :
5790
+ $this->_slug;
5791
+ }
5792
+ }
5793
+
5794
+ $this->_menu = FS_Admin_Menu_Manager::instance(
5795
+ $this->_module_id,
5796
+ $this->_module_type,
5797
+ $this->get_unique_affix()
5798
+ );
5799
+
5800
+ $this->_menu->init( $plugin_info['menu'], $this->is_addon() );
5801
+
5802
+ $this->_has_addons = $this->get_bool_option( $plugin_info, 'has_addons', false );
5803
+ $this->_has_paid_plans = $this->get_bool_option( $plugin_info, 'has_paid_plans', true );
5804
+ $this->_has_premium_version = $this->get_bool_option( $plugin_info, 'has_premium_version', $this->_has_paid_plans );
5805
+ $this->_ignore_pending_mode = $this->get_bool_option( $plugin_info, 'ignore_pending_mode', false );
5806
+ $this->_is_org_compliant = $this->get_bool_option( $plugin_info, 'is_org_compliant', true );
5807
+ $this->_is_premium_only = $this->get_bool_option( $plugin_info, 'is_premium_only', false );
5808
+ if ( $this->_is_premium_only ) {
5809
+ // If premium only plugin, disable anonymous mode.
5810
+ $this->_enable_anonymous = false;
5811
+ $this->_anonymous_mode = false;
5812
+ } else {
5813
+ $this->_enable_anonymous = $this->get_bool_option( $plugin_info, 'enable_anonymous', true );
5814
+ $this->_anonymous_mode = $this->get_bool_option( $plugin_info, 'anonymous_mode', false );
5815
+ }
5816
+ $this->_permissions = $this->get_option( $plugin_info, 'permissions', array() );
5817
+ $this->_is_bundle_license_auto_activation_enabled = $this->get_option( $plugin_info, 'bundle_license_auto_activation', false );
5818
+
5819
+ if ( ! empty( $plugin_info['trial'] ) ) {
5820
+ $this->_trial_days = $this->get_numeric_option(
5821
+ $plugin_info['trial'],
5822
+ 'days',
5823
+ // Default to 0 - trial without days specification.
5824
+ 0
5825
+ );
5826
+
5827
+ $this->_is_trial_require_payment = $this->get_bool_option( $plugin_info['trial'], 'is_require_payment', false );
5828
+ }
5829
+
5830
+ $this->_navigation = $this->get_option(
5831
+ $plugin_info,
5832
+ 'navigation',
5833
+ $this->is_free_wp_org_theme() ?
5834
+ self::NAVIGATION_TABS :
5835
+ self::NAVIGATION_MENU
5836
+ );
5837
+ }
5838
+
5839
+ /**
5840
+ * @param string[] $options
5841
+ * @param string $key
5842
+ * @param mixed $default
5843
+ *
5844
+ * @return bool
5845
+ */
5846
+ private function get_option( &$options, $key, $default = false ) {
5847
+ return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
5848
+ }
5849
+
5850
+ private function get_bool_option( &$options, $key, $default = false ) {
5851
+ return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
5852
+ }
5853
+
5854
+ private function get_numeric_option( &$options, $key, $default = false ) {
5855
+ return isset( $options[ $key ] ) && is_numeric( $options[ $key ] ) ? $options[ $key ] : $default;
5856
+ }
5857
+
5858
+ /**
5859
+ * Gate keeper.
5860
+ *
5861
+ * @author Vova Feldman (@svovaf)
5862
+ * @since 1.1.7.3
5863
+ *
5864
+ * @return bool
5865
+ */
5866
+ private function should_stop_execution() {
5867
+ if ( empty( $this->_storage->was_plugin_loaded ) ) {
5868
+ /**
5869
+ * Don't execute Freemius until plugin was fully loaded at least once,
5870
+ * to give the opportunity for the activation hook to run before pinging
5871
+ * the API for connectivity test. This logic is relevant for the
5872
+ * identification of new plugin install vs. plugin update.
5873
+ *
5874
+ * @author Vova Feldman (@svovaf)
5875
+ * @since 1.1.9
5876
+ */
5877
+ return true;
5878
+ }
5879
+
5880
+ if ( $this->is_activation_mode() ) {
5881
+ if ( ! is_admin() ) {
5882
+ /**
5883
+ * If in activation mode, don't execute Freemius outside the admin dashboard.
5884
+ *
5885
+ * @author Vova Feldman (@svovaf)
5886
+ * @since 1.1.7.3
5887
+ */
5888
+ return true;
5889
+ }
5890
+
5891
+ if ( ! WP_FS__IS_HTTP_REQUEST ) {
5892
+ /**
5893
+ * If in activation and executed without HTTP context (e.g. CLI, Cronjob),
5894
+ * then don't start Freemius.
5895
+ *
5896
+ * @author Vova Feldman (@svovaf)
5897
+ * @since 1.1.6.3
5898
+ *
5899
+ * @link https://wordpress.org/support/topic/errors-in-the-freemius-class-when-running-in-wordpress-in-cli
5900
+ */
5901
+ return true;
5902
+ }
5903
+
5904
+ if ( self::is_cron() ) {
5905
+ /**
5906
+ * If in activation mode, don't execute Freemius during wp crons
5907
+ * (wp crons have HTTP context - called as HTTP request).
5908
+ *
5909
+ * @author Vova Feldman (@svovaf)
5910
+ * @since 1.1.7.3
5911
+ */
5912
+ return true;
5913
+ }
5914
+
5915
+ if ( self::is_ajax() &&
5916
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) &&
5917
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api' )
5918
+ ) {
5919
+ /**
5920
+ * During activation, if running in AJAX mode, unless there's a sticky
5921
+ * connectivity issue notice, don't run Freemius.
5922
+ *
5923
+ * @author Vova Feldman (@svovaf)
5924
+ * @since 1.1.7.3
5925
+ */
5926
+ return true;
5927
+ }
5928
+ }
5929
+
5930
+ return false;
5931
+ }
5932
+
5933
+ /**
5934
+ * Triggered after code type has changed.
5935
+ *
5936
+ * @author Vova Feldman (@svovaf)
5937
+ * @since 1.1.9.1
5938
+ */
5939
+ function _after_code_type_change() {
5940
+ $this->_logger->entrance();
5941
+
5942
+ if ( $this->is_theme() ) {
5943
+ // Expire the cache of the previous tabs since the theme may
5944
+ // have setting updates after code type has changed.
5945
+ $this->_cache->expire( 'tabs' );
5946
+ $this->_cache->expire( 'tabs_stylesheets' );
5947
+ }
5948
+
5949
+ if ( $this->is_registered() ) {
5950
+ if ( ! $this->is_addon() ) {
5951
+ add_action(
5952
+ is_admin() ? 'admin_init' : 'init',
5953
+ array( &$this, '_plugin_code_type_changed' )
5954
+ );
5955
+ }
5956
+
5957
+ if ( $this->is_premium() ) {
5958
+ // Purge cached payments after switching to the premium version.
5959
+ // @todo This logic doesn't handle purging the cache for serviceware module upgrade.
5960
+ $this->get_api_user_scope()->purge_cache( "/plugins/{$this->_module_id}/payments.json?include_addons=true" );
5961
+ }
5962
+ }
5963
+ }
5964
+
5965
+ /**
5966
+ * Handles plugin's code type change (free <--> premium).
5967
+ *
5968
+ * @author Vova Feldman (@svovaf)
5969
+ * @since 1.0.9
5970
+ */
5971
+ function _plugin_code_type_changed() {
5972
+ $this->_logger->entrance();
5973
+
5974
+ if ( $this->is_premium() ) {
5975
+ $this->reconnect_locally();
5976
+
5977
+ // Activated premium code.
5978
+ $this->do_action( 'after_premium_version_activation' );
5979
+
5980
+ // Remove all sticky messages related to download of the premium version.
5981
+ $this->_admin_notices->remove_sticky( array(
5982
+ 'trial_started',
5983
+ 'plan_upgraded',
5984
+ 'plan_changed',
5985
+ 'license_activated',
5986
+ ) );
5987
+
5988
+ $notice = '';
5989
+ if ( ! $this->is_only_premium() ) {
5990
+ $notice = sprintf( $this->get_text_inline( 'Premium %s version was successfully activated.', 'premium-activated-message' ), $this->_module_type );
5991
+ }
5992
+
5993
+ $license_notice = $this->get_license_network_activation_notice();
5994
+ if ( ! empty( $license_notice ) ) {
5995
+ $notice .= ' ' . $license_notice;
5996
+ }
5997
+
5998
+ if ( ! empty( $notice ) ) {
5999
+ $this->_admin_notices->add_sticky(
6000
+ trim( $notice ),
6001
+ 'premium_activated',
6002
+ $this->get_text_x_inline( 'W00t',
6003
+ 'Used to express elation, enthusiasm, or triumph (especially in electronic communication).', 'woot' ) . '!'
6004
+ );
6005
+ }
6006
+ } else {
6007
+ // Remove sticky message related to premium code activation.
6008
+ $this->_admin_notices->remove_sticky( 'premium_activated' );
6009
+
6010
+ // Activated free code (after had the premium before).
6011
+ $this->do_action( 'after_free_version_reactivation' );
6012
+
6013
+ if ( $this->is_paying() && ! $this->is_premium() ) {
6014
+ $this->_admin_notices->add_sticky(
6015
+ sprintf(
6016
+ /* translators: %s: License type (e.g. you have a professional license) */
6017
+ $this->get_text_inline( 'You have a %s license.', 'you-have-x-license' ),
6018
+ $this->get_plan_title()
6019
+ ) . $this->get_complete_upgrade_instructions(),
6020
+ 'plan_upgraded',
6021
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
6022
+ );
6023
+ }
6024
+ }
6025
+
6026
+ // Schedule code type changes event.
6027
+ $this->schedule_install_sync();
6028
+
6029
+ /**
6030
+ * Unregister the uninstall hook for the other version of the plugin (with different code type) to avoid
6031
+ * triggering a fatal error when uninstalling that plugin. For example, after deactivating the "free" version
6032
+ * of a specific plugin, its uninstall hook should be unregistered after the "premium" version has been
6033
+ * activated. If we don't do that, a fatal error will occur when we try to uninstall the "free" version since
6034
+ * the main file of the "free" version will be loaded first before calling the hooked callback. Since the
6035
+ * free and premium versions are almost identical (same class or have same functions), a fatal error like
6036
+ * "Cannot redeclare class MyClass" or "Cannot redeclare my_function()" will occur.
6037
+ */
6038
+ $this->unregister_uninstall_hook();
6039
+
6040
+ $this->clear_module_main_file_cache();
6041
+
6042
+ // Update is_premium of latest version.
6043
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
6044
+ }
6045
+
6046
+ #endregion
6047
+
6048
+ #----------------------------------------------------------------------------------
6049
+ #region Add-ons
6050
+ #----------------------------------------------------------------------------------
6051
+
6052
+ /**
6053
+ * Check if add-on installed and activated on site.
6054
+ *
6055
+ * @author Vova Feldman (@svovaf)
6056
+ * @since 1.0.6
6057
+ *
6058
+ * @param string|number $id_or_slug
6059
+ * @param bool|null $is_premium Since 1.2.1.7 can check for specified add-on version.
6060
+ *
6061
+ * @return bool
6062
+ */
6063
+ function is_addon_activated( $id_or_slug, $is_premium = null ) {
6064
+ $this->_logger->entrance();
6065
+
6066
+ $addon_id = self::get_module_id( $id_or_slug );
6067
+ $is_activated = self::has_instance( $addon_id );
6068
+
6069
+ if ( ! $is_activated ) {
6070
+ return false;
6071
+ }
6072
+
6073
+ if ( is_bool( $is_premium ) ) {
6074
+ // Check if the specified code version is activate.
6075
+ $addon = $this->get_addon_instance( $addon_id );
6076
+ $is_activated = ( $is_premium === $addon->is_premium() );
6077
+ }
6078
+
6079
+ return $is_activated;
6080
+ }
6081
+
6082
+ /**
6083
+ * Check if add-on was connected to install
6084
+ *
6085
+ * @author Vova Feldman (@svovaf)
6086
+ * @since 1.1.7
6087
+ *
6088
+ * @param string|number $id_or_slug
6089
+ *
6090
+ * @return bool
6091
+ */
6092
+ function is_addon_connected( $id_or_slug ) {
6093
+ $this->_logger->entrance();
6094
+
6095
+ $sites = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN );
6096
+
6097
+ $addon_id = self::get_module_id( $id_or_slug );
6098
+ $addon = $this->get_addon( $addon_id );
6099
+ $slug = $addon->slug;
6100
+ if ( ! isset( $sites[ $slug ] ) ) {
6101
+ return false;
6102
+ }
6103
+
6104
+ $site = $sites[ $slug ];
6105
+
6106
+ $plugin = FS_Plugin_Manager::instance( $addon_id )->get();
6107
+
6108
+ if ( $plugin->parent_plugin_id != $this->_plugin->id ) {
6109
+ // The given slug do NOT belong to any of the plugin's add-ons.
6110
+ return false;
6111
+ }
6112
+
6113
+ return ( is_object( $site ) &&
6114
+ is_numeric( $site->id ) &&
6115
+ is_numeric( $site->user_id ) &&
6116
+ FS_Plugin_Plan::is_valid_id( $site->plan_id )
6117
+ );
6118
+ }
6119
+
6120
+ /**
6121
+ * Determines if add-on installed.
6122
+ *
6123
+ * NOTE: This is a heuristic and only works if the folder/file named as the slug.
6124
+ *
6125
+ * @author Vova Feldman (@svovaf)
6126
+ * @since 1.0.6
6127
+ *
6128
+ * @param string|number $id_or_slug
6129
+ *
6130
+ * @return bool
6131
+ */
6132
+ function is_addon_installed( $id_or_slug ) {
6133
+ $this->_logger->entrance();
6134
+
6135
+ $addon_id = self::get_module_id( $id_or_slug );
6136
+
6137
+ return file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->get_addon_basename( $addon_id ) ) );
6138
+ }
6139
+
6140
+ /**
6141
+ * Get add-on basename.
6142
+ *
6143
+ * @author Vova Feldman (@svovaf)
6144
+ * @since 1.0.6
6145
+ *
6146
+ * @param string|number $id_or_slug
6147
+ *
6148
+ * @return string
6149
+ */
6150
+ function get_addon_basename( $id_or_slug ) {
6151
+ $addon_id = self::get_module_id( $id_or_slug );
6152
+
6153
+ if ( $this->is_addon_activated( $addon_id ) ) {
6154
+ return self::instance( $addon_id )->get_plugin_basename();
6155
+ }
6156
+
6157
+ $addon = $this->get_addon( $addon_id );
6158
+ $premium_basename = "{$addon->premium_slug}/{$addon->slug}.php";
6159
+
6160
+ if ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $premium_basename ) ) ) {
6161
+ return $premium_basename;
6162
+ }
6163
+
6164
+ $all_plugins = $this->get_all_plugins();
6165
+
6166
+ foreach ( $all_plugins as $basename => $data ) {
6167
+ if ( $addon->slug === $data['slug'] ||
6168
+ $addon->premium_slug === $data['slug']
6169
+ ) {
6170
+ return $basename;
6171
+ }
6172
+ }
6173
+
6174
+ $free_basename = "{$addon->slug}/{$addon->slug}.php";
6175
+
6176
+ return $free_basename;
6177
+ }
6178
+
6179
+ /**
6180
+ * Get installed add-ons instances.
6181
+ *
6182
+ * @author Vova Feldman (@svovaf)
6183
+ * @since 1.0.6
6184
+ *
6185
+ * @return Freemius[]
6186
+ */
6187
+ function get_installed_addons() {
6188
+ if ( $this->is_addon() ) {
6189
+ // Add-on cannot have add-ons.
6190
+ return array();
6191
+ }
6192
+
6193
+ $installed_addons = array();
6194
+
6195
+ foreach ( self::$_instances as $instance ) {
6196
+ if ( $instance->is_addon_of( $this->_plugin->id ) ) {
6197
+ $installed_addons[] = $instance;
6198
+ }
6199
+ }
6200
+
6201
+ return $installed_addons;
6202
+ }
6203
+
6204
+ /**
6205
+ * Check if any add-ons of the plugin are installed.
6206
+ *
6207
+ * @author Leo Fajardo (@leorw)
6208
+ * @since 1.1.1
6209
+ *
6210
+ * @return bool
6211
+ */
6212
+ function has_installed_addons() {
6213
+ if ( ! $this->has_addons() ) {
6214
+ return false;
6215
+ }
6216
+
6217
+ foreach ( self::$_instances as $instance ) {
6218
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
6219
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
6220
+ return true;
6221
+ }
6222
+ }
6223
+ }
6224
+
6225
+ return false;
6226
+ }
6227
+
6228
+ /**
6229
+ * Tell Freemius that the current plugin is an add-on.
6230
+ *
6231
+ * @author Vova Feldman (@svovaf)
6232
+ * @since 1.0.6
6233
+ *
6234
+ * @param number $parent_plugin_id The parent plugin ID
6235
+ */
6236
+ function init_addon( $parent_plugin_id ) {
6237
+ $this->_plugin->parent_plugin_id = $parent_plugin_id;
6238
+ }
6239
+
6240
+ /**
6241
+ * @author Vova Feldman (@svovaf)
6242
+ * @since 1.0.6
6243
+ *
6244
+ * @return bool
6245
+ */
6246
+ function is_addon() {
6247
+ return (
6248
+ isset( $this->_plugin->parent_plugin_id ) &&
6249
+ is_numeric( $this->_plugin->parent_plugin_id )
6250
+ );
6251
+ }
6252
+
6253
+ /**
6254
+ * @author Vova Feldman (@svovaf)
6255
+ * @since 2.3.2
6256
+ *
6257
+ * @param number $parent_product_id
6258
+ *
6259
+ * @return bool
6260
+ */
6261
+ function is_addon_of( $parent_product_id ) {
6262
+ return (
6263
+ $this->is_addon() &&
6264
+ $parent_product_id == $this->_plugin->parent_plugin_id
6265
+ );
6266
+ }
6267
+
6268
+ /**
6269
+ * Deactivate add-on if it's premium only and the user does't have a valid license.
6270
+ *
6271
+ * @param bool $is_after_trial_cancel
6272
+ *
6273
+ * @return bool If add-on was deactivated.
6274
+ */
6275
+ private function deactivate_premium_only_addon_without_license( $is_after_trial_cancel = false ) {
6276
+ if ( ! $this->has_free_plan() &&
6277
+ ! $this->has_features_enabled_license() &&
6278
+ ! $this->_has_premium_license()
6279
+ ) {
6280
+ if ( $this->is_registered() ) {
6281
+ // IF wrapper is turned off because activation_timestamp is currently only stored for plugins (not addons).
6282
+ // if (empty($this->_storage->activation_timestamp) ||
6283
+ // (WP_FS__SCRIPT_START_TIME - $this->_storage->activation_timestamp) > 30
6284
+ // ) {
6285
+ /**
6286
+ * @todo When it's first fail, there's no reason to try and re-sync because the licenses were just synced after initial activation.
6287
+ *
6288
+ * Retry syncing the user add-on licenses.
6289
+ */
6290
+ // Sync licenses.
6291
+ $this->_sync_licenses();
6292
+ // }
6293
+
6294
+ // Try to activate premium license.
6295
+ $this->_activate_license( true );
6296
+ }
6297
+
6298
+ if ( ! $this->has_free_plan() &&
6299
+ ! $this->has_features_enabled_license() &&
6300
+ ! $this->_has_premium_license()
6301
+ ) {
6302
+ // @todo Check if deactivate plugins also call the deactivation hook.
6303
+
6304
+ $this->_parent->_admin_notices->add_sticky(
6305
+ sprintf(
6306
+ ( $is_after_trial_cancel ?
6307
+ $this->_parent->get_text_inline(
6308
+ '%s free trial was successfully cancelled. Since the add-on is premium only it was automatically deactivated. If you like to use it in the future, you\'ll have to purchase a license.',
6309
+ 'addon-trial-cancelled-message'
6310
+ ) :
6311
+ $this->_parent->get_text_inline(
6312
+ '%s is a premium only add-on. You have to purchase a license first before activating the plugin.',
6313
+ 'addon-no-license-message'
6314
+ )
6315
+ ),
6316
+ '<b>' . $this->_plugin->title . '</b>'
6317
+ ) . ' ' . sprintf(
6318
+ '<a href="%s" aria-label="%s" class="button button-primary" style="margin-left: 10px; vertical-align: middle;">%s &nbsp;&#10140;</a>',
6319
+ $this->_parent->addon_url( $this->_slug ),
6320
+ esc_attr( sprintf( $this->_parent->get_text_inline( 'More information about %s', 'more-information-about-x' ), $this->_plugin->title ) ),
6321
+ $this->_parent->get_text_inline( 'Purchase License', 'purchase-license' )
6322
+ ),
6323
+ 'no_addon_license_' . $this->_slug,
6324
+ ( $is_after_trial_cancel ? '' : $this->_parent->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...' ),
6325
+ ( $is_after_trial_cancel ? 'success' : 'error' )
6326
+ );
6327
+
6328
+ deactivate_plugins( array( $this->_plugin_basename ), true );
6329
+
6330
+ return true;
6331
+ }
6332
+ }
6333
+
6334
+ return false;
6335
+ }
6336
+
6337
+ #endregion
6338
+
6339
+ #----------------------------------------------------------------------------------
6340
+ #region Sandbox
6341
+ #----------------------------------------------------------------------------------
6342
+
6343
+ /**
6344
+ * Set Freemius into sandbox mode for debugging.
6345
+ *
6346
+ * @author Vova Feldman (@svovaf)
6347
+ * @since 1.0.4
6348
+ *
6349
+ * @param string $secret_key
6350
+ */
6351
+ function init_sandbox( $secret_key ) {
6352
+ $this->_plugin->secret_key = $secret_key;
6353
+
6354
+ // Update plugin details.
6355
+ FS_Plugin_Manager::instance( $this->_module_id )->update( $this->_plugin, true );
6356
+ }
6357
+
6358
+ /**
6359
+ * Check if running payments in sandbox mode.
6360
+ *
6361
+ * @author Vova Feldman (@svovaf)
6362
+ * @since 1.0.4
6363
+ *
6364
+ * @return bool
6365
+ */
6366
+ function is_payments_sandbox() {
6367
+ return ( ! $this->is_live() ) || isset( $this->_plugin->secret_key );
6368
+ }
6369
+
6370
+ #endregion
6371
+
6372
+ /**
6373
+ * Check if running test vs. live plugin.
6374
+ *
6375
+ * @author Vova Feldman (@svovaf)
6376
+ * @since 1.0.5
6377
+ *
6378
+ * @return bool
6379
+ */
6380
+ function is_live() {
6381
+ return $this->_plugin->is_live;
6382
+ }
6383
+
6384
+ /**
6385
+ * Check if super-admin skipped connection for all sites in the network.
6386
+ *
6387
+ * @author Vova Feldman (@svovaf)
6388
+ * @since 2.0.0
6389
+ */
6390
+ function is_network_anonymous() {
6391
+ if ( ! $this->_is_network_active ) {
6392
+ return false;
6393
+ }
6394
+
6395
+ $is_anonymous_ms = $this->_storage->get( 'is_anonymous_ms' );
6396
+
6397
+ if ( empty( $is_anonymous_ms ) ) {
6398
+ return false;
6399
+ }
6400
+
6401
+ return $is_anonymous_ms['is'];
6402
+ }
6403
+
6404
+ /**
6405
+ * Check if super-admin opted-in for all sites in the network.
6406
+ *
6407
+ * @author Vova Feldman (@svovaf)
6408
+ * @since 2.0.0
6409
+ */
6410
+ function is_network_connected() {
6411
+ if ( ! $this->_is_network_active ) {
6412
+ return false;
6413
+ }
6414
+
6415
+ return $this->_storage->get( 'is_network_connected' );
6416
+ }
6417
+
6418
+ /**
6419
+ * Check if the user skipped connecting the account with Freemius.
6420
+ *
6421
+ * @author Vova Feldman (@svovaf)
6422
+ * @since 1.0.7
6423
+ *
6424
+ * @return bool
6425
+ */
6426
+ function is_anonymous() {
6427
+ if ( ! isset( $this->_is_anonymous ) ) {
6428
+ if ( $this->is_network_anonymous() ) {
6429
+ $this->_is_anonymous = true;
6430
+ } else if ( fs_is_network_admin() ) {
6431
+ /**
6432
+ * When not-network-anonymous, yet, running in the network admin, consider as anonymous only when ALL non-delegated sites are set to anonymous.
6433
+ */
6434
+ $non_delegated_sites = $this->get_non_delegated_blog_ids();
6435
+
6436
+ foreach ( $non_delegated_sites as $blog_id ) {
6437
+ $is_anonymous = $this->_storage->get( 'is_anonymous', false, $blog_id );
6438
+
6439
+ if ( empty( $is_anonymous ) || false === $is_anonymous[ 'is' ] ) {
6440
+ $this->_is_anonymous = false;
6441
+ break;
6442
+ }
6443
+ }
6444
+
6445
+ if ( false !== $this->_is_anonymous ) {
6446
+ $this->_is_anonymous = true;
6447
+ }
6448
+ } else {
6449
+ if ( ! isset( $this->_storage->is_anonymous ) ) {
6450
+ // Not skipped.
6451
+ $this->_is_anonymous = false;
6452
+ } else if ( is_bool( $this->_storage->is_anonymous ) ) {
6453
+ // For back compatibility, since the variable was boolean before.
6454
+ $this->_is_anonymous = $this->_storage->is_anonymous;
6455
+
6456
+ // Upgrade stored data format to 1.1.3 format.
6457
+ $this->set_anonymous_mode( $this->_storage->is_anonymous );
6458
+ } else {
6459
+ // Version 1.1.3 and later.
6460
+ $this->_is_anonymous = $this->_storage->is_anonymous['is'];
6461
+ }
6462
+ }
6463
+ }
6464
+
6465
+ return $this->_is_anonymous;
6466
+ }
6467
+
6468
+ /**
6469
+ * Check if the user skipped the connection of a specified site.
6470
+ *
6471
+ * @author Vova Feldman (@svovaf)
6472
+ * @since 2.0.0
6473
+ *
6474
+ * @param int $blog_id
6475
+ *
6476
+ * @return bool
6477
+ */
6478
+ function is_anonymous_site( $blog_id = 0 ) {
6479
+ if ( $this->is_network_anonymous() ) {
6480
+ return true;
6481
+ }
6482
+
6483
+ $is_anonymous = $this->_storage->get( 'is_anonymous', false, $blog_id );
6484
+
6485
+ if ( empty( $is_anonymous ) ) {
6486
+ return false;
6487
+ }
6488
+
6489
+ return $is_anonymous['is'];
6490
+ }
6491
+
6492
+ /**
6493
+ * Check if user connected his account and install pending email activation.
6494
+ *
6495
+ * @author Vova Feldman (@svovaf)
6496
+ * @since 1.0.7
6497
+ *
6498
+ * @return bool
6499
+ */
6500
+ function is_pending_activation() {
6501
+ return $this->_storage->get( 'is_pending_activation', false );
6502
+ }
6503
+
6504
+ /**
6505
+ * @author Leo Fajardo (@leorw)
6506
+ * @since 2.5.0
6507
+ */
6508
+ private function clear_pending_activation_mode() {
6509
+ // Remove the pending activation sticky notice (if it still exists).
6510
+ $this->_admin_notices->remove_sticky( 'activation_pending' );
6511
+
6512
+ // Clear the plugin's pending activation mode.
6513
+ unset( $this->_storage->is_pending_activation );
6514
+ }
6515
+
6516
+ /**
6517
+ * Check if plugin must be WordPress.org compliant.
6518
+ *
6519
+ * @since 1.0.7
6520
+ *
6521
+ * @return bool
6522
+ */
6523
+ function is_org_repo_compliant() {
6524
+ return $this->_is_org_compliant;
6525
+ }
6526
+
6527
+ #--------------------------------------------------------------------------------
6528
+ #region WP Cron Common
6529
+ #--------------------------------------------------------------------------------
6530
+
6531
+ /**
6532
+ * @author Vova Feldman (@svovaf)
6533
+ * @since 2.0.0
6534
+ *
6535
+ * @param string $name Cron name.
6536
+ *
6537
+ * @return object
6538
+ */
6539
+ private function get_cron_data( $name ) {
6540
+ $this->_logger->entrance( $name );
6541
+
6542
+ /**
6543
+ * @var object $cron_data
6544
+ */
6545
+ return $this->_storage->get( "{$name}_cron", null );
6546
+ }
6547
+
6548
+ /**
6549
+ * @author Vova Feldman (@svovaf)
6550
+ * @since 2.0.0
6551
+ *
6552
+ * @param string $name Cron name.
6553
+ */
6554
+ private function clear_cron_data( $name ) {
6555
+ $this->_logger->entrance( $name );
6556
+
6557
+ $this->_storage->remove( "{$name}_cron" );
6558
+ }
6559
+
6560
+ /**
6561
+ * @author Vova Feldman (@svovaf)
6562
+ * @since 2.0.0
6563
+ *
6564
+ * @param string $name Cron name.
6565
+ * @param int $cron_blog_id The cron executing blog ID.
6566
+ */
6567
+ private function set_cron_data( $name, $cron_blog_id = 0 ) {
6568
+ $this->_logger->entrance( $name );
6569
+
6570
+ $this->_storage->store( "{$name}_cron", (object) array(
6571
+ 'version' => $this->get_plugin_version(),
6572
+ 'blog_id' => $cron_blog_id,
6573
+ 'sdk_version' => $this->version,
6574
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
6575
+ 'on' => true,
6576
+ ) );
6577
+ }
6578
+
6579
+ /**
6580
+ * Get the cron's executing blog ID.
6581
+ *
6582
+ * @author Vova Feldman (@svovaf)
6583
+ * @since 2.0.0
6584
+ *
6585
+ * @param string $name Cron name.
6586
+ *
6587
+ * @return int
6588
+ */
6589
+ private function get_cron_blog_id( $name ) {
6590
+ $this->_logger->entrance( $name );
6591
+
6592
+ if ( ! is_multisite() ) {
6593
+ // Not a multisite.
6594
+ return 0;
6595
+ }
6596
+
6597
+ $cron_data = $this->get_cron_data( $name );
6598
+
6599
+ return ( is_object( $cron_data ) && is_numeric( $cron_data->blog_id ) ) ?
6600
+ $cron_data->blog_id :
6601
+ 0;
6602
+ }
6603
+
6604
+ /**
6605
+ * @author Vova Feldman (@svovaf)
6606
+ * @since 2.0.0
6607
+ *
6608
+ * @param string $name Cron name.
6609
+ *
6610
+ * @return bool
6611
+ */
6612
+ private function is_cron_on( $name ) {
6613
+ $this->_logger->entrance( $name );
6614
+
6615
+ /**
6616
+ * @var object $cron_data
6617
+ */
6618
+ $cron_data = $this->get_cron_data( $name );
6619
+
6620
+ return ( ! is_null( $cron_data ) && true === $cron_data->on );
6621
+ }
6622
+
6623
+ /**
6624
+ * Unix timestamp for previous cron execution or false if never executed.
6625
+ *
6626
+ * @author Vova Feldman (@svovaf)
6627
+ * @since 2.0.0
6628
+ *
6629
+ * @param string $name Cron name.
6630
+ *
6631
+ * @return int|false
6632
+ */
6633
+ private function cron_last_execution( $name ) {
6634
+ $this->_logger->entrance( $name );
6635
+
6636
+ return $this->_storage->get( "{$name}_timestamp" );
6637
+ }
6638
+
6639
+ /**
6640
+ * Set cron execution time to now.
6641
+ *
6642
+ * @author Vova Feldman (@svovaf)
6643
+ * @since 2.0.0
6644
+ *
6645
+ * @param string $name Cron name.
6646
+ */
6647
+ private function set_cron_execution_timestamp( $name ) {
6648
+ $this->_logger->entrance( $name );
6649
+
6650
+ $this->_storage->store( "{$name}_timestamp", time() );
6651
+ }
6652
+
6653
+ /**
6654
+ * Sets the keepalive time to now.
6655
+ *
6656
+ * @author Leo Fajardo (@leorw)
6657
+ * @since 2.2.3
6658
+ *
6659
+ * @param bool|null $use_network_level_storage
6660
+ */
6661
+ private function set_keepalive_timestamp( $use_network_level_storage = null ) {
6662
+ $this->_logger->entrance();
6663
+
6664
+ $this->_storage->store( 'keepalive_timestamp', time(), $use_network_level_storage );
6665
+ }
6666
+
6667
+ /**
6668
+ * Check if cron was executed in the last $period of seconds.
6669
+ *
6670
+ * @author Vova Feldman (@svovaf)
6671
+ * @since 2.0.0
6672
+ *
6673
+ * @param string $name Cron name.
6674
+ * @param int $period In seconds
6675
+ *
6676
+ * @return bool
6677
+ */
6678
+ private function is_cron_executed( $name, $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
6679
+ $this->_logger->entrance( $name );
6680
+
6681
+ $last_execution = $this->cron_last_execution( $name );
6682
+
6683
+ if ( ! is_numeric( $last_execution ) ) {
6684
+ return false;
6685
+ }
6686
+
6687
+ return ( $last_execution > ( WP_FS__SCRIPT_START_TIME - $period ) );
6688
+ }
6689
+
6690
+ /**
6691
+ * WP Cron is executed on a site level. When running in a multisite network environment
6692
+ * with the network integration activated, for optimization reasons, we are consolidating
6693
+ * the installs data sync cron to be executed only from a single site.
6694
+ *
6695
+ * @author Vova Feldman (@svovaf)
6696
+ * @since 2.0.0
6697
+ *
6698
+ * @param int $except_blog_id Target any except the excluded blog ID.
6699
+ *
6700
+ * @return int
6701
+ */
6702
+ private function get_cron_target_blog_id( $except_blog_id = 0 ) {
6703
+ if ( ! is_multisite() ) {
6704
+ return 0;
6705
+ }
6706
+
6707
+ if ( $this->_is_network_active ) {
6708
+ $network_install_blog_id = $this->_storage->network_install_blog_id;
6709
+
6710
+ if (
6711
+ is_numeric( $network_install_blog_id ) &&
6712
+ $except_blog_id != $network_install_blog_id &&
6713
+ self::is_site_active( $network_install_blog_id )
6714
+ ) {
6715
+ // Try to run cron from the main network blog.
6716
+ $install = $this->get_install_by_blog_id( $network_install_blog_id );
6717
+
6718
+ if (
6719
+ is_object( $install ) &&
6720
+ $this->is_tracking_allowed( $network_install_blog_id, $install )
6721
+ ) {
6722
+ return $network_install_blog_id;
6723
+ }
6724
+ }
6725
+ }
6726
+
6727
+ // Get first opted-in blog ID with active tracking.
6728
+ $installs = $this->get_blog_install_map();
6729
+ foreach ( $installs as $blog_id => $install ) {
6730
+ if ( $except_blog_id != $blog_id &&
6731
+ self::is_site_active( $blog_id ) &&
6732
+ $this->is_tracking_allowed( $blog_id, $install )
6733
+ ) {
6734
+ return $blog_id;
6735
+ }
6736
+ }
6737
+
6738
+ return 0;
6739
+ }
6740
+
6741
+ /**
6742
+ * @author Vova Feldman (@svovaf)
6743
+ * @since 2.0.0
6744
+ *
6745
+ * @param string $name Cron name.
6746
+ * @param string $action_tag Callback action tag.
6747
+ * @param bool $is_network_clear If set to TRUE, clear sync cron even if there are installs that are still connected.
6748
+ */
6749
+ private function clear_cron( $name, $action_tag = '', $is_network_clear = false ) {
6750
+ $this->_logger->entrance( $name );
6751
+
6752
+ if ( ! $this->is_cron_on( $name ) ) {
6753
+ return;
6754
+ }
6755
+
6756
+ $clear_cron = true;
6757
+ if ( ! $is_network_clear && $this->_is_network_active ) {
6758
+ $installs = $this->get_blog_install_map();
6759
+
6760
+ foreach ( $installs as $blog_id => $install ) {
6761
+ /**
6762
+ * @var FS_Site $install
6763
+ */
6764
+ if ( $this->is_tracking_allowed( $blog_id, $install ) ) {
6765
+ $clear_cron = false;
6766
+ break;
6767
+ }
6768
+ }
6769
+ }
6770
+
6771
+ if ( ! $clear_cron ) {
6772
+ return;
6773
+ }
6774
+
6775
+ $cron_blog_id = $this->get_cron_blog_id( $name );
6776
+
6777
+ $this->clear_cron_data( $name );
6778
+
6779
+ if ( 0 < $cron_blog_id ) {
6780
+ switch_to_blog( $cron_blog_id );
6781
+ }
6782
+
6783
+ if ( empty( $action_tag ) ) {
6784
+ $action_tag = $name;
6785
+ }
6786
+
6787
+ wp_clear_scheduled_hook( $this->get_action_tag( $action_tag ) );
6788
+
6789
+ if ( 0 < $cron_blog_id ) {
6790
+ restore_current_blog();
6791
+ }
6792
+ }
6793
+
6794
+ /**
6795
+ * Unix timestamp for next cron execution or false if not scheduled.
6796
+ *
6797
+ * @author Vova Feldman (@svovaf)
6798
+ * @since 2.0.0
6799
+ *
6800
+ * @param string $name Cron name.
6801
+ * @param string $action_tag Callback action tag.
6802
+ *
6803
+ * @return int|false
6804
+ */
6805
+ private function get_next_scheduled_cron( $name, $action_tag = '' ) {
6806
+ $this->_logger->entrance( $name );
6807
+
6808
+ if ( ! $this->is_cron_on( $name ) ) {
6809
+ return false;
6810
+ }
6811
+
6812
+ $cron_blog_id = $this->get_cron_blog_id( $name );
6813
+
6814
+ if ( 0 < $cron_blog_id ) {
6815
+ switch_to_blog( $cron_blog_id );
6816
+ }
6817
+
6818
+ if ( empty( $action_tag ) ) {
6819
+ $action_tag = $name;
6820
+ }
6821
+
6822
+ $next_scheduled = wp_next_scheduled( $this->get_action_tag( $action_tag ) );
6823
+
6824
+ if ( 0 < $cron_blog_id ) {
6825
+ restore_current_blog();
6826
+ }
6827
+
6828
+ return $next_scheduled;
6829
+ }
6830
+
6831
+ /**
6832
+ * @author Vova Feldman (@svovaf)
6833
+ * @since 2.0.0
6834
+ *
6835
+ * @param string $name Cron name.
6836
+ * @param string $action_tag Callback action tag.
6837
+ * @param string $recurrence 'single' or 'daily'.
6838
+ * @param int $start_at Defaults to now.
6839
+ * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise, schedule job to start right away.
6840
+ * @param int $except_blog_id Target any except the excluded blog ID.
6841
+ */
6842
+ private function schedule_cron(
6843
+ $name,
6844
+ $action_tag = '',
6845
+ $recurrence = 'single',
6846
+ $start_at = WP_FS__SCRIPT_START_TIME,
6847
+ $randomize_start = true,
6848
+ $except_blog_id = 0
6849
+ ) {
6850
+ $this->_logger->entrance( $name );
6851
+
6852
+ $this->clear_cron( $name, $action_tag, true );
6853
+
6854
+ $cron_blog_id = $this->get_cron_target_blog_id( $except_blog_id );
6855
+
6856
+ if ( is_multisite() && 0 == $cron_blog_id ) {
6857
+ // Don't schedule cron since couldn't find a target blog.
6858
+ return;
6859
+ }
6860
+
6861
+ if ( 0 < $cron_blog_id ) {
6862
+ switch_to_blog( $cron_blog_id );
6863
+ }
6864
+
6865
+ if ( 'daily' === $recurrence ) {
6866
+ if ( $randomize_start ) {
6867
+ // Schedule first sync with a random 12 hour time range from now.
6868
+ $start_at += rand( 0, ( WP_FS__TIME_24_HOURS_IN_SEC / 2 ) );
6869
+ }
6870
+
6871
+ // Schedule daily WP cron.
6872
+ wp_schedule_event(
6873
+ $start_at,
6874
+ 'daily',
6875
+ $this->get_action_tag( $action_tag )
6876
+ );
6877
+ } else if ( 'single' === $recurrence ) {
6878
+ // Schedule single cron.
6879
+ wp_schedule_single_event(
6880
+ $start_at,
6881
+ $this->get_action_tag( $action_tag )
6882
+ );
6883
+ }
6884
+
6885
+ $this->set_cron_data( $name, $cron_blog_id );
6886
+
6887
+ if ( 0 < $cron_blog_id ) {
6888
+ restore_current_blog();
6889
+ }
6890
+ }
6891
+
6892
+ /**
6893
+ * Consolidated cron execution for performance optimization. The max number of API requests is based on the number of unique opted-in users.
6894
+ * that doesn't halt page loading.
6895
+ *
6896
+ * @author Vova Feldman (@svovaf)
6897
+ * @since 2.0.0
6898
+ *
6899
+ * @param string $name Cron name.
6900
+ * @param callable $callable The function that should be executed.
6901
+ */
6902
+ private function execute_cron( $name, $callable ) {
6903
+ $this->_logger->entrance( $name );
6904
+
6905
+ // Store the last time data sync was executed.
6906
+ $this->set_cron_execution_timestamp( $name );
6907
+
6908
+ // Check if API is temporary down.
6909
+ if ( FS_Api::is_temporary_down() ) {
6910
+ return;
6911
+ }
6912
+
6913
+ // @todo Add logic that identifies API latency, and reschedule the next background sync randomly between 8-16 hours.
6914
+
6915
+ $users_2_blog_ids = array();
6916
+
6917
+ if ( ! is_multisite() ) {
6918
+ // Add dummy blog.
6919
+ $users_2_blog_ids[0] = array( 0 );
6920
+ } else {
6921
+ $installs = $this->get_blog_install_map();
6922
+ foreach ( $installs as $blog_id => $install ) {
6923
+ if ( $this->is_tracking_allowed( $blog_id, $install ) ) {
6924
+ if ( ! isset( $users_2_blog_ids[ $install->user_id ] ) ) {
6925
+ $users_2_blog_ids[ $install->user_id ] = array();
6926
+ }
6927
+
6928
+ $users_2_blog_ids[ $install->user_id ][] = $blog_id;
6929
+ }
6930
+ }
6931
+ }
6932
+
6933
+ $current_blog_id = get_current_blog_id();
6934
+
6935
+ foreach ( $users_2_blog_ids as $user_id => $blog_ids ) {
6936
+ if ( 0 < $blog_ids[0] ) {
6937
+ $this->switch_to_blog( $blog_ids[0] );
6938
+ }
6939
+
6940
+ call_user_func_array( $callable, array( $blog_ids, ( is_multisite() ? $current_blog_id : null ) ) );
6941
+
6942
+ foreach ( $blog_ids as $blog_id ) {
6943
+ $this->do_action( "after_{$name}_cron", $blog_id );
6944
+ }
6945
+ }
6946
+
6947
+ if ( is_multisite() ) {
6948
+ $this->switch_to_blog( $current_blog_id, fs_is_network_admin() ? $this->get_network_install() : null );
6949
+
6950
+ $this->do_action( "after_{$name}_cron_multisite" );
6951
+ }
6952
+ }
6953
+
6954
+ #endregion
6955
+
6956
+ #----------------------------------------------------------------------------------
6957
+ #region Daily Sync Cron
6958
+ #----------------------------------------------------------------------------------
6959
+
6960
+
6961
+ /**
6962
+ * @author Vova Feldman (@svovaf)
6963
+ * @since 2.0.0
6964
+ *
6965
+ * @return bool
6966
+ */
6967
+ private function is_sync_cron_scheduled() {
6968
+ return $this->is_cron_on( 'sync' );
6969
+ }
6970
+
6971
+ /**
6972
+ * Get the sync cron's executing blog ID.
6973
+ *
6974
+ * @author Vova Feldman (@svovaf)
6975
+ * @since 2.0.0
6976
+ *
6977
+ * @return int
6978
+ */
6979
+ private function get_sync_cron_blog_id() {
6980
+ return $this->get_cron_blog_id( 'sync' );
6981
+ }
6982
+
6983
+ /**
6984
+ * @author Vova Feldman (@svovaf)
6985
+ * @since 1.1.7.3
6986
+ */
6987
+ private function run_manual_sync() {
6988
+ if ( ! $this->is_user_admin() ) {
6989
+ return;
6990
+ }
6991
+
6992
+ // Run manual sync.
6993
+ $this->_sync_cron();
6994
+
6995
+ // Reschedule next cron to run 24 hours from now (performance optimization).
6996
+ $this->schedule_sync_cron( time() + WP_FS__TIME_24_HOURS_IN_SEC, false );
6997
+ }
6998
+
6999
+ /**
7000
+ * Data sync cron job. Replaces the background sync non blocking HTTP request
7001
+ * that doesn't halt page loading.
7002
+ *
7003
+ * @author Vova Feldman (@svovaf)
7004
+ * @since 1.1.7.3
7005
+ * @since 2.0.0 Consolidate all the data sync into the same cron for performance optimization. The max number of API requests is based on the number of unique opted-in users.
7006
+ */
7007
+ function _sync_cron() {
7008
+ $this->_logger->entrance();
7009
+
7010
+ $this->execute_cron( 'sync', array( &$this, '_sync_cron_method' ) );
7011
+ }
7012
+
7013
+ /**
7014
+ * The actual data sync cron logic.
7015
+ *
7016
+ * @author Vova Feldman (@svovaf)
7017
+ * @since 2.0.0
7018
+ *
7019
+ * @param int[] $blog_ids
7020
+ * @param int|null $current_blog_id @since 2.2.3. This is passed from the `execute_cron` method and used by the
7021
+ * `_sync_plugin_license` method in order to switch to the previous blog when sending
7022
+ * updates for a single site in case `execute_cron` has switched to a different blog.
7023
+ */
7024
+ function _sync_cron_method( array $blog_ids, $current_blog_id = null ) {
7025
+ if ( $this->is_registered() ) {
7026
+ if ( $this->has_paid_plan() ) {
7027
+ // Initiate background plan sync.
7028
+ $this->_sync_license( true, false, $current_blog_id );
7029
+
7030
+ if ( $this->is_paying() ) {
7031
+ // Check for premium plugin updates.
7032
+ $this->check_updates( true );
7033
+ }
7034
+ } else {
7035
+ // Sync install(s) (only if something changed locally).
7036
+ if ( 1 < count( $blog_ids ) ) {
7037
+ $this->sync_installs();
7038
+ } else {
7039
+ $this->sync_install();
7040
+ }
7041
+
7042
+ $this->maybe_sync_install_user();
7043
+ }
7044
+ }
7045
+ }
7046
+
7047
+ /**
7048
+ * Check if sync was executed in the last $period of seconds.
7049
+ *
7050
+ * @author Vova Feldman (@svovaf)
7051
+ * @since 1.1.7.3
7052
+ *
7053
+ * @param int $period In seconds
7054
+ *
7055
+ * @return bool
7056
+ */
7057
+ private function is_sync_executed( $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
7058
+ return $this->is_cron_executed( 'sync', $period );
7059
+ }
7060
+
7061
+ /**
7062
+ * @author Vova Feldman (@svovaf)
7063
+ * @since 1.1.7.3
7064
+ *
7065
+ * @return bool
7066
+ */
7067
+ private function is_sync_cron_on() {
7068
+ return $this->is_cron_on( 'sync' );
7069
+ }
7070
+
7071
+ /**
7072
+ * @author Leo Fajardo (@leorw)
7073
+ * @since 2.5.0
7074
+ */
7075
+ private function maybe_schedule_sync_cron() {
7076
+ $next_schedule = $this->next_sync_cron();
7077
+
7078
+ // The event is properly scheduled, so no need to reschedule it.
7079
+ if (
7080
+ is_numeric( $next_schedule ) &&
7081
+ $next_schedule > time()
7082
+ ) {
7083
+ return;
7084
+ }
7085
+
7086
+ $this->schedule_sync_cron();
7087
+ }
7088
+
7089
+ /**
7090
+ * @author Vova Feldman (@svovaf)
7091
+ * @since 1.1.7.3
7092
+ *
7093
+ * @param int $start_at Defaults to now.
7094
+ * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise, schedule job to start right away.
7095
+ * @param int $except_blog_id Since 2.0.0 when running in a multisite network environment, the cron execution is consolidated. This param allows excluding excluded specified blog ID from being the cron executor.
7096
+ */
7097
+ private function schedule_sync_cron(
7098
+ $start_at = WP_FS__SCRIPT_START_TIME,
7099
+ $randomize_start = true,
7100
+ $except_blog_id = 0
7101
+ ) {
7102
+ $this->schedule_cron(
7103
+ 'sync',
7104
+ 'data_sync',
7105
+ 'daily',
7106
+ $start_at,
7107
+ $randomize_start,
7108
+ $except_blog_id
7109
+ );
7110
+ }
7111
+
7112
+ /**
7113
+ * Add the actual sync function to the cron job hook.
7114
+ *
7115
+ * @author Vova Feldman (@svovaf)
7116
+ * @since 1.1.7.3
7117
+ */
7118
+ private function hook_callback_to_sync_cron() {
7119
+ $this->add_action( 'data_sync', array( &$this, '_sync_cron' ) );
7120
+ }
7121
+
7122
+ /**
7123
+ * @author Vova Feldman (@svovaf)
7124
+ * @since 1.1.7.3
7125
+ *
7126
+ * @param bool $is_network_clear Since 2.0.0 If set to TRUE, clear sync cron even if there are installs that are still connected.
7127
+ */
7128
+ private function clear_sync_cron( $is_network_clear = false ) {
7129
+ $this->_logger->entrance();
7130
+
7131
+ $this->clear_cron( 'sync', 'data_sync', $is_network_clear );
7132
+ }
7133
+
7134
+ /**
7135
+ * Unix timestamp for next sync cron execution or false if not scheduled.
7136
+ *
7137
+ * @author Vova Feldman (@svovaf)
7138
+ * @since 1.1.7.3
7139
+ *
7140
+ * @return int|false
7141
+ */
7142
+ function next_sync_cron() {
7143
+ return $this->get_next_scheduled_cron( 'sync', 'data_sync' );
7144
+ }
7145
+
7146
+ /**
7147
+ * Unix timestamp for previous sync cron execution or false if never executed.
7148
+ *
7149
+ * @author Vova Feldman (@svovaf)
7150
+ * @since 1.1.7.3
7151
+ *
7152
+ * @return int|false
7153
+ */
7154
+ function last_sync_cron() {
7155
+ return $this->cron_last_execution( 'sync' );
7156
+ }
7157
+
7158
+ #endregion Daily Sync Cron ------------------------------------------------------------------
7159
+
7160
+ #----------------------------------------------------------------------------------
7161
+ #region Async Install Sync
7162
+ #----------------------------------------------------------------------------------
7163
+
7164
+ /**
7165
+ * @author Vova Feldman (@svovaf)
7166
+ * @since 1.1.7.3
7167
+ *
7168
+ * @return bool
7169
+ */
7170
+ private function is_install_sync_scheduled() {
7171
+ return $this->is_cron_on( 'install_sync' );
7172
+ }
7173
+
7174
+ /**
7175
+ * Get the sync cron's executing blog ID.
7176
+ *
7177
+ * @author Vova Feldman (@svovaf)
7178
+ * @since 2.0.0
7179
+ *
7180
+ * @return int
7181
+ */
7182
+ private function get_install_sync_cron_blog_id() {
7183
+ return $this->get_cron_blog_id( 'install_sync' );
7184
+ }
7185
+
7186
+ /**
7187
+ * Instead of running blocking install sync event, execute non blocking scheduled wp-cron.
7188
+ *
7189
+ * @author Vova Feldman (@svovaf)
7190
+ * @since 1.1.7.3
7191
+ *
7192
+ * @param int $except_blog_id Since 2.0.0 when running in a multisite network environment, the cron execution is consolidated. This param allows excluding excluded specified blog ID from being the cron executor.
7193
+ */
7194
+ private function schedule_install_sync( $except_blog_id = 0 ) {
7195
+ if ( $this->is_clone() ) {
7196
+ return;
7197
+ }
7198
+
7199
+ $this->schedule_cron( 'install_sync', 'install_sync', 'single', WP_FS__SCRIPT_START_TIME, false, $except_blog_id );
7200
+ }
7201
+
7202
+ /**
7203
+ * Unix timestamp for previous install sync cron execution or false if never executed.
7204
+ *
7205
+ * @todo There's some very strange bug that $this->_storage->install_sync_timestamp value is not being updated. But for sure the sync event is working.
7206
+ *
7207
+ * @author Vova Feldman (@svovaf)
7208
+ * @since 1.1.7.3
7209
+ *
7210
+ * @return int|false
7211
+ */
7212
+ function last_install_sync() {
7213
+ return $this->cron_last_execution( 'install_sync' );
7214
+ }
7215
+
7216
+ /**
7217
+ * Unix timestamp for next install sync cron execution or false if not scheduled.
7218
+ *
7219
+ * @author Vova Feldman (@svovaf)
7220
+ * @since 1.1.7.3
7221
+ *
7222
+ * @return int|false
7223
+ */
7224
+ function next_install_sync() {
7225
+ return $this->get_next_scheduled_cron( 'install_sync', 'install_sync' );
7226
+ }
7227
+
7228
+ /**
7229
+ * Add the actual install sync function to the cron job hook.
7230
+ *
7231
+ * @author Vova Feldman (@svovaf)
7232
+ * @since 1.1.7.3
7233
+ */
7234
+ private function hook_callback_to_install_sync() {
7235
+ $this->add_action( 'install_sync', array( &$this, '_run_sync_install' ) );
7236
+ }
7237
+
7238
+ /**
7239
+ * @author Vova Feldman (@svovaf)
7240
+ * @since 1.1.7.3
7241
+ *
7242
+ * @param bool $is_network_clear Since 2.0.0 If set to TRUE, clear sync cron even if there are installs that are still connected.
7243
+ */
7244
+ private function clear_install_sync_cron( $is_network_clear = false ) {
7245
+ $this->_logger->entrance();
7246
+
7247
+ $this->clear_cron( 'install_sync', 'install_sync', $is_network_clear );
7248
+ }
7249
+
7250
+ /**
7251
+ * @author Vova Feldman (@svovaf)
7252
+ * @since 1.1.7.3
7253
+ * @since 2.0.0 Consolidate all the data sync into the same cron for performance optimization. The max number of API requests is based on the number of unique opted-in users.
7254
+ */
7255
+ public function _run_sync_install() {
7256
+ $this->_logger->entrance();
7257
+
7258
+ $this->execute_cron( 'sync', array( &$this, '_sync_install_cron_method' ) );
7259
+ }
7260
+
7261
+ /**
7262
+ * The actual install(s) sync cron logic.
7263
+ *
7264
+ * @author Vova Feldman (@svovaf)
7265
+ * @since 2.0.0
7266
+ *
7267
+ * @param int[] $blog_ids
7268
+ * @param int|null $current_blog_id
7269
+ */
7270
+ function _sync_install_cron_method( array $blog_ids, $current_blog_id = null ) {
7271
+ if ( $this->is_registered() ) {
7272
+ if ( 1 < count( $blog_ids ) ) {
7273
+ $this->sync_installs( array(), true );
7274
+ } else {
7275
+ $this->sync_install( array(), true );
7276
+ }
7277
+
7278
+ $this->maybe_sync_install_user();
7279
+ }
7280
+ }
7281
+
7282
+ #endregion Async Install Sync ------------------------------------------------------------------
7283
+
7284
+ /**
7285
+ * Show a notice that activation is currently pending.
7286
+ *
7287
+ * @todo Add some sort of mechanism to allow users to update the email address they would like to opt-in with when $is_suspicious_email is true.
7288
+ *
7289
+ * @author Vova Feldman (@svovaf)
7290
+ * @since 1.0.7
7291
+ *
7292
+ * @param bool|string $email
7293
+ * @param bool $is_pending_trial Since 1.2.1.5
7294
+ * @param bool $is_suspicious_email Since 2.5.0 Set to true when there's an indication that email address the user opted in with is fake/dummy/placeholder.
7295
+ */
7296
+ function _add_pending_activation_notice(
7297
+ $email = false,
7298
+ $is_pending_trial = false,
7299
+ $is_suspicious_email = false
7300
+ ) {
7301
+ if ( ! is_string( $email ) ) {
7302
+ $current_user = self::_get_current_wp_user();
7303
+ $email = $current_user->user_email;
7304
+ }
7305
+
7306
+ $this->_admin_notices->add_sticky(
7307
+ sprintf(
7308
+ $this->get_text_inline( 'You should receive an activation email for %s to your mailbox at %s. Please make sure you click the activation button in that email to %s.', 'pending-activation-message' ),
7309
+ '<b>' . $this->get_plugin_name() . '</b>',
7310
+ '<b>' . $email . '</b>',
7311
+ ( $is_pending_trial ?
7312
+ $this->get_text_inline( 'start the trial', 'start-the-trial' ) :
7313
+ $this->get_text_inline( 'complete the install', 'complete-the-install' ) )
7314
+ ),
7315
+ 'activation_pending',
7316
+ 'Thanks!'
7317
+ );
7318
+ }
7319
+
7320
+ /**
7321
+ * Check if currently in plugin activation.
7322
+ *
7323
+ * @author Vova Feldman (@svovaf)
7324
+ * @since 1.1.4
7325
+ *
7326
+ * @return bool
7327
+ */
7328
+ function is_plugin_activation() {
7329
+ $result = get_transient( "fs_{$this->_module_type}_{$this->_slug}_activated" );
7330
+
7331
+ return !empty($result);
7332
+ }
7333
+
7334
+ /**
7335
+ *
7336
+ * NOTE: admin_menu action executed before admin_init.
7337
+ *
7338
+ * @author Vova Feldman (@svovaf)
7339
+ * @since 1.0.7
7340
+ */
7341
+ function _admin_init_action() {
7342
+ $is_migration = $this->is_migration();
7343
+
7344
+ /**
7345
+ * Automatically redirect to connect/activation page after plugin activation.
7346
+ *
7347
+ * @since 1.1.7 Do NOT redirect to opt-in when running in network admin mode.
7348
+ */
7349
+ if ( $this->is_plugin_activation() ) {
7350
+ delete_transient( "fs_{$this->_module_type}_{$this->_slug}_activated" );
7351
+
7352
+ if ( isset( $_GET['activate-multi'] ) ) {
7353
+ /**
7354
+ * Don't redirect if activating multiple plugins at once (bulk activation).
7355
+ */
7356
+ } else if (
7357
+ self::is_deactivation_snoozed() &&
7358
+ (
7359
+ // Either running the free code base.
7360
+ ! $this->is_premium() ||
7361
+ // Or if has a free version.
7362
+ ! $this->is_only_premium() ||
7363
+ // If premium only, don't redirect if license is activated.
7364
+ ( $this->is_registered() && ! $this->can_use_premium_code() )
7365
+ )
7366
+ ) {
7367
+ /**
7368
+ * Don't redirect if activating during the deactivation snooze period (aka troubleshooting), unless activating a paid product version that the admin didn't enter its license key yet.
7369
+ */
7370
+ } else if ( ! $is_migration ) {
7371
+ $this->_redirect_on_activation_hook();
7372
+ return;
7373
+ }
7374
+ }
7375
+
7376
+ if ( $is_migration ) {
7377
+ return;
7378
+ }
7379
+
7380
+ if ( fs_request_is_action( $this->get_unique_affix() . '_skip_activation' ) ) {
7381
+ check_admin_referer( $this->get_unique_affix() . '_skip_activation' );
7382
+
7383
+ $this->skip_connection( fs_is_network_admin() );
7384
+
7385
+ fs_redirect( $this->get_after_activation_url( 'after_skip_url' ) );
7386
+ }
7387
+
7388
+ if ( $this->is_network_activation_mode() &&
7389
+ fs_request_is_action( $this->get_unique_affix() . '_delegate_activation' )
7390
+ ) {
7391
+ check_admin_referer( $this->get_unique_affix() . '_delegate_activation' );
7392
+
7393
+ $this->delegate_connection();
7394
+
7395
+ fs_redirect( $this->get_after_activation_url( 'after_delegation_url' ) );
7396
+ }
7397
+
7398
+ $this->_add_upgrade_action_link();
7399
+
7400
+ if ( ! ( ! $this->_is_network_active && fs_is_network_admin() ) &&
7401
+ (
7402
+ ( true === $this->_storage->require_license_activation ) ||
7403
+ // Not registered nor anonymous.
7404
+ ( ! $this->is_registered() && ! $this->is_anonymous() ) ||
7405
+ // OR, network level and in network upgrade mode.
7406
+ ( fs_is_network_admin() && $this->_is_network_active && $this->is_network_upgrade_mode() )
7407
+ )
7408
+ ) {
7409
+ if ( ! $this->is_pending_activation() ) {
7410
+ if ( ! $this->is_activation_page() ) {
7411
+ /**
7412
+ * If a user visits any other admin page before activating the premium-only theme with a valid
7413
+ * license, reactivate the previous theme.
7414
+ *
7415
+ * @author Leo Fajardo (@leorw)
7416
+ * @since 1.2.2
7417
+ */
7418
+ if ( $this->is_theme() &&
7419
+ ! $this->has_settings_menu() &&
7420
+ ! isset( $_REQUEST['fs_action'] ) &&
7421
+ $this->can_activate_previous_theme()
7422
+ ) {
7423
+ if ( $this->is_only_premium() ) {
7424
+ $this->activate_previous_theme();
7425
+ return;
7426
+ }
7427
+
7428
+ if ( true === $this->_storage->require_license_activation ) {
7429
+ $this->_storage->require_license_activation = false;
7430
+ }
7431
+ }
7432
+
7433
+ if ( ! fs_is_network_admin() &&
7434
+ $this->is_network_activation_mode() &&
7435
+ ! $this->is_delegated_connection()
7436
+ ) {
7437
+ return;
7438
+ }
7439
+
7440
+ if ( $this->is_plugin_new_install() || $this->is_only_premium() ) {
7441
+ if ( ! $this->_anonymous_mode &&
7442
+ ( ! $this->is_addon() || ! $this->_parent->is_anonymous() ) ) {
7443
+ // Show notice for new plugin installations.
7444
+ $this->_admin_notices->add(
7445
+ sprintf(
7446
+ $this->get_text_inline( 'You are just one step away - %s', 'you-are-step-away' ),
7447
+ sprintf( '<b><a href="%s">%s</a></b>',
7448
+ $this->get_activation_url( array(), ! $this->is_delegated_connection() ),
7449
+ sprintf( $this->get_text_x_inline( 'Complete "%s" Activation Now',
7450
+ '%s - plugin name. As complete "PluginX" activation now', 'activate-x-now' ), $this->get_plugin_name() )
7451
+ )
7452
+ ),
7453
+ '',
7454
+ 'update-nag'
7455
+ );
7456
+ }
7457
+ } else {
7458
+ if ( $this->should_add_sticky_optin_notice() ) {
7459
+ $this->add_sticky_optin_admin_notice();
7460
+ }
7461
+
7462
+ if ( $this->has_filter( 'optin_pointer_element' ) ) {
7463
+ // Don't show admin nag if plugin update.
7464
+ wp_enqueue_script( 'wp-pointer' );
7465
+ wp_enqueue_style( 'wp-pointer' );
7466
+
7467
+ $this->_enqueue_connect_essentials();
7468
+
7469
+ add_action( 'admin_print_footer_scripts', array(
7470
+ $this,
7471
+ '_add_connect_pointer_script'
7472
+ ) );
7473
+ }
7474
+ }
7475
+ }
7476
+ }
7477
+
7478
+ if ( $this->show_opt_in_on_themes_page() &&
7479
+ $this->is_activation_page()
7480
+ ) {
7481
+ $this->_show_theme_activation_optin_dialog();
7482
+ }
7483
+ }
7484
+ }
7485
+
7486
+ /**
7487
+ * @author Vova Feldman (@svovaf)
7488
+ * @since 2.0.0
7489
+ *
7490
+ * @return bool
7491
+ */
7492
+ private function should_add_sticky_optin_notice() {
7493
+ if ( $this->is_addon() && $this->_parent->is_anonymous() ) {
7494
+ return false;
7495
+ }
7496
+
7497
+ if ( fs_is_network_admin() ) {
7498
+ if ( ! $this->_is_network_active ) {
7499
+ return false;
7500
+ }
7501
+
7502
+ if ( ! $this->is_network_activation_mode() ) {
7503
+ return false;
7504
+ }
7505
+
7506
+ return ! isset( $this->_storage->sticky_optin_added_ms );
7507
+ }
7508
+
7509
+ if ( ! $this->is_activation_mode() ) {
7510
+ return false;
7511
+ }
7512
+
7513
+ // If running from a blog admin and delegated the connection.
7514
+ return ! isset( $this->_storage->sticky_optin_added );
7515
+ }
7516
+
7517
+ /**
7518
+ * @author Leo Fajardo (@leorw)
7519
+ * @since 2.0.0
7520
+ */
7521
+ private function add_sticky_optin_admin_notice() {
7522
+ if ( ! $this->_is_network_active || ! fs_is_network_admin() ) {
7523
+ $this->_storage->sticky_optin_added = true;
7524
+ } else {
7525
+ $this->_storage->sticky_optin_added_ms = true;
7526
+ }
7527
+
7528
+ // Show notice for new plugin installations.
7529
+ $this->_admin_notices->add_sticky(
7530
+ sprintf(
7531
+ $this->get_text_inline( 'We made a few tweaks to the %s, %s', 'few-plugin-tweaks' ),
7532
+ $this->_module_type,
7533
+ sprintf( '<b><a href="%s">%s</a></b>',
7534
+ $this->get_activation_url(),
7535
+ sprintf( $this->get_text_inline( 'Opt in to make "%s" better!', 'optin-x-now' ), $this->get_plugin_name() )
7536
+ )
7537
+ ),
7538
+ 'connect_account',
7539
+ '',
7540
+ 'update-nag'
7541
+ );
7542
+ }
7543
+
7544
+ /**
7545
+ * Enqueue connect requires scripts and styles.
7546
+ *
7547
+ * @author Vova Feldman (@svovaf)
7548
+ * @since 1.1.4
7549
+ */
7550
+ function _enqueue_connect_essentials() {
7551
+ wp_enqueue_script( 'jquery' );
7552
+ wp_enqueue_script( 'json2' );
7553
+
7554
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
7555
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
7556
+ }
7557
+
7558
+ /**
7559
+ * Add connect / opt-in pointer.
7560
+ *
7561
+ * @author Vova Feldman (@svovaf)
7562
+ * @since 1.1.4
7563
+ */
7564
+ function _add_connect_pointer_script() {
7565
+ $vars = array( 'id' => $this->_module_id );
7566
+ $pointer_content = fs_get_template( 'connect.php', $vars );
7567
+ ?>
7568
+ <script type="text/javascript">// <![CDATA[
7569
+ jQuery(document).ready(function ($) {
7570
+ if ('undefined' !== typeof(jQuery().pointer)) {
7571
+
7572
+ var element = <?php echo $this->apply_filters( 'optin_pointer_element', '$("#non_existing_element");' ) ?>;
7573
+
7574
+ if (element.length > 0) {
7575
+ var optin = $(element).pointer($.extend(true, {}, {
7576
+ content : <?php echo json_encode( $pointer_content ) ?>,
7577
+ position : {
7578
+ edge : 'left',
7579
+ align: 'center'
7580
+ },
7581
+ buttons : function () {
7582
+ // Don't show pointer buttons.
7583
+ return '';
7584
+ },
7585
+ pointerWidth: 482
7586
+ }, <?php echo $this->apply_filters( 'optin_pointer_options_json', '{}' ) ?>));
7587
+
7588
+ <?php
7589
+ echo $this->apply_filters( 'optin_pointer_execute', "
7590
+
7591
+ optin.pointer('open');
7592
+
7593
+ // Tag the opt-in pointer with custom class.
7594
+ $('.wp-pointer #fs_connect')
7595
+ .parents('.wp-pointer.wp-pointer-top')
7596
+ .addClass('fs-opt-in-pointer');
7597
+
7598
+ ", 'element', 'optin' ) ?>
7599
+ }
7600
+ }
7601
+ });
7602
+ // ]]></script>
7603
+ <?php
7604
+ }
7605
+
7606
+ /**
7607
+ * Return current page's URL.
7608
+ *
7609
+ * @author Vova Feldman (@svovaf)
7610
+ * @since 1.0.7
7611
+ *
7612
+ * @return string
7613
+ */
7614
+ static function current_page_url() {
7615
+ $url = 'http';
7616
+
7617
+ if ( isset( $_SERVER["HTTPS"] ) ) {
7618
+ if ( $_SERVER["HTTPS"] == "on" ) {
7619
+ $url .= "s";
7620
+ }
7621
+ }
7622
+ $url .= "://";
7623
+ if ( $_SERVER["SERVER_PORT"] != "80" ) {
7624
+ $url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
7625
+ } else {
7626
+ $url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
7627
+ }
7628
+
7629
+ return esc_url( $url );
7630
+ }
7631
+
7632
+ /**
7633
+ * Check if the current page is the plugin's main admin settings page.
7634
+ *
7635
+ * @author Vova Feldman (@svovaf)
7636
+ * @since 1.0.7
7637
+ *
7638
+ * @return bool
7639
+ */
7640
+ function _is_plugin_page() {
7641
+ return fs_is_plugin_page( $this->_menu->get_raw_slug() ) ||
7642
+ fs_is_plugin_page( $this->_slug );
7643
+ }
7644
+
7645
+ /* Events
7646
+ ------------------------------------------------------------------------------------------------------------------*/
7647
+ /**
7648
+ * Delete site install from Database.
7649
+ *
7650
+ * @author Vova Feldman (@svovaf)
7651
+ * @since 1.0.1
7652
+ *
7653
+ * @param bool $store
7654
+ * @param int|null $blog_id Since 2.0.0
7655
+ *
7656
+ * @return false|int The install ID if deleted. Otherwise, FALSE (when install not exist).
7657
+ */
7658
+ function _delete_site( $store = true, $blog_id = null ) {
7659
+ return self::_delete_site_by_slug( $this->_slug, $this->_module_type, $store, $blog_id );
7660
+ }
7661
+
7662
+ /**
7663
+ * Delete site install from Database.
7664
+ *
7665
+ * @author Vova Feldman (@svovaf)
7666
+ * @since 1.2.2.7
7667
+ *
7668
+ * @param string $slug
7669
+ * @param string $module_type
7670
+ * @param bool $store
7671
+ * @param int|null $blog_id Since 2.0.0
7672
+ *
7673
+ * @return false|int The install ID if deleted. Otherwise, FALSE (when install not exist).
7674
+ */
7675
+ static function _delete_site_by_slug( $slug, $module_type, $store = true, $blog_id = null ) {
7676
+ $sites = self::get_all_sites( $module_type, $blog_id );
7677
+
7678
+ $install_id = false;
7679
+
7680
+ if ( isset( $sites[ $slug ] ) ) {
7681
+ if ( is_object( $sites[ $slug ] ) ) {
7682
+ $install_id = $sites[ $slug ]->id;
7683
+ }
7684
+
7685
+ unset( $sites[ $slug ] );
7686
+
7687
+ self::set_account_option_by_module( $module_type, 'sites', $sites, $store, $blog_id );
7688
+ }
7689
+
7690
+ return $install_id;
7691
+ }
7692
+
7693
+ /**
7694
+ * Delete user.
7695
+ *
7696
+ * @author Vova Feldman (@svovaf)
7697
+ * @since 2.0.0
7698
+ *
7699
+ * @param number $user_id
7700
+ * @param bool $store
7701
+ *
7702
+ * @return false|int The user ID if deleted. Otherwise, FALSE (when install not exist).
7703
+ */
7704
+ private static function delete_user( $user_id, $store = true ) {
7705
+ $users = self::get_all_users();
7706
+
7707
+ if ( ! is_array( $users ) || ! isset( $users[ $user_id ] ) ) {
7708
+ return false;
7709
+ }
7710
+
7711
+ unset( $users[ $user_id ] );
7712
+
7713
+ self::$_accounts->set_option( 'users', $users, $store );
7714
+
7715
+ return $user_id;
7716
+ }
7717
+
7718
+ /**
7719
+ * Delete plugin's plans information.
7720
+ *
7721
+ * @param bool $store Flush to Database if true.
7722
+ * @param bool $keep_associated_plans If set to false, delete all plans, even if a plan is associated with an install.
7723
+ *
7724
+ * @author Vova Feldman (@svovaf)
7725
+ * @since 1.0.9
7726
+ */
7727
+ private function _delete_plans( $store = true, $keep_associated_plans = true ) {
7728
+ $this->_logger->entrance();
7729
+
7730
+ $plans = self::get_all_plans( $this->_module_type );
7731
+
7732
+ $plans_to_keep = array();
7733
+
7734
+ if ( $keep_associated_plans ) {
7735
+ $plans_ids_to_keep = $this->get_plans_ids_associated_with_installs();
7736
+ foreach ( $plans_ids_to_keep as $plan_id ) {
7737
+ $plan = self::_get_plan_by_id( $plan_id );
7738
+ if ( is_object( $plan ) ) {
7739
+ $plans_to_keep[] = self::_encrypt_entity( $plan );
7740
+ }
7741
+ }
7742
+ }
7743
+
7744
+ if ( ! empty( $plans_to_keep ) ) {
7745
+ $plans[ $this->_slug ] = $plans_to_keep;
7746
+ } else {
7747
+ unset( $plans[ $this->_slug ] );
7748
+ }
7749
+
7750
+ $this->set_account_option( 'plans', $plans, $store );
7751
+ }
7752
+
7753
+ /**
7754
+ * Delete all plugin licenses.
7755
+ *
7756
+ * @author Vova Feldman (@svovaf)
7757
+ * @since 1.0.9
7758
+ *
7759
+ * @param bool $store
7760
+ */
7761
+ private function _delete_licenses( $store = true ) {
7762
+ $this->_logger->entrance();
7763
+
7764
+ $all_licenses = self::get_all_licenses();
7765
+
7766
+ unset( $all_licenses[ $this->_module_id ] );
7767
+
7768
+ self::$_accounts->set_option( 'all_licenses', $all_licenses, $store );
7769
+ }
7770
+
7771
+ /**
7772
+ * Check if Freemius was added on new plugin installation.
7773
+ *
7774
+ * @author Vova Feldman (@svovaf)
7775
+ * @since 1.1.5
7776
+ *
7777
+ * @return bool
7778
+ */
7779
+ function is_plugin_new_install() {
7780
+ return isset( $this->_storage->is_plugin_new_install ) &&
7781
+ $this->_storage->is_plugin_new_install;
7782
+ }
7783
+
7784
+ /**
7785
+ * Check if it's the first plugin release that is running Freemius.
7786
+ *
7787
+ * @author Vova Feldman (@svovaf)
7788
+ * @since 1.2.1.5
7789
+ *
7790
+ * @return bool
7791
+ */
7792
+ function is_first_freemius_powered_version() {
7793
+ return empty( $this->_storage->plugin_last_version );
7794
+ }
7795
+
7796
+ /**
7797
+ * @author Leo Fajardo (@leorw)
7798
+ * @since 1.2.2
7799
+ *
7800
+ * @return bool|string
7801
+ */
7802
+ private function get_previous_theme_slug() {
7803
+ return isset( $this->_storage->previous_theme ) ?
7804
+ $this->_storage->previous_theme :
7805
+ false;
7806
+ }
7807
+
7808
+ /**
7809
+ * @author Leo Fajardo (@leorw)
7810
+ * @since 1.2.2
7811
+ *
7812
+ * @return bool
7813
+ */
7814
+ private function can_activate_previous_theme() {
7815
+ return $this->can_activate_theme( $this->get_previous_theme_slug() );
7816
+ }
7817
+
7818
+ /**
7819
+ * @author Leo Fajardo (@leorw)
7820
+ * @since 2.5.0
7821
+ *
7822
+ * @return bool
7823
+ */
7824
+ private function can_activate_theme( $slug ) {
7825
+ if ( false !== $slug && current_user_can( 'switch_themes' ) ) {
7826
+ $theme_instance = wp_get_theme( $slug );
7827
+
7828
+ return $theme_instance->exists();
7829
+ }
7830
+
7831
+ return false;
7832
+ }
7833
+
7834
+ /**
7835
+ * @author Leo Fajardo (@leorw)
7836
+ * @since 1.2.2
7837
+ */
7838
+ private function activate_previous_theme() {
7839
+ switch_theme( $this->get_previous_theme_slug() );
7840
+ unset( $this->_storage->previous_theme );
7841
+
7842
+ global $pagenow;
7843
+ if ( 'themes.php' === $pagenow ) {
7844
+ /**
7845
+ * Refresh the active theme information.
7846
+ *
7847
+ * @author Leo Fajardo (@leorw)
7848
+ * @since 1.2.2
7849
+ */
7850
+ fs_redirect( $this->admin_url( $pagenow ) );
7851
+ }
7852
+ }
7853
+
7854
+ /**
7855
+ * @author Leo Fajardo (@leorw)
7856
+ * @since 1.2.2
7857
+ *
7858
+ * @return string
7859
+ */
7860
+ function get_previous_theme_activation_url() {
7861
+ if ( ! $this->can_activate_previous_theme() ) {
7862
+ return '';
7863
+ }
7864
+
7865
+ /**
7866
+ * Activation URL
7867
+ *
7868
+ * @author Leo Fajardo (@leorw)
7869
+ * @since 1.2.2
7870
+ */
7871
+ return wp_nonce_url(
7872
+ $this->admin_url( 'themes.php?action=activate&stylesheet=' . urlencode( $this->get_previous_theme_slug() ) ),
7873
+ 'switch-theme_' . $this->get_previous_theme_slug()
7874
+ );
7875
+ }
7876
+
7877
+ /**
7878
+ * Saves the slug of the previous theme if it still exists so that it can be used by the logic in the opt-in
7879
+ * form that decides whether to add a close button to the opt-in dialog or not. So after a premium-only theme is
7880
+ * activated, the close button will appear and will reactivate the previous theme if clicked. If the previous
7881
+ * theme doesn't exist, then there will be no close button.
7882
+ *
7883
+ * @author Leo Fajardo (@leorw)
7884
+ * @since 1.2.2
7885
+ *
7886
+ * @param string $slug_or_name Old theme's slug or name.
7887
+ * @param bool|WP_Theme $old_theme WP_Theme instance of the old theme if it still exists.
7888
+ */
7889
+ function _activate_theme_event_hook( $slug_or_name, $old_theme = false ) {
7890
+ $this->_storage->previous_theme = ( false !== $old_theme ) ?
7891
+ $old_theme->get_stylesheet() :
7892
+ $slug_or_name;
7893
+
7894
+ $this->_activate_plugin_event_hook();
7895
+ }
7896
+
7897
+ /**
7898
+ * Plugin activated hook.
7899
+ *
7900
+ * @author Vova Feldman (@svovaf)
7901
+ * @since 1.0.1
7902
+ *
7903
+ * @uses FS_Api
7904
+ */
7905
+ function _activate_plugin_event_hook() {
7906
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
7907
+
7908
+ if ( ! $this->is_user_admin() ) {
7909
+ return;
7910
+ }
7911
+
7912
+ $this->unregister_uninstall_hook();
7913
+
7914
+ // Clear API cache on activation.
7915
+ FS_Api::clear_cache();
7916
+
7917
+ $is_premium_version_activation = $this->is_plugin() ?
7918
+ ( current_filter() !== ( 'activate_' . $this->_free_plugin_basename ) ) :
7919
+ $this->is_premium();
7920
+
7921
+ if ( $is_premium_version_activation && $this->is_pending_activation() ) {
7922
+ $this->clear_pending_activation_mode();
7923
+ }
7924
+
7925
+ $this->_logger->info( 'Activating ' . ( $is_premium_version_activation ? 'premium' : 'free' ) . ' plugin version.' );
7926
+
7927
+ if ( $this->is_plugin() ) {
7928
+ // This logic is relevant only to plugins since both the free and premium versions of a plugin can be active at the same time.
7929
+ // 1. If running in the activation of the FREE module, get the basename of the PREMIUM.
7930
+ // 2. If running in the activation of the PREMIUM module, get the basename of the FREE.
7931
+ $other_version_basename = $is_premium_version_activation ?
7932
+ $this->_free_plugin_basename :
7933
+ $this->premium_plugin_basename();
7934
+
7935
+ if ( ! $this->_is_network_active ) {
7936
+ /**
7937
+ * Themes are always network activated, but the ACTUAL activation is per site.
7938
+ *
7939
+ * During the activation, the plugin isn't yet active, therefore,
7940
+ * _is_network_active will be set to false even if it's a network level
7941
+ * activation. So we need to fix that by looking at the is_network_admin() value.
7942
+ *
7943
+ * @author Vova Feldman
7944
+ */
7945
+ $this->_is_network_active = (
7946
+ $this->_is_multisite_integrated &&
7947
+ fs_is_network_admin()
7948
+ );
7949
+ }
7950
+
7951
+ /**
7952
+ * If the other module version is active, deactivate it.
7953
+ *
7954
+ * is_plugin_active() checks if the plugin is active on the site or the network level and
7955
+ * deactivate_plugins() deactivates the plugin whether it's activated on the site or network level.
7956
+ *
7957
+ * @author Leo Fajardo (@leorw)
7958
+ * @since 1.2.2
7959
+ */
7960
+ if (
7961
+ is_plugin_active( $other_version_basename ) &&
7962
+ $this->apply_filters( 'deactivate_on_activation', true )
7963
+ ) {
7964
+ deactivate_plugins( $other_version_basename );
7965
+ }
7966
+ }
7967
+
7968
+ if ( $this->is_registered() ) {
7969
+ if ( $is_premium_version_activation ) {
7970
+ $this->reconnect_locally();
7971
+ }
7972
+
7973
+
7974
+ // Schedule re-activation event and sync.
7975
+ // $this->sync_install( array(), true );
7976
+ $this->schedule_install_sync();
7977
+
7978
+ // If activating the premium module version, add an admin notice to congratulate for an upgrade completion.
7979
+ if ( $is_premium_version_activation ) {
7980
+ $this->_admin_notices->add(
7981
+ sprintf( $this->get_text_inline( 'The upgrade of %s was successfully completed.', 'successful-version-upgrade-message' ), sprintf( '<b>%s</b>', $this->_plugin->title ) ),
7982
+ $this->get_text_x_inline( 'W00t',
7983
+ 'Used to express elation, enthusiasm, or triumph (especially in electronic communication).', 'woot' ) . '!'
7984
+ );
7985
+ }
7986
+ } else if ( $this->is_anonymous() ) {
7987
+ if ( isset( $this->_storage->is_anonymous_ms ) && $this->_storage->is_anonymous_ms['is'] ) {
7988
+ $plugin_version = $this->_storage->is_anonymous_ms['version'];
7989
+ $network = true;
7990
+ } else {
7991
+ $plugin_version = isset( $this->_storage->is_anonymous ) ?
7992
+ $this->_storage->is_anonymous['version'] :
7993
+ null;
7994
+ $network = false;
7995
+ }
7996
+
7997
+ /**
7998
+ * Reset "skipped" click cache on the following:
7999
+ * 1. Freemius DEV mode.
8000
+ * 2. WordPress DEBUG mode.
8001
+ * 3. If a plugin and the user skipped the exact same version before.
8002
+ *
8003
+ * @since 1.2.2.7 Ulrich Pogson (@grapplerulrich) asked to not reset the SKIPPED flag if the exact same THEME version was activated before unless the developer is running with WP_DEBUG on, or Freemius debug mode on (WP_FS__DEV_MODE).
8004
+ *
8005
+ * @todo 4. If explicitly asked to retry after every activation.
8006
+ */
8007
+ if ( WP_FS__DEV_MODE ||
8008
+ (
8009
+ ( $this->is_plugin() || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ) &&
8010
+ $this->get_plugin_version() == $plugin_version
8011
+ )
8012
+ ) {
8013
+ $this->reset_anonymous_mode( $network );
8014
+ }
8015
+ }
8016
+
8017
+ $is_trial_or_has_features_enabled_license = ( $this->is_trial() || $this->has_features_enabled_license() );
8018
+
8019
+ if ( $this->is_addon() && ! $is_trial_or_has_features_enabled_license ) {
8020
+ /**
8021
+ * When activating an add-on, try to also activate a license.
8022
+ *
8023
+ * @author Leo Fajardo (@leorw)
8024
+ * @since 2.3.0
8025
+ */
8026
+ if ( ! $this->_is_network_active ) {
8027
+ $this->maybe_activate_addon_license();
8028
+ } else {
8029
+ $this->maybe_network_activate_addon_license();
8030
+ }
8031
+
8032
+ /**
8033
+ * Avoid redirecting to the license activation screen after automatically activating an add-on license.
8034
+ *
8035
+ * @author Leo Fajardo (@leorw)
8036
+ * @since 2.3.0
8037
+ */
8038
+ $is_trial_or_has_features_enabled_license = ( $this->is_trial() || $this->has_features_enabled_license() );
8039
+
8040
+ if ( $is_trial_or_has_features_enabled_license && true === $this->_storage->require_license_activation ) {
8041
+ $this->_storage->require_license_activation = false;
8042
+ }
8043
+ }
8044
+
8045
+ if (
8046
+ $is_premium_version_activation &&
8047
+ (
8048
+ ( ! $this->is_registered() && $this->is_anonymous() ) ||
8049
+ (
8050
+ $this->is_registered() &&
8051
+ ! $is_trial_or_has_features_enabled_license
8052
+ )
8053
+ )
8054
+ ) {
8055
+ $this->_storage->require_license_activation = true;
8056
+ }
8057
+
8058
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
8059
+ /**
8060
+ * If no previous version of plugin's version exist, it means that it's either
8061
+ * the first time that the plugin installed on the site, or the plugin was installed
8062
+ * before but didn't have Freemius integrated.
8063
+ *
8064
+ * Since register_activation_hook() do NOT fires on updates since 3.1, and only fires
8065
+ * on manual activation via the dashboard, is_plugin_activation() is TRUE
8066
+ * only after immediate activation.
8067
+ *
8068
+ * @since 1.1.4
8069
+ * @link https://make.wordpress.org/core/2010/10/27/plugin-activation-hooks-no-longer-fire-for-updates/
8070
+ */
8071
+ $this->_storage->is_plugin_new_install = empty( $this->_storage->plugin_last_version );
8072
+ }
8073
+
8074
+ /**
8075
+ * Also flush when activating the premium version so that even if Freemius was off before, the API
8076
+ * connectivity test can be run again.
8077
+ *
8078
+ * @author Leo Fajardo (@leorw)
8079
+ * @since 2.2.3.1
8080
+ */
8081
+ $has_api_connectivity = $this->has_api_connectivity( WP_FS__DEV_MODE || $is_premium_version_activation );
8082
+
8083
+ if ( ! $this->_anonymous_mode &&
8084
+ $has_api_connectivity &&
8085
+ ! $this->_isAutoInstall
8086
+ ) {
8087
+ // Store hint that the plugin was just activated to enable auto-redirection to settings.
8088
+ set_transient( "fs_{$this->_module_type}_{$this->_slug}_activated", true, 60 );
8089
+ }
8090
+
8091
+ /**
8092
+ * Activation hook is executed after the plugin's main file is loaded, therefore,
8093
+ * after the plugin was loaded. The logic is located at activate_plugin()
8094
+ * ./wp-admin/includes/plugin.php.
8095
+ *
8096
+ * @author Vova Feldman (@svovaf)
8097
+ * @since 1.1.9
8098
+ */
8099
+ $this->_storage->was_plugin_loaded = true;
8100
+ }
8101
+
8102
+ /**
8103
+ * @author Leo Fajardo (@leorw)
8104
+ * @since 2.3.0
8105
+ */
8106
+ private function maybe_activate_addon_license() {
8107
+ $parent_fs = $this->get_parent_instance();
8108
+
8109
+ if (
8110
+ ! is_object( $parent_fs ) ||
8111
+ ( ! $parent_fs->is_registered() && ! $parent_fs->is_network_registered() )
8112
+ ) {
8113
+ // Try to activate a license only if the parent plugin is active and has a valid `install`.
8114
+ return;
8115
+ }
8116
+
8117
+ $license = $this->get_active_parent_license();
8118
+ if ( ! is_object( $license ) ) {
8119
+ return;
8120
+ }
8121
+
8122
+ if (
8123
+ $this->is_bundle_license_auto_activation_enabled() &&
8124
+ ! empty( $license->products )
8125
+ ) {
8126
+ $this->activate_bundle_license( $license );
8127
+
8128
+ return;
8129
+ }
8130
+
8131
+ if ( ! $this->is_registered() ) {
8132
+ // Opt in with a license key.
8133
+ $this->opt_in(
8134
+ $parent_fs->get_current_or_network_user()->email,
8135
+ false,
8136
+ false,
8137
+ $license->secret_key
8138
+ );
8139
+ } else {
8140
+ // Activate the license.
8141
+ $install = $this->api_site_call(
8142
+ '/',
8143
+ 'put',
8144
+ array( 'license_key' => $this->apply_filters( 'license_key', $license->secret_key ) )
8145
+ );
8146
+
8147
+ if ( ! FS_Api::is_api_error( $install ) ) {
8148
+ $this->_sync_addon_license( $this->get_id(), true );
8149
+ }
8150
+ }
8151
+ }
8152
+
8153
+ /**
8154
+ * @author Leo Fajardo (@leorw)
8155
+ * @since 2.3.0
8156
+ *
8157
+ * @param FS_Plugin_License $license
8158
+ */
8159
+ private function maybe_network_activate_addon_license( $license = null ) {
8160
+ $parent_fs = $this->get_parent_instance();
8161
+ if ( ! is_object( $parent_fs ) || ( ! $parent_fs->is_registered() && ! $parent_fs->is_network_registered() ) ) {
8162
+ // Try to activate a license only if the parent plugin is active and has a valid `install`.
8163
+ return;
8164
+ }
8165
+
8166
+ $license = ( ! is_null( $license ) ) ?
8167
+ $license :
8168
+ $this->get_active_parent_license();
8169
+
8170
+ if ( ! is_object( $license ) ) {
8171
+ return;
8172
+ }
8173
+
8174
+ if (
8175
+ $this->is_bundle_license_auto_activation_enabled() &&
8176
+ ! empty( $license->products )
8177
+ ) {
8178
+ $this->activate_bundle_license( $license );
8179
+
8180
+ return;
8181
+ }
8182
+
8183
+ if ( ! $this->is_network_registered() ) {
8184
+ $sites = $this->get_sites_for_network_level_optin();
8185
+
8186
+ if ( count( $sites ) > $license->left() ) {
8187
+ // If the add-on is network active, try to activate the license only if it can be activated on all sites.
8188
+ return;
8189
+ }
8190
+
8191
+ // Opt in with a license key.
8192
+ $this->opt_in(
8193
+ $parent_fs->get_user()->email,
8194
+ false,
8195
+ false,
8196
+ $license->secret_key,
8197
+ false,
8198
+ false,
8199
+ false,
8200
+ null,
8201
+ $sites
8202
+ );
8203
+ } else {
8204
+ $blog_2_install_map = array();
8205
+ $site_ids = array();
8206
+
8207
+ $all_sites = Freemius::get_sites();
8208
+
8209
+ foreach ( $all_sites as $site ) {
8210
+ $blog_id = Freemius::get_site_blog_id( $site );
8211
+ $install = $this->get_install_by_blog_id( $blog_id );
8212
+
8213
+ if ( is_object( $install ) && FS_Plugin_License::is_valid_id( $install->license_id ) ) {
8214
+ // Skip license activation for installs that are already associated with a license.
8215
+ continue;
8216
+ }
8217
+
8218
+ if ( is_object( $install ) ) {
8219
+ $blog_2_install_map[ $blog_id ] = $install;
8220
+ } else {
8221
+ $site_ids[] = $blog_id;
8222
+ }
8223
+ }
8224
+
8225
+ if ( ( count( $blog_2_install_map ) + count( $site_ids ) ) > $license->left() ) {
8226
+ return;
8227
+ }
8228
+
8229
+ $user = $this->get_current_or_network_user();
8230
+
8231
+ if ( ! empty( $blog_2_install_map ) ) {
8232
+ $result = $this->activate_license_on_many_installs( $user, $license->secret_key, $blog_2_install_map );
8233
+
8234
+ if ( true !== $result ) {
8235
+ return;
8236
+ }
8237
+ }
8238
+
8239
+ if ( ! empty( $site_ids ) ) {
8240
+ $this->activate_license_on_many_sites( $user, $license->secret_key, $site_ids );
8241
+ }
8242
+ }
8243
+ }
8244
+
8245
+ /**
8246
+ * Tries to activate a bundle license for all supported products if the current product is activated with a bundle license. This is called after activating an available license (not via the license activation dialog but by clicking on a license activation button) for a product via its "Account" page.
8247
+ *
8248
+ * @author Leo Fajardo (@leorw)
8249
+ * @since 2.4.0
8250
+ *
8251
+ * @param FS_Plugin_License $license
8252
+ * @param array $sites
8253
+ * @param int $blog_id
8254
+ */
8255
+ private function maybe_activate_bundle_license( FS_Plugin_License $license = null, $sites = array(), $blog_id = 0 ) {
8256
+ if ( ! is_object( $license ) && $this->has_active_valid_license() ) {
8257
+ $license = $this->_license;
8258
+ }
8259
+
8260
+ if ( ! is_object( $license ) ) {
8261
+ return;
8262
+ }
8263
+
8264
+ $parent_license = ( ! empty( $license->products ) ) ?
8265
+ $license :
8266
+ $this->get_active_parent_license( $license->secret_key );
8267
+
8268
+ if ( is_object( $parent_license ) ) {
8269
+ $this->activate_bundle_license( $parent_license, $sites, $blog_id );
8270
+ }
8271
+ }
8272
+
8273
+ /**
8274
+ * Try to activate a bundle license for all the bundle products installed on the site.
8275
+ * (1) If a child product install already has a license, the bundle license won't be activated.
8276
+ * (2) On multi-site networks, if the attempt to activate the bundle license is triggered from the network admin, the bundle license activation will only work for non-delegated sites and only if none of them is associated with a license. Even if one of the sites has the product installed with a license key, skip the bundle license activation for the product.
8277
+ * (3) On multi-site networks, if the attempt to activate the bundle license is triggered from a site-level admin, only activate the license if the product is site-level activated or delegated, and the product installation is not yet associated with a license.
8278
+ *
8279
+ * @author Leo Fajardo (@leorw)
8280
+ * @since 2.4.0
8281
+ *
8282
+ * @param FS_Plugin_License $license
8283
+ * @param array $sites
8284
+ * @param int $current_blog_id
8285
+ */
8286
+ private function activate_bundle_license( $license, $sites = array(), $current_blog_id = 0 ) {
8287
+ $is_network_admin = fs_is_network_admin();
8288
+
8289
+ $installs_by_blog_map = array();
8290
+ $site_info_by_blog_map = array();
8291
+
8292
+ /**
8293
+ * Try to activate the license for all supported products.
8294
+ *
8295
+ * @author Leo Fajardo
8296
+ */
8297
+ foreach ( $license->products as $product_id ) {
8298
+ $fs = self::get_instance_by_id( $product_id );
8299
+
8300
+ if ( ! is_object( $fs ) ) {
8301
+ continue;
8302
+ }
8303
+
8304
+ if ( ! $fs->has_paid_plan() ) {
8305
+ continue;
8306
+ }
8307
+
8308
+ if (
8309
+ ! $fs->is_addon() &&
8310
+ ! FS_Plan_Manager::instance()->has_paid_plan( $fs->_plans )
8311
+ ) {
8312
+ /**
8313
+ * The parent product can be free-only but can have its `has_paid_plan` flag set to `true` when
8314
+ * there is a context bundle.
8315
+ */
8316
+ continue;
8317
+ }
8318
+
8319
+ if ( $current_blog_id > 0 ) {
8320
+ $fs->switch_to_blog( $current_blog_id );
8321
+ }
8322
+
8323
+ if ( $fs->has_active_valid_license() ) {
8324
+ continue;
8325
+ }
8326
+
8327
+ if ( ! $is_network_admin || $current_blog_id > 0 ) {
8328
+ if ( $fs->is_network_active() && ! $fs->is_delegated_connection( $current_blog_id ) ) {
8329
+ // Do not try to activate the license in the site level if the product is network active and the connection was not delegated.
8330
+ continue;
8331
+ }
8332
+ } else {
8333
+ if ( ! $fs->is_network_active() ) {
8334
+ // Do not try to activate the license in the network level if the product is not network active.
8335
+ continue;
8336
+ }
8337
+
8338
+ if ( $fs->is_network_delegated_connection() ) {
8339
+ // Do not try to activate the license in the network level if the activation has been delegated to site admins.
8340
+ continue;
8341
+ }
8342
+
8343
+ $has_install_with_license = false;
8344
+
8345
+ // Collection of sites that have an install entity that is not activated with a license or non-delegated sites that have no install entity, or both types of site.
8346
+ $filtered_sites = array();
8347
+
8348
+ if ( empty( $sites ) ) {
8349
+ $all_sites = self::get_sites();
8350
+
8351
+ foreach ( $all_sites as $site ) {
8352
+ $sites[] = array( 'blog_id' => self::get_site_blog_id( $site ) );
8353
+ }
8354
+ } else {
8355
+ // Populate the map here to avoid calling `$fs->get_site_info( $site );` in the other `for` loop below.
8356
+ foreach ( $sites as $site ) {
8357
+ if ( ! isset( $site['blog_id'] ) || ! is_numeric( $site['blog_id'] ) ) {
8358
+ continue;
8359
+ }
8360
+
8361
+ $site_info_by_blog_map[ $site['blog_id'] ] = $site;
8362
+ }
8363
+ }
8364
+
8365
+ foreach ( $sites as $site ) {
8366
+ if ( ! isset( $site['blog_id'] ) || ! is_numeric( $site['blog_id'] ) ) {
8367
+ continue;
8368
+ }
8369
+
8370
+ $blog_id = $site['blog_id'];
8371
+
8372
+ if ( ! isset( $installs_by_blog_map[ $blog_id ] ) ) {
8373
+ $installs_by_blog_map[ $blog_id ] = self::get_all_sites( $fs->get_module_type(), $blog_id );
8374
+ }
8375
+
8376
+ $installs = $installs_by_blog_map[ $blog_id ];
8377
+ $install = null;
8378
+
8379
+ if ( isset( $installs[ $fs->get_slug() ] ) ) {
8380
+ $install = $installs[ $fs->get_slug() ];
8381
+
8382
+ if (
8383
+ is_object( $install ) &&
8384
+ (
8385
+ ! FS_Site::is_valid_id( $install->id ) ||
8386
+ ! FS_User::is_valid_id( $install->user_id ) ||
8387
+ ! FS_Plugin_Plan::is_valid_id( $install->plan_id )
8388
+ )
8389
+ ) {
8390
+ $install = null;
8391
+ }
8392
+ }
8393
+
8394
+ if (
8395
+ is_object( $install ) &&
8396
+ FS_Plugin_License::is_valid_id( $install->license_id )
8397
+ ) {
8398
+ $has_install_with_license = true;
8399
+ break;
8400
+ }
8401
+
8402
+ if ( $fs->is_site_delegated_connection( $blog_id ) ) {
8403
+ // Site activation delegated, don't activate bundle license on the site in the network admin.
8404
+ continue;
8405
+ }
8406
+
8407
+ if ( ! isset( $site_info_by_blog_map[ $blog_id ] ) ) {
8408
+ $site_info_by_blog_map[ $blog_id ] = $fs->get_site_info( $site );
8409
+ }
8410
+
8411
+ $filtered_sites[] = $site_info_by_blog_map[ $blog_id ];
8412
+ }
8413
+
8414
+ if ( $has_install_with_license || empty( $filtered_sites ) ) {
8415
+ // Do not try to activate the license at the network level if there's any install with a license or there's no site to activate the license on.
8416
+ continue;
8417
+ }
8418
+
8419
+ $sites = $filtered_sites;
8420
+ }
8421
+
8422
+ $fs->activate_migrated_license(
8423
+ $license->secret_key,
8424
+ null,
8425
+ null,
8426
+ $sites,
8427
+ ( $current_blog_id > 0 ? $current_blog_id : null )
8428
+ );
8429
+ }
8430
+ }
8431
+
8432
+ /**
8433
+ * Returns a parent license that can be activated for the context product.
8434
+ *
8435
+ * @author Leo Fajardo (@leorw)
8436
+ * @since 2.3.0
8437
+ *
8438
+ * @param string|null $license_key
8439
+ * @param bool $flush
8440
+ *
8441
+ * @return FS_Plugin_License
8442
+ */
8443
+ function get_active_parent_license( $license_key = null, $flush = true ) {
8444
+ $parent_licenses_endpoint = "/plugins/{$this->get_id()}/parent_licenses.json?filter=activatable";
8445
+
8446
+ $fs = $this;
8447
+
8448
+ if ( $this->is_addon() ) {
8449
+ $parent_instance = $this->get_parent_instance();
8450
+
8451
+ if ( is_object( $parent_instance ) && $parent_instance->is_registered() ) {
8452
+ $fs = $parent_instance;
8453
+ }
8454
+ }
8455
+
8456
+ $foreign_licenses = $fs->get_foreign_licenses_info(
8457
+ self::get_all_licenses( $this->get_parent_id() )
8458
+ );
8459
+
8460
+ if ( ! empty ( $foreign_licenses ) ) {
8461
+ $foreign_licenses = array(
8462
+ // Prefix with `+` to tell the server to include foreign licenses in the licenses collection.
8463
+ 'ids' => ( urlencode( '+' ) . implode( ',', $foreign_licenses['ids'] ) ),
8464
+ 'license_keys' => implode( ',', array_map( 'urlencode', $foreign_licenses['license_keys'] ) )
8465
+ );
8466
+
8467
+ $parent_licenses_endpoint = add_query_arg( $foreign_licenses, $parent_licenses_endpoint );
8468
+ }
8469
+
8470
+ $result = $fs->get_current_or_network_user_api_scope()->get( $parent_licenses_endpoint, $flush );
8471
+
8472
+ if (
8473
+ ! $this->is_api_result_object( $result, 'licenses' ) ||
8474
+ ! is_array( $result->licenses ) ||
8475
+ empty( $result->licenses )
8476
+ ) {
8477
+ return null;
8478
+ }
8479
+
8480
+ $parent_license = null;
8481
+
8482
+ if ( empty( $license_key ) ) {
8483
+ $parent_license = $result->licenses[0];
8484
+ } else {
8485
+ foreach ( $result->licenses as $license ) {
8486
+ if ( $license_key === $license->secret_key ) {
8487
+ $parent_license = $license;
8488
+ break;
8489
+ }
8490
+ }
8491
+ }
8492
+
8493
+ if ( ! is_null( $parent_license ) ) {
8494
+ $parent_license = new FS_Plugin_License( $parent_license );
8495
+ }
8496
+
8497
+ return $parent_license;
8498
+ }
8499
+
8500
+ /**
8501
+ * @author Leo Fajardo (@leorw)
8502
+ * @since 2.3.0
8503
+ *
8504
+ * @return array
8505
+ */
8506
+ function get_sites_for_network_level_optin() {
8507
+ $sites = array();
8508
+ $all_sites = self::get_sites();
8509
+
8510
+ foreach ( $all_sites as $site ) {
8511
+ $blog_id = self::get_site_blog_id( $site );
8512
+
8513
+ if ( ! $this->is_site_delegated_connection( $blog_id ) &&
8514
+ ! $this->is_installed_on_site( $blog_id )
8515
+ ) {
8516
+ $sites[] = $this->get_site_info( $site );
8517
+ }
8518
+ }
8519
+
8520
+ return $sites;
8521
+ }
8522
+
8523
+ /**
8524
+ * Delete account.
8525
+ *
8526
+ * @author Vova Feldman (@svovaf)
8527
+ * @since 1.0.3
8528
+ *
8529
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
8530
+ */
8531
+ function delete_account_event( $check_user = true ) {
8532
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
8533
+
8534
+ if ( $check_user && ! $this->is_user_admin() ) {
8535
+ return;
8536
+ }
8537
+
8538
+ $this->do_action( 'before_account_delete' );
8539
+
8540
+ // Clear all admin notices.
8541
+ $this->_admin_notices->clear_all_sticky( false );
8542
+
8543
+ $this->_delete_site( false );
8544
+
8545
+ $delete_network_common_data = true;
8546
+
8547
+ if ( $this->_is_network_active ) {
8548
+ $installs = $this->get_blog_install_map();
8549
+
8550
+ // Don't delete common network data unless no other installs left.
8551
+ $delete_network_common_data = empty( $installs );
8552
+ }
8553
+
8554
+ if ( $delete_network_common_data ) {
8555
+ $this->_delete_plans( false );
8556
+
8557
+ $this->_delete_licenses( false );
8558
+
8559
+ // Delete add-ons related to plugin's account.
8560
+ $this->_delete_account_addons( false );
8561
+ }
8562
+
8563
+ // @todo Delete plans and licenses of add-ons.
8564
+
8565
+ self::$_accounts->store();
8566
+
8567
+ /**
8568
+ * IMPORTANT:
8569
+ * Clear crons must be executed before clearing all storage.
8570
+ * Otherwise, the cron will not be cleared.
8571
+ */
8572
+ if ( $delete_network_common_data ) {
8573
+ $this->clear_sync_cron();
8574
+ }
8575
+
8576
+ $this->clear_install_sync_cron();
8577
+
8578
+ // Clear all storage data.
8579
+ $this->_storage->clear_all( true, array(
8580
+ 'is_delegated_connection',
8581
+ 'connectivity_test',
8582
+ 'is_on',
8583
+ ), false );
8584
+
8585
+ // Send delete event.
8586
+ $this->get_api_site_scope()->call( '/', 'delete' );
8587
+
8588
+ $this->do_action( 'after_account_delete' );
8589
+ }
8590
+
8591
+ /**
8592
+ * Delete network level account.
8593
+ *
8594
+ * @author Vova Feldman (@svovaf)
8595
+ * @since 2.0.0
8596
+ *
8597
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
8598
+ */
8599
+ function delete_network_account_event( $check_user = true ) {
8600
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
8601
+
8602
+ if ( $check_user && ! $this->is_user_admin() ) {
8603
+ return;
8604
+ }
8605
+
8606
+ $this->do_action( 'before_network_account_delete' );
8607
+
8608
+ // Clear all admin notices.
8609
+ $this->_admin_notices->clear_all_sticky();
8610
+
8611
+ $this->_delete_plans( false, false );
8612
+
8613
+ $this->_delete_licenses( false );
8614
+
8615
+ // Delete add-ons related to plugin's account.
8616
+ $this->_delete_account_addons( false );
8617
+
8618
+ // @todo Delete plans and licenses of add-ons.
8619
+
8620
+ self::$_accounts->store( true );
8621
+
8622
+ /**
8623
+ * IMPORTANT:
8624
+ * Clear crons must be executed before clearing all storage.
8625
+ * Otherwise, the cron will not be cleared.
8626
+ */
8627
+ $this->clear_sync_cron( true );
8628
+ $this->clear_install_sync_cron( true );
8629
+
8630
+ $sites = self::get_sites();
8631
+
8632
+ $install_ids = array();
8633
+ foreach ( $sites as $site ) {
8634
+ $blog_id = self::get_site_blog_id( $site );
8635
+
8636
+ if ( $this->is_site_delegated_connection( $blog_id ) ) {
8637
+ continue;
8638
+ }
8639
+
8640
+ $install_id = $this->_delete_site( true, $blog_id );
8641
+
8642
+ // Clear all storage data.
8643
+ $this->_storage->clear_all( true, array( 'connectivity_test' ), $blog_id );
8644
+
8645
+ if ( FS_Site::is_valid_id( $install_id ) ) {
8646
+ $install_ids[] = $install_id;
8647
+ }
8648
+
8649
+ switch_to_blog( $blog_id );
8650
+
8651
+ $this->do_action( 'after_account_delete' );
8652
+
8653
+ restore_current_blog();
8654
+ }
8655
+
8656
+ $this->_storage->clear_all( true, array(
8657
+ 'connectivity_test',
8658
+ 'is_on',
8659
+ ), true );
8660
+
8661
+ // Send delete event.
8662
+ if ( ! empty( $install_ids ) ) {
8663
+ $result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json?ids=" . implode( ',', $install_ids ), 'delete' );
8664
+ }
8665
+
8666
+ $this->do_action( 'after_network_account_delete' );
8667
+ }
8668
+
8669
+ /**
8670
+ * Plugin deactivation hook.
8671
+ *
8672
+ * @author Vova Feldman (@svovaf)
8673
+ * @since 1.0.1
8674
+ */
8675
+ function _deactivate_plugin_hook() {
8676
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
8677
+
8678
+ if ( ! $this->is_user_admin() ) {
8679
+ return;
8680
+ }
8681
+
8682
+ $is_network_deactivation = fs_is_network_admin();
8683
+ $storage_keys_for_removal = array();
8684
+
8685
+ $this->_admin_notices->clear_all_sticky();
8686
+
8687
+ $storage_keys_for_removal[] = 'sticky_optin_added';
8688
+ if ( isset( $this->_storage->sticky_optin_added ) ) {
8689
+ unset( $this->_storage->sticky_optin_added );
8690
+ }
8691
+
8692
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
8693
+ // Remember that plugin was already installed.
8694
+ $this->_storage->is_plugin_new_install = false;
8695
+ }
8696
+
8697
+ // Hook to plugin uninstall.
8698
+ register_uninstall_hook( $this->_plugin_main_file_path, array( 'Freemius', '_uninstall_plugin_hook' ) );
8699
+
8700
+ $this->clear_module_main_file_cache();
8701
+ $this->clear_sync_cron( $this->_is_network_active );
8702
+ $this->clear_install_sync_cron();
8703
+
8704
+ if ( $this->is_registered() ) {
8705
+ if ( $this->is_premium() && ! $this->has_active_valid_license() ) {
8706
+ FS_Plugin_Updater::instance( $this )->delete_update_data();
8707
+ }
8708
+
8709
+ if ( $is_network_deactivation ) {
8710
+ // Send deactivation event.
8711
+ $this->sync_installs( array(
8712
+ 'is_active' => false,
8713
+ ) );
8714
+ } else {
8715
+ // Send deactivation event.
8716
+ $this->sync_install( array(
8717
+ 'is_active' => false,
8718
+ ) );
8719
+ }
8720
+ } else {
8721
+ if ( ! $this->has_api_connectivity() ) {
8722
+ // Reset connectivity test cache.
8723
+ unset( $this->_storage->connectivity_test );
8724
+
8725
+ $storage_keys_for_removal[] = 'connectivity_test';
8726
+ }
8727
+ }
8728
+
8729
+ if ( $is_network_deactivation ) {
8730
+ if ( isset( $this->_storage->sticky_optin_added_ms ) ) {
8731
+ unset( $this->_storage->sticky_optin_added_ms );
8732
+ }
8733
+
8734
+ if ( ! empty( $storage_keys_for_removal ) ) {
8735
+ $sites = self::get_sites();
8736
+
8737
+ foreach ( $sites as $site ) {
8738
+ $blog_id = self::get_site_blog_id( $site );
8739
+
8740
+ foreach ( $storage_keys_for_removal as $key ) {
8741
+ $this->_storage->remove( $key, false, $blog_id );
8742
+ }
8743
+
8744
+ $this->_storage->save( $blog_id );
8745
+ }
8746
+ }
8747
+ }
8748
+
8749
+ // Clear API cache on deactivation.
8750
+ FS_Api::clear_cache();
8751
+
8752
+ $this->remove_sdk_reference();
8753
+ }
8754
+
8755
+ /**
8756
+ * @author Vova Feldman (@svovaf)
8757
+ * @since 1.1.6
8758
+ */
8759
+ private function remove_sdk_reference() {
8760
+ global $fs_active_plugins;
8761
+
8762
+ foreach ( $fs_active_plugins->plugins as $sdk_path => $data ) {
8763
+ if ( $this->_plugin_basename == $data->plugin_path ) {
8764
+ unset( $fs_active_plugins->plugins[ $sdk_path ] );
8765
+ break;
8766
+ }
8767
+ }
8768
+
8769
+ fs_fallback_to_newest_active_sdk();
8770
+ }
8771
+
8772
+ /**
8773
+ * @author Vova Feldman (@svovaf)
8774
+ * @since 1.1.3
8775
+ *
8776
+ * @param bool $is_anonymous
8777
+ * @param bool|int $network_or_blog_id Since 2.0.0
8778
+ */
8779
+ private function set_anonymous_mode( $is_anonymous = true, $network_or_blog_id = 0 ) {
8780
+ // Store information regarding skip to try and opt-in the user
8781
+ // again in the future.
8782
+ $skip_info = array(
8783
+ 'is' => $is_anonymous,
8784
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
8785
+ 'version' => $this->get_plugin_version(),
8786
+ );
8787
+
8788
+ if ( true === $network_or_blog_id ) {
8789
+ $this->_storage->is_anonymous_ms = $skip_info;
8790
+ } else {
8791
+ $this->_storage->store( 'is_anonymous', $skip_info, $network_or_blog_id );
8792
+ }
8793
+
8794
+ $this->network_upgrade_mode_completed();
8795
+
8796
+ // Update anonymous mode cache.
8797
+ $this->_is_anonymous = $is_anonymous;
8798
+ }
8799
+
8800
+ /**
8801
+ * @author Vova Feldman (@svovaf)
8802
+ * @since 2.5.1
8803
+ *
8804
+ * @param bool|int $network_or_blog_id
8805
+ */
8806
+ private function unset_anonymous_mode( $network_or_blog_id = 0 ) {
8807
+ if ( true === $network_or_blog_id ) {
8808
+ unset( $this->_storage->is_anonymous_ms );
8809
+ } else {
8810
+ $this->_storage->remove( 'is_anonymous', true, $network_or_blog_id );
8811
+ }
8812
+ }
8813
+
8814
+ /**
8815
+ * @author Vova Feldman (@svovaf)
8816
+ * @since 2.0.0
8817
+ *
8818
+ * @param int $blog_id Site ID.
8819
+ * @param int $user_id User ID.
8820
+ * @param string $domain Site domain.
8821
+ * @param string $path Site path.
8822
+ * @param int $network_id Network ID. Only relevant on multi-network installations.
8823
+ * @param array $meta Metadata. Used to set initial site options.
8824
+ *
8825
+ * @uses Freemius::is_license_network_active() to check if the context license was network activated by the super-admin.
8826
+ * @uses Freemius::is_network_connected() to check if the super-admin network opted-in.
8827
+ * @uses Freemius::is_network_anonymous() to check if the super-admin network skipped.
8828
+ * @uses Freemius::is_network_delegated_connection() to check if the super-admin network delegated the connection to the site admins.
8829
+ */
8830
+ public function _after_new_blog_callback( $blog_id, $user_id, $domain, $path, $network_id, $meta ) {
8831
+ $this->_logger->entrance();
8832
+
8833
+ if ( ! $this->_is_network_active ) {
8834
+ FS_Clone_Manager::instance()->store_blog_install_info( $blog_id );
8835
+ return;
8836
+ }
8837
+
8838
+ $site = null;
8839
+ $new_blog_id = $blog_id;
8840
+
8841
+ if ( $this->is_premium() &&
8842
+ $this->is_network_connected() &&
8843
+ is_object( $this->_license ) &&
8844
+ $this->_license->can_activate( FS_Site::is_localhost_by_address( $domain ) ) &&
8845
+ $this->is_license_network_active( $blog_id )
8846
+ ) {
8847
+ /**
8848
+ * Running the premium version, the license was network activated, and the license can also be activated on the current site -> so try to opt-in with the license key.
8849
+ */
8850
+ $current_blog_id = get_current_blog_id();
8851
+ $license = clone $this->_license;
8852
+
8853
+ $this->switch_to_blog( $blog_id );
8854
+
8855
+ // Opt-in with network user.
8856
+ $this->install_with_user(
8857
+ $this->get_network_user(),
8858
+ $license->secret_key,
8859
+ false,
8860
+ false,
8861
+ false
8862
+ );
8863
+
8864
+ if ( is_object( $this->_site ) ) {
8865
+ if ( $this->_site->license_id == $license->id ) {
8866
+ /**
8867
+ * If the license was activated successfully, sync the license data from the remote server.
8868
+ */
8869
+ $this->_license = $license;
8870
+ $this->sync_site_license();
8871
+ }
8872
+ }
8873
+
8874
+ $site = $this->_site;
8875
+
8876
+ $this->switch_to_blog( $current_blog_id );
8877
+
8878
+ if ( is_object( $site ) ) {
8879
+ FS_Clone_Manager::instance()->store_blog_install_info( $blog_id, $site );
8880
+
8881
+ // Already connected (with or without a license), so no need to continue.
8882
+ return;
8883
+ }
8884
+ }
8885
+
8886
+ if ( $this->is_network_anonymous() ) {
8887
+ /**
8888
+ * Opt-in was network skipped so automatically skip the opt-in for the new site.
8889
+ */
8890
+ $this->skip_site_connection( $blog_id );
8891
+ } else if ( $this->is_network_delegated_connection() ) {
8892
+ /**
8893
+ * Opt-in was network delegated so automatically delegate the opt-in for the new site's admin.
8894
+ */
8895
+ $this->delegate_site_connection( $blog_id );
8896
+ } else if ( $this->is_network_connected() ) {
8897
+ /**
8898
+ * Opt-in was network activated so automatically opt-in with the network user and new site admin.
8899
+ */
8900
+ $current_blog_id = get_current_blog_id();
8901
+
8902
+ $this->switch_to_blog( $blog_id );
8903
+
8904
+ // Opt-in with network user.
8905
+ $this->install_with_user(
8906
+ $this->get_network_user(),
8907
+ false,
8908
+ false,
8909
+ false,
8910
+ false
8911
+ );
8912
+
8913
+ $site = $this->_site;
8914
+
8915
+ $this->switch_to_blog( $current_blog_id );
8916
+ } else {
8917
+ /**
8918
+ * If the super-admin mixed different options (connect, skip, delegated):
8919
+ * a) If at least one site connection was delegated, then automatically delegate connection.
8920
+ * b) Otherwise, it means that at least one site was skipped and at least one site was connected. For a simplified UX in the initial release of the multisite network integration, skip the connection for the newly created site. If the super-admin will want to opt-in they can still do that from the network level Account page.
8921
+ */
8922
+ $has_delegated_site = false;
8923
+
8924
+ $sites = self::get_sites();
8925
+ foreach ( $sites as $wp_site ) {
8926
+ $blog_id = self::get_site_blog_id( $wp_site );
8927
+
8928
+ if ( $this->is_site_delegated_connection( $blog_id ) ) {
8929
+ $has_delegated_site = true;
8930
+ break;
8931
+ }
8932
+ }
8933
+
8934
+ if ( $has_delegated_site ) {
8935
+ $this->delegate_site_connection( $blog_id );
8936
+ } else {
8937
+ $this->skip_site_connection( $blog_id );
8938
+ }
8939
+ }
8940
+
8941
+ /**
8942
+ * Store the new blog's information even if there's no install so that when a clone install is stored in the new blog's storage, we can try to resolve it automatically.
8943
+ *
8944
+ * @author Leo Fajardo (@leorw)
8945
+ * @since 2.5.0
8946
+ */
8947
+ FS_Clone_Manager::instance()->store_blog_install_info( $new_blog_id, $site );
8948
+ }
8949
+
8950
+ /**
8951
+ * @author Vova Feldman (@svovaf)
8952
+ * @since 2.5.0
8953
+ *
8954
+ * @param \WP_Site $new_site
8955
+ * @param array $args
8956
+ */
8957
+ public function _after_wp_initialize_site_callback( WP_Site $new_site, $args ) {
8958
+ $this->_logger->entrance();
8959
+
8960
+ $this->_after_new_blog_callback(
8961
+ $new_site->id,
8962
+ // Dummy user ID (not in use).
8963
+ 0,
8964
+ $new_site->domain,
8965
+ $new_site->path,
8966
+ $new_site->network_id,
8967
+ // Dummy meta, not in use.
8968
+ array()
8969
+ );
8970
+ }
8971
+
8972
+ /**
8973
+ * @author Vova Feldman (@svovaf)
8974
+ * @since 1.1.3
8975
+ *
8976
+ * @param bool|int|int[] $network_or_blog_ids Since 2.0.0.
8977
+ */
8978
+ private function reset_anonymous_mode( $network_or_blog_ids = false ) {
8979
+ if ( true === $network_or_blog_ids ) {
8980
+ $this->unset_anonymous_mode( true );
8981
+
8982
+ if ( fs_is_network_admin() ) {
8983
+ $this->_is_anonymous = null;
8984
+ }
8985
+
8986
+ // Rest anonymous mode for all non-delegated sub-sites.
8987
+ $blog_ids = $this->get_non_delegated_blog_ids();
8988
+ }
8989
+ else
8990
+ {
8991
+ if ( false === $network_or_blog_ids ) {
8992
+ $network_or_blog_ids = 0;
8993
+ }
8994
+
8995
+ $blog_ids = is_array( $network_or_blog_ids ) ?
8996
+ $network_or_blog_ids :
8997
+ array( $network_or_blog_ids );
8998
+
8999
+ foreach ( $blog_ids as $blog_id ) {
9000
+ if ( 0 === $blog_id || get_current_blog_id() == $blog_id ) {
9001
+ $this->_is_anonymous = null;
9002
+ }
9003
+ }
9004
+ }
9005
+
9006
+ foreach ( $blog_ids as $blog_id ) {
9007
+ $this->unset_anonymous_mode( $blog_id );
9008
+ }
9009
+
9010
+ /**
9011
+ * Ensure that this field is also "false", otherwise, if the current module's type is "theme" and the module
9012
+ * has no menus, the opt-in popup will not be shown immediately (in this case, the user will have to click
9013
+ * on the admin notice that contains the opt-in link in order to trigger the opt-in popup).
9014
+ *
9015
+ * @author Leo Fajardo (@leorw)
9016
+ * @since 1.2.2
9017
+ */
9018
+ if ( ! $this->_is_network_active ) {
9019
+ $this->_is_anonymous = null;
9020
+ }
9021
+ }
9022
+
9023
+ /**
9024
+ * This is used to ensure that before redirecting to the opt-in page after resetting the anonymous mode or
9025
+ * deleting the account in the network level, the URL of the page to redirect to is correct.
9026
+ *
9027
+ * @author Leo Fajardo (@leorw)
9028
+ *
9029
+ * @since 2.1.3
9030
+ */
9031
+ private function maybe_set_slug_and_network_menu_exists_flag() {
9032
+ if ( ! empty( $this->_dynamically_added_top_level_page_hook_name ) ) {
9033
+ $this->_menu->set_slug_and_network_menu_exists_flag( $this->_menu->has_menu() ?
9034
+ $this->_menu->get_slug() :
9035
+ $this->_slug
9036
+ );
9037
+ }
9038
+ }
9039
+
9040
+ /**
9041
+ * Clears the anonymous mode and redirects to the opt-in screen.
9042
+ *
9043
+ * @author Vova Feldman (@svovaf)
9044
+ * @since 1.1.7
9045
+ */
9046
+ function connect_again() {
9047
+ if ( ! $this->is_anonymous() ) {
9048
+ return;
9049
+ }
9050
+
9051
+ $this->reset_anonymous_mode( fs_is_network_admin() );
9052
+
9053
+ $this->maybe_set_slug_and_network_menu_exists_flag();
9054
+
9055
+ fs_redirect( $this->get_activation_url() );
9056
+ }
9057
+
9058
+ /**
9059
+ * Skip account connect, and set anonymous mode.
9060
+ *
9061
+ * @author Vova Feldman (@svovaf)
9062
+ * @since 1.1.1
9063
+ *
9064
+ * @param bool|int|int[] $network_or_blog_ids Since 2.5.1
9065
+ */
9066
+ function skip_connection( $network_or_blog_ids = false ) {
9067
+ $this->_logger->entrance();
9068
+
9069
+ $this->_admin_notices->remove_sticky( 'connect_account' );
9070
+
9071
+ if ( true === $network_or_blog_ids ) {
9072
+ $this->set_anonymous_mode( true, true );
9073
+
9074
+ if ( fs_is_network_admin() ) {
9075
+ $this->_is_anonymous = null;
9076
+ }
9077
+
9078
+ // Rest anonymous mode for all non-delegated sub-sites.
9079
+ $blog_ids = $this->get_non_delegated_blog_ids();
9080
+ }
9081
+ else
9082
+ {
9083
+ if ( false === $network_or_blog_ids ) {
9084
+ $network_or_blog_ids = 0;
9085
+ }
9086
+
9087
+ $blog_ids = is_array( $network_or_blog_ids ) ?
9088
+ $network_or_blog_ids :
9089
+ array( $network_or_blog_ids );
9090
+
9091
+ foreach ( $blog_ids as $blog_id ) {
9092
+ if ( 0 === $blog_id || get_current_blog_id() == $blog_id ) {
9093
+ $this->_is_anonymous = null;
9094
+ }
9095
+ }
9096
+ }
9097
+
9098
+ foreach ( $blog_ids as $blog_id ) {
9099
+ $this->skip_site_connection( $blog_id );
9100
+ }
9101
+
9102
+ $this->network_upgrade_mode_completed();
9103
+ }
9104
+
9105
+ /**
9106
+ * Skip connection for specific site in the network.
9107
+ *
9108
+ * @author Vova Feldman (@svovaf)
9109
+ * @since 2.0.0
9110
+ *
9111
+ * @param int|null $blog_id
9112
+ * @param bool $send_skip
9113
+ */
9114
+ private function skip_site_connection( $blog_id = null ) {
9115
+ $this->_logger->entrance();
9116
+
9117
+ $this->_admin_notices->remove_sticky( 'connect_account', $blog_id );
9118
+
9119
+ $this->set_anonymous_mode( true, $blog_id );
9120
+ }
9121
+
9122
+ /**
9123
+ * Plugin version update hook.
9124
+ *
9125
+ * @author Vova Feldman (@svovaf)
9126
+ * @since 1.0.4
9127
+ */
9128
+ private function update_plugin_version_event() {
9129
+ $this->_logger->entrance();
9130
+
9131
+ if ( ! $this->is_registered() ) {
9132
+ return;
9133
+ }
9134
+
9135
+ $this->schedule_install_sync();
9136
+ // $this->sync_install( array(), true );
9137
+ }
9138
+
9139
+ /**
9140
+ * Generate an MD5 signature of a plugins collection.
9141
+ * This helper methods used to identify changes in a plugins collection.
9142
+ *
9143
+ * @author Vova Feldman (@svovaf)
9144
+ * @since 2.0.0
9145
+ *
9146
+ * @param array [string]array $plugins
9147
+ *
9148
+ * @return string
9149
+ */
9150
+ private function get_plugins_thumbprint( $plugins ) {
9151
+ ksort( $plugins );
9152
+
9153
+ $thumbprint = '';
9154
+ foreach ( $plugins as $basename => $data ) {
9155
+ $thumbprint .= $data['slug'] . ',' .
9156
+ $data['Version'] . ',' .
9157
+ ( $data['is_active'] ? '1' : '0' ) . ';';
9158
+ }
9159
+
9160
+ return md5( $thumbprint );
9161
+ }
9162
+
9163
+ /**
9164
+ * Return a list of modified plugins since the last sync.
9165
+ *
9166
+ * Note:
9167
+ * There's no point to store a plugins counter since even if the number of
9168
+ * plugins didn't change, we still need to check if the versions are all the
9169
+ * same and the activity state is similar.
9170
+ *
9171
+ * @author Vova Feldman (@svovaf)
9172
+ * @since 1.1.8
9173
+ *
9174
+ * @return array|false
9175
+ */
9176
+ private function get_plugins_data_for_api() {
9177
+ // Alias.
9178
+ $site_active_plugins_option_name = 'active_plugins';
9179
+ $network_plugins_option_name = 'all_plugins';
9180
+
9181
+ /**
9182
+ * Collection of all site level active plugins.
9183
+ */
9184
+ $site_active_plugins_cache = self::$_accounts->get_option( $site_active_plugins_option_name );
9185
+
9186
+ if ( ! is_object( $site_active_plugins_cache ) ) {
9187
+ $site_active_plugins_cache = (object) array(
9188
+ 'timestamp' => '',
9189
+ 'md5' => '',
9190
+ 'plugins' => array(),
9191
+ );
9192
+ }
9193
+
9194
+ $time = time();
9195
+
9196
+ if ( ! empty( $site_active_plugins_cache->timestamp ) &&
9197
+ ( $time - $site_active_plugins_cache->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
9198
+ ) {
9199
+ // Don't send plugin updates if last update was in the past 5 min.
9200
+ return false;
9201
+ }
9202
+
9203
+ // Write timestamp to lock the logic.
9204
+ $site_active_plugins_cache->timestamp = $time;
9205
+ self::$_accounts->set_option( $site_active_plugins_option_name, $site_active_plugins_cache, true );
9206
+
9207
+ // Reload options from DB.
9208
+ self::$_accounts->load( true );
9209
+ $site_active_plugins_cache = self::$_accounts->get_option( $site_active_plugins_option_name );
9210
+
9211
+ if ( $time != $site_active_plugins_cache->timestamp ) {
9212
+ // If timestamp is different, then another thread captured the lock.
9213
+ return false;
9214
+ }
9215
+
9216
+ /**
9217
+ * Collection of all plugins (network level).
9218
+ */
9219
+ $network_plugins_cache = self::$_accounts->get_option( $network_plugins_option_name );
9220
+
9221
+ if ( ! is_object( $network_plugins_cache ) ) {
9222
+ $network_plugins_cache = (object) array(
9223
+ 'timestamp' => '',
9224
+ 'md5' => '',
9225
+ 'plugins' => array(),
9226
+ );
9227
+ }
9228
+
9229
+ // Check if there's a change in plugins.
9230
+ $network_plugins = self::get_network_plugins();
9231
+ $site_active_plugins = self::get_site_active_plugins();
9232
+
9233
+ $network_plugins_thumbprint = $this->get_plugins_thumbprint( $network_plugins );
9234
+ $site_active_plugins_thumbprint = $this->get_plugins_thumbprint( $site_active_plugins );
9235
+
9236
+ // Check if plugins status changed (version or active/inactive).
9237
+ $network_plugins_changed = ( $network_plugins_cache->md5 !== $network_plugins_thumbprint );
9238
+ $site_active_plugins_changed = ( $site_active_plugins_cache->md5 !== $site_active_plugins_thumbprint );
9239
+
9240
+ if ( ! $network_plugins_changed &&
9241
+ ! $site_active_plugins_changed
9242
+ ) {
9243
+ // No changes.
9244
+ return array();
9245
+ }
9246
+
9247
+ $plugins_update_data = array();
9248
+
9249
+ foreach ( $network_plugins_cache->plugins as $basename => $data ) {
9250
+ if ( ! isset( $network_plugins[ $basename ] ) ) {
9251
+ // Plugin uninstalled.
9252
+ $uninstalled_plugin_data = $data;
9253
+ $uninstalled_plugin_data['is_active'] = false;
9254
+ $uninstalled_plugin_data['is_uninstalled'] = true;
9255
+ $plugins_update_data[] = $uninstalled_plugin_data;
9256
+
9257
+ unset( $network_plugins[ $basename ] );
9258
+
9259
+ unset( $network_plugins_cache->plugins[ $basename ] );
9260
+ unset( $site_active_plugins_cache->plugins[ $basename ] );
9261
+
9262
+ continue;
9263
+ }
9264
+
9265
+ $was_active = $data['is_active'] ||
9266
+ ( isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
9267
+ true === $site_active_plugins_cache->plugins[ $basename ]['is_active'] );
9268
+ $is_active = $network_plugins[ $basename ]['is_active'] ||
9269
+ ( isset( $site_active_plugins[ $basename ] ) &&
9270
+ $site_active_plugins[ $basename ]['is_active'] );
9271
+
9272
+ if ( ! isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
9273
+ isset( $site_active_plugins[ $basename ] )
9274
+ ) {
9275
+ // Plugin was site level activated.
9276
+ $site_active_plugins_cache->plugins[ $basename ] = $network_plugins[ $basename ];
9277
+ $site_active_plugins_cache->plugins[ $basename ]['is_active'] = true;
9278
+ } else if ( isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
9279
+ ! isset( $site_active_plugins[ $basename ] )
9280
+ ) {
9281
+ // Plugin was site level deactivated.
9282
+ unset( $site_active_plugins_cache->plugins[ $basename ] );
9283
+ }
9284
+
9285
+ $prev_version = $data['version'];
9286
+ $current_version = $network_plugins[ $basename ]['Version'];
9287
+
9288
+ if ( $was_active !== $is_active || $prev_version !== $current_version ) {
9289
+ // Plugin activated or deactivated, or version changed.
9290
+
9291
+ if ( $was_active !== $is_active ) {
9292
+ if ( $data['is_active'] != $network_plugins[ $basename ]['is_active'] ) {
9293
+ $network_plugins_cache->plugins[ $basename ]['is_active'] = $data['is_active'];
9294
+ }
9295
+ }
9296
+
9297
+ if ( $prev_version !== $current_version ) {
9298
+ $network_plugins_cache->plugins[ $basename ]['Version'] = $current_version;
9299
+ }
9300
+
9301
+ $updated_plugin_data = $data;
9302
+ $updated_plugin_data['is_active'] = $is_active;
9303
+ $updated_plugin_data['version'] = $current_version;
9304
+ $updated_plugin_data['title'] = $network_plugins[ $basename ]['Name'];
9305
+ $plugins_update_data[] = $updated_plugin_data;
9306
+ }
9307
+ }
9308
+
9309
+ // Find new plugins that weren't yet seen before.
9310
+ foreach ( $network_plugins as $basename => $data ) {
9311
+ if ( ! isset( $network_plugins_cache->plugins[ $basename ] ) ) {
9312
+ // New plugin.
9313
+ $new_plugin = array(
9314
+ 'slug' => $data['slug'],
9315
+ 'version' => $data['Version'],
9316
+ 'title' => $data['Name'],
9317
+ 'is_active' => $data['is_active'],
9318
+ 'is_uninstalled' => false,
9319
+ );
9320
+
9321
+ $network_plugins_cache->plugins[ $basename ] = $new_plugin;
9322
+
9323
+ $is_site_level_active = (
9324
+ isset( $site_active_plugins[ $basename ] ) &&
9325
+ $site_active_plugins[ $basename ]['is_active']
9326
+ );
9327
+
9328
+ /**
9329
+ * If not network active, set the activity status based on the site-level plugin status.
9330
+ */
9331
+ if ( ! $new_plugin['is_active'] ) {
9332
+ $new_plugin['is_active'] = $is_site_level_active;
9333
+ }
9334
+
9335
+ $plugins_update_data[] = $new_plugin;
9336
+
9337
+ if ( isset( $site_active_plugins[ $basename ] ) ) {
9338
+ $site_active_plugins_cache->plugins[ $basename ] = $new_plugin;
9339
+ $site_active_plugins_cache->plugins[ $basename ]['is_active'] = $is_site_level_active;
9340
+ }
9341
+ }
9342
+ }
9343
+
9344
+ $site_active_plugins_cache->md5 = $site_active_plugins_thumbprint;
9345
+ $site_active_plugins_cache->timestamp = $time;
9346
+ self::$_accounts->set_option( $site_active_plugins_option_name, $site_active_plugins_cache, true );
9347
+
9348
+ $network_plugins_cache->md5 = $network_plugins_thumbprint;
9349
+ $network_plugins_cache->timestamp = $time;
9350
+ self::$_accounts->set_option( $network_plugins_option_name, $network_plugins_cache, true );
9351
+
9352
+ return $plugins_update_data;
9353
+ }
9354
+
9355
+ /**
9356
+ * Return a list of modified themes since the last sync.
9357
+ *
9358
+ * Note:
9359
+ * There's no point to store a themes counter since even if the number of
9360
+ * themes didn't change, we still need to check if the versions are all the
9361
+ * same and the activity state is similar.
9362
+ *
9363
+ * @author Vova Feldman (@svovaf)
9364
+ * @since 1.1.8
9365
+ *
9366
+ * @return array|false
9367
+ */
9368
+ private function get_themes_data_for_api() {
9369
+ // Alias.
9370
+ $option_name = 'all_themes';
9371
+
9372
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
9373
+
9374
+ if ( ! is_object( $all_cached_themes ) ) {
9375
+ $all_cached_themes = (object) array(
9376
+ 'timestamp' => '',
9377
+ 'md5' => '',
9378
+ 'themes' => array(),
9379
+ );
9380
+ }
9381
+
9382
+ $time = time();
9383
+
9384
+ if ( ! empty( $all_cached_themes->timestamp ) &&
9385
+ ( $time - $all_cached_themes->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
9386
+ ) {
9387
+ // Don't send theme updates if last update was in the past 5 min.
9388
+ return false;
9389
+ }
9390
+
9391
+ // Write timestamp to lock the logic.
9392
+ $all_cached_themes->timestamp = $time;
9393
+ self::$_accounts->set_option( $option_name, $all_cached_themes, true );
9394
+
9395
+ // Reload options from DB.
9396
+ self::$_accounts->load( true );
9397
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
9398
+
9399
+ if ( $time != $all_cached_themes->timestamp ) {
9400
+ // If timestamp is different, then another thread captured the lock.
9401
+ return false;
9402
+ }
9403
+
9404
+ // Get active theme.
9405
+ $active_theme = wp_get_theme();
9406
+ $active_theme_stylesheet = $active_theme->get_stylesheet();
9407
+
9408
+ // Check if there's a change in themes.
9409
+ $all_themes = wp_get_themes();
9410
+
9411
+ // Check if themes changed.
9412
+ ksort( $all_themes );
9413
+
9414
+ $themes_signature = '';
9415
+ foreach ( $all_themes as $slug => $data ) {
9416
+ $is_active = ( $slug === $active_theme_stylesheet );
9417
+ $themes_signature .= $slug . ',' .
9418
+ $data->version . ',' .
9419
+ ( $is_active ? '1' : '0' ) . ';';
9420
+ }
9421
+
9422
+ // Check if themes status changed (version or active/inactive).
9423
+ $themes_changed = ( $all_cached_themes->md5 !== md5( $themes_signature ) );
9424
+
9425
+ $themes_update_data = array();
9426
+
9427
+ if ( $themes_changed ) {
9428
+ // Change in themes, report changes.
9429
+
9430
+ // Update existing themes info.
9431
+ foreach ( $all_cached_themes->themes as $slug => $data ) {
9432
+ $is_active = ( $slug === $active_theme_stylesheet );
9433
+
9434
+ if ( ! isset( $all_themes[ $slug ] ) ) {
9435
+ // Plugin uninstalled.
9436
+ $uninstalled_theme_data = $data;
9437
+ $uninstalled_theme_data['is_active'] = false;
9438
+ $uninstalled_theme_data['is_uninstalled'] = true;
9439
+ $themes_update_data[] = $uninstalled_theme_data;
9440
+
9441
+ unset( $all_themes[ $slug ] );
9442
+ unset( $all_cached_themes->themes[ $slug ] );
9443
+ } else if ( $data['is_active'] !== $is_active ||
9444
+ $data['version'] !== $all_themes[ $slug ]->version
9445
+ ) {
9446
+ // Plugin activated or deactivated, or version changed.
9447
+
9448
+ $all_cached_themes->themes[ $slug ]['is_active'] = $is_active;
9449
+ $all_cached_themes->themes[ $slug ]['version'] = $all_themes[ $slug ]->version;
9450
+
9451
+ $themes_update_data[] = $all_cached_themes->themes[ $slug ];
9452
+ }
9453
+ }
9454
+
9455
+ // Find new themes that weren't yet seen before.
9456
+ foreach ( $all_themes as $slug => $data ) {
9457
+ if ( ! isset( $all_cached_themes->themes[ $slug ] ) ) {
9458
+ $is_active = ( $slug === $active_theme_stylesheet );
9459
+
9460
+ // New plugin.
9461
+ $new_plugin = array(
9462
+ 'slug' => $slug,
9463
+ 'version' => $data->version,
9464
+ 'title' => $data->name,
9465
+ 'is_active' => $is_active,
9466
+ 'is_uninstalled' => false,
9467
+ );
9468
+
9469
+ $themes_update_data[] = $new_plugin;
9470
+ $all_cached_themes->themes[ $slug ] = $new_plugin;
9471
+ }
9472
+ }
9473
+
9474
+ $all_cached_themes->md5 = md5( $themes_signature );
9475
+ $all_cached_themes->timestamp = time();
9476
+ self::$_accounts->set_option( $option_name, $all_cached_themes, true );
9477
+ }
9478
+
9479
+ return $themes_update_data;
9480
+ }
9481
+
9482
+ /**
9483
+ * Get site data for API install request.
9484
+ *
9485
+ * @author Vova Feldman (@svovaf)
9486
+ * @since 1.1.2
9487
+ *
9488
+ * @param string[] $override
9489
+ * @param bool $include_plugins Since 1.1.8 by default include plugin changes.
9490
+ * @param bool $include_themes Since 1.1.8 by default include plugin changes.
9491
+ * @param bool $include_blog_data Since 2.3.0 by default include the current blog's data (language, title, and URL).
9492
+ *
9493
+ * @return array
9494
+ */
9495
+ private function get_install_data_for_api(
9496
+ array $override,
9497
+ $include_plugins = true,
9498
+ $include_themes = true,
9499
+ $include_blog_data = true
9500
+ ) {
9501
+ // Alias.
9502
+ $permissions = FS_Permission_Manager::instance( $this );
9503
+
9504
+ if ( $permissions->is_extensions_tracking_allowed() ) {
9505
+ if ( ! defined( 'WP_FS__TRACK_PLUGINS' ) || false !== WP_FS__TRACK_PLUGINS ) {
9506
+ /**
9507
+ * @since 1.1.8 Also send plugin updates.
9508
+ */
9509
+ if ( $include_plugins && ! isset( $override['plugins'] ) ) {
9510
+ $plugins = $this->get_plugins_data_for_api();
9511
+ if ( ! empty( $plugins ) ) {
9512
+ $override['plugins'] = $plugins;
9513
+ }
9514
+ }
9515
+ }
9516
+
9517
+ if ( ! defined( 'WP_FS__TRACK_THEMES' ) || false !== WP_FS__TRACK_THEMES ) {
9518
+ /**
9519
+ * @since 1.1.8 Also send themes updates.
9520
+ */
9521
+ if ( $include_themes && ! isset( $override['themes'] ) ) {
9522
+ $themes = $this->get_themes_data_for_api();
9523
+ if ( ! empty( $themes ) ) {
9524
+ $override['themes'] = $themes;
9525
+ }
9526
+ }
9527
+ }
9528
+ }
9529
+
9530
+ $versions = $this->get_versions();
9531
+
9532
+ $blog_data = array();
9533
+ if ( $include_blog_data ) {
9534
+ $blog_data['url'] = self::get_unfiltered_site_url();
9535
+
9536
+ if ( $permissions->is_diagnostic_tracking_allowed() ) {
9537
+ $blog_data = array_merge( $blog_data, array(
9538
+ 'language' => self::get_sanitized_language(),
9539
+ 'title' => get_bloginfo( 'name' ),
9540
+ ) );
9541
+ }
9542
+ }
9543
+
9544
+ return array_merge( $versions, $blog_data, array(
9545
+ 'version' => $this->get_plugin_version(),
9546
+ 'is_premium' => $this->is_premium(),
9547
+ // Special params.
9548
+ 'is_active' => true,
9549
+ 'is_uninstalled' => false,
9550
+ ), $override );
9551
+ }
9552
+
9553
+ /**
9554
+ * Update installs details.
9555
+ *
9556
+ * @todo V1 of multiste network support doesn't support plugin and theme data sending.
9557
+ *
9558
+ * @author Vova Feldman (@svovaf)
9559
+ * @since 2.0.0
9560
+ *
9561
+ * @param string[] string $override
9562
+ * @param bool $only_diff
9563
+ * @param bool $is_keepalive
9564
+ * @param bool $include_plugins Since 1.1.8 by default include plugin changes.
9565
+ * @param bool $include_themes Since 1.1.8 by default include plugin changes.
9566
+ *
9567
+ * @return array
9568
+ */
9569
+ private function get_installs_data_for_api(
9570
+ array $override,
9571
+ $only_diff = false,
9572
+ $is_keepalive = false,
9573
+ $include_plugins = true,
9574
+ $include_themes = true
9575
+ ) {
9576
+ /**
9577
+ * @since 1.1.8 Also send plugin updates.
9578
+ */
9579
+ // if ( $include_plugins && ! isset( $override['plugins'] ) ) {
9580
+ // $plugins = $this->get_plugins_data_for_api();
9581
+ // if ( ! empty( $plugins ) ) {
9582
+ // $override['plugins'] = $plugins;
9583
+ // }
9584
+ // }
9585
+ /**
9586
+ * @since 1.1.8 Also send themes updates.
9587
+ */
9588
+ // if ( $include_themes && ! isset( $override['themes'] ) ) {
9589
+ // $themes = $this->get_themes_data_for_api();
9590
+ // if ( ! empty( $themes ) ) {
9591
+ // $override['themes'] = $themes;
9592
+ // }
9593
+ // }
9594
+
9595
+ // Common properties.
9596
+ $versions = $this->get_versions();
9597
+ $common = array_merge( $versions, array(
9598
+ 'version' => $this->get_plugin_version(),
9599
+ 'is_premium' => $this->is_premium(),
9600
+ ), $override );
9601
+
9602
+
9603
+ $is_common_diff_for_any_site = false;
9604
+ $common_diff_union = array();
9605
+
9606
+ $installs_data = array();
9607
+
9608
+ $sites = self::get_sites();
9609
+
9610
+ $subsite_data_for_api_by_install_id = array();
9611
+ $install_url_by_install_id = array();
9612
+ $subsite_registration_date_by_install_id = array();
9613
+
9614
+ foreach ( $sites as $site ) {
9615
+ $blog_id = self::get_site_blog_id( $site );
9616
+
9617
+ $install = $this->get_install_by_blog_id( $blog_id );
9618
+
9619
+ if ( is_object( $install ) ) {
9620
+ if ( $install->user_id != $this->_user->id ) {
9621
+ // Install belongs to a different owner.
9622
+ continue;
9623
+ }
9624
+
9625
+ if ( ! $this->is_tracking_allowed( $blog_id, $install ) ) {
9626
+ // Don't send updates regarding opted-out installs.
9627
+ continue;
9628
+ }
9629
+
9630
+ $install_data = $this->get_site_info( $site, true );
9631
+
9632
+ if ( FS_Clone_Manager::instance()->is_temporary_duplicate_by_blog_id( $install_data['blog_id'] ) ) {
9633
+ continue;
9634
+ }
9635
+
9636
+ $uid = $install_data['uid'];
9637
+ $url = $install_data['url'];
9638
+ $registration_date = $install_data['registration_date'];
9639
+
9640
+ if ( isset( $subsite_data_for_api_by_install_id[ $install->id ] ) ) {
9641
+ $clone_subsite_data = $subsite_data_for_api_by_install_id[ $install->id ];
9642
+ $clone_install_url = $install_url_by_install_id[ $install->id ];
9643
+ $clone_subsite_registration_date = $subsite_registration_date_by_install_id[ $install->id ];
9644
+
9645
+ $skip = false;
9646
+
9647
+ if (
9648
+ ! empty( $install_data['registration_date'] ) &&
9649
+ ! empty( $clone_subsite_registration_date )
9650
+ ) {
9651
+ /**
9652
+ * If the current subsite was created after the other subsite that is also linked to the same install ID, we assume that it's a clone (not the original), and therefore, would skip its processing.
9653
+ *
9654
+ * @author Leo Fajardo (@leorw)
9655
+ * @since 2.5.1
9656
+ */
9657
+ $skip = ( strtotime( $install_data['registration_date'] ) > strtotime( $clone_subsite_registration_date ) );
9658
+ } else if (
9659
+ /**
9660
+ * If we already have an install with the same URL as the subsite it's stored in, skip the current subsite. Otherwise, replace the existing install's data with the current subsite's install's data if the URLs match.
9661
+ *
9662
+ * @author Leo Fajardo (@leorw)
9663
+ * @since 2.5.0
9664
+ */
9665
+ fs_strip_url_protocol( untrailingslashit( $clone_install_url ) ) === fs_strip_url_protocol( untrailingslashit( $clone_subsite_data['url'] ) ) ||
9666
+ fs_strip_url_protocol( untrailingslashit( $install->url ) ) !== fs_strip_url_protocol( untrailingslashit( $url ) )
9667
+ ) {
9668
+ $skip = true;
9669
+ }
9670
+
9671
+ if ( $skip ) {
9672
+ // Store the skipped subsite's ID so that the clone resolution manager can try to resolve the clone install that is stored in that subsite later on.
9673
+ FS_Clone_Manager::instance()->store_blog_install_info( $blog_id );
9674
+ continue;
9675
+ }
9676
+ }
9677
+
9678
+ unset( $install_data['blog_id'] );
9679
+ unset( $install_data['uid'] );
9680
+ unset( $install_data['url'] );
9681
+ unset( $install_data['registration_date'] );
9682
+
9683
+ $install_data['is_active'] = $this->is_active_for_site( $blog_id );
9684
+ $install_data['is_uninstalled'] = $install->is_uninstalled;
9685
+
9686
+ $common_diff = null;
9687
+ $is_common_diff = false;
9688
+ if ( $only_diff ) {
9689
+ $install_data = $this->get_install_diff_for_api( $install_data, $install, $override );
9690
+ $common_diff = $this->get_install_diff_for_api( $common, $install, $override );
9691
+
9692
+ $is_common_diff = ! empty( $common_diff );
9693
+
9694
+ if ( $is_common_diff ) {
9695
+ foreach ( $common_diff as $k => $v ) {
9696
+ if ( ! isset( $common_diff_union[ $k ] ) ) {
9697
+ $common_diff_union[ $k ] = $v;
9698
+ }
9699
+ }
9700
+ }
9701
+
9702
+ $is_common_diff_for_any_site = $is_common_diff_for_any_site || $is_common_diff;
9703
+ }
9704
+
9705
+ if ( ! empty( $install_data ) || $is_common_diff || $is_keepalive ) {
9706
+ // Add install ID and site unique ID.
9707
+ $install_data['id'] = $install->id;
9708
+ $install_data['uid'] = $uid;
9709
+ $install_data['url'] = $url;
9710
+
9711
+ $subsite_data_for_api_by_install_id[ $install->id ] = $install_data;
9712
+ $install_url_by_install_id[ $install->id ] = $install->url;
9713
+ $subsite_registration_date_by_install_id[ $install->id ] = $registration_date;
9714
+ }
9715
+ }
9716
+ }
9717
+
9718
+ restore_current_blog();
9719
+
9720
+ $installs_data = array_merge(
9721
+ $installs_data,
9722
+ array_values( $subsite_data_for_api_by_install_id )
9723
+ );
9724
+
9725
+ if ( 0 < count( $installs_data ) && ( $is_common_diff_for_any_site || ! $only_diff ) ) {
9726
+ if ( ! $only_diff ) {
9727
+ $installs_data[] = $common;
9728
+ } else if ( ! empty( $common_diff_union ) ) {
9729
+ $installs_data[] = $common_diff_union;
9730
+ }
9731
+ }
9732
+
9733
+ foreach ( $installs_data as &$data ) {
9734
+ $data = (object) $data;
9735
+ }
9736
+
9737
+ return $installs_data;
9738
+ }
9739
+
9740
+ /**
9741
+ * Compare site actual data to the stored install data and return the differences for an API data sync.
9742
+ *
9743
+ * @author Vova Feldman (@svovaf)
9744
+ * @since 2.0.0
9745
+ *
9746
+ * @param array $site
9747
+ * @param FS_Site $install
9748
+ * @param string[] string $override
9749
+ *
9750
+ * @return array
9751
+ */
9752
+ private function get_install_diff_for_api( $site, $install, $override = array() ) {
9753
+ $diff = array();
9754
+ $special = array();
9755
+ $special_override = false;
9756
+
9757
+ foreach ( $site as $p => $v ) {
9758
+ if ( property_exists( $install, $p ) ) {
9759
+ if ( ( is_bool( $install->{$p} ) || ! empty( $install->{$p} ) ) &&
9760
+ $install->{$p} != $v
9761
+ ) {
9762
+ $val = self::get_api_sanitized_property( $p, $v );
9763
+
9764
+ if ( $install->{$p} != $val ) {
9765
+ $install->{$p} = $val;
9766
+ $diff[ $p ] = $val;
9767
+ }
9768
+ }
9769
+ } else {
9770
+ $special[ $p ] = $v;
9771
+
9772
+ if ( isset( $override[ $p ] ) ||
9773
+ 'plugins' === $p ||
9774
+ 'themes' === $p
9775
+ ) {
9776
+ $special_override = true;
9777
+ }
9778
+ }
9779
+ }
9780
+
9781
+ if ( $special_override || 0 < count( $diff ) ) {
9782
+ // Add special params only if has at least one
9783
+ // standard param, or if explicitly requested to
9784
+ // override a special param or a param which is not exist
9785
+ // in the install object.
9786
+ $diff = array_merge( $diff, $special );
9787
+ }
9788
+
9789
+ return $diff;
9790
+ }
9791
+
9792
+ /**
9793
+ * Update install only if changed.
9794
+ *
9795
+ * @author Vova Feldman (@svovaf)
9796
+ * @since 1.0.9
9797
+ *
9798
+ * @param string[] string $override
9799
+ * @param bool $flush
9800
+ * @param bool $is_two_way_sync @since 2.5.0 If true and there's a successful API request, the install sync cron will be cleared.
9801
+ *
9802
+ * @return false|object|string
9803
+ */
9804
+ private function send_install_update( $override = array(), $flush = false, $is_two_way_sync = false ) {
9805
+ $this->_logger->entrance();
9806
+
9807
+ $check_properties = $this->get_install_data_for_api( $override );
9808
+
9809
+ if ( $flush ) {
9810
+ $params = $check_properties;
9811
+ } else {
9812
+ $params = $this->get_install_diff_for_api( $check_properties, $this->_site, $override );
9813
+ }
9814
+
9815
+ if ( empty( $params ) ) {
9816
+ $keepalive_only_update = $this->should_send_keepalive_update();
9817
+
9818
+ if ( ! $keepalive_only_update ) {
9819
+ /**
9820
+ * There are no updates to send including keepalive.
9821
+ *
9822
+ * @author Leo Fajardo (@leorw)
9823
+ * @since 2.2.3
9824
+ */
9825
+ return false;
9826
+ }
9827
+ }
9828
+
9829
+ if ( $is_two_way_sync ) {
9830
+ /**
9831
+ * Update last install sync timestamp during a two-way sync call as we expect that updates are sent during this call.
9832
+ *
9833
+ * @author Leo Fajardo (@leorw)
9834
+ * @since 2.2.3
9835
+ */
9836
+ if ( ! is_multisite() ) {
9837
+ // Update last install sync timestamp.
9838
+ $this->set_cron_execution_timestamp( 'install_sync' );
9839
+ }
9840
+
9841
+ $params['uid'] = $this->get_anonymous_id();
9842
+ }
9843
+
9844
+ $this->set_keepalive_timestamp();
9845
+
9846
+ // Send updated values to FS.
9847
+ $site = $this->api_site_call( '/', 'put', $params, true );
9848
+
9849
+ if ( $is_two_way_sync && $this->is_api_result_entity( $site ) ) {
9850
+ /**
9851
+ * Clear scheduled install sync after a two-way sync call.
9852
+ *
9853
+ * @author Leo Fajardo (@leorw)
9854
+ * @since 2.2.3
9855
+ */
9856
+ if ( ! is_multisite() ) {
9857
+ // I successfully sent install update, clear scheduled sync if exist.
9858
+ $this->clear_install_sync_cron();
9859
+ }
9860
+ }
9861
+
9862
+ return $site;
9863
+ }
9864
+
9865
+ /**
9866
+ * Update installs only if changed.
9867
+ *
9868
+ * @author Vova Feldman (@svovaf)
9869
+ * @since 2.0.0
9870
+ *
9871
+ * @param string[] string $override
9872
+ * @param bool $flush
9873
+ * @param bool $is_two_way_sync @since 2.5.0 If true and there's a successful API request, the install sync cron will be cleared.
9874
+ *
9875
+ * @return false|object|string
9876
+ */
9877
+ private function send_installs_update( $override = array(), $flush = false, $is_two_way_sync = false ) {
9878
+ $this->_logger->entrance();
9879
+
9880
+ /**
9881
+ * Pass `true` to use the network level storage since the update is for many installs.
9882
+ *
9883
+ * @author Leo Fajardo (@leorw)
9884
+ * @since 2.2.3
9885
+ */
9886
+ $should_send_keepalive = $this->should_send_keepalive_update( true );
9887
+
9888
+ $installs_data = $this->get_installs_data_for_api( $override, ! $flush, $should_send_keepalive );
9889
+
9890
+ if ( empty( $installs_data ) ) {
9891
+ return false;
9892
+ }
9893
+
9894
+ if ( $is_two_way_sync ) {
9895
+ // Update last install sync timestamp during a two-way sync call as we expect that updates are sent during this call.
9896
+ $this->set_cron_execution_timestamp( 'install_sync' );
9897
+ }
9898
+
9899
+ /**
9900
+ * Pass `true` to use the network level storage since the update is for many installs.
9901
+ *
9902
+ * @author Leo Fajardo (@leorw)
9903
+ * @since 2.2.3
9904
+ */
9905
+ $this->set_keepalive_timestamp( true );
9906
+
9907
+ // Send updated values to FS.
9908
+ $result = $this->get_api_user_scope()->call( "/plugins/{$this->_plugin->id}/installs.json", 'put', $installs_data );
9909
+
9910
+ if ( $is_two_way_sync && $this->is_api_result_object( $result, 'installs' ) ) {
9911
+ // I successfully sent a two-way installs update, clear the scheduled install sync if it exists.
9912
+ $this->clear_install_sync_cron();
9913
+ }
9914
+
9915
+ return $result;
9916
+ }
9917
+
9918
+ /**
9919
+ * @author Leo Fajardo (@leorw)
9920
+ *
9921
+ * @param bool|null $use_network_level_storage
9922
+ *
9923
+ * @return bool
9924
+ */
9925
+ private function should_send_keepalive_update( $use_network_level_storage = null ) {
9926
+ $keepalive_timestamp = $this->_storage->get( 'keepalive_timestamp', 0, $use_network_level_storage );
9927
+
9928
+ if ( $keepalive_timestamp < ( time() - WP_FS__TIME_WEEK_IN_SEC ) ) {
9929
+ // If updated more than 7 days ago, trigger a keepalive and update the time it was triggered.
9930
+ return true;
9931
+ } else {
9932
+ // If updated 7 days ago or less, "flip a coin", if the value is 7 trigger a keepalive and update the last time it was triggered.
9933
+ return ( 7 == rand( 1, 7 ) );
9934
+ }
9935
+ }
9936
+
9937
+ /**
9938
+ * Syncs the install owner's data if needed (i.e., if the install owner is different from the loaded user).
9939
+ *
9940
+ * @author Leo Fajardo (@leorw)
9941
+ * @since 2.3.2
9942
+ */
9943
+ private function maybe_sync_install_user() {
9944
+ if ( $this->_user->id == $this->_site->user_id ) {
9945
+ return;
9946
+ }
9947
+
9948
+ // Fetch user data and store if found.
9949
+ $this->sync_user_by_current_install();
9950
+ }
9951
+
9952
+ /**
9953
+ * Update install only if changed.
9954
+ *
9955
+ * @author Vova Feldman (@svovaf)
9956
+ * @since 1.0.9
9957
+ *
9958
+ * @param string[] string $override
9959
+ * @param bool $flush
9960
+ */
9961
+ function sync_install( $override = array(), $flush = false ) {
9962
+ $this->_logger->entrance();
9963
+
9964
+ $site = $this->send_install_update( $override, $flush, true );
9965
+
9966
+ if ( false === $site ) {
9967
+ // No sync required.
9968
+ return;
9969
+ }
9970
+
9971
+ if ( ! $this->is_api_result_entity( $site ) ) {
9972
+ // Failed to sync, don't update locally.
9973
+ return;
9974
+ }
9975
+
9976
+ $this->_site = new FS_Site( $site );
9977
+
9978
+ $this->_store_site( true );
9979
+ }
9980
+
9981
+ /**
9982
+ * Update install only if changed.
9983
+ *
9984
+ * @author Vova Feldman (@svovaf)
9985
+ * @since 1.0.9
9986
+ *
9987
+ * @param string[] string $override
9988
+ * @param bool $flush
9989
+ */
9990
+ private function sync_installs( $override = array(), $flush = false ) {
9991
+ $this->_logger->entrance();
9992
+
9993
+ $result = $this->send_installs_update( $override, $flush, true );
9994
+
9995
+ if ( false === $result ) {
9996
+ // No sync required.
9997
+ return;
9998
+ }
9999
+
10000
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
10001
+ // Failed to sync, don't update locally.
10002
+ return;
10003
+ }
10004
+
10005
+ $address_to_blog_map = $this->get_address_to_blog_map();
10006
+
10007
+ foreach ( $result->installs as $install ) {
10008
+ $this->_site = new FS_Site( $install );
10009
+
10010
+ $address = trailingslashit( fs_strip_url_protocol( $install->url ) );
10011
+ $blog_id = $address_to_blog_map[ $address ];
10012
+
10013
+ $this->_store_site( true, $blog_id );
10014
+ }
10015
+ }
10016
+
10017
+ /**
10018
+ * Track install's custom event.
10019
+ *
10020
+ * IMPORTANT:
10021
+ * Custom event tracking is currently only supported for specific clients.
10022
+ * If you are not one of them, please don't use this method. If you will,
10023
+ * the API will simply ignore your request based on the plugin ID.
10024
+ *
10025
+ * Need custom tracking for your plugin or theme?
10026
+ * If you are interested in custom event tracking please contact yo@freemius.com
10027
+ * for further details.
10028
+ *
10029
+ * @author Vova Feldman (@svovaf)
10030
+ * @since 1.2.1
10031
+ *
10032
+ * @param string $name Event name.
10033
+ * @param array $properties Associative key/value array with primitive values only
10034
+ * @param bool $process_at A valid future date-time in the following format Y-m-d H:i:s.
10035
+ * @param bool $once If true, event will be tracked only once. IMPORTANT: Still trigger the API call.
10036
+ *
10037
+ * @return object|false Event data or FALSE on failure.
10038
+ *
10039
+ * @throws \Freemius_InvalidArgumentException
10040
+ */
10041
+ public function track_event( $name, $properties = array(), $process_at = false, $once = false ) {
10042
+ $this->_logger->entrance( http_build_query( array( 'name' => $name, 'once' => $once ) ) );
10043
+
10044
+ if ( ! $this->is_registered() ) {
10045
+ return false;
10046
+ }
10047
+
10048
+ $event = array( 'type' => $name );
10049
+
10050
+ if ( is_numeric( $process_at ) && $process_at > time() ) {
10051
+ $event['process_at'] = $process_at;
10052
+ }
10053
+
10054
+ if ( $once ) {
10055
+ $event['once'] = true;
10056
+ }
10057
+
10058
+ if ( ! empty( $properties ) ) {
10059
+ // Verify associative array values are primitive.
10060
+ foreach ( $properties as $k => $v ) {
10061
+ if ( ! is_scalar( $v ) ) {
10062
+ throw new Freemius_InvalidArgumentException( 'The $properties argument must be an associative key/value array with primitive values only.' );
10063
+ }
10064
+ }
10065
+
10066
+ $event['properties'] = $properties;
10067
+ }
10068
+
10069
+ $result = $this->get_api_site_scope()->call( 'events.json', 'post', $event );
10070
+
10071
+ return $this->is_api_error( $result ) ?
10072
+ false :
10073
+ $result;
10074
+ }
10075
+
10076
+ /**
10077
+ * Track install's custom event only once, but it still triggers the API call.
10078
+ *
10079
+ * IMPORTANT:
10080
+ * Custom event tracking is currently only supported for specific clients.
10081
+ * If you are not one of them, please don't use this method. If you will,
10082
+ * the API will simply ignore your request based on the plugin ID.
10083
+ *
10084
+ * Need custom tracking for your plugin or theme?
10085
+ * If you are interested in custom event tracking please contact yo@freemius.com
10086
+ * for further details.
10087
+ *
10088
+ * @author Vova Feldman (@svovaf)
10089
+ * @since 1.2.1
10090
+ *
10091
+ * @param string $name Event name.
10092
+ * @param array $properties Associative key/value array with primitive values only
10093
+ * @param bool $process_at A valid future date-time in the following format Y-m-d H:i:s.
10094
+ *
10095
+ * @return object|false Event data or FALSE on failure.
10096
+ *
10097
+ * @throws \Freemius_InvalidArgumentException
10098
+ *
10099
+ * @user Freemius::track_event()
10100
+ */
10101
+ public function track_event_once( $name, $properties = array(), $process_at = false ) {
10102
+ return $this->track_event( $name, $properties, $process_at, true );
10103
+ }
10104
+
10105
+ /**
10106
+ * Plugin uninstall hook.
10107
+ *
10108
+ * @author Vova Feldman (@svovaf)
10109
+ * @since 1.0.1
10110
+ *
10111
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
10112
+ */
10113
+ function _uninstall_plugin_event( $check_user = true ) {
10114
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
10115
+
10116
+ if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
10117
+ return;
10118
+ }
10119
+
10120
+ $params = array();
10121
+ $uninstall_reason = null;
10122
+ if ( isset( $this->_storage->uninstall_reason ) ) {
10123
+ $uninstall_reason = $this->_storage->uninstall_reason;
10124
+ $params['reason_id'] = $uninstall_reason->id;
10125
+ $params['reason_info'] = $uninstall_reason->info;
10126
+ }
10127
+
10128
+ if ( ! $this->is_registered() ) {
10129
+ // Send anonymous uninstall event only if user submitted a feedback.
10130
+ if ( isset( $uninstall_reason ) ) {
10131
+ if ( isset( $uninstall_reason->is_anonymous ) && ! $uninstall_reason->is_anonymous ) {
10132
+ $this->opt_in( false, false, false, false, true );
10133
+ } else {
10134
+ $params['uid'] = $this->get_anonymous_id();
10135
+ $this->get_api_plugin_scope()->call( 'uninstall.json', 'put', $params );
10136
+ }
10137
+ }
10138
+ } else {
10139
+ $params = array_merge( $params, array(
10140
+ 'is_active' => false,
10141
+ 'is_uninstalled' => true,
10142
+ ) );
10143
+
10144
+ if ( $this->_is_network_active ) {
10145
+ // Send uninstall event.
10146
+ $this->send_installs_update( $params );
10147
+ } else {
10148
+ // Send uninstall event and handle the result.
10149
+ $this->sync_install( $params );
10150
+ }
10151
+ }
10152
+
10153
+ // @todo Decide if we want to delete plugin information from db.
10154
+ }
10155
+
10156
+ /**
10157
+ * Set the basename of the current product and hook _activate_plugin_event_hook() to the activation action.
10158
+ *
10159
+ * @author Vova Feldman (@svovaf)
10160
+ * @since 2.2.1
10161
+ *
10162
+ * @param string $is_premium
10163
+ * @param string $caller
10164
+ *
10165
+ * @return string
10166
+ */
10167
+ function set_basename( $is_premium, $caller ) {
10168
+ $basename = plugin_basename( $caller );
10169
+
10170
+ $current_basename = $is_premium ?
10171
+ $this->_premium_plugin_basename :
10172
+ $this->_free_plugin_basename;
10173
+
10174
+ if ( $current_basename == $basename ) {
10175
+ // Basename value set correctly.
10176
+ return;
10177
+ }
10178
+
10179
+ if ( $is_premium ) {
10180
+ $this->_premium_plugin_basename = $basename;
10181
+ } else {
10182
+ $this->_free_plugin_basename = $basename;
10183
+ }
10184
+
10185
+ $plugin_dir = dirname( $this->_plugin_dir_path ) . '/';
10186
+
10187
+ register_activation_hook(
10188
+ $plugin_dir . $basename,
10189
+ array( &$this, '_activate_plugin_event_hook' )
10190
+ );
10191
+ }
10192
+
10193
+ /**
10194
+ * @author Vova Feldman (@svovaf)
10195
+ * @since 1.1.1
10196
+ * @since 2.2.1 If the context product is in its premium version, use the current module's basename, even if it was renamed.
10197
+ *
10198
+ * @return string
10199
+ */
10200
+ function premium_plugin_basename() {
10201
+ if ( ! isset( $this->_premium_plugin_basename ) ) {
10202
+ $this->_premium_plugin_basename = $this->is_premium() ?
10203
+ // The product is premium, so use the current basename.
10204
+ $this->_plugin_basename :
10205
+ $this->get_premium_slug() . '/' . basename( $this->_free_plugin_basename );
10206
+ }
10207
+
10208
+ return $this->_premium_plugin_basename;
10209
+ }
10210
+
10211
+ /**
10212
+ * Uninstall plugin hook. Called only when connected his account with Freemius for active sites tracking.
10213
+ *
10214
+ * @author Vova Feldman (@svovaf)
10215
+ * @since 1.0.2
10216
+ */
10217
+ public static function _uninstall_plugin_hook() {
10218
+ self::_load_required_static();
10219
+
10220
+ self::$_static_logger->entrance();
10221
+
10222
+ if ( ! current_user_can( 'activate_plugins' ) ) {
10223
+ return;
10224
+ }
10225
+
10226
+ $plugin_file = substr( current_filter(), strlen( 'uninstall_' ) );
10227
+
10228
+ self::$_static_logger->info( 'plugin = ' . $plugin_file );
10229
+
10230
+ define( 'WP_FS__UNINSTALL_MODE', true );
10231
+
10232
+ $fs = self::get_instance_by_file( $plugin_file );
10233
+
10234
+ if ( is_object( $fs ) ) {
10235
+ $fs->remove_sdk_reference();
10236
+
10237
+ self::require_plugin_essentials();
10238
+
10239
+ if ( is_plugin_active( $fs->_free_plugin_basename ) ||
10240
+ is_plugin_active( $fs->premium_plugin_basename() )
10241
+ ) {
10242
+ // Deleting Free or Premium plugin version while the other version still installed.
10243
+ return;
10244
+ }
10245
+
10246
+ if (
10247
+ ! $fs->is_clone() &&
10248
+ /**
10249
+ * If there's a context install, run this method only when there's also a context user (e.g., when cloning a subsite of a multisite network into a single-site installation, it's possible for an install to be associated with a non-existing user entity; we want Freemius to be off in this case, while we are trying to recover the user).
10250
+ *
10251
+ * @author Leo Fajardo
10252
+ */
10253
+ ( ! is_object( $fs->_site ) || $fs->is_registered() )
10254
+ ) {
10255
+ $fs->_uninstall_plugin_event();
10256
+ }
10257
+
10258
+ $fs->do_action( 'after_uninstall' );
10259
+ }
10260
+ }
10261
+
10262
+ #----------------------------------------------------------------------------------
10263
+ #region Plugin Information
10264
+ #----------------------------------------------------------------------------------
10265
+
10266
+ /**
10267
+ * Load WordPress core plugin.php essential module.
10268
+ *
10269
+ * @author Vova Feldman (@svovaf)
10270
+ * @since 1.1.1
10271
+ */
10272
+ private static function require_plugin_essentials() {
10273
+ if ( ! function_exists( 'get_plugins' ) ) {
10274
+ self::$_static_logger->log( 'Including wp-admin/includes/plugin.php...' );
10275
+
10276
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
10277
+ }
10278
+ }
10279
+
10280
+ /**
10281
+ * Load WordPress core pluggable.php module.
10282
+ *
10283
+ * @author Vova Feldman (@svovaf)
10284
+ * @since 1.1.2
10285
+ */
10286
+ private static function require_pluggable_essentials() {
10287
+ if ( ! function_exists( 'wp_get_current_user' ) ) {
10288
+ require_once ABSPATH . 'wp-includes/pluggable.php';
10289
+ }
10290
+ }
10291
+
10292
+ /**
10293
+ * Return plugin data.
10294
+ *
10295
+ * @author Vova Feldman (@svovaf)
10296
+ * @since 1.0.1
10297
+ *
10298
+ * @param bool $reparse_plugin_metadata
10299
+ *
10300
+ * @return array
10301
+ */
10302
+ function get_plugin_data( $reparse_plugin_metadata = false ) {
10303
+ if ( ! isset( $this->_plugin_data ) || $reparse_plugin_metadata ) {
10304
+ self::require_plugin_essentials();
10305
+
10306
+ if ( $this->is_plugin() ) {
10307
+ /**
10308
+ * @author Vova Feldman (@svovaf)
10309
+ * @since 1.2.0 When using get_plugin_data() do NOT translate plugin data.
10310
+ *
10311
+ * @link https://github.com/Freemius/wordpress-sdk/issues/77
10312
+ */
10313
+ $plugin_data = get_plugin_data(
10314
+ $this->_plugin_main_file_path,
10315
+ false,
10316
+ false
10317
+ );
10318
+ } else {
10319
+ $theme_data = wp_get_theme();
10320
+
10321
+ if ( $this->_plugin_basename !== $theme_data->get_stylesheet() && is_child_theme() ) {
10322
+ $parent_theme = $theme_data->parent();
10323
+
10324
+ if ( ( $parent_theme instanceof WP_Theme ) && $this->_plugin_basename === $parent_theme->get_stylesheet() ) {
10325
+ $theme_data = $parent_theme;
10326
+ }
10327
+ }
10328
+
10329
+ $plugin_data = array(
10330
+ 'Name' => $theme_data->get( 'Name' ),
10331
+ 'Version' => $theme_data->get( 'Version' ),
10332
+ 'Author' => $theme_data->get( 'Author' ),
10333
+ 'Description' => $theme_data->get( 'Description' ),
10334
+ 'PluginURI' => $theme_data->get( 'ThemeURI' ),
10335
+ );
10336
+ }
10337
+
10338
+ $this->_plugin_data = $plugin_data;
10339
+ }
10340
+
10341
+ return $this->_plugin_data;
10342
+ }
10343
+
10344
+ /**
10345
+ * @author Vova Feldman (@svovaf)
10346
+ * @since 1.0.1
10347
+ * @since 1.2.2.5 If slug not set load slug by module ID.
10348
+ *
10349
+ * @return string Plugin slug.
10350
+ */
10351
+ function get_slug() {
10352
+ if ( ! isset( $this->_slug ) ) {
10353
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
10354
+ $this->_slug = $id_slug_type_path_map[ $this->_module_id ]['slug'];
10355
+ }
10356
+
10357
+ return $this->_slug;
10358
+ }
10359
+
10360
+ /**
10361
+ * @author Leo Fajardo (@leorw)
10362
+ * @since 2.2.1
10363
+ *
10364
+ * @return string
10365
+ */
10366
+ function get_premium_slug() {
10367
+ return ( is_object( $this->_plugin ) && ! empty( $this->_plugin->premium_slug ) ) ?
10368
+ $this->_plugin->premium_slug :
10369
+ "{$this->_slug}-premium";
10370
+ }
10371
+
10372
+ /**
10373
+ * Retrieve the desired folder name for the product.
10374
+ *
10375
+ * @author Vova Feldman (@svovaf)
10376
+ * @since 1.2.1.7
10377
+ *
10378
+ * @return string Plugin slug.
10379
+ */
10380
+ function get_target_folder_name() {
10381
+ return $this->can_use_premium_code() ?
10382
+ $this->_plugin->premium_slug :
10383
+ $this->_slug;
10384
+ }
10385
+
10386
+ /**
10387
+ * @author Vova Feldman (@svovaf)
10388
+ * @since 1.0.1
10389
+ *
10390
+ * @return number Plugin ID.
10391
+ */
10392
+ function get_id() {
10393
+ return $this->_plugin->id;
10394
+ }
10395
+
10396
+ /**
10397
+ * @author Leo Fajardo (@leorw)
10398
+ * @since 2.2.4
10399
+ *
10400
+ * @return number|null Bundle ID.
10401
+ */
10402
+ function get_bundle_id() {
10403
+ return ( isset( $this->_plugin->bundle_id ) && FS_Plugin::is_valid_id( $this->_plugin->bundle_id ) ) ?
10404
+ $this->_plugin->bundle_id :
10405
+ null;
10406
+ }
10407
+
10408
+ /**
10409
+ * @author Vova Feldman (@svovaf)
10410
+ * @since 2.3.1
10411
+ *
10412
+ * @return string|null Bundle public key.
10413
+ */
10414
+ function get_bundle_public_key() {
10415
+ return isset( $this->_plugin->bundle_public_key ) ?
10416
+ $this->_plugin->bundle_public_key :
10417
+ null;
10418
+ }
10419
+
10420
+ /**
10421
+ * Get whether the SDK has been initiated in the context of a Bundle.
10422
+ *
10423
+ * This will return true, if `bundle_id` is present in the SDK init parameters.
10424
+ *
10425
+ * ```php
10426
+ * $my_fs = fs_dynamic_init( array(
10427
+ * // ...
10428
+ * 'bundle_id' => 'XXXX', // Will return true since we have bundle id.
10429
+ * 'bundle_public_key' => 'pk_XXXX',
10430
+ * ) );
10431
+ * ```
10432
+ *
10433
+ * @author Swashata Ghosh (@swashata)
10434
+ * @since 2.5.0
10435
+ *
10436
+ * @return bool True if we are running in bundle context, false otherwise.
10437
+ */
10438
+ private function has_bundle_context() {
10439
+ return ! is_null( $this->get_bundle_id() );
10440
+ }
10441
+
10442
+ /**
10443
+ * @author Vova Feldman (@svovaf)
10444
+ * @since 1.2.1.5
10445
+ *
10446
+ * @return string Freemius SDK version
10447
+ */
10448
+ function get_sdk_version() {
10449
+ return $this->version;
10450
+ }
10451
+
10452
+ /**
10453
+ * @author Vova Feldman (@svovaf)
10454
+ * @since 1.2.1.5
10455
+ *
10456
+ * @return number Parent plugin ID (if parent exist).
10457
+ */
10458
+ function get_parent_id() {
10459
+ return $this->is_addon() ?
10460
+ $this->get_parent_instance()->get_id() :
10461
+ $this->_plugin->id;
10462
+ }
10463
+
10464
+ /**
10465
+ * @author Vova Feldman (@svovaf)
10466
+ * @since 2.3.1
10467
+ *
10468
+ * @return string
10469
+ */
10470
+ function get_usage_tracking_terms_url() {
10471
+ return $this->apply_filters(
10472
+ 'usage_tracking_terms_url',
10473
+ "https://freemius.com/wordpress/usage-tracking/{$this->_plugin->id}/{$this->_slug}/"
10474
+ );
10475
+ }
10476
+
10477
+ /**
10478
+ * @author Vova Feldman (@svovaf)
10479
+ * @since 2.3.1
10480
+ *
10481
+ * @return string
10482
+ */
10483
+ function get_eula_url() {
10484
+ return $this->apply_filters(
10485
+ 'eula_url',
10486
+ "https://freemius.com/product/{$this->_plugin->id}/{$this->_slug}/legal/eula/"
10487
+ );
10488
+ }
10489
+
10490
+ /**
10491
+ * @author Vova Feldman (@svovaf)
10492
+ * @since 1.0.1
10493
+ *
10494
+ * @return string Plugin public key.
10495
+ */
10496
+ function get_public_key() {
10497
+ return $this->_plugin->public_key;
10498
+ }
10499
+
10500
+ /**
10501
+ * Will be available only on sandbox mode.
10502
+ *
10503
+ * @author Vova Feldman (@svovaf)
10504
+ * @since 1.0.4
10505
+ *
10506
+ * @return mixed Plugin secret key.
10507
+ */
10508
+ function get_secret_key() {
10509
+ return $this->_plugin->secret_key;
10510
+ }
10511
+
10512
+ /**
10513
+ * @author Vova Feldman (@svovaf)
10514
+ * @since 1.1.1
10515
+ *
10516
+ * @return bool
10517
+ */
10518
+ function has_secret_key() {
10519
+ return ! empty( $this->_plugin->secret_key );
10520
+ }
10521
+
10522
+ /**
10523
+ * @author Vova Feldman (@svovaf)
10524
+ * @since 1.0.9
10525
+ *
10526
+ * @param string|bool $premium_suffix
10527
+ *
10528
+ * @return string
10529
+ */
10530
+ function get_plugin_name( $premium_suffix = false ) {
10531
+ $this->_logger->entrance();
10532
+
10533
+ /**
10534
+ * This `if-else` can be squeezed into a single `if` but I intentionally split it for code readability.
10535
+ *
10536
+ * @author Vova Feldman
10537
+ */
10538
+ if ( ! isset( $this->_plugin_name ) ) {
10539
+ // Name is not yet set.
10540
+ $this->set_name( $premium_suffix );
10541
+ } else if (
10542
+ ! empty( $premium_suffix ) &&
10543
+ ( ! is_object( $this->_plugin ) || $this->_plugin->premium_suffix !== $premium_suffix )
10544
+ ) {
10545
+ // Name is already set, but there's a change in the premium suffix.
10546
+ $this->set_name( $premium_suffix );
10547
+ }
10548
+
10549
+ return $this->_plugin_name;
10550
+ }
10551
+
10552
+ /**
10553
+ * Calculates and stores the product's name. This helper function was created specifically for get_plugin_name() just to make the code clearer.
10554
+ *
10555
+ * @author Vova Feldman (@svovaf)
10556
+ * @since 2.2.1
10557
+ *
10558
+ * @param string $premium_suffix
10559
+ */
10560
+ private function set_name( $premium_suffix = '' ) {
10561
+ $plugin_data = $this->get_plugin_data();
10562
+
10563
+ // Get name.
10564
+ $this->_plugin_name = $plugin_data['Name'];
10565
+
10566
+ if ( is_string( $premium_suffix ) ) {
10567
+ $premium_suffix = trim( $premium_suffix );
10568
+
10569
+ if ( ! empty( $premium_suffix ) ) {
10570
+ // Check if plugin name contains " (premium)" or a custom suffix and remove it.
10571
+ $suffix = ( ' ' . strtolower( $premium_suffix ) );
10572
+ $suffix_len = strlen( $suffix );
10573
+
10574
+ if ( strlen( $plugin_data['Name'] ) > $suffix_len &&
10575
+ $suffix === substr( strtolower( $plugin_data['Name'] ), - $suffix_len )
10576
+ ) {
10577
+ $this->_plugin_name = substr( $plugin_data['Name'], 0, - $suffix_len );
10578
+ }
10579
+ }
10580
+ }
10581
+
10582
+ $this->_logger->departure( 'Name = ' . $this->_plugin_name );
10583
+ }
10584
+
10585
+ /**
10586
+ * @author Vova Feldman (@svovaf)
10587
+ * @since 1.0.0
10588
+ *
10589
+ * @param bool $reparse_plugin_metadata
10590
+ *
10591
+ * @return string
10592
+ */
10593
+ function get_plugin_version( $reparse_plugin_metadata = false ) {
10594
+ $this->_logger->entrance();
10595
+
10596
+ $plugin_data = $this->get_plugin_data( $reparse_plugin_metadata );
10597
+
10598
+ $this->_logger->departure( 'Version = ' . $plugin_data['Version'] );
10599
+
10600
+ return $this->apply_filters( 'plugin_version', $plugin_data['Version'] );
10601
+ }
10602
+
10603
+ /**
10604
+ * @author Vova Feldman (@svovaf)
10605
+ * @since 1.2.1.7
10606
+ *
10607
+ * @return string
10608
+ */
10609
+ function get_plugin_title() {
10610
+ $this->_logger->entrance();
10611
+
10612
+ $title = $this->_plugin->title;
10613
+
10614
+ return $this->apply_filters( 'plugin_title', $title );
10615
+ }
10616
+
10617
+ /**
10618
+ * @author Vova Feldman (@svovaf)
10619
+ * @since 1.2.2.7
10620
+ *
10621
+ * @param bool $lowercase
10622
+ *
10623
+ * @return string
10624
+ */
10625
+ function get_module_label( $lowercase = false ) {
10626
+ $label = $this->is_addon() ?
10627
+ $this->get_text_inline( 'Add-On', 'addon' ) :
10628
+ ( $this->is_plugin() ?
10629
+ $this->get_text_inline( 'Plugin', 'plugin' ) :
10630
+ $this->get_text_inline( 'Theme', 'theme' ) );
10631
+
10632
+ if ( $lowercase ) {
10633
+ $label = strtolower( $label );
10634
+ }
10635
+
10636
+ return $label;
10637
+ }
10638
+
10639
+ /**
10640
+ * @author Vova Feldman (@svovaf)
10641
+ * @since 1.0.4
10642
+ *
10643
+ * @return string
10644
+ */
10645
+ function get_plugin_basename() {
10646
+ if ( ! isset( $this->_plugin_basename ) ) {
10647
+ if ( $this->is_plugin() ) {
10648
+ $this->_plugin_basename = plugin_basename( $this->_plugin_main_file_path );
10649
+ } else {
10650
+ $this->_plugin_basename = basename( dirname( $this->_plugin_main_file_path ) );
10651
+ }
10652
+ }
10653
+
10654
+ return $this->_plugin_basename;
10655
+ }
10656
+
10657
+ function get_plugin_folder_name() {
10658
+ $this->_logger->entrance();
10659
+
10660
+ $plugin_folder = $this->_plugin_basename;
10661
+
10662
+ while ( '.' !== dirname( $plugin_folder ) ) {
10663
+ $plugin_folder = dirname( $plugin_folder );
10664
+ }
10665
+
10666
+ $this->_logger->departure( 'Folder Name = ' . $plugin_folder );
10667
+
10668
+ return $plugin_folder;
10669
+ }
10670
+
10671
+ #endregion ------------------------------------------------------------------
10672
+
10673
+ /* Account
10674
+ ------------------------------------------------------------------------------------------------------------------*/
10675
+
10676
+ /**
10677
+ * Find plugin's slug by plugin's basename.
10678
+ *
10679
+ * @author Vova Feldman (@svovaf)
10680
+ * @since 1.0.9
10681
+ *
10682
+ * @param string $plugin_base_name
10683
+ *
10684
+ * @return false|string
10685
+ */
10686
+ private static function find_slug_by_basename( $plugin_base_name ) {
10687
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
10688
+
10689
+ if ( ! array( $file_slug_map ) || ! isset( $file_slug_map[ $plugin_base_name ] ) ) {
10690
+ return false;
10691
+ }
10692
+
10693
+ return $file_slug_map[ $plugin_base_name ];
10694
+ }
10695
+
10696
+ /**
10697
+ * Store the map between the plugin's basename to the slug.
10698
+ *
10699
+ * @author Vova Feldman (@svovaf)
10700
+ * @since 1.0.9
10701
+ */
10702
+ private function store_file_slug_map() {
10703
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
10704
+
10705
+ if ( ! array( $file_slug_map ) ) {
10706
+ $file_slug_map = array();
10707
+ }
10708
+
10709
+ if ( ! isset( $file_slug_map[ $this->_plugin_basename ] ) ||
10710
+ $file_slug_map[ $this->_plugin_basename ] !== $this->_slug
10711
+ ) {
10712
+ $file_slug_map[ $this->_plugin_basename ] = $this->_slug;
10713
+ self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
10714
+ }
10715
+ }
10716
+
10717
+ /**
10718
+ * @return array[number]FS_User
10719
+ */
10720
+ static function get_all_users() {
10721
+ $users = self::maybe_get_entities_account_option( 'users', array() );
10722
+
10723
+ if ( ! is_array( $users ) ) {
10724
+ $users = array();
10725
+ }
10726
+
10727
+ return $users;
10728
+ }
10729
+
10730
+ /**
10731
+ * @param string $module_type
10732
+ * @param null|int $blog_id Since 2.0.0
10733
+ *
10734
+ * @return array[string]FS_Site
10735
+ */
10736
+ private static function get_all_sites(
10737
+ $module_type = WP_FS__MODULE_TYPE_PLUGIN,
10738
+ $blog_id = null,
10739
+ $is_backup = false
10740
+ ) {
10741
+ $sites = self::get_account_option(
10742
+ ( $is_backup ? 'prev_' : '' ) . 'sites',
10743
+ $module_type,
10744
+ $blog_id
10745
+ );
10746
+
10747
+ if ( ! is_array( $sites ) ) {
10748
+ $sites = array();
10749
+ }
10750
+
10751
+ return $sites;
10752
+ }
10753
+
10754
+ /**
10755
+ * @author Leo Fajardo (@leorw)
10756
+ *
10757
+ * @since 1.2.2
10758
+ *
10759
+ * @param string $option_name
10760
+ * @param string $module_type
10761
+ * @param null|int $network_level_or_blog_id Since 2.0.0
10762
+ *
10763
+ * @return mixed
10764
+ */
10765
+ private static function get_account_option( $option_name, $module_type = null, $network_level_or_blog_id = null ) {
10766
+ if ( ! is_null( $module_type ) && WP_FS__MODULE_TYPE_PLUGIN !== $module_type ) {
10767
+ $option_name = $module_type . '_' . $option_name;
10768
+ }
10769
+
10770
+ return self::maybe_get_entities_account_option( $option_name, array(), $network_level_or_blog_id );
10771
+ }
10772
+
10773
+ /**
10774
+ * @author Leo Fajardo (@leorw)
10775
+ *
10776
+ * @since 1.2.2
10777
+ *
10778
+ * @param string $option_name
10779
+ * @param mixed $option_value
10780
+ * @param bool $store
10781
+ * @param null|int $network_level_or_blog_id Since 2.0.0
10782
+ */
10783
+ private function set_account_option( $option_name, $option_value, $store, $network_level_or_blog_id = null ) {
10784
+ self::set_account_option_by_module(
10785
+ $this->_module_type,
10786
+ $option_name,
10787
+ $option_value,
10788
+ $store,
10789
+ $network_level_or_blog_id
10790
+ );
10791
+ }
10792
+
10793
+ /**
10794
+ * @author Vova Feldman (@svovaf)
10795
+ *
10796
+ * @since 1.2.2.7
10797
+ *
10798
+ * @param string $module_type
10799
+ * @param string $option_name
10800
+ * @param mixed $option_value
10801
+ * @param bool $store
10802
+ * @param null|int $network_level_or_blog_id Since 2.0.0
10803
+ */
10804
+ private static function set_account_option_by_module(
10805
+ $module_type,
10806
+ $option_name,
10807
+ $option_value,
10808
+ $store,
10809
+ $network_level_or_blog_id = null
10810
+ ) {
10811
+ if ( WP_FS__MODULE_TYPE_PLUGIN != $module_type ) {
10812
+ $option_name = $module_type . '_' . $option_name;
10813
+ }
10814
+
10815
+ self::$_accounts->set_option( $option_name, $option_value, $store, $network_level_or_blog_id );
10816
+ }
10817
+
10818
+ /**
10819
+ * This method can also return non-entity or non-entities collection option like the `user_id_license_ids_map` option.
10820
+ *
10821
+ * @author Leo Fajardo (@leorw)
10822
+ * @since 2.3.1
10823
+ *
10824
+ * @param string $option_name
10825
+ * @param mixed $default
10826
+ * @param null|bool|int $network_level_or_blog_id When an integer, use the given blog storage. When `true` use the multisite storage (if there's a network). When `false`, use the current context blog storage. When `null`, the decision which storage to use (MS vs. Current S) will be handled internally and determined based on the $option (based on self::$_SITE_LEVEL_PARAMS).
10827
+ *
10828
+ * @return mixed|FS_Plugin[]|FS_User[]|FS_Site[]|FS_Plugin_License[]|FS_Plugin_Plan[]|FS_Plugin_Tag[]
10829
+ */
10830
+ private static function maybe_get_entities_account_option( $option_name, $default = null, $network_level_or_blog_id = null ) {
10831
+ $option = self::$_accounts->get_option( $option_name, $default, $network_level_or_blog_id );
10832
+
10833
+ $class_name = '';
10834
+
10835
+ if ( fs_starts_with( $option_name, WP_FS__MODULE_TYPE_THEME . '_' ) ) {
10836
+ $option_name = str_replace( WP_FS__MODULE_TYPE_THEME . '_', '', $option_name );
10837
+ }
10838
+
10839
+ switch ( $option_name ) {
10840
+ case 'plugins':
10841
+ case 'themes':
10842
+ case 'addons':
10843
+ $class_name = FS_Plugin::get_class_name();
10844
+ break;
10845
+ case 'users':
10846
+ $class_name = FS_User::get_class_name();
10847
+ break;
10848
+ case 'sites':
10849
+ $class_name = FS_Site::get_class_name();
10850
+ break;
10851
+ case 'licenses':
10852
+ case 'all_licenses':
10853
+ $class_name = FS_Plugin_License::get_class_name();
10854
+ break;
10855
+ case 'plans':
10856
+ $class_name = FS_Plugin_Plan::get_class_name();
10857
+ break;
10858
+ case 'updates':
10859
+ $class_name = FS_Plugin_Tag::get_class_name();
10860
+ break;
10861
+ }
10862
+
10863
+ if ( empty( $class_name ) ) {
10864
+ return $option;
10865
+ }
10866
+
10867
+ return fs_get_entities( $option, $class_name );
10868
+ }
10869
+
10870
+ /**
10871
+ * @author Vova Feldman (@svovaf)
10872
+ * @since 1.0.6
10873
+ *
10874
+ * @param number|null $module_id
10875
+ *
10876
+ * @return FS_Plugin_License[]
10877
+ */
10878
+ private static function get_all_licenses( $module_id = null ) {
10879
+ $licenses = self::get_account_option( 'all_licenses' );
10880
+
10881
+ if ( ! is_array( $licenses ) ) {
10882
+ $licenses = array();
10883
+ }
10884
+
10885
+ if ( is_null( $module_id ) ) {
10886
+ return $licenses;
10887
+ }
10888
+
10889
+ $licenses = isset( $licenses[ $module_id ] ) ?
10890
+ $licenses[ $module_id ] :
10891
+ array();
10892
+
10893
+ return $licenses;
10894
+ }
10895
+
10896
+ /**
10897
+ * @author Leo Fajardo (@leorw)
10898
+ * @since 2.0.0
10899
+ *
10900
+ * @return array
10901
+ */
10902
+ private static function get_all_licenses_by_module_type() {
10903
+ $licenses = self::get_account_option( 'all_licenses' );
10904
+
10905
+ $licenses_by_module_type = array(
10906
+ WP_FS__MODULE_TYPE_PLUGIN => array(),
10907
+ WP_FS__MODULE_TYPE_THEME => array()
10908
+ );
10909
+
10910
+ if ( ! is_array( $licenses ) ) {
10911
+ return $licenses_by_module_type;
10912
+ }
10913
+
10914
+ foreach ( $licenses as $module_id => $module_licenses ) {
10915
+ $fs = self::get_instance_by_id( $module_id );
10916
+ if ( false === $fs ) {
10917
+ continue;
10918
+ }
10919
+
10920
+ $licenses_by_module_type[ $fs->_module_type ] = array_merge( $licenses_by_module_type[ $fs->_module_type ], $module_licenses );
10921
+ }
10922
+
10923
+ return $licenses_by_module_type;
10924
+ }
10925
+
10926
+ /**
10927
+ * @author Leo Fajardo (@leorw)
10928
+ * @since 2.0.0
10929
+ *
10930
+ * @param number $module_id
10931
+ * @param number|null $user_id
10932
+ *
10933
+ * @return array
10934
+ */
10935
+ private static function get_user_id_license_ids_map( $module_id, $user_id = null ) {
10936
+ $all_modules_user_id_license_ids_map = self::get_account_option( 'user_id_license_ids_map' );
10937
+
10938
+ if ( ! is_array( $all_modules_user_id_license_ids_map ) ) {
10939
+ $all_modules_user_id_license_ids_map = array();
10940
+ }
10941
+
10942
+ $user_id_license_ids_map = isset( $all_modules_user_id_license_ids_map[ $module_id ] ) ?
10943
+ $all_modules_user_id_license_ids_map[ $module_id ] :
10944
+ array();
10945
+
10946
+ if ( FS_User::is_valid_id( $user_id ) ) {
10947
+ $user_id_license_ids_map = isset( $user_id_license_ids_map[ $user_id ] ) ?
10948
+ $user_id_license_ids_map[ $user_id ] :
10949
+ array();
10950
+ }
10951
+
10952
+ return $user_id_license_ids_map;
10953
+ }
10954
+
10955
+ /**
10956
+ * @author Leo Fajardo (@leorw)
10957
+ * @since 2.0.0
10958
+ *
10959
+ * @param array $new_user_id_license_ids_map
10960
+ * @param number $module_id
10961
+ * @param number|null $user_id
10962
+ */
10963
+ private static function store_user_id_license_ids_map( $new_user_id_license_ids_map, $module_id, $user_id = null ) {
10964
+ $all_modules_user_id_license_ids_map = self::get_account_option( 'user_id_license_ids_map' );
10965
+ if ( ! is_array( $all_modules_user_id_license_ids_map ) ) {
10966
+ $all_modules_user_id_license_ids_map = array();
10967
+ }
10968
+
10969
+ if ( ! isset( $all_modules_user_id_license_ids_map[ $module_id ] ) ) {
10970
+ $all_modules_user_id_license_ids_map[ $module_id ] = array();
10971
+ }
10972
+
10973
+ if ( FS_User::is_valid_id( $user_id ) ) {
10974
+ $all_modules_user_id_license_ids_map[ $module_id ][ $user_id ] = $new_user_id_license_ids_map;
10975
+ } else {
10976
+ $all_modules_user_id_license_ids_map[ $module_id ] = $new_user_id_license_ids_map;
10977
+ }
10978
+
10979
+ self::$_accounts->set_option( 'user_id_license_ids_map', $all_modules_user_id_license_ids_map, true );
10980
+ }
10981
+
10982
+ /**
10983
+ * Get a collection of the user's linked license IDs.
10984
+ *
10985
+ * @author Vova Feldman (@svovaf)
10986
+ * @since 2.0.0
10987
+ *
10988
+ * @param number $user_id
10989
+ *
10990
+ * @return number[]
10991
+ */
10992
+ private function get_user_linked_license_ids( $user_id ) {
10993
+ return self::get_user_id_license_ids_map( $this->_module_id, $user_id );
10994
+ }
10995
+
10996
+ /**
10997
+ * Override the user's linked license IDs with a new IDs collection.
10998
+ *
10999
+ * @author Vova Feldman (@svovaf)
11000
+ * @since 2.0.0
11001
+ *
11002
+ * @param number $user_id
11003
+ * @param number[] $license_ids
11004
+ */
11005
+ private function set_user_linked_license_ids( $user_id, array $license_ids ) {
11006
+ self::store_user_id_license_ids_map( $license_ids, $this->_module_id, $user_id );
11007
+ }
11008
+
11009
+ /**
11010
+ * Link a specified license ID to a given user.
11011
+ *
11012
+ * @author Vova Feldman (@svovaf)
11013
+ * @since 2.0.0
11014
+ *
11015
+ * @param number $license_id
11016
+ * @param number $user_id
11017
+ */
11018
+ private function link_license_2_user( $license_id, $user_id ) {
11019
+ $license_ids = $this->get_user_linked_license_ids( $user_id );
11020
+
11021
+ if ( in_array( $license_id, $license_ids ) ) {
11022
+ // License already linked.
11023
+ return;
11024
+ }
11025
+
11026
+ $license_ids[] = $license_id;
11027
+
11028
+ $this->set_user_linked_license_ids( $user_id, $license_ids );
11029
+ }
11030
+
11031
+ /**
11032
+ * @param string|bool $module_type
11033
+ *
11034
+ * @return FS_Plugin_Plan[]
11035
+ */
11036
+ private static function get_all_plans( $module_type = false ) {
11037
+ $plans = self::get_account_option( 'plans', $module_type );
11038
+
11039
+ if ( ! is_array( $plans ) ) {
11040
+ $plans = array();
11041
+ }
11042
+
11043
+ return $plans;
11044
+ }
11045
+
11046
+ /**
11047
+ * @author Vova Feldman (@svovaf)
11048
+ * @since 1.0.4
11049
+ *
11050
+ * @return FS_Plugin_Tag[]
11051
+ */
11052
+ private static function get_all_updates() {
11053
+ $updates = self::maybe_get_entities_account_option( 'updates', array() );
11054
+
11055
+ if ( ! is_array( $updates ) ) {
11056
+ $updates = array();
11057
+ }
11058
+
11059
+ return $updates;
11060
+ }
11061
+
11062
+ /**
11063
+ * @author Vova Feldman (@svovaf)
11064
+ * @since 1.0.6
11065
+ *
11066
+ * @return array<number,FS_Plugin[]>|false
11067
+ */
11068
+ private static function get_all_addons() {
11069
+ $addons = self::maybe_get_entities_account_option( 'addons', array() );
11070
+
11071
+ if ( ! is_array( $addons ) ) {
11072
+ $addons = array();
11073
+ }
11074
+
11075
+ return $addons;
11076
+ }
11077
+
11078
+ /**
11079
+ * @author Vova Feldman (@svovaf)
11080
+ * @since 1.0.6
11081
+ *
11082
+ * @return number[]|false
11083
+ */
11084
+ private static function get_all_account_addons() {
11085
+ $addons = self::$_accounts->get_option( 'account_addons', array() );
11086
+
11087
+ if ( ! is_array( $addons ) ) {
11088
+ $addons = array();
11089
+ }
11090
+
11091
+ return $addons;
11092
+ }
11093
+
11094
+ /**
11095
+ * Check if user has connected his account (opted-in).
11096
+ *
11097
+ * Note:
11098
+ * If the user opted-in and opted-out on a later stage,
11099
+ * this will still return true. If you want to check if the
11100
+ * user is currently opted-in, use:
11101
+ * `$fs->is_registered() && $fs->is_tracking_allowed()`
11102
+ *
11103
+ * @author Vova Feldman (@svovaf)
11104
+ * @since 1.0.1
11105
+ *
11106
+ * @param bool $ignore_anonymous_state Since 2.5.1
11107
+ *
11108
+ * @return bool
11109
+ */
11110
+ function is_registered( $ignore_anonymous_state = false ) {
11111
+ return (
11112
+ is_object( $this->_user ) &&
11113
+ (
11114
+ $this->is_premium() ||
11115
+ $ignore_anonymous_state ||
11116
+ ! $this->is_anonymous()
11117
+ )
11118
+ );
11119
+ }
11120
+
11121
+ /**
11122
+ * Returns TRUE if the user opted-in and didn't disconnect (opt-out).
11123
+ *
11124
+ * @author Leo Fajardo (@leorw)
11125
+ * @since 1.2.1.5
11126
+ *
11127
+ * @return bool
11128
+ */
11129
+ function is_tracking_allowed( $blog_id = null, $install = null ) {
11130
+ if ( is_null( $install ) ) {
11131
+ $install = is_null( $blog_id ) ?
11132
+ $this->_site :
11133
+ $this->get_install_by_blog_id( $blog_id );
11134
+ }
11135
+
11136
+ return (
11137
+ is_object( $install ) &&
11138
+ FS_Permission_Manager::instance( $this )->is_homepage_url_tracking_allowed( $blog_id )
11139
+ );
11140
+ }
11141
+
11142
+ /**
11143
+ * Returns TRUE if the user never opted-in or manually opted-out.
11144
+ *
11145
+ * @author Vova Feldman (@svovaf)
11146
+ * @since 1.2.1.5
11147
+ *
11148
+ * @param int|null $blog_id
11149
+ *
11150
+ * @return bool
11151
+ */
11152
+ function is_tracking_prohibited( $blog_id = null ) {
11153
+ return (
11154
+ ! $this->is_registered( true ) ||
11155
+ ! $this->is_tracking_allowed( $blog_id )
11156
+ );
11157
+ }
11158
+
11159
+ /**
11160
+ * @author Leo Fajardo (@leorw)
11161
+ * @since 2.4.0
11162
+ *
11163
+ * @return bool
11164
+ */
11165
+ function is_bundle_license_auto_activation_enabled() {
11166
+ return $this->is_addon() ?
11167
+ ( is_object( $this->_parent ) && $this->_parent->is_bundle_license_auto_activation_enabled() ) :
11168
+ $this->_is_bundle_license_auto_activation_enabled;
11169
+ }
11170
+
11171
+ /**
11172
+ * @author Vova Feldman (@svovaf)
11173
+ * @since 1.0.4
11174
+ *
11175
+ * @return FS_Plugin
11176
+ */
11177
+ function get_plugin() {
11178
+ return $this->_plugin;
11179
+ }
11180
+
11181
+ /**
11182
+ * @author Vova Feldman (@svovaf)
11183
+ * @since 1.0.3
11184
+ *
11185
+ * @return FS_User
11186
+ */
11187
+ function get_user() {
11188
+ return $this->_user;
11189
+ }
11190
+
11191
+ /**
11192
+ * @author Vova Feldman (@svovaf)
11193
+ * @since 1.0.3
11194
+ *
11195
+ * @return FS_Site
11196
+ */
11197
+ function get_site() {
11198
+ return $this->_site;
11199
+ }
11200
+
11201
+ /**
11202
+ * @author Leo Fajardo (@leorw)
11203
+ * @since 2.5.0
11204
+ */
11205
+ function store_site( $site ) {
11206
+ $this->_site = $site;
11207
+ $this->_store_site( true );
11208
+ }
11209
+
11210
+ /**
11211
+ * Deletes the current install with an option to back it up in case restoration will be needed (e.g., if the automatic clone resolution attempt fails).
11212
+ *
11213
+ * @author Leo Fajardo (@leorw)
11214
+ * @since 2.5.0
11215
+ */
11216
+ function delete_current_install( $back_up ) {
11217
+ // Back up and delete the unique ID.
11218
+ if ( $back_up ) {
11219
+ self::$_accounts->set_option( 'prev_unique_id', $this->get_anonymous_id() );
11220
+ }
11221
+
11222
+ self::$_accounts->set_option( 'unique_id', null );
11223
+
11224
+ if ( $back_up ) {
11225
+ // Back up the install before deleting it so that it can be restored later on if necessary (e.g., if the automatic clone resolution attempt fails).
11226
+ $this->back_up_site();
11227
+ }
11228
+
11229
+ $this->_delete_site();
11230
+ $this->_site = null;
11231
+ }
11232
+
11233
+ /**
11234
+ * @author Leo Fajardo (@leorw)
11235
+ * @since 2.5.0
11236
+ */
11237
+ function restore_backup_site() {
11238
+ self::$_accounts->set_option(
11239
+ 'unique_id',
11240
+ self::$_accounts->get_option( 'prev_unique_id' )
11241
+ );
11242
+
11243
+ $sites = self::get_all_sites( $this->_module_type, null, true );
11244
+ $this->store_site( clone $sites[ $this->_slug ] );
11245
+ }
11246
+
11247
+ /**
11248
+ * Get plugin add-ons.
11249
+ *
11250
+ * @author Vova Feldman (@svovaf)
11251
+ * @since 1.0.6
11252
+ *
11253
+ * @since 1.1.7.3 If not yet loaded, fetch data from the API.
11254
+ *
11255
+ * @param bool $flush
11256
+ *
11257
+ * @return FS_Plugin[]|false
11258
+ */
11259
+ function get_addons( $flush = false ) {
11260
+ $this->_logger->entrance();
11261
+
11262
+ if ( ! $this->_has_addons ) {
11263
+ return false;
11264
+ }
11265
+
11266
+ $addons = $this->sync_addons( $flush );
11267
+
11268
+ return ( ! is_array( $addons ) || empty( $addons ) ) ?
11269
+ false :
11270
+ $addons;
11271
+ }
11272
+
11273
+ /**
11274
+ * @author Vova Feldman (@svovaf)
11275
+ * @since 1.0.6
11276
+ *
11277
+ * @return number[]|false
11278
+ */
11279
+ function get_account_addons() {
11280
+ $this->_logger->entrance();
11281
+
11282
+ $addons = self::get_all_account_addons();
11283
+
11284
+ if ( ! is_array( $addons ) ||
11285
+ ! isset( $addons[ $this->_plugin->id ] ) ||
11286
+ ! is_array( $addons[ $this->_plugin->id ] ) ||
11287
+ 0 === count( $addons[ $this->_plugin->id ] )
11288
+ ) {
11289
+ return false;
11290
+ }
11291
+
11292
+ return $addons[ $this->_plugin->id ];
11293
+ }
11294
+
11295
+ /**
11296
+ * Check if user has any
11297
+ *
11298
+ * @author Vova Feldman (@svovaf)
11299
+ * @since 1.1.6
11300
+ *
11301
+ * @return bool
11302
+ */
11303
+ function has_account_addons() {
11304
+ $addons = $this->get_account_addons();
11305
+
11306
+ return is_array( $addons ) && ( 0 < count( $addons ) );
11307
+ }
11308
+
11309
+
11310
+ /**
11311
+ * Get add-on by ID (from local data).
11312
+ *
11313
+ * @author Vova Feldman (@svovaf)
11314
+ * @since 1.0.6
11315
+ *
11316
+ * @param number $id
11317
+ *
11318
+ * @return FS_Plugin|false
11319
+ */
11320
+ function get_addon( $id ) {
11321
+ $this->_logger->entrance();
11322
+
11323
+ $addons = $this->get_addons();
11324
+
11325
+ if ( is_array( $addons ) ) {
11326
+ foreach ( $addons as $addon ) {
11327
+ if ( $id == $addon->id ) {
11328
+ return $addon;
11329
+ }
11330
+ }
11331
+ }
11332
+
11333
+ return false;
11334
+ }
11335
+
11336
+ /**
11337
+ * Get add-on by slug (from local data).
11338
+ *
11339
+ * @author Vova Feldman (@svovaf)
11340
+ * @since 1.0.6
11341
+ *
11342
+ * @param string $slug
11343
+ *
11344
+ * @param bool $flush
11345
+ *
11346
+ * @return FS_Plugin|false
11347
+ */
11348
+ function get_addon_by_slug( $slug, $flush = false ) {
11349
+ $this->_logger->entrance();
11350
+
11351
+ $addons = $this->get_addons( $flush );
11352
+
11353
+ if ( is_array( $addons ) ) {
11354
+ foreach ( $addons as $addon ) {
11355
+ if ( $slug === $addon->slug ) {
11356
+ return $addon;
11357
+ }
11358
+ }
11359
+ }
11360
+
11361
+ return false;
11362
+ }
11363
+
11364
+ /**
11365
+ * @var array<number,object[]> {
11366
+ * @key number Add-on ID.
11367
+ * @val object[] The add-on's plans and prices object.
11368
+ * }
11369
+ */
11370
+ private $plans_and_pricing_by_addon_id;
11371
+
11372
+ /**
11373
+ * @author Leo Fajardo (@leorw)
11374
+ * @since 2.3.0
11375
+ *
11376
+ * @return array<number,object[]> {
11377
+ * @key number Add-on ID.
11378
+ * @val object[] The add-on's plans and prices object.
11379
+ * }
11380
+ */
11381
+ function _get_addons_plans_and_pricing_map_by_id() {
11382
+ if ( ! isset( $this->plans_and_pricing_by_addon_id ) ) {
11383
+ $result = $this->get_api_plugin_scope()->get( $this->add_show_pending( "/addons/pricing.json?type=visible" ) );
11384
+
11385
+ $plans_and_pricing_by_addon_id = array();
11386
+ if ( $this->is_api_result_object( $result, 'addons' ) ) {
11387
+ foreach ( $result->addons as $addon ) {
11388
+ $plans_and_pricing_by_addon_id[ $addon->id ] = $addon->plans;
11389
+ }
11390
+ }
11391
+
11392
+ $this->plans_and_pricing_by_addon_id = $plans_and_pricing_by_addon_id;
11393
+ }
11394
+
11395
+ return $this->plans_and_pricing_by_addon_id;
11396
+ }
11397
+
11398
+ /**
11399
+ * @author Leo Fajardo (@leorw)
11400
+ * @since 2.3.0
11401
+ *
11402
+ * @param number $addon_id
11403
+ * @param bool $is_installed
11404
+ *
11405
+ * @return array
11406
+ */
11407
+ function _get_addon_info( $addon_id, $is_installed ) {
11408
+ $addon = $this->get_addon( $addon_id );
11409
+
11410
+ if ( ! is_object( $addon ) ) {
11411
+ // Unexpected call.
11412
+ return array();
11413
+ }
11414
+
11415
+ $slug = $addon->slug;
11416
+
11417
+ $addon_storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $slug );
11418
+
11419
+ if ( ! fs_is_network_admin() ) {
11420
+ // Get blog-level activated installations.
11421
+ $sites = self::maybe_get_entities_account_option( 'sites', array() );
11422
+ } else {
11423
+ $sites = null;
11424
+
11425
+ if ( $this->is_addon_activated( $addon_id ) &&
11426
+ $this->get_addon_instance( $addon_id )->is_network_active()
11427
+ ) {
11428
+ if ( FS_Site::is_valid_id( $addon_storage->network_install_blog_id ) ) {
11429
+ // Get network-level activated installations.
11430
+ $sites = self::maybe_get_entities_account_option(
11431
+ 'sites',
11432
+ array(),
11433
+ $addon_storage->network_install_blog_id
11434
+ );
11435
+ }
11436
+ }
11437
+ }
11438
+
11439
+ $addon_info = array(
11440
+ 'is_connected' => false,
11441
+ 'slug' => $slug,
11442
+ 'title' => $addon->title,
11443
+ 'is_whitelabeled' => $addon_storage->is_whitelabeled
11444
+ );
11445
+
11446
+ if ( ! $is_installed ) {
11447
+ $plans_and_pricing_by_addon_id = $this->_get_addons_plans_and_pricing_map_by_id();
11448
+
11449
+ if ( isset( $plans_and_pricing_by_addon_id[ $addon_id ] ) ) {
11450
+ $has_paid_plan = false;
11451
+ $plans = $plans_and_pricing_by_addon_id[ $addon_id ];
11452
+
11453
+ if ( is_array( $plans ) && count( $plans ) > 0 ) {
11454
+ foreach ( $plans as $plan ) {
11455
+ if ( isset( $plan->pricing ) &&
11456
+ is_array( $plan->pricing ) &&
11457
+ count( $plan->pricing ) > 0
11458
+ ) {
11459
+ $has_paid_plan = true;
11460
+ break;
11461
+ }
11462
+ }
11463
+ }
11464
+
11465
+ $addon_info['has_paid_plan'] = $has_paid_plan;
11466
+ }
11467
+ }
11468
+
11469
+ if ( ! is_array( $sites ) || ! isset( $sites[ $slug ] ) ) {
11470
+ return $addon_info;
11471
+ }
11472
+
11473
+ $site = $sites[ $slug ];
11474
+
11475
+ $addon_info['is_connected'] = (
11476
+ ( $addon->parent_plugin_id == $this->get_id() ) &&
11477
+ is_object( $site ) &&
11478
+ FS_Site::is_valid_id( $site->id ) &&
11479
+ FS_User::is_valid_id( $site->user_id ) &&
11480
+ FS_Plugin_Plan::is_valid_id( $site->plan_id )
11481
+ );
11482
+
11483
+ if ( $addon_info['is_connected'] && $is_installed ) {
11484
+ return $addon_info;
11485
+ }
11486
+
11487
+ $addon_info['site'] = $site;
11488
+
11489
+ $plugins_data = self::maybe_get_entities_account_option( WP_FS__MODULE_TYPE_PLUGIN . 's', array() );
11490
+ if ( isset( $plugins_data[ $slug ] ) ) {
11491
+ $plugin_data = $plugins_data[ $slug ];
11492
+
11493
+ $addon_info['version'] = $plugin_data->version;
11494
+ }
11495
+
11496
+ $all_plans = self::maybe_get_entities_account_option( 'plans', array() );
11497
+ if ( isset( $all_plans[ $slug ] ) ) {
11498
+ $plans = $all_plans[ $slug ];
11499
+
11500
+ foreach ( $plans as $plan ) {
11501
+ if ( $site->plan_id == Freemius::_decrypt( $plan->id ) ) {
11502
+ $addon_info['plan_name'] = Freemius::_decrypt( $plan->name );
11503
+ $addon_info['plan_title'] = Freemius::_decrypt( $plan->title );
11504
+ break;
11505
+ }
11506
+ }
11507
+ }
11508
+
11509
+ $licenses = self::maybe_get_entities_account_option( 'all_licenses', array() );
11510
+ if ( is_array( $licenses ) && isset( $licenses[ $addon_id ] ) ) {
11511
+ foreach ( $licenses[ $addon_id ] as $license ) {
11512
+ if ( $license->id == $site->license_id ) {
11513
+ $addon_info['license'] = $license;
11514
+ break;
11515
+ }
11516
+ }
11517
+ }
11518
+
11519
+ if ( isset( $addon_info['license'] ) ) {
11520
+ if ( isset( $addon_storage->subscriptions ) &&
11521
+ ! empty( $addon_storage->subscriptions )
11522
+ ) {
11523
+ $addon_subscriptions = fs_get_entities( $addon_storage->subscriptions, FS_Subscription::get_class_name() );
11524
+
11525
+ foreach ( $addon_subscriptions as $subscription ) {
11526
+ if ( $subscription->license_id == $site->license_id ) {
11527
+ $addon_info['subscription'] = $subscription;
11528
+ break;
11529
+ }
11530
+ }
11531
+ }
11532
+ }
11533
+
11534
+ return $addon_info;
11535
+ }
11536
+
11537
+ /**
11538
+ * @author Vova Feldman (@svovaf)
11539
+ * @since 2.0.0
11540
+ *
11541
+ * @param number $user_id
11542
+ *
11543
+ * @return FS_User
11544
+ */
11545
+ static function _get_user_by_id( $user_id ) {
11546
+ self::$_static_logger->entrance( "user_id = {$user_id}" );
11547
+
11548
+ $users = self::get_all_users();
11549
+
11550
+ if ( is_array( $users ) ) {
11551
+ if ( isset( $users[ $user_id ] ) &&
11552
+ $users[ $user_id ] instanceof FS_User &&
11553
+ $user_id == $users[ $user_id ]->id
11554
+ ) {
11555
+ return $users[ $user_id ];
11556
+ }
11557
+
11558
+ // If user wasn't found by the key, iterate over all the users collection.
11559
+ foreach ( $users as $user ) {
11560
+ /**
11561
+ * @var FS_User $user
11562
+ */
11563
+ if ( $user_id == $user->id ) {
11564
+ return $user;
11565
+ }
11566
+ }
11567
+ }
11568
+
11569
+ return null;
11570
+ }
11571
+
11572
+ /**
11573
+ * Checks if a Freemius user_id is associated with a super-admin.
11574
+ *
11575
+ * @author Vova Feldman (@svovaf)
11576
+ * @since 2.0.0
11577
+ *
11578
+ * @param number $user_id
11579
+ *
11580
+ * @return bool
11581
+ */
11582
+ private static function is_super_admin( $user_id ) {
11583
+ $is_super_admin = false;
11584
+
11585
+ $user = self::_get_user_by_id( $user_id );
11586
+
11587
+ if ( $user instanceof FS_User && ! empty( $user->email ) ) {
11588
+ self::require_pluggable_essentials();
11589
+
11590
+ $wp_user = get_user_by( 'email', $user->email );
11591
+
11592
+ if ( $wp_user instanceof WP_User ) {
11593
+ $super_admins = get_super_admins();
11594
+ $is_super_admin = ( is_array( $super_admins ) && in_array( $wp_user->user_login, $super_admins ) );
11595
+ }
11596
+ }
11597
+
11598
+ return $is_super_admin;
11599
+ }
11600
+
11601
+ #----------------------------------------------------------------------------------
11602
+ #region Plans & Licensing
11603
+ #----------------------------------------------------------------------------------
11604
+
11605
+ /**
11606
+ * Check if running premium plugin code.
11607
+ *
11608
+ * @author Vova Feldman (@svovaf)
11609
+ * @since 1.0.5
11610
+ *
11611
+ * @return bool
11612
+ */
11613
+ function is_premium() {
11614
+ /**
11615
+ * `$this->_plugin` will be `false` when `is_activation_mode` calls this method directly from the
11616
+ * `register_constructor_hooks` method.
11617
+ *
11618
+ * @author Leo Fajardo (@leorw)
11619
+ * @since 2.2.3
11620
+ */
11621
+ return is_object( $this->_plugin ) ?
11622
+ $this->_plugin->is_premium :
11623
+ false;
11624
+ }
11625
+
11626
+ /**
11627
+ * Get site's plan ID.
11628
+ *
11629
+ * @author Vova Feldman (@svovaf)
11630
+ * @since 1.0.2
11631
+ *
11632
+ * @return number
11633
+ */
11634
+ function get_plan_id() {
11635
+ return $this->_site->plan_id;
11636
+ }
11637
+
11638
+ /**
11639
+ * Get site's plan title.
11640
+ *
11641
+ * @author Vova Feldman (@svovaf)
11642
+ * @since 1.0.2
11643
+ *
11644
+ * @return string
11645
+ */
11646
+ function get_plan_title() {
11647
+ $plan = $this->get_plan();
11648
+
11649
+ return is_object( $plan ) ? $plan->title : 'PLAN_TITLE';
11650
+ }
11651
+
11652
+ /**
11653
+ * Get site's plan name.
11654
+ *
11655
+ * @author Vova Feldman (@svovaf)
11656
+ * @since 2.0.0
11657
+ *
11658
+ * @return string
11659
+ */
11660
+ function get_plan_name() {
11661
+ $plan = $this->get_plan();
11662
+
11663
+ return is_object( $plan ) ? $plan->name : 'PLAN_NAME';
11664
+ }
11665
+
11666
+ /**
11667
+ * @author Vova Feldman (@svovaf)
11668
+ * @since 1.0.9
11669
+ *
11670
+ * @return FS_Plugin_Plan|false
11671
+ */
11672
+ function get_plan() {
11673
+ if ( ! is_object( $this->_site ) ) {
11674
+ return false;
11675
+ }
11676
+
11677
+ return FS_Plugin_Plan::is_valid_id( $this->_site->plan_id ) ?
11678
+ $this->_get_plan_by_id( $this->_site->plan_id ) :
11679
+ false;
11680
+ }
11681
+
11682
+ /**
11683
+ * @author Vova Feldman (@svovaf)
11684
+ * @since 1.0.3
11685
+ *
11686
+ * @return bool
11687
+ */
11688
+ function is_trial() {
11689
+ $this->_logger->entrance();
11690
+
11691
+ if ( ! $this->is_registered() || ! is_object( $this->_site ) ) {
11692
+ return false;
11693
+ }
11694
+
11695
+ return $this->_site->is_trial();
11696
+ }
11697
+
11698
+ /**
11699
+ * Check if currently in a trial with payment method (credit card or paypal).
11700
+ *
11701
+ * @author Vova Feldman (@svovaf)
11702
+ * @since 1.1.7
11703
+ *
11704
+ * @return bool
11705
+ */
11706
+ function is_paid_trial() {
11707
+ $this->_logger->entrance();
11708
+
11709
+ if ( ! $this->is_trial() ) {
11710
+ return false;
11711
+ }
11712
+
11713
+ if ( ! $this->has_active_valid_license() ) {
11714
+ return false;
11715
+ }
11716
+
11717
+ if ( $this->_site->trial_plan_id != $this->_license->plan_id ) {
11718
+ return false;
11719
+ }
11720
+
11721
+ /**
11722
+ * @var FS_Subscription $subscription
11723
+ */
11724
+ $subscription = $this->_get_subscription( $this->_license->id );
11725
+
11726
+ return ( is_object( $subscription ) && $subscription->is_active() );
11727
+ }
11728
+
11729
+ /**
11730
+ * Check if trial already utilized.
11731
+ *
11732
+ * @since 1.0.9
11733
+ *
11734
+ * @return bool
11735
+ */
11736
+ function is_trial_utilized() {
11737
+ $this->_logger->entrance();
11738
+
11739
+ if ( ! $this->is_registered() ) {
11740
+ return false;
11741
+ }
11742
+
11743
+ return $this->_site->is_trial_utilized();
11744
+ }
11745
+
11746
+ /**
11747
+ * Get trial plan information (if in trial).
11748
+ *
11749
+ * @author Vova Feldman (@svovaf)
11750
+ * @since 1.0.9
11751
+ *
11752
+ * @return bool|FS_Plugin_Plan
11753
+ */
11754
+ function get_trial_plan() {
11755
+ $this->_logger->entrance();
11756
+
11757
+ if ( ! $this->is_trial() ) {
11758
+ return false;
11759
+ }
11760
+
11761
+ // Try to load plan from local cache.
11762
+ $trial_plan = $this->_get_plan_by_id( $this->_site->trial_plan_id );
11763
+
11764
+ if ( ! is_object( $trial_plan ) ) {
11765
+ $trial_plan = $this->_fetch_site_plan( $this->_site->trial_plan_id );
11766
+
11767
+ /**
11768
+ * If managed to fetch the plan, add it to the plans collection.
11769
+ */
11770
+ if ( $trial_plan instanceof FS_Plugin_Plan ) {
11771
+ if ( ! is_array( $this->_plans ) ) {
11772
+ $this->_plans = array();
11773
+ }
11774
+
11775
+ $this->_plans[] = $trial_plan;
11776
+ $this->_store_plans();
11777
+ }
11778
+ }
11779
+
11780
+ if ( $trial_plan instanceof FS_Plugin_Plan ) {
11781
+ return $trial_plan;
11782
+ }
11783
+
11784
+ /**
11785
+ * If for some reason failed to get the trial plan, fallback to a dummy name and title.
11786
+ */
11787
+ $trial_plan = new FS_Plugin_Plan();
11788
+ $trial_plan->id = $this->_site->trial_plan_id;
11789
+ $trial_plan->name = 'pro';
11790
+ $trial_plan->title = 'Pro';
11791
+
11792
+ return $trial_plan;
11793
+ }
11794
+
11795
+ /**
11796
+ * Check if the user has an activate, non-expired license on current plugin's install.
11797
+ *
11798
+ * @since 1.0.9
11799
+ *
11800
+ * @return bool
11801
+ */
11802
+ function is_paying() {
11803
+ $this->_logger->entrance();
11804
+
11805
+ if ( ! $this->is_registered() ) {
11806
+ return false;
11807
+ }
11808
+
11809
+ if ( ! $this->has_paid_plan() ) {
11810
+ return false;
11811
+ }
11812
+
11813
+ return (
11814
+ ! $this->is_trial() &&
11815
+ 'free' !== $this->get_plan_name() &&
11816
+ $this->has_active_valid_license()
11817
+ );
11818
+ }
11819
+
11820
+ /**
11821
+ * @author Vova Feldman (@svovaf)
11822
+ * @since 1.0.4
11823
+ *
11824
+ * @return bool
11825
+ */
11826
+ function is_free_plan() {
11827
+ if ( ! $this->is_registered() ) {
11828
+ return true;
11829
+ }
11830
+
11831
+ if ( ! $this->has_paid_plan() ) {
11832
+ return true;
11833
+ }
11834
+
11835
+ return (
11836
+ 'free' === $this->get_plan_name() ||
11837
+ ! $this->has_features_enabled_license()
11838
+ );
11839
+ }
11840
+
11841
+ /**
11842
+ * @author Vova Feldman (@svovaf)
11843
+ * @since 1.0.5
11844
+ *
11845
+ * @return bool
11846
+ */
11847
+ function _has_premium_license() {
11848
+ $this->_logger->entrance();
11849
+
11850
+ $premium_license = $this->_get_available_premium_license();
11851
+
11852
+ return ( false !== $premium_license );
11853
+ }
11854
+
11855
+ /**
11856
+ * Check if user has any licenses associated with the plugin (including expired or blocking).
11857
+ *
11858
+ * @author Vova Feldman (@svovaf)
11859
+ * @since 1.1.7.3
11860
+ *
11861
+ * @param bool $including_foreign
11862
+ *
11863
+ * @return bool
11864
+ */
11865
+ function has_any_license( $including_foreign = true ) {
11866
+ if ( ! is_array( $this->_licenses ) || 0 === count( $this->_licenses ) ) {
11867
+ return false;
11868
+ }
11869
+
11870
+ if ( $including_foreign ) {
11871
+ return true;
11872
+ }
11873
+
11874
+ foreach ( $this->_licenses as $license ) {
11875
+ if ( $this->_user->id == $license->user_id ) {
11876
+ return true;
11877
+ }
11878
+ }
11879
+
11880
+ return false;
11881
+ }
11882
+
11883
+ /**
11884
+ * @author Vova Feldman (@svovaf)
11885
+ * @since 1.0.5
11886
+ *
11887
+ * @param bool|null $is_localhost
11888
+ *
11889
+ * @return FS_Plugin_License|false
11890
+ */
11891
+ function _get_available_premium_license( $is_localhost = null ) {
11892
+ $this->_logger->entrance();
11893
+
11894
+ $licenses = $this->get_available_premium_licenses( $is_localhost );
11895
+ if ( ! empty( $licenses ) ) {
11896
+ return $licenses[0];
11897
+ }
11898
+
11899
+ return false;
11900
+ }
11901
+
11902
+ /**
11903
+ * @author Vova Feldman (@svovaf)
11904
+ * @since 1.0.5
11905
+ *
11906
+ * @param bool|null $is_localhost
11907
+ *
11908
+ * @return FS_Plugin_License[]
11909
+ */
11910
+ function get_available_premium_licenses( $is_localhost = null ) {
11911
+ $this->_logger->entrance();
11912
+
11913
+ $licenses = array();
11914
+ if ( ! $this->has_paid_plan() ) {
11915
+ return $licenses;
11916
+ }
11917
+
11918
+ if ( is_array( $this->_licenses ) ) {
11919
+ foreach ( $this->_licenses as $license ) {
11920
+ if ( ! $license->can_activate( $is_localhost ) ) {
11921
+ continue;
11922
+ }
11923
+
11924
+ $licenses[] = $license;
11925
+ }
11926
+ }
11927
+
11928
+ return $licenses;
11929
+ }
11930
+
11931
+ /**
11932
+ * Sync local plugin plans with remote server.
11933
+ *
11934
+ * IMPORTANT: If for some reason a site is associated with deleted plan, we'll preserve the plan's information and append it as the last plan. This means that if plan is deleted, the is_plan() method will ALWAYS return true for any given argument (it becomes the most inclusive plan).
11935
+ *
11936
+ * @author Vova Feldman (@svovaf)
11937
+ * @since 1.0.5
11938
+ *
11939
+ * @return FS_Plugin_Plan[]|object
11940
+ */
11941
+ function _sync_plans() {
11942
+ $plans = $this->_fetch_plugin_plans();
11943
+
11944
+ if ( $this->is_array_instanceof( $plans, 'FS_Plugin_Plan' ) ) {
11945
+ $plans_map = array();
11946
+ foreach ( $plans as $plan ) {
11947
+ $plans_map[ $plan->id ] = true;
11948
+ }
11949
+
11950
+ $plans_ids_to_keep = $this->get_plans_ids_associated_with_installs();
11951
+
11952
+ foreach ( $plans_ids_to_keep as $plan_id ) {
11953
+ if ( isset( $plans_map[ $plan_id ] ) ) {
11954
+ continue;
11955
+ }
11956
+
11957
+ $missing_plan = self::_get_plan_by_id( $plan_id );
11958
+
11959
+ if ( is_object( $missing_plan ) ) {
11960
+ $plans[] = $missing_plan;
11961
+ }
11962
+ }
11963
+
11964
+ $this->_plans = $plans;
11965
+ $this->_store_plans();
11966
+ }
11967
+
11968
+ $this->do_action( 'after_plans_sync', $plans );
11969
+
11970
+ return $this->_plans;
11971
+ }
11972
+
11973
+ /**
11974
+ * Check if specified plan exists locally. If not, fetch it and store it.
11975
+ *
11976
+ * @author Vova Feldman (@svovaf)
11977
+ * @since 2.0.0
11978
+ *
11979
+ * @param number $plan_id
11980
+ *
11981
+ * @return \FS_Plugin_Plan|object The plan entity or the API error object on failure.
11982
+ */
11983
+ private function sync_plan_if_not_exist( $plan_id ) {
11984
+ $plan = self::_get_plan_by_id( $plan_id );
11985
+
11986
+ if ( is_object( $plan ) ) {
11987
+ // Plan already exists.
11988
+ return $plan;
11989
+ }
11990
+
11991
+ $plan = $this->fetch_plan_by_id( $plan_id );
11992
+
11993
+ if ( $plan instanceof FS_Plugin_Plan ) {
11994
+ $this->_plans[] = $plan;
11995
+ $this->_store_plans();
11996
+
11997
+ return $plan;
11998
+ }
11999
+
12000
+ return $plan;
12001
+ }
12002
+
12003
+ /**
12004
+ * Check if specified license exists locally. If not, fetch it and store it.
12005
+ *
12006
+ * @author Vova Feldman (@svovaf)
12007
+ * @since 2.0.0
12008
+ *
12009
+ * @param number $license_id
12010
+ * @param string $license_key
12011
+ *
12012
+ * @return \FS_Plugin_Plan|object The plan entity or the API error object on failure.
12013
+ */
12014
+ private function sync_license_if_not_exist( $license_id, $license_key ) {
12015
+ $license = $this->_get_license_by_id( $license_id );
12016
+
12017
+ if ( is_object( $license ) ) {
12018
+ // License already exists.
12019
+ return $license;
12020
+ }
12021
+
12022
+ $license = $this->fetch_license_by_key( $license_id, $license_key );
12023
+
12024
+ if ( $license instanceof FS_Plugin_License ) {
12025
+ $this->_licenses[] = $license;
12026
+
12027
+ $this->set_license( $license );
12028
+
12029
+ $this->_store_licenses();
12030
+
12031
+ return $license;
12032
+ }
12033
+
12034
+ return $license;
12035
+ }
12036
+
12037
+ /**
12038
+ * Get a collection of unique plan IDs that are associated with any installs in the network.
12039
+ *
12040
+ * @author Leo Fajardo (@leorw)
12041
+ * @since 2.0.0
12042
+ *
12043
+ * @return number[]
12044
+ */
12045
+ private function get_plans_ids_associated_with_installs() {
12046
+ if ( ! is_multisite() ) {
12047
+ if ( ! is_object( $this->_site ) ||
12048
+ ! FS_Plugin_Plan::is_valid_id( $this->_site->plan_id )
12049
+ ) {
12050
+ return array();
12051
+ }
12052
+
12053
+ return array( $this->_site->plan_id );
12054
+ }
12055
+
12056
+ $plan_ids = array();
12057
+ $sites = self::get_sites();
12058
+ foreach ( $sites as $site ) {
12059
+ $blog_id = self::get_site_blog_id( $site );
12060
+ $install = $this->get_install_by_blog_id( $blog_id );
12061
+
12062
+ if ( ! is_object( $install ) ||
12063
+ ! FS_Plugin_Plan::is_valid_id( $install->plan_id )
12064
+ ) {
12065
+ continue;
12066
+ }
12067
+
12068
+ $plan_ids[ $install->plan_id ] = true;
12069
+ }
12070
+
12071
+ return array_keys( $plan_ids );
12072
+ }
12073
+
12074
+ /**
12075
+ * Get a collection of unique license IDs that are associated with any installs in the network.
12076
+ *
12077
+ * @author Leo Fajardo (@leorw)
12078
+ * @since 2.0.0
12079
+ *
12080
+ * @return number[]
12081
+ */
12082
+ private function get_license_ids_associated_with_installs() {
12083
+ if ( ! $this->_is_network_active ) {
12084
+ if ( ! is_object( $this->_site ) ||
12085
+ ! FS_Plugin_License::is_valid_id( $this->_site->license_id )
12086
+ ) {
12087
+ return array();
12088
+ }
12089
+
12090
+ return array( $this->_site->license_id );
12091
+ }
12092
+
12093
+ $license_ids = array();
12094
+ $sites = self::get_sites();
12095
+ foreach ( $sites as $site ) {
12096
+ $blog_id = self::get_site_blog_id( $site );
12097
+ $install = $this->get_install_by_blog_id( $blog_id );
12098
+
12099
+ if ( ! is_object( $install ) ||
12100
+ ! FS_Plugin_License::is_valid_id( $install->license_id )
12101
+ ) {
12102
+ continue;
12103
+ }
12104
+
12105
+ $license_ids[ $install->license_id ] = true;
12106
+ }
12107
+
12108
+ return array_keys( $license_ids );
12109
+ }
12110
+
12111
+ /**
12112
+ * @author Vova Feldman (@svovaf)
12113
+ * @since 1.0.5
12114
+ *
12115
+ * @param number $id
12116
+ *
12117
+ * @return FS_Plugin_Plan|false
12118
+ */
12119
+ function _get_plan_by_id( $id ) {
12120
+ $this->_logger->entrance();
12121
+
12122
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
12123
+ $this->_sync_plans();
12124
+ }
12125
+
12126
+ foreach ( $this->_plans as $plan ) {
12127
+ if ( $id == $plan->id ) {
12128
+ return $plan;
12129
+ }
12130
+ }
12131
+
12132
+ return false;
12133
+ }
12134
+
12135
+ /**
12136
+ * @author Vova Feldman (@svovaf)
12137
+ * @since 1.1.8.1
12138
+ *
12139
+ * @param string $name
12140
+ *
12141
+ * @return FS_Plugin_Plan|false
12142
+ */
12143
+ private function get_plan_by_name( $name ) {
12144
+ $this->_logger->entrance();
12145
+
12146
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
12147
+ $this->_sync_plans();
12148
+ }
12149
+
12150
+ foreach ( $this->_plans as $plan ) {
12151
+ if ( $name == $plan->name ) {
12152
+ return $plan;
12153
+ }
12154
+ }
12155
+
12156
+ return false;
12157
+ }
12158
+
12159
+ /**
12160
+ * Sync local licenses with remote server.
12161
+ *
12162
+ * @author Vova Feldman (@svovaf)
12163
+ * @since 1.0.6
12164
+ *
12165
+ * @param number|bool $site_license_id
12166
+ * @param number|null $blog_id
12167
+ *
12168
+ * @return FS_Plugin_License[]|object
12169
+ */
12170
+ function _sync_licenses( $site_license_id = false, $blog_id = null ) {
12171
+ $this->_logger->entrance();
12172
+
12173
+ $is_network_admin = fs_is_network_admin();
12174
+
12175
+ if ( $is_network_admin && is_null( $blog_id ) ) {
12176
+ $all_licenses = self::get_all_licenses( $this->_module_id );
12177
+ } else {
12178
+ $all_licenses = $this->get_user_licenses( $this->_user->id );
12179
+ }
12180
+
12181
+ $foreign_licenses = $this->get_foreign_licenses_info( $all_licenses, $site_license_id );
12182
+
12183
+ $all_licenses_map = array();
12184
+ foreach ( $all_licenses as $license ) {
12185
+ $all_licenses_map[ $license->id ] = true;
12186
+ }
12187
+
12188
+ $licenses = $this->_fetch_licenses( false, $site_license_id, $foreign_licenses, $blog_id );
12189
+
12190
+ if ( $this->is_array_instanceof( $licenses, 'FS_Plugin_License' ) ) {
12191
+ $licenses_map = array();
12192
+ foreach ( $licenses as $license ) {
12193
+ $licenses_map[ $license->id ] = true;
12194
+ }
12195
+
12196
+ // $license_ids_to_keep = $this->get_license_ids_associated_with_installs();
12197
+ // foreach ( $license_ids_to_keep as $license_id ) {
12198
+ // if ( isset( $licenses_map[ $license_id ] ) ) {
12199
+ // continue;
12200
+ // }
12201
+ //
12202
+ // $missing_license = self::_get_license_by_id( $license_id, false );
12203
+ // if ( is_object( $missing_license ) ) {
12204
+ // $licenses[] = $missing_license;
12205
+ // $licenses_map[ $missing_license->id ] = true;
12206
+ // }
12207
+ // }
12208
+
12209
+ $user_license_ids = $this->get_user_linked_license_ids( $this->_user->id );
12210
+
12211
+ foreach ( $user_license_ids as $key => $license_id ) {
12212
+ if ( ! isset( $licenses_map[ $license_id ] ) ) {
12213
+ // Remove access to licenses that no longer exist.
12214
+ unset( $user_license_ids[ $key ] );
12215
+ }
12216
+ }
12217
+
12218
+ if ( ! empty( $user_license_ids ) ) {
12219
+ foreach ( $licenses_map as $license_id => $value ) {
12220
+ if ( ! isset( $all_licenses_map[ $license_id ] ) ) {
12221
+ // Associate new licenses with the user who triggered the license syncing.
12222
+ $user_license_ids[] = $license_id;
12223
+ }
12224
+ }
12225
+
12226
+ $user_license_ids = array_unique( $user_license_ids );
12227
+ } else {
12228
+ $user_license_ids = array_keys( $licenses_map );
12229
+ }
12230
+
12231
+ if ( ! $is_network_admin || ! is_null( $blog_id ) ) {
12232
+ $user_licenses = array();
12233
+ foreach ( $licenses as $license ) {
12234
+ if ( ! in_array( $license->id, $user_license_ids ) ) {
12235
+ continue;
12236
+ }
12237
+
12238
+ $user_licenses[] = $license;
12239
+ }
12240
+
12241
+ $this->_licenses = $user_licenses;
12242
+ } else {
12243
+ $this->_licenses = $licenses;
12244
+ }
12245
+
12246
+ $this->set_user_linked_license_ids( $this->_user->id, $user_license_ids );
12247
+
12248
+ $this->_store_licenses( true, $this->_module_id, $licenses );
12249
+ }
12250
+
12251
+ // Update current license.
12252
+ if ( is_object( $this->_license ) ) {
12253
+ $license = $this->_get_license_by_id( $this->_license->id );
12254
+
12255
+ if ( is_object( $license ) ) {
12256
+ /**
12257
+ * `$license` can be `false` in case a user change action has just been completed and this method
12258
+ * has synced the `$this->_licenses` collection for the new user. In this case, the
12259
+ * `$this->_licenses` collection may have only the newly activated license that is associated with
12260
+ * the new user. `set_license` will eventually be called in the same request by the logic that
12261
+ * follows outside this method which will detect that the install's license has been updated, and
12262
+ * then `_update_site_license` will be called which in turn will call `set_license`.
12263
+ *
12264
+ * @author Leo Fajardo (@leorw)
12265
+ * @since 2.3.2
12266
+ */
12267
+ $this->set_license( $license );
12268
+ }
12269
+ }
12270
+
12271
+ return $this->_licenses;
12272
+ }
12273
+
12274
+ /**
12275
+ * @author Vova Feldman (@svovaf)
12276
+ * @since 1.0.5
12277
+ *
12278
+ * @param number $id
12279
+ * @param bool $sync_licenses
12280
+ *
12281
+ * @return FS_Plugin_License|false
12282
+ */
12283
+ function _get_license_by_id( $id, $sync_licenses = true ) {
12284
+ $this->_logger->entrance();
12285
+
12286
+ if ( ! FS_Plugin_License::is_valid_id( $id ) ) {
12287
+ return false;
12288
+ }
12289
+
12290
+ /**
12291
+ * When running from the network level admin and opted-in from the network,
12292
+ * check if the license exists in the network user licenses collection.
12293
+ *
12294
+ * @author Vova Feldman (@svovaf)
12295
+ * @since 2.0.0
12296
+ */
12297
+ if ( fs_is_network_admin() &&
12298
+ $this->is_network_registered() &&
12299
+ ( ! is_object( $this->_user ) || $this->_storage->network_user_id != $this->_user->id )
12300
+ ) {
12301
+ $licenses = $this->get_user_licenses( $this->_storage->network_user_id );
12302
+
12303
+ foreach ( $licenses as $license ) {
12304
+ if ( $id == $license->id ) {
12305
+ return $license;
12306
+ }
12307
+ }
12308
+ }
12309
+
12310
+ if ( ! $this->has_any_license() && $sync_licenses ) {
12311
+ $this->_sync_licenses( $id );
12312
+ }
12313
+
12314
+ if ( is_array( $this->_licenses ) ) {
12315
+ foreach ( $this->_licenses as $license ) {
12316
+ if ( $id == $license->id ) {
12317
+ return $license;
12318
+ }
12319
+ }
12320
+ }
12321
+
12322
+ return false;
12323
+ }
12324
+
12325
+ /**
12326
+ * Get license by ID. Unlike _get_license_by_id(), this method only checks the local storage and return any license, whether it's associated with the current context user/install or not.
12327
+ *
12328
+ * @author Vova Feldman (@svovaf)
12329
+ * @since 2.0.0
12330
+ *
12331
+ * @param number $id
12332
+ *
12333
+ * @return FS_Plugin_License
12334
+ */
12335
+ private function get_license_by_id( $id ) {
12336
+ $licenses = self::get_all_licenses( $this->_module_id );
12337
+
12338
+ if ( is_array( $licenses ) && ! empty( $licenses ) ) {
12339
+ foreach ( $licenses as $license ) {
12340
+ if ( $id == $license->id ) {
12341
+ return $license;
12342
+ }
12343
+ }
12344
+ }
12345
+
12346
+ return null;
12347
+ }
12348
+
12349
+ /**
12350
+ * Synchronize the site's context license by fetching the license form the API and updating the local data with it.
12351
+ *
12352
+ * @author Vova Feldman (@svovaf)
12353
+ * @since 2.0.0
12354
+ *
12355
+ * @return \FS_Plugin_License|mixed
12356
+ */
12357
+ private function sync_site_license() {
12358
+ $api = $this->get_api_user_scope();
12359
+
12360
+ $result = $api->get( "/licenses/{$this->_license->id}.json?license_key=" . urlencode( $this->_license->secret_key ), true );
12361
+
12362
+ if ( ! $this->is_api_result_entity( $result ) ) {
12363
+ return $result;
12364
+ }
12365
+
12366
+ $license = $this->_update_site_license( new FS_Plugin_License( $result ) );
12367
+ $this->_store_licenses();
12368
+
12369
+ return $license;
12370
+ }
12371
+
12372
+ /**
12373
+ * Get all user's available licenses for the current module.
12374
+ *
12375
+ * @author Vova Feldman (@svovaf)
12376
+ * @since 2.0.0
12377
+ *
12378
+ * @param number $user_id
12379
+ *
12380
+ * @return FS_Plugin_License[]
12381
+ */
12382
+ private function get_user_licenses( $user_id ) {
12383
+ $all_licenses = self::get_all_licenses( $this->_module_id );
12384
+ if ( empty( $all_licenses ) ) {
12385
+ return array();
12386
+ }
12387
+
12388
+ $user_license_ids = $this->get_user_linked_license_ids( $user_id );
12389
+ if ( empty( $user_license_ids ) ) {
12390
+ return array();
12391
+ }
12392
+
12393
+ $licenses = array();
12394
+ foreach ( $all_licenses as $license ) {
12395
+ if ( in_array( $license->id, $user_license_ids ) ) {
12396
+ $licenses[] = $license;
12397
+ }
12398
+ }
12399
+
12400
+ return $licenses;
12401
+ }
12402
+
12403
+ /**
12404
+ * Checks if the context license is network activated except on the given blog ID.
12405
+ *
12406
+ * @author Vova Feldman (@svovaf)
12407
+ * @since 2.0.0
12408
+ *
12409
+ * @param int $except_blog_id
12410
+ *
12411
+ * @return bool
12412
+ */
12413
+ private function is_license_network_active( $except_blog_id = 0 ) {
12414
+ $this->_logger->entrance();
12415
+
12416
+ if ( ! is_object( $this->_license ) ) {
12417
+ return false;
12418
+ }
12419
+
12420
+ $sites = self::get_sites();
12421
+
12422
+ if ( $this->_license->total_activations() < ( count( $sites ) - 1 ) ) {
12423
+ // There are more sites than the number of activations, so license cannot be network activated.
12424
+ return false;
12425
+ }
12426
+
12427
+ foreach ( $sites as $site ) {
12428
+ $blog_id = self::get_site_blog_id( $site );
12429
+
12430
+ if ( $except_blog_id == $blog_id ) {
12431
+ // Skip excluded blog.
12432
+ continue;
12433
+ }
12434
+
12435
+ $install = $this->get_install_by_blog_id( $blog_id );
12436
+
12437
+ if ( is_object( $install ) && $install->license_id != $this->_license->id ) {
12438
+ return false;
12439
+ }
12440
+ }
12441
+
12442
+ return true;
12443
+ }
12444
+
12445
+ /**
12446
+ * Checks if license can be activated on all the network sites (opted-in or skipped) that are not yet associated with a license. If possible, try to make the activation, if not return false.
12447
+ *
12448
+ * Notice: On success, this method will also update the license activations counters (without updating the license in the storage).
12449
+ *
12450
+ * @author Vova Feldman (@svovaf)
12451
+ * @since 2.0.0
12452
+ *
12453
+ * @param \FS_User $user
12454
+ * @param \FS_Plugin_License $license
12455
+ *
12456
+ * @return bool
12457
+ */
12458
+ private function try_activate_license_on_network( FS_User $user, FS_Plugin_License $license ) {
12459
+ $this->_logger->entrance();
12460
+
12461
+ $result = $this->can_activate_license_on_network( $license );
12462
+
12463
+ if ( false === $result ) {
12464
+ return false;
12465
+ }
12466
+
12467
+ $installs_without_license = $result['installs'];
12468
+ if ( ! empty( $installs_without_license ) ) {
12469
+ $this->activate_license_on_many_installs( $user, $license->secret_key, $installs_without_license );
12470
+ }
12471
+
12472
+ $disconnected_site_ids = $result['sites'];
12473
+ if ( ! empty( $disconnected_site_ids ) ) {
12474
+ $this->activate_license_on_many_sites( $user, $license->secret_key, $disconnected_site_ids );
12475
+ }
12476
+
12477
+ $this->link_license_2_user( $license->id, $user->id );
12478
+
12479
+ // Sync license after activations.
12480
+ $license->activated += $result['production_count'];
12481
+ $license->activated_local += $result['localhost_count'];
12482
+
12483
+ // $this->_store_licenses()
12484
+
12485
+ return true;
12486
+ }
12487
+
12488
+ /**
12489
+ * Checks if the given license can be activated on the whole network.
12490
+ *
12491
+ * @author Vova Feldman (@svovaf)
12492
+ * @since 2.0.0
12493
+ *
12494
+ * @param \FS_Plugin_License $license
12495
+ *
12496
+ * @return false|array {
12497
+ * @type array[int]FS_Site $installs Blog ID to install map.
12498
+ * @type int[] $sites Non-connected blog IDs.
12499
+ * @type int $production_count Production sites count.
12500
+ * @type int $localhost_count Production sites count.
12501
+ * }
12502
+ */
12503
+ private function can_activate_license_on_network( FS_Plugin_License $license ) {
12504
+ $sites = self::get_sites();
12505
+
12506
+ $production_count = 0;
12507
+ $localhost_count = 0;
12508
+
12509
+ $installs_without_license = array();
12510
+ $disconnected_site_ids = array();
12511
+
12512
+ foreach ( $sites as $site ) {
12513
+ $blog_id = self::get_site_blog_id( $site );
12514
+ $install = $this->get_install_by_blog_id( $blog_id );
12515
+
12516
+ if ( is_object( $install ) ) {
12517
+ if ( FS_Plugin_License::is_valid_id( $install->license_id ) ) {
12518
+ // License already activated on the install.
12519
+ continue;
12520
+ }
12521
+
12522
+ $url = $install->url;
12523
+
12524
+ $installs_without_license[ $blog_id ] = $install;
12525
+ } else {
12526
+ $url = is_object( $site ) ?
12527
+ $site->siteurl :
12528
+ self::get_unfiltered_site_url( $blog_id );
12529
+
12530
+ $disconnected_site_ids[] = $blog_id;
12531
+ }
12532
+
12533
+ if ( FS_Site::is_localhost_by_address( $url ) ) {
12534
+ $localhost_count ++;
12535
+ } else {
12536
+ $production_count ++;
12537
+ }
12538
+ }
12539
+
12540
+ if ( ! $license->can_activate_bulk( $production_count, $localhost_count ) ) {
12541
+ return false;
12542
+ }
12543
+
12544
+ return array(
12545
+ 'installs' => $installs_without_license,
12546
+ 'sites' => $disconnected_site_ids,
12547
+ 'production_count' => $production_count,
12548
+ 'localhost_count' => $localhost_count,
12549
+ );
12550
+ }
12551
+
12552
+ /**
12553
+ * Activate a given license on a collection of installs.
12554
+ *
12555
+ * @author Vova Feldman (@svovaf)
12556
+ * @since 2.0.0
12557
+ *
12558
+ * @param \FS_User $user
12559
+ * @param string $license_key
12560
+ * @param array $blog_2_install_map {
12561
+ * @key int Blog ID.
12562
+ * @value FS_Site Blog's associated install.
12563
+ * }
12564
+ *
12565
+ * @return mixed|true
12566
+ */
12567
+ private function activate_license_on_many_installs(
12568
+ FS_User $user,
12569
+ $license_key,
12570
+ array $blog_2_install_map
12571
+ ) {
12572
+ $params = array(
12573
+ array( 'license_key' => $this->apply_filters( 'license_key', $license_key ) )
12574
+ );
12575
+
12576
+ $install_2_blog_map = array();
12577
+ foreach ( $blog_2_install_map as $blog_id => $install ) {
12578
+ $params[] = array( 'id' => $install->id );
12579
+
12580
+ $install_2_blog_map[ $install->id ] = $blog_id;
12581
+ }
12582
+
12583
+ $result = $this->get_api_user_scope_by_user( $user )->call(
12584
+ "plugins/{$this->_plugin->id}/installs.json",
12585
+ 'PUT',
12586
+ $params
12587
+ );
12588
+
12589
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
12590
+ return $result;
12591
+ }
12592
+
12593
+ foreach ( $result->installs as $r_install ) {
12594
+ $install = new FS_Site( $r_install );
12595
+ $install->is_disconnected = false;
12596
+
12597
+ // Update install.
12598
+ $this->_store_site(
12599
+ true,
12600
+ $install_2_blog_map[ $r_install->id ],
12601
+ $install
12602
+ );
12603
+ }
12604
+
12605
+ return true;
12606
+ }
12607
+
12608
+ /**
12609
+ * Activate a given license on a collection of blogs/sites that are not yet opted-in.
12610
+ *
12611
+ * @author Vova Feldman (@svovaf)
12612
+ * @since 2.3.1
12613
+ *
12614
+ * @param \FS_User $user
12615
+ * @param string $license_key
12616
+ *
12617
+ * @return true|mixed True if successful, otherwise, the API result.
12618
+ */
12619
+ private function activate_license_on_site( FS_User $user, $license_key ) {
12620
+ return $this->activate_license_on_many_sites( $user, $license_key );
12621
+ }
12622
+
12623
+ /**
12624
+ * Activate a given license on a collection of blogs/sites that are not yet opted-in.
12625
+ *
12626
+ * @author Vova Feldman (@svovaf)
12627
+ * @since 2.0.0
12628
+ *
12629
+ * @param \FS_User $user
12630
+ * @param string $license_key
12631
+ * @param int[] $site_ids
12632
+ *
12633
+ * @return true|mixed True if successful, otherwise, the API result.
12634
+ */
12635
+ private function activate_license_on_many_sites(
12636
+ FS_User $user,
12637
+ $license_key,
12638
+ array $site_ids = array()
12639
+ ) {
12640
+ $sites = array();
12641
+ foreach ( $site_ids as $site_id ) {
12642
+ $sites[] = $this->get_site_info( array( 'blog_id' => $site_id ) );
12643
+ }
12644
+
12645
+ // Install the plugin.
12646
+ $result = $this->create_installs_with_user(
12647
+ $user,
12648
+ $license_key,
12649
+ false,
12650
+ $sites,
12651
+ false,
12652
+ true
12653
+ );
12654
+
12655
+ if ( ! $this->is_api_result_entity( $result ) &&
12656
+ ! $this->is_api_result_object( $result, 'installs' )
12657
+ ) {
12658
+ return $result;
12659
+ }
12660
+
12661
+ $installs = array();
12662
+
12663
+ if ( $this->is_api_result_entity( $result ) ) {
12664
+ $install = new FS_Site( $result );
12665
+
12666
+ $this->_user = $user;
12667
+
12668
+ $this->_store_site( true, null, $install );
12669
+
12670
+ $this->_site = $install;
12671
+
12672
+ $this->reset_anonymous_mode();
12673
+ } else {
12674
+ foreach ( $result->installs as $install ) {
12675
+ $installs[] = new FS_Site( $install );
12676
+ }
12677
+
12678
+ // Map site addresses to their blog IDs.
12679
+ $address_to_blog_map = $this->get_address_to_blog_map();
12680
+
12681
+ $first_blog_id = null;
12682
+
12683
+ foreach ( $installs as $install ) {
12684
+ $address = trailingslashit( fs_strip_url_protocol( $install->url ) );
12685
+ $blog_id = $address_to_blog_map[ $address ];
12686
+
12687
+ $this->_store_site( true, $blog_id, $install );
12688
+
12689
+ $this->reset_anonymous_mode( $blog_id );
12690
+
12691
+ if ( is_null( $first_blog_id ) ) {
12692
+ $first_blog_id = $blog_id;
12693
+ }
12694
+ }
12695
+
12696
+ if ( ! FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ) {
12697
+ $this->_storage->network_install_blog_id = $first_blog_id;
12698
+ }
12699
+ }
12700
+
12701
+ return true;
12702
+ }
12703
+
12704
+ /**
12705
+ * Sync site's license with user licenses.
12706
+ *
12707
+ * @author Vova Feldman (@svovaf)
12708
+ * @since 1.0.6
12709
+ *
12710
+ * @param FS_Plugin_License|null $new_license
12711
+ *
12712
+ * @return FS_Plugin_License|null
12713
+ */
12714
+ function _update_site_license( $new_license ) {
12715
+ $this->_logger->entrance();
12716
+
12717
+ /**
12718
+ * In case this call will be removed in the future, the `_sync_licenses()` method needs to be updated
12719
+ * accordingly so that it will also handle the case when an ownership change is done via license
12720
+ * activation.
12721
+ *
12722
+ * @author Leo Fajardo (@leorw)
12723
+ * @since 2.3.2
12724
+ */
12725
+ $this->set_license( $new_license );
12726
+
12727
+ if ( ! is_object( $new_license ) ) {
12728
+ $this->_site->license_id = null;
12729
+ $this->_sync_site_subscription( null );
12730
+
12731
+ return $this->_license;
12732
+ }
12733
+
12734
+ $this->_site->license_id = $this->_license->id;
12735
+
12736
+ if ( ! is_array( $this->_licenses ) ) {
12737
+ $this->_licenses = array();
12738
+ }
12739
+
12740
+ $is_license_found = false;
12741
+ for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
12742
+ if ( $new_license->id == $this->_licenses[ $i ]->id ) {
12743
+ $this->_licenses[ $i ] = $new_license;
12744
+
12745
+ $is_license_found = true;
12746
+ break;
12747
+ }
12748
+ }
12749
+
12750
+ // If new license just append.
12751
+ if ( ! $is_license_found ) {
12752
+ $this->_licenses[] = $new_license;
12753
+ }
12754
+
12755
+ $this->_sync_site_subscription( $new_license );
12756
+
12757
+ return $this->_license;
12758
+ }
12759
+
12760
+ /**
12761
+ * @author Vova Feldman (@svovaf)
12762
+ * @since 2.3.1
12763
+ *
12764
+ * @param \FS_Plugin_License $license
12765
+ */
12766
+ private function set_license( FS_Plugin_License $license = null ) {
12767
+ $this->_license = $license;
12768
+
12769
+ $this->maybe_update_whitelabel_flag( $license );
12770
+ }
12771
+
12772
+ /**
12773
+ * @author Leo Fajardo (@leorw)
12774
+ * @since 2.3.1
12775
+ *
12776
+ * @param FS_Plugin_License $license
12777
+ */
12778
+ private function maybe_update_whitelabel_flag( $license ) {
12779
+ $is_whitelabeled = isset( $this->_storage->is_whitelabeled ) ?
12780
+ $this->_storage->is_whitelabeled :
12781
+ false;
12782
+
12783
+ if ( is_object( $license ) ) {
12784
+ $license_user = self::_get_user_by_id( $license->user_id );
12785
+
12786
+ if ( ! is_object( $license_user ) ) {
12787
+ // If foreign license, do not update the `is_whitelabeled` flag.
12788
+ return;
12789
+ }
12790
+
12791
+ if ( $this->is_addon() ) {
12792
+ /**
12793
+ * Store the last license data to the parent's storage since it's needed only when showing the
12794
+ * "Start Debug" dialog which is triggered from the "Account" page. This way, there's no need to
12795
+ * iterate over the add-ons just to get the last license data.
12796
+ */
12797
+ $this->get_parent_instance()->store_last_activated_license_data( $license, $license_user );
12798
+ } else {
12799
+ $this->store_last_activated_license_data( $license );
12800
+ }
12801
+
12802
+ if ( $license->is_whitelabeled ) {
12803
+ // Activated a developer license, data should be hidden.
12804
+ $is_whitelabeled = true;
12805
+ } else if ( $this->is_registered() && $this->_user->id == $license->user_id ) {
12806
+ // The account owner activated a regular license key, no need to hide the data.
12807
+ $is_whitelabeled = false;
12808
+ }
12809
+ }
12810
+
12811
+ $this->_storage->is_whitelabeled = $is_whitelabeled;
12812
+
12813
+ // Reset the whitelabeled status after update.
12814
+ $this->is_whitelabeled = null;
12815
+ if ( $this->is_addon() ) {
12816
+ $parent_fs = $this->get_parent_instance();
12817
+
12818
+ if ( is_object( $parent_fs ) ) {
12819
+ $parent_fs->is_whitelabeled = null;
12820
+ }
12821
+ }
12822
+ }
12823
+
12824
+ /**
12825
+ * @author Leo Fajardo (@leorw)
12826
+ * @since 2.3.1
12827
+ *
12828
+ * @param FS_Plugin_License $license
12829
+ * @param FS_User $license_user
12830
+ */
12831
+ private function store_last_activated_license_data( FS_Plugin_License $license, $license_user = null ) {
12832
+ if ( ! is_object( $license_user ) ) {
12833
+ $this->_storage->last_license_key = md5( $license->secret_key );
12834
+ $this->_storage->last_license_user_id = null;
12835
+ } else {
12836
+ $this->_storage->last_license_user_key = md5( $license_user->secret_key );
12837
+ $this->_storage->last_license_user_id = $license_user->id;
12838
+ }
12839
+ }
12840
+
12841
+ /**
12842
+ * @author Leo Fajardo (@leorw)
12843
+ * @since 2.3.1
12844
+ *
12845
+ * @param bool $ignore_data_debug_mode
12846
+ *
12847
+ * @return bool
12848
+ */
12849
+ function is_whitelabeled_by_flag( $ignore_data_debug_mode = false ) {
12850
+ if ( true !== $this->_storage->is_whitelabeled ) {
12851
+ return false;
12852
+ } else if ( $ignore_data_debug_mode ) {
12853
+ return true;
12854
+ }
12855
+
12856
+ $fs = $this->is_addon() ?
12857
+ $this->get_parent_instance() :
12858
+ $this;
12859
+
12860
+ return ! $fs->is_data_debug_mode();
12861
+ }
12862
+
12863
+ /**
12864
+ * @author Leo Fajardo (@leorw)
12865
+ * @since 2.3.1
12866
+ *
12867
+ * @return number
12868
+ */
12869
+ function get_last_license_user_id() {
12870
+ return ( FS_User::is_valid_id( $this->_storage->last_license_user_id ) ) ?
12871
+ $this->_storage->last_license_user_id :
12872
+ null;
12873
+ }
12874
+
12875
+ /**
12876
+ * @author Leo Fajardo (@leorw)
12877
+ * @since 2.3.1
12878
+ *
12879
+ * @param int $blog_id
12880
+ * @param bool $ignore_data_debug_mode
12881
+ *
12882
+ * @return bool
12883
+ */
12884
+ function is_whitelabeled( $ignore_data_debug_mode = false, $blog_id = null ) {
12885
+ if ( ! is_null( $blog_id ) ) {
12886
+ $this->switch_to_blog( $blog_id );
12887
+ }
12888
+
12889
+ if ( ! is_null( $this->is_whitelabeled ) ) {
12890
+ $is_whitelabeled = $this->is_whitelabeled;
12891
+ } else {
12892
+ $is_whitelabeled = false;
12893
+
12894
+ $is_whitelabeled_flag = $this->is_whitelabeled_by_flag( true );
12895
+
12896
+ if ( ! $this->has_addons() ) {
12897
+ $is_whitelabeled = $is_whitelabeled_flag;
12898
+ } else if ( $is_whitelabeled_flag ) {
12899
+ $is_whitelabeled = true;
12900
+ } else {
12901
+ if ( $this->is_registered() || $this->is_premium() ) {
12902
+ $addon_ids = $this->get_updated_account_addons();
12903
+ } else {
12904
+ $addons = self::get_all_addons();
12905
+
12906
+ $plugin_addons = isset( $addons[ $this->_plugin->id ] ) ?
12907
+ $addons[ $this->_plugin->id ] :
12908
+ array();
12909
+
12910
+ $addon_ids = array();
12911
+ foreach ( $plugin_addons as $addon ) {
12912
+ $addon_ids[] = $addon->id;
12913
+ }
12914
+ }
12915
+
12916
+ $installed_addons = $this->get_installed_addons();
12917
+ foreach ( $installed_addons as $fs_addon ) {
12918
+ $addon_ids[] = $fs_addon->get_id();
12919
+ }
12920
+
12921
+ if ( ! empty( $addon_ids ) ) {
12922
+ $addon_ids = array_unique( $addon_ids );
12923
+
12924
+ $is_network_level = (
12925
+ fs_is_network_admin() &&
12926
+ $this->is_network_active()
12927
+ );
12928
+
12929
+ foreach ( $addon_ids as $addon_id ) {
12930
+ $addon = $this->get_addon( $addon_id );
12931
+
12932
+ if ( ! is_object( $addon ) ) {
12933
+ continue;
12934
+ }
12935
+
12936
+ $addon_storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $addon->slug );
12937
+ $fs_addon = $this->is_addon_activated( $addon_id ) ?
12938
+ self::get_addon_instance( $addon_id ) :
12939
+ null;
12940
+
12941
+ $was_addon_network_activated = false;
12942
+
12943
+ if ( is_object( $fs_addon ) ) {
12944
+ $was_addon_network_activated = $fs_addon->is_network_active();
12945
+ } else if ( $is_network_level ) {
12946
+ $was_addon_network_activated = $addon_storage->get( 'was_plugin_loaded', false, true );
12947
+ }
12948
+
12949
+ $network_delegated_connection = (
12950
+ $was_addon_network_activated &&
12951
+ $addon_storage->get( 'is_delegated_connection', false, true )
12952
+ );
12953
+
12954
+ if (
12955
+ $is_network_level &&
12956
+ ( ! $was_addon_network_activated || $network_delegated_connection )
12957
+ ) {
12958
+ $sites = self::get_sites();
12959
+
12960
+ /**
12961
+ * If in network admin area and the add-on was not network-activated or network-activated
12962
+ * and network-delegated, find any add-on whose is_whitelabeled flag is true.
12963
+ */
12964
+ foreach ( $sites as $site ) {
12965
+ $site_info = $this->get_site_info( $site );
12966
+
12967
+ if ( $addon_storage->get( 'is_whitelabeled', false, $site_info['blog_id'] ) ) {
12968
+ $is_whitelabeled = true;
12969
+ break;
12970
+ }
12971
+ }
12972
+
12973
+ if ( $is_whitelabeled ) {
12974
+ break;
12975
+ }
12976
+ } else {
12977
+ /**
12978
+ * This will be executed when any of the following is met:
12979
+ * 1. Add-on was network-activated, not network-delegated, and in network admin area.
12980
+ * 2. Add-on was network-activated, network-delegated, and in site admin area.
12981
+ * 3. Add-on was not network-activated and in site admin area.
12982
+ */
12983
+ if ( true === $addon_storage->is_whitelabeled ) {
12984
+ $is_whitelabeled = true;
12985
+ break;
12986
+ }
12987
+ }
12988
+ }
12989
+ }
12990
+ }
12991
+
12992
+ $this->is_whitelabeled = $is_whitelabeled;
12993
+
12994
+ if ( ! $is_whitelabeled || ! $this->is_data_debug_mode() ) {
12995
+ $this->_admin_notices->remove_sticky( 'data_debug_mode_enabled' );
12996
+ }
12997
+
12998
+ if ( ! is_null( $blog_id ) ) {
12999
+ $this->restore_current_blog();
13000
+ }
13001
+ }
13002
+
13003
+ return (
13004
+ $is_whitelabeled &&
13005
+ ( $ignore_data_debug_mode || ! $this->is_data_debug_mode() )
13006
+ );
13007
+ }
13008
+
13009
+ /**
13010
+ * Sync site's subscription.
13011
+ *
13012
+ * @author Vova Feldman (@svovaf)
13013
+ * @since 1.0.9
13014
+ *
13015
+ * @param FS_Plugin_License|null $license
13016
+ *
13017
+ * @return bool|\FS_Subscription
13018
+ */
13019
+ private function _sync_site_subscription( $license ) {
13020
+ if ( ! is_object( $license ) ) {
13021
+ $this->delete_unused_subscriptions();
13022
+
13023
+ return false;
13024
+ }
13025
+
13026
+ // Load subscription details if not lifetime.
13027
+ $subscription = $license->is_lifetime() ?
13028
+ false :
13029
+ $this->_fetch_site_license_subscription();
13030
+
13031
+ if ( is_object( $subscription ) && ! isset( $subscription->error ) ) {
13032
+ $this->store_subscription( $subscription );
13033
+ } else {
13034
+ $this->delete_unused_subscriptions();
13035
+ }
13036
+
13037
+ return $subscription;
13038
+ }
13039
+
13040
+ /**
13041
+ * @author Vova Feldman (@svovaf)
13042
+ * @since 1.0.6
13043
+ *
13044
+ * @return bool|\FS_Plugin_License
13045
+ */
13046
+ function _get_license() {
13047
+ if ( ! fs_is_network_admin() || is_object( $this->_license ) ) {
13048
+ return $this->_license;
13049
+ }
13050
+
13051
+ return $this->_get_available_premium_license();
13052
+ }
13053
+
13054
+ /**
13055
+ * @param number $license_id
13056
+ *
13057
+ * @return null|\FS_Subscription
13058
+ */
13059
+ function _get_subscription( $license_id ) {
13060
+ if ( ! isset( $this->_storage->subscriptions ) ||
13061
+ empty( $this->_storage->subscriptions )
13062
+ ) {
13063
+ return null;
13064
+ }
13065
+
13066
+ foreach ( fs_get_entities( $this->_storage->subscriptions, FS_Subscription::get_class_name() ) as $subscription ) {
13067
+ if ( $subscription->license_id == $license_id ) {
13068
+ return $subscription;
13069
+ }
13070
+ }
13071
+
13072
+ return null;
13073
+ }
13074
+
13075
+ /**
13076
+ * @author Leo Fajardo (@leorw)
13077
+ * @since 2.0.0
13078
+ *
13079
+ * @param FS_Subscription $subscription
13080
+ */
13081
+ function store_subscription( FS_Subscription $subscription ) {
13082
+ if ( ! isset( $this->_storage->subscriptions ) ) {
13083
+ $this->_storage->subscriptions = array();
13084
+ }
13085
+
13086
+ if ( empty( $this->_storage->subscriptions ) || ! is_multisite() ) {
13087
+ $this->_storage->subscriptions = array( $subscription );
13088
+
13089
+ return;
13090
+ }
13091
+
13092
+ $subscriptions = fs_get_entities( $this->_storage->subscriptions, FS_Subscription::get_class_name() );
13093
+
13094
+ $updated_subscription = false;
13095
+ foreach ( $subscriptions as $key => $existing_subscription ) {
13096
+ if ( $existing_subscription->id == $subscription->id ) {
13097
+ $subscriptions[ $key ] = $subscription;
13098
+ $updated_subscription = true;
13099
+ break;
13100
+ }
13101
+ }
13102
+
13103
+ if ( ! $updated_subscription ) {
13104
+ $subscriptions[] = $subscription;
13105
+ }
13106
+
13107
+ $this->_storage->subscriptions = $subscriptions;
13108
+ }
13109
+
13110
+ /**
13111
+ * @author Leo Fajardo (@leorw)
13112
+ * @since 2.0.0
13113
+ */
13114
+ function delete_unused_subscriptions() {
13115
+ if ( ! isset( $this->_storage->subscriptions ) ||
13116
+ empty( $this->_storage->subscriptions ) ||
13117
+ // Clean up only if there are already at least 3 subscriptions.
13118
+ ( count( $this->_storage->subscriptions ) < 3 )
13119
+ ) {
13120
+ return;
13121
+ }
13122
+
13123
+ if ( ! is_multisite() ) {
13124
+ // If not multisite, there should only be 1 subscription, so just clear the array.
13125
+ $this->_storage->subscriptions = array();
13126
+
13127
+ return;
13128
+ }
13129
+
13130
+ $subscriptions_to_keep_by_license_id_map = array();
13131
+ $sites = self::get_sites();
13132
+ foreach ( $sites as $site ) {
13133
+ $blog_id = self::get_site_blog_id( $site );
13134
+ $install = $this->get_install_by_blog_id( $blog_id );
13135
+
13136
+ if ( ! is_object( $install ) ||
13137
+ ! FS_Plugin_License::is_valid_id( $install->license_id )
13138
+ ) {
13139
+ continue;
13140
+ }
13141
+
13142
+ $subscriptions_to_keep_by_license_id_map[ $install->license_id ] = true;
13143
+ }
13144
+
13145
+ if ( empty( $subscriptions_to_keep_by_license_id_map ) ) {
13146
+ $this->_storage->subscriptions = array();
13147
+
13148
+ return;
13149
+ }
13150
+
13151
+ foreach ( $this->_storage->subscriptions as $key => $subscription ) {
13152
+ if ( ! isset( $subscriptions_to_keep_by_license_id_map[ $subscription->license_id ] ) ) {
13153
+ unset( $this->_storage->subscriptions[ $key ] );
13154
+ }
13155
+ }
13156
+ }
13157
+
13158
+ /**
13159
+ * @author Vova Feldman (@svovaf)
13160
+ * @since 1.0.2
13161
+ *
13162
+ * @param string $plan Plan name
13163
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
13164
+ *
13165
+ * @return bool
13166
+ */
13167
+ function is_plan( $plan, $exact = false ) {
13168
+ $this->_logger->entrance();
13169
+
13170
+ if ( ! $this->is_registered() ) {
13171
+ return false;
13172
+ }
13173
+
13174
+ $plan = strtolower( $plan );
13175
+
13176
+ $current_plan_name = $this->get_plan_name();
13177
+
13178
+ if ( $current_plan_name === $plan ) {
13179
+ // Exact plan.
13180
+ return true;
13181
+ } else if ( $exact ) {
13182
+ // Required exact, but plans are different.
13183
+ return false;
13184
+ }
13185
+
13186
+ $current_plan_order = - 1;
13187
+ $required_plan_order = PHP_INT_MAX;
13188
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
13189
+ if ( $plan === $this->_plans[ $i ]->name ) {
13190
+ $required_plan_order = $i;
13191
+ } else if ( $current_plan_name === $this->_plans[ $i ]->name ) {
13192
+ $current_plan_order = $i;
13193
+ }
13194
+ }
13195
+
13196
+ return ( $current_plan_order > $required_plan_order );
13197
+ }
13198
+
13199
+ /**
13200
+ * Check if module has only one plan.
13201
+ *
13202
+ * @author Vova Feldman (@svovaf)
13203
+ * @since 1.2.1.7
13204
+ *
13205
+ * @param bool $double_check In some cases developers prefer to release their paid offering as premium-only, even though there is a free version. For those cases, looking at the 'is_premium_only' value isn't enough because the result will return false even when the product has only signle paid plan.
13206
+ *
13207
+ * @return bool
13208
+ */
13209
+ function is_single_plan( $double_check = false ) {
13210
+ $this->_logger->entrance();
13211
+
13212
+ if ( ! $this->is_registered() ||
13213
+ ! is_array( $this->_plans ) ||
13214
+ 0 === count( $this->_plans )
13215
+ ) {
13216
+ return true;
13217
+ }
13218
+
13219
+ $has_free_plan = $this->has_free_plan();
13220
+
13221
+ if ( ! $has_free_plan && $double_check ) {
13222
+ foreach ( $this->_plans as $plan ) {
13223
+ if ( $plan->is_free() ) {
13224
+ $has_free_plan = true;
13225
+ break;
13226
+ }
13227
+ }
13228
+ }
13229
+
13230
+ return ( 1 === ( count( $this->_plans ) - ( $has_free_plan ? 1 : 0 ) ) );
13231
+ }
13232
+
13233
+ /**
13234
+ * Check if plan based on trial. If not in trial mode, should return false.
13235
+ *
13236
+ * @since 1.0.9
13237
+ *
13238
+ * @param string $plan Plan name
13239
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
13240
+ *
13241
+ * @return bool
13242
+ */
13243
+ function is_trial_plan( $plan, $exact = false ) {
13244
+ $this->_logger->entrance();
13245
+
13246
+ if ( ! $this->is_registered() ) {
13247
+ return false;
13248
+ }
13249
+
13250
+ if ( ! $this->is_trial() ) {
13251
+ return false;
13252
+ }
13253
+
13254
+ $trial_plan = $this->get_trial_plan();
13255
+
13256
+ if ( $trial_plan->name === $plan ) {
13257
+ // Exact plan.
13258
+ return true;
13259
+ } else if ( $exact ) {
13260
+ // Required exact, but plans are different.
13261
+ return false;
13262
+ }
13263
+
13264
+ $current_plan_order = - 1;
13265
+ $required_plan_order = - 1;
13266
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
13267
+ if ( $plan === $this->_plans[ $i ]->name ) {
13268
+ $required_plan_order = $i;
13269
+ } else if ( $trial_plan->name === $this->_plans[ $i ]->name ) {
13270
+ $current_plan_order = $i;
13271
+ }
13272
+ }
13273
+
13274
+ return ( $current_plan_order > $required_plan_order );
13275
+ }
13276
+
13277
+ /**
13278
+ * Check if plugin has any paid plans.
13279
+ *
13280
+ * @author Vova Feldman (@svovaf)
13281
+ * @since 1.0.7
13282
+ *
13283
+ * @return bool
13284
+ */
13285
+ function has_paid_plan() {
13286
+ return $this->_has_paid_plans ||
13287
+ FS_Plan_Manager::instance()->has_paid_plan( $this->_plans );
13288
+ }
13289
+
13290
+ /**
13291
+ * Check if plugin has any plan with a trail.
13292
+ *
13293
+ * @author Vova Feldman (@svovaf)
13294
+ * @since 1.0.9
13295
+ *
13296
+ * @return bool
13297
+ */
13298
+ function has_trial_plan() {
13299
+ /**
13300
+ * @author Vova Feldman(@svovaf)
13301
+ * @since 1.2.1.5
13302
+ *
13303
+ * Allow setting a trial from the SDK without calling the API.
13304
+ * But, if the user did opt-in, continue using the real data from the API.
13305
+ */
13306
+ if ( $this->_trial_days >= 0 ) {
13307
+ return true;
13308
+ }
13309
+
13310
+ return $this->_storage->get( 'has_trial_plan', false );
13311
+ }
13312
+
13313
+ /**
13314
+ * Check if plugin has any free plan, or is it premium only.
13315
+ *
13316
+ * Note: If no plans configured, assume plugin is free.
13317
+ *
13318
+ * @author Vova Feldman (@svovaf)
13319
+ * @since 1.0.7
13320
+ *
13321
+ * @return bool
13322
+ */
13323
+ function has_free_plan() {
13324
+ return ! $this->is_only_premium();
13325
+ }
13326
+
13327
+ /**
13328
+ * Displays a license activation dialog box when the user clicks on the "Activate License"
13329
+ * or "Change License" link on the plugins
13330
+ * page.
13331
+ *
13332
+ * @author Leo Fajardo (@leorw)
13333
+ * @since 1.1.9
13334
+ */
13335
+ function _add_license_activation_dialog_box() {
13336
+ $vars = array(
13337
+ 'id' => $this->_module_id,
13338
+ );
13339
+
13340
+ fs_require_template( 'forms/license-activation.php', $vars );
13341
+ fs_require_template( 'forms/resend-key.php', $vars );
13342
+ }
13343
+
13344
+ /**
13345
+ * Displays an email address update dialog box when the user clicks on the email address "Edit" button on the "Account" page.
13346
+ *
13347
+ * @author Leo Fajardo (@leorw)
13348
+ * @since 2.5.0
13349
+ */
13350
+ function _add_email_address_update_dialog_box() {
13351
+ $vars = array( 'id' => $this->_module_id );
13352
+
13353
+ fs_require_template( 'forms/email-address-update.php', $vars );
13354
+ }
13355
+
13356
+ /**
13357
+ * @author Leo Fajardo (@leorw)
13358
+ * @since 2.5.0
13359
+ */
13360
+ function _add_email_address_update_option() {
13361
+ if ( ! $this->should_handle_user_change() ) {
13362
+ return;
13363
+ }
13364
+
13365
+ // Add email address update AJAX handler.
13366
+ $this->add_ajax_action( 'update_email_address', array( &$this, '_email_address_update_ajax_handler' ) );
13367
+ }
13368
+
13369
+ /**
13370
+ * @author Leo Fajardo (@leorw)
13371
+ * @since 2.5.0
13372
+ */
13373
+ function _email_address_update_ajax_handler() {
13374
+ $this->check_ajax_referer( 'update_email_address' );
13375
+
13376
+ $new_email_address = fs_request_get( 'email_address' );
13377
+ $transfer_type = fs_request_get( 'transfer_type' );
13378
+
13379
+ $result = $this->update_email( $new_email_address );
13380
+
13381
+ if ( ! FS_Api::is_api_error( $result ) ) {
13382
+ self::shoot_ajax_success();
13383
+ }
13384
+
13385
+ $error = '';
13386
+
13387
+ if ( FS_Api::is_api_error_object( $result ) ) {
13388
+ switch ( $result->error->code ) {
13389
+ case 'user_exist':
13390
+ case 'account_verification_required':
13391
+ $error = array(
13392
+ 'code' => 'change_ownership',
13393
+ 'url' => $this->get_account_url( 'change_owner', array(
13394
+ 'state' => 'init',
13395
+ 'candidate_email' => $new_email_address,
13396
+ 'transfer_type' => $transfer_type,
13397
+ ) ),
13398
+ );
13399
+
13400
+ break;
13401
+ }
13402
+ }
13403
+
13404
+ if ( empty( $error ) ) {
13405
+ $error = is_object( $result ) ?
13406
+ var_export( $result->error, true ) :
13407
+ $result;
13408
+ }
13409
+
13410
+ self::shoot_ajax_failure( $error );
13411
+ }
13412
+
13413
+ /**
13414
+ * Returns a collection of IDs of installs that are associated with the context product and its add-ons, and activated with foreign licenses.
13415
+ *
13416
+ * @author Leo Fajardo (@leorw)
13417
+ * @since 2.3.2
13418
+ *
13419
+ * @return number[]
13420
+ */
13421
+ function get_installs_ids_with_foreign_licenses() {
13422
+ $installs = array();
13423
+
13424
+ if (
13425
+ is_object( $this->_license ) &&
13426
+ $this->_site->user_id != $this->_license->user_id
13427
+ ) {
13428
+ $installs[] = $this->_site->id;
13429
+ }
13430
+
13431
+ /**
13432
+ * Also try to get foreign licenses for the context product's add-ons.
13433
+ */
13434
+ $installs_by_slug_map = $this->get_parent_and_addons_installs_info();
13435
+
13436
+ foreach ( $installs_by_slug_map as $slug => $install_info ) {
13437
+ if ( $slug == $this->get_slug() ) {
13438
+ continue;
13439
+ }
13440
+
13441
+ $install = $install_info['install'];
13442
+ $license = $install_info['license'];
13443
+
13444
+ if (
13445
+ is_object( $license ) &&
13446
+ $install->user_id != $license->user_id
13447
+ ) {
13448
+ $installs[] = $install->id;
13449
+ }
13450
+ }
13451
+
13452
+ return $installs;
13453
+ }
13454
+
13455
+ /**
13456
+ * Displays the "Change User" dialog box when the user clicks on the "Change User" button on the "Account" page.
13457
+ *
13458
+ * @author Leo Fajardo (@leorw)
13459
+ * @since 2.3.2
13460
+ *
13461
+ * @param number[] $install_ids
13462
+ */
13463
+ function _add_user_change_dialog_box( $install_ids ) {
13464
+ $vars = array(
13465
+ 'id' => $this->_module_id,
13466
+ 'license_owners' => $this->fetch_installs_licenses_owners_data( $install_ids )
13467
+ );
13468
+
13469
+ fs_require_template( 'forms/user-change.php', $vars );
13470
+ }
13471
+
13472
+ /**
13473
+ * @author Leo Fajardo (@leorw)
13474
+ * @since 2.3.1
13475
+ */
13476
+ function _add_data_debug_mode_dialog_box() {
13477
+ $vars = array(
13478
+ 'id' => $this->_module_id,
13479
+ );
13480
+
13481
+ fs_require_template( 'forms/data-debug-mode.php', $vars );
13482
+ }
13483
+
13484
+ /**
13485
+ * Displays a subscription cancellation dialog box when the user clicks on the "Deactivate License"
13486
+ * link on the "Account" page or deactivates a plugin and there's an active subscription that is
13487
+ * either associated with a non-lifetime single-site license or non-lifetime multisite license that
13488
+ * is only activated on a single production site.
13489
+ *
13490
+ * @author Leo Fajardo (@leorw)
13491
+ * @since 2.2.1
13492
+ *
13493
+ * @param bool $is_license_deactivation
13494
+ *
13495
+ * @return array
13496
+ */
13497
+ function _get_subscription_cancellation_dialog_box_template_params( $is_license_deactivation = false ) {
13498
+ if ( fs_is_network_admin() ) {
13499
+ // Subscription cancellation dialog box is currently not supported for multisite networks.
13500
+ return array();
13501
+ }
13502
+
13503
+ if ( $this->is_whitelabeled() ) {
13504
+ return array();
13505
+ }
13506
+
13507
+ $license = $this->_get_license();
13508
+
13509
+ /**
13510
+ * If the installation is associated with a non-lifetime license, which is either a single-site or only activated on a single production site (or zero), and connected to an active subscription, suggest the customer to cancel the subscription upon deactivation.
13511
+ *
13512
+ * @author Leo Fajardo (@leorw) (Comment added by Vova Feldman @svovaf)
13513
+ * @since 2.2.1
13514
+ */
13515
+ if ( ! is_object( $license ) ||
13516
+ $license->is_lifetime() ||
13517
+ ( ! $license->is_single_site() && $license->activated > 1 )
13518
+ ) {
13519
+ return array();
13520
+ }
13521
+
13522
+ /**
13523
+ * @var FS_Subscription $subscription
13524
+ */
13525
+ $subscription = $this->_get_subscription( $license->id );
13526
+ if ( ! is_object( $subscription ) || ! $subscription->is_active() ) {
13527
+ return array();
13528
+ }
13529
+
13530
+ return array(
13531
+ 'id' => $this->_module_id,
13532
+ 'license' => $license,
13533
+ 'has_trial' => $this->is_paid_trial(),
13534
+ 'is_license_deactivation' => $is_license_deactivation,
13535
+ );
13536
+ }
13537
+
13538
+ /**
13539
+ * @author Leo Fajardo (@leorw)
13540
+ * @since 2.0.2
13541
+ */
13542
+ function _add_premium_version_upgrade_selection_dialog_box() {
13543
+ $modules_update = get_site_transient( $this->is_theme() ? 'update_themes' : 'update_plugins' );
13544
+ if ( ! isset( $modules_update->response[ $this->_plugin_basename ] ) ) {
13545
+ return;
13546
+ }
13547
+
13548
+ $vars = array(
13549
+ 'id' => $this->_module_id,
13550
+ 'new_version' => is_object( $modules_update->response[ $this->_plugin_basename ] ) ?
13551
+ $modules_update->response[ $this->_plugin_basename ]->new_version :
13552
+ $modules_update->response[ $this->_plugin_basename ]['new_version']
13553
+ );
13554
+
13555
+ fs_require_template( 'forms/premium-versions-upgrade-metadata.php', $vars );
13556
+ fs_require_once_template( 'forms/premium-versions-upgrade-handler.php', $vars );
13557
+ }
13558
+
13559
+ /**
13560
+ * Displays the opt-out dialog box when the user clicks on the "Opt Out" link on the "Plugins"
13561
+ * page.
13562
+ *
13563
+ * @author Leo Fajardo (@leorw)
13564
+ * @since 1.2.1.5
13565
+ */
13566
+ function _add_optout_dialog() {
13567
+ if ( $this->is_theme() ) {
13568
+ $vars = null;
13569
+ fs_require_once_template( '/js/jquery.content-change.php', $vars );
13570
+ }
13571
+
13572
+ $vars = array( 'id' => $this->_module_id );
13573
+ fs_require_template( 'forms/optout.php', $vars );
13574
+ }
13575
+
13576
+ /**
13577
+ * Prepare page to include all required UI and logic for the license activation dialog.
13578
+ *
13579
+ * @author Vova Feldman (@svovaf)
13580
+ * @since 1.2.0
13581
+ */
13582
+ function _add_license_activation() {
13583
+ if ( $this->is_migration() ) {
13584
+ return;
13585
+ }
13586
+
13587
+ if ( ! $this->is_user_admin() ) {
13588
+ // Only admins can activate a license.
13589
+ return;
13590
+ }
13591
+
13592
+ if ( ! $this->has_paid_plan() ) {
13593
+ // Module doesn't have any paid plans.
13594
+ return;
13595
+ }
13596
+
13597
+ if (
13598
+ $this->has_premium_version() &&
13599
+ ! $this->is_premium() &&
13600
+ /**
13601
+ * Also handle the case when an upgrade was made using the free version.
13602
+ *
13603
+ * @author Leo Fajardo (@leorw)
13604
+ * @since 2.3.2
13605
+ */
13606
+ ! is_object( $this->_get_license() )
13607
+ ) {
13608
+ // Only add license activation logic to the premium version, or in case of a serviceware plugin, also in the free version.
13609
+ return;
13610
+ }
13611
+
13612
+ // Add license activation link and AJAX request handler.
13613
+ if ( self::is_plugins_page() ) {
13614
+ $is_network_admin = fs_is_network_admin();
13615
+
13616
+ if (
13617
+ ( $is_network_admin && $this->is_network_active() && ! $this->is_network_delegated_connection() ) ||
13618
+ ( ! $is_network_admin && ( ! $this->is_network_active() || $this->is_delegated_connection() ) )
13619
+ ) {
13620
+ if (
13621
+ $this->is_premium() ||
13622
+ ( $this->has_paid_plan() && ! $this->has_premium_version() )
13623
+ ) {
13624
+ /**
13625
+ * @since 1.2.0 Add license action link only on plugins page.
13626
+ */
13627
+ $this->_add_license_action_link();
13628
+ }
13629
+ }
13630
+ }
13631
+
13632
+ // Add license activation AJAX callback.
13633
+ $this->add_ajax_action( 'activate_license', array( &$this, '_activate_license_ajax_action' ) );
13634
+
13635
+ // Add resend license AJAX callback.
13636
+ $this->add_ajax_action( 'resend_license_key', array( &$this, '_resend_license_key_ajax_action' ) );
13637
+ }
13638
+
13639
+ /**
13640
+ * Prepares page to include all required UI and logic for the "Change User" dialog.
13641
+ *
13642
+ * @author Leo Fajardo (@leorw)
13643
+ * @since 2.3.2
13644
+ */
13645
+ function _add_user_change_option() {
13646
+ if ( ! $this->should_handle_user_change() ) {
13647
+ return;
13648
+ }
13649
+
13650
+ $installs_ids_with_foreign_licenses = $this->get_installs_ids_with_foreign_licenses();
13651
+
13652
+ if ( empty( $installs_ids_with_foreign_licenses ) ) {
13653
+ // Handle user change only when the parent product or one of its add-ons is activated with a foreign license.
13654
+ return;
13655
+ }
13656
+
13657
+ // Add user change AJAX handler.
13658
+ $this->add_ajax_action( 'change_user', array( &$this, '_user_change_ajax_action' ) );
13659
+ }
13660
+
13661
+ /**
13662
+ * @author Leo Fajardo (@leorw)
13663
+ * @since 2.3.2
13664
+ */
13665
+ function should_handle_user_change() {
13666
+ if ( ! $this->is_user_admin() ) {
13667
+ // Only admins can change user.
13668
+ return false;
13669
+ }
13670
+
13671
+ if ( $this->is_addon() ) {
13672
+ return false;
13673
+ }
13674
+
13675
+ if ( ! $this->is_registered() ) {
13676
+ return false;
13677
+ }
13678
+
13679
+ if (
13680
+ $this->is_network_active() &&
13681
+ ( fs_is_network_admin() || ! $this->is_site_delegated_connection() )
13682
+ ) {
13683
+ // Handle only on site-level "Account" section for now.
13684
+ return false;
13685
+ }
13686
+
13687
+ return true;
13688
+ }
13689
+
13690
+ /**
13691
+ * @author Leo Fajardo (@leorw)
13692
+ * @since 2.0.2
13693
+ */
13694
+ function _add_premium_version_upgrade_selection() {
13695
+ if ( ! $this->is_user_admin() ) {
13696
+ return;
13697
+ }
13698
+
13699
+ if ( ! $this->is_premium() || $this->has_any_active_valid_license() ) {
13700
+ // This is relevant only to the free versions and premium versions without an active license.
13701
+ return;
13702
+ }
13703
+
13704
+ if ( self::is_updates_page() || ( $this->is_plugin() && self::is_plugins_page() ) ) {
13705
+ $this->_add_premium_version_upgrade_selection_action();
13706
+ }
13707
+ }
13708
+
13709
+ /**
13710
+ * @author Edgar Melkonyan
13711
+ * @since 2.4.1
13712
+ *
13713
+ * @throws Freemius_Exception
13714
+ */
13715
+ function _toggle_whitelabel_mode_ajax_handler() {
13716
+ $this->_logger->entrance();
13717
+
13718
+ $this->check_ajax_referer( 'toggle_whitelabel_mode' );
13719
+
13720
+ if ( ! $this->is_user_admin() ) {
13721
+ // Only for admins.
13722
+ self::shoot_ajax_failure();
13723
+ }
13724
+
13725
+ $license = $this->get_api_user_scope()->call(
13726
+ "/licenses/{$this->_site->license_id}.json",
13727
+ 'put',
13728
+ array( 'is_whitelabeled' => ! $this->_license->is_whitelabeled )
13729
+ );
13730
+
13731
+ if ( ! $this->is_api_result_entity( $license ) ) {
13732
+ self::shoot_ajax_failure(
13733
+ FS_Api::is_api_error_object( $license ) ?
13734
+ $license->error->message :
13735
+ fs_text_inline( "An unknown error has occurred while trying to toggle the license's white-label mode.", 'unknown-error-occurred', $this->get_slug() )
13736
+ );
13737
+ }
13738
+
13739
+ $this->_license->is_whitelabeled = $license->is_whitelabeled;
13740
+ $this->_store_licenses();
13741
+
13742
+ $this->_sync_license();
13743
+
13744
+ if ( ! $license->is_whitelabeled ) {
13745
+ $this->_admin_notices->remove_sticky( 'license_whitelabeled' );
13746
+ } else {
13747
+ $this->_admin_notices->add_sticky(
13748
+ sprintf(
13749
+ $this->get_text_inline(
13750
+ 'Your %s license was flagged as white-labeled to hide sensitive information from the WP Admin (e.g. your email, license key, prices, billing address & invoices). If you ever wish to revert it back, you can easily do it through your %s. If this was a mistake you can also %s.',
13751
+ 'license_whitelabeled'
13752
+ ),
13753
+ "<strong>{$this->get_plugin_title()}</strong>",
13754
+ sprintf( '<a href="https://users.freemius.com" target="_blank">%s</a>', $this->get_text_inline( 'User Dashboard', 'user-dashboard' ) ),
13755
+ sprintf( '<a href="#" class="fs-toggle-whitelabel-mode">%s</a>', $this->get_text_inline( 'revert it now', 'revert-it-now' ) )
13756
+ ),
13757
+ 'license_whitelabeled'
13758
+ );
13759
+ }
13760
+
13761
+ self::shoot_ajax_response( array( 'success' => true ) );
13762
+ }
13763
+
13764
+ /**
13765
+ * @author Leo Fajardo (@leorw)
13766
+ * @since 2.3.0
13767
+ */
13768
+ function _add_beta_mode_update_handler() {
13769
+ if ( ! $this->is_user_admin() ) {
13770
+ return;
13771
+ }
13772
+
13773
+ if ( ! $this->is_premium() ) {
13774
+ return;
13775
+ }
13776
+
13777
+ $this->add_ajax_action( 'set_beta_mode', array( &$this, '_set_beta_mode_ajax_handler' ) );
13778
+ }
13779
+
13780
+ /**
13781
+ * @author Leo Fajardo (@leorw)
13782
+ * @since 2.3.0
13783
+ */
13784
+ function _set_beta_mode_ajax_handler() {
13785
+ $this->_logger->entrance();
13786
+
13787
+ $this->check_ajax_referer( 'set_beta_mode' );
13788
+
13789
+ if ( ! $this->is_user_admin() ) {
13790
+ // Only for admins.
13791
+ self::shoot_ajax_failure();
13792
+ }
13793
+
13794
+ $is_beta = trim( fs_request_get( 'is_beta', '', 'post' ) );
13795
+
13796
+ if ( empty( $is_beta ) || ! in_array( $is_beta, array( 'true', 'false' ) ) ) {
13797
+ self::shoot_ajax_failure();
13798
+ }
13799
+
13800
+ $site = $this->api_site_call(
13801
+ '',
13802
+ 'put',
13803
+ array(
13804
+ 'is_beta' => ( 'true' == $is_beta ),
13805
+ 'fields' => 'is_beta'
13806
+ )
13807
+ );
13808
+
13809
+ if ( ! $this->is_api_result_entity( $site ) ) {
13810
+ self::shoot_ajax_failure(
13811
+ FS_Api::is_api_error_object( $site ) ?
13812
+ $site->error->message :
13813
+ fs_text_inline( "An unknown error has occurred while trying to set the user's beta mode.", 'unknown-error-occurred', $this->get_slug() )
13814
+ );
13815
+ }
13816
+
13817
+ $this->_site->is_beta = $site->is_beta;
13818
+ $this->_store_site();
13819
+
13820
+ self::shoot_ajax_response( array( 'success' => true ) );
13821
+ }
13822
+
13823
+ /**
13824
+ * License activation WP AJAX handler.
13825
+ *
13826
+ * @author Leo Fajardo (@leorw)
13827
+ * @since 1.1.9
13828
+ *
13829
+ * @uses Freemius::activate_license()
13830
+ */
13831
+ function _activate_license_ajax_action() {
13832
+ $this->_logger->entrance();
13833
+
13834
+ $this->check_ajax_referer( 'activate_license' );
13835
+
13836
+ $license_key = trim( fs_request_get( 'license_key' ) );
13837
+
13838
+ if ( empty( $license_key ) ) {
13839
+ exit;
13840
+ }
13841
+
13842
+ $sites = fs_is_network_admin() ?
13843
+ fs_request_get( 'sites', array(), 'post' ) :
13844
+ array();
13845
+
13846
+ $result = $this->activate_license(
13847
+ $license_key,
13848
+ $sites,
13849
+ fs_request_get_bool( 'is_marketing_allowed', null ),
13850
+ fs_request_get( 'blog_id', null ),
13851
+ fs_request_get( 'module_id', null, 'post' ),
13852
+ fs_request_get( 'user_id', null ),
13853
+ fs_request_get_bool( 'is_extensions_tracking_allowed', null ),
13854
+ fs_request_get_bool( 'is_diagnostic_tracking_allowed', null )
13855
+ );
13856
+
13857
+ if (
13858
+ $result['success'] &&
13859
+ $this->is_bundle_license_auto_activation_enabled()
13860
+ ) {
13861
+ $license = new FS_Plugin_License();
13862
+ $license->secret_key = $license_key;
13863
+
13864
+ $this->maybe_activate_bundle_license( $license, $sites );
13865
+ }
13866
+
13867
+ echo json_encode( $result );
13868
+
13869
+ exit;
13870
+ }
13871
+
13872
+ /**
13873
+ * User change WP AJAX handler.
13874
+ *
13875
+ * @author Leo Fajardo (@leorw)
13876
+ * @since 2.3.2
13877
+ */
13878
+ function _user_change_ajax_action() {
13879
+ $this->_logger->entrance();
13880
+
13881
+ $this->check_ajax_referer( 'change_user' );
13882
+
13883
+ $new_email_address = trim( fs_request_get( 'email_address', '' ) );
13884
+ $new_user_id = fs_request_get( 'user_id' );
13885
+
13886
+ if ( empty( $new_email_address ) && ! FS_User::is_valid_id( $new_user_id ) ) {
13887
+ self::shoot_ajax_failure( fs_text_inline( 'Invalid new user ID or email address.', 'invalid-new-user-id-or-email', $this->get_slug() ) );
13888
+ }
13889
+
13890
+ $params = array();
13891
+
13892
+ if ( ! empty( $new_email_address ) ) {
13893
+ $params['user_email'] = $new_email_address;
13894
+ } else {
13895
+ $params['user_id'] = $new_user_id;
13896
+ }
13897
+
13898
+ $installs_info_by_slug_map = $this->get_parent_and_addons_installs_info();
13899
+ $install_ids = array();
13900
+
13901
+ foreach ( $installs_info_by_slug_map as $slug => $install_info ) {
13902
+ $install_ids[ $slug ] = $install_info['install']->id;
13903
+ }
13904
+
13905
+ $params['install_ids'] = implode( ',', array_values( $install_ids ) );
13906
+
13907
+ $install = $this->get_api_site_scope()->call( $this->add_show_pending( '/' ), 'put', $params );
13908
+
13909
+ if ( FS_Api::is_api_error( $install ) ) {
13910
+ $error = '';
13911
+
13912
+ if ( is_object( $install ) ) {
13913
+ switch ( $install->error->code ) {
13914
+ case 'user_exist':
13915
+ $error = (
13916
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...' .
13917
+ $this->get_text_inline( 'Sorry, we could not complete the email update. Another user with the same email is already registered.', 'user-exist-message' ) . ' ' .
13918
+ sprintf( $this->get_text_inline( 'If you would like to give up the ownership of the %s\'s account to %s click the Change Ownership button.', 'user-exist-message_ownership' ), $this->_module_type, '<b>' . $new_email_address . '</b>' ) .
13919
+ sprintf(
13920
+ '<a style="line-height: 40px;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
13921
+ $this->get_account_url( 'change_owner', array(
13922
+ 'state' => 'init',
13923
+ 'candidate_email' => $new_email_address
13924
+ ) ),
13925
+ $this->get_text_inline( 'Change Ownership', 'change-ownership' )
13926
+ )
13927
+ );
13928
+ break;
13929
+ }
13930
+ }
13931
+
13932
+ if ( empty( $error ) ) {
13933
+ $error = FS_Api::is_api_error_object( $install ) ?
13934
+ $install->error->message :
13935
+ var_export( $install->error, true );
13936
+ }
13937
+
13938
+ self::shoot_ajax_failure( $error );
13939
+ } else {
13940
+ if (
13941
+ // If successful ownership change.
13942
+ $this->get_user()->id != $install->user_id ||
13943
+ ! empty( $new_email_address )
13944
+ ) {
13945
+ $this->complete_ownership_change_by_license( $install->user_id, $install_ids );
13946
+ }
13947
+ }
13948
+
13949
+ self::shoot_ajax_success();
13950
+ }
13951
+
13952
+ /**
13953
+ * @author Leo Fajardo (@leorw)
13954
+ * @since 2.3.2.14
13955
+ */
13956
+ function starting_migration() {
13957
+ if ( ! empty( $this->_storage->license_migration ) ) {
13958
+ // Do not overwrite the data if already set.
13959
+ return;
13960
+ }
13961
+
13962
+ $this->_storage->license_migration = array(
13963
+ 'is_migrating' => true,
13964
+ 'start_timestamp' => time()
13965
+ );
13966
+ }
13967
+
13968
+ /**
13969
+ * @author Leo Fajardo (@leorw)
13970
+ * @since 2.3.2.14
13971
+ */
13972
+ function is_migration() {
13973
+ if ( $this->is_addon() ) {
13974
+ return $this->get_parent_instance()->is_migration();
13975
+ }
13976
+
13977
+ if ( empty( $this->_storage->license_migration ) ) {
13978
+ return false;
13979
+ }
13980
+
13981
+ if ( ! $this->_storage->license_migration['is_migrating'] ) {
13982
+ return false;
13983
+ }
13984
+
13985
+ return (
13986
+ // Return `true` if the migration is within 5 minutes from the starting time.
13987
+ ( time() - $this->_storage->license_migration['start_timestamp'] ) <= WP_FS__TIME_5_MIN_IN_SEC
13988
+ );
13989
+ }
13990
+
13991
+ /**
13992
+ *
13993
+ * A helper method to activate migrated licenses. If the product is network activated and integrated, the method will network activate the license.
13994
+ *
13995
+ * @author Vova Feldman (@svovaf)
13996
+ * @since 2.3.0
13997
+ *
13998
+ * @param string $license_key
13999
+ * @param null|bool $is_marketing_allowed
14000
+ * @param null|number $plugin_id
14001
+ * @param array $sites
14002
+ * @param int $blog_id
14003
+ *
14004
+ * @return array {
14005
+ * @var bool $success
14006
+ * @var string $error
14007
+ * @var string $next_page
14008
+ * }
14009
+ *
14010
+ * @uses Freemius::activate_license()
14011
+ */
14012
+ function activate_migrated_license(
14013
+ $license_key,
14014
+ $is_marketing_allowed = null,
14015
+ $plugin_id = null,
14016
+ $sites = array(),
14017
+ $blog_id = null
14018
+ ) {
14019
+ $this->_logger->entrance();
14020
+
14021
+ $result = $this->activate_license(
14022
+ $license_key,
14023
+ ( empty( $sites ) && is_null( $blog_id ) && $this->is_network_active() ) ?
14024
+ $this->get_sites_for_network_level_optin() :
14025
+ $sites,
14026
+ $is_marketing_allowed,
14027
+ $blog_id,
14028
+ $plugin_id
14029
+ );
14030
+
14031
+ // No need to show the sticky after license activation notice after migrating a license.
14032
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
14033
+
14034
+ return $result;
14035
+ }
14036
+
14037
+ /**
14038
+ * @author Leo Fajardo (@leorw)
14039
+ * @since 2.3.1
14040
+ *
14041
+ * @return string
14042
+ */
14043
+ function get_pricing_js_path() {
14044
+ if ( ! isset( $this->_pricing_js_path ) ) {
14045
+ $pricing_js_path = $this->apply_filters( 'freemius_pricing_js_path', '' );
14046
+
14047
+ if ( empty( $pricing_js_path ) ) {
14048
+ global $fs_active_plugins;
14049
+
14050
+ foreach ( $fs_active_plugins->plugins as $sdk_path => $data ) {
14051
+ if ( $data->plugin_path == $this->get_plugin_basename() ) {
14052
+ $plugin_or_theme_root_dir = ( $this->is_plugin() ? WP_PLUGIN_DIR : get_theme_root( get_stylesheet() ) );
14053
+
14054
+ $pricing_js_path = $plugin_or_theme_root_dir
14055
+ . '/'
14056
+ // The basename will be `plugins`, `themes`, or the basename of a custom plugins or themes directory.
14057
+ . str_replace( '../' . basename( $plugin_or_theme_root_dir ) . '/', '', $sdk_path )
14058
+ . '/includes/freemius-pricing/freemius-pricing.js';
14059
+
14060
+ break;
14061
+ }
14062
+ }
14063
+ }
14064
+
14065
+ $this->_pricing_js_path = $pricing_js_path;
14066
+ }
14067
+
14068
+ return $this->_pricing_js_path;
14069
+ }
14070
+
14071
+ /**
14072
+ * @author Leo Fajardo (@leorw)
14073
+ * @since 2.3.1
14074
+ *
14075
+ * @return bool
14076
+ */
14077
+ function should_use_external_pricing() {
14078
+ if ( is_null( $this->_use_external_pricing ) ) {
14079
+ $pricing_js_path = $this->get_pricing_js_path();
14080
+
14081
+ $this->_use_external_pricing = ( empty( $pricing_js_path ) || ! file_exists( $pricing_js_path ) );
14082
+ }
14083
+
14084
+ return $this->_use_external_pricing;
14085
+ }
14086
+
14087
+ /**
14088
+ * The implementation of this method was previously in `_activate_license_ajax_action()`.
14089
+ *
14090
+ * @author Vova Feldman (@svovaf)
14091
+ * @since 2.2.4
14092
+ * @since 2.0.0 When a super-admin that hasn't connected before is network activating a license and excluding some of the sites for the license activation, go over the unselected sites in the network and if a site is not connected, skipped, nor delegated, if it's a freemium product then just skip the connection for the site, if it's a premium only product, delegate the connection and license activation to the site admin (Vova Feldman @svovaf).
14093
+ * @param string $license_key
14094
+ * @param array $sites
14095
+ * @param null|bool $is_marketing_allowed
14096
+ * @param null|int $blog_id
14097
+ * @param null|number $plugin_id
14098
+ * @param null|number $license_owner_id
14099
+ * @param bool|null $is_extensions_tracking_allowed
14100
+ * @param bool|null $is_diagnostic_tracking_allowed Since 2.5.0.2 to allow license activation with minimal data footprint.
14101
+ *
14102
+ *
14103
+ * @return array {
14104
+ * @var bool $success
14105
+ * @var string $error
14106
+ * @var string $next_page
14107
+ * }
14108
+ */
14109
+ private function activate_license(
14110
+ $license_key,
14111
+ $sites = array(),
14112
+ $is_marketing_allowed = null,
14113
+ $blog_id = null,
14114
+ $plugin_id = null,
14115
+ $license_owner_id = null,
14116
+ $is_extensions_tracking_allowed = null,
14117
+ $is_diagnostic_tracking_allowed = null
14118
+ ) {
14119
+ $this->_logger->entrance();
14120
+
14121
+ $license_key = trim( $license_key );
14122
+
14123
+ $is_network_activation_or_migration = (
14124
+ fs_is_network_admin() ||
14125
+ ( ! empty( $sites ) && $this->is_migration() )
14126
+ );
14127
+
14128
+ if ( ! $is_network_activation_or_migration ) {
14129
+ // If the license activation is executed outside the context of a network admin, ignore the sites collection.
14130
+ $sites = array();
14131
+ }
14132
+
14133
+ $fs = ( empty($plugin_id) || $plugin_id == $this->_module_id ) ?
14134
+ $this :
14135
+ $this->get_addon_instance( $plugin_id );
14136
+
14137
+ FS_Permission_Manager::instance( $this )->update_permissions_tracking_flag( array(
14138
+ FS_Permission_Manager::PERMISSION_DIAGNOSTIC => $is_diagnostic_tracking_allowed,
14139
+ FS_Permission_Manager::PERMISSION_EXTENSIONS => $is_extensions_tracking_allowed,
14140
+ ) );
14141
+
14142
+ $error = false;
14143
+ $next_page = false;
14144
+
14145
+ $has_valid_blog_id = is_numeric( $blog_id );
14146
+
14147
+ $user = null;
14148
+
14149
+ if ( $fs->is_addon() && $fs->get_parent_instance()->is_registered() ) {
14150
+ /**
14151
+ * When activating an add-on's license and the parent is opted-in, activate the license with the parent's opted-in user context.
14152
+ *
14153
+ * @author Vova Feldman (@svovaf)
14154
+ */
14155
+ $user = $fs->get_parent_instance()->get_current_or_network_user();
14156
+ } else if ( $fs->is_registered() ) {
14157
+ $user = $fs->get_current_or_network_user();
14158
+ }
14159
+
14160
+ if ( $has_valid_blog_id ) {
14161
+ /**
14162
+ * If a specific blog ID was provided, activate the license only on the specific blog that is associated with the given blog ID.
14163
+ *
14164
+ * @author Leo Fajardo (@leorw)
14165
+ */
14166
+ $fs->switch_to_blog( $blog_id );
14167
+ }
14168
+
14169
+ if ( is_object( $user ) ) {
14170
+ if ( $is_network_activation_or_migration && ! $has_valid_blog_id ) {
14171
+ // If no specific blog ID was provided, activate the license for all sites in the network.
14172
+ $blog_2_install_map = array();
14173
+ $site_ids = array();
14174
+
14175
+ foreach ( $sites as $site ) {
14176
+ if ( ! isset( $site['blog_id'] ) || ! is_numeric( $site['blog_id'] ) ) {
14177
+ continue;
14178
+ }
14179
+
14180
+ $install = $fs->get_install_by_blog_id( $site['blog_id'] );
14181
+
14182
+ if ( is_object( $install ) ) {
14183
+ $blog_2_install_map[ $site['blog_id'] ] = $install;
14184
+ } else {
14185
+ $site_ids[] = $site['blog_id'];
14186
+ }
14187
+ }
14188
+
14189
+ if ( ! empty( $blog_2_install_map ) ) {
14190
+ $result = $fs->activate_license_on_many_installs( $user, $license_key, $blog_2_install_map );
14191
+
14192
+ if ( true !== $result ) {
14193
+ $error = FS_Api::is_api_error_object( $result ) ?
14194
+ $result->error->message :
14195
+ var_export( $result, true );
14196
+ }
14197
+ }
14198
+
14199
+ if ( empty( $error ) && ! empty( $site_ids ) ) {
14200
+ $result = $fs->activate_license_on_many_sites( $user, $license_key, $site_ids );
14201
+
14202
+ if ( true !== $result ) {
14203
+ $error = FS_Api::is_api_error_object( $result ) ?
14204
+ $result->error->message :
14205
+ var_export( $result, true );
14206
+ }
14207
+ }
14208
+ } else {
14209
+ if ( $fs->is_registered() ) {
14210
+ $params = array(
14211
+ 'license_key' => $fs->apply_filters( 'license_key', $license_key )
14212
+ );
14213
+
14214
+ $install_ids = array();
14215
+
14216
+ $change_owner = FS_User::is_valid_id( $license_owner_id );
14217
+
14218
+ if ( $change_owner ) {
14219
+ $params['user_id'] = $license_owner_id;
14220
+
14221
+ $installs_info_by_slug_map = $fs->get_parent_and_addons_installs_info();
14222
+
14223
+ foreach ( $installs_info_by_slug_map as $slug => $install_info ) {
14224
+ $install_ids[ $slug ] = $install_info['install']->id;
14225
+ }
14226
+
14227
+ $params['install_ids'] = implode( ',', array_values( $install_ids ) );
14228
+ }
14229
+
14230
+ $api = $fs->get_api_site_scope();
14231
+
14232
+ $install = $api->call( $fs->add_show_pending( '/' ), 'put', $params );
14233
+
14234
+ if ( FS_Api::is_api_error( $install ) ) {
14235
+ $error = FS_Api::is_api_error_object( $install ) ?
14236
+ $install->error->message :
14237
+ var_export( $install->error, true );
14238
+ } else {
14239
+ $fs->reconnect_locally( $has_valid_blog_id );
14240
+
14241
+ if (
14242
+ $change_owner &&
14243
+ // If successful ownership change.
14244
+ $fs->get_user()->id != $install->user_id
14245
+ ) {
14246
+ $fs->complete_ownership_change_by_license( $install->user_id, $install_ids );
14247
+ }
14248
+ }
14249
+ } else /* ( $fs->is_addon() && $fs->get_parent_instance()->is_registered() ) */ {
14250
+ $result = $fs->activate_license_on_site( $user, $license_key );
14251
+
14252
+ if ( true !== $result ) {
14253
+ $error = FS_Api::is_api_error_object( $result ) ?
14254
+ $result->error->message :
14255
+ var_export( $result, true );
14256
+ }
14257
+ }
14258
+ }
14259
+
14260
+ if ( empty( $error ) ) {
14261
+ $fs->network_upgrade_mode_completed();
14262
+
14263
+ $fs->_user = $user;
14264
+
14265
+ if ( fs_is_network_admin() && ! $has_valid_blog_id ) {
14266
+ $fs->_site = $fs->get_network_install();
14267
+ }
14268
+
14269
+ $fs->_sync_license( true, $has_valid_blog_id );
14270
+
14271
+ $this->maybe_sync_install_user();
14272
+
14273
+ $next_page = $fs->is_addon() ?
14274
+ $fs->get_parent_instance()->get_account_url() :
14275
+ $fs->get_after_activation_url( 'after_connect_url' );
14276
+ }
14277
+ } else {
14278
+ $next_page = $fs->opt_in(
14279
+ false,
14280
+ false,
14281
+ false,
14282
+ $license_key,
14283
+ false,
14284
+ false,
14285
+ false,
14286
+ $is_marketing_allowed,
14287
+ $sites
14288
+ );
14289
+
14290
+ if ( isset( $next_page->error ) ) {
14291
+ $error = $next_page->error;
14292
+ } else {
14293
+ if ( $is_network_activation_or_migration ) {
14294
+ /**
14295
+ * Get the list of sites that were just opted-in (and license activated).
14296
+ * This is an optimization for the next part below saving some DB queries.
14297
+ */
14298
+ $connected_sites = array();
14299
+ foreach ( $sites as $site ) {
14300
+ if ( isset( $site['blog_id'] ) && is_numeric( $site['blog_id'] ) ) {
14301
+ $connected_sites[ $site['blog_id'] ] = true;
14302
+ }
14303
+ }
14304
+
14305
+ $all_sites = self::get_sites();
14306
+ $pending_blog_ids = array();
14307
+
14308
+ /**
14309
+ * Check if there are any sites that are not connected, skipped, nor delegated. For every site that falls into that category, if the product is freemium, skip the connection. If the product is premium only, delegate the connection to the site administrator.
14310
+ *
14311
+ * @author Vova Feldman (@svovaf)
14312
+ */
14313
+ foreach ( $all_sites as $site ) {
14314
+ $blog_id = self::get_site_blog_id( $site );
14315
+
14316
+ if ( isset( $connected_sites[ $blog_id ] ) ) {
14317
+ // Site was just connected.
14318
+ continue;
14319
+ }
14320
+
14321
+ if ( $fs->is_installed_on_site( $blog_id ) ) {
14322
+ // Site was already connected before.
14323
+ continue;
14324
+ }
14325
+
14326
+ if ( $fs->is_site_delegated_connection( $blog_id ) ) {
14327
+ // Site's connection was delegated.
14328
+ continue;
14329
+ }
14330
+
14331
+ if ( $fs->is_anonymous_site( $blog_id ) ) {
14332
+ // Site connection was already skipped.
14333
+ continue;
14334
+ }
14335
+
14336
+ $pending_blog_ids[] = $blog_id;
14337
+ }
14338
+
14339
+ if ( ! empty( $pending_blog_ids ) ) {
14340
+ if ( $fs->is_freemium() && $fs->is_enable_anonymous() ) {
14341
+ $fs->skip_connection( $pending_blog_ids );
14342
+ } else {
14343
+ $fs->delegate_connection( $pending_blog_ids );
14344
+ }
14345
+ }
14346
+ }
14347
+ }
14348
+ }
14349
+
14350
+ if ( false === $error && true === $fs->_storage->require_license_activation ) {
14351
+ $fs->_storage->require_license_activation = false;
14352
+ }
14353
+
14354
+ $result = array(
14355
+ 'success' => ( false === $error )
14356
+ );
14357
+
14358
+ if ( false !== $error ) {
14359
+ $result['error'] = $fs->apply_filters( 'opt_in_error_message', $error );
14360
+ } else {
14361
+ if ( $fs->is_addon() || $fs->has_addons() ) {
14362
+ /**
14363
+ * Purge the valid user licenses cache so that when the "Account" or the "Add-Ons" page is loaded,
14364
+ * an updated valid user licenses collection will be fetched from the server which is used to also
14365
+ * update the account add-ons (add-ons the user has licenses for).
14366
+ *
14367
+ * @author Leo Fajardo (@leorw)
14368
+ * @since 2.2.4
14369
+ */
14370
+ $fs->purge_valid_user_licenses_cache();
14371
+ }
14372
+
14373
+ $result['next_page'] = $next_page;
14374
+ }
14375
+
14376
+ return $result;
14377
+ }
14378
+
14379
+ /**
14380
+ * @author Leo Fajardo (@leorw)
14381
+ * @since 2.3.2
14382
+ *
14383
+ * @return array {
14384
+ * @key string Product slug.
14385
+ * @value array {
14386
+ * @property FS_Site $site
14387
+ * @property FS_Plugin_License $license
14388
+ * }
14389
+ * }
14390
+ */
14391
+ private function get_parent_and_addons_installs_info() {
14392
+ $fs = $this->is_addon() ?
14393
+ $this->get_parent_instance() :
14394
+ $this;
14395
+
14396
+ $installed_addons_ids = array();
14397
+
14398
+ $installed_addons_instances = $fs->get_installed_addons();
14399
+ foreach ( $installed_addons_instances as $instance ) {
14400
+ $installed_addons_ids[] = $instance->get_id();
14401
+ }
14402
+
14403
+ $addons_ids = array_unique( array_merge(
14404
+ $installed_addons_ids,
14405
+ $fs->get_updated_account_addons()
14406
+ ) );
14407
+
14408
+ // Add parent product info.
14409
+ $installs_info_by_slug_map = array(
14410
+ $fs->get_slug() => array(
14411
+ 'install' => $fs->get_site(),
14412
+ 'license' => $fs->_get_license()
14413
+ )
14414
+ );
14415
+
14416
+ foreach ( $addons_ids as $addon_id ) {
14417
+ $is_installed = isset( $installed_addons_ids_map[ $addon_id ] );
14418
+
14419
+ $addon_info = $fs->_get_addon_info( $addon_id, $is_installed );
14420
+
14421
+ if ( ! isset( $addon_info['is_connected'] ) || ! $addon_info['is_connected'] ) {
14422
+ // Add-on is not associated with an install entity.
14423
+ continue;
14424
+ }
14425
+
14426
+ $installs_info_by_slug_map[ $addon_info['slug'] ] = array(
14427
+ 'install' => $addon_info['site'],
14428
+ 'license' => isset( $addon_info['license'] ) ?
14429
+ $addon_info['license'] :
14430
+ null
14431
+ );
14432
+ }
14433
+
14434
+ return $installs_info_by_slug_map;
14435
+ }
14436
+
14437
+ /**
14438
+ * @author Leo Fajardo (@leorw)
14439
+ * @since 1.2.3.1
14440
+ */
14441
+ function _network_activate_ajax_action() {
14442
+ $this->_logger->entrance();
14443
+
14444
+ $this->check_ajax_referer( 'network_activate' );
14445
+
14446
+ $plugin_id = fs_request_get( 'module_id', '', 'post' );
14447
+ $fs = ( $plugin_id == $this->_module_id ) ?
14448
+ $this :
14449
+ $this->get_addon_instance( $plugin_id );
14450
+
14451
+ $error = false;
14452
+
14453
+ $sites = fs_request_get( 'sites', array(), 'post' );
14454
+ if ( is_array( $sites ) && ! empty( $sites ) ) {
14455
+ $sites_by_action = array(
14456
+ 'allow' => array(),
14457
+ 'delegate' => array(),
14458
+ 'skip' => array()
14459
+ );
14460
+
14461
+ foreach ( $sites as $site ) {
14462
+ $sites_by_action[ $site['action'] ][] = $site;
14463
+ }
14464
+
14465
+ $total_sites = count( $sites );
14466
+ $total_sites_to_delegate = count( $sites_by_action['delegate'] );
14467
+
14468
+ $next_page = '';
14469
+
14470
+ $has_any_install = fs_request_get_bool( 'has_any_install' );
14471
+
14472
+ if ( $total_sites === $total_sites_to_delegate &&
14473
+ ! $this->is_network_upgrade_mode() &&
14474
+ ! $has_any_install
14475
+ ) {
14476
+ $this->delegate_connection();
14477
+ } else {
14478
+ if ( ! empty( $sites_by_action['delegate'] ) ) {
14479
+ $this->delegate_connection( self::get_sites_blog_ids( $sites_by_action['delegate'] ) );
14480
+ }
14481
+
14482
+ if ( ! empty( $sites_by_action['skip'] ) ) {
14483
+ $this->skip_connection( self::get_sites_blog_ids( $sites_by_action['skip'] ) );
14484
+ }
14485
+
14486
+ if ( empty( $sites_by_action['allow'] ) ) {
14487
+ if ( $has_any_install ) {
14488
+ $first_install = $fs->find_first_install();
14489
+
14490
+ if ( ! is_null( $first_install ) ) {
14491
+ $fs->_site = $first_install['install'];
14492
+ $fs->_storage->network_install_blog_id = $first_install['blog_id'];
14493
+
14494
+ $fs->_user = self::_get_user_by_id( $fs->_site->user_id );
14495
+ $fs->_storage->network_user_id = $fs->_user->id;
14496
+ }
14497
+ }
14498
+ } else {
14499
+ if ( ! $fs->is_registered() || ! $this->_is_network_active ) {
14500
+ $next_page = $fs->opt_in(
14501
+ false,
14502
+ false,
14503
+ false,
14504
+ false,
14505
+ false,
14506
+ false,
14507
+ false,
14508
+ fs_request_get_bool( 'is_marketing_allowed', null ),
14509
+ $sites_by_action['allow']
14510
+ );
14511
+ } else {
14512
+ $next_page = $fs->install_with_user(
14513
+ $this->get_network_user(),
14514
+ false,
14515
+ false,
14516
+ false,
14517
+ true,
14518
+ $sites_by_action['allow']
14519
+ );
14520
+ }
14521
+
14522
+ if ( is_object( $next_page ) && isset( $next_page->error ) ) {
14523
+ $error = $next_page->error;
14524
+ }
14525
+ }
14526
+ }
14527
+
14528
+ if ( empty( $next_page ) ) {
14529
+ $next_page = $this->get_after_activation_url( 'after_network_activation_url' );
14530
+ }
14531
+ } else {
14532
+ $error = $this->get_text_inline( 'Invalid site details collection.', 'invalid_site_details_collection' );
14533
+ }
14534
+
14535
+ $result = array(
14536
+ 'success' => ( false === $error )
14537
+ );
14538
+
14539
+ if ( false !== $error ) {
14540
+ $result['error'] = $error;
14541
+ } else {
14542
+ $result['next_page'] = $next_page;
14543
+ }
14544
+
14545
+ echo json_encode( $result );
14546
+
14547
+ exit;
14548
+ }
14549
+
14550
+ /**
14551
+ * Billing update AJAX callback.
14552
+ *
14553
+ * @author Vova Feldman (@svovaf)
14554
+ * @since 1.2.1.5
14555
+ */
14556
+ function _update_billing_ajax_action() {
14557
+ $this->_logger->entrance();
14558
+
14559
+ $this->check_ajax_referer( 'update_billing' );
14560
+
14561
+ if ( ! $this->is_user_admin() ) {
14562
+ // Only for admins.
14563
+ self::shoot_ajax_failure();
14564
+ }
14565
+
14566
+ $billing = fs_request_get( 'billing' );
14567
+
14568
+ $api = $this->get_api_user_scope();
14569
+ $result = $api->call( '/billing.json', 'put', array_merge( $billing, array(
14570
+ 'plugin_id' => $this->get_parent_id(),
14571
+ ) ) );
14572
+
14573
+ if ( ! $this->is_api_result_entity( $result ) ) {
14574
+ self::shoot_ajax_failure();
14575
+ }
14576
+
14577
+ // Purge cached billing.
14578
+ $this->get_api_user_scope()->purge_cache( 'billing.json' );
14579
+
14580
+ self::shoot_ajax_success();
14581
+ }
14582
+
14583
+ /**
14584
+ * Trial start for anonymous users (AJAX callback).
14585
+ *
14586
+ * @author Vova Feldman (@svovaf)
14587
+ * @since 1.2.1.5
14588
+ */
14589
+ function _start_trial_ajax_action() {
14590
+ $this->_logger->entrance();
14591
+
14592
+ $this->check_ajax_referer( 'start_trial' );
14593
+
14594
+ if ( ! $this->is_user_admin() ) {
14595
+ // Only for admins.
14596
+ self::shoot_ajax_failure();
14597
+ }
14598
+
14599
+ $trial_data = fs_request_get( 'trial' );
14600
+
14601
+ $next_page = $this->opt_in(
14602
+ false,
14603
+ false,
14604
+ false,
14605
+ false,
14606
+ false,
14607
+ $trial_data['plan_id']
14608
+ );
14609
+
14610
+ if ( is_object( $next_page ) && $this->is_api_error( $next_page ) ) {
14611
+ self::shoot_ajax_failure(
14612
+ isset( $next_page->error ) ?
14613
+ $next_page->error->message :
14614
+ var_export( $next_page, true )
14615
+ );
14616
+ }
14617
+
14618
+ $this->shoot_ajax_success( array(
14619
+ 'next_page' => $next_page,
14620
+ ) );
14621
+ }
14622
+
14623
+ /**
14624
+ * @author Leo Fajardo (@leorw)
14625
+ * @since 1.2.0
14626
+ */
14627
+ function _resend_license_key_ajax_action() {
14628
+ $this->_logger->entrance();
14629
+
14630
+ $this->check_ajax_referer( 'resend_license_key' );
14631
+
14632
+ $email_address = sanitize_email( trim( fs_request_get( 'email', '', 'post' ) ) );
14633
+
14634
+ if ( empty( $email_address ) ) {
14635
+ exit;
14636
+ }
14637
+
14638
+ $error = false;
14639
+
14640
+ $api = $this->get_api_plugin_scope();
14641
+ $result = $api->call( '/licenses/resend.json', 'post',
14642
+ array(
14643
+ 'email' => $email_address,
14644
+ 'url' => home_url(),
14645
+ )
14646
+ );
14647
+
14648
+ if ( is_object( $result ) && isset( $result->error ) ) {
14649
+ $error = $result->error;
14650
+
14651
+ if ( in_array( $error->code, array( 'invalid_email', 'no_user' ) ) ) {
14652
+ $error = $this->get_text_inline( "We couldn't find your email address in the system, are you sure it's the right address?", 'email-not-found' );
14653
+ } else if ( 'no_license' === $error->code ) {
14654
+ $error = $this->get_text_inline( "We can't see any active licenses associated with that email address, are you sure it's the right address?", 'no-active-licenses' );
14655
+ } else {
14656
+ $error = $error->message;
14657
+ }
14658
+ }
14659
+
14660
+ $licenses = array(
14661
+ 'success' => ( false === $error )
14662
+ );
14663
+
14664
+ if ( false !== $error ) {
14665
+ $licenses['error'] = sprintf( '%s... %s', $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ), strtolower( $error ) );
14666
+ }
14667
+
14668
+ echo json_encode( $licenses );
14669
+
14670
+ exit;
14671
+ }
14672
+
14673
+ /**
14674
+ * @author Vova Feldman (@svovaf)
14675
+ * @since 1.2.1.8
14676
+ *
14677
+ * @var string
14678
+ */
14679
+ private static $_pagenow;
14680
+
14681
+ /**
14682
+ * Get current page or the referer if executing a WP AJAX request.
14683
+ *
14684
+ * @author Vova Feldman (@svovaf)
14685
+ * @since 1.2.1.8
14686
+ *
14687
+ * @return string
14688
+ */
14689
+ static function get_current_page() {
14690
+ if ( ! isset( self::$_pagenow ) ) {
14691
+ global $pagenow;
14692
+ if ( empty( $pagenow ) && is_admin() && is_multisite() ) {
14693
+ /**
14694
+ * It appears that `$pagenow` is not yet initialized in some network admin pages when this method
14695
+ * is called, so initialize it here using some pieces of code from `wp-includes/vars.php`.
14696
+ *
14697
+ * @author Leo Fajardo (@leorw)
14698
+ * @since 2.2.3
14699
+ */
14700
+ if ( is_network_admin() ) {
14701
+ preg_match( '#/wp-admin/network/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
14702
+ } else if ( is_user_admin() ) {
14703
+ preg_match( '#/wp-admin/user/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
14704
+ } else {
14705
+ preg_match( '#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
14706
+ }
14707
+
14708
+ $pagenow = $self_matches[1];
14709
+ $pagenow = trim( $pagenow, '/' );
14710
+ $pagenow = preg_replace( '#\?.*?$#', '', $pagenow );
14711
+ if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) {
14712
+ $pagenow = 'index.php';
14713
+ } else {
14714
+ preg_match( '#(.*?)(/|$)#', $pagenow, $self_matches );
14715
+ $pagenow = strtolower( $self_matches[1] );
14716
+ if ( '.php' !== substr($pagenow, -4, 4) )
14717
+ $pagenow .= '.php'; // for Options +Multiviews: /wp-admin/themes/index.php (themes.php is queried)
14718
+ }
14719
+ }
14720
+
14721
+ self::$_pagenow = $pagenow;
14722
+
14723
+ if ( self::is_ajax() &&
14724
+ 'admin-ajax.php' === $pagenow
14725
+ ) {
14726
+ $referer = fs_get_raw_referer();
14727
+
14728
+ if ( is_string( $referer ) ) {
14729
+ $parts = explode( '?', $referer );
14730
+
14731
+ self::$_pagenow = basename( $parts[0] );
14732
+ }
14733
+ }
14734
+ }
14735
+
14736
+ return self::$_pagenow;
14737
+ }
14738
+
14739
+ /**
14740
+ * Helper method to check if user in the plugins page.
14741
+ *
14742
+ * @author Vova Feldman (@svovaf)
14743
+ * @since 1.2.1.5
14744
+ *
14745
+ * @return bool
14746
+ */
14747
+ static function is_plugins_page() {
14748
+ return ( 'plugins.php' === self::get_current_page() );
14749
+ }
14750
+
14751
+ /**
14752
+ * @author Leo Fajardo (@leorw)
14753
+ * @since 2.2.3
14754
+ *
14755
+ * @return bool
14756
+ */
14757
+ static function is_plugin_install_page() {
14758
+ return ( 'plugin-install.php' === self::get_current_page() );
14759
+ }
14760
+
14761
+ /**
14762
+ * @author Leo Fajardo (@leorw)
14763
+ * @since 2.0.2
14764
+ *
14765
+ * @return bool
14766
+ */
14767
+ static function is_updates_page() {
14768
+ return ( 'update-core.php' === self::get_current_page() );
14769
+ }
14770
+
14771
+ /**
14772
+ * Helper method to check if user in the themes page.
14773
+ *
14774
+ * @author Vova Feldman (@svovaf)
14775
+ * @since 1.2.2.6
14776
+ *
14777
+ * @return bool
14778
+ */
14779
+ static function is_themes_page() {
14780
+ return ( 'themes.php' === self::get_current_page() );
14781
+ }
14782
+
14783
+ #----------------------------------------------------------------------------------
14784
+ #region Affiliation
14785
+ #----------------------------------------------------------------------------------
14786
+
14787
+ /**
14788
+ * @author Leo Fajardo (@leorw)
14789
+ * @since 1.2.3
14790
+ *
14791
+ * @return bool
14792
+ */
14793
+ function has_affiliate_program() {
14794
+ if ( ! is_object( $this->_plugin ) ) {
14795
+ return false;
14796
+ }
14797
+
14798
+ return $this->_plugin->has_affiliate_program();
14799
+ }
14800
+
14801
+ /**
14802
+ * Get Plugin ID under which we will track affiliate application.
14803
+ *
14804
+ * This could either be the Bundle ID or the main plugin ID.
14805
+ *
14806
+ * @return number Bundle ID if developer has provided one, else the main plugin ID.
14807
+ */
14808
+ private function get_plugin_id_for_affiliate_terms() {
14809
+ return $this->has_bundle_context() ?
14810
+ $this->get_bundle_id() :
14811
+ $this->_plugin_id;
14812
+ }
14813
+
14814
+ /**
14815
+ * @author Leo Fajardo (@leorw)
14816
+ * @since 1.2.4
14817
+ */
14818
+ private function fetch_affiliate_terms() {
14819
+ if ( ! is_object( $this->plugin_affiliate_terms ) ) {
14820
+ /**
14821
+ * In case we have a bundle set in SDK configuration, we would like to use that for affiliates, not the main plugin.
14822
+ */
14823
+ $plugins_api = $this->has_bundle_context() ?
14824
+ $this->get_api_bundle_scope() :
14825
+ $this->get_api_plugin_scope();
14826
+
14827
+ $affiliate_terms = $plugins_api->get( '/aff.json?type=affiliation', false );
14828
+
14829
+ /**
14830
+ * At this point, we intentionally don't fallback to the main plugin, because the developer has chosen to use bundle. So it makes sense the affiliate program should be in context to the bundle too.
14831
+ */
14832
+ if ( ! $this->is_api_result_entity( $affiliate_terms ) ) {
14833
+ return;
14834
+ }
14835
+
14836
+ $this->plugin_affiliate_terms = new FS_AffiliateTerms( $affiliate_terms );
14837
+ }
14838
+ }
14839
+
14840
+ /**
14841
+ * @author Leo Fajardo (@leorw)
14842
+ * @since 1.2.4
14843
+ */
14844
+ private function fetch_affiliate_and_custom_terms() {
14845
+ if ( ! empty( $this->_storage->affiliate_application_data ) ) {
14846
+ $application_data = $this->_storage->affiliate_application_data;
14847
+ $flush = ( ! isset( $application_data['status'] ) || 'pending' === $application_data['status'] );
14848
+
14849
+ $plugin_id_for_affiliate = $this->get_plugin_id_for_affiliate_terms();
14850
+
14851
+ $users_api = $this->get_api_user_scope();
14852
+ $result = $users_api->get( "/plugins/{$plugin_id_for_affiliate}/aff/{$this->plugin_affiliate_terms->id}/affiliates.json", $flush );
14853
+ if ( $this->is_api_result_object( $result, 'affiliates' ) ) {
14854
+ if ( ! empty( $result->affiliates ) ) {
14855
+ $affiliate = new FS_Affiliate( $result->affiliates[0] );
14856
+
14857
+ if ( ! isset( $application_data['status'] ) || $application_data['status'] !== $affiliate->status ) {
14858
+ $application_data['status'] = $affiliate->status;
14859
+ $this->_storage->affiliate_application_data = $application_data;
14860
+ }
14861
+
14862
+ if ( $affiliate->is_using_custom_terms ) {
14863
+ $affiliate_terms = $users_api->get( "/plugins/{$this->_plugin->id}/affiliates/{$affiliate->id}/aff/{$affiliate->custom_affiliate_terms_id}.json", $flush );
14864
+ if ( $this->is_api_result_entity( $affiliate_terms ) ) {
14865
+ $this->custom_affiliate_terms = new FS_AffiliateTerms( $affiliate_terms );
14866
+ }
14867
+ }
14868
+
14869
+ $this->affiliate = $affiliate;
14870
+ }
14871
+ }
14872
+ }
14873
+ }
14874
+
14875
+ /**
14876
+ * @author Leo Fajardo (@leorw)
14877
+ * @since 1.2.3
14878
+ */
14879
+ private function fetch_affiliate_and_terms() {
14880
+ $this->_logger->entrance();
14881
+
14882
+ $this->fetch_affiliate_terms();
14883
+ $this->fetch_affiliate_and_custom_terms();
14884
+ }
14885
+
14886
+ /**
14887
+ * @author Leo Fajardo (@leorw)
14888
+ * @since 1.2.3
14889
+ *
14890
+ * @return FS_Affiliate
14891
+ */
14892
+ function get_affiliate() {
14893
+ return $this->affiliate;
14894
+ }
14895
+
14896
+
14897
+ /**
14898
+ * @author Leo Fajardo (@leorw)
14899
+ * @since 1.2.3
14900
+ *
14901
+ * @return FS_AffiliateTerms
14902
+ */
14903
+ function get_affiliate_terms() {
14904
+ return is_object( $this->custom_affiliate_terms ) ?
14905
+ $this->custom_affiliate_terms :
14906
+ $this->plugin_affiliate_terms;
14907
+ }
14908
+
14909
+ /**
14910
+ * @author Leo Fajardo (@leorw)
14911
+ * @since 1.2.3
14912
+ */
14913
+ function _submit_affiliate_application() {
14914
+ $this->_logger->entrance();
14915
+
14916
+ $this->check_ajax_referer( 'submit_affiliate_application' );
14917
+
14918
+ if ( ! $this->is_user_admin() ) {
14919
+ // Only for admins.
14920
+ self::shoot_ajax_failure();
14921
+ }
14922
+
14923
+ $affiliate = fs_request_get( 'affiliate' );
14924
+
14925
+ if ( empty( $affiliate['promotion_methods'] ) ) {
14926
+ unset( $affiliate['promotion_methods'] );
14927
+ }
14928
+
14929
+ if ( ! empty( $affiliate['additional_domains'] ) ) {
14930
+ $affiliate['additional_domains'] = array_unique( $affiliate['additional_domains'] );
14931
+ }
14932
+
14933
+ if ( ! $this->is_registered() ) {
14934
+ // Opt in but don't track usage.
14935
+ $next_page = $this->opt_in(
14936
+ false,
14937
+ false,
14938
+ false,
14939
+ false,
14940
+ false,
14941
+ false,
14942
+ true
14943
+ );
14944
+
14945
+ if ( is_object( $next_page ) && $this->is_api_error( $next_page ) ) {
14946
+ self::shoot_ajax_failure(
14947
+ isset( $next_page->error ) ?
14948
+ $next_page->error->message :
14949
+ var_export( $next_page, true )
14950
+ );
14951
+ } else if ( $this->is_pending_activation() ) {
14952
+ self::shoot_ajax_failure( $this->get_text_inline( 'Account is pending activation. Please check your email and click the link to activate your account and then submit the affiliate form again.', 'account-is-pending-activation' ) );
14953
+ }
14954
+ }
14955
+
14956
+ $this->fetch_affiliate_terms();
14957
+
14958
+ $plugin_id_for_affiliate = $this->get_plugin_id_for_affiliate_terms();
14959
+
14960
+ $api = $this->get_api_user_scope();
14961
+ $result = $api->call(
14962
+ ( "/plugins/{$plugin_id_for_affiliate}/aff/{$this->plugin_affiliate_terms->id}/affiliates.json" ),
14963
+ 'post',
14964
+ $affiliate
14965
+ );
14966
+
14967
+ if ( $this->is_api_error( $result ) ) {
14968
+ self::shoot_ajax_failure(
14969
+ isset( $result->error ) ?
14970
+ $result->error->message :
14971
+ var_export( $result, true )
14972
+ );
14973
+ } else {
14974
+ if ( $this->_admin_notices->has_sticky( 'affiliate_program' ) ) {
14975
+ $this->_admin_notices->remove_sticky( 'affiliate_program' );
14976
+ }
14977
+
14978
+ $affiliate_application_data = array(
14979
+ 'status' => 'pending',
14980
+ 'stats_description' => $affiliate['stats_description'],
14981
+ 'promotion_method_description' => $affiliate['promotion_method_description'],
14982
+ );
14983
+
14984
+ if ( ! empty( $affiliate['promotion_methods'] ) ) {
14985
+ $affiliate_application_data['promotion_methods'] = $affiliate['promotion_methods'];
14986
+ }
14987
+
14988
+ if ( ! empty( $affiliate['domain'] ) ) {
14989
+ $affiliate_application_data['domain'] = $affiliate['domain'];
14990
+ }
14991
+
14992
+ if ( ! empty( $affiliate['additional_domains'] ) ) {
14993
+ $affiliate_application_data['additional_domains'] = $affiliate['additional_domains'];
14994
+ }
14995
+
14996
+ $this->_storage->affiliate_application_data = $affiliate_application_data;
14997
+ }
14998
+
14999
+ // Purge cached affiliate.
15000
+ $api->purge_cache( 'affiliate.json' );
15001
+
15002
+ self::shoot_ajax_success( $result );
15003
+ }
15004
+
15005
+ /**
15006
+ * @author Leo Fajardo (@leorw)
15007
+ * @since 1.2.3
15008
+ *
15009
+ * @return array|null
15010
+ */
15011
+ function get_affiliate_application_data() {
15012
+ if ( empty( $this->_storage->affiliate_application_data ) ) {
15013
+ return null;
15014
+ }
15015
+
15016
+ return $this->_storage->affiliate_application_data;
15017
+ }
15018
+
15019
+ #endregion Affiliation ------------------------------------------------------------
15020
+
15021
+ #----------------------------------------------------------------------------------
15022
+ #region URL Generators
15023
+ #----------------------------------------------------------------------------------
15024
+
15025
+ /**
15026
+ * Alias to pricing_url().
15027
+ *
15028
+ * @author Vova Feldman (@svovaf)
15029
+ * @since 1.0.2
15030
+ *
15031
+ * @uses pricing_url()
15032
+ *
15033
+ * @param string $period Billing cycle
15034
+ * @param bool $is_trial
15035
+ *
15036
+ * @return string
15037
+ */
15038
+ function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
15039
+ return $this->pricing_url( $period, $is_trial );
15040
+ }
15041
+
15042
+ /**
15043
+ * @author Vova Feldman (@svovaf)
15044
+ * @since 1.0.9
15045
+ *
15046
+ * @uses get_upgrade_url()
15047
+ *
15048
+ * @return string
15049
+ */
15050
+ function get_trial_url() {
15051
+ return $this->get_upgrade_url( WP_FS__PERIOD_ANNUALLY, true );
15052
+ }
15053
+
15054
+ /**
15055
+ * @author Leo Fajardo (@leorw)
15056
+ * @since 2.1.4
15057
+ *
15058
+ * @param string $new_version
15059
+ *
15060
+ * @return string
15061
+ */
15062
+ function version_upgrade_checkout_link( $new_version ) {
15063
+ if ( ! is_object( $this->_license ) ) {
15064
+ $url = $this->pricing_url();
15065
+
15066
+ $purchase_license_text = $this->get_text_inline( 'Buy a license now', 'buy-license-now' );
15067
+ } else {
15068
+ $subscription = $this->_get_subscription( $this->_license->id );
15069
+
15070
+ $url = $this->checkout_url(
15071
+ is_object( $subscription ) ?
15072
+ ( 1 == $subscription->billing_cycle ? WP_FS__PERIOD_MONTHLY : WP_FS__PERIOD_ANNUALLY ) :
15073
+ WP_FS__PERIOD_LIFETIME,
15074
+ false,
15075
+ array( 'licenses' => $this->_license->quota )
15076
+ );
15077
+
15078
+ $purchase_license_text = $this->get_text_inline( 'Renew your license now', 'renew-license-now' );
15079
+ }
15080
+
15081
+ return sprintf(
15082
+ $this->get_text_inline( '%s to access version %s security & feature updates, and support.', 'x-for-updates-and-support' ),
15083
+ sprintf( '<a href="%s">%s</a>', $url, $purchase_license_text ),
15084
+ $new_version
15085
+ );
15086
+ }
15087
+
15088
+ /**
15089
+ * Plugin's pricing URL.
15090
+ *
15091
+ * @author Vova Feldman (@svovaf)
15092
+ * @since 1.0.4
15093
+ *
15094
+ * @param string $billing_cycle Billing cycle
15095
+ *
15096
+ * @param bool $is_trial
15097
+ *
15098
+ * @return string
15099
+ */
15100
+ function pricing_url( $billing_cycle = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
15101
+ $this->_logger->entrance();
15102
+
15103
+ $params = array(
15104
+ 'billing_cycle' => $billing_cycle
15105
+ );
15106
+
15107
+ if ( $is_trial ) {
15108
+ $params['trial'] = 'true';
15109
+ }
15110
+
15111
+ $url = $this->is_addon() ?
15112
+ $this->_parent->addon_url( $this->_slug ) :
15113
+ $this->_get_admin_page_url( 'pricing', $params );
15114
+
15115
+ return $this->apply_filters( 'pricing_url', $url );
15116
+ }
15117
+
15118
+ /**
15119
+ * Checkout page URL.
15120
+ *
15121
+ * @author Vova Feldman (@svovaf)
15122
+ * @since 1.0.6
15123
+ *
15124
+ * @param string $billing_cycle Billing cycle
15125
+ * @param bool $is_trial
15126
+ * @param array $extra (optional) Extra parameters, override other query params.
15127
+ * @param bool|null $network
15128
+ *
15129
+ * @return string
15130
+ */
15131
+ function checkout_url(
15132
+ $billing_cycle = WP_FS__PERIOD_ANNUALLY,
15133
+ $is_trial = false,
15134
+ $extra = array(),
15135
+ $network = null
15136
+ ) {
15137
+ $this->_logger->entrance();
15138
+
15139
+ $params = array(
15140
+ 'checkout' => 'true',
15141
+ 'billing_cycle' => $billing_cycle,
15142
+ );
15143
+
15144
+ if ( $is_trial ) {
15145
+ $params['trial'] = 'true';
15146
+ }
15147
+
15148
+ /**
15149
+ * Params in extra override other params.
15150
+ */
15151
+ $params = array_merge( $params, $extra );
15152
+
15153
+ return $this->_get_admin_page_url( 'pricing', $params, $network );
15154
+ }
15155
+
15156
+ /**
15157
+ * Add-on checkout URL.
15158
+ *
15159
+ * @author Vova Feldman (@svovaf)
15160
+ * @since 1.1.7
15161
+ *
15162
+ * @param number $addon_id
15163
+ * @param number $pricing_id
15164
+ * @param string $billing_cycle
15165
+ * @param bool $is_trial
15166
+ * @param bool|null $network
15167
+ *
15168
+ * @return string
15169
+ */
15170
+ function addon_checkout_url(
15171
+ $addon_id,
15172
+ $pricing_id,
15173
+ $billing_cycle = WP_FS__PERIOD_ANNUALLY,
15174
+ $is_trial = false,
15175
+ $network = null
15176
+ ) {
15177
+ return $this->checkout_url( $billing_cycle, $is_trial, array(
15178
+ 'plugin_id' => $addon_id,
15179
+ 'pricing_id' => $pricing_id,
15180
+ ), $network );
15181
+ }
15182
+
15183
+ #endregion
15184
+
15185
+ #endregion ------------------------------------------------------------------
15186
+
15187
+ /**
15188
+ * Check if plugin has any add-ons.
15189
+ *
15190
+ * @author Vova Feldman (@svovaf)
15191
+ * @since 1.0.5
15192
+ *
15193
+ * @since 1.1.7.3 Base logic only on the parameter provided by the developer in the init function.
15194
+ *
15195
+ * @return bool
15196
+ */
15197
+ function has_addons() {
15198
+ $this->_logger->entrance();
15199
+
15200
+ return $this->_has_addons;
15201
+ }
15202
+
15203
+ /**
15204
+ * Check if plugin can work in anonymous mode.
15205
+ *
15206
+ * @author Vova Feldman (@svovaf)
15207
+ * @since 1.0.9
15208
+ *
15209
+ * @return bool
15210
+ *
15211
+ * @deprecated Please use is_enable_anonymous() instead.
15212
+ */
15213
+ function enable_anonymous() {
15214
+ return $this->_enable_anonymous;
15215
+ }
15216
+
15217
+ /**
15218
+ * Check if plugin can work in anonymous mode.
15219
+ *
15220
+ * @author Vova Feldman (@svovaf)
15221
+ * @since 1.1.9
15222
+ *
15223
+ * @return bool
15224
+ */
15225
+ function is_enable_anonymous() {
15226
+ return $this->_enable_anonymous;
15227
+ }
15228
+
15229
+ /**
15230
+ * Check if plugin is premium only (no free plans).
15231
+ *
15232
+ * @author Vova Feldman (@svovaf)
15233
+ * @since 1.1.9
15234
+ *
15235
+ * @return bool
15236
+ */
15237
+ function is_only_premium() {
15238
+ return $this->_is_premium_only;
15239
+ }
15240
+
15241
+ /**
15242
+ * Checks if the plugin's type is "plugin". The other type is "theme".
15243
+ *
15244
+ * @author Leo Fajardo (@leorw)
15245
+ * @since 1.2.2
15246
+ *
15247
+ * @return bool
15248
+ */
15249
+ function is_plugin() {
15250
+ return ( WP_FS__MODULE_TYPE_PLUGIN === $this->_module_type );
15251
+ }
15252
+
15253
+ /**
15254
+ * @author Leo Fajardo (@leorw)
15255
+ * @since 1.2.2
15256
+ *
15257
+ * @return string
15258
+ */
15259
+ function get_module_type() {
15260
+ if ( ! isset( $this->_module_type ) ) {
15261
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
15262
+ $this->_module_type = $id_slug_type_path_map[ $this->_module_id ]['type'];
15263
+ }
15264
+
15265
+ return $this->_module_type;
15266
+ }
15267
+
15268
+ /**
15269
+ * @author Leo Fajardo (@leorw)
15270
+ * @since 1.2.2
15271
+ *
15272
+ * @return string
15273
+ */
15274
+ function get_plugin_main_file_path() {
15275
+ return $this->_plugin_main_file_path;
15276
+ }
15277
+
15278
+ /**
15279
+ * Check if module has a premium code version.
15280
+ *
15281
+ * Serviceware module might be freemium without any
15282
+ * premium code version, where the paid features
15283
+ * are all part of the service.
15284
+ *
15285
+ * @author Vova Feldman (@svovaf)
15286
+ * @since 1.2.1.6
15287
+ *
15288
+ * @return bool
15289
+ */
15290
+ function has_premium_version() {
15291
+ return $this->_has_premium_version;
15292
+ }
15293
+
15294
+ /**
15295
+ * Check if feature supported with current site's plan.
15296
+ *
15297
+ * @author Vova Feldman (@svovaf)
15298
+ * @since 1.0.1
15299
+ *
15300
+ * @todo IMPLEMENT
15301
+ *
15302
+ * @param number $feature_id
15303
+ *
15304
+ * @throws Exception
15305
+ */
15306
+ function is_feature_supported( $feature_id ) {
15307
+ throw new Exception( 'not implemented' );
15308
+ }
15309
+
15310
+ /**
15311
+ * @author Vova Feldman (@svovaf)
15312
+ * @since 1.0.1
15313
+ *
15314
+ * @return bool Is running in SSL/HTTPS
15315
+ */
15316
+ function is_ssl() {
15317
+ return WP_FS__IS_HTTPS;
15318
+ }
15319
+
15320
+ /**
15321
+ * @author Vova Feldman (@svovaf)
15322
+ * @since 1.0.9
15323
+ *
15324
+ * @return bool Is running in AJAX call.
15325
+ *
15326
+ * @link http://wordpress.stackexchange.com/questions/70676/how-to-check-if-i-am-in-admin-ajax
15327
+ */
15328
+ static function is_ajax() {
15329
+ return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
15330
+ }
15331
+
15332
+ /**
15333
+ * Check if it's an AJAX call targeted for the current module.
15334
+ *
15335
+ * @author Vova Feldman (@svovaf)
15336
+ * @since 1.2.0
15337
+ *
15338
+ * @param array|string $actions Collection of AJAX actions.
15339
+ *
15340
+ * @return bool
15341
+ */
15342
+ function is_ajax_action( $actions ) {
15343
+ // Verify it's an ajax call.
15344
+ if ( ! self::is_ajax() ) {
15345
+ return false;
15346
+ }
15347
+
15348
+ // Verify the call is relevant for the plugin.
15349
+ if ( $this->_module_id != fs_request_get( 'module_id' ) ) {
15350
+ return false;
15351
+ }
15352
+
15353
+ // Verify it's one of the specified actions.
15354
+ if ( is_string( $actions ) ) {
15355
+ $actions = explode( ',', $actions );
15356
+ }
15357
+
15358
+ if ( is_array( $actions ) && 0 < count( $actions ) ) {
15359
+ $ajax_action = fs_request_get( 'action' );
15360
+
15361
+ foreach ( $actions as $action ) {
15362
+ if ( $ajax_action === $this->get_action_tag( $action ) ) {
15363
+ return true;
15364
+ }
15365
+ }
15366
+ }
15367
+
15368
+ return false;
15369
+ }
15370
+
15371
+ /**
15372
+ * Check if it's an AJAX call targeted for current request.
15373
+ *
15374
+ * @author Vova Feldman (@svovaf)
15375
+ * @since 1.2.0
15376
+ *
15377
+ * @param array|string $actions Collection of AJAX actions.
15378
+ * @param number|null $module_id
15379
+ *
15380
+ * @return bool
15381
+ */
15382
+ static function is_ajax_action_static( $actions, $module_id = null ) {
15383
+ // Verify it's an ajax call.
15384
+ if ( ! self::is_ajax() ) {
15385
+ return false;
15386
+ }
15387
+
15388
+
15389
+ if ( ! empty( $module_id ) ) {
15390
+ // Verify the call is relevant for the plugin.
15391
+ if ( $module_id != fs_request_get( 'module_id' ) ) {
15392
+ return false;
15393
+ }
15394
+ }
15395
+
15396
+ // Verify it's one of the specified actions.
15397
+ if ( is_string( $actions ) ) {
15398
+ $actions = explode( ',', $actions );
15399
+ }
15400
+
15401
+ if ( is_array( $actions ) && 0 < count( $actions ) ) {
15402
+ $ajax_action = fs_request_get( 'action' );
15403
+
15404
+ foreach ( $actions as $action ) {
15405
+ if ( $ajax_action === self::get_ajax_action_static( $action, $module_id ) ) {
15406
+ return true;
15407
+ }
15408
+ }
15409
+ }
15410
+
15411
+ return false;
15412
+ }
15413
+
15414
+ /**
15415
+ * @author Vova Feldman (@svovaf)
15416
+ * @since 1.1.7
15417
+ *
15418
+ * @return bool
15419
+ */
15420
+ static function is_cron() {
15421
+ return ( defined( 'DOING_CRON' ) && DOING_CRON );
15422
+ }
15423
+
15424
+ /**
15425
+ * @author Leo Fajardo (@leorw)
15426
+ * @since 2.5.0
15427
+ *
15428
+ * @return bool
15429
+ */
15430
+ static function is_admin_post() {
15431
+ return ( 'admin-post.php' === self::get_current_page() );
15432
+ }
15433
+
15434
+ /**
15435
+ * Check if a real user is visiting the admin dashboard.
15436
+ *
15437
+ * @author Vova Feldman (@svovaf)
15438
+ * @since 1.1.7
15439
+ *
15440
+ * @return bool
15441
+ */
15442
+ function is_user_in_admin() {
15443
+ return (
15444
+ is_admin() &&
15445
+ ! self::is_ajax() &&
15446
+ ! self::is_cron() &&
15447
+ ! self::is_admin_post()
15448
+ );
15449
+ }
15450
+
15451
+ /**
15452
+ * Check if a real user is in the customizer view.
15453
+ *
15454
+ * @author Vova Feldman (@svovaf)
15455
+ * @since 1.2.2.7
15456
+ *
15457
+ * @return bool
15458
+ */
15459
+ static function is_customizer() {
15460
+ return is_customize_preview();
15461
+ }
15462
+
15463
+ /**
15464
+ * Check if running in HTTPS and if site's plan matching the specified plan.
15465
+ *
15466
+ * @param string $plan
15467
+ * @param bool $exact
15468
+ *
15469
+ * @return bool
15470
+ */
15471
+ function is_ssl_and_plan( $plan, $exact = false ) {
15472
+ return ( $this->is_ssl() && $this->is_plan( $plan, $exact ) );
15473
+ }
15474
+
15475
+ /**
15476
+ * Construct plugin's settings page URL.
15477
+ *
15478
+ * @author Vova Feldman (@svovaf)
15479
+ * @since 1.0.4
15480
+ *
15481
+ * @param string $page
15482
+ * @param array $params
15483
+ * @param bool|null $network
15484
+ *
15485
+ * @return string
15486
+ */
15487
+ function _get_admin_page_url( $page = '', $params = array(), $network = null ) {
15488
+ if ( is_null( $network ) ) {
15489
+ $network = (
15490
+ $this->_is_network_active &&
15491
+ ( fs_is_network_admin() || ! $this->is_delegated_connection() )
15492
+ );
15493
+ }
15494
+
15495
+ if ( 0 < count( $params ) ) {
15496
+ foreach ( $params as $k => $v ) {
15497
+ $params[ $k ] = urlencode( $v );
15498
+ }
15499
+ }
15500
+
15501
+ $page_param = $this->_menu->get_slug( $page );
15502
+
15503
+ if ( empty( $page ) &&
15504
+ // Show the opt-in as an overlay for free wp.org themes or themes without any settings page.
15505
+ $this->show_opt_in_on_themes_page()
15506
+ ) {
15507
+ $params[ $this->get_unique_affix() . '_show_optin' ] = 'true';
15508
+
15509
+ return add_query_arg(
15510
+ $params,
15511
+ $this->admin_url( 'themes.php', 'admin', $network )
15512
+ );
15513
+ }
15514
+
15515
+ if ( ! $this->has_settings_menu() ) {
15516
+ if ( ! empty( $page ) ) {
15517
+ // Module doesn't have a setting page, but since the request is for
15518
+ // a specific Freemius page, use the admin.php path.
15519
+ return add_query_arg( array_merge( $params, array(
15520
+ 'page' => $page_param,
15521
+ ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
15522
+ } else {
15523
+ if ( $this->is_activation_mode() ) {
15524
+ /**
15525
+ * @author Vova Feldman
15526
+ * @since 1.2.1.6
15527
+ *
15528
+ * If plugin doesn't have a settings page, create one for the opt-in screen.
15529
+ */
15530
+ return add_query_arg( array_merge( $params, array(
15531
+ 'page' => $this->_slug,
15532
+ ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
15533
+ } else {
15534
+ // Plugin without a settings page.
15535
+ return add_query_arg(
15536
+ $params,
15537
+ $this->admin_url( 'plugins.php', 'admin', $network )
15538
+ );
15539
+ }
15540
+ }
15541
+ }
15542
+
15543
+ // Module has a submenu settings page.
15544
+ if ( ! $this->_menu->is_top_level() ) {
15545
+ $parent_slug = $this->_menu->get_parent_slug();
15546
+ $menu_file = ( false !== strpos( $parent_slug, '.php' ) ) ?
15547
+ $parent_slug :
15548
+ 'admin.php';
15549
+
15550
+ return add_query_arg( array_merge( $params, array(
15551
+ 'page' => $page_param,
15552
+ ) ), $this->admin_url( $menu_file, 'admin', $network ) );
15553
+ }
15554
+
15555
+ // Module has a top level CPT settings page.
15556
+ if ( $this->_menu->is_cpt() ) {
15557
+ if ( empty( $page ) && $this->is_activation_mode() ) {
15558
+ return add_query_arg( array_merge( $params, array(
15559
+ 'page' => $page_param
15560
+ ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
15561
+ } else {
15562
+ if ( ! empty( $page ) ) {
15563
+ $params['page'] = $page_param;
15564
+ }
15565
+
15566
+ return add_query_arg(
15567
+ $params,
15568
+ $this->admin_url( $this->_menu->get_raw_slug(), 'admin', $network )
15569
+ );
15570
+ }
15571
+ }
15572
+
15573
+ // Module has a custom top level settings page.
15574
+ return add_query_arg( array_merge( $params, array(
15575
+ 'page' => $page_param,
15576
+ ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
15577
+ }
15578
+
15579
+ #--------------------------------------------------------------------------------
15580
+ #region Multisite
15581
+ #--------------------------------------------------------------------------------
15582
+
15583
+ /**
15584
+ * @author Leo Fajardo (@leorw)
15585
+ * @since 2.0.0
15586
+ *
15587
+ * @return bool
15588
+ */
15589
+ function is_network_active() {
15590
+ return $this->_is_network_active;
15591
+ }
15592
+
15593
+ /**
15594
+ * Delegate activation for the given sites in the network (or all sites if `null`) to site admins.
15595
+ *
15596
+ * @author Leo Fajardo (@leorw)
15597
+ * @since 2.0.0
15598
+ *
15599
+ * @param bool|int[] $all_or_blog_ids
15600
+ */
15601
+ private function delegate_connection( $all_or_blog_ids = true ) {
15602
+ $this->_logger->entrance();
15603
+
15604
+ $this->_admin_notices->remove_sticky( 'connect_account' );
15605
+
15606
+ if ( true === $all_or_blog_ids ) {
15607
+ // All sites delegation.
15608
+ $this->_storage->store( 'is_delegated_connection', true, true );
15609
+ } else {
15610
+ // Specified sites delegation.
15611
+ foreach ( $all_or_blog_ids as $blog_id ) {
15612
+ $this->delegate_site_connection( $blog_id );
15613
+ }
15614
+ }
15615
+
15616
+ $this->network_upgrade_mode_completed();
15617
+ }
15618
+
15619
+ /**
15620
+ * Delegate specific network site conncetion to the site admin.
15621
+ *
15622
+ * @author Vova Feldman (@svovaf)
15623
+ * @since 2.0.0
15624
+ *
15625
+ * @param int $blog_id
15626
+ */
15627
+ private function delegate_site_connection( $blog_id ) {
15628
+ $this->_storage->store( 'is_delegated_connection', true, $blog_id );
15629
+ }
15630
+
15631
+ /**
15632
+ * Check if super-admin delegated the connection of ALL sites to the site admins.
15633
+ *
15634
+ * @author Vova Feldman (@svovaf)
15635
+ * @since 2.0.0
15636
+ *
15637
+ * @return bool
15638
+ */
15639
+ function is_network_delegated_connection() {
15640
+ if ( ! $this->_is_network_active ) {
15641
+ return false;
15642
+ }
15643
+
15644
+ return $this->_storage->get( 'is_delegated_connection', false, true );
15645
+ }
15646
+
15647
+ /**
15648
+ * @author Leo Fajardo (@leorw)
15649
+ * @since 2.0.0
15650
+ *
15651
+ * @param int $blog_id
15652
+ *
15653
+ * @return bool
15654
+ */
15655
+ function is_site_delegated_connection( $blog_id = 0 ) {
15656
+ if ( ! $this->_is_network_active ) {
15657
+ return false;
15658
+ }
15659
+
15660
+ if ( 0 == $blog_id ) {
15661
+ $blog_id = get_current_blog_id();
15662
+ }
15663
+
15664
+ return $this->_storage->get( 'is_delegated_connection', false, $blog_id );
15665
+ }
15666
+
15667
+ /**
15668
+ * Check if delegated the connection. When running within the network admin,
15669
+ * and haven't specified the blog ID, checks if network level delegated. If running
15670
+ * within a site admin or specified a blog ID, check if delegated the connection for
15671
+ * the current context site.
15672
+ *
15673
+ * If executed outside the the admin, check if delegated the connection
15674
+ * for the current context site OR the whole network.
15675
+ *
15676
+ * @author Vova Feldman (@svovaf)
15677
+ * @since 2.0.0
15678
+ *
15679
+ * @param int $blog_id If set, checks if network delegated or blog specific delegated.
15680
+ *
15681
+ * @return bool
15682
+ */
15683
+ function is_delegated_connection( $blog_id = 0 ) {
15684
+ if ( ! $this->_is_network_active ) {
15685
+ return false;
15686
+ }
15687
+
15688
+ if ( fs_is_network_admin() && 0 == $blog_id ) {
15689
+ return $this->is_network_delegated_connection();
15690
+ }
15691
+
15692
+ return (
15693
+ $this->is_network_delegated_connection() ||
15694
+ $this->is_site_delegated_connection( $blog_id )
15695
+ );
15696
+ }
15697
+
15698
+ /**
15699
+ * Check if the current module is active for the site.
15700
+ *
15701
+ * @author Vova Feldman (@svovaf)
15702
+ * @since 2.0.0
15703
+ *
15704
+ * @param int $blog_id
15705
+ *
15706
+ * @return bool
15707
+ */
15708
+ function is_active_for_site( $blog_id ) {
15709
+ if ( ! is_multisite() ) {
15710
+ // Not a multisite and this code is executed, means that the plugin is active.
15711
+ return true;
15712
+ }
15713
+
15714
+ if ( $this->is_theme() ) {
15715
+ // All themes are site level activated.
15716
+ return true;
15717
+ }
15718
+
15719
+ if ( $this->_is_network_active ) {
15720
+ // Plugin was network activated so it's active.
15721
+ return true;
15722
+ }
15723
+
15724
+ return in_array( $this->_plugin_basename, (array) get_blog_option( $blog_id, 'active_plugins', array() ) );
15725
+ }
15726
+
15727
+ /**
15728
+ * @todo Implement pagination when accessing the subsites collection.
15729
+ *
15730
+ * @author Leo Fajardo (@leorw)
15731
+ * @since 2.0.0
15732
+ *
15733
+ * @param int $limit Default to 1,000
15734
+ * @param int $offset Default to 0
15735
+ *
15736
+ * @return array Active & public sites collection.
15737
+ */
15738
+ static function get_sites( $limit = 1000, $offset = 0 ) {
15739
+ if ( ! is_multisite() ) {
15740
+ return array();
15741
+ }
15742
+
15743
+ /**
15744
+ * For consistency with get_blog_list() which only return active public sites.
15745
+ *
15746
+ * @author Vova Feldman (@svovaf)
15747
+ */
15748
+ $args = array(
15749
+ /**
15750
+ * Commented out in order to handle the migration of site options whether the site is public or not.
15751
+ *
15752
+ * @author Leo Fajardo (@leorw)
15753
+ * @since 2.2.1
15754
+ */
15755
+ // 'public' => 1,
15756
+ 'archived' => 0,
15757
+ 'mature' => 0,
15758
+ 'spam' => 0,
15759
+ 'deleted' => 0,
15760
+ 'number' => $limit,
15761
+ 'offset' => $offset,
15762
+ );
15763
+
15764
+ return get_sites( $args );
15765
+ }
15766
+
15767
+ /**
15768
+ * Checks if a given blog is active.
15769
+ *
15770
+ * @author Vova Feldman (@svovaf)
15771
+ * @since 2.0.0
15772
+ *
15773
+ * @param $blog_id
15774
+ *
15775
+ * @return bool
15776
+ */
15777
+ private static function is_site_active( $blog_id ) {
15778
+ global $wpdb;
15779
+
15780
+ $blog_info = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d", $blog_id ) );
15781
+
15782
+ if ( ! is_object( $blog_info ) ) {
15783
+ return false;
15784
+ }
15785
+
15786
+ return (
15787
+ true == $blog_info->public &&
15788
+ false == $blog_info->archived &&
15789
+ false == $blog_info->mature &&
15790
+ false == $blog_info->spam &&
15791
+ false == $blog_info->deleted
15792
+ );
15793
+ }
15794
+
15795
+ /**
15796
+ * Get a mapping between the site addresses to their blog IDs.
15797
+ *
15798
+ * @author Vova Feldman (@svovaf)
15799
+ * @since 2.0.0
15800
+ *
15801
+ * @return array {
15802
+ * @key string Site address without protocol with a trailing slash.
15803
+ * @value int Site's blog ID.
15804
+ * }
15805
+ */
15806
+ private function get_address_to_blog_map() {
15807
+ $sites = self::get_sites();
15808
+
15809
+ // Map site addresses to their blog IDs.
15810
+ $address_to_blog_map = array();
15811
+ foreach ( $sites as $site ) {
15812
+ $blog_id = self::get_site_blog_id( $site );
15813
+ $address = self::get_unfiltered_site_url( $blog_id, true, true );
15814
+ $address_to_blog_map[ $address ] = $blog_id;
15815
+ }
15816
+
15817
+ return $address_to_blog_map;
15818
+ }
15819
+
15820
+ /**
15821
+ * Get a mapping between the site addresses to their blog IDs.
15822
+ *
15823
+ * @author Vova Feldman (@svovaf)
15824
+ * @since 2.0.0
15825
+ *
15826
+ * @return array {
15827
+ * @key int Site's blog ID.
15828
+ * @value FS_Site Associated install.
15829
+ * }
15830
+ */
15831
+ function get_blog_install_map() {
15832
+ $sites = self::get_sites();
15833
+
15834
+ // Map site blog ID to its install.
15835
+ $install_map = array();
15836
+
15837
+ foreach ( $sites as $site ) {
15838
+ $blog_id = self::get_site_blog_id( $site );
15839
+ $install = $this->get_install_by_blog_id( $blog_id );
15840
+
15841
+ if ( is_object( $install ) ) {
15842
+ $install_map[ $blog_id ] = $install;
15843
+ }
15844
+ }
15845
+
15846
+ return $install_map;
15847
+ }
15848
+
15849
+ /**
15850
+ * @author Vova Feldman (@svovaf)
15851
+ * @since 2.5.1
15852
+ *
15853
+ * @param bool|null $is_delegated When `true`, returns only connection delegated blog IDs. When `false`, only non-delegated blog IDs.
15854
+ *
15855
+ * @return int[]
15856
+ */
15857
+ private function get_blog_ids( $is_delegated = null ) {
15858
+ $blog_ids = array();
15859
+
15860
+ $sites = self::get_sites();
15861
+ foreach ( $sites as $site ) {
15862
+ $blog_id = self::get_site_blog_id( $site );
15863
+
15864
+ if (
15865
+ is_null( $is_delegated ) ||
15866
+ $is_delegated === $this->is_site_delegated_connection( $blog_id )
15867
+ ) {
15868
+ $blog_ids[] = $blog_id;
15869
+ }
15870
+ }
15871
+
15872
+ return $blog_ids;
15873
+ }
15874
+
15875
+ /**
15876
+ * @author Vova Feldman (@svovaf)
15877
+ * @since 2.5.1
15878
+ *
15879
+ * @return int[]
15880
+ */
15881
+ private function get_non_delegated_blog_ids() {
15882
+ return $this->get_blog_ids( false );
15883
+ }
15884
+
15885
+ /**
15886
+ * Gets a map of module IDs that the given user has opted-in to.
15887
+ *
15888
+ * @author Leo Fajardo (@leorw)
15889
+ * @since 2.1.0
15890
+ *
15891
+ * @param number $fs_user_id
15892
+ *
15893
+ * @return array {
15894
+ * @key number $plugin_id
15895
+ * @value bool Always true.
15896
+ * }
15897
+ */
15898
+ private static function get_user_opted_in_module_ids_map( $fs_user_id ) {
15899
+ self::$_static_logger->entrance();
15900
+
15901
+ if ( ! is_multisite() ) {
15902
+ $installs = array_merge(
15903
+ self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN ),
15904
+ self::get_all_sites( WP_FS__MODULE_TYPE_THEME )
15905
+ );
15906
+ } else {
15907
+ $sites = self::get_sites();
15908
+
15909
+ $installs = array();
15910
+ foreach ( $sites as $site ) {
15911
+ $blog_id = self::get_site_blog_id( $site );
15912
+
15913
+ $installs = array_merge(
15914
+ $installs,
15915
+ self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN, $blog_id ),
15916
+ self::get_all_sites( WP_FS__MODULE_TYPE_THEME, $blog_id )
15917
+ );
15918
+ }
15919
+ }
15920
+
15921
+ $module_ids_map = array();
15922
+ foreach ( $installs as $install ) {
15923
+ if ( is_object( $install ) &&
15924
+ FS_Site::is_valid_id( $install->id ) &&
15925
+ FS_User::is_valid_id( $install->user_id ) &&
15926
+ ( $install->user_id == $fs_user_id )
15927
+ ) {
15928
+ $module_ids_map[ $install->plugin_id ] = true;
15929
+ }
15930
+ }
15931
+
15932
+ return $module_ids_map;
15933
+ }
15934
+
15935
+ /**
15936
+ * @author Leo Fajardo (@leorw)
15937
+ *
15938
+ * @return null|array {
15939
+ * 'install' => FS_Site Module's install,
15940
+ * 'blog_id' => string The associated blog ID.
15941
+ * }
15942
+ */
15943
+ function find_first_install() {
15944
+ $sites = self::get_sites();
15945
+
15946
+ foreach ( $sites as $site ) {
15947
+ $blog_id = self::get_site_blog_id( $site );
15948
+ $install = $this->get_install_by_blog_id( $blog_id );
15949
+
15950
+ if ( is_object( $install ) ) {
15951
+ return array(
15952
+ 'install' => $install,
15953
+ 'blog_id' => $blog_id
15954
+ );
15955
+ }
15956
+ }
15957
+
15958
+ return null;
15959
+ }
15960
+
15961
+ /**
15962
+ * Switches the Freemius site level context to a specified blog.
15963
+ *
15964
+ * @author Vova Feldman (@svovaf)
15965
+ * @since 2.0.0
15966
+ *
15967
+ * @param int $blog_id
15968
+ * @param FS_Site $install
15969
+ * @param bool $flush
15970
+ *
15971
+ * @return bool Since 2.3.1 returns if a switch was made.
15972
+ */
15973
+ function switch_to_blog( $blog_id, FS_Site $install = null, $flush = false ) {
15974
+ if ( ! is_numeric( $blog_id ) ) {
15975
+ return false;
15976
+ }
15977
+
15978
+ if ( ! $flush && $blog_id == $this->_context_is_network_or_blog_id ) {
15979
+ return false;
15980
+ }
15981
+
15982
+ switch_to_blog( $blog_id );
15983
+ $this->_context_is_network_or_blog_id = $blog_id;
15984
+
15985
+ self::$_accounts->set_site_blog_context( $blog_id );
15986
+ $this->_storage->set_site_blog_context( $blog_id );
15987
+ $this->_storage->set_network_active( $this->_is_network_active, $this->is_delegated_connection( $blog_id ) );
15988
+
15989
+ $this->_site = is_object( $install ) ?
15990
+ $install :
15991
+ $this->get_install_by_blog_id( $blog_id );
15992
+
15993
+ $this->_user = false;
15994
+ $this->_licenses = false;
15995
+ $this->_license = null;
15996
+ $this->is_whitelabeled = null;
15997
+
15998
+ if ( is_object( $this->_site ) ) {
15999
+ // Try to fetch user from install.
16000
+ $this->_user = self::_get_user_by_id( $this->_site->user_id );
16001
+
16002
+ if ( ! is_object( $this->_user ) &&
16003
+ FS_User::is_valid_id( $this->_storage->prev_user_id )
16004
+ ) {
16005
+ // Try to fetch previously saved user.
16006
+ $this->_user = self::_get_user_by_id( $this->_storage->prev_user_id );
16007
+
16008
+ if ( ! is_object( $this->_user ) ) {
16009
+ // Fallback to network's user.
16010
+ $this->_user = $this->get_network_user();
16011
+ }
16012
+ }
16013
+
16014
+ $all_plugin_licenses = self::get_all_licenses( $this->_module_id );
16015
+
16016
+ if ( ! empty( $all_plugin_licenses ) ) {
16017
+ if ( ! FS_Plugin_License::is_valid_id( $this->_site->license_id ) ) {
16018
+ $this->_license = null;
16019
+ } else {
16020
+ $license_found = false;
16021
+ foreach ( $all_plugin_licenses as $license ) {
16022
+ if ( $license->id == $this->_site->license_id ) {
16023
+ // License found.
16024
+ $this->_license = $license;
16025
+ $license_found = true;
16026
+ break;
16027
+ }
16028
+ }
16029
+
16030
+ if ( $license_found ) {
16031
+ $this->link_license_2_user( $this->_license->id, $this->_user->id );
16032
+ }
16033
+ }
16034
+
16035
+ $this->_licenses = $this->get_user_licenses( $this->_user->id );
16036
+ }
16037
+ }
16038
+
16039
+ unset( $this->_site_api );
16040
+ unset( $this->_user_api );
16041
+
16042
+ return true;
16043
+ }
16044
+
16045
+ /**
16046
+ * Restore the blog context to the blog that originally loaded the module.
16047
+ *
16048
+ * @author Vova Feldman (@svovaf)
16049
+ * @since 2.0.0
16050
+ */
16051
+ function restore_current_blog() {
16052
+ $this->switch_to_blog( $this->_blog_id );
16053
+ }
16054
+
16055
+ /**
16056
+ * @author Vova Feldman (@svovaf)
16057
+ * @since 2.0.0
16058
+ *
16059
+ * @param array|WP_Site $site
16060
+ *
16061
+ * @return int
16062
+ */
16063
+ static function get_site_blog_id( &$site ) {
16064
+ return ( $site instanceof WP_Site ) ?
16065
+ $site->blog_id :
16066
+ ( is_object( $site ) && isset( $site->userblog_id ) ?
16067
+ $site->userblog_id :
16068
+ $site['blog_id'] );
16069
+ }
16070
+
16071
+ /**
16072
+ * @author Vova Feldman (@svovaf)
16073
+ * @since 2.5.1
16074
+ *
16075
+ * @param WP_Site[]|array[] $sites
16076
+ *
16077
+ * @return int[]
16078
+ */
16079
+ static function get_sites_blog_ids( $sites ) {
16080
+ $blog_ids = array();
16081
+ foreach ( $sites as $site ) {
16082
+ $blog_ids[] = self::get_site_blog_id( $site );
16083
+ }
16084
+
16085
+ return $blog_ids;
16086
+ }
16087
+
16088
+ /**
16089
+ * @author Leo Fajardo (@leorw)
16090
+ * @since 2.0.0
16091
+ *
16092
+ * @param array|WP_Site|null $site
16093
+ * @param bool $load_registration Since 2.5.1 When set to `true` the method will attempt to return the subsite's registration date, regardless of the `$site` type and value. In most calls, the registration date will be returned anyway, even when the value is `false`. This param is purely for performance optimization.
16094
+ *
16095
+ * @return array
16096
+ */
16097
+ function get_site_info( $site = null, $load_registration = false ) {
16098
+ $this->_logger->entrance();
16099
+
16100
+ $switched = false;
16101
+
16102
+ $registration_date = null;
16103
+
16104
+ if ( is_null( $site ) ) {
16105
+ $url = self::get_unfiltered_site_url();
16106
+ $name = get_bloginfo( 'name' );
16107
+ $blog_id = null;
16108
+ } else {
16109
+ $blog_id = self::get_site_blog_id( $site );
16110
+
16111
+ if ( get_current_blog_id() != $blog_id ) {
16112
+ switch_to_blog( $blog_id );
16113
+ $switched = true;
16114
+ }
16115
+
16116
+ if ( $site instanceof WP_Site ) {
16117
+ $url = $site->siteurl;
16118
+ $name = $site->blogname;
16119
+ $registration_date = $site->registered;
16120
+ } else {
16121
+ $url = self::get_unfiltered_site_url( $blog_id );
16122
+ $name = get_bloginfo( 'name' );
16123
+ }
16124
+ }
16125
+
16126
+ if ( empty( $registration_date ) && $load_registration ) {
16127
+ $blog_details = get_blog_details( $blog_id, false );
16128
+
16129
+ if ( is_object( $blog_details ) && isset( $blog_details->registered ) ) {
16130
+ $registration_date = $blog_details->registered;
16131
+ }
16132
+ }
16133
+
16134
+ $info = array(
16135
+ 'uid' => $this->get_anonymous_id( $blog_id ),
16136
+ 'url' => $url,
16137
+ );
16138
+
16139
+ // Add these diagnostic information only if user allowed to track.
16140
+ if ( FS_Permission_Manager::instance( $this )->is_diagnostic_tracking_allowed() ) {
16141
+ $info = array_merge( $info, array(
16142
+ 'title' => $name,
16143
+ 'language' => self::get_sanitized_language(),
16144
+ ) );
16145
+ }
16146
+
16147
+ if ( is_numeric( $blog_id ) ) {
16148
+ $info['blog_id'] = $blog_id;
16149
+ }
16150
+
16151
+ if ( ! empty( $registration_date ) ) {
16152
+ $info[ 'registration_date' ] = $registration_date;
16153
+ }
16154
+
16155
+ if ( $switched ) {
16156
+ restore_current_blog();
16157
+ }
16158
+
16159
+ return $info;
16160
+ }
16161
+
16162
+ /**
16163
+ * Load the module's install based on the blog ID.
16164
+ *
16165
+ * @author Vova Feldman (@svovaf)
16166
+ * @since 2.0.0
16167
+ *
16168
+ * @param int|null $blog_id
16169
+ *
16170
+ * @return FS_Site
16171
+ */
16172
+ function get_install_by_blog_id( $blog_id = null ) {
16173
+ $installs = self::get_all_sites( $this->_module_type, $blog_id );
16174
+ $install = isset( $installs[ $this->_slug ] ) ? $installs[ $this->_slug ] : null;
16175
+
16176
+ if ( is_object( $install ) &&
16177
+ is_numeric( $install->id ) &&
16178
+ is_numeric( $install->user_id ) &&
16179
+ FS_Plugin_Plan::is_valid_id( $install->plan_id )
16180
+ ) {
16181
+ // Load site.
16182
+ $install = clone $install;
16183
+ }
16184
+
16185
+ return $install;
16186
+ }
16187
+
16188
+ /**
16189
+ * Check if module is installed on a specified site.
16190
+ *
16191
+ * @author Vova Feldman (@svovaf)
16192
+ * @since 2.0.0
16193
+ *
16194
+ * @param int|null $blog_id
16195
+ *
16196
+ * @return bool
16197
+ */
16198
+ function is_installed_on_site( $blog_id = null ) {
16199
+ $installs = self::get_all_sites( $this->_module_type, $blog_id );
16200
+ $install = isset( $installs[ $this->_slug ] ) ? $installs[ $this->_slug ] : null;
16201
+
16202
+ return (
16203
+ is_object( $install ) &&
16204
+ is_numeric( $install->id ) &&
16205
+ is_numeric( $install->user_id ) &&
16206
+ FS_Plugin_Plan::is_valid_id( $install->plan_id )
16207
+ );
16208
+ }
16209
+
16210
+ /**
16211
+ * Check if super-admin connected at least one site via the network opt-in.
16212
+ *
16213
+ * @author Vova Feldman (@svovaf)
16214
+ * @since 2.0.0
16215
+ *
16216
+ * @return bool
16217
+ */
16218
+ function is_network_registered() {
16219
+ if ( ! $this->_is_network_active ) {
16220
+ return false;
16221
+ }
16222
+
16223
+ return FS_User::is_valid_id( $this->_storage->network_user_id );
16224
+ }
16225
+
16226
+ /**
16227
+ * Returns the main user associated with the network.
16228
+ *
16229
+ * @author Vova Feldman (@svovaf)
16230
+ * @since 2.0.0
16231
+ *
16232
+ * @return FS_User
16233
+ */
16234
+ function get_network_user() {
16235
+ if ( ! $this->_is_network_active ) {
16236
+ return null;
16237
+ }
16238
+
16239
+ return FS_User::is_valid_id( $this->_storage->network_user_id ) ?
16240
+ self::_get_user_by_id( $this->_storage->network_user_id ) :
16241
+ null;
16242
+ }
16243
+
16244
+ /**
16245
+ * Returns the current context user or the network's main user.
16246
+ *
16247
+ * @author Vova Feldman (@svovaf)
16248
+ * @since 2.0.0
16249
+ *
16250
+ * @return FS_User
16251
+ */
16252
+ function get_current_or_network_user() {
16253
+ return ( $this->_user instanceof FS_User ) ?
16254
+ $this->_user :
16255
+ $this->get_network_user();
16256
+ }
16257
+
16258
+ /**
16259
+ * Returns the main install associated with the network.
16260
+ *
16261
+ * @author Vova Feldman (@svovaf)
16262
+ * @since 2.0.0
16263
+ *
16264
+ * @return FS_Site
16265
+ */
16266
+ function get_network_install() {
16267
+ if ( ! $this->_is_network_active ) {
16268
+ return null;
16269
+ }
16270
+
16271
+ return FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ?
16272
+ $this->get_install_by_blog_id( $this->_storage->network_install_blog_id ) :
16273
+ null;
16274
+ }
16275
+
16276
+ /**
16277
+ * Returns the blog ID that is associated with the main install.
16278
+ *
16279
+ * @author Leo Fajardo (@leorw)
16280
+ * @since 2.0.0
16281
+ *
16282
+ * @return int|null
16283
+ */
16284
+ function get_network_install_blog_id() {
16285
+ if ( ! $this->_is_network_active ) {
16286
+ return null;
16287
+ }
16288
+
16289
+ return FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ?
16290
+ $this->_storage->network_install_blog_id :
16291
+ null;
16292
+ }
16293
+
16294
+ /**
16295
+ * Returns the current context install or the network's main install.
16296
+ *
16297
+ * @author Vova Feldman (@svovaf)
16298
+ * @since 2.0.0
16299
+ *
16300
+ * @return FS_Site
16301
+ */
16302
+ function get_current_or_network_install() {
16303
+ return ( $this->_site instanceof FS_Site ) ?
16304
+ $this->_site :
16305
+ $this->get_network_install();
16306
+ }
16307
+
16308
+ /**
16309
+ * Check if executing a site level action from the network level admin.
16310
+ *
16311
+ * @author Vova Feldman (@svovaf)
16312
+ * @since 2.0.0
16313
+ *
16314
+ * @return false|int If yes, return the requested blog ID.
16315
+ */
16316
+ private function is_network_level_site_specific_action() {
16317
+ if ( ! $this->_is_network_active ) {
16318
+ return false;
16319
+ }
16320
+
16321
+ if ( ! fs_is_network_admin() ) {
16322
+ return false;
16323
+ }
16324
+
16325
+ $blog_id = fs_request_get( 'blog_id', '' );
16326
+
16327
+ return is_numeric( $blog_id ) ? $blog_id : false;
16328
+ }
16329
+
16330
+ /**
16331
+ * Check if executing an action from the network level admin.
16332
+ *
16333
+ * @author Vova Feldman (@svovaf)
16334
+ * @since 2.0.0
16335
+ *
16336
+ * @return bool
16337
+ */
16338
+ private function is_network_level_action() {
16339
+ return ( $this->_is_network_active && fs_is_network_admin() );
16340
+ }
16341
+
16342
+ /**
16343
+ * Needs to be executed after site deactivation, archive, deletion, or flag as spam.
16344
+ * The logic updates the network level user and blog, and reschedule the crons if the cron executing site matching the site that is no longer publicly active.
16345
+ *
16346
+ * @author Vova Feldman (@svovaf)
16347
+ * @since 2.0.0
16348
+ *
16349
+ * @param int $context_blog_id
16350
+ */
16351
+ private function update_multisite_data_after_site_deactivation( $context_blog_id = 0 ) {
16352
+ $this->_logger->entrance();
16353
+
16354
+ if ( $this->_is_network_active ) {
16355
+ if ( $context_blog_id == $this->_storage->network_install_blog_id ) {
16356
+ $installs_map = $this->get_blog_install_map();
16357
+
16358
+ foreach ( $installs_map as $blog_id => $install ) {
16359
+ /**
16360
+ * @var FS_Site $install
16361
+ */
16362
+ if ( $context_blog_id == $blog_id ) {
16363
+ continue;
16364
+ }
16365
+
16366
+ if ( $install->user_id != $this->_storage->network_user_id ) {
16367
+ continue;
16368
+ }
16369
+
16370
+ // Switch reference to a blog that is opted-in and belong to the same super-admin.
16371
+ $this->_storage->network_install_blog_id = $blog_id;
16372
+ break;
16373
+ }
16374
+ }
16375
+ }
16376
+
16377
+ if ( ! $this->is_registered() ) {
16378
+ return;
16379
+ }
16380
+
16381
+ if ( $this->is_sync_cron_scheduled() &&
16382
+ $context_blog_id == $this->get_sync_cron_blog_id()
16383
+ ) {
16384
+ $this->schedule_sync_cron( WP_FS__SCRIPT_START_TIME, true, $context_blog_id );
16385
+ }
16386
+
16387
+ if ( $this->is_install_sync_scheduled() &&
16388
+ $context_blog_id == $this->get_install_sync_cron_blog_id()
16389
+ ) {
16390
+ $this->schedule_install_sync( $context_blog_id );
16391
+ }
16392
+ }
16393
+
16394
+ /**
16395
+ * Executed after site deactivation, archive, or flag as spam.
16396
+ *
16397
+ * @author Vova Feldman (@svovaf)
16398
+ * @since 2.0.0
16399
+ *
16400
+ * @param int $context_blog_id
16401
+ */
16402
+ public function _after_site_deactivated_callback( $context_blog_id = 0 ) {
16403
+ $this->_logger->entrance();
16404
+
16405
+ $install = $this->get_install_by_blog_id( $context_blog_id );
16406
+
16407
+ if ( ! is_object( $install ) ) {
16408
+ // Site not connected.
16409
+ return;
16410
+ }
16411
+
16412
+ $this->update_multisite_data_after_site_deactivation( $context_blog_id );
16413
+
16414
+ if ( ! $this->is_registered() ) {
16415
+ return;
16416
+ }
16417
+
16418
+ $current_blog_id = get_current_blog_id();
16419
+
16420
+ $this->switch_to_blog( $context_blog_id );
16421
+
16422
+ // Send deactivation event.
16423
+ $this->sync_install( array(
16424
+ 'is_active' => false,
16425
+ ) );
16426
+
16427
+ $this->switch_to_blog( $current_blog_id );
16428
+ }
16429
+
16430
+ /**
16431
+ * Executed after site deletion.
16432
+ *
16433
+ * @author Vova Feldman (@svovaf)
16434
+ * @since 2.0.0
16435
+ *
16436
+ * @param int $context_blog_id
16437
+ * @param bool $drop True if site's database tables should be dropped. Default is false.
16438
+ */
16439
+ public function _after_site_deleted_callback( $context_blog_id = 0, $drop = false ) {
16440
+ $this->_logger->entrance();
16441
+
16442
+ $install = $this->get_install_by_blog_id( $context_blog_id );
16443
+
16444
+ if ( ! is_object( $install ) ) {
16445
+ // Site not connected.
16446
+ return;
16447
+ }
16448
+
16449
+ $this->update_multisite_data_after_site_deactivation( $context_blog_id );
16450
+
16451
+ if ( ! $this->is_registered() ) {
16452
+ return;
16453
+ }
16454
+
16455
+ $current_blog_id = get_current_blog_id();
16456
+
16457
+ $this->switch_to_blog( $context_blog_id );
16458
+
16459
+ if ( $drop ) {
16460
+ // Delete install if dropping site DB.
16461
+ $this->delete_account_event();
16462
+ } else {
16463
+ // Send deactivation event.
16464
+ $this->sync_install( array(
16465
+ 'is_active' => false,
16466
+ ) );
16467
+ }
16468
+
16469
+ $this->switch_to_blog( $current_blog_id );
16470
+ }
16471
+
16472
+ /**
16473
+ * Executed after site deletion, called from wp_delete_site
16474
+ *
16475
+ * @author Dario Curvino (@dudo)
16476
+ * @since 2.5.0
16477
+ *
16478
+ * @param WP_Site $old_site
16479
+ */
16480
+ public function _after_wpsite_deleted_callback( WP_Site $old_site ) {
16481
+ $this->_logger->entrance();
16482
+
16483
+ $this->_after_site_deleted_callback( $old_site->blog_id, true );
16484
+ }
16485
+
16486
+ /**
16487
+ * Executed after site re-activation.
16488
+ *
16489
+ * @author Vova Feldman (@svovaf)
16490
+ * @since 2.0.0
16491
+ *
16492
+ * @param int $context_blog_id
16493
+ */
16494
+ public function _after_site_reactivated_callback( $context_blog_id = 0 ) {
16495
+ $this->_logger->entrance();
16496
+
16497
+ $install = $this->get_install_by_blog_id( $context_blog_id );
16498
+
16499
+ if ( ! is_object( $install ) ) {
16500
+ // Site not connected.
16501
+ return;
16502
+ }
16503
+
16504
+ if ( ! self::is_site_active( $context_blog_id ) ) {
16505
+ // Site not yet active (can be in spam mode, archived, deleted...).
16506
+ return;
16507
+ }
16508
+
16509
+ $current_blog_id = get_current_blog_id();
16510
+
16511
+ $this->switch_to_blog( $context_blog_id );
16512
+
16513
+ // Send re-activation event.
16514
+ $this->sync_install( array(
16515
+ 'is_active' => true,
16516
+ ) );
16517
+
16518
+ $this->switch_to_blog( $current_blog_id );
16519
+ }
16520
+
16521
+ #endregion Multisite
16522
+
16523
+ /**
16524
+ * @author Leo Fajardo (@leorw)
16525
+ *
16526
+ * @param string $path
16527
+ * @param string $scheme
16528
+ * @param bool $network
16529
+ *
16530
+ * @return string
16531
+ */
16532
+ private function admin_url( $path = '', $scheme = 'admin', $network = true ) {
16533
+ return ( $this->_is_network_active && $network ) ?
16534
+ network_admin_url( $path, $scheme ) :
16535
+ admin_url( $path, $scheme );
16536
+ }
16537
+
16538
+ /**
16539
+ * Check if currently in a specified admin page.
16540
+ *
16541
+ * @author Vova Feldman (@svovaf)
16542
+ * @since 1.2.2.7
16543
+ *
16544
+ * @param string $page
16545
+ *
16546
+ * @return bool
16547
+ */
16548
+ function is_admin_page( $page ) {
16549
+ return ( $this->_menu->get_slug( $page ) === fs_request_get( 'page', '', 'get' ) );
16550
+ }
16551
+
16552
+ /**
16553
+ * Check if currently in the product's main admin page.
16554
+ *
16555
+ * @author Vova Feldman (@svovaf)
16556
+ * @since 2.3.1
16557
+ *
16558
+ * @return bool
16559
+ */
16560
+ function is_main_admin_page() {
16561
+ return $this->is_admin_page( '' );
16562
+ }
16563
+
16564
+ /**
16565
+ * Get module's main admin setting page URL.
16566
+ *
16567
+ * @author Vova Feldman (@svovaf)
16568
+ * @since 1.2.2.7
16569
+ *
16570
+ * @return string
16571
+ */
16572
+ function main_menu_url() {
16573
+ return $this->_menu->main_menu_url();
16574
+ }
16575
+
16576
+ /**
16577
+ * Check if currently on the theme's setting page or
16578
+ * on any of the Freemius added pages (via tabs).
16579
+ *
16580
+ * @author Vova Feldman (@svovaf)
16581
+ * @since 1.2.2.7
16582
+ *
16583
+ * @return bool
16584
+ *
16585
+ * @deprecated Please use is_product_settings_page() instead;
16586
+ */
16587
+ function is_theme_settings_page() {
16588
+ return $this->is_product_settings_page();
16589
+ }
16590
+
16591
+ /**
16592
+ * Check if currently on the product's main setting page or on any of the Freemius added pages (via tabs).
16593
+ *
16594
+ * @author Vova Feldman (@svovaf)
16595
+ * @since 1.2.2.7
16596
+ *
16597
+ * @return bool
16598
+ */
16599
+ function is_product_settings_page() {
16600
+ $page = fs_request_get( 'page', '', 'get' );
16601
+ $menu_slug = $this->_menu->get_slug();
16602
+
16603
+ if ( $page === $menu_slug ) {
16604
+ return true;
16605
+ }
16606
+
16607
+ return fs_starts_with(
16608
+ // e.g., {$menu_slug}-account, {$menu_slug}-affiliation, etc.
16609
+ $page,
16610
+ ( $menu_slug . '-' )
16611
+ );
16612
+ }
16613
+
16614
+ /**
16615
+ * Plugin's account page + sync license URL.
16616
+ *
16617
+ * @author Vova Feldman (@svovaf)
16618
+ * @since 1.1.9.1
16619
+ *
16620
+ * @param bool|number $plugin_id
16621
+ * @param bool $add_action_nonce
16622
+ * @param array $params
16623
+ *
16624
+ * @return string
16625
+ */
16626
+ function _get_sync_license_url( $plugin_id = false, $add_action_nonce = true, $params = array() ) {
16627
+ if ( is_numeric( $plugin_id ) ) {
16628
+ $params['plugin_id'] = $plugin_id;
16629
+ }
16630
+
16631
+ return $this->get_account_url(
16632
+ $this->get_unique_affix() . '_sync_license',
16633
+ $params,
16634
+ $add_action_nonce
16635
+ );
16636
+ }
16637
+
16638
+ /**
16639
+ * Plugin's account URL.
16640
+ *
16641
+ * @author Vova Feldman (@svovaf)
16642
+ * @since 1.0.4
16643
+ *
16644
+ * @param bool|string $action
16645
+ * @param array $params
16646
+ *
16647
+ * @param bool $add_action_nonce
16648
+ *
16649
+ * @return string
16650
+ */
16651
+ function get_account_url( $action = false, $params = array(), $add_action_nonce = true ) {
16652
+ if ( is_string( $action ) ) {
16653
+ $params['fs_action'] = $action;
16654
+ }
16655
+
16656
+ self::require_pluggable_essentials();
16657
+
16658
+ return ( $add_action_nonce && is_string( $action ) ) ?
16659
+ fs_nonce_url( $this->_get_admin_page_url( 'account', $params ), $action ) :
16660
+ $this->_get_admin_page_url( 'account', $params );
16661
+ }
16662
+
16663
+ /**
16664
+ * @author Vova Feldman (@svovaf)
16665
+ * @since 1.2.0
16666
+ *
16667
+ * @param string $tab
16668
+ * @param bool $action
16669
+ * @param array $params
16670
+ * @param bool $add_action_nonce
16671
+ *
16672
+ * @return string
16673
+ *
16674
+ * @uses get_account_url()
16675
+ */
16676
+ function get_account_tab_url( $tab, $action = false, $params = array(), $add_action_nonce = true ) {
16677
+ $params['tab'] = $tab;
16678
+
16679
+ return $this->get_account_url( $action, $params, $add_action_nonce );
16680
+ }
16681
+
16682
+ /**
16683
+ * Plugin's account URL.
16684
+ *
16685
+ * @author Vova Feldman (@svovaf)
16686
+ * @since 1.0.4
16687
+ *
16688
+ * @param bool|string $topic
16689
+ * @param bool|string $message
16690
+ * @param bool|string $summary Since 2.5.1.
16691
+ *
16692
+ * @return string
16693
+ */
16694
+ function contact_url( $topic = false, $message = false, $summary = false ) {
16695
+ $params = array();
16696
+ if ( is_string( $topic ) ) {
16697
+ $params['topic'] = $topic;
16698
+ }
16699
+ if ( is_string( $message ) ) {
16700
+ $params['message'] = $message;
16701
+ }
16702
+
16703
+ if ( is_string( $summary ) ) {
16704
+ $params['summary'] = $summary;
16705
+ }
16706
+
16707
+ if ( $this->is_addon() ) {
16708
+ $params['addon_id'] = $this->get_id();
16709
+
16710
+ return $this->get_parent_instance()->_get_admin_page_url( 'contact', $params );
16711
+ } else {
16712
+ return $this->_get_admin_page_url( 'contact', $params );
16713
+ }
16714
+ }
16715
+
16716
+ /**
16717
+ * Add-on direct info URL.
16718
+ *
16719
+ * @author Vova Feldman (@svovaf)
16720
+ * @since 1.1.0
16721
+ *
16722
+ * @param string $slug
16723
+ *
16724
+ * @return string
16725
+ */
16726
+ function addon_url( $slug ) {
16727
+ return $this->_get_admin_page_url( 'addons', array(
16728
+ 'slug' => $slug
16729
+ ) );
16730
+ }
16731
+
16732
+ /**
16733
+ * Add-ons URL.
16734
+ *
16735
+ * @author Vova Feldman (@svovaf)
16736
+ * @since 2.4.5
16737
+ *
16738
+ * @return string
16739
+ */
16740
+ function get_addons_url() {
16741
+ return $this->_get_admin_page_url( 'addons' );
16742
+ }
16743
+
16744
+ /* Logger
16745
+ ------------------------------------------------------------------------------------------------------------------*/
16746
+ /**
16747
+ * @param string $id
16748
+ * @param bool $prefix_slug
16749
+ *
16750
+ * @return FS_Logger
16751
+ */
16752
+ function get_logger( $id = '', $prefix_slug = true ) {
16753
+ return FS_Logger::get_logger( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id );
16754
+ }
16755
+
16756
+ /**
16757
+ * Note: This method is used externally so don't delete it.
16758
+ *
16759
+ * @param $id
16760
+ * @param bool $load_options
16761
+ * @param bool $prefix_slug
16762
+ *
16763
+ * @return FS_Option_Manager
16764
+ */
16765
+ function get_options_manager( $id, $load_options = false, $prefix_slug = true ) {
16766
+ return FS_Option_Manager::get_manager( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id, $load_options );
16767
+ }
16768
+
16769
+ /* Security
16770
+ ------------------------------------------------------------------------------------------------------------------*/
16771
+ private static function _encrypt( $str ) {
16772
+ if ( is_null( $str ) ) {
16773
+ return null;
16774
+ }
16775
+
16776
+ /**
16777
+ * The encrypt/decrypt functions are used to protect
16778
+ * the user from messing up with some of the sensitive
16779
+ * data stored for the module as a JSON in the database.
16780
+ *
16781
+ * I used the same suggested hack by the theme review team.
16782
+ * For more details, look at the function `Base64UrlDecode()`
16783
+ * in `./sdk/FreemiusBase.php`.
16784
+ *
16785
+ * @todo Remove this hack once the base64 error is removed from the Theme Check.
16786
+ *
16787
+ * @author Vova Feldman (@svovaf)
16788
+ * @since 1.2.2
16789
+ */
16790
+ $fn = 'base64' . '_encode';
16791
+
16792
+ return $fn( $str );
16793
+ }
16794
+
16795
+ static function _decrypt( $str ) {
16796
+ if ( is_null( $str ) ) {
16797
+ return null;
16798
+ }
16799
+
16800
+ /**
16801
+ * The encrypt/decrypt functions are used to protect
16802
+ * the user from messing up with some of the sensitive
16803
+ * data stored for the module as a JSON in the database.
16804
+ *
16805
+ * I used the same suggested hack by the theme review team.
16806
+ * For more details, look at the function `Base64UrlDecode()`
16807
+ * in `./sdk/FreemiusBase.php`.
16808
+ *
16809
+ * @todo Remove this hack once the base64 error is removed from the Theme Check.
16810
+ *
16811
+ * @author Vova Feldman (@svovaf)
16812
+ * @since 1.2.2
16813
+ */
16814
+ $fn = 'base64' . '_decode';
16815
+
16816
+ return $fn( $str );
16817
+ }
16818
+
16819
+ /**
16820
+ * @author Vova Feldman (@svovaf)
16821
+ * @since 1.0.5
16822
+ *
16823
+ * @param FS_Entity $entity
16824
+ *
16825
+ * @return FS_Entity Return an encrypted clone entity.
16826
+ */
16827
+ private static function _encrypt_entity( FS_Entity $entity ) {
16828
+ $clone = clone $entity;
16829
+ $props = get_object_vars( $entity );
16830
+
16831
+ foreach ( $props as $key => $val ) {
16832
+ $clone->{$key} = self::_encrypt( $val );
16833
+ }
16834
+
16835
+ return $clone;
16836
+ }
16837
+
16838
+ /**
16839
+ * @author Vova Feldman (@svovaf)
16840
+ * @since 1.0.5
16841
+ *
16842
+ * @param FS_Entity $entity
16843
+ *
16844
+ * @return FS_Entity Return an decrypted clone entity.
16845
+ */
16846
+ private static function decrypt_entity( FS_Entity $entity ) {
16847
+ $clone = clone $entity;
16848
+ $props = get_object_vars( $entity );
16849
+
16850
+ foreach ( $props as $key => $val ) {
16851
+ $clone->{$key} = self::_decrypt( $val );
16852
+ }
16853
+
16854
+ return $clone;
16855
+ }
16856
+
16857
+ /**
16858
+ * Tries to activate account based on POST params.
16859
+ *
16860
+ * @author Vova Feldman (@svovaf)
16861
+ * @since 1.0.2
16862
+ *
16863
+ * @deprecated Not in use, outdated.
16864
+ */
16865
+ function _activate_account() {
16866
+ if ( $this->is_registered() ) {
16867
+ // Already activated.
16868
+ return;
16869
+ }
16870
+
16871
+ self::_clean_admin_content_section();
16872
+
16873
+ if ( fs_request_is_action( 'activate' ) && fs_request_is_post() ) {
16874
+ // check_admin_referer( 'activate_' . $this->_plugin->public_key );
16875
+
16876
+ // Verify matching plugin details.
16877
+ if ( $this->_plugin->id != fs_request_get( 'plugin_id' ) || $this->_slug != fs_request_get( 'plugin_slug' ) ) {
16878
+ return;
16879
+ }
16880
+
16881
+ $user = new FS_User();
16882
+ $user->id = fs_request_get( 'user_id' );
16883
+ $user->public_key = fs_request_get( 'user_public_key' );
16884
+ $user->secret_key = fs_request_get( 'user_secret_key' );
16885
+ $user->email = fs_request_get( 'user_email' );
16886
+ $user->first = fs_request_get( 'user_first' );
16887
+ $user->last = fs_request_get( 'user_last' );
16888
+ $user->is_verified = fs_request_get_bool( 'user_is_verified' );
16889
+
16890
+ $site = new FS_Site();
16891
+ $site->id = fs_request_get( 'install_id' );
16892
+ $site->public_key = fs_request_get( 'install_public_key' );
16893
+ $site->secret_key = fs_request_get( 'install_secret_key' );
16894
+ $site->plan_id = fs_request_get( 'plan_id' );
16895
+
16896
+ $plans = array();
16897
+ $plans_data = json_decode( urldecode( fs_request_get( 'plans' ) ) );
16898
+ foreach ( $plans_data as $p ) {
16899
+ $plan = new FS_Plugin_Plan( $p );
16900
+ if ( $site->plan_id == $plan->id ) {
16901
+ $plan->title = fs_request_get( 'plan_title' );
16902
+ $plan->name = fs_request_get( 'plan_name' );
16903
+ }
16904
+
16905
+ $plans[] = $plan;
16906
+ }
16907
+
16908
+ $this->_set_account( $user, $site, $plans );
16909
+
16910
+ // Reload the page with the keys.
16911
+ fs_redirect( $this->_get_admin_page_url() );
16912
+ }
16913
+ }
16914
+
16915
+ /**
16916
+ * @author Vova Feldman (@svovaf)
16917
+ * @since 1.0.7
16918
+ *
16919
+ * @param string $email
16920
+ *
16921
+ * @return FS_User|false
16922
+ */
16923
+ static function _get_user_by_email( $email ) {
16924
+ self::$_static_logger->entrance();
16925
+
16926
+ $email = trim( strtolower( $email ) );
16927
+
16928
+ $users = self::get_all_users();
16929
+
16930
+ if ( is_array( $users ) ) {
16931
+ foreach ( $users as $user ) {
16932
+ if ( $email === trim( strtolower( $user->email ) ) ) {
16933
+ return $user;
16934
+ }
16935
+ }
16936
+ }
16937
+
16938
+ return false;
16939
+ }
16940
+
16941
+ #----------------------------------------------------------------------------------
16942
+ #region Account (Loading, Updates & Activation)
16943
+ #----------------------------------------------------------------------------------
16944
+
16945
+ /***
16946
+ * Load account information (user + site).
16947
+ *
16948
+ * @author Vova Feldman (@svovaf)
16949
+ * @since 1.0.1
16950
+ */
16951
+ private function _load_account() {
16952
+ $this->_logger->entrance();
16953
+
16954
+ $this->do_action( 'before_account_load' );
16955
+
16956
+ $users = self::get_all_users();
16957
+ $plans = self::get_all_plans( $this->_module_type );
16958
+
16959
+ if ( $this->_logger->is_on() && is_admin() ) {
16960
+ $this->_logger->log( 'users = ' . var_export( $users, true ) );
16961
+ $this->_logger->log( 'plans = ' . var_export( $plans, true ) );
16962
+ }
16963
+
16964
+ $site = fs_is_network_admin() ?
16965
+ $this->get_network_install() :
16966
+ $this->get_install_by_blog_id();
16967
+
16968
+ if ( fs_is_network_admin() &&
16969
+ $this->is_network_active() &&
16970
+ ! is_object( $site ) &&
16971
+ FS_Site::is_valid_id( $this->_storage->network_install_blog_id )
16972
+ ) {
16973
+ $first_install = $this->find_first_install();
16974
+
16975
+ if ( is_null( $first_install ) ) {
16976
+ unset( $this->_storage->network_install_blog_id );
16977
+ } else {
16978
+ $site = $first_install['install'];
16979
+ $this->_storage->network_install_blog_id = $first_install['blog_id'];
16980
+ }
16981
+ }
16982
+
16983
+ if ( is_object( $site ) &&
16984
+ is_numeric( $site->id ) &&
16985
+ is_numeric( $site->user_id ) &&
16986
+ FS_Plugin_Plan::is_valid_id( $site->plan_id )
16987
+ ) {
16988
+ // Load site.
16989
+ $this->_site = $site;
16990
+ }
16991
+
16992
+ $user = null;
16993
+ if ( fs_is_network_admin() && $this->_is_network_active ) {
16994
+ $user = $this->get_network_user();
16995
+ }
16996
+
16997
+ if ( is_object( $user ) ) {
16998
+ $this->_user = clone $user;
16999
+ } else if ( $this->_site ) {
17000
+ $user = self::_get_user_by_id( $this->_site->user_id );
17001
+
17002
+ if ( ! is_object( $user ) && FS_User::is_valid_id( $this->_storage->prev_user_id ) ) {
17003
+ /**
17004
+ * Try to load the previous owner. This recovery is used for the following use-case:
17005
+ * 1. Opt-in
17006
+ * 2. Cloning site1 to site2
17007
+ * 3. Ownership switch in site1 (same applies for site2)
17008
+ * 4. Install data sync on site2
17009
+ * 5. Now site2's install is associated with the new owner which does not exists locally.
17010
+ */
17011
+ $user = self::_get_user_by_id( $this->_storage->prev_user_id );
17012
+ }
17013
+
17014
+ if ( ! is_object( $user ) ) {
17015
+ /**
17016
+ * This is a special fault tolerance mechanism to handle a scenario that the user data is missing.
17017
+ */
17018
+ if (
17019
+ ! isset( $this->_storage->user_recovery_from_install_last_attempt_timestamp ) ||
17020
+ time() > ( $this->_storage->user_recovery_from_install_last_attempt_timestamp + FS_Clone_Manager::CLONE_RESOLUTION_MAX_EXECUTION_TIME )
17021
+ ) {
17022
+ $user = $this->sync_user_by_current_install();
17023
+ } else {
17024
+ return;
17025
+ }
17026
+
17027
+ if ( is_object( $user ) ) {
17028
+ $this->_storage->user_was_recovered_from_install = true;
17029
+ } else {
17030
+ $this->_storage->user_recovery_from_install_attempts = isset( $this->_storage->user_recovery_from_install_attempts ) ?
17031
+ ( $this->_storage->user_recovery_from_install_attempts + 1 ) :
17032
+ 1;
17033
+
17034
+ if ( $this->_storage->user_recovery_from_install_attempts >= 3 ) {
17035
+ $this->delete_current_install( false );
17036
+ } else {
17037
+ $this->_storage->user_recovery_from_install_last_attempt_timestamp = time();
17038
+
17039
+ return;
17040
+ }
17041
+ }
17042
+ }
17043
+
17044
+ $this->_user = ( $user instanceof FS_User ) ?
17045
+ clone $user :
17046
+ null;
17047
+ }
17048
+
17049
+ if ( is_object( $this->_user ) ) {
17050
+ // Load licenses.
17051
+ $this->_licenses = $this->get_user_licenses( $this->_user->id );
17052
+ }
17053
+
17054
+ if ( is_object( $this->_site ) ) {
17055
+ // Load plans.
17056
+ $this->_plans = isset( $plans[ $this->_slug ] ) ?
17057
+ $plans[ $this->_slug ] :
17058
+ array();
17059
+
17060
+ if ( ! is_array( $this->_plans ) || empty( $this->_plans ) ) {
17061
+ $this->_sync_plans();
17062
+ } else {
17063
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
17064
+ if ( $this->_plans[ $i ] instanceof FS_Plugin_Plan ) {
17065
+ $this->_plans[ $i ] = self::decrypt_entity( $this->_plans[ $i ] );
17066
+ } else {
17067
+ unset( $this->_plans[ $i ] );
17068
+ }
17069
+ }
17070
+ }
17071
+
17072
+ $this->_license = $this->_get_license_by_id( $this->_site->license_id );
17073
+
17074
+ if ( $this->_site->version != $this->get_plugin_version() ) {
17075
+ // If stored install version is different than current installed plugin version,
17076
+ // then update plugin version event.
17077
+ $this->update_plugin_version_event();
17078
+ }
17079
+ }
17080
+
17081
+ if ( true === $this->_storage->require_license_activation &&
17082
+ ! fs_request_get_bool( 'require_license', true )
17083
+ ) {
17084
+ $this->_storage->require_license_activation = false;
17085
+ }
17086
+
17087
+ if ( $this->is_theme() ) {
17088
+ $this->_register_account_hooks();
17089
+ }
17090
+
17091
+ if (
17092
+ $this->is_user_in_admin() &&
17093
+ $this->is_clone() &&
17094
+ empty( FS_Clone_Manager::instance()->get_clone_identification_timestamp() )
17095
+ ) {
17096
+ FS_Clone_Manager::instance()->store_clone_identification_timestamp();
17097
+ }
17098
+ }
17099
+
17100
+ /**
17101
+ * Special user recovery mechanism.
17102
+ *
17103
+ * @author Vova Feldman (@svovaf)
17104
+ * @since 2.0.0
17105
+ *
17106
+ * @param number|null $site_user_id
17107
+ *
17108
+ * @return \FS_User|mixed
17109
+ */
17110
+ private function sync_user_by_current_install( $site_user_id = null ) {
17111
+ $site_user_id = FS_Site::is_valid_id( $site_user_id ) ?
17112
+ $site_user_id :
17113
+ $this->_site->user_id;
17114
+
17115
+ $api = $this->get_api_site_scope();
17116
+
17117
+ $uid = $this->get_anonymous_id();
17118
+ $request_path = "/users/{$site_user_id}.json?uid={$uid}";
17119
+
17120
+ $result = $api->get( $request_path, false, WP_FS__TIME_10_MIN_IN_SEC );
17121
+
17122
+ if ( $this->is_api_result_entity( $result ) ) {
17123
+ $user = new FS_User( $result );
17124
+ $this->_user = $user;
17125
+ $this->_store_user();
17126
+
17127
+ return $user;
17128
+ }
17129
+
17130
+ $error_code = FS_Api::get_error_code( $result );
17131
+
17132
+ if ( in_array( $error_code, array( 'invalid_unique_id', 'user_cannot_be_recovered' ) ) ) {
17133
+ /**
17134
+ * Those API errors will continue coming and are not recoverable with the
17135
+ * current site's data. Therefore, extend the API call's cached result to 7 days.
17136
+ */
17137
+ $api->update_cache_expiration( $request_path, WP_FS__TIME_WEEK_IN_SEC );
17138
+ }
17139
+
17140
+ return $result;
17141
+ }
17142
+
17143
+ /**
17144
+ * @author Vova Feldman (@svovaf)
17145
+ * @since 1.0.1
17146
+ *
17147
+ * @param FS_User $user
17148
+ * @param FS_Site $site
17149
+ * @param bool|array $plans
17150
+ */
17151
+ private function _set_account( FS_User $user, FS_Site $site, $plans = false ) {
17152
+ $site->user_id = $user->id;
17153
+
17154
+ $this->_site = $site;
17155
+ $this->_user = $user;
17156
+ if ( false !== $plans ) {
17157
+ $this->_plans = $plans;
17158
+ }
17159
+
17160
+ $this->send_install_update();
17161
+
17162
+ $this->_store_account();
17163
+
17164
+ }
17165
+
17166
+ /**
17167
+ * Get a sanitized array with the WordPress version, SDK version, and PHP version.
17168
+ * Each version is trimmed after the 16th char.
17169
+ *
17170
+ * @author Vova Feldman (@svovaf)
17171
+ * @since 2.2.1
17172
+ *
17173
+ * @return array
17174
+ */
17175
+ private function get_versions() {
17176
+ $versions = array();
17177
+ $versions['sdk_version'] = $this->version;
17178
+
17179
+ // Collect these diagnostic information only if it's allowed.
17180
+ if ( FS_Permission_Manager::instance( $this )->is_diagnostic_tracking_allowed() ) {
17181
+ $versions['platform_version'] = get_bloginfo( 'version' );
17182
+ $versions['programming_language_version'] = phpversion();
17183
+ }
17184
+
17185
+ foreach ( $versions as $k => $version ) {
17186
+ $versions[ $k ] = self::get_api_sanitized_property( $k, $version );
17187
+ }
17188
+
17189
+ return $versions;
17190
+ }
17191
+
17192
+ /**
17193
+ * Get sanitized site language.
17194
+ *
17195
+ * @param string $language
17196
+ * @param int $max_len
17197
+ *
17198
+ * @since 2.5.1
17199
+ * @author Vova Feldman (@svovaf)
17200
+ *
17201
+ * @return string
17202
+ */
17203
+ private static function get_sanitized_language( $language = '', $max_len = self::LANGUAGE_MAX_CHARS ) {
17204
+ if ( empty( $language ) ) {
17205
+ $language = get_bloginfo( 'language' );
17206
+ }
17207
+
17208
+ return substr( $language, 0, $max_len );
17209
+ }
17210
+
17211
+ /**
17212
+ * Get core version stripped from pre-release and build.
17213
+ *
17214
+ * @since 2.5.1
17215
+ * @author Vova Feldman (@svovaf)
17216
+ *
17217
+ * @param string $version
17218
+ * @param int $parts
17219
+ * @param int $max_len
17220
+ * @param bool $include_pre_release
17221
+ *
17222
+ * @return string
17223
+ */
17224
+ private static function get_core_version(
17225
+ $version,
17226
+ $parts = 3,
17227
+ $max_len = self::VERSION_MAX_CHARS,
17228
+ $include_pre_release = false
17229
+ ) {
17230
+ if ( empty( $version ) ) {
17231
+ // Version is empty.
17232
+ return '';
17233
+ }
17234
+
17235
+ if ( is_numeric( $version ) ) {
17236
+ $is_float_version = is_float( $version );
17237
+
17238
+ $version = (string) $version;
17239
+
17240
+ /**
17241
+ * Casting a whole float number to a string cuts the decimal point. This part make sure to add the missing decimal part to the version.
17242
+ */
17243
+ if ( $is_float_version && false === strpos( $version, '.' ) ) {
17244
+ $version .= '.0';
17245
+ }
17246
+ }
17247
+
17248
+ if ( ! is_string( $version ) ) {
17249
+ return '';
17250
+ }
17251
+
17252
+ if ( $parts < 1 ) {
17253
+ return '';
17254
+ }
17255
+
17256
+ $pre_release_regex = $include_pre_release ?
17257
+ '(\-(alpha|beta|RC)([0-9]+)?)?' :
17258
+ '';
17259
+
17260
+ if ( 0 === preg_match( '/^([0-9]+(\.[0-9]+){0,' . ( $parts - 1 ) . '}' . $pre_release_regex . ')/i', $version, $matches ) ) {
17261
+ // Version is not starting with a digit.
17262
+ return '';
17263
+ }
17264
+
17265
+ return substr( $matches[1], 0, $max_len );
17266
+ }
17267
+
17268
+ /**
17269
+ * @param string $prop
17270
+ * @param mixed $val
17271
+ *
17272
+ * @return mixed
17273
+ *@author Vova Feldman (@svovaf)
17274
+ *
17275
+ * @since 2.5.1
17276
+ */
17277
+ private static function get_api_sanitized_property( $prop, $val ) {
17278
+ if ( ! is_string( $val ) || empty( $val ) ) {
17279
+ return $val;
17280
+ }
17281
+
17282
+ switch ( $prop ) {
17283
+ case 'programming_language_version':
17284
+ // Get core PHP version, which can have up to 3 parts (ignore pre-releases).
17285
+ return self::get_core_version( $val );
17286
+ case 'platform_version':
17287
+ // Get the exact WordPress version, which can have up to 3 parts (including pre-releases).
17288
+ return self::get_core_version( $val, 3, self::VERSION_MAX_CHARS, true );
17289
+ case 'sdk_version':
17290
+ // Get the exact SDK version, which can have up to 4 parts.
17291
+ return self::get_core_version( $val, 4 );
17292
+ case 'version':
17293
+ // Get the entire version but just limited in length.
17294
+ return substr( $val, 0, self::VERSION_MAX_CHARS );
17295
+ case 'language':
17296
+ return self::get_sanitized_language( $val );
17297
+ default:
17298
+ return $val;
17299
+ }
17300
+ }
17301
+
17302
+ /**
17303
+ * @author Leo Fajardo (@leorw)
17304
+ * @since 2.3.0
17305
+ *
17306
+ * @return bool
17307
+ */
17308
+ function has_beta_update() {
17309
+ return (
17310
+ ! empty( $this->_storage->beta_data ) &&
17311
+ ( true === $this->_storage->beta_data['is_beta'] ) &&
17312
+ version_compare( $this->_storage->beta_data['version'], $this->get_plugin_version(), '>' )
17313
+ );
17314
+ }
17315
+
17316
+ /**
17317
+ * @author Leo Fajardo (@leorw)
17318
+ * @since 2.3.0
17319
+ *
17320
+ * @return bool
17321
+ */
17322
+ function is_beta() {
17323
+ return (
17324
+ ! empty( $this->_storage->beta_data ) &&
17325
+ ( true === $this->_storage->beta_data['is_beta'] ) &&
17326
+ ( $this->get_plugin_version() === $this->_storage->beta_data['version'] )
17327
+ );
17328
+ }
17329
+
17330
+ /**
17331
+ * @author Vova Feldman (@svovaf)
17332
+ * @since 1.1.7.4
17333
+ *
17334
+ * @param array $override_with
17335
+ * @param bool|int|null $network_level_or_blog_id If true, return params for network level opt-in. If integer, get params for specified blog in the network.
17336
+ *
17337
+ * @return array
17338
+ */
17339
+ function get_opt_in_params( $override_with = array(), $network_level_or_blog_id = null ) {
17340
+ $this->_logger->entrance();
17341
+
17342
+ $current_user = self::_get_current_wp_user();
17343
+
17344
+ $activation_action = $this->get_unique_affix() . '_activate_new';
17345
+ $return_url = $this->is_anonymous() ?
17346
+ // If skipped already, then return to the account page.
17347
+ $this->get_account_url( $activation_action, array(), false ) :
17348
+ // Return to the module's main page.
17349
+ $this->get_after_activation_url( 'after_connect_url', array( 'fs_action' => $activation_action ) );
17350
+
17351
+ $versions = $this->get_versions();
17352
+
17353
+ $params = array_merge( $versions, array(
17354
+ 'user_firstname' => $current_user->user_firstname,
17355
+ 'user_lastname' => $current_user->user_lastname,
17356
+ 'user_email' => $current_user->user_email,
17357
+ 'plugin_slug' => $this->_slug,
17358
+ 'plugin_id' => $this->get_id(),
17359
+ 'plugin_public_key' => $this->get_public_key(),
17360
+ 'plugin_version' => $this->get_plugin_version(),
17361
+ 'return_url' => fs_nonce_url( $return_url, $activation_action ),
17362
+ 'account_url' => fs_nonce_url( $this->_get_admin_page_url(
17363
+ 'account',
17364
+ array( 'fs_action' => 'sync_user' )
17365
+ ), 'sync_user' ),
17366
+ 'is_premium' => $this->is_premium(),
17367
+ 'is_active' => true,
17368
+ 'is_uninstalled' => false,
17369
+ 'is_localhost' => WP_FS__IS_LOCALHOST,
17370
+ ) );
17371
+
17372
+ if ( $this->is_addon() ) {
17373
+ $parent_fs = $this->get_parent_instance();
17374
+
17375
+ $params['parent_plugin_slug'] = $parent_fs->_slug;
17376
+ $params['parent_plugin_id'] = $parent_fs->get_id();
17377
+ }
17378
+
17379
+ if ( true === $network_level_or_blog_id ) {
17380
+ if ( ! isset( $override_with['sites'] ) ) {
17381
+ $params['sites'] = $this->get_sites_for_network_level_optin();
17382
+ }
17383
+ } else {
17384
+ $site = is_numeric( $network_level_or_blog_id ) ?
17385
+ array( 'blog_id' => $network_level_or_blog_id ) :
17386
+ null;
17387
+
17388
+ $site = $this->get_site_info( $site );
17389
+
17390
+ $diagnostic_info = array();
17391
+ if ( FS_Permission_Manager::instance( $this )->is_diagnostic_tracking_allowed() ) {
17392
+ $diagnostic_info = array(
17393
+ 'site_name' => $site['title'],
17394
+ 'language' => self::get_sanitized_language( $site['language'] ),
17395
+ );
17396
+ }
17397
+
17398
+ $params = array_merge( $params, $diagnostic_info, array(
17399
+ 'site_uid' => $site['uid'],
17400
+ 'site_url' => $site['url'],
17401
+ ) );
17402
+ }
17403
+
17404
+ if ( $this->is_pending_activation() &&
17405
+ ! empty( $this->_storage->pending_license_key )
17406
+ ) {
17407
+ $params['license_key'] = $this->_storage->pending_license_key;
17408
+ }
17409
+
17410
+ if ( WP_FS__SKIP_EMAIL_ACTIVATION && $this->has_secret_key() ) {
17411
+ // Even though rand() is known for its security issues,
17412
+ // the timestamp adds another layer of protection.
17413
+ // It would be very hard for an attacker to get the secret key form here.
17414
+ // Plus, this should never run in production since the secret should never
17415
+ // be included in the production version.
17416
+ $params['ts'] = WP_FS__SCRIPT_START_TIME;
17417
+ $params['salt'] = md5( uniqid( rand() ) );
17418
+ $params['secure'] = md5(
17419
+ $params['ts'] .
17420
+ $params['salt'] .
17421
+ $this->get_secret_key()
17422
+ );
17423
+ }
17424
+
17425
+ if ( is_multisite() && function_exists( 'get_network' ) ) {
17426
+ $params['network_uid'] = $this->get_anonymous_network_id();
17427
+ }
17428
+
17429
+ return array_merge( $params, $override_with );
17430
+ }
17431
+
17432
+ /**
17433
+ * 1. If successful opt-in or pending activation returns the next page that the user should be redirected to.
17434
+ * 2. If there was an API error, return the API result.
17435
+ *
17436
+ * @author Vova Feldman (@svovaf)
17437
+ * @since 1.1.7.4
17438
+ *
17439
+ * @param string|bool $email
17440
+ * @param string|bool $first
17441
+ * @param string|bool $last
17442
+ * @param string|bool $license_key
17443
+ * @param bool $is_uninstall If "true", this means that the module is currently being uninstalled.
17444
+ * In this case, the user and site info will be sent to the server but no
17445
+ * data will be saved to the WP installation's database.
17446
+ * @param number|bool $trial_plan_id
17447
+ * @param bool $is_disconnected Whether to opt in without tracking.
17448
+ * @param null|bool $is_marketing_allowed
17449
+ * @param array $sites If network-level opt-in, an array of containing details of sites.
17450
+ * @param bool $redirect
17451
+ *
17452
+ * @return string|object
17453
+ * @use WP_Error
17454
+ */
17455
+ function opt_in(
17456
+ $email = false,
17457
+ $first = false,
17458
+ $last = false,
17459
+ $license_key = false,
17460
+ $is_uninstall = false,
17461
+ $trial_plan_id = false,
17462
+ $is_disconnected = false,
17463
+ $is_marketing_allowed = null,
17464
+ $sites = array(),
17465
+ $redirect = true
17466
+ ) {
17467
+ $this->_logger->entrance();
17468
+
17469
+ if ( false === $email ) {
17470
+ $current_user = self::_get_current_wp_user();
17471
+ $email = $current_user->user_email;
17472
+ }
17473
+
17474
+ /**
17475
+ * @since 1.2.1 If activating with license key, ignore the context-user
17476
+ * since the user will be automatically loaded from the license.
17477
+ */
17478
+ if ( empty( $license_key ) ) {
17479
+ // Clean up pending license if opt-ing in again.
17480
+ $this->_storage->remove( 'pending_license_key' );
17481
+
17482
+ if ( ! $is_uninstall ) {
17483
+ $fs_user = Freemius::_get_user_by_email( $email );
17484
+ if ( is_object( $fs_user ) && ! $this->is_pending_activation() ) {
17485
+ return $this->install_with_user(
17486
+ $fs_user,
17487
+ false,
17488
+ $trial_plan_id,
17489
+ $redirect,
17490
+ true,
17491
+ $sites
17492
+ );
17493
+ }
17494
+ }
17495
+ }
17496
+
17497
+ $user_info = array();
17498
+ if ( ! empty( $email ) ) {
17499
+ $user_info['user_email'] = $email;
17500
+ }
17501
+ if ( ! empty( $first ) ) {
17502
+ $user_info['user_firstname'] = $first;
17503
+ }
17504
+ if ( ! empty( $last ) ) {
17505
+ $user_info['user_lastname'] = $last;
17506
+ }
17507
+
17508
+ if ( ! empty( $sites ) ) {
17509
+ $is_network = true;
17510
+
17511
+ $user_info['sites'] = $sites;
17512
+ } else {
17513
+ $is_network = false;
17514
+ }
17515
+
17516
+ $params = $this->get_opt_in_params( $user_info, $is_network );
17517
+
17518
+ $filtered_license_key = false;
17519
+ if ( is_string( $license_key ) ) {
17520
+ $filtered_license_key = $this->apply_filters( 'license_key', $license_key );
17521
+ $params['license_key'] = $filtered_license_key;
17522
+ } else if ( FS_Plugin_Plan::is_valid_id( $trial_plan_id ) ) {
17523
+ $params['trial_plan_id'] = $trial_plan_id;
17524
+ }
17525
+
17526
+ if ( $is_uninstall ) {
17527
+ $params['uninstall_params'] = array(
17528
+ 'reason_id' => $this->_storage->uninstall_reason->id,
17529
+ 'reason_info' => $this->_storage->uninstall_reason->info
17530
+ );
17531
+ }
17532
+
17533
+ if ( isset( $params['license_key'] ) ) {
17534
+ $fs_user = Freemius::_get_user_by_email( $email );
17535
+
17536
+ if ( is_object( $fs_user ) ) {
17537
+ /**
17538
+ * If opting in with a context license and the context WP Admin user already opted in
17539
+ * before from the current site, add the user context security params to avoid the
17540
+ * unnecessary email activation when the context license is owned by the same context user.
17541
+ *
17542
+ * @author Leo Fajardo (@leorw)
17543
+ * @since 1.2.3
17544
+ */
17545
+ $params = array_merge( $params, FS_Security::instance()->get_context_params(
17546
+ $fs_user,
17547
+ false,
17548
+ 'install_with_existing_user'
17549
+ ) );
17550
+ }
17551
+ }
17552
+
17553
+ if ( is_bool( $is_marketing_allowed ) ) {
17554
+ $params['is_marketing_allowed'] = $is_marketing_allowed;
17555
+ }
17556
+
17557
+ $params['is_disconnected'] = $is_disconnected;
17558
+ $params['format'] = 'json';
17559
+ $params['is_extensions_tracking_allowed'] = FS_Permission_Manager::instance( $this )->is_extensions_tracking_allowed();
17560
+ $params['is_diagnostic_tracking_allowed'] = FS_Permission_Manager::instance( $this )->is_diagnostic_tracking_allowed();
17561
+
17562
+ $request = array(
17563
+ 'method' => 'POST',
17564
+ 'body' => $params,
17565
+ 'timeout' => 60,
17566
+ );
17567
+
17568
+ $url = $this->add_show_pending( WP_FS__ADDRESS . '/action/service/user/install/' );
17569
+ $response = self::safe_remote_post( $url, $request );
17570
+
17571
+ if ( is_wp_error( $response ) ) {
17572
+ /**
17573
+ * @var WP_Error $response
17574
+ */
17575
+ $result = new stdClass();
17576
+
17577
+ $error_code = $response->get_error_code();
17578
+ $error_type = str_replace( ' ', '', ucwords( str_replace( '_', ' ', $error_code ) ) );
17579
+
17580
+ $result->error = (object) array(
17581
+ 'type' => $error_type,
17582
+ 'message' => $response->get_error_message(),
17583
+ 'code' => $error_code,
17584
+ 'http' => 402
17585
+ );
17586
+
17587
+ $this->maybe_modify_api_curl_error_message( $result );
17588
+
17589
+ return $result;
17590
+ }
17591
+
17592
+ // Module is being uninstalled, don't handle the returned data.
17593
+ if ( $is_uninstall ) {
17594
+ return true;
17595
+ }
17596
+
17597
+ /**
17598
+ * When json_decode() executed on PHP 5.2 with an invalid JSON, it will throw a PHP warning. Unfortunately, the new Theme Check doesn't allow PHP silencing and the theme review team isn't open to change that, therefore, instead of using `@json_decode()` we had to use the method without the `@` directive.
17599
+ *
17600
+ * @author Vova Feldman (@svovaf)
17601
+ * @since 1.2.3
17602
+ * @link https://themes.trac.wordpress.org/ticket/46134#comment:5
17603
+ * @link https://themes.trac.wordpress.org/ticket/46134#comment:9
17604
+ * @link https://themes.trac.wordpress.org/ticket/46134#comment:12
17605
+ * @link https://themes.trac.wordpress.org/ticket/46134#comment:14
17606
+ */
17607
+ $decoded = is_string( $response['body'] ) ?
17608
+ json_decode( $response['body'] ) :
17609
+ null;
17610
+
17611
+ if ( empty( $decoded ) ) {
17612
+ return false;
17613
+ }
17614
+
17615
+ if ( ! $this->is_api_result_object( $decoded ) ) {
17616
+ if ( ! empty( $params['license_key'] ) ) {
17617
+ // Pass the fully entered license key to the failure handler.
17618
+ $params['license_key'] = $license_key;
17619
+ }
17620
+
17621
+ return $is_uninstall ?
17622
+ $decoded :
17623
+ $this->apply_filters( 'after_install_failure', $decoded, $params );
17624
+ } else if ( isset( $decoded->pending_activation ) && $decoded->pending_activation ) {
17625
+ if ( $is_network ) {
17626
+ $site_ids = array();
17627
+ foreach ( $sites as $site ) {
17628
+ $site_ids[] = $site['blog_id'];
17629
+ }
17630
+
17631
+ /**
17632
+ * Store the sites so that they can be installed once the user has clicked on the activation link
17633
+ * in the email.
17634
+ *
17635
+ * @author Leo Fajardo (@leorw)
17636
+ */
17637
+ $this->_storage->pending_sites_info = array(
17638
+ 'blog_ids' => $site_ids,
17639
+ 'license_key' => $license_key,
17640
+ 'trial_plan_id' => $trial_plan_id
17641
+ );
17642
+ }
17643
+
17644
+ // Pending activation, add message.
17645
+ return $this->set_pending_confirmation(
17646
+ ( isset( $decoded->email ) ?
17647
+ $decoded->email :
17648
+ true ),
17649
+ false,
17650
+ $filtered_license_key,
17651
+ ! empty( $params['trial_plan_id'] ),
17652
+ isset( $decoded->is_suspicious_email ) && $decoded->is_suspicious_email
17653
+ );
17654
+ } else if ( isset( $decoded->install_secret_key ) ) {
17655
+ return $this->install_with_new_user(
17656
+ $decoded->user_id,
17657
+ $decoded->user_public_key,
17658
+ $decoded->user_secret_key,
17659
+ ( isset( $decoded->is_marketing_allowed ) && ! is_null( $decoded->is_marketing_allowed ) ?
17660
+ $decoded->is_marketing_allowed :
17661
+ null ),
17662
+ ( isset( $decoded->is_extensions_tracking_allowed ) && ! is_null( $decoded->is_extensions_tracking_allowed ) ?
17663
+ $decoded->is_extensions_tracking_allowed :
17664
+ null ),
17665
+ ( isset( $decoded->is_diagnostic_tracking_allowed ) && ! is_null( $decoded->is_diagnostic_tracking_allowed ) ?
17666
+ $decoded->is_diagnostic_tracking_allowed :
17667
+ null ),
17668
+ $decoded->install_id,
17669
+ $decoded->install_public_key,
17670
+ $decoded->install_secret_key,
17671
+ false
17672
+ );
17673
+ } else if ( is_array( $decoded->installs ) ) {
17674
+ return $this->install_many_with_new_user(
17675
+ $decoded->user_id,
17676
+ $decoded->user_public_key,
17677
+ $decoded->user_secret_key,
17678
+ ( isset( $decoded->is_marketing_allowed ) && ! is_null( $decoded->is_marketing_allowed ) ?
17679
+ $decoded->is_marketing_allowed :
17680
+ null ),
17681
+ ( isset( $decoded->is_extensions_tracking_allowed ) && ! is_null( $decoded->is_extensions_tracking_allowed ) ?
17682
+ $decoded->is_extensions_tracking_allowed :
17683
+ null ),
17684
+ ( isset( $decoded->is_diagnostic_tracking_allowed ) && ! is_null( $decoded->is_diagnostic_tracking_allowed ) ?
17685
+ $decoded->is_diagnostic_tracking_allowed :
17686
+ null ),
17687
+ $decoded->installs,
17688
+ false
17689
+ );
17690
+ }
17691
+
17692
+ return $decoded;
17693
+ }
17694
+
17695
+ /**
17696
+ * Set user and site identities.
17697
+ *
17698
+ * @author Vova Feldman (@svovaf)
17699
+ * @since 1.0.9
17700
+ *
17701
+ * @param FS_User $user
17702
+ * @param FS_Site $site
17703
+ * @param bool $redirect
17704
+ * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will
17705
+ * redirect (or return a URL) to the account page with a special parameter to
17706
+ * trigger the auto installation processes.
17707
+ *
17708
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
17709
+ */
17710
+ function setup_account(
17711
+ FS_User $user,
17712
+ FS_Site $site,
17713
+ $redirect = true,
17714
+ $auto_install = false
17715
+ ) {
17716
+ return $this->setup_network_account(
17717
+ $user,
17718
+ array( $site ),
17719
+ $redirect,
17720
+ $auto_install,
17721
+ false
17722
+ );
17723
+ }
17724
+
17725
+ /**
17726
+ * Set user and site identities.
17727
+ *
17728
+ * @author Vova Feldman (@svovaf)
17729
+ * @since 2.0.0
17730
+ *
17731
+ * @param FS_User $user
17732
+ * @param FS_Site[] $installs
17733
+ * @param bool $redirect
17734
+ * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will redirect (or return a URL) to the account page with a special parameter to trigger the auto installation processes.
17735
+ * @param bool $is_network_level_opt_in
17736
+ *
17737
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
17738
+ */
17739
+ function setup_network_account(
17740
+ FS_User $user,
17741
+ array $installs,
17742
+ $redirect = true,
17743
+ $auto_install = false,
17744
+ $is_network_level_opt_in = true
17745
+ ) {
17746
+ $first_install = $installs[0];
17747
+
17748
+ $this->_user = $user;
17749
+ $this->_site = $first_install;
17750
+
17751
+ $this->_sync_plans();
17752
+
17753
+ if ( $this->_storage->handle_gdpr_admin_notice &&
17754
+ $this->should_handle_gdpr_admin_notice() &&
17755
+ FS_GDPR_Manager::instance()->should_show_opt_in_notice()
17756
+ ) {
17757
+ /**
17758
+ * Clear user lock after an opt-in.
17759
+ */
17760
+ require_once WP_FS__DIR_INCLUDES . '/class-fs-user-lock.php';
17761
+ FS_User_Lock::instance()->unlock();
17762
+ }
17763
+
17764
+ if ( 1 < count( $installs ) ) {
17765
+ // Only network level opt-in can have more than one install.
17766
+ $is_network_level_opt_in = true;
17767
+ }
17768
+ // $is_network_level_opt_in = self::is_ajax_action_static( 'network_activate', $this->_module_id );
17769
+ // If Freemius was OFF before, turn it on.
17770
+ $this->turn_on();
17771
+
17772
+ $this->handle_account_connection(
17773
+ $installs,
17774
+ ( ! $this->_is_network_active || ! $is_network_level_opt_in )
17775
+ );
17776
+
17777
+ if ( is_numeric( $first_install->license_id ) ) {
17778
+ $this->set_license( $this->_get_license_by_id( $first_install->license_id ) );
17779
+ }
17780
+
17781
+ $this->_admin_notices->remove_sticky( 'connect_account' );
17782
+
17783
+ if ( $this->is_pending_activation() || ! $this->has_settings_menu() ) {
17784
+ $this->clear_pending_activation_mode();
17785
+
17786
+ if ( ! $this->is_paying_or_trial() ) {
17787
+ $this->_admin_notices->add_sticky(
17788
+ sprintf( $this->get_text_inline( '%s opt-in was successfully completed.', 'plugin-x-activation-message' ), '<b>' . $this->get_plugin_name() . '</b>' ),
17789
+ 'activation_complete'
17790
+ );
17791
+ }
17792
+ }
17793
+
17794
+ if ( $this->is_paying_or_trial() ) {
17795
+ if ( ! $this->is_premium() ||
17796
+ ! $this->has_premium_version() ||
17797
+ ! $this->has_settings_menu()
17798
+ ) {
17799
+ if ( $this->is_paying() ) {
17800
+ $this->_admin_notices->add_sticky(
17801
+ sprintf(
17802
+ $this->get_text_inline( 'Your account was successfully activated with the %s plan.', 'activation-with-plan-x-message' ),
17803
+ $this->get_plan_title()
17804
+ ) . $this->get_complete_upgrade_instructions(),
17805
+ 'plan_upgraded',
17806
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
17807
+ );
17808
+ } else {
17809
+ $trial_plan = $this->get_trial_plan();
17810
+
17811
+ $this->_admin_notices->add_sticky(
17812
+ sprintf(
17813
+ $this->get_text_inline( 'Your trial has been successfully started.', 'trial-started-message' ),
17814
+ '<i>' . $this->get_plugin_name() . '</i>'
17815
+ ) . $this->get_complete_upgrade_instructions( $trial_plan->title ),
17816
+ 'trial_started',
17817
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
17818
+ );
17819
+ }
17820
+ }
17821
+
17822
+ $this->_admin_notices->remove_sticky( array(
17823
+ 'trial_promotion',
17824
+ ) );
17825
+ }
17826
+
17827
+ $plugin_id = fs_request_get( 'plugin_id', false );
17828
+
17829
+ // Store activation time ONLY for plugins & themes (not add-ons).
17830
+ if ( ! is_numeric( $plugin_id ) || ( $plugin_id == $this->_plugin->id ) ) {
17831
+ if ( empty( $this->_storage->activation_timestamp ) ) {
17832
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
17833
+ }
17834
+ }
17835
+
17836
+ $next_page = '';
17837
+
17838
+ $extra = array();
17839
+ if ( $auto_install ) {
17840
+ $extra['auto_install'] = 'true';
17841
+ }
17842
+
17843
+ if ( is_numeric( $plugin_id ) ) {
17844
+ /**
17845
+ * @author Leo Fajardo (@leorw)
17846
+ * @since 1.2.1.6
17847
+ *
17848
+ * Also sync the license after an anonymous user subscribes.
17849
+ */
17850
+ if ( $this->is_anonymous() || $plugin_id != $this->_plugin->id ) {
17851
+ // Add-on was installed - sync license right after install.
17852
+ $next_page = $this->_get_sync_license_url( $plugin_id, true, $extra );
17853
+ }
17854
+ } else {
17855
+ /**
17856
+ * @author Vova Feldman (@svovaf)
17857
+ * @since 1.1.9 If site installed with a valid license, sync license.
17858
+ */
17859
+ if ( $this->is_paying() ) {
17860
+ $this->_sync_plugin_license(
17861
+ true,
17862
+ // Installs data is already synced in the beginning of this method directly or via _set_account().
17863
+ false
17864
+ );
17865
+ }
17866
+
17867
+ // Reload the page with the keys.
17868
+ $next_page = $this->is_anonymous() ?
17869
+ // If user previously skipped, redirect to account page.
17870
+ $this->get_account_url( false, $extra ) :
17871
+ $this->get_after_activation_url( 'after_connect_url', array(), $is_network_level_opt_in );
17872
+ }
17873
+
17874
+ if ( ! empty( $next_page ) && $redirect ) {
17875
+ fs_redirect( $next_page );
17876
+ }
17877
+
17878
+ return $next_page;
17879
+ }
17880
+
17881
+ /**
17882
+ * Install plugin with new user information after approval.
17883
+ *
17884
+ * @author Vova Feldman (@svovaf)
17885
+ * @since 1.0.7
17886
+ */
17887
+ function _install_with_new_user() {
17888
+ $this->_logger->entrance();
17889
+
17890
+ if ( $this->is_registered() ) {
17891
+ return;
17892
+ }
17893
+
17894
+ if ( ( $this->is_plugin() && fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) ||
17895
+ // @todo This logic should be improved because it's executed on every load of a theme.
17896
+ $this->is_theme()
17897
+ ) {
17898
+ // check_admin_referer( $this->_slug . '_activate_new' );
17899
+
17900
+ if ( fs_request_has( 'user_secret_key' ) ) {
17901
+ if ( fs_is_network_admin() && isset( $this->_storage->pending_sites_info ) ) {
17902
+ $pending_sites_info = $this->_storage->pending_sites_info;
17903
+
17904
+ $this->install_many_pending_with_user(
17905
+ fs_request_get( 'user_id' ),
17906
+ fs_request_get( 'user_public_key' ),
17907
+ fs_request_get( 'user_secret_key' ),
17908
+ fs_request_get_bool( 'is_marketing_allowed', null ),
17909
+ fs_request_get_bool( 'is_extensions_tracking_allowed', null ),
17910
+ fs_request_get_bool( 'is_diagnostic_tracking_allowed', null ),
17911
+ $pending_sites_info['blog_ids'],
17912
+ $pending_sites_info['license_key'],
17913
+ $pending_sites_info['trial_plan_id']
17914
+ );
17915
+ } else {
17916
+ $this->install_with_new_user(
17917
+ fs_request_get( 'user_id' ),
17918
+ fs_request_get( 'user_public_key' ),
17919
+ fs_request_get( 'user_secret_key' ),
17920
+ fs_request_get_bool( 'is_marketing_allowed', null ),
17921
+ fs_request_get_bool( 'is_extensions_tracking_allowed', null ),
17922
+ fs_request_get_bool( 'is_diagnostic_tracking_allowed', null ),
17923
+ fs_request_get( 'install_id' ),
17924
+ fs_request_get( 'install_public_key' ),
17925
+ fs_request_get( 'install_secret_key' ),
17926
+ true,
17927
+ fs_request_get_bool( 'auto_install' )
17928
+ );
17929
+ }
17930
+ } else if ( fs_request_has( 'pending_activation' ) ) {
17931
+ $this->set_pending_confirmation(
17932
+ fs_request_get( 'user_email' ),
17933
+ true,
17934
+ false,
17935
+ false,
17936
+ fs_request_get_bool( 'is_suspicious_email' )
17937
+ );
17938
+ }
17939
+ }
17940
+ }
17941
+
17942
+ /**
17943
+ * @author Vova Feldman (@svovaf)
17944
+ * @since 2.0.0
17945
+ *
17946
+ * @param number $id
17947
+ * @param string $public_key
17948
+ * @param string $secret_key
17949
+ *
17950
+ * @return \FS_User
17951
+ */
17952
+ private function setup_user( $id, $public_key, $secret_key ) {
17953
+ $user = self::_get_user_by_id( $id );
17954
+
17955
+ if ( is_object( $user ) ) {
17956
+ $this->_user = $user;
17957
+ } else {
17958
+ $user = new FS_User();
17959
+ $user->id = $id;
17960
+ $user->public_key = $public_key;
17961
+ $user->secret_key = $secret_key;
17962
+
17963
+ $this->_user = $user;
17964
+ $user_result = $this->get_api_user_scope()->get();
17965
+ $user = new FS_User( $user_result );
17966
+
17967
+ $this->_user = $user;
17968
+ $this->_store_user();
17969
+ }
17970
+
17971
+ return $user;
17972
+ }
17973
+
17974
+ /**
17975
+ * Install plugin with new user.
17976
+ *
17977
+ * @author Vova Feldman (@svovaf)
17978
+ * @since 1.1.7.4
17979
+ *
17980
+ * @param number $user_id
17981
+ * @param string $user_public_key
17982
+ * @param string $user_secret_key
17983
+ * @param bool|null $is_marketing_allowed
17984
+ * @param bool|null $is_extensions_tracking_allowed Since 2.3.2
17985
+ * @param bool|null $is_diagnostic_tracking_allowed Since 2.5.0.2
17986
+ * @param number $install_id
17987
+ * @param string $install_public_key
17988
+ * @param string $install_secret_key
17989
+ * @param bool $redirect
17990
+ * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will redirect (or return a URL) to the account page with a special parameter to trigger the auto installation processes.
17991
+ *
17992
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
17993
+ */
17994
+ private function install_with_new_user(
17995
+ $user_id,
17996
+ $user_public_key,
17997
+ $user_secret_key,
17998
+ $is_marketing_allowed,
17999
+ $is_extensions_tracking_allowed,
18000
+ $is_diagnostic_tracking_allowed,
18001
+ $install_id,
18002
+ $install_public_key,
18003
+ $install_secret_key,
18004
+ $redirect = true,
18005
+ $auto_install = false
18006
+ ) {
18007
+ /**
18008
+ * This method is also executed after opting in with a license key since the
18009
+ * license can be potentially associated with a different owner.
18010
+ *
18011
+ * @since 2.0.0
18012
+ */
18013
+ $user = self::_get_user_by_id( $user_id );
18014
+
18015
+ if ( ! is_object( $user ) ) {
18016
+ $user = new FS_User();
18017
+ $user->id = $user_id;
18018
+ $user->public_key = $user_public_key;
18019
+ $user->secret_key = $user_secret_key;
18020
+
18021
+ $this->_user = $user;
18022
+ $user_result = $this->get_api_user_scope()->get();
18023
+ $user = new FS_User( $user_result );
18024
+ }
18025
+
18026
+ $this->_user = $user;
18027
+
18028
+ $site = new FS_Site();
18029
+ $site->id = $install_id;
18030
+ $site->public_key = $install_public_key;
18031
+ $site->secret_key = $install_secret_key;
18032
+
18033
+ $this->_site = $site;
18034
+ $site_result = $this->get_api_site_scope( true )->get();
18035
+ $site = new FS_Site( $site_result );
18036
+ $this->_site = $site;
18037
+
18038
+ if ( ! is_null( $is_marketing_allowed ) ) {
18039
+ $this->disable_opt_in_notice_and_lock_user();
18040
+ }
18041
+
18042
+ FS_Permission_Manager::instance( $this )->update_permissions_tracking_flag( array(
18043
+ FS_Permission_Manager::PERMISSION_DIAGNOSTIC => $is_diagnostic_tracking_allowed,
18044
+ FS_Permission_Manager::PERMISSION_EXTENSIONS => $is_extensions_tracking_allowed,
18045
+ ) );
18046
+
18047
+ return $this->setup_account(
18048
+ $this->_user,
18049
+ $this->_site,
18050
+ $redirect,
18051
+ $auto_install
18052
+ );
18053
+ }
18054
+
18055
+ /**
18056
+ * Install plugin with user.
18057
+ *
18058
+ * @author Leo Fajardo (@leorw)
18059
+ * @since 2.0.0
18060
+ *
18061
+ * @param number $user_id
18062
+ * @param string $user_public_key
18063
+ * @param string $user_secret_key
18064
+ * @param bool|null $is_marketing_allowed
18065
+ * @param bool|null $is_extensions_tracking_allowed Since 2.3.2
18066
+ * @param bool|null $is_diagnostic_tracking_allowed Since 2.5.0.2
18067
+ * @param array $site_ids
18068
+ * @param bool $license_key
18069
+ * @param bool $trial_plan_id
18070
+ * @param bool $redirect
18071
+ *
18072
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
18073
+ */
18074
+ private function install_many_pending_with_user(
18075
+ $user_id,
18076
+ $user_public_key,
18077
+ $user_secret_key,
18078
+ $is_marketing_allowed,
18079
+ $is_extensions_tracking_allowed,
18080
+ $is_diagnostic_tracking_allowed,
18081
+ $site_ids,
18082
+ $license_key = false,
18083
+ $trial_plan_id = false,
18084
+ $redirect = true
18085
+ ) {
18086
+ $user = $this->setup_user( $user_id, $user_public_key, $user_secret_key );
18087
+
18088
+ if ( ! is_null( $is_marketing_allowed ) ) {
18089
+ $this->disable_opt_in_notice_and_lock_user();
18090
+ }
18091
+
18092
+ FS_Permission_Manager::instance( $this )->update_permissions_tracking_flag( array(
18093
+ FS_Permission_Manager::PERMISSION_DIAGNOSTIC => $is_diagnostic_tracking_allowed,
18094
+ FS_Permission_Manager::PERMISSION_EXTENSIONS => $is_extensions_tracking_allowed,
18095
+ ) );
18096
+
18097
+ $sites = array();
18098
+ foreach ( $site_ids as $site_id ) {
18099
+ $sites[] = $this->get_site_info( array( 'blog_id' => $site_id ) );
18100
+ }
18101
+
18102
+ $this->install_with_user( $user, $license_key, $trial_plan_id, $redirect, true, $sites );
18103
+ }
18104
+
18105
+ /**
18106
+ * Multi-site install with a new user.
18107
+ *
18108
+ * @author Vova Feldman (@svovaf)
18109
+ * @since 2.0.0
18110
+ *
18111
+ * @param number $user_id
18112
+ * @param string $user_public_key
18113
+ * @param string $user_secret_key
18114
+ * @param bool|null $is_marketing_allowed
18115
+ * @param bool|null $is_extensions_tracking_allowed Since 2.3.2
18116
+ * @param bool|null $is_diagnostic_tracking_allowed Since 2.5.0.2
18117
+ * @param object[] $installs
18118
+ * @param bool $redirect
18119
+ * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will redirect (or return a URL) to the account page with a special parameter to trigger the auto installation processes.
18120
+ *
18121
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
18122
+ */
18123
+ private function install_many_with_new_user(
18124
+ $user_id,
18125
+ $user_public_key,
18126
+ $user_secret_key,
18127
+ $is_marketing_allowed,
18128
+ $is_extensions_tracking_allowed,
18129
+ $is_diagnostic_tracking_allowed,
18130
+ array $installs,
18131
+ $redirect = true,
18132
+ $auto_install = false
18133
+ ) {
18134
+ $this->setup_user( $user_id, $user_public_key, $user_secret_key );
18135
+
18136
+ if ( ! is_null( $is_marketing_allowed ) ) {
18137
+ $this->disable_opt_in_notice_and_lock_user();
18138
+ }
18139
+
18140
+ FS_Permission_Manager::instance( $this )->update_permissions_tracking_flag( array(
18141
+ FS_Permission_Manager::PERMISSION_DIAGNOSTIC => $is_diagnostic_tracking_allowed,
18142
+ FS_Permission_Manager::PERMISSION_EXTENSIONS => $is_extensions_tracking_allowed,
18143
+ ) );
18144
+
18145
+ $install_ids = array();
18146
+
18147
+ foreach ( $installs as $install ) {
18148
+ $install_ids[] = $install->id;
18149
+ }
18150
+
18151
+ $items_per_request = 25;
18152
+ $left = count( $install_ids );
18153
+ $offset = 0;
18154
+
18155
+ $installs = array();
18156
+ while ( $left > 0 ) {
18157
+ $result = $this->get_api_user_scope()->get( "/plugins/{$this->_module_id}/installs.json?ids=" . implode( ',', array_slice( $install_ids, $offset, $items_per_request ) ) );
18158
+
18159
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
18160
+ // @todo Handle API error.
18161
+ }
18162
+
18163
+ $installs = array_merge( $installs, $result->installs );
18164
+
18165
+ $left -= $items_per_request;
18166
+ $offset += $items_per_request;
18167
+ }
18168
+
18169
+ foreach ( $installs as &$install ) {
18170
+ $install = new FS_Site( $install );
18171
+ }
18172
+
18173
+ return $this->setup_network_account(
18174
+ $this->_user,
18175
+ $installs,
18176
+ $redirect,
18177
+ $auto_install
18178
+ );
18179
+ }
18180
+
18181
+ /**
18182
+ * @author Vova Feldman (@svovaf)
18183
+ * @since 1.1.7.4
18184
+ *
18185
+ * @param string|bool $email
18186
+ * @param bool $redirect
18187
+ * @param string|bool $license_key Since 1.2.1.5
18188
+ * @param bool $is_pending_trial Since 1.2.1.5
18189
+ *
18190
+ * @return string Since 1.2.1.5 if $redirect is `false`, return the pending activation page.
18191
+ */
18192
+ private function set_pending_confirmation(
18193
+ $email = false,
18194
+ $redirect = true,
18195
+ $license_key = false,
18196
+ $is_pending_trial = false,
18197
+ $is_suspicious_email = false
18198
+ ) {
18199
+ if ( $this->_ignore_pending_mode ) {
18200
+ /**
18201
+ * If explicitly asked to ignore pending mode, set to anonymous mode
18202
+ * if require confirmation before finalizing the opt-in.
18203
+ *
18204
+ * @author Vova Feldman
18205
+ * @since 1.2.1.6
18206
+ */
18207
+ $this->skip_connection( fs_is_network_admin() );
18208
+ } else {
18209
+ // Install must be activated via email since
18210
+ // user with the same email already exist.
18211
+ $this->_storage->is_pending_activation = true;
18212
+ $this->_add_pending_activation_notice( $email, $is_pending_trial, $is_suspicious_email );
18213
+ }
18214
+
18215
+ if ( ! empty( $license_key ) ) {
18216
+ $this->_storage->pending_license_key = $license_key;
18217
+ }
18218
+
18219
+ // Remove the opt-in sticky notice.
18220
+ $this->_admin_notices->remove_sticky( array(
18221
+ 'connect_account',
18222
+ 'trial_promotion',
18223
+ ) );
18224
+
18225
+ $next_page = $this->get_after_activation_url( 'after_pending_connect_url' );
18226
+
18227
+ if ( $redirect ) {
18228
+ // Reload the page with a pending activation message.
18229
+ fs_redirect( $next_page );
18230
+ }
18231
+
18232
+ return $next_page;
18233
+ }
18234
+
18235
+ /**
18236
+ * Install plugin with current logged WP user info.
18237
+ *
18238
+ * @author Vova Feldman (@svovaf)
18239
+ * @since 1.0.7
18240
+ */
18241
+ function _install_with_current_user() {
18242
+ $this->_logger->entrance();
18243
+
18244
+ if ( $this->is_registered() ) {
18245
+ return;
18246
+ }
18247
+
18248
+ if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) && fs_request_is_post() ) {
18249
+ // check_admin_referer( 'activate_existing_' . $this->_plugin->public_key );
18250
+
18251
+ /**
18252
+ * @author Vova Feldman (@svovaf)
18253
+ * @since 1.1.9 Add license key if given.
18254
+ */
18255
+ $license_key = fs_request_get( 'license_secret_key' );
18256
+
18257
+ FS_Permission_Manager::instance( $this )->update_permissions_tracking_flag( array(
18258
+ FS_Permission_Manager::PERMISSION_DIAGNOSTIC => fs_request_get_bool( 'is_diagnostic_tracking_allowed', null ),
18259
+ FS_Permission_Manager::PERMISSION_EXTENSIONS => fs_request_get_bool( 'is_extensions_tracking_allowed', null ),
18260
+ ) );
18261
+
18262
+ $this->install_with_current_user( $license_key );
18263
+ }
18264
+ }
18265
+
18266
+
18267
+ /**
18268
+ * @author Vova Feldman (@svovaf)
18269
+ * @since 1.1.7.4
18270
+ *
18271
+ * @param string|bool $license_key
18272
+ * @param number|bool $trial_plan_id
18273
+ * @param array $sites Since 2.0.0
18274
+ * @param bool $redirect
18275
+ *
18276
+ * @return object|string If redirect is `false`, returns the next page the user should be redirected to, or the API error object if failed to install.
18277
+ */
18278
+ function install_with_current_user(
18279
+ $license_key = false,
18280
+ $trial_plan_id = false,
18281
+ $sites = array(),
18282
+ $redirect = true
18283
+ ) {
18284
+ // Get current logged WP user.
18285
+ $current_user = self::_get_current_wp_user();
18286
+
18287
+ // Find the relevant FS user by the email.
18288
+ $user = self::_get_user_by_email( $current_user->user_email );
18289
+
18290
+ return $this->install_with_user( $user, $license_key, $trial_plan_id, $redirect, true, $sites );
18291
+ }
18292
+
18293
+ /**
18294
+ * @author Vova Feldman (@svovaf)
18295
+ * @since 2.0.0
18296
+ *
18297
+ * @param \FS_User $user
18298
+ * @param string|bool $license_key
18299
+ * @param number|bool $trial_plan_id
18300
+ * @param bool $redirect
18301
+ * @param bool $setup_account Since 2.0.0. When set to FALSE, executes a light installation without setting up the account as if it's the first opt-in.
18302
+ * @param array $sites Since 2.0.0. If not empty, should be a collection of site details for the bulk install API request.
18303
+ *
18304
+ * @return \FS_Site|object|string If redirect is `false`, returns the next page the user should be redirected to, or the API error object if failed to install. If $setup_account is set to `false`, return the newly created install.
18305
+ */
18306
+ function install_with_user(
18307
+ FS_User $user,
18308
+ $license_key = false,
18309
+ $trial_plan_id = false,
18310
+ $redirect = true,
18311
+ $setup_account = true,
18312
+ $sites = array()
18313
+ ) {
18314
+ // We have to set the user before getting user scope API handler.
18315
+ $this->_user = $user;
18316
+
18317
+ // Install the plugin.
18318
+ $result = $this->create_installs_with_user(
18319
+ $user,
18320
+ $license_key,
18321
+ $trial_plan_id,
18322
+ $sites,
18323
+ $redirect
18324
+ );
18325
+
18326
+ if ( ! $this->is_api_result_entity( $result ) &&
18327
+ ! $this->is_api_result_object( $result, 'installs' )
18328
+ ) {
18329
+ // @todo Handler potential API error of the $result
18330
+ }
18331
+
18332
+ if ( empty( $sites ) ) {
18333
+ $site = new FS_Site( $result );
18334
+ $this->_site = $site;
18335
+
18336
+ if ( ! $setup_account ) {
18337
+ $this->_store_site();
18338
+
18339
+ $this->sync_plan_if_not_exist( $site->plan_id );
18340
+
18341
+ if ( ! empty( $license_key ) && FS_Plugin_License::is_valid_id( $site->license_id ) ) {
18342
+ $this->sync_license_if_not_exist( $site->license_id, $license_key );
18343
+ }
18344
+
18345
+ $this->_admin_notices->remove_sticky( 'connect_account', false );
18346
+
18347
+ return $site;
18348
+ }
18349
+
18350
+ return $this->setup_account( $this->_user, $this->_site, $redirect );
18351
+ } else {
18352
+ $installs = array();
18353
+ foreach ( $result->installs as $install ) {
18354
+ $installs[] = new FS_Site( $install );
18355
+ }
18356
+
18357
+ return $this->setup_network_account(
18358
+ $user,
18359
+ $installs,
18360
+ $redirect
18361
+ );
18362
+ }
18363
+ }
18364
+
18365
+ /**
18366
+ * Initiate an API request to create a collection of installs.
18367
+ *
18368
+ * @author Vova Feldman (@svovaf)
18369
+ * @since 2.0.0
18370
+ *
18371
+ * @param \FS_User $user
18372
+ * @param bool $license_key
18373
+ * @param bool $trial_plan_id
18374
+ * @param array $sites
18375
+ * @param bool $redirect
18376
+ * @param bool $silent
18377
+ *
18378
+ * @return object|mixed
18379
+ */
18380
+ private function create_installs_with_user(
18381
+ FS_User $user,
18382
+ $license_key = false,
18383
+ $trial_plan_id = false,
18384
+ $sites = array(),
18385
+ $redirect = false,
18386
+ $silent = false
18387
+ ) {
18388
+ $extra_install_params = array(
18389
+ 'uid' => $this->get_anonymous_id(),
18390
+ 'is_disconnected' => false,
18391
+ );
18392
+
18393
+ if ( ! empty( $license_key ) ) {
18394
+ $extra_install_params['license_key'] = $this->apply_filters( 'license_key', $license_key );
18395
+
18396
+ if ( $silent ) {
18397
+ $extra_install_params['ignore_license_owner'] = true;
18398
+ }
18399
+ } else if ( FS_Plugin_Plan::is_valid_id( $trial_plan_id ) ) {
18400
+ $extra_install_params['trial_plan_id'] = $trial_plan_id;
18401
+ }
18402
+
18403
+ if ( ! empty( $sites ) ) {
18404
+ $extra_install_params['sites'] = $sites;
18405
+ }
18406
+
18407
+ $args = $this->get_install_data_for_api( $extra_install_params, false, false );
18408
+
18409
+ // Install the plugin.
18410
+ $result = $this->get_api_user_scope_by_user( $user )->call(
18411
+ "/plugins/{$this->get_id()}/installs.json",
18412
+ 'post',
18413
+ $args
18414
+ );
18415
+
18416
+ if ( ! $this->is_api_result_entity( $result ) &&
18417
+ ! $this->is_api_result_object( $result, 'installs' )
18418
+ ) {
18419
+ if ( ! empty( $args['license_key'] ) ) {
18420
+ // Pass the fully entered license key to the failure handler.
18421
+ $args['license_key'] = $license_key;
18422
+ }
18423
+
18424
+ $result = $this->apply_filters( 'after_install_failure', $result, $args );
18425
+
18426
+ if ( ! $silent ) {
18427
+ $this->_admin_notices->add(
18428
+ sprintf( $this->get_text_inline( 'Couldn\'t activate %s.', 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
18429
+ $this->get_text_inline( 'Please contact us with the following message:', 'contact-us-with-error-message' ) . ' ' . '<b>' . $result->error->message . '</b>',
18430
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
18431
+ 'error'
18432
+ );
18433
+ }
18434
+
18435
+ if ( $redirect ) {
18436
+ /**
18437
+ * We set the user before getting the user scope API handler, so the user became temporarily
18438
+ * registered (`is_registered() = true`). Since the API returned an error and we will redirect,
18439
+ * we have to set the user to `null`, otherwise, the user will be redirected to the wrong
18440
+ * activation page based on the return value of `is_registered()`. In addition, in case the
18441
+ * context plugin doesn't have a settings menu and the default page is the `Plugins` page,
18442
+ * misleading plugin activation errors will be shown on the `Plugins` page.
18443
+ *
18444
+ * @author Leo Fajardo (@leorw)
18445
+ */
18446
+ $this->_user = null;
18447
+
18448
+ fs_redirect( $this->get_activation_url( array( 'error' => $result->error->message ) ) );
18449
+ }
18450
+ }
18451
+
18452
+ return $result;
18453
+ }
18454
+
18455
+ /**
18456
+ * Tries to activate add-on account based on parent plugin info.
18457
+ *
18458
+ * @author Vova Feldman (@svovaf)
18459
+ * @since 1.0.6
18460
+ *
18461
+ * @param Freemius $parent_fs
18462
+ * @param bool|int|null $network_level_or_blog_id True for network level opt-in and integer for opt-in for specified blog in the network.
18463
+ * @param FS_Plugin_License $bundle_license Since 2.4.0. If provided, this license will be activated for the add-on.
18464
+ */
18465
+ private function _activate_addon_account(
18466
+ Freemius $parent_fs,
18467
+ $network_level_or_blog_id = null,
18468
+ FS_Plugin_License $bundle_license = null
18469
+ ) {
18470
+ if ( $this->is_registered() ) {
18471
+ // Already activated.
18472
+ return;
18473
+ }
18474
+
18475
+ /**
18476
+ * Do not override the `uid` if network-level opt-in since the call to `get_sites_for_network_level_optin()`
18477
+ * already returns the data for the current blog.
18478
+ *
18479
+ * @author Leo Fajardo (@leorw)
18480
+ * @since 2.3.0
18481
+ */
18482
+ $uid_param_to_override = ( true === $network_level_or_blog_id ) ?
18483
+ array() :
18484
+ array( 'uid' => $this->get_anonymous_id() );
18485
+
18486
+ $params = $this->get_install_data_for_api(
18487
+ $uid_param_to_override,
18488
+ false,
18489
+ false,
18490
+ /**
18491
+ * Do not include the data for the current blog if network-level opt-in since the call to `get_sites_for_network_level_optin`
18492
+ * already includes the data for it.
18493
+ *
18494
+ * @author Leo Fajardo (@leorw)
18495
+ * @since 2.3.0
18496
+ */
18497
+ ( true !== $network_level_or_blog_id )
18498
+ );
18499
+
18500
+ if ( true === $network_level_or_blog_id ) {
18501
+ $params['sites'] = $this->get_sites_for_network_level_optin();
18502
+
18503
+ if ( empty( $params['sites'] ) ) {
18504
+ return;
18505
+ }
18506
+ }
18507
+
18508
+ if ( is_object( $bundle_license ) ) {
18509
+ $params['license_key'] = $bundle_license->secret_key;
18510
+ }
18511
+
18512
+ // Activate add-on with parent plugin credentials.
18513
+ $result = $parent_fs->get_api_site_scope()->call(
18514
+ "/addons/{$this->_plugin->id}/installs.json",
18515
+ 'post',
18516
+ $params
18517
+ );
18518
+
18519
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
18520
+ if ( is_object( $bundle_license ) ) {
18521
+ /**
18522
+ * When a license object is provided, it's an attempt by the SDK to activate a bundle license and not a user-initiated action, therefore, do not show any admin notice to avoid confusion (e.g.: the notice will show up just above the opt-in link). If the license activation fails, the admin will see an opt-in link instead.
18523
+ *
18524
+ * @author Leo Fajardo (@leorw)
18525
+ * @since 2.4.0
18526
+ */
18527
+ } else {
18528
+ $error_message = FS_Api::is_api_error_object( $result ) ?
18529
+ $result->error->message :
18530
+ $this->get_text_inline( 'An unknown error has occurred.', 'unknown-error' );
18531
+
18532
+ $this->_admin_notices->add(
18533
+ sprintf( $this->get_text_inline( 'Couldn\'t activate %s.', 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
18534
+ $this->get_text_inline( 'Please contact us with the following message:', 'contact-us-with-error-message' ) . ' ' . '<b>' . $error_message . '</b>',
18535
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
18536
+ 'error'
18537
+ );
18538
+ }
18539
+
18540
+ return;
18541
+ }
18542
+
18543
+ $addon_installs = $result->installs;
18544
+ foreach ( $addon_installs as $key => $addon_install ) {
18545
+ $addon_installs[ $key ] = new FS_Site( $addon_install );
18546
+ }
18547
+
18548
+ $first_install = $addon_installs[0];
18549
+
18550
+ // Get user information based on parent's plugin.
18551
+ $user = $parent_fs->get_user();
18552
+
18553
+ // First of all, set site and user info - otherwise we won't
18554
+ // be able to invoke API calls.
18555
+ $this->_site = $first_install;
18556
+ $this->_user = $user;
18557
+
18558
+ // Sync add-on plans.
18559
+ $this->_sync_plans();
18560
+
18561
+ $this->handle_account_connection( $addon_installs, ! fs_is_network_admin() );
18562
+
18563
+ // Get site's current plan.
18564
+ //$this->_site->plan = $this->_get_plan_by_id( $this->_site->plan->id );
18565
+
18566
+ // Sync licenses.
18567
+ $this->_sync_licenses();
18568
+
18569
+ if ( ! fs_is_network_admin() ) {
18570
+ // Try to activate premium license.
18571
+ $this->_activate_license( true, $bundle_license );
18572
+
18573
+ if ( is_object( $bundle_license ) ) {
18574
+ $this->maybe_activate_bundle_license( $bundle_license );
18575
+ }
18576
+ } else {
18577
+ if ( is_object( $bundle_license ) ) {
18578
+ $premium_license = $bundle_license;
18579
+ } else {
18580
+ $license_id = fs_request_get( 'license_id' );
18581
+
18582
+ if ( is_object( $this->_site ) &&
18583
+ FS_Plugin_License::is_valid_id( $license_id ) &&
18584
+ $license_id == $this->_site->license_id
18585
+ ) {
18586
+ // License is already activated.
18587
+ return;
18588
+ }
18589
+
18590
+ $premium_license = FS_Plugin_License::is_valid_id( $license_id ) ?
18591
+ $this->_get_license_by_id( $license_id ) :
18592
+ $this->_get_available_premium_license();
18593
+ }
18594
+
18595
+ if ( is_object( $premium_license ) ) {
18596
+ $this->maybe_network_activate_addon_license( $premium_license );
18597
+ }
18598
+ }
18599
+ }
18600
+
18601
+ /**
18602
+ * @author Leo Fajardo (@leorw)
18603
+ * @since 2.3.0
18604
+ *
18605
+ * @param FS_Site[] $installs
18606
+ * @param bool $is_site_level
18607
+ */
18608
+ private function handle_account_connection( $installs, $is_site_level ) {
18609
+ $first_install = $installs[0];
18610
+
18611
+ if ( $is_site_level ) {
18612
+ $this->_set_account( $this->_user, $first_install );
18613
+
18614
+ $this->do_action( 'after_account_connection', $this->_user, $first_install );
18615
+ } else {
18616
+ $this->_store_user();
18617
+
18618
+ // Map site addresses to their blog IDs.
18619
+ $address_to_blog_map = $this->get_address_to_blog_map();
18620
+
18621
+ $first_blog_id = null;
18622
+ $blog_2_install_map = array();
18623
+ foreach ( $installs as $install ) {
18624
+ $address = trailingslashit( fs_strip_url_protocol( $install->url ) );
18625
+ $blog_id = $address_to_blog_map[ $address ];
18626
+
18627
+ $this->_store_site( true, $blog_id, $install );
18628
+
18629
+ if ( is_null( $first_blog_id ) ) {
18630
+ $first_blog_id = $blog_id;
18631
+ }
18632
+
18633
+ $blog_2_install_map[ $blog_id ] = $install;
18634
+ }
18635
+
18636
+ if ( ! FS_User::is_valid_id( $this->_storage->network_user_id ) ||
18637
+ ! is_object( self::_get_user_by_id( $this->_storage->network_user_id ) )
18638
+ ) {
18639
+ // Store network user.
18640
+ $this->_storage->network_user_id = $this->_user->id;
18641
+ }
18642
+
18643
+ if ( ! FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ) {
18644
+ $this->_storage->network_install_blog_id = $first_blog_id;
18645
+ }
18646
+
18647
+ if ( count( $installs ) === count( $address_to_blog_map ) ) {
18648
+ // Super admin opted in for all sites in the network.
18649
+ $this->_storage->is_network_connected = true;
18650
+ }
18651
+
18652
+ $this->_store_licenses( false );
18653
+
18654
+ self::$_accounts->store();
18655
+
18656
+ // Don't sync the installs data on network upgrade
18657
+ if ( ! $this->network_upgrade_mode_completed() ) {
18658
+ $this->send_installs_update();
18659
+ }
18660
+
18661
+ $current_blog = get_current_blog_id();
18662
+
18663
+ foreach ( $blog_2_install_map as $blog_id => $install ) {
18664
+ $this->switch_to_blog( $blog_id );
18665
+
18666
+ $this->do_action( 'after_account_connection', $this->_user, $install );
18667
+ }
18668
+
18669
+ // Switch install context back to the first install.
18670
+ $this->switch_to_blog(
18671
+ $current_blog,
18672
+ $first_install,
18673
+ ( $this->_site->id != $first_install->id )
18674
+ );
18675
+
18676
+ $this->do_action( 'after_network_account_connection', $this->_user, $blog_2_install_map );
18677
+ }
18678
+ }
18679
+
18680
+ /**
18681
+ * Tries to activate parent account based on add-on's info.
18682
+ *
18683
+ * @author Vova Feldman (@svovaf)
18684
+ * @since 1.2.2.7
18685
+ *
18686
+ * @param Freemius $parent_fs
18687
+ */
18688
+ private function activate_parent_account( Freemius $parent_fs ) {
18689
+ if ( ! $this->is_addon() ) {
18690
+ // This is not an add-on.
18691
+ return;
18692
+ }
18693
+
18694
+ if ( $parent_fs->is_registered() ) {
18695
+ // Already activated.
18696
+ return;
18697
+ }
18698
+
18699
+ // Activate parent with add-on's user credentials.
18700
+ $parent_install = $this->get_api_user_scope()->call(
18701
+ "/plugins/{$parent_fs->_plugin->id}/installs.json",
18702
+ 'post',
18703
+ $parent_fs->get_install_data_for_api( array(
18704
+ 'uid' => $parent_fs->get_anonymous_id(),
18705
+ ), false, false )
18706
+ );
18707
+
18708
+ if ( isset( $parent_install->error ) ) {
18709
+ $this->_admin_notices->add(
18710
+ sprintf( $this->get_text_inline( 'Couldn\'t activate %s.', 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
18711
+ $this->get_text_inline( 'Please contact us with the following message:', 'contact-us-with-error-message' ) . ' ' . '<b>' . $parent_install->error->message . '</b>',
18712
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
18713
+ 'error'
18714
+ );
18715
+
18716
+ return;
18717
+ }
18718
+
18719
+ $parent_fs->_admin_notices->remove_sticky( 'connect_account' );
18720
+
18721
+ if ( $parent_fs->is_pending_activation() ) {
18722
+ $parent_fs->clear_pending_activation_mode();
18723
+ }
18724
+
18725
+ // Get user information based on parent's plugin.
18726
+ $user = $this->get_user();
18727
+
18728
+ // First of all, set site info - otherwise we won't
18729
+ // be able to invoke API calls.
18730
+ $parent_fs->_site = new FS_Site( $parent_install );
18731
+ $parent_fs->_user = $user;
18732
+
18733
+ // Sync add-on plans.
18734
+ $parent_fs->_sync_plans();
18735
+
18736
+ $parent_fs->_set_account( $user, $parent_fs->_site );
18737
+ }
18738
+
18739
+ #endregion
18740
+
18741
+ #----------------------------------------------------------------------------------
18742
+ #region Admin Menu Items
18743
+ #----------------------------------------------------------------------------------
18744
+
18745
+ private $_menu_items = array();
18746
+
18747
+ /**
18748
+ * @author Vova Feldman (@svovaf)
18749
+ * @since 1.2.1.8
18750
+ *
18751
+ * @return array
18752
+ */
18753
+ function get_menu_items() {
18754
+ return $this->_menu_items;
18755
+ }
18756
+
18757
+ /**
18758
+ * @author Vova Feldman (@svovaf)
18759
+ * @since 1.0.7
18760
+ *
18761
+ * @return string
18762
+ */
18763
+ function get_menu_slug() {
18764
+ return $this->_menu->get_slug();
18765
+ }
18766
+
18767
+ /**
18768
+ * @author Vova Feldman (@svovaf)
18769
+ * @since 1.0.9
18770
+ */
18771
+ function _prepare_admin_menu() {
18772
+ // if ( ! $this->is_on() ) {
18773
+ // return;
18774
+ // }
18775
+
18776
+ if ( is_object( $this->_site ) && ! $this->is_registered() ) {
18777
+ return;
18778
+ }
18779
+
18780
+ /**
18781
+ * When running from a site admin with a network activated module and the connection
18782
+ * was NOT delegated and the user still haven't skipped or opted-in, then hide the
18783
+ * site level settings.
18784
+ *
18785
+ * @author Vova Feldman (@svovaf)
18786
+ * @since 2.0.0
18787
+ */
18788
+ $should_hide_site_admin_settings = (
18789
+ $this->_is_network_active &&
18790
+ ! fs_is_network_admin() &&
18791
+ ! $this->is_delegated_connection() &&
18792
+ ! $this->is_anonymous() &&
18793
+ ! $this->is_registered()
18794
+ );
18795
+
18796
+ $should_hide_site_admin_settings = $this->apply_filters( 'should_hide_site_admin_settings_on_network_activation_mode', $should_hide_site_admin_settings );
18797
+
18798
+ if ( ( ! $this->has_api_connectivity() && ! $this->is_enable_anonymous() ) ||
18799
+ $should_hide_site_admin_settings
18800
+ ) {
18801
+ $this->_menu->remove_menu_item( $should_hide_site_admin_settings );
18802
+ } else {
18803
+ $this->do_action( fs_is_network_admin() ?
18804
+ 'before_network_admin_menu_init' :
18805
+ 'before_admin_menu_init'
18806
+ );
18807
+
18808
+ $this->add_menu_action();
18809
+
18810
+ $this->add_network_menu_when_missing();
18811
+
18812
+ $this->add_submenu_items();
18813
+ }
18814
+ }
18815
+
18816
+ /**
18817
+ * Admin dashboard menu items modifications.
18818
+ *
18819
+ * NOTE: admin_menu action executed before admin_init.
18820
+ *
18821
+ * @author Vova Feldman (@svovaf)
18822
+ * @since 1.0.7
18823
+ *
18824
+ */
18825
+ private function add_menu_action() {
18826
+ if ( $this->is_activation_mode() ) {
18827
+ if ( $this->show_opt_in_on_setting_page() ) {
18828
+ $this->override_plugin_menu_with_activation();
18829
+ } else {
18830
+ /**
18831
+ * Handle theme opt-in when the opt-in form shows as a dialog box in the themes page.
18832
+ */
18833
+ if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) ) {
18834
+ add_action( 'load-themes.php', array( &$this, '_install_with_current_user' ) );
18835
+ } else if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ||
18836
+ fs_request_get_bool( 'pending_activation' )
18837
+ ) {
18838
+ add_action( 'load-themes.php', array( &$this, '_install_with_new_user' ) );
18839
+ }
18840
+ }
18841
+ } else {
18842
+ if ( ! $this->is_registered() ) {
18843
+ // If not registered try to install user.
18844
+ if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) {
18845
+ $this->_install_with_new_user();
18846
+ }
18847
+ } else if (
18848
+ fs_request_is_action( 'sync_user' ) &&
18849
+ ( ! $this->has_settings_menu() || $this->show_opt_in_on_themes_page() )
18850
+ ) {
18851
+ $this->_handle_account_user_sync();
18852
+ }
18853
+ }
18854
+ }
18855
+
18856
+ /**
18857
+ * @author Vova Feldman (@svovaf)
18858
+ * @since 1.0.1
18859
+ */
18860
+ function _redirect_on_clicked_menu_link() {
18861
+ $this->_logger->entrance();
18862
+
18863
+ $page = fs_request_get('page');
18864
+ $page = is_string($page) ? strtolower($page) : '';
18865
+
18866
+ $this->_logger->log( 'page = ' . $page );
18867
+
18868
+ foreach ( $this->_menu_items as $priority => $items ) {
18869
+ foreach ( $items as $item ) {
18870
+ if ( isset( $item['url'] ) ) {
18871
+ if ( $page === $this->_menu->get_slug( strtolower( $item['menu_slug'] ) ) ) {
18872
+ $this->_logger->log( 'Redirecting to ' . $item['url'] );
18873
+
18874
+ fs_redirect( $item['url'] );
18875
+ }
18876
+ }
18877
+ }
18878
+ }
18879
+ }
18880
+
18881
+ /**
18882
+ * Remove plugin's all admin menu items & pages, and replace with activation page.
18883
+ *
18884
+ * @author Vova Feldman (@svovaf)
18885
+ * @since 1.0.1
18886
+ */
18887
+ private function override_plugin_menu_with_activation() {
18888
+ $this->_logger->entrance();
18889
+
18890
+ $hook = false;
18891
+
18892
+ if ( ! $this->has_settings_menu() ) {
18893
+ // Add the opt-in page without a menu item.
18894
+ $hook = FS_Admin_Menu_Manager::add_subpage(
18895
+ null,
18896
+ $this->get_plugin_name(),
18897
+ $this->get_plugin_name(),
18898
+ 'manage_options',
18899
+ $this->_slug,
18900
+ array( &$this, '_connect_page_render' )
18901
+ );
18902
+ } else if ( $this->_menu->is_top_level() ) {
18903
+ if ( $this->_menu->is_override_exact() ) {
18904
+ // Make sure the current page is matching the activation page.
18905
+ if ( ! $this->is_matching_url( $this->get_activation_url() ) ) {
18906
+ return;
18907
+ }
18908
+ }
18909
+
18910
+ $hook = $this->_menu->override_menu_item( array( &$this, '_connect_page_render' ) );
18911
+
18912
+ if ( false === $hook ) {
18913
+ // Create new menu item just for the opt-in.
18914
+ $hook = FS_Admin_Menu_Manager::add_page(
18915
+ $this->get_plugin_name(),
18916
+ $this->get_plugin_name(),
18917
+ 'manage_options',
18918
+ $this->_menu->get_slug(),
18919
+ array( &$this, '_connect_page_render' )
18920
+ );
18921
+ }
18922
+ } else {
18923
+ $menus = array( $this->_menu->get_parent_slug() );
18924
+
18925
+ if ( $this->_menu->is_override_exact() ) {
18926
+ // Make sure the current page is matching the activation page.
18927
+ if ( ! $this->is_matching_url( $this->get_activation_url() ) ) {
18928
+ return;
18929
+ }
18930
+ }
18931
+
18932
+ foreach ( $menus as $parent_slug ) {
18933
+ $hook = $this->_menu->override_submenu_action(
18934
+ $parent_slug,
18935
+ $this->_menu->get_raw_slug(),
18936
+ array( &$this, '_connect_page_render' )
18937
+ );
18938
+
18939
+ if ( false !== $hook ) {
18940
+ // Found plugin's submenu item.
18941
+ break;
18942
+ }
18943
+ }
18944
+ }
18945
+
18946
+ if ( $this->is_activation_page() ) {
18947
+ // Clean admin page from distracting content.
18948
+ self::_clean_admin_content_section();
18949
+ }
18950
+
18951
+ if ( false !== $hook ) {
18952
+ if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) ) {
18953
+ $this->_install_with_current_user();
18954
+ } else if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) {
18955
+ $this->_install_with_new_user();
18956
+ }
18957
+ }
18958
+ }
18959
+
18960
+ /**
18961
+ * If a plugin was network activated and connected but don't have a network
18962
+ * level settings, then add an artificial menu item for the Account and other
18963
+ * Freemius settings.
18964
+ *
18965
+ * @author Vova Feldman (@svovaf)
18966
+ * @since 2.0.0
18967
+ */
18968
+ private function add_network_menu_when_missing() {
18969
+ $this->_logger->entrance();
18970
+
18971
+ if ( ! $this->_is_network_active ) {
18972
+ // Plugin wasn't activated on the network level.
18973
+ return;
18974
+ }
18975
+
18976
+ if ( ! fs_is_network_admin() ) {
18977
+ // The context is not the network admin.
18978
+ return;
18979
+ }
18980
+
18981
+ if ( $this->_menu->has_network_menu() ) {
18982
+ // Plugin already has a network level menu.
18983
+ return;
18984
+ }
18985
+
18986
+ if ( $this->is_network_activation_mode() ) {
18987
+ /**
18988
+ * Do not add during activation mode, otherwise, there will be duplicate menus while the opt-in
18989
+ * screen is being shown.
18990
+ *
18991
+ * @author Leo Fajardo (@leorw)
18992
+ */
18993
+ return;
18994
+ }
18995
+
18996
+ if ( ! WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED ) {
18997
+ if ( $this->is_network_delegated_connection() ) {
18998
+ // Super-admin delegated the connection to the site admins.
18999
+ return;
19000
+ }
19001
+ }
19002
+
19003
+ if ( ! $this->_menu->has_menu() || $this->_menu->is_top_level() ) {
19004
+
19005
+ if ( $this->_menu->has_menu() ||
19006
+ ! $this->is_addon() ||
19007
+ $this->is_activation_mode()
19008
+ ) {
19009
+ $this->_dynamically_added_top_level_page_hook_name = $this->_menu->add_page_and_update(
19010
+ $this->get_plugin_name(),
19011
+ $this->get_plugin_name(),
19012
+ 'manage_options',
19013
+ $this->_menu->has_menu() ? $this->_menu->get_slug() : $this->_slug
19014
+ );
19015
+ }
19016
+ } else {
19017
+ $this->_menu->add_subpage_and_update(
19018
+ $this->_menu->get_parent_slug(),
19019
+ $this->get_plugin_name(),
19020
+ $this->get_plugin_name(),
19021
+ 'manage_options',
19022
+ $this->_menu->get_slug()
19023
+ );
19024
+ }
19025
+ }
19026
+
19027
+ /**
19028
+ * @author Leo Fajardo (@leorw)
19029
+ * @since 1.2.1
19030
+ *
19031
+ * return string
19032
+ */
19033
+ function get_top_level_menu_capability() {
19034
+ global $menu;
19035
+
19036
+ $top_level_menu_slug = $this->get_top_level_menu_slug();
19037
+
19038
+ foreach ( $menu as $menu_info ) {
19039
+ /**
19040
+ * The second element in the menu info array is the capability/role that has access to the menu and the
19041
+ * third element is the menu slug.
19042
+ */
19043
+ if ( $menu_info[2] === $top_level_menu_slug ) {
19044
+ return $menu_info[1];
19045
+ }
19046
+ }
19047
+
19048
+ return 'read';
19049
+ }
19050
+
19051
+ /**
19052
+ * @author Vova Feldman (@svovaf)
19053
+ * @since 1.0.0
19054
+ *
19055
+ * @return string
19056
+ */
19057
+ private function get_top_level_menu_slug() {
19058
+ return ( $this->is_addon() ?
19059
+ $this->get_parent_instance()->_menu->get_top_level_menu_slug() :
19060
+ $this->_menu->get_top_level_menu_slug() );
19061
+ }
19062
+
19063
+ /**
19064
+ * @author Vova Feldman (@svovaf)
19065
+ * @since 1.2.2.7
19066
+ *
19067
+ * @return string
19068
+ */
19069
+ function get_pricing_cta_label() {
19070
+ $label = $this->get_text_inline( 'Upgrade', 'upgrade' );
19071
+
19072
+ if ( $this->is_in_trial_promotion() &&
19073
+ ! $this->is_paying_or_trial()
19074
+ ) {
19075
+ // If running a trial promotion, modify the pricing to load the trial.
19076
+ $label = $this->get_text_inline( 'Start Trial', 'start-trial' );
19077
+ } else if ( $this->is_paying() ) {
19078
+ $label = $this->get_text_inline( 'Pricing', 'pricing' );
19079
+ }
19080
+
19081
+ return $label;
19082
+ }
19083
+
19084
+ /**
19085
+ * @author Vova Feldman (@svovaf)
19086
+ * @since 1.2.2.7
19087
+ *
19088
+ * @return bool
19089
+ */
19090
+ function is_pricing_page_visible() {
19091
+ return (
19092
+ // Has at least one paid plan.
19093
+ $this->has_paid_plan() &&
19094
+ // Didn't ask to hide the pricing page.
19095
+ $this->is_page_visible( 'pricing' ) &&
19096
+ // Don't have a valid active license or has more than one plan.
19097
+ ( ! $this->is_paying() || ! $this->is_single_plan( true ) )
19098
+ );
19099
+ }
19100
+
19101
+ /**
19102
+ * @author Leo Fajardo (@leorw)
19103
+ * @since 2.3.0
19104
+ *
19105
+ * @param bool $is_activation_mode
19106
+ *
19107
+ * @return bool
19108
+ */
19109
+ private function should_add_submenu_or_action_links( $is_activation_mode ) {
19110
+ if ( $this->is_addon() ) {
19111
+ // No submenu items or action links for add-ons.
19112
+ return false;
19113
+ }
19114
+
19115
+ if ( $this->show_opt_in_on_themes_page() ) {
19116
+ if ( ! fs_is_network_admin() ) {
19117
+ // Also add action links or submenu items when running in a free .org theme so the tabs will be visible.
19118
+ return true;
19119
+ }
19120
+ } else if ( $is_activation_mode ) {
19121
+ // Don't show submenu-items/tabs in activation mode, unless it's a wp.org theme.
19122
+ return false;
19123
+ }
19124
+
19125
+ if ( fs_is_network_admin() ) {
19126
+ /**
19127
+ * Add submenu items or action links to network level when plugin was network activated and the super
19128
+ * admin did NOT delegate the connection of all sites to site admins.
19129
+ */
19130
+ return (
19131
+ $this->_is_network_active &&
19132
+ ( WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED ||
19133
+ ! $this->is_network_delegated_connection() )
19134
+ );
19135
+ }
19136
+
19137
+ return ( ! $this->_is_network_active || $this->is_delegated_connection() );
19138
+ }
19139
+
19140
+ /**
19141
+ * Add default Freemius menu items.
19142
+ *
19143
+ * @author Vova Feldman (@svovaf)
19144
+ * @since 1.0.0
19145
+ * @since 1.2.2.7 Also add submenu items when running in a free .org theme so the tabs will be visible.
19146
+ */
19147
+ private function add_submenu_items() {
19148
+ $this->_logger->entrance();
19149
+
19150
+ $is_activation_mode = $this->is_activation_mode();
19151
+
19152
+ $add_submenu_items = $this->should_add_submenu_or_action_links( $is_activation_mode );
19153
+
19154
+ if ( $add_submenu_items ) {
19155
+ if ( $this->has_affiliate_program() ) {
19156
+ // Add affiliation page.
19157
+ $this->add_submenu_item(
19158
+ $this->get_text_inline( 'Affiliation', 'affiliation' ),
19159
+ array( &$this, '_affiliation_page_render' ),
19160
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text_inline( 'Affiliation', 'affiliation' ),
19161
+ 'manage_options',
19162
+ 'affiliation',
19163
+ 'Freemius::_clean_admin_content_section',
19164
+ WP_FS__DEFAULT_PRIORITY,
19165
+ $this->is_submenu_item_visible( 'affiliation' )
19166
+ );
19167
+ }
19168
+ }
19169
+
19170
+ if ( $add_submenu_items ||
19171
+ ( $is_activation_mode &&
19172
+ $this->is_only_premium() &&
19173
+ $this->is_admin_page( 'account' ) &&
19174
+ fs_request_is_action( $this->get_unique_affix() . '_sync_license' )
19175
+ )
19176
+ ) {
19177
+ if ( ! WP_FS__DEMO_MODE && $this->is_registered() ) {
19178
+ $show_account = (
19179
+ $this->is_submenu_item_visible( 'account' ) &&
19180
+ /**
19181
+ * @since 1.2.2.7 Don't show the Account for free WP.org themes without any paid plans.
19182
+ */
19183
+ ( ! $this->is_free_wp_org_theme() || $this->has_paid_plan() )
19184
+ );
19185
+
19186
+ // Add user account page.
19187
+ $this->add_submenu_item(
19188
+ $this->get_text_inline( 'Account', 'account' ),
19189
+ array( &$this, '_account_page_render' ),
19190
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text_inline( 'Account', 'account' ),
19191
+ 'manage_options',
19192
+ 'account',
19193
+ array( &$this, '_account_page_load' ),
19194
+ WP_FS__DEFAULT_PRIORITY,
19195
+ ( $add_submenu_items && $show_account )
19196
+ );
19197
+ }
19198
+ }
19199
+
19200
+ if ( $add_submenu_items ) {
19201
+ if (! WP_FS__DEMO_MODE && ! $this->is_whitelabeled() ) {
19202
+ // Add contact page.
19203
+ $this->add_submenu_item(
19204
+ $this->get_text_inline( 'Contact Us', 'contact-us' ),
19205
+ array( &$this, '_contact_page_render' ),
19206
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text_inline( 'Contact Us', 'contact-us' ),
19207
+ 'manage_options',
19208
+ 'contact',
19209
+ 'Freemius::_clean_admin_content_section',
19210
+ WP_FS__DEFAULT_PRIORITY,
19211
+ $this->is_submenu_item_visible( 'contact' )
19212
+ );
19213
+ }
19214
+
19215
+ if ( $this->has_addons() ) {
19216
+ $this->add_submenu_item(
19217
+ $this->get_text_inline( 'Add-Ons', 'add-ons' ),
19218
+ array( &$this, '_addons_page_render' ),
19219
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text_inline( 'Add-Ons', 'add-ons' ),
19220
+ 'manage_options',
19221
+ 'addons',
19222
+ array( &$this, '_addons_page_load' ),
19223
+ WP_FS__LOWEST_PRIORITY - 1,
19224
+ $this->is_submenu_item_visible( 'addons' )
19225
+ );
19226
+ }
19227
+ }
19228
+
19229
+ if ( $add_submenu_items ||
19230
+ ( $is_activation_mode && $this->is_only_premium() && $this->is_admin_page( 'pricing' ) )
19231
+ ) {
19232
+ if (! WP_FS__DEMO_MODE && ! $this->is_whitelabeled() ) {
19233
+ $show_pricing = (
19234
+ $this->is_submenu_item_visible( 'pricing' ) &&
19235
+ $this->is_pricing_page_visible()
19236
+ );
19237
+
19238
+ $pricing_cta_text = $this->get_pricing_cta_label();
19239
+ $pricing_class = 'upgrade-mode';
19240
+ if ( $show_pricing ) {
19241
+ if ( $this->is_in_trial_promotion() &&
19242
+ ! $this->is_paying_or_trial()
19243
+ ) {
19244
+ // If running a trial promotion, modify the pricing to load the trial.
19245
+ $pricing_class = 'trial-mode';
19246
+ } else if ( $this->is_paying() ) {
19247
+ $pricing_class = '';
19248
+ }
19249
+ }
19250
+
19251
+ // Add upgrade/pricing page.
19252
+ $this->add_submenu_item(
19253
+ $pricing_cta_text . '&nbsp;&nbsp;' . ( is_rtl() ? $this->get_text_x_inline( '&#x2190;', 'ASCII arrow left icon', 'symbol_arrow-left' ) : $this->get_text_x_inline( '&#x27a4;', 'ASCII arrow right icon', 'symbol_arrow-right' ) ),
19254
+ array( &$this, '_pricing_page_render' ),
19255
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text_x_inline( 'Pricing', 'noun', 'pricing' ),
19256
+ 'manage_options',
19257
+ 'pricing',
19258
+ 'Freemius::_clean_admin_content_section',
19259
+ WP_FS__LOWEST_PRIORITY,
19260
+ ( $add_submenu_items && $show_pricing ),
19261
+ $pricing_class
19262
+ );
19263
+ }
19264
+ }
19265
+
19266
+ if ( ! $is_activation_mode || ( true !== $this->_storage->require_license_activation ) ) {
19267
+ /**
19268
+ * Add the other menu items if there are any when not in activation mode or license activation is not
19269
+ * required (license activation is required for registered or anonymous users after activating the
19270
+ * premium version when the site is not in trial mode or there's no active valid license).
19271
+ *
19272
+ * @author Leo Fajardo (@leorw)
19273
+ * @since 2.2.1
19274
+ */
19275
+ if ( 0 < count( $this->_menu_items ) ) {
19276
+ if ( ! $this->_menu->is_top_level() ) {
19277
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
19278
+
19279
+ // Append submenu items right after the plugin's submenu item.
19280
+ $this->order_sub_submenu_items();
19281
+ } else {
19282
+ // Append submenu items.
19283
+ $this->embed_submenu_items();
19284
+ }
19285
+ }
19286
+ }
19287
+ }
19288
+
19289
+ /**
19290
+ * Moved the actual submenu item additions to a separated function,
19291
+ * in order to support sub-submenu items when the plugin's settings
19292
+ * only have a submenu and not top-level menu item.
19293
+ *
19294
+ * @author Vova Feldman (@svovaf)
19295
+ * @since 1.1.4
19296
+ */
19297
+ private function embed_submenu_items() {
19298
+ $item_template = $this->_menu->is_top_level() ?
19299
+ '<span class="fs-submenu-item %s %s %s">%s</span>' :
19300
+ '<span class="fs-submenu-item fs-sub %s %s %s">%s</span>';
19301
+
19302
+ $top_level_menu_capability = $this->get_top_level_menu_capability();
19303
+
19304
+ ksort( $this->_menu_items );
19305
+
19306
+ $is_first_submenu_item = true;
19307
+
19308
+ foreach ( $this->_menu_items as $priority => $items ) {
19309
+ foreach ( $items as $item ) {
19310
+ $capability = ( ! empty( $item['capability'] ) ? $item['capability'] : $top_level_menu_capability );
19311
+
19312
+ $menu_item = sprintf(
19313
+ $item_template,
19314
+ $this->get_unique_affix(),
19315
+ $item['menu_slug'],
19316
+ ! empty( $item['class'] ) ? $item['class'] : '',
19317
+ $item['menu_title']
19318
+ );
19319
+
19320
+ $top_level_menu_slug = $this->get_top_level_menu_slug();
19321
+ $menu_slug = $this->_menu->get_slug( $item['menu_slug'] );
19322
+
19323
+ if ( ! isset( $item['url'] ) ) {
19324
+ $hook = FS_Admin_Menu_Manager::add_subpage(
19325
+ $item['show_submenu'] ?
19326
+ $top_level_menu_slug :
19327
+ null,
19328
+ $item['page_title'],
19329
+ $menu_item,
19330
+ $capability,
19331
+ $menu_slug,
19332
+ $item['render_function']
19333
+ );
19334
+
19335
+ if ( false !== $item['before_render_function'] ) {
19336
+ add_action( "load-$hook", $item['before_render_function'] );
19337
+ }
19338
+ } else {
19339
+ FS_Admin_Menu_Manager::add_subpage(
19340
+ $item['show_submenu'] ?
19341
+ $top_level_menu_slug :
19342
+ null,
19343
+ $item['page_title'],
19344
+ $menu_item,
19345
+ $capability,
19346
+ $menu_slug,
19347
+ array( $this, '' )
19348
+ );
19349
+ }
19350
+
19351
+ if ( $item['show_submenu'] && $is_first_submenu_item ) {
19352
+ if ( $this->_is_network_active && ! empty( $this->_dynamically_added_top_level_page_hook_name ) ) {
19353
+ /**
19354
+ * If the top-level menu has been dynamically created, remove the first submenu item that
19355
+ * WordPress automatically creates when there's no submenu item whose slug matches the
19356
+ * parent's. In the following example, the `Awesome Plugin` submenu item will be removed.
19357
+ *
19358
+ * Awesome Plugin
19359
+ * - Awesome Plugin <-- we want to remove this since there's no real setting page for the top-level
19360
+ *
19361
+ * @author Leo Fajardo (@leorw)
19362
+ */
19363
+ remove_submenu_page( $top_level_menu_slug, $top_level_menu_slug );
19364
+ }
19365
+
19366
+ $is_first_submenu_item = false;
19367
+ }
19368
+ }
19369
+ }
19370
+ }
19371
+
19372
+ /**
19373
+ * Re-order the submenu items so all Freemius added new submenu items
19374
+ * are added right after the plugin's settings submenu item.
19375
+ *
19376
+ * @author Vova Feldman (@svovaf)
19377
+ * @since 1.1.4
19378
+ */
19379
+ private function order_sub_submenu_items() {
19380
+ global $submenu;
19381
+
19382
+ $menu_slug = $this->_menu->get_top_level_menu_slug();
19383
+
19384
+ /**
19385
+ * Before "admin_menu" fires, WordPress will loop over the default submenus and remove pages for which the user
19386
+ * does not have permissions. So in case a plugin does not have top-level menu but does have submenus under any
19387
+ * of the default menus, only users that have the right role can access its sub-submenus (Account, Contact Us,
19388
+ * Support Forum, etc.) since $submenu[ $menu_slug ] will be empty if the user doesn't have permission.
19389
+ *
19390
+ * In case a plugin does not have submenus under any of the default menus but does have submenus under the menu
19391
+ * of another plugin, only users that have the right role can access its sub-submenus since we will use the
19392
+ * capability needed to access the parent menu as the capability for the submenus that we will add.
19393
+ */
19394
+ if ( empty( $submenu[ $menu_slug ] ) ) {
19395
+ return;
19396
+ }
19397
+
19398
+ $top_level_menu = &$submenu[ $menu_slug ];
19399
+
19400
+ $all_submenu_items_after = array();
19401
+
19402
+ $found_submenu_item = false;
19403
+
19404
+ foreach ( $top_level_menu as $submenu_id => $meta ) {
19405
+ if ( $found_submenu_item ) {
19406
+ // Remove all submenu items after the plugin's submenu item.
19407
+ $all_submenu_items_after[] = $meta;
19408
+ unset( $top_level_menu[ $submenu_id ] );
19409
+ }
19410
+
19411
+ if ( $this->_menu->get_raw_slug() === $meta[2] ) {
19412
+ // Found the submenu item, put all below.
19413
+ $found_submenu_item = true;
19414
+ continue;
19415
+ }
19416
+ }
19417
+
19418
+ // Embed all plugin's new submenu items.
19419
+ $this->embed_submenu_items();
19420
+
19421
+ // Start with specially high number to make sure it's appended.
19422
+ $i = max( 10000, max( array_keys( $top_level_menu ) ) + 1 );
19423
+ foreach ( $all_submenu_items_after as $meta ) {
19424
+ $top_level_menu[ $i ] = $meta;
19425
+ $i ++;
19426
+ }
19427
+
19428
+ // Sort submenu items.
19429
+ ksort( $top_level_menu );
19430
+ }
19431
+
19432
+ /**
19433
+ * Helper method to return the module's support forum URL.
19434
+ *
19435
+ * @author Vova Feldman (@svovaf)
19436
+ * @since 1.2.2.7
19437
+ *
19438
+ * @return string
19439
+ */
19440
+ function get_support_forum_url() {
19441
+ return $this->apply_filters( 'support_forum_url', "https://wordpress.org/support/{$this->_module_type}/{$this->_slug}" );
19442
+ }
19443
+
19444
+ /**
19445
+ * Displays the Support Forum link when enabled.
19446
+ *
19447
+ * Can be filtered like so:
19448
+ *
19449
+ * function _fs_show_support_menu( $is_visible, $menu_id ) {
19450
+ * if ( 'support' === $menu_id ) {
19451
+ * return _fs->is_registered();
19452
+ * }
19453
+ * return $is_visible;
19454
+ * }
19455
+ * _fs()->add_filter('is_submenu_visible', '_fs_show_support_menu', 10, 2);
19456
+ *
19457
+ */
19458
+ function _add_default_submenu_items() {
19459
+ if ( ! $this->is_on() ) {
19460
+ return;
19461
+ }
19462
+
19463
+ if ( ! $this->is_activation_mode() &&
19464
+ ( ( $this->_is_network_active && fs_is_network_admin() ) ||
19465
+ ( ! $this->_is_network_active && is_admin() ) )
19466
+ ) {
19467
+ $this->add_submenu_link_item(
19468
+ $this->apply_filters( 'support_forum_submenu', $this->get_text_inline( 'Support Forum', 'support-forum' ) ),
19469
+ $this->get_support_forum_url(),
19470
+ 'wp-support-forum',
19471
+ null,
19472
+ 50,
19473
+ $this->is_submenu_item_visible( 'support' )
19474
+ );
19475
+ }
19476
+ }
19477
+
19478
+ /**
19479
+ * @author Vova Feldman (@svovaf)
19480
+ * @since 1.0.1
19481
+ *
19482
+ * @param string $menu_title
19483
+ * @param callable $render_function
19484
+ * @param bool|string $page_title
19485
+ * @param string $capability
19486
+ * @param bool|string $menu_slug
19487
+ * @param bool|callable $before_render_function
19488
+ * @param int $priority
19489
+ * @param bool $show_submenu
19490
+ * @param string $class Since 1.2.1.5 can add custom classes to menu items.
19491
+ */
19492
+ function add_submenu_item(
19493
+ $menu_title,
19494
+ $render_function,
19495
+ $page_title = false,
19496
+ $capability = 'manage_options',
19497
+ $menu_slug = false,
19498
+ $before_render_function = false,
19499
+ $priority = WP_FS__DEFAULT_PRIORITY,
19500
+ $show_submenu = true,
19501
+ $class = ''
19502
+ ) {
19503
+ $this->_logger->entrance( 'Title = ' . $menu_title );
19504
+
19505
+ if ( $this->is_addon() ) {
19506
+ $parent_fs = $this->get_parent_instance();
19507
+
19508
+ if ( is_object( $parent_fs ) ) {
19509
+ $parent_fs->add_submenu_item(
19510
+ $menu_title,
19511
+ $render_function,
19512
+ $page_title,
19513
+ $capability,
19514
+ $menu_slug,
19515
+ $before_render_function,
19516
+ $priority,
19517
+ $show_submenu,
19518
+ $class
19519
+ );
19520
+
19521
+ return;
19522
+ }
19523
+ }
19524
+
19525
+ if ( ! isset( $this->_menu_items[ $priority ] ) ) {
19526
+ $this->_menu_items[ $priority ] = array();
19527
+ }
19528
+
19529
+ $this->_menu_items[ $priority ][] = array(
19530
+ 'page_title' => is_string( $page_title ) ? $page_title : $menu_title,
19531
+ 'menu_title' => $menu_title,
19532
+ 'capability' => $capability,
19533
+ 'menu_slug' => is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ),
19534
+ 'render_function' => $render_function,
19535
+ 'before_render_function' => $before_render_function,
19536
+ 'show_submenu' => $show_submenu,
19537
+ 'class' => $class,
19538
+ );
19539
+ }
19540
+
19541
+ /**
19542
+ * @author Vova Feldman (@svovaf)
19543
+ * @since 1.0.1
19544
+ *
19545
+ * @param string $menu_title
19546
+ * @param string $url
19547
+ * @param bool $menu_slug
19548
+ * @param string $capability
19549
+ * @param int $priority
19550
+ * @param bool $show_submenu
19551
+ */
19552
+ function add_submenu_link_item(
19553
+ $menu_title,
19554
+ $url,
19555
+ $menu_slug = false,
19556
+ $capability = 'read',
19557
+ $priority = WP_FS__DEFAULT_PRIORITY,
19558
+ $show_submenu = true
19559
+ ) {
19560
+ $this->_logger->entrance( 'Title = ' . $menu_title . '; Url = ' . $url );
19561
+
19562
+ if ( $this->is_addon() ) {
19563
+ $parent_fs = $this->get_parent_instance();
19564
+
19565
+ if ( is_object( $parent_fs ) ) {
19566
+ $parent_fs->add_submenu_link_item(
19567
+ $menu_title,
19568
+ $url,
19569
+ $menu_slug,
19570
+ $capability,
19571
+ $priority,
19572
+ $show_submenu
19573
+ );
19574
+
19575
+ return;
19576
+ }
19577
+ }
19578
+
19579
+ if ( ! isset( $this->_menu_items[ $priority ] ) ) {
19580
+ $this->_menu_items[ $priority ] = array();
19581
+ }
19582
+
19583
+ $this->_menu_items[ $priority ][] = array(
19584
+ 'menu_title' => $menu_title,
19585
+ 'capability' => $capability,
19586
+ 'menu_slug' => is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ),
19587
+ 'url' => $url,
19588
+ 'page_title' => $menu_title,
19589
+ 'render_function' => 'fs_dummy',
19590
+ 'before_render_function' => '',
19591
+ 'show_submenu' => $show_submenu,
19592
+ );
19593
+ }
19594
+
19595
+ #endregion ------------------------------------------------------------------
19596
+
19597
+ #--------------------------------------------------------------------------------
19598
+ #region Admin Notices
19599
+ #--------------------------------------------------------------------------------
19600
+
19601
+ /**
19602
+ * @author Vova Feldman (@svovaf)
19603
+ * @since 2.3.1
19604
+ *
19605
+ * @param string|string[] $ids
19606
+ * @param int|null $network_level_or_blog_id
19607
+ *
19608
+ * @uses FS_Admin_Notices::remove_sticky()
19609
+ */
19610
+ function remove_sticky( $ids, $network_level_or_blog_id = null ) {
19611
+ $this->_admin_notices->remove_sticky( $ids, $network_level_or_blog_id );
19612
+ }
19613
+
19614
+ #endregion
19615
+
19616
+ #--------------------------------------------------------------------------------
19617
+ #region Actions / Hooks / Filters
19618
+ #--------------------------------------------------------------------------------
19619
+
19620
+ /**
19621
+ * @author Vova Feldman (@svovaf)
19622
+ * @since 1.1.7
19623
+ *
19624
+ * @param string $tag
19625
+ *
19626
+ * @return string
19627
+ */
19628
+ public function get_action_tag( $tag ) {
19629
+ return self::get_action_tag_static( $tag, $this->_slug, $this->is_plugin() );
19630
+ }
19631
+
19632
+ /**
19633
+ * @author Vova Feldman (@svovaf)
19634
+ * @since 1.2.1.6
19635
+ *
19636
+ * @param string $tag
19637
+ * @param string $slug
19638
+ * @param bool $is_plugin
19639
+ *
19640
+ * @return string
19641
+ */
19642
+ static function get_action_tag_static( $tag, $slug = '', $is_plugin = true ) {
19643
+ $action = "fs_{$tag}";
19644
+
19645
+ if ( ! empty( $slug ) ) {
19646
+ $action .= '_' . self::get_module_unique_affix( $slug, $is_plugin );
19647
+ }
19648
+
19649
+ return $action;
19650
+ }
19651
+
19652
+ /**
19653
+ * Returns a string that can be used to generate a unique action name,
19654
+ * option name, HTML element ID, or HTML element class.
19655
+ *
19656
+ * @author Leo Fajardo (@leorw)
19657
+ * @since 1.2.2
19658
+ *
19659
+ * @return string
19660
+ */
19661
+ public function get_unique_affix() {
19662
+ return self::get_module_unique_affix( $this->_slug, $this->is_plugin() );
19663
+ }
19664
+
19665
+ /**
19666
+ * Returns a string that can be used to generate a unique action name,
19667
+ * option name, HTML element ID, or HTML element class.
19668
+ *
19669
+ * @author Vova Feldman (@svovaf)
19670
+ * @since 1.2.2.5
19671
+ *
19672
+ * @param string $slug
19673
+ * @param bool $is_plugin
19674
+ *
19675
+ * @return string
19676
+ */
19677
+ static function get_module_unique_affix( $slug, $is_plugin = true ) {
19678
+ $affix = $slug;
19679
+
19680
+ if ( ! $is_plugin ) {
19681
+ $affix .= '-' . WP_FS__MODULE_TYPE_THEME;
19682
+ }
19683
+
19684
+ return $affix;
19685
+ }
19686
+
19687
+ /**
19688
+ * @author Vova Feldman (@svovaf)
19689
+ * @since 1.2.1
19690
+ * @since 1.2.2.5 The AJAX action names are based on the module ID, not like the non-AJAX actions that are
19691
+ * based on the slug for backward compatibility.
19692
+ *
19693
+ * @param string $tag
19694
+ *
19695
+ * @return string
19696
+ */
19697
+ function get_ajax_action( $tag ) {
19698
+ return self::get_ajax_action_static( $tag, $this->_module_id );
19699
+ }
19700
+
19701
+ /**
19702
+ * @author Vova Feldman (@svovaf)
19703
+ * @since 1.2.1.7
19704
+ *
19705
+ * @param string $tag
19706
+ *
19707
+ * @return string
19708
+ */
19709
+ function get_ajax_security( $tag ) {
19710
+ return wp_create_nonce( $this->get_ajax_action( $tag ) );
19711
+ }
19712
+
19713
+ /**
19714
+ * @author Vova Feldman (@svovaf)
19715
+ * @since 1.2.1.7
19716
+ *
19717
+ * @param string $tag
19718
+ */
19719
+ function check_ajax_referer( $tag ) {
19720
+ check_ajax_referer( $this->get_ajax_action( $tag ), 'security' );
19721
+ }
19722
+
19723
+ /**
19724
+ * @author Vova Feldman (@svovaf)
19725
+ * @since 1.2.1.6
19726
+ * @since 1.2.2.5 The AJAX action names are based on the module ID, not like the non-AJAX actions that are
19727
+ * based on the slug for backward compatibility.
19728
+ *
19729
+ * @param string $tag
19730
+ * @param number|null $module_id
19731
+ *
19732
+ * @return string
19733
+ */
19734
+ static function get_ajax_action_static( $tag, $module_id = null ) {
19735
+ $action = "fs_{$tag}";
19736
+
19737
+ if ( ! empty( $module_id ) ) {
19738
+ $action .= "_{$module_id}";
19739
+ }
19740
+
19741
+ return $action;
19742
+ }
19743
+
19744
+ /**
19745
+ * Do action, specific for the current context plugin.
19746
+ *
19747
+ * @author Vova Feldman (@svovaf)
19748
+ * @since 1.0.1
19749
+ *
19750
+ * @param string $tag The name of the action to be executed.
19751
+ * @param mixed $arg,... Optional. Additional arguments which are passed on to the
19752
+ * functions hooked to the action. Default empty.
19753
+ *
19754
+ * @uses do_action()
19755
+ */
19756
+ function do_action( $tag, $arg = '' ) {
19757
+ $args = func_get_args();
19758
+
19759
+ $this->_logger->entrance( $tag );
19760
+
19761
+ call_user_func_array( 'do_action', array_merge(
19762
+ array( $this->get_action_tag( $tag ) ),
19763
+ array_slice( $args, 1 ) )
19764
+ );
19765
+ }
19766
+
19767
+ /**
19768
+ * Add action, specific for the current context plugin.
19769
+ *
19770
+ * @author Vova Feldman (@svovaf)
19771
+ * @since 1.0.1
19772
+ *
19773
+ * @param string $tag
19774
+ * @param callable $function_to_add
19775
+ * @param int $priority
19776
+ * @param int $accepted_args
19777
+ *
19778
+ * @uses add_action()
19779
+ */
19780
+ function add_action(
19781
+ $tag,
19782
+ $function_to_add,
19783
+ $priority = WP_FS__DEFAULT_PRIORITY,
19784
+ $accepted_args = 1
19785
+ ) {
19786
+ $this->_logger->entrance( $tag );
19787
+
19788
+ add_action( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
19789
+ }
19790
+
19791
+ /**
19792
+ * Add AJAX action, specific for the current context plugin.
19793
+ *
19794
+ * @author Vova Feldman (@svovaf)
19795
+ * @since 1.2.1
19796
+ *
19797
+ * @param string $tag
19798
+ * @param callable $function_to_add
19799
+ * @param int $priority
19800
+ *
19801
+ * @uses add_action()
19802
+ *
19803
+ * @return bool True if action added, false if no need to add the action since the AJAX call isn't matching.
19804
+ */
19805
+ function add_ajax_action(
19806
+ $tag,
19807
+ $function_to_add,
19808
+ $priority = WP_FS__DEFAULT_PRIORITY
19809
+ ) {
19810
+ $this->_logger->entrance( $tag );
19811
+
19812
+ return self::add_ajax_action_static(
19813
+ $tag,
19814
+ $function_to_add,
19815
+ $priority,
19816
+ $this->_module_id
19817
+ );
19818
+ }
19819
+
19820
+ /**
19821
+ * Add AJAX action.
19822
+ *
19823
+ * @author Vova Feldman (@svovaf)
19824
+ * @since 1.2.1.6
19825
+ *
19826
+ * @param string $tag
19827
+ * @param callable $function_to_add
19828
+ * @param int $priority
19829
+ * @param number|null $module_id
19830
+ *
19831
+ * @return bool True if action added, false if no need to add the action since the AJAX call isn't matching.
19832
+ * @uses add_action()
19833
+ *
19834
+ */
19835
+ static function add_ajax_action_static(
19836
+ $tag,
19837
+ $function_to_add,
19838
+ $priority = WP_FS__DEFAULT_PRIORITY,
19839
+ $module_id = null
19840
+ ) {
19841
+ self::$_static_logger->entrance( $tag );
19842
+
19843
+ if ( ! self::is_ajax_action_static( $tag, $module_id ) ) {
19844
+ return false;
19845
+ }
19846
+
19847
+ add_action(
19848
+ 'wp_ajax_' . self::get_ajax_action_static( $tag, $module_id ),
19849
+ $function_to_add,
19850
+ $priority,
19851
+ 0
19852
+ );
19853
+
19854
+ self::$_static_logger->info( "$tag AJAX callback action added." );
19855
+
19856
+ return true;
19857
+ }
19858
+
19859
+ /**
19860
+ * Send a JSON response back to an Ajax request.
19861
+ *
19862
+ * @author Vova Feldman (@svovaf)
19863
+ * @since 1.2.1.5
19864
+ *
19865
+ * @param mixed $response
19866
+ */
19867
+ static function shoot_ajax_response( $response ) {
19868
+ wp_send_json( $response );
19869
+ }
19870
+
19871
+ /**
19872
+ * Send a JSON response back to an Ajax request, indicating success.
19873
+ *
19874
+ * @author Vova Feldman (@svovaf)
19875
+ * @since 1.2.1.5
19876
+ *
19877
+ * @param mixed $data Data to encode as JSON, then print and exit.
19878
+ */
19879
+ static function shoot_ajax_success( $data = null ) {
19880
+ wp_send_json_success( $data );
19881
+ }
19882
+
19883
+ /**
19884
+ * Send a JSON response back to an Ajax request, indicating failure.
19885
+ *
19886
+ * @author Vova Feldman (@svovaf)
19887
+ * @since 1.2.1.5
19888
+ *
19889
+ * @param mixed $error Optional error message.
19890
+ */
19891
+ static function shoot_ajax_failure( $error = '' ) {
19892
+ $result = array( 'success' => false );
19893
+ if ( ! empty( $error ) ) {
19894
+ $result['error'] = $error;
19895
+ }
19896
+
19897
+ wp_send_json( $result );
19898
+ }
19899
+
19900
+ /**
19901
+ * Returns an AJAX URL with a special extra param to indicate whether the request was triggered from the network admin or blog admin.
19902
+ *
19903
+ * @author Vova Feldman (@svovaf)
19904
+ * @since 2.5.1
19905
+ *
19906
+ * @param string $wrap_with By default, returns the AJAX URL wrapped with single quotes.
19907
+ *
19908
+ * @return string
19909
+ */
19910
+ static function ajax_url( $wrap_with = "'") {
19911
+ if ( fs_is_network_admin() ) {
19912
+ $param_name = '_fs_network_admin';
19913
+ } else {
19914
+ $param_name = '_fs_blog_admin';
19915
+ }
19916
+
19917
+ $url = admin_url( 'admin-ajax.php', 'relative' );
19918
+ $url .= ( false === strpos( $url, '?' ) ) ? '?' : '&';
19919
+ $url .= "{$param_name}=true";
19920
+
19921
+ return "{$wrap_with}{$url}{$wrap_with}";
19922
+ }
19923
+
19924
+ /**
19925
+ * Apply filter, specific for the current context plugin.
19926
+ *
19927
+ * @author Vova Feldman (@svovaf)
19928
+ * @since 1.0.9
19929
+ *
19930
+ * @param string $tag The name of the filter hook.
19931
+ * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
19932
+ *
19933
+ * @return mixed The filtered value after all hooked functions are applied to it.
19934
+ *
19935
+ * @uses apply_filters()
19936
+ */
19937
+ function apply_filters( $tag, $value ) {
19938
+ $args = func_get_args();
19939
+
19940
+ $this->_logger->entrance( $tag );
19941
+
19942
+ array_unshift( $args, $this->get_unique_affix() );
19943
+
19944
+ return call_user_func_array( 'fs_apply_filter', $args );
19945
+ }
19946
+
19947
+ /**
19948
+ * Add filter, specific for the current context plugin.
19949
+ *
19950
+ * @author Vova Feldman (@svovaf)
19951
+ * @since 1.0.9
19952
+ *
19953
+ * @param string $tag
19954
+ * @param callable $function_to_add
19955
+ * @param int $priority
19956
+ * @param int $accepted_args
19957
+ *
19958
+ * @uses add_filter()
19959
+ */
19960
+ function add_filter( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
19961
+ $this->_logger->entrance( $tag );
19962
+
19963
+ add_filter( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
19964
+ }
19965
+
19966
+ /**
19967
+ * Check if has filter.
19968
+ *
19969
+ * @author Vova Feldman (@svovaf)
19970
+ * @since 1.1.4
19971
+ *
19972
+ * @param string $tag
19973
+ * @param callable|bool $function_to_check Optional. The callback to check for. Default false.
19974
+ *
19975
+ * @return false|int
19976
+ *
19977
+ * @uses has_filter()
19978
+ */
19979
+ function has_filter( $tag, $function_to_check = false ) {
19980
+ $this->_logger->entrance( $tag );
19981
+
19982
+ return has_filter( $this->get_action_tag( $tag ), $function_to_check );
19983
+ }
19984
+
19985
+ #endregion
19986
+
19987
+ /**
19988
+ * Override default i18n text phrases.
19989
+ *
19990
+ * @author Vova Feldman (@svovaf)
19991
+ * @since 1.1.6
19992
+ *
19993
+ * @param string[] string $key_value
19994
+ *
19995
+ * @uses fs_override_i18n()
19996
+ */
19997
+ function override_i18n( $key_value ) {
19998
+ fs_override_i18n( $key_value, $this->_slug );
19999
+ }
20000
+
20001
+ /* Account Page
20002
+ ------------------------------------------------------------------------------------------------------------------*/
20003
+ /**
20004
+ * Update site information.
20005
+ *
20006
+ * @author Vova Feldman (@svovaf)
20007
+ * @since 1.0.1
20008
+ *
20009
+ * @param bool $store Flush to Database if true.
20010
+ * @param null|int $network_level_or_blog_id Since 2.0.0
20011
+ * @param \FS_Site $site Since 2.0.0
20012
+ */
20013
+ private function _store_site( $store = true, $network_level_or_blog_id = null, FS_Site $site = null, $is_backup = false ) {
20014
+ $this->_logger->entrance();
20015
+
20016
+ if ( is_null( $site ) ) {
20017
+ $site = $this->_site;
20018
+ }
20019
+
20020
+ if ( !isset( $site ) || !is_object($site) || empty( $site->id ) ) {
20021
+ $this->_logger->error( "Empty install ID, can't store site." );
20022
+
20023
+ return;
20024
+ }
20025
+
20026
+ $site_clone = clone $site;
20027
+
20028
+ $sites = self::get_all_sites( $this->_module_type, $network_level_or_blog_id, $is_backup );
20029
+
20030
+ if (
20031
+ ! $is_backup &&
20032
+ is_object( $this->_user ) && $this->_user->id != $site->user_id
20033
+ ) {
20034
+ $this->sync_user_by_current_install( $site->user_id );
20035
+
20036
+ $prev_stored_user_id = $this->_storage->get( 'prev_user_id', false, $network_level_or_blog_id );
20037
+
20038
+ if ( empty( $prev_stored_user_id ) &&
20039
+ is_object($this->_user) && $this->_user->id != $site->user_id
20040
+ ) {
20041
+ /**
20042
+ * Store the current user ID as the previous user ID so that the previous user can be used
20043
+ * as the install's owner while the new owner's details are not yet available.
20044
+ *
20045
+ * This will be executed only in the `replica` site. For example, there are 2 sites, namely `original`
20046
+ * and `replica`, then an ownership change was initiated and completed in the `original`, the `replica`
20047
+ * will be using the previous user until it is updated again (e.g.: until the next clone of `original`
20048
+ * into `replica`.
20049
+ *
20050
+ * @author Leo Fajardo (@leorw)
20051
+ */
20052
+ $this->_storage->store( 'prev_user_id', $sites[ $this->_slug ]->user_id, $network_level_or_blog_id );
20053
+ }
20054
+ }
20055
+
20056
+ $sites[ $this->_slug ] = $site_clone;
20057
+
20058
+ $this->set_account_option(
20059
+ ( $is_backup ? 'prev_' : '' ) . 'sites',
20060
+ $sites,
20061
+ $store,
20062
+ $network_level_or_blog_id
20063
+ );
20064
+ }
20065
+
20066
+ /**
20067
+ * Stores the context site in the sites backup storage. This logic is used before deleting the site info so that it can be restored later on if necessary (e.g., if the automatic clone resolution attempt fails).
20068
+ *
20069
+ * @author Leo Fajardo (@leorw)
20070
+ * @since 2.5.0
20071
+ */
20072
+ private function back_up_site() {
20073
+ $this->_logger->entrance();
20074
+
20075
+ $site_clone = clone $this->_site;
20076
+
20077
+ $this->_store_site( true, null, $site_clone, true );
20078
+ }
20079
+
20080
+ /**
20081
+ * Update plugin's plans information.
20082
+ *
20083
+ * @author Vova Feldman (@svovaf)
20084
+ * @since 1.0.2
20085
+ *
20086
+ * @param bool $store Flush to Database if true.
20087
+ */
20088
+ private function _store_plans( $store = true ) {
20089
+ $this->_logger->entrance();
20090
+
20091
+ $plans = self::get_all_plans( $this->_module_type );
20092
+
20093
+ // Copy plans.
20094
+ $encrypted_plans = array();
20095
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
20096
+ $encrypted_plans[] = self::_encrypt_entity( $this->_plans[ $i ] );
20097
+ }
20098
+
20099
+ $plans[ $this->_slug ] = $encrypted_plans;
20100
+
20101
+ $this->set_account_option( 'plans', $plans, $store );
20102
+ }
20103
+
20104
+ /**
20105
+ * Update user's plugin licenses.
20106
+ *
20107
+ * @author Vova Feldman (@svovaf)
20108
+ * @since 1.0.5
20109
+ *
20110
+ * @param bool $store
20111
+ * @param number|bool $module_id
20112
+ * @param FS_Plugin_License[] $licenses
20113
+ */
20114
+ private function _store_licenses( $store = true, $module_id = false, $licenses = array() ) {
20115
+ $this->_logger->entrance();
20116
+
20117
+ $all_licenses = self::get_all_licenses();
20118
+
20119
+ if ( ! FS_Plugin::is_valid_id( $module_id ) ) {
20120
+ $module_id = $this->_module_id;
20121
+
20122
+ $user_licenses = is_array( $this->_licenses ) ?
20123
+ $this->_licenses :
20124
+ array();
20125
+
20126
+ if ( empty( $user_licenses ) ) {
20127
+ // If the context user doesn't have any license, don't update the licenses collection.
20128
+ return;
20129
+ }
20130
+
20131
+ $new_user_licenses_map = array();
20132
+ foreach ( $user_licenses as $user_license ) {
20133
+ $new_user_licenses_map[ $user_license->id ] = $user_license;
20134
+ }
20135
+
20136
+ self::store_user_id_license_ids_map( array_keys( $new_user_licenses_map ), $this->_module_id, $this->_user->id );
20137
+
20138
+ // Update user licenses.
20139
+ $licenses_to_update_count = count( $new_user_licenses_map );
20140
+ foreach ( $all_licenses[ $module_id ] as $key => $license ) {
20141
+ if ( 0 === $licenses_to_update_count ) {
20142
+ break;
20143
+ }
20144
+
20145
+ if ( isset( $new_user_licenses_map[ $license->id ] ) ) {
20146
+ // Update license.
20147
+ $all_licenses[ $module_id ][ $key ] = $new_user_licenses_map[ $license->id ];
20148
+ unset( $new_user_licenses_map[ $license->id ] );
20149
+
20150
+ $licenses_to_update_count --;
20151
+ }
20152
+ }
20153
+
20154
+ if ( ! empty( $new_user_licenses_map ) ) {
20155
+ // Add new licenses.
20156
+ $all_licenses[ $module_id ] = array_merge( array_values( $new_user_licenses_map ), $all_licenses[ $module_id ] );
20157
+ }
20158
+
20159
+ $licenses = $all_licenses[ $module_id ];
20160
+ }
20161
+
20162
+ if ( ! isset( $all_licenses[ $module_id ] ) ) {
20163
+ $all_licenses[ $module_id ] = array();
20164
+ }
20165
+
20166
+ $all_licenses[ $module_id ] = $licenses;
20167
+
20168
+ self::$_accounts->set_option( 'all_licenses', $all_licenses, $store );
20169
+ }
20170
+
20171
+ /**
20172
+ * Update user information.
20173
+ *
20174
+ * @author Vova Feldman (@svovaf)
20175
+ * @since 1.0.1
20176
+ *
20177
+ * @param bool $store Flush to Database if true.
20178
+ */
20179
+ private function _store_user( $store = true ) {
20180
+ $this->_logger->entrance();
20181
+
20182
+ if ( empty( $this->_user->id ) ) {
20183
+ $this->_logger->error( "Empty user ID, can't store user." );
20184
+
20185
+ return;
20186
+ }
20187
+
20188
+ $users = self::get_all_users();
20189
+ $users[ $this->_user->id ] = $this->_user;
20190
+ self::$_accounts->set_option( 'users', $users, $store );
20191
+ }
20192
+
20193
+ /**
20194
+ * Update new updates information.
20195
+ *
20196
+ * @author Vova Feldman (@svovaf)
20197
+ * @since 1.0.4
20198
+ *
20199
+ * @param FS_Plugin_Tag|null $update
20200
+ * @param bool $store Flush to Database if true.
20201
+ * @param bool|number $plugin_id
20202
+ */
20203
+ private function _store_update( $update, $store = true, $plugin_id = false ) {
20204
+ $this->_logger->entrance();
20205
+
20206
+ if ( $update instanceof FS_Plugin_Tag ) {
20207
+ $update->updated = time();
20208
+ }
20209
+
20210
+ if ( ! is_numeric( $plugin_id ) ) {
20211
+ $plugin_id = $this->_plugin->id;
20212
+ }
20213
+
20214
+ $updates = self::get_all_updates();
20215
+ $updates[ $plugin_id ] = $update;
20216
+ self::$_accounts->set_option( 'updates', $updates, $store );
20217
+ }
20218
+
20219
+ /**
20220
+ * Update new updates information.
20221
+ *
20222
+ * @author Vova Feldman (@svovaf)
20223
+ * @since 1.0.6
20224
+ *
20225
+ * @param FS_Plugin[] $plugin_addons
20226
+ * @param bool $store Flush to Database if true.
20227
+ */
20228
+ private function _store_addons( $plugin_addons, $store = true ) {
20229
+ $this->_logger->entrance();
20230
+
20231
+ $addons = self::get_all_addons();
20232
+ $addons[ $this->_plugin->id ] = $plugin_addons;
20233
+ self::$_accounts->set_option( 'addons', $addons, $store );
20234
+ }
20235
+
20236
+ /**
20237
+ * Delete plugin's associated add-ons.
20238
+ *
20239
+ * @author Vova Feldman (@svovaf)
20240
+ * @since 1.0.8
20241
+ *
20242
+ * @param bool $store
20243
+ *
20244
+ * @return bool
20245
+ */
20246
+ private function _delete_account_addons( $store = true ) {
20247
+ $all_addons = self::get_all_account_addons();
20248
+
20249
+ if ( ! isset( $all_addons[ $this->_plugin->id ] ) ) {
20250
+ return false;
20251
+ }
20252
+
20253
+ unset( $all_addons[ $this->_plugin->id ] );
20254
+
20255
+ self::$_accounts->set_option( 'account_addons', $all_addons, $store );
20256
+
20257
+ return true;
20258
+ }
20259
+
20260
+ /**
20261
+ * Update account add-ons list.
20262
+ *
20263
+ * @author Vova Feldman (@svovaf)
20264
+ * @since 1.0.6
20265
+ *
20266
+ * @param FS_Plugin[] $addons
20267
+ * @param bool $store Flush to Database if true.
20268
+ */
20269
+ private function _store_account_addons( $addons, $store = true ) {
20270
+ $this->_logger->entrance();
20271
+
20272
+ $all_addons = self::get_all_account_addons();
20273
+ $all_addons[ $this->_plugin->id ] = $addons;
20274
+ self::$_accounts->set_option( 'account_addons', $all_addons, $store );
20275
+ }
20276
+
20277
+ /**
20278
+ * Purges the cache for the valid user licenses API call so that when the `Account` or `Add-Ons` page is loaded,
20279
+ * the valid user licenses will be fetched again and the account add-ons may be updated.
20280
+ *
20281
+ * @author Leo Fajardo (@leorw)
20282
+ * @since 2.2.4
20283
+ */
20284
+ private function purge_valid_user_licenses_cache() {
20285
+ if ( ! $this->is_registered() ) {
20286
+ return;
20287
+ }
20288
+
20289
+ $this->get_api_user_scope()->purge_cache( $this->get_valid_user_licenses_endpoint() );
20290
+ }
20291
+
20292
+ /**
20293
+ * @author Leo Fajardo (@leorw)
20294
+ * @since 2.3.0
20295
+ *
20296
+ * @param array $all_licenses
20297
+ * @param number|null $site_license_id
20298
+ * @param bool $include_parent_licenses
20299
+ *
20300
+ * @return array
20301
+ */
20302
+ private function get_foreign_licenses_info( $all_licenses, $site_license_id = null, $include_parent_licenses = false ) {
20303
+ $foreign_licenses = array(
20304
+ 'ids' => array(),
20305
+ 'license_keys' => array()
20306
+ );
20307
+
20308
+ $parent_license_ids_map = array();
20309
+
20310
+ foreach ( $all_licenses as $license ) {
20311
+ if ( $license->user_id == $this->_user->id || $license->id == $site_license_id ) {
20312
+ continue;
20313
+ }
20314
+
20315
+ $foreign_licenses['ids'][] = $license->id;
20316
+ $foreign_licenses['license_keys'][] = $license->secret_key;
20317
+
20318
+ if (
20319
+ $include_parent_licenses &&
20320
+ is_object( $this->_license ) &&
20321
+ FS_Plugin_License::is_valid_id( $this->_license->parent_license_id ) &&
20322
+ ! isset( $parent_license_ids_map[ $this->_license->parent_license_id ] )
20323
+ ) {
20324
+ /**
20325
+ * Include the parent license's info only if it has not been included before since child licenses
20326
+ * can have the same parent license.
20327
+ */
20328
+ $foreign_licenses['ids'][] = $this->_license->parent_license_id;
20329
+ $foreign_licenses['license_keys'][] = $license->secret_key;
20330
+
20331
+ $parent_license_ids_map[ $this->_license->parent_license_id ] = true;
20332
+ }
20333
+ }
20334
+
20335
+ if ( empty( $foreign_licenses['ids'] ) ) {
20336
+ $foreign_licenses = array();
20337
+ }
20338
+
20339
+ return $foreign_licenses;
20340
+ }
20341
+
20342
+ /**
20343
+ * @author Leo Fajardo (@leorw)
20344
+ * @since 2.3.0
20345
+ *
20346
+ * @return string
20347
+ */
20348
+ private function get_valid_user_licenses_endpoint() {
20349
+ $user_licenses_endpoint = '/licenses.json?type=active' .
20350
+ ( FS_Plugin::is_valid_id( $this->get_bundle_id() ) ? '&is_enriched=true' : '' );
20351
+
20352
+ $foreign_licenses = $this->get_foreign_licenses_info( self::get_all_licenses( $this->_module_id ), null, true );
20353
+
20354
+ if ( ! empty ( $foreign_licenses ) ) {
20355
+ $foreign_licenses = array(
20356
+ // Prefix with `+` to tell the server to include foreign licenses in the licenses collection.
20357
+ 'ids' => ( urlencode( '+' ) . implode( ',', $foreign_licenses['ids'] ) ),
20358
+ 'license_keys' => implode( ',', array_map( 'urlencode', $foreign_licenses['license_keys'] ) )
20359
+ );
20360
+
20361
+ $user_licenses_endpoint = add_query_arg( $foreign_licenses, $user_licenses_endpoint );
20362
+ }
20363
+
20364
+ return $user_licenses_endpoint;
20365
+ }
20366
+
20367
+ /**
20368
+ * Fetches active licenses that are enriched with product type if there's a context `bundle_id` and bundle
20369
+ * licenses enriched with product IDs if there are any. From the licenses, the `get_updated_account_addons`
20370
+ * method filters out non–add-on product IDs and stores the add-on IDs.
20371
+ *
20372
+ * @author Leo Fajardo (@leorw)
20373
+ * @since 2.2.4
20374
+ *
20375
+ * @return stdClass[] array
20376
+ */
20377
+ private function fetch_valid_user_licenses() {
20378
+ $this->_logger->entrance();
20379
+
20380
+ $result = $this->get_api_user_scope()->get( $this->get_valid_user_licenses_endpoint() );
20381
+
20382
+ if ( ! $this->is_api_result_object( $result, 'licenses' ) ||
20383
+ ! is_array( $result->licenses )
20384
+ ) {
20385
+ return array();
20386
+ }
20387
+
20388
+ return $result->licenses;
20389
+ }
20390
+
20391
+ /**
20392
+ * @author Leo Fajardo (@leorw)
20393
+ * @since 2.2.4
20394
+ *
20395
+ * @return number[] Account add-on IDs.
20396
+ */
20397
+ function get_updated_account_addons() {
20398
+ $addons = $this->get_addons();
20399
+ if ( empty( $addons ) ) {
20400
+ return array();
20401
+ }
20402
+
20403
+ $account_addons = $this->get_account_addons();
20404
+ if ( ! is_array( $account_addons ) ) {
20405
+ $account_addons = array();
20406
+ }
20407
+
20408
+ $user_licenses = $this->is_registered() ?
20409
+ $this->fetch_valid_user_licenses() :
20410
+ array();
20411
+
20412
+ if ( empty( $user_licenses ) ) {
20413
+ return $account_addons;
20414
+ }
20415
+
20416
+ $addon_ids = array();
20417
+ foreach ( $addons as $addon ) {
20418
+ $addon_ids[] = $addon->id;
20419
+ }
20420
+
20421
+ $license_product_ids = array();
20422
+
20423
+ foreach ( $user_licenses as $license ) {
20424
+ if ( isset( $license->plugin_type ) && 'bundle' === $license->plugin_type ) {
20425
+ $license_product_ids = array_merge( $license_product_ids, $license->products );
20426
+ } else {
20427
+ $license_product_ids[] = $license->plugin_id;
20428
+ }
20429
+ }
20430
+
20431
+ // Filter out non–add-on IDs.
20432
+ $new_account_addons = array_intersect( $addon_ids, $license_product_ids );
20433
+ if ( count( $new_account_addons ) !== count( $account_addons ) ) {
20434
+ $this->_store_account_addons( array_unique( $new_account_addons ) );
20435
+ }
20436
+
20437
+ return $new_account_addons;
20438
+ }
20439
+
20440
+ /**
20441
+ * Store account params in the Database.
20442
+ *
20443
+ * @author Vova Feldman (@svovaf)
20444
+ * @since 1.0.1
20445
+ *
20446
+ * @param null|int $blog_id Since 2.0.0
20447
+ */
20448
+ private function _store_account( $blog_id = null ) {
20449
+ $this->_logger->entrance();
20450
+
20451
+ $this->_store_site( false, $blog_id );
20452
+ $this->_store_user( false );
20453
+ $this->_store_plans( false );
20454
+ $this->_store_licenses( false );
20455
+
20456
+ self::$_accounts->store( $blog_id );
20457
+ }
20458
+
20459
+ /**
20460
+ * Sync user's information.
20461
+ *
20462
+ * @author Vova Feldman (@svovaf)
20463
+ * @since 1.0.3
20464
+ * @uses FS_Api
20465
+ */
20466
+ private function _handle_account_user_sync() {
20467
+ $this->_logger->entrance();
20468
+
20469
+ $api = $this->get_api_user_scope();
20470
+
20471
+ // Get user's information.
20472
+ $user = $api->get( '/', true );
20473
+
20474
+ if ( isset( $user->id ) ) {
20475
+ $this->_user->first = $user->first;
20476
+ $this->_user->last = $user->last;
20477
+ $this->_user->email = $user->email;
20478
+
20479
+ $is_menu_item_account_visible = $this->is_submenu_item_visible( 'account' );
20480
+
20481
+ if ( $user->is_verified &&
20482
+ ( ! isset( $this->_user->is_verified ) || false === $this->_user->is_verified )
20483
+ ) {
20484
+ $this->_user->is_verified = true;
20485
+
20486
+ $this->do_action( 'account_email_verified', $user->email );
20487
+
20488
+ $this->_admin_notices->add(
20489
+ $this->get_text_inline( 'Your email has been successfully verified - you are AWESOME!', 'email-verified-message' ),
20490
+ $this->get_text_x_inline( 'Right on', 'a positive response', 'right-on' ) . '!',
20491
+ 'success',
20492
+ // Make admin sticky if account menu item is invisible,
20493
+ // since the page will be auto redirected to the plugin's
20494
+ // main settings page, and the non-sticky message
20495
+ // will disappear.
20496
+ ! $is_menu_item_account_visible,
20497
+ 'email_verified'
20498
+ );
20499
+ }
20500
+
20501
+ // Flush user details to DB.
20502
+ $this->_store_user();
20503
+
20504
+ $this->do_action( 'after_account_user_sync', $user );
20505
+
20506
+ /**
20507
+ * If account menu item is hidden, redirect to plugin's main settings page.
20508
+ *
20509
+ * @author Vova Feldman (@svovaf)
20510
+ * @since 1.1.6
20511
+ *
20512
+ * @link https://github.com/Freemius/wordpress-sdk/issues/6
20513
+ */
20514
+ if ( ! $is_menu_item_account_visible ) {
20515
+ fs_redirect( $this->_get_admin_page_url() );
20516
+ }
20517
+ }
20518
+ }
20519
+
20520
+ /**
20521
+ * @author Vova Feldman (@svovaf)
20522
+ * @since 1.0.9
20523
+ * @uses FS_Api
20524
+ *
20525
+ * @param number|bool $license_id
20526
+ *
20527
+ * @return FS_Subscription|object|bool
20528
+ */
20529
+ private function _fetch_site_license_subscription( $license_id = false ) {
20530
+ $this->_logger->entrance();
20531
+ $api = $this->get_api_site_scope();
20532
+
20533
+ if ( ! is_numeric( $license_id ) ) {
20534
+ $license_id = FS_Plugin_License::is_valid_id( $this->_license->parent_license_id ) ?
20535
+ $this->_license->parent_license_id :
20536
+ $this->_license->id;
20537
+ }
20538
+
20539
+ $result = $api->get( "/licenses/{$license_id}/subscriptions.json", true );
20540
+
20541
+ return ! isset( $result->error ) ?
20542
+ ( ( is_array( $result->subscriptions ) && 0 < count( $result->subscriptions ) ) ?
20543
+ new FS_Subscription( $result->subscriptions[0] ) :
20544
+ false
20545
+ ) :
20546
+ $result;
20547
+ }
20548
+
20549
+ /**
20550
+ * @author Vova Feldman (@svovaf)
20551
+ * @since 1.0.4
20552
+ * @uses FS_Api
20553
+ *
20554
+ * @param number|bool $plan_id
20555
+ *
20556
+ * @return FS_Plugin_Plan|object
20557
+ */
20558
+ private function _fetch_site_plan( $plan_id = false ) {
20559
+ $this->_logger->entrance();
20560
+ $api = $this->get_api_site_scope();
20561
+
20562
+ if ( ! is_numeric( $plan_id ) ) {
20563
+ $plan_id = $this->_site->plan_id;
20564
+ }
20565
+
20566
+ $plan = $api->get( "/plans/{$plan_id}.json", true );
20567
+
20568
+ return ! isset( $plan->error ) ? new FS_Plugin_Plan( $plan ) : $plan;
20569
+ }
20570
+
20571
+ /**
20572
+ * @auth