| 1 |
<?php |
| 2 |
namespace EverCompare\Admin; |
| 3 |
|
| 4 |
defined( 'ABSPATH' ) || exit; |
| 5 |
/** |
| 6 |
* Dashboard handlers class |
| 7 |
*/ |
| 8 |
class Dashboard { |
| 9 |
|
| 10 |
/** |
| 11 |
* Menu capability |
| 12 |
*/ |
| 13 |
const MENU_CAPABILITY = 'manage_options'; |
| 14 |
|
| 15 |
/** |
| 16 |
* Parent Menu Page Slug |
| 17 |
*/ |
| 18 |
const MENU_PAGE_SLUG = 'evercompare'; |
| 19 |
|
| 20 |
/** |
| 21 |
* [$parent_menu_hook] Parent Menu Hook |
| 22 |
* @var string |
| 23 |
*/ |
| 24 |
static $parent_menu_hook = ''; |
| 25 |
|
| 26 |
/** |
| 27 |
* [$_instance] |
| 28 |
* @var null |
| 29 |
*/ |
| 30 |
private static $_instance = null; |
| 31 |
|
| 32 |
/** |
| 33 |
* [instance] Initializes a singleton instance |
| 34 |
* @return [Admin] |
| 35 |
*/ |
| 36 |
public static function instance() { |
| 37 |
if ( is_null( self::$_instance ) ) { |
| 38 |
self::$_instance = new self(); |
| 39 |
} |
| 40 |
return self::$_instance; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Initialize the class |
| 45 |
*/ |
| 46 |
private function __construct() { |
| 47 |
|
| 48 |
Admin_Fields::instance(); |
| 49 |
|
| 50 |
if( isset( get_option('woolentor_others_tabs')['compare'] ) && get_option('woolentor_others_tabs')['compare'] == 'on' ){ |
| 51 |
add_action( 'admin_menu', [ $this, 'add_menu_if_woolentor' ], 226 ); |
| 52 |
}else{ |
| 53 |
add_action( 'admin_menu', [ $this, 'add_menu' ], 20 ); |
| 54 |
} |
| 55 |
|
| 56 |
add_filter('plugin_action_links_'.EVERCOMPARE_BASE, [ $this, 'action_links' ] ); |
| 57 |
|
| 58 |
// Add a post display state for special EverCompare page. |
| 59 |
add_filter( 'display_post_states', [ $this, 'add_display_post_states' ], 10, 2 ); |
| 60 |
|
| 61 |
// Redirect Option page |
| 62 |
$this->redirect_option_page(); |
| 63 |
|
| 64 |
// Recommended plugin |
| 65 |
add_action('init', [ $this, 'plugin_recommendations' ]); |
| 66 |
|
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* [action_links] add plugin action link |
| 71 |
* @param [array] $links default plugin action link |
| 72 |
* @return [array] plugin action link |
| 73 |
*/ |
| 74 |
public function action_links( $links ) { |
| 75 |
|
| 76 |
if ( ! current_user_can( self::MENU_CAPABILITY ) ) { |
| 77 |
return $links; |
| 78 |
} |
| 79 |
|
| 80 |
$settings_link = '<a href="'.admin_url( 'admin.php?page='.self::MENU_PAGE_SLUG ).'">'.esc_html__( 'Settings', 'ever-compare' ).'</a>'; |
| 81 |
|
| 82 |
array_unshift( $links, $settings_link ); |
| 83 |
|
| 84 |
return $links; |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* [add_menu_if_woolentor] Admin Menu If WooLentor active |
| 89 |
*/ |
| 90 |
public function add_menu_if_woolentor(){ |
| 91 |
|
| 92 |
self::$parent_menu_hook = add_submenu_page( |
| 93 |
'woolentor_page', |
| 94 |
esc_html__( 'Compare', 'ever-compare' ), |
| 95 |
esc_html__( 'Compare', 'ever-compare' ), |
| 96 |
'manage_options', |
| 97 |
self::MENU_PAGE_SLUG, |
| 98 |
[ $this,'dashboard' ] |
| 99 |
); |
| 100 |
|
| 101 |
add_action( 'load-' . self::$parent_menu_hook, [ $this, 'init_hooks'] ); |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* [add_menu] Admin Menu |
| 107 |
*/ |
| 108 |
public function add_menu(){ |
| 109 |
|
| 110 |
global $submenu; |
| 111 |
|
| 112 |
self::$parent_menu_hook = add_menu_page( |
| 113 |
esc_html__( 'Ever Compare', 'ever-compare' ), |
| 114 |
esc_html__( 'Ever Compare', 'ever-compare' ), |
| 115 |
self::MENU_CAPABILITY, |
| 116 |
self::MENU_PAGE_SLUG, |
| 117 |
[ $this,'dashboard' ], |
| 118 |
'dashicons-update-alt', |
| 119 |
59 |
| 120 |
); |
| 121 |
|
| 122 |
if ( current_user_can( self::MENU_CAPABILITY ) ) { |
| 123 |
|
| 124 |
foreach ( $this->sub_menu_nav() as $menukey => $menu ) { |
| 125 |
$submenu[ self::MENU_PAGE_SLUG ][] = array( |
| 126 |
$menu['title'], |
| 127 |
self::MENU_CAPABILITY, |
| 128 |
'admin.php?page='.self::MENU_PAGE_SLUG.'#'.$menukey, |
| 129 |
); |
| 130 |
} |
| 131 |
|
| 132 |
} |
| 133 |
|
| 134 |
add_action( 'load-' . self::$parent_menu_hook, [ $this, 'init_hooks'] ); |
| 135 |
|
| 136 |
|
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* Initialize our hooks for the admin page |
| 141 |
* |
| 142 |
* @return void |
| 143 |
*/ |
| 144 |
public function init_hooks() { |
| 145 |
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); |
| 146 |
} |
| 147 |
|
| 148 |
/** |
| 149 |
* [enqueue_scripts] Add Scripts Base Menu Slug |
| 150 |
* @param [string] $hook |
| 151 |
* @return [void] |
| 152 |
*/ |
| 153 |
public function enqueue_scripts() { |
| 154 |
wp_enqueue_style( 'evercompare-admin' ); |
| 155 |
wp_enqueue_script( 'evercompare-admin' ); |
| 156 |
} |
| 157 |
|
| 158 |
/** |
| 159 |
* [dashboard] Dashboard plugin page |
| 160 |
* @return [HTML] |
| 161 |
*/ |
| 162 |
public function dashboard(){ |
| 163 |
Admin_Fields::instance()->plugin_page(); |
| 164 |
} |
| 165 |
|
| 166 |
/** |
| 167 |
* [sub_menu_nav] |
| 168 |
* @return [array] |
| 169 |
*/ |
| 170 |
public function sub_menu_nav() { |
| 171 |
|
| 172 |
$submenu = [ |
| 173 |
'settings' => [ |
| 174 |
'title' => esc_html__( 'Settings', 'ever-compare' ), |
| 175 |
'subtitle' => esc_html__( 'Settings', 'ever-compare' ), |
| 176 |
'icon' => '', |
| 177 |
'class' => '', |
| 178 |
], |
| 179 |
]; |
| 180 |
|
| 181 |
return apply_filters( 'ever_compare_dashboard_submenu', $submenu ); |
| 182 |
|
| 183 |
} |
| 184 |
|
| 185 |
/** |
| 186 |
* [redirect_option_page] After Active the plugin then redirect to option page |
| 187 |
* @return [void] |
| 188 |
*/ |
| 189 |
public function redirect_option_page() { |
| 190 |
if ( get_option( 'evercompare_do_activation_redirect', FALSE ) ) { |
| 191 |
delete_option('evercompare_do_activation_redirect'); |
| 192 |
if( !isset( $_GET['activate-multi'] ) ){ //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 193 |
wp_redirect( admin_url( "admin.php?page=".self::MENU_PAGE_SLUG ) ); |
| 194 |
} |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
/** |
| 199 |
* Add a post display state for special WishSuite page in the page list table. |
| 200 |
* |
| 201 |
* @param array $post_states An array of post display states. |
| 202 |
* @param WP_Post $post The current post object. |
| 203 |
*/ |
| 204 |
public function add_display_post_states( $post_states, $post ){ |
| 205 |
if ( (int)ever_compare_get_option( 'compare_page', 'ever_compare_table_settings_tabs' ) === $post->ID ) { |
| 206 |
$post_states['evercompare_page_for_compare_table'] = __( 'EverCompare', 'ever-compare' ); |
| 207 |
} |
| 208 |
return $post_states; |
| 209 |
} |
| 210 |
|
| 211 |
/** |
| 212 |
* [plugin_recommendations] |
| 213 |
* @return [void] |
| 214 |
*/ |
| 215 |
public function plugin_recommendations(){ |
| 216 |
|
| 217 |
$get_instance = Recommended_Plugins::instance( |
| 218 |
array( |
| 219 |
'text_domain' => 'ever-compare', |
| 220 |
'parent_menu_slug' => self::MENU_PAGE_SLUG, |
| 221 |
'menu_capability' => self::MENU_CAPABILITY, |
| 222 |
'menu_page_slug' => 'everrecommendations', |
| 223 |
'priority' => 25, |
| 224 |
'assets_url' => EVERCOMPARE_ASSETS, |
| 225 |
'hook_suffix' => 'ever-compare_page_everrecommendations' |
| 226 |
) |
| 227 |
); |
| 228 |
|
| 229 |
$get_instance->add_new_tab( array( |
| 230 |
|
| 231 |
'title' => esc_html__( 'Recommended Plugins', 'ever-compare' ), |
| 232 |
'active' => true, |
| 233 |
'plugins' => array( |
| 234 |
|
| 235 |
array( |
| 236 |
'slug' => 'support-genix-lite', |
| 237 |
'location' => 'support-genix-lite.php', |
| 238 |
'name' => esc_html__( 'Support Genix – Helpdesk, AI Chatbot, Knowledge Base & Customer Support Ticketing System', 'ever-compare' ) |
| 239 |
), |
| 240 |
array( |
| 241 |
'slug' => 'hashbar-wp-notification-bar', |
| 242 |
'location' => 'init.php', |
| 243 |
'name' => esc_html__( 'HashBar – Announcement, Notification Bar & Popup Campaign', 'ever-compare' ) |
| 244 |
), |
| 245 |
array( |
| 246 |
'slug' => 'wp-plugin-manager', |
| 247 |
'location' => 'plugin-main.php', |
| 248 |
'name' => esc_html__( 'WP Plugin Manager – Deactivate plugins per page', 'ever-compare' ) |
| 249 |
), |
| 250 |
array( |
| 251 |
'slug' => 'ht-contactform', |
| 252 |
'location' => 'contact-form-widget-elementor.php', |
| 253 |
'name' => esc_html__( 'HT Contact Form – Drag & Drop Form Builder for WordPress', 'ever-compare' ) |
| 254 |
), |
| 255 |
array( |
| 256 |
'slug' => 'cookieray', |
| 257 |
'location' => 'cookieray.php', |
| 258 |
'name' => esc_html__( 'CookieRay – Cookie Banner for Cookie Consent (GDPR/CCPA Compliant)', 'ever-compare' ) |
| 259 |
), |
| 260 |
array( |
| 261 |
'slug' => 'kelune-crm', |
| 262 |
'location' => 'kelune-crm.php', |
| 263 |
'name' => esc_html__( 'Kelune CRM – Contact Management, Email Marketing, Newsletter & Marketing Automation', 'ever-compare' ) |
| 264 |
), |
| 265 |
) |
| 266 |
|
| 267 |
) ); |
| 268 |
|
| 269 |
$get_instance->add_new_tab( array( |
| 270 |
'title' => esc_html__( 'WooCommerce', 'ever-compare' ), |
| 271 |
'plugins' => array( |
| 272 |
array( |
| 273 |
'slug' => 'woolentor-addons', |
| 274 |
'location' => 'woolentor_addons_elementor.php', |
| 275 |
'name' => esc_html__( 'ShopLentor – All-in-One WooCommerce Growth & Store Enhancement Plugin', 'ever-compare' ) |
| 276 |
), |
| 277 |
array( |
| 278 |
'slug' => 'whols', |
| 279 |
'location' => 'whols.php', |
| 280 |
'name' => esc_html__( 'Whols – Wholesale Prices and B2B Store Solution for WooCommerce', 'ever-compare' ) |
| 281 |
), |
| 282 |
array( |
| 283 |
'slug' => 'recurio', |
| 284 |
'location' => 'recurio.php', |
| 285 |
'name' => esc_html__( 'Recurio – Ultimate Subscription for WooCommerce', 'ever-compare' ) |
| 286 |
), |
| 287 |
) |
| 288 |
) ); |
| 289 |
|
| 290 |
$get_instance->add_new_tab(array( |
| 291 |
'title' => esc_html__( 'Popular', 'ever-compare' ), |
| 292 |
'plugins' => array( |
| 293 |
array( |
| 294 |
'slug' => 'ht-mega-for-elementor', |
| 295 |
'location' => 'htmega_addons_elementor.php', |
| 296 |
'name' => esc_html__( 'HT Mega Addons for Elementor – Elementor Widgets & Template Builder', 'ever-compare' ) |
| 297 |
), |
| 298 |
array( |
| 299 |
'slug' => 'wp-plugin-manager', |
| 300 |
'location' => 'plugin-main.php', |
| 301 |
'name' => esc_html__( 'WP Plugin Manager – Deactivate plugins per page', 'ever-compare' ) |
| 302 |
), |
| 303 |
array( |
| 304 |
'slug' => 'ht-easy-google-analytics', |
| 305 |
'location' => 'ht-easy-google-analytics.php', |
| 306 |
'name' => esc_html__( 'HT Easy GA4 – Google Analytics WordPress Plugin', 'ever-compare' ) |
| 307 |
), |
| 308 |
array( |
| 309 |
'slug' => 'cookieray', |
| 310 |
'location' => 'cookieray.php', |
| 311 |
'name' => esc_html__( 'CookieRay – Cookie Banner for Cookie Consent (GDPR/CCPA Compliant)', 'ever-compare' ) |
| 312 |
), |
| 313 |
array( |
| 314 |
'slug' => 'insert-headers-and-footers-script', |
| 315 |
'location' => 'init.php', |
| 316 |
'name' => esc_html__( 'Insert Headers and Footers Code – HT Script', 'ever-compare' ) |
| 317 |
), |
| 318 |
array( |
| 319 |
'slug' => 'pixelavo', |
| 320 |
'location' => 'pixelavo.php', |
| 321 |
'name' => esc_html__( 'Pixelavo – Server Side Tracking & Pixel + AI Ads Tools', 'ever-compare' ) |
| 322 |
), |
| 323 |
array( |
| 324 |
'slug' => 'courseglade-lms', |
| 325 |
'location' => 'courseglade-lms.php', |
| 326 |
'name' => esc_html__( 'CourseGlade LMS – Online Course & eLearning Platform', 'ever-compare' ) |
| 327 |
), |
| 328 |
) |
| 329 |
)); |
| 330 |
|
| 331 |
|
| 332 |
} |
| 333 |
|
| 334 |
|
| 335 |
} |