| 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 |
if ( powerkit_coming_soon_page_visible() || powerkit_coming_soon_site_visible() ) { |
| 35 |
$httpcode = get_option( 'powerkit_coming_soon_httpcode', 404 ); |
| 36 |
|
| 37 |
status_header( $httpcode ); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Init Page |
| 43 |
*/ |
| 44 |
public function init_page() { |
| 45 |
// Check location. |
| 46 |
if ( is_admin() ) { |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
if ( powerkit_coming_soon_page_visible() || powerkit_coming_soon_site_visible() ) { |
| 51 |
add_filter( 'pre_get_document_title', array( $this, 'title' ) ); |
| 52 |
add_action( 'template_redirect', array( $this, 'template' ) ); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Title |
| 58 |
*/ |
| 59 |
public function title() { |
| 60 |
$page_id = get_option( 'powerkit_coming_soon_page' ); |
| 61 |
|
| 62 |
if ( $page_id ) { |
| 63 |
|
| 64 |
$page = get_post( $page_id ); |
| 65 |
|
| 66 |
// Set title. |
| 67 |
$title = $page ? $page->post_title : esc_html__( 'Coming Soon', 'powerkit' ); |
| 68 |
|
| 69 |
return $title; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Template |
| 75 |
*/ |
| 76 |
public function template() { |
| 77 |
$page_id = get_option( 'powerkit_coming_soon_page' ); |
| 78 |
|
| 79 |
if ( $page_id ) { |
| 80 |
// Get page object. |
| 81 |
$object = get_post( $page_id ); |
| 82 |
|
| 83 |
// Get title. |
| 84 |
$title = $object ? $object->post_title : esc_html__( 'Coming Soon', 'powerkit' ); |
| 85 |
|
| 86 |
// Get content. |
| 87 |
$content = $object ? $object->post_content : esc_html__( 'Get Ready... Something Really Cool Is Coming Soon', 'powerkit' ); |
| 88 |
|
| 89 |
// Set template path. |
| 90 |
$template_path = apply_filters( 'powerkit_coming_soon_template', POWERKIT_CS_TEMPLATES . '/default.php' ); |
| 91 |
|
| 92 |
if ( ! file_exists( $template_path ) ) { |
| 93 |
wp_die( 'Template file does not exist!' ); |
| 94 |
} |
| 95 |
|
| 96 |
include_once $template_path; |
| 97 |
} |
| 98 |
|
| 99 |
die(); |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Register the stylesheets for the public-facing side of the site. |
| 104 |
*/ |
| 105 |
public function wp_enqueue_scripts() { |
| 106 |
// Styles. |
| 107 |
wp_enqueue_style( 'powerkit-coming-soon', powerkit_style( plugin_dir_url( __FILE__ ) . 'css/public-powerkit-coming-soon.css' ), array(), powerkit_get_setting( 'version' ), 'all' ); |
| 108 |
|
| 109 |
// Add RTL support. |
| 110 |
wp_style_add_data( 'powerkit-coming-soon', 'rtl', 'replace' ); |
| 111 |
} |
| 112 |
} |
| 113 |
|