| 1 |
<?php |
| 2 |
|
| 3 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-plugin-install-list-table.php'); |
| 4 |
|
| 5 |
class QuadMenu_Suggestions_List_Table extends WP_Plugin_Install_List_Table |
| 6 |
{ |
| 7 |
|
| 8 |
public $promote = array( |
| 9 |
'wp-whatsapp-chat', |
| 10 |
'insta-gallery', |
| 11 |
'woocommerce-checkout-manager', |
| 12 |
'woocommerce-direct-checkout', |
| 13 |
'perfect-woocommerce-brands', |
| 14 |
'autocomplete-woocommerce-orders', |
| 15 |
'wp-menu-icons', |
| 16 |
'quadmenu', |
| 17 |
); |
| 18 |
|
| 19 |
private function remove_plugins($plugins) |
| 20 |
{ |
| 21 |
|
| 22 |
$promote = array(); |
| 23 |
|
| 24 |
foreach ($this->promote as $order => $slug) { |
| 25 |
|
| 26 |
if ($id = @max(array_keys(array_column($plugins, 'slug'), $slug))) { |
| 27 |
|
| 28 |
$promote[] = $plugins[$id]; |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
return $promote; |
| 33 |
} |
| 34 |
|
| 35 |
public function self_admin_url($url, $path) |
| 36 |
{ |
| 37 |
|
| 38 |
if (strpos($url, 'tab=plugin-information') !== false) { |
| 39 |
$url = network_admin_url($path); |
| 40 |
} |
| 41 |
|
| 42 |
return $url; |
| 43 |
} |
| 44 |
|
| 45 |
public function network_admin_url($url, $path) |
| 46 |
{ |
| 47 |
|
| 48 |
if (strpos($url, 'plugins.php') !== false) { |
| 49 |
$url = self_admin_url($path); |
| 50 |
} |
| 51 |
|
| 52 |
return $url; |
| 53 |
} |
| 54 |
|
| 55 |
public function display_rows() |
| 56 |
{ |
| 57 |
add_filter('self_admin_url', array($this, 'self_admin_url'), 10, 2); |
| 58 |
add_filter('network_admin_url', array($this, 'network_admin_url'), 10, 2); |
| 59 |
parent::display_rows(); |
| 60 |
} |
| 61 |
|
| 62 |
public function is_connected() |
| 63 |
{ |
| 64 |
|
| 65 |
global $wp_version; |
| 66 |
|
| 67 |
$http_args = array( |
| 68 |
'timeout' => 15, |
| 69 |
'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url('/'), |
| 70 |
); |
| 71 |
|
| 72 |
return is_wp_error(wp_remote_get('http://api.wordpress.org/plugins/info/1.2/', $http_args)); |
| 73 |
} |
| 74 |
|
| 75 |
public function get_plugins() |
| 76 |
{ |
| 77 |
|
| 78 |
$plugins = get_transient('ql_suggestions_plugins'); |
| 79 |
|
| 80 |
if ($plugins === false) { |
| 81 |
|
| 82 |
$args = array( |
| 83 |
'per_page' => 36, |
| 84 |
'author' => 'quadlayers', |
| 85 |
'locale' => get_user_locale(), |
| 86 |
); |
| 87 |
|
| 88 |
$api = plugins_api('query_plugins', $args); |
| 89 |
|
| 90 |
if (!is_wp_error($api)) { |
| 91 |
|
| 92 |
$plugins = $this->remove_plugins($api->plugins); |
| 93 |
|
| 94 |
set_transient('ql_suggestions_plugins', $plugins, 24 * HOUR_IN_SECONDS); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
return $plugins; |
| 99 |
} |
| 100 |
|
| 101 |
public function prepare_items() |
| 102 |
{ |
| 103 |
|
| 104 |
include_once(ABSPATH . 'wp-admin/includes/plugin-install.php'); |
| 105 |
|
| 106 |
global $tabs, $tab; |
| 107 |
|
| 108 |
wp_enqueue_style('thickbox'); |
| 109 |
wp_enqueue_script('plugin-install'); |
| 110 |
wp_enqueue_script('thickbox'); |
| 111 |
wp_enqueue_script('updates'); |
| 112 |
|
| 113 |
wp_reset_vars(array('tab')); |
| 114 |
|
| 115 |
$tabs = array(); |
| 116 |
|
| 117 |
if ('search' === $tab) { |
| 118 |
$tabs['search'] = __('Search Results'); |
| 119 |
} |
| 120 |
if ($tab === 'beta' || false !== strpos(get_bloginfo('version'), '-')) { |
| 121 |
$tabs['beta'] = _x('Beta Testing', 'Plugin Installer'); |
| 122 |
} |
| 123 |
$tabs['featured'] = _x('Featured', 'Plugin Installer'); |
| 124 |
$tabs['popular'] = _x('Popular', 'Plugin Installer'); |
| 125 |
$tabs['recommended'] = _x('Recommended', 'Plugin Installer'); |
| 126 |
$tabs['favorites'] = _x('Favorites', 'Plugin Installer'); |
| 127 |
|
| 128 |
$nonmenu_tabs = array('plugin-information'); // Valid actions to perform which do not have a Menu item. |
| 129 |
|
| 130 |
$tabs = apply_filters('install_plugins_tabs', $tabs); |
| 131 |
|
| 132 |
$nonmenu_tabs = apply_filters('install_plugins_nonmenu_tabs', $nonmenu_tabs); |
| 133 |
|
| 134 |
// If a non-valid menu tab has been selected, And it's not a non-menu action. |
| 135 |
if (empty($tab) || (!isset($tabs[$tab]) && !in_array($tab, (array) $nonmenu_tabs))) { |
| 136 |
$tab = key($tabs); |
| 137 |
} |
| 138 |
|
| 139 |
$this->items = $this->get_plugins(); |
| 140 |
} |
| 141 |
} |
| 142 |
|