Skip to content

Commit

Permalink
Fix shortcode (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
nosolosw authored Dec 4, 2017
1 parent 954bdc2 commit 2f237ff
Showing 1 changed file with 31 additions and 26 deletions.
57 changes: 31 additions & 26 deletions targets/wordpress/plugin/class-happychat.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,23 @@ public function __construct() {

private function get_token() {
$current_user = wp_get_current_user();
return get_user_meta($current_user->ID, 'wp_woocommerce_wpcom_signin_access_token', true);
return get_user_meta( $current_user->ID, 'wp_woocommerce_wpcom_signin_access_token', true );
}

public function shortcode_to_happychat_form( $atts ) {
self::do_enqueue_scripts();

$happychat_node_id = 'happychat-form';
return '<span id="'.$happychat_node_id.'">
return '<span id="' . $happychat_node_id . '">
<button class="button view"
onclick="Happychat.open( \''.$happychat_node_id.'\', [ \'woo\' ], \''.self::get_token().'\' )"
onclick="Happychat.open( \'' . $happychat_node_id . '\', [ \'woo\' ], \'' . self::get_token() . '\' )"
>
Chat with us
</button>
</span>';
}

private function should_offer_chat(){
private function should_offer_chat() {
global $wp;

// Display on front page not currently supported.
Expand All @@ -57,23 +59,30 @@ private function should_offer_chat(){
return $should_offer_chat;
}

public function enqueue_scripts() {
if ( self::should_offer_chat() ) {
private function do_enqueue_scripts() {
wp_register_style(
'happychat-form-css',
plugins_url( 'assets/happychat.css', __FILE__ ),
array(),
self::VERSION
);

wp_register_script(
'happychat-form-js',
plugins_url( 'assets/happychat.js', __FILE__ ),
array(),
self::VERSION,
true
);

wp_enqueue_style( 'happychat-form-css' );
wp_enqueue_script( 'happychat-form-js' );

wp_register_style(
'happychat-form-css',
plugins_url( 'assets/happychat.css', __FILE__ ),
array(),
self::VERSION
);
}

wp_register_script(
'happychat-form-js',
plugins_url( 'assets/happychat.js', __FILE__ ),
array(),
self::VERSION,
true
);
public function enqueue_scripts() {
if ( self::should_offer_chat() ) {
self::do_enqueue_scripts();

wp_register_script(
'happychat-form-js-init',
Expand All @@ -83,15 +92,11 @@ public function enqueue_scripts() {
true
);

wp_enqueue_style( 'happychat-form-css' );
wp_enqueue_script( 'happychat-form-js' );

$happychatSettings = array(
$happychat_settings = array(
'token' => self::get_token(),
'groups' => [ 'woo' ]
'groups' => [ 'woo' ],
);

wp_localize_script( 'happychat-form-js-init', 'happychatSettings', $happychatSettings );
wp_localize_script( 'happychat-form-js-init', 'happychatSettings', $happychat_settings );
wp_enqueue_script( 'happychat-form-js-init' );
}
}
Expand Down

0 comments on commit 2f237ff

Please sign in to comment.