| 1 |
<?php |
| 2 |
defined( 'ABSPATH' ) || exit; |
| 3 |
require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; |
| 4 |
|
| 5 |
if ( ! class_exists( 'YayRecommended' ) ) { |
| 6 |
class YayRecommended { |
| 7 |
|
| 8 |
public $pluginPrefix = ''; |
| 9 |
public $subMenuSlug = ''; |
| 10 |
public $recommendedPlugin = array(); |
| 11 |
|
| 12 |
public function __construct( $pluginPrefix ) { |
| 13 |
$this->pluginPrefix = $pluginPrefix; |
| 14 |
$this->recommendedPlugin = $this->get_recommended_plugins(); |
| 15 |
$this->doHooks(); |
| 16 |
} |
| 17 |
|
| 18 |
public function doHooks() { |
| 19 |
add_action( |
| 20 |
'init', |
| 21 |
function() { |
| 22 |
add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
| 23 |
add_action( 'admin_footer', array( $this, 'add_global_script_styles' ) ); |
| 24 |
add_action( 'wp_ajax_yay_recommended_get_plugin_data', array( $this, 'yay_recommended_get_plugin_data' ) ); |
| 25 |
add_action( 'wp_ajax_yay_recommended_activate_plugin', array( $this, 'yay_recommended_activate_plugin' ) ); |
| 26 |
add_action( 'wp_ajax_yay_recommended_upgrade_plugin', array( $this, 'yay_recommended_upgrade_plugin' ) ); |
| 27 |
} |
| 28 |
); |
| 29 |
} |
| 30 |
|
| 31 |
private function get_recommended_plugins() { |
| 32 |
$recommendedPlugins = array( |
| 33 |
'filebird' => array( |
| 34 |
'slug' => 'filebird', |
| 35 |
'name' => __( 'FileBird - WordPress Media Library Folders & File Manager', 'filebird' ), |
| 36 |
'short_description' => __( 'Organize thousands of WordPress media files in folders / categories at ease.', 'filebird' ), |
| 37 |
'icon' => 'https://ps.w.org/filebird/assets/icon-128x128.gif?rev=2299145', |
| 38 |
'download_link' => 'https://downloads.wordpress.org/plugin/filebird.zip', |
| 39 |
'type' => array( 'featured' ), |
| 40 |
'version' => 0, |
| 41 |
), |
| 42 |
'yaymail' => array( |
| 43 |
'slug' => 'yaymail', |
| 44 |
'name' => __( 'YayMail - WooCommerce Email Customizer', 'filebird' ), |
| 45 |
'short_description' => __( 'Customize WooCommerce email templates with live preview & drag and drop email builder.', 'filebird' ), |
| 46 |
'icon' => 'https://ps.w.org/yaymail/assets/icon-256x256.gif?rev=2599198', |
| 47 |
'download_link' => 'https://downloads.wordpress.org/plugin/yaymail.zip', |
| 48 |
'type' => array( 'featured', 'woocommerce' ), |
| 49 |
'version' => 0, |
| 50 |
), |
| 51 |
'yaycurrency' => array( |
| 52 |
'slug' => 'yaycurrency', |
| 53 |
'name' => __( 'YayCurrency - WooCommerce Multi-Currency Switcher', 'filebird' ), |
| 54 |
'short_description' => __( 'WooCommerce Multi-Currency made easy, powerful, and flexible.', 'filebird' ), |
| 55 |
'icon' => 'https://ps.w.org/yaycurrency/assets/icon-256x256.png?rev=2550570', |
| 56 |
'download_link' => 'https://downloads.wordpress.org/plugin/yaycurrency.zip', |
| 57 |
'type' => array( 'featured', 'woocommerce' ), |
| 58 |
'version' => 0, |
| 59 |
), |
| 60 |
'yayswatches' => array( |
| 61 |
'slug' => 'yayswatches', |
| 62 |
'name' => __( 'YaySwatches - Variation Swatches for WooCommerce', 'filebird' ), |
| 63 |
'short_description' => __( 'Optimize your variable product showcase with color swatches, image swatches, custom images, buttons, and more!', 'filebird' ), |
| 64 |
'icon' => 'https://ps.w.org/yayswatches/assets/icon-256x256.png?rev=2757155', |
| 65 |
'download_link' => 'https://downloads.wordpress.org/plugin/yayswatches.zip', |
| 66 |
'type' => array( 'woocommerce' ), |
| 67 |
'version' => 0, |
| 68 |
), |
| 69 |
'yayextra' => array( |
| 70 |
'slug' => 'yayextra', |
| 71 |
'name' => __( 'YayExtra - WooCommerce Extra Product Options', 'filebird' ), |
| 72 |
'short_description' => __( 'Add WooCommerce product options like personal engraving, print-on-demand items, gifts, custom canvas prints, and personalized products.', 'filebird' ), |
| 73 |
'icon' => 'https://ps.w.org/yayextra/assets/icon-256x256.png?rev=2776349', |
| 74 |
'download_link' => 'https://downloads.wordpress.org/plugin/yayextra.zip', |
| 75 |
'type' => array( 'woocommerce' ), |
| 76 |
'version' => 0, |
| 77 |
), |
| 78 |
'yaypricing' => array( |
| 79 |
'slug' => 'yaypricing', |
| 80 |
'name' => __( 'YayPricing - WooCommerce Dynamic Pricing & Discounts', 'filebird' ), |
| 81 |
'short_description' => __( 'Offer automatic pricing and discounts to design a powerful marketing strategy for your WooCommerce store.', 'filebird' ), |
| 82 |
'icon' => 'https://yaycommerce.com/wp-content/uploads/2022/11/yaypricing-256x256-1.png', |
| 83 |
'download_link' => 'https://yaycommerce.com/yaypricing-woocommerce-dynamic-pricing-and-discounts/', |
| 84 |
'type' => array( 'woocommerce' ), |
| 85 |
'version' => 0, |
| 86 |
), |
| 87 |
'yaysmtp' => array( |
| 88 |
'slug' => 'yaysmtp', |
| 89 |
'name' => __( 'YaySMTP - Simple WP SMTP Mail', 'filebird' ), |
| 90 |
'short_description' => __( 'Send WordPress emails successfully with WP Mail SMTP via your favorite Mailer.', 'filebird' ), |
| 91 |
'icon' => 'https://ps.w.org/yaysmtp/assets/icon-256x256.png?rev=2437984', |
| 92 |
'download_link' => 'https://downloads.wordpress.org/plugin/yaysmtp.zip', |
| 93 |
'type' => array( 'featured', 'marketing' ), |
| 94 |
'version' => 0, |
| 95 |
), |
| 96 |
'wp-whatsapp' => array( |
| 97 |
'slug' => 'wp-whatsapp', |
| 98 |
'name' => __( 'WP Chat App', 'filebird' ), |
| 99 |
'short_description' => __( 'Integrate WhatsApp experience directly into your WordPress website.', 'filebird' ), |
| 100 |
'icon' => 'https://ps.w.org/wp-whatsapp/assets/icon-256x256.png?rev=2725670', |
| 101 |
'download_link' => 'https://downloads.wordpress.org/plugin/wp-whatsapp.zip', |
| 102 |
'type' => array( 'featured' ), |
| 103 |
'version' => 0, |
| 104 |
), |
| 105 |
'filester' => array( |
| 106 |
'slug' => 'filester', |
| 107 |
'name' => __( 'Filester - File Manager Pro', 'filebird' ), |
| 108 |
'short_description' => __( 'Best WordPress file manager without FTP access. Clean design. No need to upgrade because this…', 'filebird' ), |
| 109 |
'icon' => 'https://ps.w.org/filester/assets/icon-256x256.gif?rev=2305540', |
| 110 |
'download_link' => 'https://downloads.wordpress.org/plugin/filester.zip', |
| 111 |
'type' => array( 'management' ), |
| 112 |
'version' => 0, |
| 113 |
), |
| 114 |
'cf7-multi-step' => array( |
| 115 |
'slug' => 'cf7-multi-step', |
| 116 |
'name' => __( 'Multi Step for Contact Form 7', 'filebird' ), |
| 117 |
'short_description' => __( 'Break your looooooong form into user-friendly steps.', 'filebird' ), |
| 118 |
'icon' => 'https://ps.w.org/cf7-multi-step/assets/icon-256x256.png?rev=1994366', |
| 119 |
'download_link' => 'https://downloads.wordpress.org/plugin/cf7-multi-step.zip', |
| 120 |
'type' => array( 'management' ), |
| 121 |
'version' => 0, |
| 122 |
), |
| 123 |
'cf7-database' => array( |
| 124 |
'slug' => 'cf7-database', |
| 125 |
'name' => __( 'Database for Contact Form 7', 'filebird' ), |
| 126 |
'short_description' => __( 'Automatically save all data submitted via Contact Form 7 to your database.', 'filebird' ), |
| 127 |
'icon' => 'https://ps.w.org/cf7-database/assets/icon-128x128.png?rev=1614091', |
| 128 |
'download_link' => 'https://downloads.wordpress.org/plugin/cf7-database.zip', |
| 129 |
'type' => array( 'management' ), |
| 130 |
'version' => 0, |
| 131 |
), |
| 132 |
'wp-duplicate-page' => array( |
| 133 |
'slug' => 'wp-duplicate-page', |
| 134 |
'name' => __( 'WP Duplicate Page', 'filebird' ), |
| 135 |
'short_description' => __( 'Clone WordPress page, post, custom post types.', 'filebird' ), |
| 136 |
'icon' => 'https://ps.w.org/wp-duplicate-page/assets/icon-256x256.gif?rev=2432962', |
| 137 |
'download_link' => 'https://downloads.wordpress.org/plugin/wp-duplicate-page.zip', |
| 138 |
'type' => array( 'management' ), |
| 139 |
'version' => 0, |
| 140 |
), |
| 141 |
'notibar' => array( |
| 142 |
'slug' => 'notibar', |
| 143 |
'name' => __( 'Notibar - Notification Bar for WordPress', 'filebird' ), |
| 144 |
'short_description' => __( 'Customizer for sticky header, notification bar, alert, promo code, marketing campaign, top banner.', 'filebird' ), |
| 145 |
'icon' => 'https://ps.w.org/notibar/assets/icon-256x256.png?rev=2387855', |
| 146 |
'download_link' => 'https://downloads.wordpress.org/plugin/notibar.zip', |
| 147 |
'type' => array( 'marketing' ), |
| 148 |
'version' => 0, |
| 149 |
), |
| 150 |
); |
| 151 |
return $recommendedPlugins; |
| 152 |
} |
| 153 |
|
| 154 |
public function admin_menu() { |
| 155 |
$this->subMenuSlug = add_submenu_page( 'nta_whatsapp', __( 'Recommended Plugins', 'filebird' ), __( 'Recommended Plugins', 'filebird' ), 'manage_options', 'nta_whatsapp_recommended_plugins', array( $this, 'recommended_plugins_view' ) ); |
| 156 |
} |
| 157 |
|
| 158 |
public function recommended_plugins_view() { |
| 159 |
if ( function_exists( 'WC' ) ) { |
| 160 |
$featuredTab = '<li class="plugin-install-tab plugin-install-featured" data-tab="featured"><a href="#" >' . esc_html__( 'Featured', 'filebird' ) . '</a> </li>'; |
| 161 |
$wooTab = '<li class="plugin-install-tab plugin-install-woocommerce" data-tab="woocommerce"><a href="#" class="current" aria-current="page">' . esc_html__( 'WooCommerce', 'filebird' ) . '</a> </li>'; |
| 162 |
} else { |
| 163 |
$featuredTab = '<li class="plugin-install-tab plugin-install-featured" data-tab="featured"><a href="#" class="current" aria-current="page">' . esc_html__( 'Featured', 'filebird' ) . '</a> </li>'; |
| 164 |
$wooTab = '<li class="plugin-install-tab plugin-install-woocommerce" data-tab="woocommerce"><a href="#" >' . esc_html__( 'WooCommerce', 'filebird' ) . '</a> </li>'; |
| 165 |
} |
| 166 |
?> |
| 167 |
<style> |
| 168 |
.yay-recommended-plugins-layout { |
| 169 |
margin-top: 20px; |
| 170 |
} |
| 171 |
.wrap .notice, .wrap .error { |
| 172 |
display: none !important; |
| 173 |
} |
| 174 |
.yay-recommended-plugins-layout-header { |
| 175 |
background: #fff; |
| 176 |
box-sizing: border-box; |
| 177 |
padding: 0; |
| 178 |
z-index: 1001; |
| 179 |
} |
| 180 |
|
| 181 |
.yay-recommended-plugins-header{ |
| 182 |
display: flex; |
| 183 |
flex-wrap: wrap; |
| 184 |
justify-content: space-between; |
| 185 |
align-items: center; |
| 186 |
position: relative; |
| 187 |
box-sizing: border-box; |
| 188 |
margin: 12px 0 25px; |
| 189 |
padding: 0 10px; |
| 190 |
width: 100%; |
| 191 |
box-shadow: 0 1px 1px rgb(0 0 0 / 4%); |
| 192 |
border: 1px solid #c3c4c7; |
| 193 |
background: #fff; |
| 194 |
color: #50575e; |
| 195 |
font-size: 13px; |
| 196 |
} |
| 197 |
.yay-recommended-plugins-header-title { |
| 198 |
font-size: 1.2em; |
| 199 |
margin-left: 8px; |
| 200 |
} |
| 201 |
.yay-recommended-plugins-layout .plugin-card .desc, .plugin-card .name { |
| 202 |
margin-right: 0; |
| 203 |
} |
| 204 |
.yay-recommended-plugins-layout .plugin-card-bottom { |
| 205 |
display: flex; |
| 206 |
justify-content: space-between; |
| 207 |
align-items: center; |
| 208 |
} |
| 209 |
.yay-recommended-plugins-layout .plugin-action-buttons, |
| 210 |
.yay-recommended-plugins-layout .plugin-action-buttons li, |
| 211 |
.plugin-card .column-rating, .plugin-card .column-updated { |
| 212 |
margin-bottom: 0; |
| 213 |
} |
| 214 |
.yay-recommended-plugins-layout .loading-process { |
| 215 |
pointer-events: none; |
| 216 |
} |
| 217 |
.yay-recommended-plugins-layout .column-rating { |
| 218 |
min-height: 30px; |
| 219 |
line-height: 30px; |
| 220 |
} |
| 221 |
.yay-recommended-plugins-layout .plugin-status-inactive { |
| 222 |
color: #ff4d4f; |
| 223 |
} |
| 224 |
.yay-recommended-plugins-layout .plugin-status-active { |
| 225 |
color: #52c41a; |
| 226 |
} |
| 227 |
.yay-recommended-plugins-layout .plugin-status-not-install { |
| 228 |
color: #1d2327; |
| 229 |
} |
| 230 |
@media screen and (max-width: 1100px) and (min-width: 782px), (max-width: 480px) { |
| 231 |
.yay-recommended-plugins-layout .plugin-card .column-compatibility, |
| 232 |
.yay-recommended-plugins-layout .plugin-card .column-updated { |
| 233 |
width: calc(100% - 220px); |
| 234 |
} |
| 235 |
.yay-recommended-plugins-layout .plugin-action-buttons li .button, |
| 236 |
.yay-recommended-plugins-layout .plugin-action-buttons { |
| 237 |
margin: 0; |
| 238 |
} |
| 239 |
} |
| 240 |
</style> |
| 241 |
<div class="wrap"> |
| 242 |
<div class="yay-recommended-plugins-layout"> |
| 243 |
<div class="yay-recommended-plugins-layout-header"> |
| 244 |
<div class="wp-filter yay-recommended-plugins-header"> |
| 245 |
<h2 class="yay-recommended-plugins-header-title"><?php esc_attr_e( 'Recommended Plugins', 'filebird' ); ?></h2> |
| 246 |
<ul class="filter-links"> |
| 247 |
<?php |
| 248 |
echo wp_kses_post( $featuredTab ); |
| 249 |
?> |
| 250 |
<li class="plugin-install-tab plugin-install-all" data-tab="all"><a href="#"><?php esc_html_e( 'All', 'filebird' ); ?></a></li> |
| 251 |
<?php |
| 252 |
echo wp_kses_post( $wooTab ); |
| 253 |
?> |
| 254 |
<li class="plugin-install-tab plugin-install-management" data-tab="management"><a href="#"><?php esc_html_e( 'Management', 'filebird' ); ?></a> </li> |
| 255 |
<li class="plugin-install-tab plugin-install-marketing" data-tab="marketing"><a href="#"><?php esc_html_e( 'Marketing', 'filebird' ); ?></a></li> |
| 256 |
</ul> |
| 257 |
</div> |
| 258 |
</div> |
| 259 |
<div class="wp-list-table widefat plugin-install"> |
| 260 |
<div id="the-list"></div> |
| 261 |
</div> |
| 262 |
</div> |
| 263 |
</div> |
| 264 |
<?php |
| 265 |
} |
| 266 |
|
| 267 |
public function add_global_script_styles() { |
| 268 |
$screen = get_current_screen(); |
| 269 |
if ( $screen->base !== $this->subMenuSlug ) { |
| 270 |
return; |
| 271 |
} |
| 272 |
$activeWC = function_exists( 'WC' ); |
| 273 |
wp_enqueue_script( 'plugin-install' ); |
| 274 |
wp_enqueue_script( 'thickbox' ); |
| 275 |
wp_enqueue_style( 'thickbox' ); |
| 276 |
wp_register_script( "{$this->pluginPrefix}-yayrecommended", plugin_dir_url( __FILE__ ) . '/assets/js/recommended.js', array( 'jquery' ), '1.0', true ); |
| 277 |
wp_localize_script( |
| 278 |
"{$this->pluginPrefix}-yayrecommended", |
| 279 |
'yayRecommended', |
| 280 |
array( |
| 281 |
'nonce' => wp_create_nonce( 'yay_recommended_nonce' ), |
| 282 |
'admin_ajax' => admin_url( 'admin-ajax.php' ), |
| 283 |
'woo_active' => $activeWC, |
| 284 |
) |
| 285 |
); |
| 286 |
wp_enqueue_script( "{$this->pluginPrefix}-yayrecommended" ); |
| 287 |
} |
| 288 |
|
| 289 |
public function yay_recommended_get_plugin_data() { |
| 290 |
try { |
| 291 |
if ( isset( $_POST['tab'] ) ) { |
| 292 |
$nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( $_POST['nonce'] ) : ''; |
| 293 |
if ( ! wp_verify_nonce( $nonce, 'yay_recommended_nonce' ) ) { |
| 294 |
wp_send_json_error( array( 'mess' => __( 'Nonce is invalid', 'filebird' ) ) ); |
| 295 |
} |
| 296 |
$tab = sanitize_text_field( $_POST['tab'] ); |
| 297 |
$recommendedPlugins = array(); |
| 298 |
$recommendedData = apply_filters( 'yay_recommended_plugins_excluded', $this->recommendedPlugin ); |
| 299 |
foreach ( $recommendedData as $key => $plugin ) { |
| 300 |
if ( in_array( $tab, $plugin['type'] ) || 'all' === $tab ) { |
| 301 |
$recommendedPlugins[ $key ] = $plugin; |
| 302 |
} |
| 303 |
} |
| 304 |
ob_start(); |
| 305 |
$path = plugin_dir_path( __FILE__ ) . '/views/content.php'; |
| 306 |
include $path; |
| 307 |
$html = ob_get_contents(); |
| 308 |
ob_end_clean(); |
| 309 |
wp_send_json_success( |
| 310 |
array( |
| 311 |
'mess' => __( 'Get data success', 'filebird' ), |
| 312 |
'html' => $html, |
| 313 |
) |
| 314 |
); |
| 315 |
} |
| 316 |
} catch ( \Exception $ex ) { |
| 317 |
wp_send_json_error( |
| 318 |
array( |
| 319 |
'mess' => __( 'Error exception.', 'filebird' ), |
| 320 |
array( |
| 321 |
'error' => $ex, |
| 322 |
), |
| 323 |
) |
| 324 |
); |
| 325 |
} catch ( \Error $ex ) { |
| 326 |
wp_send_json_error( |
| 327 |
array( |
| 328 |
'mess' => __( 'Error.', 'filebird' ), |
| 329 |
array( |
| 330 |
'error' => $ex, |
| 331 |
), |
| 332 |
) |
| 333 |
); |
| 334 |
} |
| 335 |
} |
| 336 |
|
| 337 |
public function yay_recommended_activate_plugin() { |
| 338 |
try { |
| 339 |
if ( isset( $_POST['file'] ) ) { |
| 340 |
$nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( $_POST['nonce'] ) : ''; |
| 341 |
if ( ! wp_verify_nonce( $nonce, 'yay_recommended_nonce' ) ) { |
| 342 |
wp_send_json_error( array( 'mess' => __( 'Nonce is invalid', 'filebird' ) ) ); |
| 343 |
} |
| 344 |
$file = sanitize_text_field( $_POST['file'] ); |
| 345 |
$result = activate_plugin( $file ); |
| 346 |
|
| 347 |
if ( is_wp_error( $result ) ) { |
| 348 |
wp_send_json_error( |
| 349 |
array( |
| 350 |
'mess' => $result->get_error_message(), |
| 351 |
) |
| 352 |
); |
| 353 |
} |
| 354 |
wp_send_json_success( |
| 355 |
array( |
| 356 |
'mess' => __( 'Activate success', 'filebird' ), |
| 357 |
) |
| 358 |
); |
| 359 |
} |
| 360 |
} catch ( \Exception $ex ) { |
| 361 |
wp_send_json_error( |
| 362 |
array( |
| 363 |
'mess' => __( 'Error exception.', 'filebird' ), |
| 364 |
array( |
| 365 |
'error' => $ex, |
| 366 |
), |
| 367 |
) |
| 368 |
); |
| 369 |
} catch ( \Error $ex ) { |
| 370 |
wp_send_json_error( |
| 371 |
array( |
| 372 |
'mess' => __( 'Error.', 'filebird' ), |
| 373 |
array( |
| 374 |
'error' => $ex, |
| 375 |
), |
| 376 |
) |
| 377 |
); |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
public function yay_recommended_upgrade_plugin() { |
| 382 |
try { |
| 383 |
require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; |
| 384 |
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 385 |
require_once ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php'; |
| 386 |
require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php'; |
| 387 |
if ( isset( $_POST['plugin'] ) ) { |
| 388 |
$nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( $_POST['nonce'] ) : ''; |
| 389 |
if ( ! wp_verify_nonce( $nonce, 'yay_recommended_nonce' ) ) { |
| 390 |
wp_send_json_error( array( 'mess' => __( 'Nonce is invalid', 'filebird' ) ) ); |
| 391 |
} |
| 392 |
$plugin = sanitize_text_field( $_POST['plugin'] ); |
| 393 |
$type = isset( $_POST['type'] ) ? sanitize_text_field( $_POST['type'] ) : 'install'; |
| 394 |
$skin = new \WP_Ajax_Upgrader_Skin(); |
| 395 |
$upgrader = new \Plugin_Upgrader( $skin ); |
| 396 |
if ( 'install' === $type ) { |
| 397 |
$result = $upgrader->install( $plugin ); |
| 398 |
if ( is_wp_error( $result ) ) { |
| 399 |
wp_send_json_error( |
| 400 |
array( |
| 401 |
'mess' => $result->get_error_message(), |
| 402 |
) |
| 403 |
); |
| 404 |
} |
| 405 |
$args = array( |
| 406 |
'slug' => $upgrader->result['destination_name'], |
| 407 |
'fields' => array( |
| 408 |
'short_description' => true, |
| 409 |
'icons' => true, |
| 410 |
'banners' => false, |
| 411 |
'added' => false, |
| 412 |
'reviews' => false, |
| 413 |
'sections' => false, |
| 414 |
'requires' => false, |
| 415 |
'rating' => false, |
| 416 |
'ratings' => false, |
| 417 |
'downloaded' => false, |
| 418 |
'last_updated' => false, |
| 419 |
'added' => false, |
| 420 |
'tags' => false, |
| 421 |
'compatibility' => false, |
| 422 |
'homepage' => false, |
| 423 |
'donate_link' => false, |
| 424 |
), |
| 425 |
); |
| 426 |
$pluginData = plugins_api( 'plugin_information', $args ); |
| 427 |
if ( $pluginData && ! is_wp_error( $pluginData ) ) { |
| 428 |
$installStatus = install_plugin_install_status( $pluginData ); |
| 429 |
$activePlugin = activate_plugin( $installStatus['file'] ); |
| 430 |
if ( is_wp_error( $activePlugin ) ) { |
| 431 |
wp_send_json_error( |
| 432 |
array( |
| 433 |
'mess' => $activePlugin->get_error_message(), |
| 434 |
) |
| 435 |
); |
| 436 |
} else { |
| 437 |
wp_send_json_success( |
| 438 |
array( |
| 439 |
'mess' => __( 'Install success', 'filebird' ), |
| 440 |
) |
| 441 |
); |
| 442 |
} |
| 443 |
} else { |
| 444 |
wp_send_json_error( |
| 445 |
array( |
| 446 |
'mess' => 'Error', |
| 447 |
) |
| 448 |
); |
| 449 |
} |
| 450 |
} else { |
| 451 |
$is_active = is_plugin_active( $plugin ); |
| 452 |
$result = $upgrader->upgrade( $plugin ); |
| 453 |
if ( is_wp_error( $result ) ) { |
| 454 |
wp_send_json_error( |
| 455 |
array( |
| 456 |
'mess' => $result->get_error_message(), |
| 457 |
) |
| 458 |
); |
| 459 |
} else { |
| 460 |
activate_plugin( $plugin ); |
| 461 |
wp_send_json_success( |
| 462 |
array( |
| 463 |
'mess' => __( 'Update success', 'filebird' ), |
| 464 |
'active' => $is_active, |
| 465 |
) |
| 466 |
); |
| 467 |
} |
| 468 |
} |
| 469 |
} |
| 470 |
} catch ( \Exception $ex ) { |
| 471 |
wp_send_json_error( |
| 472 |
array( |
| 473 |
'mess' => __( 'Error exception.', 'filebird' ), |
| 474 |
array( |
| 475 |
'error' => $ex, |
| 476 |
), |
| 477 |
) |
| 478 |
); |
| 479 |
} catch ( \Error $ex ) { |
| 480 |
wp_send_json_error( |
| 481 |
array( |
| 482 |
'mess' => __( 'Error.', 'filebird' ), |
| 483 |
array( |
| 484 |
'error' => $ex, |
| 485 |
), |
| 486 |
) |
| 487 |
); |
| 488 |
} |
| 489 |
} |
| 490 |
|
| 491 |
public function check_pro_version_exists( $pluginDetail ) { |
| 492 |
$existProVer = false; |
| 493 |
$allPlugin = get_plugins(); |
| 494 |
if ( 'filebird' === $pluginDetail['slug'] ) { |
| 495 |
$existProVer = array_key_exists( 'filebird-pro/filebird.php', $allPlugin ) === true ? 'filebird-pro/filebird.php' : false; |
| 496 |
} |
| 497 |
if ( 'yaymail' === $pluginDetail['slug'] ) { |
| 498 |
if ( array_key_exists( 'yaymail-pro/yaymail.php', $allPlugin ) ) { |
| 499 |
$existProVer = 'yaymail-pro/yaymail.php'; |
| 500 |
} elseif ( array_key_exists( 'email-customizer-for-woocommerce/yaymail.php', $allPlugin ) ) { |
| 501 |
$existProVer = 'email-customizer-for-woocommerce/yaymail.php'; |
| 502 |
} |
| 503 |
} |
| 504 |
if ( 'yaycurrency' === $pluginDetail['slug'] ) { |
| 505 |
if ( array_key_exists( 'yaycurrency-pro/yay-currency.php', $allPlugin ) ) { |
| 506 |
$existProVer = 'yaycurrency-pro/yay-currency.php'; |
| 507 |
} elseif ( array_key_exists( 'multi-currency-switcher/yay-currency.php', $allPlugin ) ) { |
| 508 |
$existProVer = 'multi-currency-switcher/yay-currency.php'; |
| 509 |
} |
| 510 |
} |
| 511 |
if ( 'yaysmtp' === $pluginDetail['slug'] ) { |
| 512 |
$existProVer = array_key_exists( 'yaysmtp-pro/yay-smtp.php', $allPlugin ) === true ? 'yaysmtp-pro/yay-smtp.php' : false; |
| 513 |
} |
| 514 |
if ( 'yayswatches' === $pluginDetail['slug'] ) { |
| 515 |
$existProVer = array_key_exists( 'yayswatches-pro/yay-swatches.php', $allPlugin ) === true ? 'yayswatches-pro/yay-swatches.php' : false; |
| 516 |
} |
| 517 |
if ( 'yayextra' === $pluginDetail['slug'] ) { |
| 518 |
$existProVer = array_key_exists( 'yayextra-pro/yayextra.php', $allPlugin ) === true ? 'yayextra-pro/yayextra.php' : false; |
| 519 |
} |
| 520 |
if ( 'yaypricing' === $pluginDetail['slug'] ) { |
| 521 |
$existProVer = array_key_exists( 'yaypricing-pro/yaypricing.php', $allPlugin ) === true ? 'yaypricing-pro/yaypricing.php' : false; |
| 522 |
} |
| 523 |
if ( 'cf7-multi-step' === $pluginDetail['slug'] ) { |
| 524 |
$existProVer = array_key_exists( 'contact-form-7-multi-step-pro/contact-form-7-multi-step.php', $allPlugin ) === true ? 'contact-form-7-multi-step-pro/contact-form-7-multi-step.php' : false; |
| 525 |
} |
| 526 |
if ( 'cf7-database' === $pluginDetail['slug'] ) { |
| 527 |
$existProVer = array_key_exists( 'contact-form-7-database-pro/cf7-database.php', $allPlugin ) === true ? 'contact-form-7-database-pro/cf7-database.php' : false; |
| 528 |
} |
| 529 |
if ( 'wp-whatsapp' === $pluginDetail['slug'] ) { |
| 530 |
$existProVer = array_key_exists( 'whatsapp-for-wordpress/whatsapp.php', $allPlugin ) === true ? 'whatsapp-for-wordpress/whatsapp.php' : false; |
| 531 |
} |
| 532 |
return $existProVer; |
| 533 |
} |
| 534 |
} |
| 535 |
} |
| 536 |
|
| 537 |
if ( ! class_exists( 'FileBirdRecommended' ) ) { |
| 538 |
class FileBirdRecommended extends YayRecommended { |
| 539 |
|
| 540 |
public function __construct( $pluginPrefix ) { |
| 541 |
parent::__construct( $pluginPrefix ); |
| 542 |
add_filter( 'yay_recommended_plugins_excluded', array( $this, 'exclude_recommended_plugins' ), 10, 1 ); |
| 543 |
} |
| 544 |
|
| 545 |
public function exclude_recommended_plugins( $plugins ) { |
| 546 |
if ( array_key_exists( 'filebird', $plugins ) ) { |
| 547 |
unset( $plugins['filebird'] ); |
| 548 |
} |
| 549 |
return $plugins; |
| 550 |
} |
| 551 |
|
| 552 |
public function admin_menu() { |
| 553 |
$this->subMenuSlug = add_submenu_page( 'filebird-settings', __( 'Recommended Plugins', 'filebird' ), __( 'Recommended', 'filebird' ), 'manage_options', 'filebird-settings-recommended-plugins', array( $this, 'recommended_plugins_view' ), 1 ); |
| 554 |
} |
| 555 |
} |
| 556 |
|
| 557 |
new FileBirdRecommended( 'filebird' ); |
| 558 |
} |
| 559 |
|