class-insert-head-body-footer-code.php
| 1 | <?php |
| 2 | |
| 3 | namespace ASENHA\Classes; |
| 4 | |
| 5 | /** |
| 6 | * Class for Insert <head>, <body> and <footer> code module |
| 7 | * |
| 8 | * @since 6.9.5 |
| 9 | */ |
| 10 | class Insert_Head_Body_Footer_Code { |
| 11 | |
| 12 | /** |
| 13 | * Insert code before </head> tag |
| 14 | * |
| 15 | * @since 3.3.0 |
| 16 | */ |
| 17 | public function insert_head_code() { |
| 18 | |
| 19 | $this->insert_code( 'head' ); |
| 20 | |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Insert code after <body> tag |
| 25 | * |
| 26 | * @since 3.3.0 |
| 27 | */ |
| 28 | public function insert_body_code() { |
| 29 | |
| 30 | $this->insert_code( 'body' ); |
| 31 | |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Insert code in footer section before </body> tag |
| 36 | * |
| 37 | * @since 3.3.0 |
| 38 | */ |
| 39 | public function insert_footer_code() { |
| 40 | |
| 41 | $this->insert_code( 'footer' ); |
| 42 | |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Insert code |
| 47 | * |
| 48 | * @since 3.3.0 |
| 49 | */ |
| 50 | public function insert_code( $location ) { |
| 51 | |
| 52 | // Do not insert code in admin, feed, robots or trackbacks |
| 53 | if ( is_admin() || is_feed() || is_robots() || is_trackback() ) { |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | // Get option that stores the code |
| 58 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 59 | |
| 60 | if ( 'head' == $location ) { |
| 61 | |
| 62 | $code = array_key_exists( 'head_code', $options ) ? $options['head_code'] : ''; |
| 63 | |
| 64 | } |
| 65 | |
| 66 | if ( 'body' == $location ) { |
| 67 | |
| 68 | $code = array_key_exists( 'body_code', $options ) ? $options['body_code'] : ''; |
| 69 | |
| 70 | } |
| 71 | |
| 72 | if ( 'footer' == $location ) { |
| 73 | |
| 74 | $code = array_key_exists( 'footer_code', $options ) ? $options['footer_code'] : ''; |
| 75 | |
| 76 | } |
| 77 | |
| 78 | // [TODO] Properly escape code |
| 79 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 80 | echo wp_unslash( $code ) . PHP_EOL; |
| 81 | |
| 82 | } |
| 83 | |
| 84 | } |