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