class-wpcode-auto-insert-admin.php
1 year ago
class-wpcode-auto-insert-archive.php
1 year ago
class-wpcode-auto-insert-everywhere.php
4 months ago
class-wpcode-auto-insert-single.php
1 year ago
class-wpcode-auto-insert-site-wide.php
1 year ago
class-wpcode-auto-insert-type.php
4 months ago
class-wpcode-auto-insert-admin.php
111 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class to auto-insert snippets in the Admin area. |
| 4 | * |
| 5 | * @package wpcode |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * Class WPCode_Auto_Insert_Admin. |
| 14 | */ |
| 15 | class WPCode_Auto_Insert_Admin extends WPCode_Auto_Insert_Type { |
| 16 | |
| 17 | /** |
| 18 | * The category of this type. |
| 19 | * |
| 20 | * @var string |
| 21 | */ |
| 22 | public $category = 'global'; |
| 23 | |
| 24 | /** |
| 25 | * Load the available options and labels. |
| 26 | * |
| 27 | * @return void |
| 28 | */ |
| 29 | public function init() { |
| 30 | $this->locations = array( |
| 31 | 'admin_head' => array(), |
| 32 | 'admin_footer' => array(), |
| 33 | ); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Load the label. |
| 38 | * |
| 39 | * @return void |
| 40 | */ |
| 41 | public function load_label() { |
| 42 | $this->label = __( 'Admin Area', 'insert-headers-and-footers' ); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Load the available locations. |
| 47 | * |
| 48 | * @return void |
| 49 | */ |
| 50 | public function load_locations() { |
| 51 | $this->locations = array( |
| 52 | 'admin_head' => array( |
| 53 | 'label' => esc_html__( 'Admin header', 'insert-headers-and-footers' ), |
| 54 | 'description' => esc_html__( 'Insert snippet in the wp-admin header area.', 'insert-headers-and-footers' ), |
| 55 | ), |
| 56 | 'admin_footer' => array( |
| 57 | 'label' => esc_html__( 'Admin footer', 'insert-headers-and-footers' ), |
| 58 | 'description' => esc_html__( 'Insert snippet in the wp-admin footer.', 'insert-headers-and-footers' ), |
| 59 | ), |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Checks if we are on an archive page and we should be executing hooks. |
| 65 | * |
| 66 | * @return bool |
| 67 | */ |
| 68 | public function conditions() { |
| 69 | return is_admin(); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Add hooks specific to single posts. |
| 74 | * |
| 75 | * @return void |
| 76 | */ |
| 77 | public function hooks() { |
| 78 | add_action( 'admin_head', array( $this, 'insert_admin_head' ), 9 ); |
| 79 | add_action( 'admin_footer', array( $this, 'insert_admin_footer' ), 9 ); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Output snippet in the admin head. |
| 84 | * |
| 85 | * @return void |
| 86 | */ |
| 87 | public function insert_admin_head() { |
| 88 | $this->output_location( 'admin_head' ); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Output snippet in the admin footer. |
| 93 | * |
| 94 | * @return void |
| 95 | */ |
| 96 | public function insert_admin_footer() { |
| 97 | $this->output_location( 'admin_footer' ); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Override the parent method to add the start hook specific to the admin. |
| 102 | * |
| 103 | * @return void |
| 104 | */ |
| 105 | protected function add_start_hook() { |
| 106 | add_action( 'admin_init', array( $this, 'maybe_run_hooks' ) ); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | new WPCode_Auto_Insert_Admin(); |
| 111 |