pro-awareness.php
526 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Wpmet\Libs; |
| 4 | |
| 5 | defined( 'ABSPATH' ) || exit; |
| 6 | |
| 7 | if ( ! class_exists( '\Wpmet\Libs\Pro_Awareness' ) ) : |
| 8 | |
| 9 | class Pro_Awareness { |
| 10 | |
| 11 | |
| 12 | private static $instance; |
| 13 | |
| 14 | private $text_domain; |
| 15 | private $plugin_file; |
| 16 | private $parent_menu_slug; |
| 17 | private $menu_slug = '_get_help'; |
| 18 | private $default_grid_link = 'https://wpmet.com/support-ticket'; |
| 19 | private $default_grid_title = ''; |
| 20 | private $default_grid_thumbnail = ''; |
| 21 | private $default_grid_desc = ''; |
| 22 | private $pro_link_conf = array(); |
| 23 | |
| 24 | private $grids = array(); |
| 25 | private $action_links = array(); |
| 26 | private $row_meta_links = array(); |
| 27 | private $parent_menu_text = ''; |
| 28 | private $products = array(); |
| 29 | |
| 30 | |
| 31 | protected $script_version = '1.2.0'; |
| 32 | |
| 33 | /** |
| 34 | * Get version of this script |
| 35 | * |
| 36 | * @return string Version name |
| 37 | */ |
| 38 | public function get_version() { |
| 39 | return $this->script_version; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Get current directory path |
| 44 | * |
| 45 | * @return string |
| 46 | */ |
| 47 | public function get_script_location() { |
| 48 | return __FILE__; |
| 49 | } |
| 50 | |
| 51 | |
| 52 | public static function instance( $text_domain ) { |
| 53 | |
| 54 | self::$instance = new self(); |
| 55 | |
| 56 | return self::$instance->set_text_domain( $text_domain ); |
| 57 | } |
| 58 | |
| 59 | protected function set_text_domain( $val ) { |
| 60 | |
| 61 | $this->text_domain = $val; |
| 62 | |
| 63 | return $this; |
| 64 | } |
| 65 | |
| 66 | private function default_grid() { |
| 67 | |
| 68 | $title = ! empty( $this->default_grid_title ) |
| 69 | ? $this->default_grid_title |
| 70 | : esc_html__( 'Support Center', 'elementskit-lite' ); |
| 71 | $description = ! empty( $this->default_grid_desc ) |
| 72 | ? $this->default_grid_desc |
| 73 | : esc_html__( 'Our experienced support team is ready to resolve your issues any time.', 'elementskit-lite' ); |
| 74 | return array( |
| 75 | 'url' => $this->default_grid_link, |
| 76 | 'title' => $title, |
| 77 | 'thumbnail' => $this->default_grid_thumbnail, |
| 78 | 'description' => $description, |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | public function set_parent_menu_text( $text ) { |
| 83 | |
| 84 | $this->parent_menu_text = $text; |
| 85 | |
| 86 | return $this; |
| 87 | } |
| 88 | |
| 89 | public function set_default_grid_link( $url ) { |
| 90 | |
| 91 | $this->default_grid_link = $url; |
| 92 | |
| 93 | return $this; |
| 94 | } |
| 95 | |
| 96 | public function set_default_grid_title( $title ) { |
| 97 | |
| 98 | $this->default_grid_title = $title; |
| 99 | |
| 100 | return $this; |
| 101 | } |
| 102 | |
| 103 | public function set_default_grid_desc( $title ) { |
| 104 | |
| 105 | $this->default_grid_desc = $title; |
| 106 | |
| 107 | return $this; |
| 108 | } |
| 109 | |
| 110 | public function set_default_grid_thumbnail( $thumbnail ) { |
| 111 | |
| 112 | $this->default_grid_thumbnail = $thumbnail; |
| 113 | |
| 114 | return $this; |
| 115 | } |
| 116 | |
| 117 | public function set_parent_menu_slug( $slug ) { |
| 118 | |
| 119 | $this->parent_menu_slug = $slug; |
| 120 | |
| 121 | return $this; |
| 122 | } |
| 123 | |
| 124 | |
| 125 | public function set_menu_slug( $slug ) { |
| 126 | |
| 127 | $this->menu_slug = $slug; |
| 128 | |
| 129 | return $this; |
| 130 | } |
| 131 | |
| 132 | public function set_plugin_file( $plugin_file ) { |
| 133 | |
| 134 | $this->plugin_file = $plugin_file; |
| 135 | |
| 136 | return $this; |
| 137 | } |
| 138 | |
| 139 | public function set_pro_link( $url, $conf = array() ) { |
| 140 | |
| 141 | if ( $url == '' ) { |
| 142 | return $this; |
| 143 | } |
| 144 | |
| 145 | $this->pro_link_conf[] = array( |
| 146 | 'url' => $url, |
| 147 | 'target' => '_blank', |
| 148 | 'anchor' => empty( $conf['anchor'] ) ? sprintf( '<span style="color: #FCB214;" class="pro_aware pro">%s</span>', esc_html__( 'Upgrade To Premium', 'elementskit-lite' ) ) : $conf['anchor'], |
| 149 | 'permission' => empty( $conf['permission'] ) ? 'manage_options' : $conf['permission'], |
| 150 | ); |
| 151 | |
| 152 | return $this; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Set page grid |
| 157 | */ |
| 158 | public function set_page_grid( $conf = array() ) { |
| 159 | |
| 160 | if ( ! empty( $conf['url'] ) ) { |
| 161 | |
| 162 | $this->grids[] = array( |
| 163 | 'url' => $conf['url'], |
| 164 | 'title' => empty( $conf['title'] ) ? esc_html__( 'Default Title', 'elementskit-lite' ) : $conf['title'], |
| 165 | 'thumbnail' => empty( $conf['thumbnail'] ) ? '' : esc_url( $conf['thumbnail'] ), |
| 166 | 'description' => empty( $conf['description'] ) ? '' : $conf['description'], |
| 167 | ); |
| 168 | } |
| 169 | |
| 170 | return $this; |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Set wpmet products |
| 175 | */ |
| 176 | public function set_products( $product = array() ) { |
| 177 | $this->products[] = array( |
| 178 | 'url' => empty( $product['url'] ) ? '' : esc_url( $product['url'] ), |
| 179 | 'title' => empty( $product['title'] ) ? esc_html__( 'Default Title', 'elementskit-lite' ) : $product['title'], |
| 180 | 'thumbnail' => empty( $product['thumbnail'] ) ? '' : esc_url( $product['thumbnail'] ), |
| 181 | 'description' => empty( $product['description'] ) ? '' : $product['description'], |
| 182 | ); |
| 183 | |
| 184 | return $this; |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * @deprecated This method will be removed |
| 189 | */ |
| 190 | public function set_grid( $conf = array() ) { |
| 191 | $this->set_page_grid( $conf ); |
| 192 | |
| 193 | return $this; |
| 194 | } |
| 195 | |
| 196 | protected function prepare_pro_links() { |
| 197 | |
| 198 | if ( ! empty( $this->pro_link_conf ) ) { |
| 199 | |
| 200 | foreach ( $this->pro_link_conf as $conf ) { |
| 201 | |
| 202 | add_submenu_page( $this->parent_menu_slug, $conf['anchor'], $conf['anchor'], $conf['permission'], $conf['url'], '' ); |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | protected function prepare_grid_links() { |
| 208 | |
| 209 | if ( ! empty( $this->grids ) ) { |
| 210 | |
| 211 | $get_help_title = !empty( $this->parent_menu_text ) |
| 212 | ? $this->parent_menu_text |
| 213 | : esc_html__( 'Get Help', 'elementskit-lite' ); |
| 214 | |
| 215 | add_submenu_page( |
| 216 | $this->parent_menu_slug, |
| 217 | $get_help_title, |
| 218 | $get_help_title, |
| 219 | 'manage_options', |
| 220 | $this->text_domain . $this->menu_slug, |
| 221 | array( $this, 'generate_grids' ) |
| 222 | ); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | |
| 227 | public function generate_grids() { |
| 228 | |
| 229 | /** |
| 230 | * Adding default grid at first position |
| 231 | */ |
| 232 | array_unshift( $this->grids, $this->default_grid() ); |
| 233 | |
| 234 | ?> |
| 235 | |
| 236 | |
| 237 | <div class="pro_aware grid_container wpmet_pro_a-grid-container"> |
| 238 | |
| 239 | <?php do_action( $this->text_domain . '/pro_awareness/before_grid_contents' ); ?> |
| 240 | |
| 241 | <div class="wpmet_pro_a-row"> |
| 242 | <?php |
| 243 | foreach ( $this->grids as $grid ) { |
| 244 | ?> |
| 245 | <div class="grid wpmet_pro_a-grid"> |
| 246 | <div class="wpmet_pro_a-grid-inner"> |
| 247 | <a target="_blank" rel="noopener noreferrer" href="<?php echo esc_url( $grid['url'] ); ?>" |
| 248 | class="wpmet_pro_a_wrapper" title="<?php echo esc_attr( $grid['title'] ); ?>" |
| 249 | title="<?php echo esc_attr( $grid['title'] ); ?>"> |
| 250 | <div class="wpmet_pro_a_thumb"> |
| 251 | <img src="<?php echo esc_url( $grid['thumbnail'] ); ?>" alt="Thumbnail"> |
| 252 | </div> |
| 253 | <!-- // thumbnail --> |
| 254 | |
| 255 | <h4 class="wpmet_pro_a_grid_title"><?php echo esc_html( $grid['title'] ); ?></h4> |
| 256 | <?php if ( ! empty( $grid['description'] ) ) { ?> |
| 257 | <p class="wpmet_pro_a_description"><?php echo esc_html( $grid['description'] ); ?></p> |
| 258 | <!-- // description --> |
| 259 | <?php } ?> |
| 260 | <!-- // title --> |
| 261 | </a> |
| 262 | </div> |
| 263 | </div> |
| 264 | <?php |
| 265 | } |
| 266 | ?> |
| 267 | </div> |
| 268 | |
| 269 | <div class="wpmet-products hidden"> |
| 270 | <div class="wpmet-products__header"> |
| 271 | <h1><?php esc_html_e('Take your website to the next level','elementskit-lite'); ?></h1> |
| 272 | <p><?php esc_html_e('We have some plugins you can install to get most from Wordpress.','elementskit-lite'); ?> |
| 273 | <br> <?php esc_html_e('These are absolute FREE to use.','elementskit-lite'); ?></p> |
| 274 | </div> |
| 275 | <div class="wpmet-products__content"> |
| 276 | <?php foreach ( $this->products as $product ) : ?> |
| 277 | <a title="<?php echo esc_attr($product['title']); ?>" class="help-card" href="<?php echo esc_url( $product['url'] ); ?>" target="_blank" rel="noopener noreferrer"> |
| 278 | <label> |
| 279 | <img src="<?php echo esc_url( $product['thumbnail'] ); ?>" alt="Thumbnail"> |
| 280 | </label> |
| 281 | <span><?php echo esc_html($product['description']); ?></span></a> |
| 282 | <?php endforeach; ?> |
| 283 | </div> |
| 284 | </div> |
| 285 | |
| 286 | <?php do_action( $this->text_domain . '/pro_awareness/after_grid_contents' ); ?> |
| 287 | |
| 288 | </div> |
| 289 | |
| 290 | <?php |
| 291 | } |
| 292 | |
| 293 | public static function enqueue_scripts() { |
| 294 | echo " |
| 295 | <script> |
| 296 | jQuery(document).ready( function($) { |
| 297 | $('.pro_aware').parent().attr('target','_blank'); |
| 298 | }); |
| 299 | </script> |
| 300 | |
| 301 | <style> |
| 302 | .wpmet_pro_a-grid-container { |
| 303 | max-width: 1350px; |
| 304 | width: 100%; |
| 305 | padding-right: 15px; |
| 306 | padding-left: 15px; |
| 307 | box-sizing: border-box; |
| 308 | margin-top: 50px; |
| 309 | } |
| 310 | |
| 311 | .wpmet_pro_a-grid-inner .wpmet_pro_a_wrapper { |
| 312 | padding: 35px 50px; |
| 313 | display: block; |
| 314 | } |
| 315 | |
| 316 | .wpmet_pro_a-row { |
| 317 | display: grid; |
| 318 | grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); |
| 319 | grid-gap: 30px; |
| 320 | } |
| 321 | |
| 322 | .wpmet_pro_a-grid { |
| 323 | background-color: #fff; |
| 324 | border-radius: 4px; |
| 325 | box-shadow: 0px 2px 5px 10px rgba(0,0,0,.01); |
| 326 | transition: all .4s ease; |
| 327 | } |
| 328 | |
| 329 | .wpmet_pro_a-grid:hover { |
| 330 | transform: translateY(-3px); |
| 331 | box-shadow: 0px 10px 15px 15px rgba(0,0,0,.05); |
| 332 | } |
| 333 | |
| 334 | .wpmet_pro_a_thumb { |
| 335 | min-height: 76px; |
| 336 | margin-bottom: 10px; |
| 337 | display: block; |
| 338 | border-radius: inherit; |
| 339 | } |
| 340 | |
| 341 | .wpmet_pro_a_grid_title { |
| 342 | font-size: 1.6rem; |
| 343 | display: inline-block; |
| 344 | line-height: normal; |
| 345 | text-decoration: none; |
| 346 | margin: 0px; |
| 347 | font-weight: 600; |
| 348 | color: #021343; |
| 349 | } |
| 350 | |
| 351 | .wpmet_pro_a_description { |
| 352 | margin-bottom: 0; |
| 353 | text-decoration: none; |
| 354 | display: inline-block; |
| 355 | margin-top: 10px; |
| 356 | font-size: 15px; |
| 357 | line-height: 22px; |
| 358 | color: #5D5E65; |
| 359 | } |
| 360 | .wp-submenu > li > a{ |
| 361 | position: relative; |
| 362 | } |
| 363 | |
| 364 | .wpmet_pro_a-grid-container .wpmet-products { |
| 365 | margin-top: 80px; |
| 366 | } |
| 367 | |
| 368 | .wpmet_pro_a-grid-container .wpmet-products h1 { |
| 369 | font-size: 40px; |
| 370 | color: #021343; |
| 371 | font-weight: 700; |
| 372 | margin-bottom: 0; |
| 373 | line-height: 44px; |
| 374 | } |
| 375 | |
| 376 | .wpmet_pro_a-grid-container .wpmet-products p { |
| 377 | color: #5D5E65; |
| 378 | font-size: 16px; |
| 379 | } |
| 380 | |
| 381 | .wpmet_pro_a-grid-container .wpmet-products__content { |
| 382 | margin-top: 40px; |
| 383 | display: grid; |
| 384 | grid-gap: 20px; |
| 385 | grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); |
| 386 | } |
| 387 | |
| 388 | .wpmet_pro_a-grid-container .wpmet-products__content .help-card { |
| 389 | background-color: #fff; |
| 390 | border-radius: 4px; |
| 391 | -webkit-box-shadow: 0px 2px 5px 10px #00000003; |
| 392 | box-shadow: 0px 2px 5px 10px #00000003; |
| 393 | -webkit-transition: all .4s ease; |
| 394 | transition: all .4s ease; |
| 395 | padding: 30px; |
| 396 | } |
| 397 | |
| 398 | .wpmet_pro_a-grid-container .wpmet-products__content .help-card:hover { |
| 399 | -webkit-transform: translateY(-3px); |
| 400 | transform: translateY(-3px); |
| 401 | -webkit-box-shadow: 0px 10px 15px 15px #0000000d; |
| 402 | box-shadow: 0px 10px 15px 15px #0000000d; |
| 403 | } |
| 404 | |
| 405 | .wpmet_pro_a-grid-container .wpmet-products__content label { |
| 406 | color: #021343; |
| 407 | font-size: 16px; |
| 408 | font-weight: 700; |
| 409 | display: -webkit-box; |
| 410 | display: -ms-flexbox; |
| 411 | display: flex; |
| 412 | -webkit-column-gap: 10px; |
| 413 | -moz-column-gap: 10px; |
| 414 | column-gap: 10px; |
| 415 | -webkit-box-align: center; |
| 416 | -ms-flex-align: center; |
| 417 | align-items: center; |
| 418 | margin-bottom: 15px; |
| 419 | } |
| 420 | |
| 421 | .wpmet_pro_a-grid-container .wpmet-products__content span { |
| 422 | display: inline-block; |
| 423 | color: #5D5E65; |
| 424 | font-size: 16px; |
| 425 | } |
| 426 | |
| 427 | @media (max-width: 767px) { |
| 428 | .wpmet_pro_a_grid_title { |
| 429 | font-size: 1.2rem; |
| 430 | } |
| 431 | } |
| 432 | </style> |
| 433 | "; |
| 434 | } |
| 435 | |
| 436 | public function insert_plugin_links( $links ) { |
| 437 | |
| 438 | foreach ( $this->action_links as $action_link ) { |
| 439 | |
| 440 | if ( ! empty( $action_link['link'] ) && ! empty( $action_link['text'] ) ) { |
| 441 | |
| 442 | $attributes = ''; |
| 443 | |
| 444 | if ( ! empty( $action_link['attr'] ) ) { |
| 445 | |
| 446 | foreach ( $action_link['attr'] as $key => $val ) { |
| 447 | |
| 448 | $attributes .= $key . '="' . esc_attr( $val ) . '" '; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | $links[] = sprintf( '<a href="%s" ' . $attributes . ' > %s </a>', esc_url( $action_link['link'] ), esc_html( $action_link['text'] ) ); |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | return $links; |
| 457 | } |
| 458 | |
| 459 | public function insert_plugin_row_meta( $links, $file ) { |
| 460 | if ( $file == $this->plugin_file ) { |
| 461 | |
| 462 | foreach ( $this->row_meta_links as $meta ) { |
| 463 | |
| 464 | if ( ! empty( $meta['link'] ) && ! empty( $meta['text'] ) ) { |
| 465 | |
| 466 | $attributes = ''; |
| 467 | |
| 468 | if ( ! empty( $meta['attr'] ) ) { |
| 469 | |
| 470 | foreach ( $meta['attr'] as $key => $val ) { |
| 471 | |
| 472 | $attributes .= $key . '="' . esc_attr( $val ) . '" '; |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | $links[] = sprintf( '<a href="%s" %s > %s </a>', $meta['link'], $attributes, esc_html( $meta['text'] ) ); |
| 477 | } |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | return $links; |
| 482 | } |
| 483 | |
| 484 | public function set_plugin_action_link( $text, $link, $attr = array() ) { |
| 485 | |
| 486 | $this->action_links[] = array( |
| 487 | 'text' => $text, |
| 488 | 'link' => $link, |
| 489 | 'attr' => $attr, |
| 490 | ); |
| 491 | |
| 492 | return $this; |
| 493 | } |
| 494 | |
| 495 | public function set_plugin_row_meta( $text, $link, $attr = array() ) { |
| 496 | |
| 497 | $this->row_meta_links[] = array( |
| 498 | 'text' => $text, |
| 499 | 'link' => $link, |
| 500 | 'attr' => $attr, |
| 501 | ); |
| 502 | |
| 503 | return $this; |
| 504 | } |
| 505 | |
| 506 | public function generate_menus() { |
| 507 | add_filter( 'plugin_action_links_' . $this->plugin_file, array( $this, 'insert_plugin_links' ) ); |
| 508 | add_filter( 'plugin_row_meta', array( $this, 'insert_plugin_row_meta' ), 10, 2 ); |
| 509 | |
| 510 | if ( ! empty( $this->parent_menu_slug ) ) { |
| 511 | $this->prepare_grid_links(); |
| 512 | $this->prepare_pro_links(); |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | public static function init() { |
| 517 | add_action( 'admin_head', array( __CLASS__, 'enqueue_scripts' ) ); |
| 518 | } |
| 519 | |
| 520 | public function call() { |
| 521 | add_action( 'admin_menu', array( $this, 'generate_menus' ), 99999 ); |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | endif; |
| 526 |