| 1 |
<?php |
| 2 |
/** |
| 3 |
* Master Addons Popup Builder Initialization |
| 4 |
* |
| 5 |
* @package MasterAddons |
| 6 |
* @subpackage PopupBuilder |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace MasterAddons\Inc\Admin\PopupBuilder; |
| 10 |
|
| 11 |
if (!defined('ABSPATH')) { |
| 12 |
exit; |
| 13 |
} |
| 14 |
|
| 15 |
class Popup_Builder_Init { |
| 16 |
|
| 17 |
private static $instance = null; |
| 18 |
|
| 19 |
public static function get_instance() { |
| 20 |
if (is_null(self::$instance)) { |
| 21 |
self::$instance = new self(); |
| 22 |
} |
| 23 |
return self::$instance; |
| 24 |
} |
| 25 |
|
| 26 |
private function __construct() { |
| 27 |
add_action('init', [$this, 'initialize'], 1); |
| 28 |
add_action('admin_init', [$this, 'admin_redirects']); |
| 29 |
} |
| 30 |
|
| 31 |
public function initialize() { |
| 32 |
Popup_CPT::get_instance(); |
| 33 |
Popup_Admin::get_instance(); |
| 34 |
Popup_Shortcode::get_instance(); |
| 35 |
Elementor_Integration::get_instance(); |
| 36 |
Popup_Frontend::get_instance(); |
| 37 |
} |
| 38 |
|
| 39 |
public function admin_redirects() { |
| 40 |
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only checks of WordPress-set admin query vars for redirect flow; no form data is processed. |
| 41 |
global $pagenow; |
| 42 |
$target_post_type = 'jltma_popup'; |
| 43 |
$redirect_url = admin_url('edit.php?post_type=jltma_popup'); |
| 44 |
|
| 45 |
if ('post.php' === $pagenow && isset($_GET['post'])) { |
| 46 |
if (isset($_GET['action']) && in_array($_GET['action'], ['elementor', 'trash', 'delete', 'restore', 'untrash'], true)) { |
| 47 |
return; |
| 48 |
} |
| 49 |
$post_id = absint($_GET['post']); |
| 50 |
if ($post_id && $target_post_type === get_post_type($post_id)) { |
| 51 |
wp_safe_redirect($redirect_url); |
| 52 |
exit; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
if ('post-new.php' === $pagenow && isset($_GET['post_type'])) { |
| 57 |
$current_post_type = sanitize_key($_GET['post_type']); |
| 58 |
if ($target_post_type === $current_post_type) { |
| 59 |
wp_safe_redirect($redirect_url); |
| 60 |
exit; |
| 61 |
} |
| 62 |
} |
| 63 |
// phpcs:enable WordPress.Security.NonceVerification.Recommended |
| 64 |
} |
| 65 |
} |
| 66 |
|