Help
8 years ago
Page
8 years ago
Promo
8 years ago
Help.php
8 years ago
Page.php
8 years ago
Pages.php
8 years ago
Promo.php
8 years ago
Page.php
133 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | abstract class AC_Admin_Page { |
| 8 | |
| 9 | /** |
| 10 | * Should this page be displayed when no page is selected |
| 11 | * |
| 12 | * @var bool |
| 13 | */ |
| 14 | private $default; |
| 15 | |
| 16 | /** |
| 17 | * @var string |
| 18 | */ |
| 19 | private $slug; |
| 20 | |
| 21 | /** |
| 22 | * @var string |
| 23 | */ |
| 24 | private $label; |
| 25 | |
| 26 | /** |
| 27 | * @var bool False when menu page is hidden in menu |
| 28 | */ |
| 29 | private $show_in_menu = true; |
| 30 | |
| 31 | /** |
| 32 | * Display pages |
| 33 | * |
| 34 | * @return void |
| 35 | */ |
| 36 | public abstract function display(); |
| 37 | |
| 38 | /** |
| 39 | * Is this the default to to display when no active page is present |
| 40 | * |
| 41 | * @return bool |
| 42 | */ |
| 43 | public function is_default() { |
| 44 | return (bool) $this->default; |
| 45 | } |
| 46 | |
| 47 | public function set_default( $default ) { |
| 48 | $this->default = (bool) $default; |
| 49 | |
| 50 | return $this; |
| 51 | } |
| 52 | |
| 53 | public function get_slug() { |
| 54 | return $this->slug; |
| 55 | } |
| 56 | |
| 57 | public function set_slug( $slug ) { |
| 58 | $this->slug = sanitize_key( $slug ); |
| 59 | |
| 60 | return $this; |
| 61 | } |
| 62 | |
| 63 | public function show_in_menu() { |
| 64 | return $this->show_in_menu; |
| 65 | } |
| 66 | |
| 67 | public function set_show_in_menu( $show ) { |
| 68 | $this->show_in_menu = (bool) $show; |
| 69 | |
| 70 | return $this; |
| 71 | } |
| 72 | |
| 73 | public function get_label() { |
| 74 | return $this->label; |
| 75 | } |
| 76 | |
| 77 | public function set_label( $label ) { |
| 78 | $this->label = $label; |
| 79 | |
| 80 | return $this; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @return string URL |
| 85 | */ |
| 86 | public function get_link() { |
| 87 | return add_query_arg( array( 'tab' => $this->slug ), AC()->admin()->get_settings_url() ); |
| 88 | } |
| 89 | |
| 90 | public function is_current_screen() { |
| 91 | return AC()->admin()->is_current_page( $this->get_slug() ); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Cast page to an array |
| 96 | * |
| 97 | * @return array |
| 98 | */ |
| 99 | public function to_array() { |
| 100 | return array( |
| 101 | 'slug' => $this->get_slug(), |
| 102 | 'label' => $this->get_label(), |
| 103 | 'default' => $this->is_default(), |
| 104 | ); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Show the label of the page |
| 109 | * |
| 110 | * @return string |
| 111 | */ |
| 112 | public function __toString() { |
| 113 | return $this->get_label(); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * @param string $action |
| 118 | * |
| 119 | * @return bool |
| 120 | */ |
| 121 | public function verify_nonce( $action ) { |
| 122 | return wp_verify_nonce( filter_input( INPUT_POST, '_ac_nonce' ), $action ); |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Nonce Field |
| 127 | */ |
| 128 | public function nonce_field( $action ) { |
| 129 | wp_nonce_field( $action, '_ac_nonce', false ); |
| 130 | } |
| 131 | |
| 132 | } |
| 133 |