Skip to content

Commit

Permalink
4.4.8
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelbart committed Sep 23, 2020
1 parent 6998688 commit 8b63f35
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 41 deletions.
17 changes: 9 additions & 8 deletions core/assets/js/helpful.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
});

$.each($(".helpful"), function () {
var current_container = $(this);
var currentContainer = $(this);

if ($(current_container).is(".helpful-prevent-form")) {
self.feedbackForm(current_container);
if ($(currentContainer).is(".helpful-prevent-form")) {
self.feedbackForm(currentContainer);
}

if ($(current_container).find(".helpful-toggle-feedback").length) {
$(current_container).find(".helpful-toggle-feedback").click(function (e) {
if ($(currentContainer).find(".helpful-toggle-feedback").length) {
$(currentContainer).find(".helpful-toggle-feedback").click(function (e) {
e.preventDefault();
$(this).parent().find("div").removeAttr("hidden");
$(this).remove();
Expand All @@ -59,10 +59,11 @@
e.preventDefault();

var ajaxData = {
action: "helpful_save_feedback",
cancel: 1,
type: $(currentForm).find("[name='type']").val(),
"action": "helpful_save_feedback",
"cancel": 1,
"type": $(currentForm).find("[name='type']").val(),
"_wpnonce": $(currentForm).find("[name='_wpnonce']").val(),
"post_id": $(currentForm).find("[name='post_id']").val(),
};

var request = self.ajaxRequest(ajaxData);
Expand Down
25 changes: 13 additions & 12 deletions core/helpers/class-values.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,29 @@ public static function get_defaults()
*/
public static function convert_tags( $string, $post_id )
{
$post = get_post( $post_id );
$pro = Stats::get_pro( $post_id );
$contra = Stats::get_contra( $post_id );

if ( ! isset( $post->ID ) ) {
return $string;
}
$display_name = '';
$author_id = get_post_field( 'post_author', $post_id );

$pro = Stats::get_pro( $post->ID );
$contra = Stats::get_contra( $post->ID );
if ( $author_id ) {
$display_name = get_the_author_meta( 'display_name', $author_id );
}

$tags = [
'{pro}' => $pro,
'{contra}' => $contra,
'{total}' => ( (int) $pro + (int) $contra ),
'{permalink}' => esc_url( get_permalink( $post->ID ) ),
'{author}' => get_the_author_meta( 'display_name', $post->post_author ),
'{pro_percent}' => Stats::get_pro( $post->ID, true ),
'{contra_percent}' => Stats::get_contra( $post->ID, true ),
'{feedback_form}' => Feedback::after_vote( $post->ID, true ),
'{permalink}' => esc_url( get_permalink( $post_id ) ),
'{author}' => $display_name,
'{pro_percent}' => Stats::get_pro( $post_id, true ),
'{contra_percent}' => Stats::get_contra( $post_id, true ),
'{feedback_form}' => Feedback::after_vote( $post_id, true ),
'{feedback_toggle}' => sprintf(
'<div class="helpful-feedback-toggle-container"><button class="helpful-button helpful-toggle-feedback" type="button" role="button">%s</button><div hidden>%s</div></div>',
_x( 'Give feedback', 'toggle feedback button', 'helpful' ),
Feedback::after_vote( $post->ID, true )
Feedback::after_vote( $post_id, true )
),
];

Expand Down
26 changes: 7 additions & 19 deletions core/modules/class-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ public function __construct()
add_action( 'wp', [ &$this, 'set_user_cookie' ], 1 );
add_filter( 'helpful_themes', [ &$this, 'default_themes' ], 1 );
add_action( 'wp_enqueue_scripts', [ &$this, 'enqueue_scripts' ], PHP_INT_MAX );

add_action( 'wp_ajax_helpful_save_vote', [ &$this, 'save_vote' ] );
add_action( 'wp_ajax_helpful_save_feedback', [ &$this, 'save_feedback' ] );
add_action( 'wp_ajax_nopriv_helpful_save_vote', [ &$this, 'save_vote' ] );
add_action( 'wp_ajax_nopriv_helpful_save_feedback', [ &$this, 'save_feedback' ] );

add_filter( 'the_content', [ &$this, 'the_content' ] );
add_shortcode( 'helpful', [ &$this, 'helpful' ] );
add_action( 'helpful_the_content', [ &$this, 'replace_tags' ], 10, 2 );
add_action( 'helpful_the_shortcode', [ &$this, 'replace_tags' ], 10, 2 );
}

/**
Expand Down Expand Up @@ -211,7 +211,7 @@ public function save_vote()
}
}

echo apply_filters( 'helpful_the_content', $response, $post_id );
echo Helpers\Values::convert_tags( $response, $post_id );
wp_die();
}

Expand Down Expand Up @@ -245,7 +245,7 @@ public function save_feedback()

if ( ! empty( $_REQUEST['website'] ) && true === $spam_protection ) {
$message = do_shortcode( get_option( 'helpful_feedback_message_spam' ) );
echo apply_filters( 'helpful_the_content', $message, $post_id );
echo Helpers\Values::convert_tags( $message, $post_id );
wp_die();
}

Expand All @@ -267,8 +267,7 @@ public function save_feedback()
$message = do_shortcode( get_option( 'helpful_after_fallback' ) );
}

echo apply_filters( 'helpful_the_content', $message, $post_id );

echo Helpers\Values::convert_tags( $message, $post_id );
wp_die();
}

Expand Down Expand Up @@ -364,7 +363,7 @@ public function the_content( $content )
$shortcode = ob_get_contents();
ob_end_clean();

$shortcode = apply_filters( 'helpful_the_content', $shortcode, $helpful['post_id'] );
$shortcode = Helpers\Values::convert_tags( $shortcode, $helpful['post_id'] );

return $content . $shortcode;
}
Expand Down Expand Up @@ -441,19 +440,8 @@ public function helpful( $atts, $content = '' )
$shortcode = ob_get_contents();
ob_end_clean();

$shortcode = apply_filters( 'helpful_the_shortcode', $shortcode, $helpful['post_id'] );
$shortcode = Helpers\Values::convert_tags( $shortcode, $helpful['post_id'] );

return $content . $shortcode;
}

/**
* @param string
* @return string
*/
public function replace_tags( $content, $post_id )
{
$content = Helpers\Values::convert_tags( $content, $post_id );

return $content;
}
}
2 changes: 1 addition & 1 deletion helpful.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: Helpful
* Description: Add a fancy feedback form under your posts or post-types and ask your visitors a question. Give them the abbility to vote with yes or no.
* Version: 4.4.7
* Version: 4.4.8
* Author: Pixelbart
* Author URI: https://pixelbart.de
* Text Domain: helpful
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: helpful, poll, feedback, reviews, vote, review, voting
Requires at least: 4.6
Tested up to: 5.6
Requires PHP: 5.6.20
Stable tag: 4.4.7
Stable tag: 4.4.8
License: MIT License
License URI: https://opensource.org/licenses/MIT

Expand Down

0 comments on commit 8b63f35

Please sign in to comment.