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