| 1 |
<?php |
| 2 |
/** |
| 3 |
* Yatra admin setup |
| 4 |
* |
| 5 |
* @package Yatra |
| 6 |
* @since 1.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
defined('ABSPATH') || exit; |
| 10 |
|
| 11 |
/** |
| 12 |
* Main Yatra_Admin Class. |
| 13 |
* |
| 14 |
* @class Yatra |
| 15 |
*/ |
| 16 |
final class Yatra_Admin |
| 17 |
{ |
| 18 |
|
| 19 |
/** |
| 20 |
* The single instance of the class. |
| 21 |
* |
| 22 |
* @var Yatra_Admin |
| 23 |
* @since 1.0.0 |
| 24 |
*/ |
| 25 |
protected static $_instance = null; |
| 26 |
|
| 27 |
|
| 28 |
/** |
| 29 |
* Main Yatra_Admin Instance. |
| 30 |
* |
| 31 |
* Ensures only one instance of Yatra_Admin is loaded or can be loaded. |
| 32 |
* |
| 33 |
* @since 1.0.0 |
| 34 |
* @static |
| 35 |
* @return Yatra_Admin - Main instance. |
| 36 |
*/ |
| 37 |
public static function instance() |
| 38 |
{ |
| 39 |
if (is_null(self::$_instance)) { |
| 40 |
self::$_instance = new self(); |
| 41 |
} |
| 42 |
return self::$_instance; |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
/** |
| 47 |
* Yatra Constructor. |
| 48 |
*/ |
| 49 |
public function __construct() |
| 50 |
{ |
| 51 |
$this->includes(); |
| 52 |
$this->init_hooks(); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Hook into actions and filters. |
| 57 |
* |
| 58 |
* @since 1.0.0 |
| 59 |
*/ |
| 60 |
private function init_hooks() |
| 61 |
{ |
| 62 |
|
| 63 |
add_action('admin_menu', array($this, 'admin_menu')); |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
function admin_menu() |
| 68 |
{ |
| 69 |
$settings_page = add_submenu_page( |
| 70 |
'edit.php?post_type=tour', |
| 71 |
'Settings', |
| 72 |
'Settings', |
| 73 |
'manage_options', |
| 74 |
'yatra-settings', |
| 75 |
array($this, 'settings') |
| 76 |
); |
| 77 |
add_action('load-' . $settings_page, array($this, 'settings_page_init')); |
| 78 |
} |
| 79 |
|
| 80 |
public function settings() |
| 81 |
{ |
| 82 |
Yatra_Admin_Settings::output(); |
| 83 |
|
| 84 |
|
| 85 |
} |
| 86 |
|
| 87 |
public function settings_page_init() |
| 88 |
{ |
| 89 |
global $current_tab, $current_section; |
| 90 |
|
| 91 |
// Include settings pages. |
| 92 |
Yatra_Admin_Settings::get_settings_pages(); |
| 93 |
|
| 94 |
// Get current tab/section. |
| 95 |
$current_tab = empty($_GET['tab']) ? 'general' : sanitize_title(wp_unslash($_GET['tab'])); // WPCS: input var okay, CSRF ok. |
| 96 |
$current_section = empty($_REQUEST['section']) ? '' : sanitize_title(wp_unslash($_REQUEST['section'])); // WPCS: input var okay, CSRF ok. |
| 97 |
|
| 98 |
// Save settings if data has been posted. |
| 99 |
if ('' !== $current_section && apply_filters("yatra_save_settings_{$current_tab}_{$current_section}", !empty($_POST['save']))) { // WPCS: input var okay, CSRF ok. |
| 100 |
Yatra_Admin_Settings::save(); |
| 101 |
} elseif ('' === $current_section && apply_filters("yatra_save_settings_{$current_tab}", !empty($_POST['save']))) { // WPCS: input var okay, CSRF ok. |
| 102 |
Yatra_Admin_Settings::save(); |
| 103 |
} |
| 104 |
|
| 105 |
// Add any posted messages. |
| 106 |
if (!empty($_GET['yatra_error'])) { // WPCS: input var okay, CSRF ok. |
| 107 |
Yatra_Admin_Settings::add_error(wp_kses_post(wp_unslash($_GET['yatra_error']))); // WPCS: input var okay, CSRF ok. |
| 108 |
} |
| 109 |
|
| 110 |
if (!empty($_GET['yatra_message'])) { // WPCS: input var okay, CSRF ok. |
| 111 |
Yatra_Admin_Settings::add_message(wp_kses_post(wp_unslash($_GET['yatra_message']))); // WPCS: input var okay, CSRF ok. |
| 112 |
} |
| 113 |
|
| 114 |
do_action('yatra_settings_page_init'); |
| 115 |
|
| 116 |
|
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
/** |
| 121 |
* Include required core files used in admin. |
| 122 |
*/ |
| 123 |
public function includes() |
| 124 |
{ |
| 125 |
|
| 126 |
include_once YATRA_ABSPATH . 'includes/admin/class-yatra-admin-assets.php'; |
| 127 |
include_once YATRA_ABSPATH . 'includes/admin/class-yatra-admin-post-types.php'; |
| 128 |
include_once YATRA_ABSPATH . 'includes/admin/class-yatra-admin-permalinks.php'; |
| 129 |
|
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
} |
| 134 |
|