Skip to content

Commit

Permalink
トライアルメッセージ出せるようにする
Browse files Browse the repository at this point in the history
Top bar の仕組みを参考に、カスタマイザーにトップバーのための仕組みを作成。

- header.php を子テーマに
- includes/trial.php にカスタマイザーや、トライアルメッセージのためのテンプレートタグを追加
  • Loading branch information
toiee-kameda committed Nov 30, 2020
1 parent 1c46d98 commit a2241f1
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 5 deletions.
109 changes: 109 additions & 0 deletions header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php
/**
* The header for our theme.
*
* Displays all of the <head> section and everything up till <div id="content">
*
* @package BusinessPress
*/
?><!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>
<div id="page" class="site">
<a class="skip-link screen-reader-text" href="#content"><?php esc_html_e( 'Skip to content', 'businesspress' ); ?></a>

<header id="masthead" class="site-header">

<?php if ( get_theme_mod( 'kameradio_enable_trial_bar' ) && tlib_user_is_trial() ) : ?>
<div class="top-bar top-bar-trial">
<div class="top-bar-content top-bar-content-trial">
<?php kameradio_top_bar_trial_message(); ?>
</div><!-- .top-bar-content -->
</div><!-- .top-bar -->
<?php endif; ?>

<?php if ( get_theme_mod( 'businesspress_enable_top_bar' ) ) : ?>
<div class="top-bar">
<div class="top-bar-content">
<?php businesspress_top_bar_main(); ?>
<?php businesspress_header_social_link(); ?>
</div><!-- .top-bar-content -->
</div><!-- .top-bar -->
<?php endif; ?>

<div class="main-header main-header-original">
<div class="main-header-content">
<div class="site-branding">
<?php businesspress_logo(); ?>
<?php businesspress_title(); ?>
</div><!-- .site-branding -->
<?php businesspress_main_navigation(); ?>
<button class="drawer-hamburger">
<span class="screen-reader-text"><?php esc_html_e( 'Menu', 'businesspress' ); ?></span>
<span class="drawer-hamburger-icon"></span>
</button>
</div><!-- .main-header-content -->
<div class="drawer-overlay"></div>
<div class="drawer-navigation">
<div class="drawer-navigation-content">
<?php businesspress_main_navigation(); ?>
<?php if ( get_theme_mod( 'businesspress_enable_top_bar' ) ) : ?>
<?php businesspress_header_social_link(); ?>
<?php endif; ?>
</div><!-- .drawer-navigation-content -->
</div><!-- .drawer-navigation -->
</div><!-- .main-header -->

<?php if ( is_front_page() && get_theme_mod( 'businesspress_enable_home_header' ) ) : ?>
<?php get_template_part( 'template-parts/content', 'home-header' ); ?>
<?php elseif ( is_page() && ! get_post_meta( get_the_ID(), 'businesspress_hide_page_title', true ) ) : ?>
<div class="jumbotron"<?php businesspress_post_background(); ?>>
<div class="jumbotron-overlay">
<div class="jumbotron-content">
<?php if ( ! get_theme_mod( 'businesspress_hide_subheader' ) ) : ?>
<div class="subheader"><?php echo esc_attr( str_replace( '-', ' ', get_post_field( 'post_name', get_the_ID() ) ) ) ; ?></div>
<?php endif; ?>
<h2 class="jumbotron-title"><?php the_title(); ?></h2>
</div><!-- .jumbotron-content -->
</div><!-- .jumbotron-overlay -->
</div><!-- .jumbotron -->
<?php endif; ?>

<?php if ( is_home() && ! is_paged() && get_theme_mod( 'businesspress_enable_featured_slider' ) ) : ?>
<div class="featured-post">
<?php
$featured = new WP_Query( array(
'cat' => get_theme_mod( 'businesspress_featured_category' ),
'posts_per_page' => get_theme_mod( 'businesspress_featured_slider_number', '4' ),
'no_found_rows' => true,
'ignore_sticky_posts' => true
) );
if ( $featured->have_posts() ) :
while ( $featured->have_posts() ) : $featured->the_post();
get_template_part( 'template-parts/content', 'featured' );
endwhile;
endif;
wp_reset_postdata(); ?>
</div><!-- .featured-post -->
<?php elseif ( is_home() && ! is_paged() && ! is_front_page() && ! get_post_meta( get_option( 'page_for_posts' ), 'businesspress_hide_page_title', true ) ) : ?>
<div class="jumbotron"<?php businesspress_post_background( get_post_thumbnail_id( get_option( 'page_for_posts' ) ) ); ?>>
<div class="jumbotron-overlay">
<div class="jumbotron-content">
<?php if ( ! get_theme_mod( 'businesspress_hide_subheader' ) ) : ?>
<div class="subheader"><?php echo esc_attr( str_replace( '-', ' ', get_post_field( 'post_name', get_option( 'page_for_posts' ) ) ) ); ?></div>
<?php endif; ?>
<h1 class="jumbotron-title"><?php echo get_the_title( get_option( 'page_for_posts' ) ); ?></h1>
</div><!-- .jumbotron-content -->
</div><!-- .jumbotron-overlay -->
</div><!-- .jumbotron -->
<?php endif; ?>

</header><!-- #masthead -->

<div id="content" class="site-content">
62 changes: 58 additions & 4 deletions includes/trial.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/
if( function_exists('acf_add_options_page') && function_exists( 'wc_memberships_get_user_active_memberships' ) ) :

function tlib_user_is_trial() {
$user_id = get_current_user_id();
function tlib_user_is_trial( $return_end_date = false ) {
$user_id = get_current_user_id();
$memberships = wc_memberships_get_user_active_memberships( $user_id );
$premiums = get_field( 'premium_member_plans', 'option' );
$trial = get_field( 'trial_member_plan', 'option' );
Expand All @@ -25,8 +25,13 @@ function tlib_user_is_trial() {

// トライアルを持っていたら、メッセージを出す
if ( isset( $mem_ids[ $trial ] ) ) {
return true;
echo "Beacon('show-message', '{$trial_msgid}' );\n";
if ( $return_end_date ) {
$id = ($mem_ids[ $trial ])->id;
$end_date = get_post_meta( $id, '_end_date', true );
return $end_date;
} else {
return true;
}
}

return false;
Expand Down Expand Up @@ -150,3 +155,52 @@ function( $classes ) {
));

endif;


/**
* トライアルバーを表示するための設定
*/
function tlib_trial_trial_bar( $wp_customize ) {
// Top Bar
$wp_customize->add_section( 'kameradio_trial_bar', array(
'title' => esc_html__( 'トライアル・バー', 'kameradio' ),
'priority' => 50,
) );
$wp_customize->add_setting( 'kameradio_enable_trial_bar', array(
'default' => '',
'sanitize_callback' => 'businesspress_sanitize_checkbox',
) );
$wp_customize->add_control( 'kameradio_enable_trial_bar', array(
'label' => esc_html__( 'Enable Trial Bar', 'kameradio' ),
'section' => 'kameradio_trial_bar',
'type' => 'checkbox',
'priority' => 1,
) );
$wp_customize->add_setting( 'kameradio_trial_bar_text', array(
'default' => '',
'sanitize_callback' => 'wp_kses',
) );
$wp_customize->add_control( 'kameradio_trial_bar_text', array(
'label' => esc_html__( 'Message', 'kameradio' ),
'section' => 'kameradio_trial_bar',
'type' => 'text',
'priority' => 2,
) );
}
add_action( 'customize_register', 'tlib_trial_trial_bar' );

/**
* トライアルメッセージを表示する
*
* @return void
*/
function kameradio_top_bar_trial_message() {
$_end_date = tlib_user_is_trial( true );
$end_date = date( 'Y/m/d', strtotime( $_end_date ) );
$remain = floor( ( strtotime( $_end_date ) - time() ) / 60 / 60 / 24 );
$message = get_theme_mod( 'kameradio_trial_bar_text' );
$message = get_theme_mod( 'kameradio_trial_bar_text' );

$message = str_replace( array( '%remain%', '%end_date%' ), array( $remain, $end_date ), $message );
echo $message;
}
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Description: Businesspress child theme.
Author: toiee Lab
Author URI: https://toiee.jp/
Template: businesspress
Version: 1.7.1
Version: 1.8
*/

.page-title-series {
Expand Down

0 comments on commit a2241f1

Please sign in to comment.