| 1 |
<?php |
| 2 |
/** |
| 3 |
* The public-facing functionality of the module. |
| 4 |
* |
| 5 |
* @link https://codesupply.co |
| 6 |
* @since 1.0.0 |
| 7 |
* |
| 8 |
* @package Powerkit |
| 9 |
* @subpackage Modules/public |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* The public-facing functionality of the module. |
| 14 |
*/ |
| 15 |
class Powerkit_Coming_Soon_Public extends Powerkit_Module_Public { |
| 16 |
|
| 17 |
/** |
| 18 |
* Initialize |
| 19 |
*/ |
| 20 |
public function initialize() { |
| 21 |
add_filter( 'wp', array( $this, 'init_page' ) ); |
| 22 |
add_action( 'wp', array( $this, 'change_httpcode' ) ); |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Set HTTP status header. |
| 27 |
*/ |
| 28 |
public function change_httpcode() { |
| 29 |
// Check location. |
| 30 |
if ( is_admin() ) { |
| 31 |
return; |
| 32 |
} |
| 33 |
|
| 34 |
// Check Administrator. |
| 35 |
if ( current_user_can( 'editor' ) || current_user_can( 'administrator' ) ) { |
| 36 |
return; |
| 37 |
} |
| 38 |
|
| 39 |
// Check Status. |
| 40 |
if ( ! powerkit_coming_soon_status() ) { |
| 41 |
return; |
| 42 |
} |
| 43 |
|
| 44 |
$httpcode = get_option( 'powerkit_coming_soon_httpcode', 404 ); |
| 45 |
|
| 46 |
status_header( $httpcode ); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Init Page |
| 51 |
*/ |
| 52 |
public function init_page() { |
| 53 |
// Check location. |
| 54 |
if ( is_admin() ) { |
| 55 |
return; |
| 56 |
} |
| 57 |
|
| 58 |
// Check Administrator. |
| 59 |
if ( current_user_can( 'editor' ) || current_user_can( 'administrator' ) ) { |
| 60 |
return; |
| 61 |
} |
| 62 |
|
| 63 |
// Check Status. |
| 64 |
if ( ! powerkit_coming_soon_status() ) { |
| 65 |
return; |
| 66 |
} |
| 67 |
|
| 68 |
add_filter( 'pre_get_document_title', array( $this, 'title' ) ); |
| 69 |
add_action( 'template_redirect', array( $this, 'template' ) ); |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Title |
| 74 |
*/ |
| 75 |
public function title() { |
| 76 |
// Check Status. |
| 77 |
if ( powerkit_coming_soon_status() ) { |
| 78 |
$page_id = get_option( 'powerkit_coming_soon_page' ); |
| 79 |
|
| 80 |
$page = get_post( $page_id ); |
| 81 |
|
| 82 |
// Set title. |
| 83 |
$title = $page ? $page->post_title : esc_html__( 'Coming Soon', 'powerkit' ); |
| 84 |
} |
| 85 |
|
| 86 |
return $title; |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Template |
| 91 |
*/ |
| 92 |
public function template() { |
| 93 |
// Check Status. |
| 94 |
if ( ! powerkit_coming_soon_status() ) { |
| 95 |
return; |
| 96 |
} |
| 97 |
|
| 98 |
$page_id = get_option( 'powerkit_coming_soon_page' ); |
| 99 |
|
| 100 |
// Get page object. |
| 101 |
$object = get_post( $page_id ); |
| 102 |
|
| 103 |
// Get title. |
| 104 |
$title = $object ? $object->post_title : esc_html__( 'Coming Soon', 'powerkit' ); |
| 105 |
|
| 106 |
// Get content. |
| 107 |
$content = $object ? $object->post_content : esc_html__( 'Get Ready... Something Really Cool Is Coming Soon', 'powerkit' ); |
| 108 |
|
| 109 |
// Set template path. |
| 110 |
$template_path = apply_filters( 'powerkit_coming_soon_template', POWERKIT_CS_TEMPLATES . '/default.php' ); |
| 111 |
|
| 112 |
if ( ! file_exists( $template_path ) ) { |
| 113 |
wp_die( 'Template file does not exist!' ); |
| 114 |
} |
| 115 |
|
| 116 |
include_once $template_path; |
| 117 |
|
| 118 |
die(); |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Register the stylesheets for the public-facing side of the site. |
| 123 |
*/ |
| 124 |
public function wp_enqueue_scripts() { |
| 125 |
// Styles. |
| 126 |
wp_enqueue_style( 'powerkit-coming-soon', powerkit_style( plugin_dir_url( __FILE__ ) . 'css/public-powerkit-coming-soon.css' ), array(), powerkit_get_setting( 'version' ), 'all' ); |
| 127 |
|
| 128 |
// Add RTL support. |
| 129 |
wp_style_add_data( 'powerkit-coming-soon', 'rtl', 'replace' ); |
| 130 |
} |
| 131 |
} |
| 132 |
|