From beedeb0bd6c1964bbbf64ee6086a786c291956d1 Mon Sep 17 00:00:00 2001 From: Kevin Pliester Date: Thu, 3 Oct 2019 10:59:27 +0200 Subject: [PATCH] 4.1.0 --- core/classes/class-helpful-frontend.php | 1 + .../classes/class-helpful-helper-feedback.php | 17 +++++++-- .../classes/class-helpful-helper-optimize.php | 1 - core/classes/class-helpful-metabox.php | 2 +- core/classes/class-helpful-setup.php | 36 +++++++++++++++++++ core/classes/class-helpful-shortcodes.php | 7 ++++ helpful.php | 2 +- 7 files changed, 60 insertions(+), 6 deletions(-) diff --git a/core/classes/class-helpful-frontend.php b/core/classes/class-helpful-frontend.php index b51119d..139406f 100644 --- a/core/classes/class-helpful-frontend.php +++ b/core/classes/class-helpful-frontend.php @@ -49,6 +49,7 @@ public function set_user_cookie() { $string = bin2hex( openssl_random_pseudo_bytes( 16 ) ); $string = apply_filters( 'helpful_user_string', $string ); $lifetime = '+30 days'; + $lifetime = apply_filters( 'helpful_user_cookie_time', $lifetime ); if ( ! session_id() ) { session_start(); diff --git a/core/classes/class-helpful-helper-feedback.php b/core/classes/class-helpful-helper-feedback.php index 9d4fb78..1b468ab 100644 --- a/core/classes/class-helpful-helper-feedback.php +++ b/core/classes/class-helpful-helper-feedback.php @@ -74,7 +74,10 @@ public static function getAvatar( $email = null, $size = 55 ) { } } - return sprintf( 'no avatar', $default, $size ); + $html = 'no avatar'; + $html = apply_filters( 'helpful_feedback_noavatar', $html ); + + return sprintf( $html, $default, $size ); } /** @@ -120,7 +123,14 @@ public static function insertFeedback() { $pro = 0; $contra = 0; $message = null; - $post_id = absint( $_REQUEST['post_id'] ); + + if ( ! isset( $_REQUEST['post_id'] ) ) { + $message = 'Helpful Notice: Feedback was not saved because the post id is empty in %s on line %d.'; + helpful_error_log( sprintf( $message, __FILE__, __LINE__ ) ); + return null; + } + + $post_id = absint( sanitize_text_field( wp_unslash( $_REQUEST['post_id'] ) ) ); if ( ! isset( $_REQUEST['message'] ) ) { $message = 'Helpful Notice: Feedback was not saved because the message is empty in %s on line %d.'; @@ -143,7 +153,7 @@ public static function insertFeedback() { } if ( isset( $_REQUEST['message'] ) ) { - $message = sanitize_textarea_field( wp_strip_all_tags( $_REQUEST['message'] ) ); + $message = sanitize_textarea_field( wp_strip_all_tags( wp_unslash( $_REQUEST['message'] ) ) ); $message = stripslashes( $message ); $message = apply_filters( 'helpful_feedback_submit_message', $message ); } @@ -219,6 +229,7 @@ public static function send_email( $feedback ) { '{blog_url}' => site_url(), ]; + $tags = apply_filters( 'helpful_feedback_email_tags', $tags ); $body = get_option( 'helpful_feedback_email_content' ); $body = str_replace( array_keys( $tags ), array_values( $tags ), $body ); diff --git a/core/classes/class-helpful-helper-optimize.php b/core/classes/class-helpful-helper-optimize.php index 2c07e4a..a38ad54 100644 --- a/core/classes/class-helpful-helper-optimize.php +++ b/core/classes/class-helpful-helper-optimize.php @@ -240,7 +240,6 @@ public static function clear_cache() { * @return array */ public static function update_metas() { - $results = []; $response = []; $post_types = get_option( 'helpful_post_types' ); diff --git a/core/classes/class-helpful-metabox.php b/core/classes/class-helpful-metabox.php index e4c523e..d852298 100644 --- a/core/classes/class-helpful-metabox.php +++ b/core/classes/class-helpful-metabox.php @@ -101,7 +101,7 @@ public function save_metabox_data( $post_id ) { } if ( isset( $_POST['helpful_feedback_receivers'] ) ) { - $receivers = sanitize_text_field( $_POST['helpful_feedback_receivers'] ); + $receivers = sanitize_text_field( wp_unslash( $_POST['helpful_feedback_receivers'] ) ); update_post_meta( $post_id, 'helpful_feedback_receivers', $receivers ); } } diff --git a/core/classes/class-helpful-setup.php b/core/classes/class-helpful-setup.php index ac46acc..fac4674 100644 --- a/core/classes/class-helpful-setup.php +++ b/core/classes/class-helpful-setup.php @@ -43,6 +43,7 @@ public function __construct() { add_action( 'admin_menu', [ $this, 'register_admin_menu' ] ); add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); + add_filter( 'plugin_row_meta', [ $this, 'plugin_row_meta' ], 10, 2 ); } /** @@ -296,4 +297,39 @@ public function enqueue_scripts() { wp_localize_script( 'helpful-admin', 'helpful_admin', $vars ); } } + + /** + * Method for adding and filtering plugin row meta of Helpful. + * + * @param array $links default links. + * @param string $file file string. + * + * @return array + */ + public function plugin_row_meta( $links, $file ) { + + if ( false !== strpos( $file, basename( HELPFUL_FILE ) ) ) { + $links['documentation'] = sprintf( + '%s', + 'https://helpful-plugin.info/documentation/', + esc_html_x( 'Documentation', 'plugin row meta', 'helpful' ) + ); + + $links['donate'] = sprintf( + '%s', + 'https://www.buymeacoffee.com/pixelbart', + esc_html_x( 'Donate', 'plugin row meta', 'helpful' ) + ); + + $links['support'] = sprintf( + '%s', + 'https://wordpress.org/support/plugin/helpful/', + esc_html_x( 'Support', 'plugin row meta', 'helpful' ) + ); + + $links = apply_filters( 'helpful_plugin_row_meta', $links ); + } + + return $links; + } } diff --git a/core/classes/class-helpful-shortcodes.php b/core/classes/class-helpful-shortcodes.php index 75180b4..d0a3665 100644 --- a/core/classes/class-helpful-shortcodes.php +++ b/core/classes/class-helpful-shortcodes.php @@ -89,12 +89,16 @@ public function add_to_content( $content ) { $default_template = HELPFUL_PATH . 'templates/helpful.php'; $custom_template = locate_template( 'helpful/helpful.php' ); + do_action( 'helpful_before' ); + if ( '' !== $custom_template ) { include $custom_template; } else { include $default_template; } + do_action( 'helpful_after' ); + $content .= ob_get_contents(); ob_end_clean(); @@ -114,13 +118,16 @@ public function shortcode_helpful( $atts, $content = '' ) { global $post; $defaults = Helpful_Helper_Values::getDefaults(); + $defaults = apply_filters( 'helpful_shortcode_defaults', $defaults ); $user_id = Helpful_Helper_Values::getUser(); if ( get_option( 'helpful_exists_hide' ) && Helpful_Helper_Values::checkUser( $user_id, $post->ID ) ) { return; } + $helpful = shortcode_atts( $defaults, $atts ); + $helpful = apply_filters( 'helpful_shortcode_atts', $helpful ); $hidden = false; $class = ''; diff --git a/helpful.php b/helpful.php index ae385ed..557c9ec 100644 --- a/helpful.php +++ b/helpful.php @@ -32,4 +32,4 @@ } /* Include classes and functions */ -require_once HELPFUL_PATH . 'core/autoload.php'; +require_once HELPFUL_PATH . 'core/autoload.php'; \ No newline at end of file