diff --git a/core/class-helper.php b/core/class-helper.php
index 02d06c2..3d8706d 100644
--- a/core/class-helper.php
+++ b/core/class-helper.php
@@ -9,435 +9,435 @@
namespace Helpful\Core;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
+if (!defined('ABSPATH')) {
+ exit;
}
class Helper
{
- /**
- * Returns the WordPress information about the plugin.
- *
- * @version 4.3.0
- * @return array
- */
- public static function get_plugin_data()
- {
- if ( ! function_exists( 'get_plugin_data' ) ) {
- require_once ABSPATH . 'wp-admin/includes/plugin.php';
- }
-
- $transient_name = 'helpful_plugin_data';
-
- $plugin_data = get_transient( $transient_name );
-
- if ( false === $plugin_data ) {
- $plugin_data = get_plugin_data( HELPFUL_FILE );
-
- set_transient( $transient_name, maybe_serialize( $plugin_data ), HOUR_IN_SECONDS );
- }
-
- return maybe_unserialize( $plugin_data );
- }
-
- /**
- * Set custom timezone if set in the options.
- *
- * @version 4.3.0
- * @return void
- */
- public static function set_timezone()
- {
- $timezone = get_option( 'helpful_timezone' );
-
- if ( isset( $timezone ) && '' !== trim( $timezone ) ) {
- date_default_timezone_set( $timezone );
- }
- }
-
- /**
- * Returns the available options for Same-Site cookies.
- *
- * @return array
- */
- public static function get_samesite_options()
- {
- $defaults = [ 'None', 'Lax', 'Strict' ];
-
- return apply_filters( 'helpful_samesite_options', $defaults );
- }
-
- /**
- * Checks if the current tab is in use.
- *
- * @param string $tab
- *
- * @return bool
- */
- public static function is_active_tab( $tab )
- {
- $screen = get_current_screen();
-
- if ( 'toplevel_page_helpful' !== $screen->base ) {
- return false;
- }
-
- $current = apply_filters( 'helpful_current_tab', false );
-
- if ( $tab !== $current ) {
- return false;
- }
-
- return true;
- }
-
- /**
- * Get credits array.
- *
- * @return array
- */
- public static function get_credits_data()
- {
- $credits = [
- 'url' => apply_filters( 'helpful_credits_url', 'https://helpful-plugin.info' ),
- 'name' => apply_filters( 'helpful_credits_name', 'Helpful' ),
- 'rel' => apply_filters( 'helpful_credits_rel', 'noopener' ),
- ];
-
- $html = '%3$s';
- $html = apply_filters( 'helpful_credits_html', $html );
-
- $credits['html'] = sprintf( $html, $credits['url'], $credits['rel'], $credits['name'] );
-
- return apply_filters( 'helpful_default_credits', $credits );
- }
-
- /**
- * Get admin tabs.
- *
- * @return array
- */
- public static function get_admin_tabs()
- {
- $current = apply_filters( 'helpful_current_tab', false );
- return apply_filters( 'helpful_get_admin_tabs', __return_empty_array(), $current );
- }
-
- /**
- * Get tab url.
- *
- * @param string $tab
- *
- * @return string
- */
- public static function get_tab_url( $tab )
- {
- $tab = sanitize_text_field( wp_unslash( $tab ) );
- return apply_filters( 'helpful_get_tab_url', admin_url( 'admin.php?page=helpful&tab=' . $tab ) );
- }
-
- /**
- * Get tab class.
- *
- * @param string $tab
- *
- * @return string
- */
- public static function get_tab_class( $tab )
- {
- $tab = sanitize_text_field( wp_unslash( $tab ) );
-
- $class = '';
-
- if ( self::is_active_tab( $tab ) ) {
- $class = 'active';
- }
-
- return apply_filters( 'helpful_get_tab_class', $class );
- }
-
- /**
- * Get tab attribute.
- *
- * @param string $tab
- *
- * @return string
- */
- public static function get_tab_attr( $tab )
- {
- $tab = sanitize_text_field( wp_unslash( $tab ) );
-
- $attr = '';
-
- if ( self::is_active_tab( $tab ) ) {
- $attr = 'selected';
- }
-
- return apply_filters( 'helpful_get_tab_attr', $attr );
- }
-
- /**
- * Returns the URL of the logo.
- *
- * @return string
- */
- public static function get_logo()
- {
- $logo = plugins_url( 'core/assets/images/helpful-heart.svg', HELPFUL_FILE );
- return apply_filters( 'helpful_logo', $logo );
- }
-
- /**
- * Returns an array of media data from Helpful.
- *
- * @return array
- */
- public static function get_plugin_media_data()
- {
- $media = [
- 'logo' => self::get_logo(),
- 'color' => '#88c057',
- ];
-
- return apply_filters( 'helpful_media_data', $media );
- }
-
- /**
- * Plugins URL
- *
- * @param string $path
- *
- * @return string
- */
- public static function plugins_url( $path )
- {
- return plugins_url( $path, HELPFUL_FILE );
- }
-
- /**
- * Filter the conditions and check if you are for example on the homepage and not in the single view.
- *
- * @version 4.3.0
- *
- * @return array
- */
- public static function get_conditions()
- {
- $conditions = [];
-
- if ( ! is_singular() ) {
- $conditions[] = 'is_not_singular';
- }
-
- if ( is_archive() ) {
- $conditions[] = 'is_archive';
- }
-
- if ( is_home() ) {
- $conditions[] = 'is_home';
- }
-
- if ( is_front_page() ) {
- $conditions[] = 'is_front_page';
- }
-
- return apply_filters( 'helpful_conditions', $conditions );
- }
-
- /**
- * Get html output for alerts.
- *
- * @param string $message
- * @param string $type
- * @param int $close
- *
- * @return string
- */
- public static function get_alert( $message, $type = 'none', $close = 2500 )
- {
- $classes = 'helpful-alert helpful-auto-close';
-
- $types = [ 'success', 'danger', 'info' ];
-
- if ( in_array( $type, $types ) ) {
- $classes .= ' helpful-alert-' . $type;
- }
-
- $close = intval( $close );
-
- return sprintf( '
%s
', $classes, $close, $message );
- }
-
- /**
- * Translatable Datatables Language String
- *
- * @return array
- */
- public static function datatables_language_string()
- {
- $language = [
- 'decimal' => esc_html_x( '', 'datatables decimal', 'helpful' ),
- 'emptyTable' => esc_html_x( 'No data available in table', 'datatables emptyTable', 'helpful' ),
- 'info' => esc_html_x( 'Showing _START_ to _END_ of _TOTAL_ entries', 'datatables info', 'helpful' ),
- 'infoEmpty' => esc_html_x( 'Showing 0 to 0 of 0 entries', 'datatables infoEmpty', 'helpful' ),
- 'infoFiltered' => esc_html_x( '(filtered from _MAX_ total entries)', 'datatables infoFiltered', 'helpful' ),
- 'infoPostFix' => esc_html_x( '', 'datatables infoPostFix', 'helpful' ),
- 'thousands' => esc_html_x( ',', 'datatables thousands', 'helpful' ),
- 'lengthMenu' => esc_html_x( 'Show _MENU_ entries', 'datatables lengthMenu', 'helpful' ),
- 'loadingRecords' => esc_html_x( 'Loading...', 'datatables loadingRecords', 'helpful' ),
- 'processing' => esc_html_x( 'Processing...', 'datatables processing', 'helpful' ),
- 'search' => esc_html_x( 'Search:', 'datatables search', 'helpful' ),
- 'zeroRecords' => esc_html_x( 'No matching records found', 'datatables zeroRecords', 'helpful' ),
- 'paginate' => [
- 'first' => esc_html_x( 'First', 'datatables first', 'helpful' ),
- 'last' => esc_html_x( 'Last', 'datatables last', 'helpful' ),
- 'next' => esc_html_x( 'Next', 'datatables next', 'helpful' ),
- 'previous' => esc_html_x( 'Previous', 'datatables previous', 'helpful' ),
- ],
- 'aria' => [
- 'sortAscending' => esc_html_x( ': activate to sort column ascending', 'datatables sortAscending', 'helpful' ),
- 'sortDescending' => esc_html_x( ': activate to sort column descending', 'datatables sortDescending', 'helpful' ),
- ],
- 'select' => [
- 'rows' => [
- '_' => esc_html_x( '%d rows selected', 'datatables previous', 'helpful' ),
- '0' => esc_html_x( '', 'datatables previous', 'helpful' ),
- '1' => esc_html_x( '1 row selected', 'datatables previous', 'helpful' ),
- ],
- ],
- 'buttons' => [
- 'print' => esc_html_x( 'Print', 'datatables print', 'helpful' ),
- 'colvis' => esc_html_x( 'Columns', 'datatables colvis', 'helpful' ),
- 'copy' => esc_html_x( 'Copy', 'datatables copy', 'helpful' ),
- 'copyTitle' => esc_html_x( 'Copy to clipboard', 'datatables copyTitle', 'helpful' ),
- 'copyKeys' => esc_html_x(
- 'Press ctrl or \u2318 + C to copy table
to temporary storage.
To cancel, click on the message or press Escape.',
- 'datatables copyKeys',
- 'helpful'
- ),
- 'copySuccess' => [
- '_' => esc_html_x( '%d rows copied', 'datatables copySuccess', 'helpful' ),
- '1' => esc_html_x( '1 row copied', 'datatables copySuccess', 'helpful' ),
- ],
- 'pageLength' => [
- '-1' => esc_html_x( 'Show all rows', 'datatables pageLength', 'helpful' ),
- '_' => esc_html_x( 'Show %d rows', 'datatables pageLength', 'helpful' ),
- ],
- ],
- ];
-
- return apply_filters( 'helpful_datatables_language', $language );
- }
-
- /**
- * Returns non-permitted characters and words from the WordPress blacklist.
- *
- * @return string
- */
- public static function get_disallowed_keys()
- {
- if ( version_compare( get_bloginfo( 'version' ), '5.5.0' ) >= 0 ) {
- return trim( get_option( 'disallowed_keys' ) );
- }
-
- return trim( get_option( 'blacklist_keys' ) );
- }
-
- /**
- * Checks if the content is set on the internal blacklist of WordPress
- *
- * @param string $content the content to be checked.
- *
- * @return bool
- */
- public static function backlist_check( $content )
- {
- $mod_keys = self::get_disallowed_keys();
-
- if ( '' === $mod_keys ) {
- return false;
- }
-
- $without_html = wp_strip_all_tags( $content );
- $words = explode( "\n", $mod_keys );
-
- foreach ( (array) $words as $word ) :
- $word = trim( $word );
-
- if ( empty( $word ) ) {
- continue;
- }
-
- $word = preg_quote( $word, '#' );
- $pattern = "#$word#i";
-
- if ( preg_match( $pattern, $content ) || preg_match( $pattern, $without_html ) ) {
- return true;
- }
- endforeach;
-
- return false;
- }
-
- /**
- * Checks if the current page uses AMP.
- *
- * @return bool
- */
- public static function is_amp()
- {
- if ( function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() ) {
- return true;
- }
-
- if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
- return true;
- }
-
- return false;
- }
-
- /**
- * Sets a capability.
- *
- * @param string $option
- * @param string $value
- *
- * @return void
- */
- public static function set_capability( $option, $value )
- {
- $options = [
- 'helpful_capability',
- 'helpful_settings_capability',
- 'helpful_feedback_capability',
- ];
-
- if ( ! in_array( $option, $options ) ) {
- return;
- }
-
- if ( null === $value || false === $value ) {
- delete_option( $option );
- }
-
- update_option(
- sanitize_text_field( $option ),
- sanitize_text_field( $value )
- );
- }
-
- /**
- * Checks if the feedback was deactivated by option.
- *
- * @return bool
- */
- public static function is_feedback_disabled()
- {
- if ( 'on' !== get_option( 'helpful_feedback_disabled' ) ) {
- return false;
- }
-
- return true;
- }
-}
\ No newline at end of file
+ /**
+ * Returns the WordPress information about the plugin.
+ *
+ * @version 4.3.0
+ * @return array
+ */
+ public static function get_plugin_data()
+ {
+ if (!function_exists('get_plugin_data')) {
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
+ }
+
+ $transient_name = 'helpful_plugin_data';
+
+ $plugin_data = get_transient($transient_name);
+
+ if (false === $plugin_data) {
+ $plugin_data = get_plugin_data(HELPFUL_FILE);
+
+ set_transient($transient_name, maybe_serialize($plugin_data), HOUR_IN_SECONDS);
+ }
+
+ return maybe_unserialize($plugin_data);
+ }
+
+ /**
+ * Set custom timezone if set in the options.
+ *
+ * @version 4.3.0
+ * @return void
+ */
+ public static function set_timezone()
+ {
+ $timezone = get_option('helpful_timezone');
+
+ if (isset($timezone) && '' !== trim($timezone)) {
+ date_default_timezone_set($timezone);
+ }
+ }
+
+ /**
+ * Returns the available options for Same-Site cookies.
+ *
+ * @return array
+ */
+ public static function get_samesite_options()
+ {
+ $defaults = ['None', 'Lax', 'Strict'];
+
+ return apply_filters('helpful_samesite_options', $defaults);
+ }
+
+ /**
+ * Checks if the current tab is in use.
+ *
+ * @param string $tab
+ *
+ * @return bool
+ */
+ public static function is_active_tab($tab)
+ {
+ $screen = get_current_screen();
+
+ if ('toplevel_page_helpful' !== $screen->base) {
+ return false;
+ }
+
+ $current = apply_filters('helpful_current_tab', false);
+
+ if ($tab !== $current) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Get credits array.
+ *
+ * @return array
+ */
+ public static function get_credits_data()
+ {
+ $credits = [
+ 'url' => apply_filters('helpful_credits_url', 'https://helpful-plugin.info'),
+ 'name' => apply_filters('helpful_credits_name', 'Helpful'),
+ 'rel' => apply_filters('helpful_credits_rel', 'noopener'),
+ ];
+
+ $html = '%3$s';
+ $html = apply_filters('helpful_credits_html', $html);
+
+ $credits['html'] = sprintf($html, $credits['url'], $credits['rel'], $credits['name']);
+
+ return apply_filters('helpful_default_credits', $credits);
+ }
+
+ /**
+ * Get admin tabs.
+ *
+ * @return array
+ */
+ public static function get_admin_tabs()
+ {
+ $current = apply_filters('helpful_current_tab', false);
+ return apply_filters('helpful_get_admin_tabs', __return_empty_array(), $current);
+ }
+
+ /**
+ * Get tab url.
+ *
+ * @param string $tab
+ *
+ * @return string
+ */
+ public static function get_tab_url($tab)
+ {
+ $tab = sanitize_text_field(wp_unslash($tab));
+ return apply_filters('helpful_get_tab_url', admin_url('admin.php?page=helpful&tab=' . $tab));
+ }
+
+ /**
+ * Get tab class.
+ *
+ * @param string $tab
+ *
+ * @return string
+ */
+ public static function get_tab_class($tab)
+ {
+ $tab = sanitize_text_field(wp_unslash($tab));
+
+ $class = '';
+
+ if (self::is_active_tab($tab)) {
+ $class = 'active';
+ }
+
+ return apply_filters('helpful_get_tab_class', $class);
+ }
+
+ /**
+ * Get tab attribute.
+ *
+ * @param string $tab
+ *
+ * @return string
+ */
+ public static function get_tab_attr($tab)
+ {
+ $tab = sanitize_text_field(wp_unslash($tab));
+
+ $attr = '';
+
+ if (self::is_active_tab($tab)) {
+ $attr = 'selected';
+ }
+
+ return apply_filters('helpful_get_tab_attr', $attr);
+ }
+
+ /**
+ * Returns the URL of the logo.
+ *
+ * @return string
+ */
+ public static function get_logo()
+ {
+ $logo = plugins_url('core/assets/images/helpful-heart.svg', HELPFUL_FILE);
+ return apply_filters('helpful_logo', $logo);
+ }
+
+ /**
+ * Returns an array of media data from Helpful.
+ *
+ * @return array
+ */
+ public static function get_plugin_media_data()
+ {
+ $media = [
+ 'logo' => self::get_logo(),
+ 'color' => '#88c057',
+ ];
+
+ return apply_filters('helpful_media_data', $media);
+ }
+
+ /**
+ * Plugins URL
+ *
+ * @param string $path
+ *
+ * @return string
+ */
+ public static function plugins_url($path)
+ {
+ return plugins_url($path, HELPFUL_FILE);
+ }
+
+ /**
+ * Filter the conditions and check if you are for example on the homepage and not in the single view.
+ *
+ * @version 4.3.0
+ *
+ * @return array
+ */
+ public static function get_conditions()
+ {
+ $conditions = [];
+
+ if (!is_singular()) {
+ $conditions[] = 'is_not_singular';
+ }
+
+ if (is_archive()) {
+ $conditions[] = 'is_archive';
+ }
+
+ if (is_home()) {
+ $conditions[] = 'is_home';
+ }
+
+ if (is_front_page()) {
+ $conditions[] = 'is_front_page';
+ }
+
+ return apply_filters('helpful_conditions', $conditions);
+ }
+
+ /**
+ * Get html output for alerts.
+ *
+ * @param string $message
+ * @param string $type
+ * @param int $close
+ *
+ * @return string
+ */
+ public static function get_alert($message, $type = 'none', $close = 2500)
+ {
+ $classes = 'helpful-alert helpful-auto-close';
+
+ $types = ['success', 'danger', 'info'];
+
+ if (in_array($type, $types)) {
+ $classes .= ' helpful-alert-' . $type;
+ }
+
+ $close = intval($close);
+
+ return sprintf('%s
', $classes, $close, $message);
+ }
+
+ /**
+ * Translatable Datatables Language String
+ *
+ * @return array
+ */
+ public static function datatables_language_string()
+ {
+ $language = [
+ 'decimal' => esc_html_x('', 'datatables decimal', 'helpful'),
+ 'emptyTable' => esc_html_x('No data available in table', 'datatables emptyTable', 'helpful'),
+ 'info' => esc_html_x('Showing _START_ to _END_ of _TOTAL_ entries', 'datatables info', 'helpful'),
+ 'infoEmpty' => esc_html_x('Showing 0 to 0 of 0 entries', 'datatables infoEmpty', 'helpful'),
+ 'infoFiltered' => esc_html_x('(filtered from _MAX_ total entries)', 'datatables infoFiltered', 'helpful'),
+ 'infoPostFix' => esc_html_x('', 'datatables infoPostFix', 'helpful'),
+ 'thousands' => esc_html_x(',', 'datatables thousands', 'helpful'),
+ 'lengthMenu' => esc_html_x('Show _MENU_ entries', 'datatables lengthMenu', 'helpful'),
+ 'loadingRecords' => esc_html_x('Loading...', 'datatables loadingRecords', 'helpful'),
+ 'processing' => esc_html_x('Processing...', 'datatables processing', 'helpful'),
+ 'search' => esc_html_x('Search:', 'datatables search', 'helpful'),
+ 'zeroRecords' => esc_html_x('No matching records found', 'datatables zeroRecords', 'helpful'),
+ 'paginate' => [
+ 'first' => esc_html_x('First', 'datatables first', 'helpful'),
+ 'last' => esc_html_x('Last', 'datatables last', 'helpful'),
+ 'next' => esc_html_x('Next', 'datatables next', 'helpful'),
+ 'previous' => esc_html_x('Previous', 'datatables previous', 'helpful'),
+ ],
+ 'aria' => [
+ 'sortAscending' => esc_html_x(': activate to sort column ascending', 'datatables sortAscending', 'helpful'),
+ 'sortDescending' => esc_html_x(': activate to sort column descending', 'datatables sortDescending', 'helpful'),
+ ],
+ 'select' => [
+ 'rows' => [
+ '_' => esc_html_x('%d rows selected', 'datatables previous', 'helpful'),
+ '0' => esc_html_x('', 'datatables previous', 'helpful'),
+ '1' => esc_html_x('1 row selected', 'datatables previous', 'helpful'),
+ ],
+ ],
+ 'buttons' => [
+ 'print' => esc_html_x('Print', 'datatables print', 'helpful'),
+ 'colvis' => esc_html_x('Columns', 'datatables colvis', 'helpful'),
+ 'copy' => esc_html_x('Copy', 'datatables copy', 'helpful'),
+ 'copyTitle' => esc_html_x('Copy to clipboard', 'datatables copyTitle', 'helpful'),
+ 'copyKeys' => esc_html_x(
+ 'Press ctrl or \u2318 + C to copy table
to temporary storage.
To cancel, click on the message or press Escape.',
+ 'datatables copyKeys',
+ 'helpful'
+ ),
+ 'copySuccess' => [
+ '_' => esc_html_x('%d rows copied', 'datatables copySuccess', 'helpful'),
+ '1' => esc_html_x('1 row copied', 'datatables copySuccess', 'helpful'),
+ ],
+ 'pageLength' => [
+ '-1' => esc_html_x('Show all rows', 'datatables pageLength', 'helpful'),
+ '_' => esc_html_x('Show %d rows', 'datatables pageLength', 'helpful'),
+ ],
+ ],
+ ];
+
+ return apply_filters('helpful_datatables_language', $language);
+ }
+
+ /**
+ * Returns non-permitted characters and words from the WordPress blacklist.
+ *
+ * @return string
+ */
+ public static function get_disallowed_keys()
+ {
+ if (version_compare(get_bloginfo('version'), '5.5.0') >= 0) {
+ return trim(get_option('disallowed_keys'));
+ }
+
+ return trim(get_option('blacklist_keys'));
+ }
+
+ /**
+ * Checks if the content is set on the internal blacklist of WordPress
+ *
+ * @param string $content the content to be checked.
+ *
+ * @return bool
+ */
+ public static function backlist_check($content)
+ {
+ $mod_keys = self::get_disallowed_keys();
+
+ if ('' === $mod_keys) {
+ return false;
+ }
+
+ $without_html = wp_strip_all_tags($content);
+ $words = explode("\n", $mod_keys);
+
+ foreach ((array) $words as $word):
+ $word = trim($word);
+
+ if (empty($word)) {
+ continue;
+ }
+
+ $word = preg_quote($word, '#');
+ $pattern = "#$word#i";
+
+ if (preg_match($pattern, $content) || preg_match($pattern, $without_html)) {
+ return true;
+ }
+ endforeach;
+
+ return false;
+ }
+
+ /**
+ * Checks if the current page uses AMP.
+ *
+ * @return bool
+ */
+ public static function is_amp()
+ {
+ if (function_exists('ampforwp_is_amp_endpoint') && ampforwp_is_amp_endpoint()) {
+ return true;
+ }
+
+ if (function_exists('is_amp_endpoint') && is_amp_endpoint()) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Sets a capability.
+ *
+ * @param string $option
+ * @param string $value
+ *
+ * @return void
+ */
+ public static function set_capability($option, $value)
+ {
+ $options = [
+ 'helpful_capability',
+ 'helpful_settings_capability',
+ 'helpful_feedback_capability',
+ ];
+
+ if (!in_array($option, $options)) {
+ return;
+ }
+
+ if (null === $value || false === $value) {
+ delete_option($option);
+ }
+
+ update_option(
+ sanitize_text_field($option),
+ sanitize_text_field($value)
+ );
+ }
+
+ /**
+ * Checks if the feedback was deactivated by option.
+ *
+ * @return bool
+ */
+ public static function is_feedback_disabled()
+ {
+ if ('on' !== get_option('helpful_feedback_disabled')) {
+ return false;
+ }
+
+ return true;
+ }
+}
diff --git a/core/functions/helpers.php b/core/functions/helpers.php
index 5677468..1044289 100644
--- a/core/functions/helpers.php
+++ b/core/functions/helpers.php
@@ -5,83 +5,87 @@
* @package Helpful
* @author Pixelbart
*/
-use Helpful\Core\Helpers as Helpers;
use Helpful\Core\Helper;
+use Helpful\Core\Helpers as Helpers;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
+if (!defined('ABSPATH')) {
+ exit;
}
-if ( ! function_exists( 'helpful_backlist_check' ) ) {
- /**
- * WordPress blacklist checker
- *
- * @param string $content the content to be checked.
- *
- * @return bool
- */
- function helpful_backlist_check( $content ) {
- return Helper::backlist_check( $content );
- }
+if (!function_exists('helpful_backlist_check')) {
+ /**
+ * WordPress blacklist checker
+ *
+ * @param string $content the content to be checked.
+ *
+ * @return bool
+ */
+ function helpful_backlist_check($content)
+ {
+ return Helper::backlist_check($content);
+ }
}
-if ( ! function_exists( 'helpful_trim_all' ) ) {
- /**
- * Trim all whitespaces.
- *
- * @param string $string string to trim.
- * @return string
- */
- function helpful_trim_all( $string ) {
- return preg_replace( '/\s+/', '', $string );
- }
+if (!function_exists('helpful_trim_all')) {
+ /**
+ * Trim all whitespaces.
+ *
+ * @param string $string string to trim.
+ * @return string
+ */
+ function helpful_trim_all($string)
+ {
+ return preg_replace('/\s+/', '', $string);
+ }
}
-if ( ! function_exists( 'helpful_error_log' ) ) {
- /**
- * This allows custom error messages to be placed in the error_logs.
- * WP_DEBUG and WP_DEBUG_LOG must be set to true.
- *
- * @source https://wordpress.org/support/article/debugging-in-wordpress/
- *
- * @param string $message error message.
- */
- function helpful_error_log( $message ) {
- if ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) {
- if ( is_array( $message ) || is_object( $message ) ) {
- error_log( print_r( $message, true ) );
- } else {
- error_log( $message );
- }
- }
- }
+if (!function_exists('helpful_error_log')) {
+ /**
+ * This allows custom error messages to be placed in the error_logs.
+ * WP_DEBUG and WP_DEBUG_LOG must be set to true.
+ *
+ * @source https://wordpress.org/support/article/debugging-in-wordpress/
+ *
+ * @param string $message error message.
+ */
+ function helpful_error_log($message)
+ {
+ if (defined('WP_DEBUG') && true === WP_DEBUG) {
+ if (is_array($message) || is_object($message)) {
+ error_log(print_r($message, true));
+ } else {
+ error_log($message);
+ }
+ }
+ }
}
-if ( ! function_exists( 'helpful_has_user_voted' ) ) {
- /**
- * Checks by a Post-ID whether a vote has already been taken for this post.
- *
- * @global $post
- *
- * @param int|null $post_id
- * @param bool $bool Returns the vote status (pro, contra, none) if true.
- *
- * @return bool|string
- */
- function helpful_has_user_voted( $post_id = null, $bool = true ) {
- return Helpers\Values::has_user_voted( $post_id, $bool );
- }
+if (!function_exists('helpful_has_user_voted')) {
+ /**
+ * Checks by a Post-ID whether a vote has already been taken for this post.
+ *
+ * @global $post
+ *
+ * @param int|null $post_id
+ * @param bool $bool Returns the vote status (pro, contra, none) if true.
+ *
+ * @return bool|string
+ */
+ function helpful_has_user_voted($post_id = null, $bool = true)
+ {
+ return Helpers\Values::has_user_voted($post_id, $bool);
+ }
}
-if ( ! function_exists( 'helpful_is_amp' ) ) {
- /**
- * Checks if AMP is used and outputs either TRUE or FALSE. Is used to avoid including Helpful in AMP.
- *
- * @return bool
- */
- function helpful_is_amp()
- {
- return Helper::is_amp();
- }
+if (!function_exists('helpful_is_amp')) {
+ /**
+ * Checks if AMP is used and outputs either TRUE or FALSE. Is used to avoid including Helpful in AMP.
+ *
+ * @return bool
+ */
+ function helpful_is_amp()
+ {
+ return Helper::is_amp();
+ }
}
\ No newline at end of file
diff --git a/core/helpers/class-user.php b/core/helpers/class-user.php
index 6dfada0..385e27b 100644
--- a/core/helpers/class-user.php
+++ b/core/helpers/class-user.php
@@ -1,7 +1,5 @@
* @version 4.3.0
@@ -24,28 +22,20 @@ class User
*/
public static function get_user()
{
- $user = null;
+ $user = self::get_user_string();
- /**
- * No more user is set using sessions or cookies.
- */
if ('on' === get_option('helpful_user_random')) {
return self::get_user_string();
}
- if (isset($_COOKIE['helpful_user'])) {
+ if (isset($_COOKIE['helpful_user']) && '' !== trim($_COOKIE['helpful_user'])) {
$user = sanitize_text_field($_COOKIE['helpful_user']);
}
- if (isset($_SESSION['helpful_user'])) {
+ if (isset($_SESSION['helpful_user']) && '' !== trim($_SESSION['helpful_user'])) {
$user = sanitize_text_field($_SESSION['helpful_user']);
}
- if (null === $user) {
- self::set_user();
- $user = self::get_user();
- }
-
return $user;
}
@@ -114,6 +104,10 @@ public static function set_user()
if (70300 > PHP_VERSION_ID) {
setcookie('helpful_user', $string, strtotime($lifetime), '/');
}
+
+ if (isset($_SESSION['helpful_user']) && isset($_COOKIE['helpful_user'])) {
+ unset($_SESSION['helpful_user']);
+ }
}
$session_start = apply_filters('helpful_session_start', true);
diff --git a/core/modules/class-core.php b/core/modules/class-core.php
index 2b1ddf5..c55ab1c 100644
--- a/core/modules/class-core.php
+++ b/core/modules/class-core.php
@@ -8,329 +8,341 @@
*/
namespace Helpful\Core\Modules;
-use Helpful\Core\Helpers as Helpers;
use Helpful\Core\Helper;
+use Helpful\Core\Helpers as Helpers;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
+if (!defined('ABSPATH')) {
+ exit;
}
class Core
{
- /**
- * Instance
- *
- * @var Core
- */
- public static $instance;
-
- /**
- * Set instance and fire class
- *
- * @return Core
- */
- public static function get_instance()
- {
- if ( ! isset( self::$instance ) ) {
- self::$instance = new self();
- }
- return self::$instance;
- }
-
- /**
- * Class constructor
- *
- * @return void
- */
- public function __construct()
- {
- Helper::set_timezone();
-
- add_action( 'admin_init', [ &$this, 'setup_helpful_table' ] );
- add_action( 'admin_init', [ &$this, 'setup_feedback_table' ] );
-
- // Causes problems and was therefore commented out.
- // add_action( 'init', [ &$this, 'setup_defaults' ] );
-
- add_action( 'activated_plugin', [ &$this, 'load_first' ] );
-
- add_filter( 'plugin_row_meta', [ &$this, 'plugin_row_meta' ], 10, 2 );
- add_filter( 'helpful_debug_fields', [ &$this, 'debug_fields' ] );
-
- add_filter( 'helpful_current_tab', [ &$this, 'current_tab' ] );
- add_filter( 'helpful_editor_settings', [ &$this, 'editor_settings' ] );
-
- /**
- * Load Elementor Widgets
- *
- * @since 4.1.2
- */
- add_action( 'elementor/widgets/widgets_registered', [ &$this, 'elementor_widgets' ] );
- add_action( 'elementor/controls/controls_registered', [ &$this, 'elementor_controls' ] );
- add_action( 'elementor/elements/categories_registered', [ &$this, 'elementor_categories' ] );
- }
-
- /**
- * Set default options.
- *
- * @return bool
- */
- public function setup_defaults()
- {
- $status = intval( get_option( 'helpful_defaults' ) );
-
- if ( 1 === $status ) {
- return false;
- }
-
- $this->set_defaults( true );
-
- update_option( 'helpful_defaults', 1 );
-
- return true;
- }
-
- /**
- * Create database table for helpful
- *
- * @global $wpdb
- *
- * @return bool
- */
- public function setup_helpful_table()
- {
- // Updates database tables.
- Helpers\Database::update_tables();
-
- if ( false === get_transient( 'setup_helpful_table' ) ) {
- Helpers\Database::setup_helpful_table();
- set_transient( 'setup_helpful_table', 1, WEEK_IN_SECONDS );
- }
- }
-
- /**
- * Create database table for feedback
- *
- * @global $wpdb
- *
- * @return bool
- */
- public function setup_feedback_table()
- {
- if ( false === get_transient( 'setup_feedback_table' ) ) {
- Helpers\Database::setup_feedback_table();
- set_transient( 'setup_feedback_table', 1, WEEK_IN_SECONDS );
- }
- }
-
- /**
- * Default values for settings
- *
- * @param bool $status set true for filling defaults.
- *
- * @return bool
- */
- public function set_defaults( $status = false )
- {
- if ( false === $status ) {
- return false;
- }
-
- ob_start();
- require_once HELPFUL_PATH . 'templates/feedback-email.php';
- $feedback_email_content = ob_get_contents();
- ob_end_clean();
-
- $options = [
- 'helpful_heading' => _x( 'Was this post helpful?', 'default headline', 'helpful' ),
- 'helpful_content' => _x( 'Let us know if you liked the post. That’s the only way we can improve.', 'default description', 'helpful' ),
- 'helpful_exists' => _x( 'You have already voted for this post.', 'already voted', 'helpful' ),
- 'helpful_success' => _x( 'Thank you for voting.', 'text after voting', 'helpful' ),
- 'helpful_error' => _x( 'Sorry, an error has occurred.', 'error after voting', 'helpful' ),
- 'helpful_pro' => _x( 'Yes', 'text pro button', 'helpful' ),
- 'helpful_contra' => _x( 'No', 'text contra button', 'helpful' ),
- 'helpful_column_pro' => _x( 'Pro', 'column name', 'helpful' ),
- 'helpful_column_contra' => _x( 'Contra', 'column name', 'helpful' ),
- 'helpful_column_feedback' => _x( 'Feedback', 'column name', 'helpful' ),
- 'helpful_after_pro' => _x( 'Thank you for voting.', 'text after voting', 'helpful' ),
- 'helpful_after_contra' => _x( 'Thank you for voting.', 'text after voting', 'helpful' ),
- 'helpful_after_fallback' => _x( 'Thank you for voting.', 'text after voting', 'helpful' ),
- 'helpful_feedback_label_message' => _x( 'Message', 'label for feedback form field', 'helpful' ),
- 'helpful_feedback_label_name' => _x( 'Name', 'label for feedback form field', 'helpful' ),
- 'helpful_feedback_label_email' => _x( 'Email', 'label for feedback form field', 'helpful' ),
- 'helpful_feedback_label_submit' => _x( 'Send Feedback', 'label for feedback form field', 'helpful' ),
- 'helpful_feedback_label_cancel' => _x( 'Cancel', 'label for feedback form field', 'helpful' ),
- 'helpful_post_types' => [ 'post' ],
- 'helpful_count_hide' => false,
- 'helpful_credits' => true,
- 'helpful_uninstall' => false,
- 'helpful_widget' => true,
- 'helpful_widget_amount' => 3,
- 'helpful_widget_pro' => true,
- 'helpful_widget_contra' => true,
- 'helpful_widget_pro_recent' => true,
- 'helpful_widget_contra_recent' => true,
- 'helpful_feedback_subject' => _x( 'There\'s new feedback for you.', 'feedback email subject', 'helpful' ),
- 'helpful_feedback_receivers' => get_option( 'admin_email' ),
- 'helpful_feedback_email_content' => $feedback_email_content,
- ];
-
- $options = apply_filters( 'helpful_options', $options );
-
- foreach ( $options as $slug => $value ) :
- if ( ! get_option( $slug ) ) {
- update_option( $slug, $value );
- }
- endforeach;
-
- return true;
- }
-
- /**
- * Loads helpful first
- *
- * @return void
- */
- public function load_first()
- {
- if ( ! get_option( 'helpful_plugin_first' ) ) {
- return;
- }
-
- $path = str_replace( WP_PLUGIN_DIR . '/', '', HELPFUL_FILE );
- if ( $plugins = get_option( 'active_plugins' ) ) {
- if ( $key = array_search( $path, $plugins ) ) {
- array_splice( $plugins, $key, 1 );
- array_unshift( $plugins, $path );
- update_option( 'active_plugins', $plugins );
- }
- }
- }
-
- /**
- * 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;
- }
-
- /**
- * Register custom elementor widgets
- *
- * @return void
- */
- public function elementor_widgets()
- {
- $elementor = \Elementor\Plugin::instance();
-
- /**
- * Register Helpful Widget
- *
- * @see Helpful_Elementor_Widget
- */
- $elementor->widgets_manager->register_widget_type( new Elementor_Widget() );
- }
-
- /**
- * Register custom elementor controls
- *
- * @return void
- */
- public function elementor_controls()
- {
- // nothing
- }
-
- /**
- * Register categories
- *
- * @param object $elementor elementor object.
- *
- * @return void
- */
- public function elementor_categories( $elementor )
- {
- // nothing
- }
-
- /**
- * Fields for Debug Informations.
- *
- * @param array $fields
- *
- * @return array
- */
- public function debug_fields( $fields )
- {
- $fields['datatables'] = [
- 'label' => esc_html_x( 'DataTables version', 'debug field label', 'helpful' ),
- 'value' => '1.10.20',
- ];
-
- return $fields;
- }
-
- /**
- * Returns the current tab.
- *
- * @return string
- */
- public function current_tab()
- {
- $tab = 'start';
-
- if ( isset( $_GET['tab'] ) && '' !== trim( $_GET['tab'] ) ) {
- $tab = sanitize_text_field( wp_unslash( $_GET['tab'] ) );
- }
-
- return $tab;
- }
-
- /**
- * Returns the WP_Editor settings of Helpful.
- *
- * @return array
- */
- public function editor_settings()
- {
- return [
- 'teeny' => true,
- 'media_buttons' => false,
- 'textarea_rows' => 5,
- 'tinymce' => false,
- 'quicktags' => [
- 'buttons' => 'strong,em,del,ul,ol,li,close,link'
- ],
- ];
- }
-}
\ No newline at end of file
+ /**
+ * Instance
+ *
+ * @var Core
+ */
+ public static $instance;
+
+ /**
+ * Set instance and fire class
+ *
+ * @return Core
+ */
+ public static function get_instance()
+ {
+ if (!isset(self::$instance)) {
+ self::$instance = new self();
+ }
+ return self::$instance;
+ }
+
+ /**
+ * Class constructor
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ Helper::set_timezone();
+
+ add_action('init', [ & $this, 'set_user_cookie'], 1);
+
+ add_action('admin_init', [ & $this, 'setup_helpful_table']);
+ add_action('admin_init', [ & $this, 'setup_feedback_table']);
+
+ // Causes problems and was therefore commented out.
+ // add_action( 'init', [ &$this, 'setup_defaults' ] );
+
+ add_action('activated_plugin', [ & $this, 'load_first']);
+
+ add_filter('plugin_row_meta', [ & $this, 'plugin_row_meta'], 10, 2);
+ add_filter('helpful_debug_fields', [ & $this, 'debug_fields']);
+
+ add_filter('helpful_current_tab', [ & $this, 'current_tab']);
+ add_filter('helpful_editor_settings', [ & $this, 'editor_settings']);
+
+ /**
+ * Load Elementor Widgets
+ *
+ * @since 4.1.2
+ */
+ add_action('elementor/widgets/widgets_registered', [ & $this, 'elementor_widgets']);
+ add_action('elementor/controls/controls_registered', [ & $this, 'elementor_controls']);
+ add_action('elementor/elements/categories_registered', [ & $this, 'elementor_categories']);
+ }
+
+ /**
+ * Set users cookie with unique id
+ *
+ * @return void
+ */
+ public function set_user_cookie()
+ {
+ Helpers\User::set_user();
+ }
+
+ /**
+ * Set default options.
+ *
+ * @return bool
+ */
+ public function setup_defaults()
+ {
+ $status = intval(get_option('helpful_defaults'));
+
+ if (1 === $status) {
+ return false;
+ }
+
+ $this->set_defaults(true);
+
+ update_option('helpful_defaults', 1);
+
+ return true;
+ }
+
+ /**
+ * Create database table for helpful
+ *
+ * @global $wpdb
+ *
+ * @return bool
+ */
+ public function setup_helpful_table()
+ {
+ // Updates database tables.
+ Helpers\Database::update_tables();
+
+ if (false === get_transient('setup_helpful_table')) {
+ Helpers\Database::setup_helpful_table();
+ set_transient('setup_helpful_table', 1, WEEK_IN_SECONDS);
+ }
+ }
+
+ /**
+ * Create database table for feedback
+ *
+ * @global $wpdb
+ *
+ * @return bool
+ */
+ public function setup_feedback_table()
+ {
+ if (false === get_transient('setup_feedback_table')) {
+ Helpers\Database::setup_feedback_table();
+ set_transient('setup_feedback_table', 1, WEEK_IN_SECONDS);
+ }
+ }
+
+ /**
+ * Default values for settings
+ *
+ * @param bool $status set true for filling defaults.
+ *
+ * @return bool
+ */
+ public function set_defaults($status = false)
+ {
+ if (false === $status) {
+ return false;
+ }
+
+ ob_start();
+ require_once HELPFUL_PATH . 'templates/feedback-email.php';
+ $feedback_email_content = ob_get_contents();
+ ob_end_clean();
+
+ $options = [
+ 'helpful_heading' => _x('Was this post helpful?', 'default headline', 'helpful'),
+ 'helpful_content' => _x('Let us know if you liked the post. That’s the only way we can improve.', 'default description', 'helpful'),
+ 'helpful_exists' => _x('You have already voted for this post.', 'already voted', 'helpful'),
+ 'helpful_success' => _x('Thank you for voting.', 'text after voting', 'helpful'),
+ 'helpful_error' => _x('Sorry, an error has occurred.', 'error after voting', 'helpful'),
+ 'helpful_pro' => _x('Yes', 'text pro button', 'helpful'),
+ 'helpful_contra' => _x('No', 'text contra button', 'helpful'),
+ 'helpful_column_pro' => _x('Pro', 'column name', 'helpful'),
+ 'helpful_column_contra' => _x('Contra', 'column name', 'helpful'),
+ 'helpful_column_feedback' => _x('Feedback', 'column name', 'helpful'),
+ 'helpful_after_pro' => _x('Thank you for voting.', 'text after voting', 'helpful'),
+ 'helpful_after_contra' => _x('Thank you for voting.', 'text after voting', 'helpful'),
+ 'helpful_after_fallback' => _x('Thank you for voting.', 'text after voting', 'helpful'),
+ 'helpful_feedback_label_message' => _x('Message', 'label for feedback form field', 'helpful'),
+ 'helpful_feedback_label_name' => _x('Name', 'label for feedback form field', 'helpful'),
+ 'helpful_feedback_label_email' => _x('Email', 'label for feedback form field', 'helpful'),
+ 'helpful_feedback_label_submit' => _x('Send Feedback', 'label for feedback form field', 'helpful'),
+ 'helpful_feedback_label_cancel' => _x('Cancel', 'label for feedback form field', 'helpful'),
+ 'helpful_post_types' => ['post'],
+ 'helpful_count_hide' => false,
+ 'helpful_credits' => true,
+ 'helpful_uninstall' => false,
+ 'helpful_widget' => true,
+ 'helpful_widget_amount' => 3,
+ 'helpful_widget_pro' => true,
+ 'helpful_widget_contra' => true,
+ 'helpful_widget_pro_recent' => true,
+ 'helpful_widget_contra_recent' => true,
+ 'helpful_feedback_subject' => _x('There\'s new feedback for you.', 'feedback email subject', 'helpful'),
+ 'helpful_feedback_receivers' => get_option('admin_email'),
+ 'helpful_feedback_email_content' => $feedback_email_content,
+ ];
+
+ $options = apply_filters('helpful_options', $options);
+
+ foreach ($options as $slug => $value):
+ if (!get_option($slug)) {
+ update_option($slug, $value);
+ }
+ endforeach;
+
+ return true;
+ }
+
+ /**
+ * Loads helpful first
+ *
+ * @return void
+ */
+ public function load_first()
+ {
+ if (!get_option('helpful_plugin_first')) {
+ return;
+ }
+
+ $path = str_replace(WP_PLUGIN_DIR . '/', '', HELPFUL_FILE);
+ if ($plugins = get_option('active_plugins')) {
+ if ($key = array_search($path, $plugins)) {
+ array_splice($plugins, $key, 1);
+ array_unshift($plugins, $path);
+ update_option('active_plugins', $plugins);
+ }
+ }
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Register custom elementor widgets
+ *
+ * @return void
+ */
+ public function elementor_widgets()
+ {
+ $elementor = \Elementor\Plugin::instance();
+
+ /**
+ * Register Helpful Widget
+ *
+ * @see Helpful_Elementor_Widget
+ */
+ $elementor->widgets_manager->register_widget_type(new Elementor_Widget());
+ }
+
+ /**
+ * Register custom elementor controls
+ *
+ * @return void
+ */
+ public function elementor_controls()
+ {
+ // nothing
+ }
+
+ /**
+ * Register categories
+ *
+ * @param object $elementor elementor object.
+ *
+ * @return void
+ */
+ public function elementor_categories($elementor)
+ {
+ // nothing
+ }
+
+ /**
+ * Fields for Debug Informations.
+ *
+ * @param array $fields
+ *
+ * @return array
+ */
+ public function debug_fields($fields)
+ {
+ $fields['datatables'] = [
+ 'label' => esc_html_x('DataTables version', 'debug field label', 'helpful'),
+ 'value' => '1.10.20',
+ ];
+
+ return $fields;
+ }
+
+ /**
+ * Returns the current tab.
+ *
+ * @return string
+ */
+ public function current_tab()
+ {
+ $tab = 'start';
+
+ if (isset($_GET['tab']) && '' !== trim($_GET['tab'])) {
+ $tab = sanitize_text_field(wp_unslash($_GET['tab']));
+ }
+
+ return $tab;
+ }
+
+ /**
+ * Returns the WP_Editor settings of Helpful.
+ *
+ * @return array
+ */
+ public function editor_settings()
+ {
+ return [
+ 'teeny' => true,
+ 'media_buttons' => false,
+ 'textarea_rows' => 5,
+ 'tinymce' => false,
+ 'quicktags' => [
+ 'buttons' => 'strong,em,del,ul,ol,li,close,link',
+ ],
+ ];
+ }
+}
diff --git a/core/modules/class-frontend.php b/core/modules/class-frontend.php
index df2925e..b40122b 100644
--- a/core/modules/class-frontend.php
+++ b/core/modules/class-frontend.php
@@ -8,535 +8,523 @@
*/
namespace Helpful\Core\Modules;
-use Helpful\Core\Helpers as Helpers;
use Helpful\Core\Helper;
+use Helpful\Core\Helpers as Helpers;
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
+if (!defined('ABSPATH')) {
+ exit;
}
class Frontend
{
- /**
- * Instance
- *
- * @var Frontend
- */
- public static $instance;
-
- /**
- * Set instance and fire class
- *
- * @return Frontend
- */
- public static function get_instance()
- {
- if ( ! isset( self::$instance ) ) {
- self::$instance = new self();
- }
- return self::$instance;
- }
-
- /**
- * Class Constructor
- *
- * @return void
- */
- 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_filter( 'init', [ &$this, 'filter_nonces' ] );
- }
-
- /**
- * Set users cookie with unique id
- *
- * @return void
- */
- public function set_user_cookie()
- {
- Helpers\User::set_user();
- }
-
- /**
- * Retrieve default themes
- *
- * @param array $themes themes array.
- *
- * @return array
- */
- public function default_themes( $themes )
- {
- $themes[] = [
- 'id' => 'base',
- 'label' => esc_html_x( 'Base', 'theme name', 'helpful' ),
- 'stylesheet' => plugins_url( 'core/assets/themes/base.css', HELPFUL_FILE ),
- ];
-
- $themes[] = [
- 'id' => 'dark',
- 'label' => esc_html_x( 'Dark', 'theme name', 'helpful' ),
- 'stylesheet' => plugins_url( 'core/assets/themes/dark.css', HELPFUL_FILE ),
- ];
-
- $themes[] = [
- 'id' => 'minimal',
- 'label' => esc_html_x( 'Minimal', 'theme name', 'helpful' ),
- 'stylesheet' => plugins_url( 'core/assets/themes/minimal.css', HELPFUL_FILE ),
- ];
-
- $themes[] = [
- 'id' => 'flat',
- 'label' => esc_html_x( 'Flat', 'theme name', 'helpful' ),
- 'stylesheet' => plugins_url( 'core/assets/themes/flat.css', HELPFUL_FILE ),
- ];
-
- $themes[] = [
- 'id' => 'simple',
- 'label' => esc_html_x( 'Simple', 'theme name', 'helpful' ),
- 'stylesheet' => plugins_url( 'core/assets/themes/simple.css', HELPFUL_FILE ),
- ];
-
- $themes[] = [
- 'id' => 'clean',
- 'label' => esc_html_x( 'Clean', 'theme name', 'helpful' ),
- 'stylesheet' => plugins_url( 'core/assets/themes/clean.css', HELPFUL_FILE ),
- ];
-
- $themes[] = [
- 'id' => 'blank',
- 'label' => esc_html_x( 'Blank', 'theme name', 'helpful' ),
- 'stylesheet' => null,
- ];
-
- return $themes;
- }
-
- /**
- * Enqueue styles and scripts
- *
- * @return void
- */
- public function enqueue_scripts()
- {
- if ( helpful_is_amp() ) {
- return __return_empty_string();
- }
-
- $active_theme = get_option( 'helpful_theme' );
- $themes = apply_filters( 'helpful_themes', [] );
- $plugin = Helper::get_plugin_data();
-
-
- if ( ! empty( $themes ) ) {
- foreach ( $themes as $theme ) {
- if ( $active_theme !== $theme['id'] ) {
- continue;
- }
-
- if ( 'blank' === $theme['id'] ) {
- break;
- }
-
- wp_enqueue_style( 'helpful-theme-' . $theme['id'], $theme['stylesheet'], [], $plugin['Version'] );
- }
- }
-
- $file = Helper::plugins_url( 'core/assets/js/helpful.js' );
- wp_enqueue_script( 'helpful', $file, [ 'jquery' ], $plugin['Version'], true );
-
- $user = Helpers\User::get_user();
- $nonce = wp_create_nonce( 'helpful_frontend_nonce' );
- $vars = [
- 'ajax_url' => admin_url( 'admin-ajax.php' ),
- 'ajax_data' => [
- 'user_id' => $user,
- '_wpnonce' => $nonce,
- ],
- 'translations' => [
- 'fieldIsRequired' => __( 'This field is required.', 'helpful' ),
- ],
- ];
-
- if ( isset( $_SESSION ) ) {
- $vars['ajax_session'] = apply_filters( 'helpful_ajax_session', $_SESSION );
- }
-
- if ( false === apply_filters( 'helpful_verify_frontend_nonce', true ) && isset( $vars['ajax_data' ] ) ) {
- $vars['ajax_data'] = [];
- }
-
- $vars = apply_filters( 'helpful_frontend_ajax_vars', $vars );
-
- wp_localize_script( 'helpful', 'helpful', $vars );
- }
-
- /**
- * Ajax save user vote and render response.
- *
- * @return void
- */
- public function save_vote()
- {
- if ( apply_filters( 'helpful_verify_frontend_nonce', true ) ) {
- check_ajax_referer( 'helpful_frontend_nonce' );
- }
-
- do_action( 'helpful_ajax_save_vote' );
-
- $user_id = null;
- $post_id = null;
- $value = null;
-
- if ( isset( $_POST['user_id'] ) ) {
- $user_id = sanitize_text_field( $_POST['user_id'] );
- }
-
- if ( isset( $_POST['post'] ) ) {
- $post_id = intval( $_POST['post'] );
- }
-
- if ( isset( $_POST['value'] ) ) {
- $value = sanitize_text_field( $_POST['value'] );
- }
-
- if ( false === Helpers\User::check_user( $user_id, $post_id ) ) {
- if ( 'pro' === $value ) {
- Helpers\Values::insert_pro( $user_id, $post_id );
- } else {
- Helpers\Values::insert_contra( $user_id, $post_id );
- }
-
- $response = do_shortcode( Helpers\Feedback::after_vote( $post_id ) );
- }
-
- $response = Helpers\Values::convert_tags( $response, $post_id );
- echo apply_filters( 'helpful_pre_save_vote', $response, $post_id );
- wp_die();
- }
-
- /**
- * Ajax save user feedback and render response.
- *
- * @return void
- */
- public function save_feedback()
- {
- if ( apply_filters( 'helpful_verify_feedback_nonce', true ) ) {
- check_ajax_referer( 'helpful_feedback_nonce' );
- }
-
- do_action( 'helpful_ajax_save_feedback' );
-
- $post_id = null;
-
- if ( isset( $_REQUEST['post_id'] ) && is_numeric( $_REQUEST['post_id'] ) ) {
- $post_id = intval( $_REQUEST['post_id'] );
- }
-
- /**
- * Simple Spam Protection
- */
- $spam_protection = apply_filters( 'helpful_simple_spam_protection', '1' );
-
- if ( '1' !== $spam_protection ) {
- $spam_protection = false;
- } else {
- $spam_protection = true;
- }
-
- if ( ! empty( $_REQUEST['website'] ) && true === $spam_protection ) {
- $message = do_shortcode( get_option( 'helpful_feedback_message_spam' ) );
- $message = apply_filters( 'helpful_pre_feedback_message_spam', $message, $post_id );
- echo Helpers\Values::convert_tags( $message, $post_id );
- wp_die();
- }
-
- if ( ! isset( $_REQUEST['helpful_cancel'] ) ) {
- Helpers\Feedback::insert_feedback();
- }
-
- /* OLD STYLE */
- /*
- $type = 'pro';
-
- if ( isset( $_REQUEST['type'] ) ) {
- $type = sanitize_text_field( $_REQUEST['type'] );
- }
- */
-
- global $helpful_type;
-
- $user_id = Helpers\User::get_user();
- $type = Helpers\User::get_user_vote_status( $user_id, $post_id );
-
- $helpful_type[ $post_id ] = $type;
-
- if ( 'pro' === $type ) {
- $message = do_shortcode( get_option( 'helpful_after_pro' ) );
-
- if ( get_post_meta( $post_id, 'helpful_after_pro', true ) ) {
- $message = do_shortcode( get_post_meta( $post_id, 'helpful_after_pro', true ) );
- }
-
- $message = apply_filters( 'helpful_pre_after_pro', $message, $post_id );
- } elseif ( 'contra' === $type ) {
- $message = do_shortcode( get_option( 'helpful_after_contra' ) );
-
- if ( get_post_meta( $post_id, 'helpful_after_contra', true ) ) {
- $message = do_shortcode( get_post_meta( $post_id, 'helpful_after_contra', true ) );
- }
-
- $message = apply_filters( 'helpful_pre_after_contra', $message, $post_id );
- } else {
- $message = do_shortcode( get_option( 'helpful_after_fallback' ) );
-
- if ( get_post_meta( $post_id, 'helpful_after_fallback', true ) ) {
- $message = do_shortcode( get_post_meta( $post_id, 'helpful_after_fallback', true ) );
- }
-
- $message = apply_filters( 'helpful_pre_after_fallback', $message, $post_id );
- }
-
- $message = Helpers\Values::convert_tags( $message, $post_id );
- echo apply_filters( 'helpful_pre_save_feedback', $message, $post_id );
- wp_die();
- }
-
- /**
- * Add helpful to post content
- *
- * @global $post
- * @version 4.3.0
- *
- * @param string $content post content.
- *
- * @return string
- */
- public function the_content( $content )
- {
- global $post;
-
- if ( helpful_is_amp() ) {
- return $content;
- }
-
- if ( ! isset( $post->ID ) ) {
- return $content;
- }
-
- $helpful = Helpers\Values::get_defaults();
- $post_types = get_option( 'helpful_post_types' );
- $user_id = Helpers\User::get_user();
-
- if ( 'on' === get_post_meta( $helpful['post_id'], 'helpful_hide_on_post', true ) ) {
- return $content;
- }
-
- if ( ! is_array( $post_types ) || ! in_array( $post->post_type, $post_types, true ) ) {
- return $content;
- }
-
- if ( get_option( 'helpful_hide_in_content' ) ) {
- return $content;
- }
-
- if ( get_option( 'helpful_exists_hide' ) && Helpers\User::check_user( $user_id, $helpful['post_id'] ) ) {
- return $content;
- }
-
- $conditions = Helper::get_conditions();
-
- if ( ! empty( $conditions ) ) {
- return $content;
- }
-
- $exists = false;
- $hidden = false;
- $class = '';
-
- if ( isset( $helpful['exists'] ) && 1 === $helpful['exists'] ) {
- if ( isset( $helpful['exists-hide'] ) && 1 === $helpful['exists-hide'] ) {
- return __return_empty_string();
- }
-
- $exists = true;
- $hidden = true;
- $class = 'helpful-exists';
- $helpful['content'] = do_shortcode( $helpful['exists_text'] );
-
- if ( get_post_meta( $helpful['post_id'], 'helpful_exists', true ) ) {
- $helpful['content'] = do_shortcode( get_post_meta( $helpful['post_id'], 'helpful_exists', true ) );
- }
- }
-
- if ( null === $helpful['post_id'] ) {
- return esc_html__( 'No post found. Helpful must be placed in a post loop.', 'helpful' );
- }
-
- if ( false !== $exists && get_option( 'helpful_feedback_after_vote' ) ) {
- if ( ! Helper::is_feedback_disabled() ) {
- $shortcode = Helpers\Feedback::after_vote( $helpful['post_id'], true );
- $shortcode = Helpers\Values::convert_tags( $shortcode, $helpful['post_id'] );
- return $content . $shortcode;
- }
- }
-
- $helpful['content'] = do_shortcode( $helpful['content'] );
-
- if ( get_post_meta( $helpful['post_id'], 'helpful_heading', true ) ) {
- $helpful['heading'] = do_shortcode( get_post_meta( $helpful['post_id'], 'helpful_heading', true ) );
- }
-
- if ( get_post_meta( $helpful['post_id'], 'helpful_pro', true ) ) {
- $helpful['button_pro'] = do_shortcode( get_post_meta( $helpful['post_id'], 'helpful_pro', true ) );
- }
-
- if ( get_post_meta( $helpful['post_id'], 'helpful_contra', true ) ) {
- $helpful['button_contra'] = do_shortcode( get_post_meta( $helpful['post_id'], 'helpful_contra', true ) );
- }
-
- ob_start();
-
- $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' );
-
- $shortcode = ob_get_contents();
- ob_end_clean();
+ /**
+ * Instance
+ *
+ * @var Frontend
+ */
+ public static $instance;
+
+ /**
+ * Set instance and fire class
+ *
+ * @return Frontend
+ */
+ public static function get_instance()
+ {
+ if (!isset(self::$instance)) {
+ self::$instance = new self();
+ }
+ return self::$instance;
+ }
+
+ /**
+ * Class Constructor
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ 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_filter('init', [ & $this, 'filter_nonces']);
+ }
+
+ /**
+ * Retrieve default themes
+ *
+ * @param array $themes themes array.
+ *
+ * @return array
+ */
+ public function default_themes($themes)
+ {
+ $themes[] = [
+ 'id' => 'base',
+ 'label' => esc_html_x('Base', 'theme name', 'helpful'),
+ 'stylesheet' => plugins_url('core/assets/themes/base.css', HELPFUL_FILE),
+ ];
+
+ $themes[] = [
+ 'id' => 'dark',
+ 'label' => esc_html_x('Dark', 'theme name', 'helpful'),
+ 'stylesheet' => plugins_url('core/assets/themes/dark.css', HELPFUL_FILE),
+ ];
+
+ $themes[] = [
+ 'id' => 'minimal',
+ 'label' => esc_html_x('Minimal', 'theme name', 'helpful'),
+ 'stylesheet' => plugins_url('core/assets/themes/minimal.css', HELPFUL_FILE),
+ ];
+
+ $themes[] = [
+ 'id' => 'flat',
+ 'label' => esc_html_x('Flat', 'theme name', 'helpful'),
+ 'stylesheet' => plugins_url('core/assets/themes/flat.css', HELPFUL_FILE),
+ ];
+
+ $themes[] = [
+ 'id' => 'simple',
+ 'label' => esc_html_x('Simple', 'theme name', 'helpful'),
+ 'stylesheet' => plugins_url('core/assets/themes/simple.css', HELPFUL_FILE),
+ ];
+
+ $themes[] = [
+ 'id' => 'clean',
+ 'label' => esc_html_x('Clean', 'theme name', 'helpful'),
+ 'stylesheet' => plugins_url('core/assets/themes/clean.css', HELPFUL_FILE),
+ ];
+
+ $themes[] = [
+ 'id' => 'blank',
+ 'label' => esc_html_x('Blank', 'theme name', 'helpful'),
+ 'stylesheet' => null,
+ ];
+
+ return $themes;
+ }
+
+ /**
+ * Enqueue styles and scripts
+ *
+ * @return void
+ */
+ public function enqueue_scripts()
+ {
+ if (helpful_is_amp()) {
+ return __return_empty_string();
+ }
+
+ $active_theme = get_option('helpful_theme');
+ $themes = apply_filters('helpful_themes', []);
+ $plugin = Helper::get_plugin_data();
+
+ if (!empty($themes)) {
+ foreach ($themes as $theme) {
+ if ($active_theme !== $theme['id']) {
+ continue;
+ }
+
+ if ('blank' === $theme['id']) {
+ break;
+ }
+
+ wp_enqueue_style('helpful-theme-' . $theme['id'], $theme['stylesheet'], [], $plugin['Version']);
+ }
+ }
+
+ $file = Helper::plugins_url('core/assets/js/helpful.js');
+ wp_enqueue_script('helpful', $file, ['jquery'], $plugin['Version'], true);
+
+ $user = Helpers\User::get_user();
+ $nonce = wp_create_nonce('helpful_frontend_nonce');
+ $vars = [
+ 'ajax_url' => admin_url('admin-ajax.php'),
+ 'ajax_data' => [
+ 'user_id' => $user,
+ '_wpnonce' => $nonce,
+ ],
+ 'translations' => [
+ 'fieldIsRequired' => __('This field is required.', 'helpful'),
+ ],
+ ];
+
+ if (isset($_SESSION)) {
+ $vars['ajax_session'] = apply_filters('helpful_ajax_session', $_SESSION);
+ }
+
+ if (false === apply_filters('helpful_verify_frontend_nonce', true) && isset($vars['ajax_data'])) {
+ $vars['ajax_data'] = [];
+ }
+
+ $vars = apply_filters('helpful_frontend_ajax_vars', $vars);
+
+ wp_localize_script('helpful', 'helpful', $vars);
+ }
+
+ /**
+ * Ajax save user vote and render response.
+ *
+ * @return void
+ */
+ public function save_vote()
+ {
+ if (apply_filters('helpful_verify_frontend_nonce', true)) {
+ check_ajax_referer('helpful_frontend_nonce');
+ }
+
+ do_action('helpful_ajax_save_vote');
+
+ $user_id = null;
+ $post_id = null;
+ $value = null;
+
+ if (isset($_POST['user_id'])) {
+ $user_id = sanitize_text_field($_POST['user_id']);
+ }
+
+ if (isset($_POST['post'])) {
+ $post_id = intval($_POST['post']);
+ }
+
+ if (isset($_POST['value'])) {
+ $value = sanitize_text_field($_POST['value']);
+ }
+
+ if (false === Helpers\User::check_user($user_id, $post_id)) {
+ if ('pro' === $value) {
+ Helpers\Values::insert_pro($user_id, $post_id);
+ } else {
+ Helpers\Values::insert_contra($user_id, $post_id);
+ }
+
+ $response = do_shortcode(Helpers\Feedback::after_vote($post_id));
+ }
+
+ $response = Helpers\Values::convert_tags($response, $post_id);
+ echo apply_filters('helpful_pre_save_vote', $response, $post_id);
+ wp_die();
+ }
+
+ /**
+ * Ajax save user feedback and render response.
+ *
+ * @return void
+ */
+ public function save_feedback()
+ {
+ if (apply_filters('helpful_verify_feedback_nonce', true)) {
+ check_ajax_referer('helpful_feedback_nonce');
+ }
+
+ do_action('helpful_ajax_save_feedback');
+
+ $post_id = null;
+
+ if (isset($_REQUEST['post_id']) && is_numeric($_REQUEST['post_id'])) {
+ $post_id = intval($_REQUEST['post_id']);
+ }
+
+ /**
+ * Simple Spam Protection
+ */
+ $spam_protection = apply_filters('helpful_simple_spam_protection', '1');
+
+ if ('1' !== $spam_protection) {
+ $spam_protection = false;
+ } else {
+ $spam_protection = true;
+ }
+
+ if (!empty($_REQUEST['website']) && true === $spam_protection) {
+ $message = do_shortcode(get_option('helpful_feedback_message_spam'));
+ $message = apply_filters('helpful_pre_feedback_message_spam', $message, $post_id);
+ echo Helpers\Values::convert_tags($message, $post_id);
+ wp_die();
+ }
+
+ if (!isset($_REQUEST['helpful_cancel'])) {
+ Helpers\Feedback::insert_feedback();
+ }
+
+ /* OLD STYLE */
+ /*
+ $type = 'pro';
+
+ if ( isset( $_REQUEST['type'] ) ) {
+ $type = sanitize_text_field( $_REQUEST['type'] );
+ }
+ */
+
+ global $helpful_type;
+
+ $user_id = Helpers\User::get_user();
+ $type = Helpers\User::get_user_vote_status($user_id, $post_id);
+
+ $helpful_type[$post_id] = $type;
+
+ if ('pro' === $type) {
+ $message = do_shortcode(get_option('helpful_after_pro'));
+
+ if (get_post_meta($post_id, 'helpful_after_pro', true)) {
+ $message = do_shortcode(get_post_meta($post_id, 'helpful_after_pro', true));
+ }
+
+ $message = apply_filters('helpful_pre_after_pro', $message, $post_id);
+ } elseif ('contra' === $type) {
+ $message = do_shortcode(get_option('helpful_after_contra'));
+
+ if (get_post_meta($post_id, 'helpful_after_contra', true)) {
+ $message = do_shortcode(get_post_meta($post_id, 'helpful_after_contra', true));
+ }
+
+ $message = apply_filters('helpful_pre_after_contra', $message, $post_id);
+ } else {
+ $message = do_shortcode(get_option('helpful_after_fallback'));
+
+ if (get_post_meta($post_id, 'helpful_after_fallback', true)) {
+ $message = do_shortcode(get_post_meta($post_id, 'helpful_after_fallback', true));
+ }
+
+ $message = apply_filters('helpful_pre_after_fallback', $message, $post_id);
+ }
+
+ $message = Helpers\Values::convert_tags($message, $post_id);
+ echo apply_filters('helpful_pre_save_feedback', $message, $post_id);
+ wp_die();
+ }
+
+ /**
+ * Add helpful to post content
+ *
+ * @global $post
+ * @version 4.3.0
+ *
+ * @param string $content post content.
+ *
+ * @return string
+ */
+ public function the_content($content)
+ {
+ global $post;
+
+ if (helpful_is_amp()) {
+ return $content;
+ }
+
+ if (!isset($post->ID)) {
+ return $content;
+ }
+
+ $helpful = Helpers\Values::get_defaults();
+ $post_types = get_option('helpful_post_types');
+ $user_id = Helpers\User::get_user();
+
+ if ('on' === get_post_meta($helpful['post_id'], 'helpful_hide_on_post', true)) {
+ return $content;
+ }
+
+ if (!is_array($post_types) || !in_array($post->post_type, $post_types, true)) {
+ return $content;
+ }
+
+ if (get_option('helpful_hide_in_content')) {
+ return $content;
+ }
+
+ if (get_option('helpful_exists_hide') && Helpers\User::check_user($user_id, $helpful['post_id'])) {
+ return $content;
+ }
+
+ $conditions = Helper::get_conditions();
+
+ if (!empty($conditions)) {
+ return $content;
+ }
+
+ $exists = false;
+ $hidden = false;
+ $class = '';
+
+ if (isset($helpful['exists']) && 1 === $helpful['exists']) {
+ if (isset($helpful['exists-hide']) && 1 === $helpful['exists-hide']) {
+ return __return_empty_string();
+ }
+
+ $exists = true;
+ $hidden = true;
+ $class = 'helpful-exists';
+ $helpful['content'] = do_shortcode($helpful['exists_text']);
+
+ if (get_post_meta($helpful['post_id'], 'helpful_exists', true)) {
+ $helpful['content'] = do_shortcode(get_post_meta($helpful['post_id'], 'helpful_exists', true));
+ }
+ }
+
+ if (null === $helpful['post_id']) {
+ return esc_html__('No post found. Helpful must be placed in a post loop.', 'helpful');
+ }
+
+ if (false !== $exists && get_option('helpful_feedback_after_vote')) {
+ if (!Helper::is_feedback_disabled()) {
+ $shortcode = Helpers\Feedback::after_vote($helpful['post_id'], true);
+ $shortcode = Helpers\Values::convert_tags($shortcode, $helpful['post_id']);
+ return $content . $shortcode;
+ }
+ }
+
+ $helpful['content'] = do_shortcode($helpful['content']);
+
+ if (get_post_meta($helpful['post_id'], 'helpful_heading', true)) {
+ $helpful['heading'] = do_shortcode(get_post_meta($helpful['post_id'], 'helpful_heading', true));
+ }
+
+ if (get_post_meta($helpful['post_id'], 'helpful_pro', true)) {
+ $helpful['button_pro'] = do_shortcode(get_post_meta($helpful['post_id'], 'helpful_pro', true));
+ }
+
+ if (get_post_meta($helpful['post_id'], 'helpful_contra', true)) {
+ $helpful['button_contra'] = do_shortcode(get_post_meta($helpful['post_id'], 'helpful_contra', true));
+ }
+
+ ob_start();
+
+ $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');
+
+ $shortcode = ob_get_contents();
+ ob_end_clean();
- $shortcode = Helpers\Values::convert_tags( $shortcode, $helpful['post_id'] );
+ $shortcode = Helpers\Values::convert_tags($shortcode, $helpful['post_id']);
- return $content . $shortcode;
- }
-
- /**
- * Callback for helpful shortcode
- *
- * @global $post
- * @version 4.3.0
- *
- * @param array $atts shortcode attributes.
- * @param string $content shortcode content.
- *
- * @return string
- */
- public function helpful( $atts, $content = '' )
- {
- global $post;
-
- if ( helpful_is_amp() ) {
- return __return_empty_string();
- }
-
- $defaults = Helpers\Values::get_defaults();
- $defaults = apply_filters( 'helpful_shortcode_defaults', $defaults );
-
- $helpful = shortcode_atts( $defaults, $atts );
- $helpful = apply_filters( 'helpful_shortcode_atts', $helpful );
-
- $user_id = Helpers\User::get_user();
-
- if ( get_option( 'helpful_exists_hide' ) && Helpers\User::check_user( $user_id, $helpful['post_id'] ) ) {
- return __return_empty_string();
- }
-
- $exists = false;
- $hidden = false;
- $class = '';
-
- if ( isset( $helpful['exists'] ) && 1 === $helpful['exists'] ) {
- if ( isset( $helpful['exists-hide'] ) && 1 === $helpful['exists-hide'] ) {
- return __return_empty_string();
- }
-
- $exists = true;
- $hidden = true;
- $class = 'helpful-exists';
- $helpful['content'] = $helpful['exists_text'];
- }
-
- if ( null === $helpful['post_id'] ) {
- return esc_html__( 'No post found. Helpful must be placed in a post loop.', 'helpful' );
- }
-
- if ( false !== $exists && get_option( 'helpful_feedback_after_vote' ) ) {
- if ( ! Helper::is_feedback_disabled() ) {
- $shortcode = Helpers\Feedback::after_vote( $helpful['post_id'], true );
- $shortcode = Helpers\Values::convert_tags( $shortcode, $helpful['post_id'] );
- return $shortcode;
- }
- }
-
- if ( get_post_meta( $helpful['post_id'], 'helpful_heading', true ) ) {
- $helpful['heading'] = do_shortcode( get_post_meta( $helpful['post_id'], 'helpful_heading', true ) );
- }
-
- if ( get_post_meta( $helpful['post_id'], 'helpful_pro', true ) ) {
- $helpful['button_pro'] = do_shortcode( get_post_meta( $helpful['post_id'], 'helpful_pro', true ) );
- }
-
- if ( get_post_meta( $helpful['post_id'], 'helpful_contra', true ) ) {
- $helpful['button_contra'] = do_shortcode( get_post_meta( $helpful['post_id'], 'helpful_contra', true ) );
- }
-
- ob_start();
-
- $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' );
-
- $shortcode = ob_get_contents();
- ob_end_clean();
-
- $shortcode = Helpers\Values::convert_tags( $shortcode, $helpful['post_id'] );
-
- return $content . $shortcode;
- }
-
- /**
- * Filters the frontend nonces and set the value to false, using option.
- *
- * @return void
- */
- public function filter_nonces()
- {
- if ( 'on' === get_option( 'helpful_disable_frontend_nonce' ) ) {
- add_filter( 'helpful_verify_frontend_nonce', '__return_false' );
- }
-
- if ( 'on' === get_option( 'helpful_disable_feedback_nonce' ) ) {
- add_filter( 'helpful_verify_feedback_nonce', '__return_false' );
- }
- }
-}
\ No newline at end of file
+ return $content . $shortcode;
+ }
+
+ /**
+ * Callback for helpful shortcode
+ *
+ * @global $post
+ * @version 4.3.0
+ *
+ * @param array $atts shortcode attributes.
+ * @param string $content shortcode content.
+ *
+ * @return string
+ */
+ public function helpful($atts, $content = '')
+ {
+ global $post;
+
+ if (helpful_is_amp()) {
+ return __return_empty_string();
+ }
+
+ $defaults = Helpers\Values::get_defaults();
+ $defaults = apply_filters('helpful_shortcode_defaults', $defaults);
+
+ $helpful = shortcode_atts($defaults, $atts);
+ $helpful = apply_filters('helpful_shortcode_atts', $helpful);
+
+ $user_id = Helpers\User::get_user();
+
+ if (get_option('helpful_exists_hide') && Helpers\User::check_user($user_id, $helpful['post_id'])) {
+ return __return_empty_string();
+ }
+
+ $exists = false;
+ $hidden = false;
+ $class = '';
+
+ if (isset($helpful['exists']) && 1 === $helpful['exists']) {
+ if (isset($helpful['exists-hide']) && 1 === $helpful['exists-hide']) {
+ return __return_empty_string();
+ }
+
+ $exists = true;
+ $hidden = true;
+ $class = 'helpful-exists';
+ $helpful['content'] = $helpful['exists_text'];
+ }
+
+ if (null === $helpful['post_id']) {
+ return esc_html__('No post found. Helpful must be placed in a post loop.', 'helpful');
+ }
+
+ if (false !== $exists && get_option('helpful_feedback_after_vote')) {
+ if (!Helper::is_feedback_disabled()) {
+ $shortcode = Helpers\Feedback::after_vote($helpful['post_id'], true);
+ $shortcode = Helpers\Values::convert_tags($shortcode, $helpful['post_id']);
+ return $shortcode;
+ }
+ }
+
+ if (get_post_meta($helpful['post_id'], 'helpful_heading', true)) {
+ $helpful['heading'] = do_shortcode(get_post_meta($helpful['post_id'], 'helpful_heading', true));
+ }
+
+ if (get_post_meta($helpful['post_id'], 'helpful_pro', true)) {
+ $helpful['button_pro'] = do_shortcode(get_post_meta($helpful['post_id'], 'helpful_pro', true));
+ }
+
+ if (get_post_meta($helpful['post_id'], 'helpful_contra', true)) {
+ $helpful['button_contra'] = do_shortcode(get_post_meta($helpful['post_id'], 'helpful_contra', true));
+ }
+
+ ob_start();
+
+ $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');
+
+ $shortcode = ob_get_contents();
+ ob_end_clean();
+
+ $shortcode = Helpers\Values::convert_tags($shortcode, $helpful['post_id']);
+
+ return $content . $shortcode;
+ }
+
+ /**
+ * Filters the frontend nonces and set the value to false, using option.
+ *
+ * @return void
+ */
+ public function filter_nonces()
+ {
+ if ('on' === get_option('helpful_disable_frontend_nonce')) {
+ add_filter('helpful_verify_frontend_nonce', '__return_false');
+ }
+
+ if ('on' === get_option('helpful_disable_feedback_nonce')) {
+ add_filter('helpful_verify_feedback_nonce', '__return_false');
+ }
+ }
+}
diff --git a/helpful.php b/helpful.php
index 47c2471..f0eb81a 100644
--- a/helpful.php
+++ b/helpful.php
@@ -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.32
+ * Version: 4.4.33
* Author: Pixelbart
* Author URI: https://pixelbart.de
* Text Domain: helpful
@@ -11,122 +11,123 @@
*/
/* Prevent direct access */
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
+if (!defined('ABSPATH')) {
+ exit;
}
-define( 'HELPFUL_FILE', __FILE__ );
-define( 'HELPFUL_PATH', plugin_dir_path( __FILE__ ) );
-define( 'HELPFUL_PHP_MIN', '5.6.20' );
+define('HELPFUL_FILE', __FILE__);
+define('HELPFUL_PATH', plugin_dir_path(__FILE__));
+define('HELPFUL_PHP_MIN', '5.6.20');
/* Load Helpful after plugins are loaded */
-add_action( 'plugins_loaded', [ 'HelpfulPlugin', 'get_instance' ] );
-
-if ( ! class_exists( 'HelpfulPlugin' ) ) {
-
- class HelpfulPlugin
- {
- /**
- * Class Prefix.
- *
- * @var string
- */
- private $prefix = 'Helpful\\';
-
- /**
- * Saves an instance of the class.
- *
- * @var HelpfulPlugin
- */
- private static $instance;
-
- /**
- * Creates an instance of the class if it does not yet exist.
- *
- * @return HelpfulPlugin
- */
- public static function get_instance()
- {
- if ( ! isset( self::$instance ) ) {
- self::$instance = new self();
- }
-
- return self::$instance;
- }
-
- /**
- * Class constructor.
- *
- * @return void
- */
- private function __construct()
- {
- /* Starts the autoloader. */
- spl_autoload_register( [ $this, 'autoload' ] );
-
- /* Initializes the classes and functions. */
- $this->init();
- }
-
- /**
- * Includes all classes.
- *
- * @param string $class_name
- *
- * @return void
- */
- public function autoload( $class_name )
- {
- /* Stores the prefix. */
- $prefix = $this->prefix;
-
- $len = strlen( $prefix );
-
- if ( 0 !== strncmp( $prefix, $class_name, $len ) ) {
- return;
- }
-
- $relative_class = substr( $class_name, $len );
-
- $path = explode( '\\', strtolower( str_replace( '_', '-', $relative_class ) ) );
- $file = array_pop( $path );
- $file = HELPFUL_PATH . implode( '/', $path ) . '/class-' . $file . '.php';
-
- /* Includes the file if the file exists. */
- if ( file_exists( $file ) ) {
- require $file;
- }
- }
-
- /**
- * Initializes the classes.
- *
- * @return void
- */
- public function init()
- {
- include_once HELPFUL_PATH . 'core/functions/helpers.php';
-
- Helpful\Core\Modules\Core::get_instance();
- Helpful\Core\Modules\Maintenance::get_instance();
- Helpful\Core\Modules\debug::get_instance();
- Helpful\Core\Modules\Admin::get_instance();
-
- Helpful\Core\Modules\Feedback_Admin::get_instance();
- Helpful\Core\Modules\Metabox::get_instance();
- Helpful\Core\Modules\Widget::get_instance();
- Helpful\Core\Modules\Customizer::get_instance();
- Helpful\Core\Modules\Frontend::get_instance();
-
- Helpful\Core\Tabs\Start::get_instance();
- Helpful\Core\Tabs\Details::get_instance();
- Helpful\Core\Tabs\Texts::get_instance();
- Helpful\Core\Tabs\Feedback::get_instance();
- Helpful\Core\Tabs\Design::get_instance();
- Helpful\Core\Tabs\System::get_instance();
- Helpful\Core\Tabs\Log::get_instance();
-
- include_once HELPFUL_PATH . 'core/functions/values.php';
- }
- }
+add_action('plugins_loaded', ['HelpfulPlugin', 'get_instance']);
+
+if (!class_exists('HelpfulPlugin')) {
+
+ class HelpfulPlugin
+ {
+ /**
+ * Class Prefix.
+ *
+ * @var string
+ */
+ private $prefix = 'Helpful\\';
+
+ /**
+ * Saves an instance of the class.
+ *
+ * @var HelpfulPlugin
+ */
+ private static $instance;
+
+ /**
+ * Creates an instance of the class if it does not yet exist.
+ *
+ * @return HelpfulPlugin
+ */
+ public static function get_instance()
+ {
+ if (!isset(self::$instance)) {
+ self::$instance = new self();
+ }
+
+ return self::$instance;
+ }
+
+ /**
+ * Class constructor.
+ *
+ * @return void
+ */
+ private function __construct()
+ {
+ /* Starts the autoloader. */
+ spl_autoload_register([$this, 'autoload']);
+
+ /* Initializes the classes and functions. */
+ $this->init();
+ }
+
+ /**
+ * Includes all classes.
+ *
+ * @param string $class_name
+ *
+ * @return void
+ */
+ public function autoload($class_name)
+ {
+ /* Stores the prefix. */
+ $prefix = $this->prefix;
+
+ $len = strlen($prefix);
+
+ if (0 !== strncmp($prefix, $class_name, $len)) {
+ return;
+ }
+
+ $relative_class = substr($class_name, $len);
+
+ $path = explode('\\', strtolower(str_replace('_', '-', $relative_class)));
+ $file = array_pop($path);
+ $file = HELPFUL_PATH . implode('/', $path) . '/class-' . $file . '.php';
+
+ /* Includes the file if the file exists. */
+ if (file_exists($file)) {
+ require $file;
+ }
+ }
+
+ /**
+ * Initializes the classes.
+ *
+ * @return void
+ */
+ public function init()
+ {
+ include_once HELPFUL_PATH . 'core/functions/helpers.php';
+
+ Helpful\Core\Modules\Core::get_instance();
+
+ Helpful\Core\Modules\Maintenance::get_instance();
+ Helpful\Core\Modules\debug::get_instance();
+ Helpful\Core\Modules\Admin::get_instance();
+
+ Helpful\Core\Modules\Feedback_Admin::get_instance();
+ Helpful\Core\Modules\Metabox::get_instance();
+ Helpful\Core\Modules\Widget::get_instance();
+ Helpful\Core\Modules\Customizer::get_instance();
+ Helpful\Core\Modules\Frontend::get_instance();
+
+ Helpful\Core\Tabs\Start::get_instance();
+ Helpful\Core\Tabs\Details::get_instance();
+ Helpful\Core\Tabs\Texts::get_instance();
+ Helpful\Core\Tabs\Feedback::get_instance();
+ Helpful\Core\Tabs\Design::get_instance();
+ Helpful\Core\Tabs\System::get_instance();
+ Helpful\Core\Tabs\Log::get_instance();
+
+ include_once HELPFUL_PATH . 'core/functions/values.php';
+ }
+ }
}
diff --git a/readme.txt b/readme.txt
index 9f955f2..0fc6128 100644
--- a/readme.txt
+++ b/readme.txt
@@ -5,7 +5,7 @@ Tags: helpful, poll, feedback, reviews, vote, review, voting
Requires at least: 4.6
Tested up to: 5.7
Requires PHP: 5.6.20
-Stable tag: 4.4.32
+Stable tag: 4.4.33
License: MIT License
License URI: https://opensource.org/licenses/MIT