| 1 |
<?php |
| 2 |
/** |
| 3 |
* Whols Frontend |
| 4 |
* |
| 5 |
* @since 1.0.0 |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Whols; |
| 9 |
|
| 10 |
/** |
| 11 |
* Frontend class. |
| 12 |
*/ |
| 13 |
class Frontend { |
| 14 |
public $version = ''; |
| 15 |
|
| 16 |
/** |
| 17 |
* Frontend constructor. |
| 18 |
* |
| 19 |
* @since 1.0.0 |
| 20 |
*/ |
| 21 |
public function __construct() { |
| 22 |
// Set time as the version for development mode. |
| 23 |
if( defined('WP_DEBUG') && WP_DEBUG ){ |
| 24 |
$this->version = time(); |
| 25 |
} else { |
| 26 |
$this->version = WHOLS_VERSION; |
| 27 |
} |
| 28 |
|
| 29 |
// Admin assets hook into action. |
| 30 |
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend_assets' ) ); |
| 31 |
|
| 32 |
// Filter the content to add the [whols_registration_form] shortcode to the assigned page |
| 33 |
add_filter( 'the_content', array( $this, 'filter_the_content' ) ); |
| 34 |
|
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Enqueue frontend assets |
| 39 |
* |
| 40 |
* @since 1.0.0 |
| 41 |
*/ |
| 42 |
public function enqueue_frontend_assets() { |
| 43 |
// Scripts |
| 44 |
$suffix = \Automattic\Jetpack\Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; |
| 45 |
wp_enqueue_script( 'serializejson', WC()->plugin_url() . '/assets/js/jquery-serializejson/jquery.serializejson' . $suffix . '.js', array( 'jquery' ), '2.8.1' ); |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
/** |
| 50 |
* If the content doesn't have the shortcode, add it to the end of the content |
| 51 |
* |
| 52 |
* @param content The content of the post. |
| 53 |
* |
| 54 |
* @return The content of the page, with the shortcode appended to the end. |
| 55 |
*/ |
| 56 |
public function filter_the_content( $content ){ |
| 57 |
global $post; |
| 58 |
|
| 59 |
if( $post && $post->ID == whols_get_option('registration_page') && !has_shortcode($content, 'whols_registration_form') ){ |
| 60 |
$shortcode = do_shortcode('[whols_registration_form]'); |
| 61 |
return $content . $shortcode; |
| 62 |
} |
| 63 |
|
| 64 |
return $content; |
| 65 |
} |
| 66 |
} |