From 107533b1ac0028bce2b42c52677f62d2be3d5f44 Mon Sep 17 00:00:00 2001 From: Kevin Pliester <5339107+pixelbart@users.noreply.github.com> Date: Fri, 24 Sep 2021 13:29:05 +0200 Subject: [PATCH] 4.4.54 --- core/class-helper.php | 16 ++- core/helpers/class-database.php | 5 +- core/helpers/class-feedback.php | 53 +++++---- core/helpers/class-optimize.php | 7 +- core/helpers/class-stats.php | 137 +++++++++++++++--------- core/helpers/class-user.php | 25 +++-- core/helpers/class-values.php | 29 ++--- core/modules/class-admin.php | 31 ++++-- core/modules/class-core.php | 4 +- core/modules/class-elementor-widget.php | 13 ++- core/modules/class-feedback-admin.php | 4 +- core/modules/class-frontend.php | 48 ++++----- core/modules/class-maintenance.php | 7 +- core/modules/class-metabox.php | 5 +- core/modules/class-widget.php | 9 +- core/services/class-csv.php | 5 +- core/services/class-helpful.php | 24 +++++ core/services/class-options.php | 8 +- core/services/class-session.php | 4 +- core/tabs/class-design.php | 5 +- core/tabs/class-start.php | 5 +- core/tabs/class-system.php | 5 +- helpful.php | 2 +- readme.txt | 2 +- templates/feedback.php | 19 ++-- templates/tabs/tab-details.php | 46 ++++---- templates/tabs/tab-feedback.php | 52 ++++----- templates/tabs/tab-system.php | 32 +++--- templates/tabs/tab-texts.php | 28 ++--- 29 files changed, 395 insertions(+), 235 deletions(-) diff --git a/core/class-helper.php b/core/class-helper.php index 0ac04e4..bd95212 100644 --- a/core/class-helper.php +++ b/core/class-helper.php @@ -7,6 +7,8 @@ */ namespace Helpful\Core; +use Helpful\Core\Services as Services; + /* Prevent direct access */ if (!defined('ABSPATH')) { exit; @@ -47,7 +49,9 @@ public static function get_plugin_data() */ public static function set_timezone() { - $timezone = get_option('helpful_timezone'); + $options = new Services\Options(); + + $timezone = $options->get_option('helpful_timezone'); if (isset($timezone) && '' !== trim($timezone)) { date_default_timezone_set($timezone); @@ -335,11 +339,13 @@ public static function datatables_language_string() */ public static function get_disallowed_keys() { + $options = new Services\Options(); + if (version_compare(get_bloginfo('version'), '5.5.0') >= 0) { - return trim(get_option('disallowed_keys')); + return trim($options->get_option('disallowed_keys')); } - return trim(get_option('blacklist_keys')); + return trim($options->get_option('blacklist_keys')); } /** @@ -435,7 +441,9 @@ public static function set_capability($option, $value) */ public static function is_feedback_disabled() { - if ('on' === get_option('helpful_feedback_disabled')) { + $options = new Services\Options(); + + if ('on' === $options->get_option('helpful_feedback_disabled')) { return true; } diff --git a/core/helpers/class-database.php b/core/helpers/class-database.php index 9da4f9e..ef438c2 100644 --- a/core/helpers/class-database.php +++ b/core/helpers/class-database.php @@ -8,6 +8,7 @@ namespace Helpful\Core\Helpers; use Helpful\Core\Helper; +use Helpful\Core\Services as Services; /* Prevent direct access */ if (!defined('ABSPATH')) { @@ -183,7 +184,9 @@ public static function handle_table_instances() */ public static function update_tables() { - if (get_option('helpful_update_table_integer')) { + $options = new Services\Options(); + + if ($options->get_option('helpful_update_table_integer')) { return; } diff --git a/core/helpers/class-feedback.php b/core/helpers/class-feedback.php index 873db15..b4589cf 100644 --- a/core/helpers/class-feedback.php +++ b/core/helpers/class-feedback.php @@ -8,6 +8,7 @@ namespace Helpful\Core\Helpers; use Helpful\Core\Helper; +use Helpful\Core\Services as Services; /* Prevent direct access */ if (!defined('ABSPATH')) { @@ -76,8 +77,10 @@ public static function get_feedback($entry) */ public static function get_feedback_items($limit = null) { + $options = new Services\Options(); + if (is_null($limit)) { - $limit = absint(get_option('helpful_widget_amount')); + $limit = absint($options->get_option('helpful_widget_amount')); } global $wpdb; @@ -110,6 +113,8 @@ public static function insert_feedback() $pro = 0; $contra = 0; $message = null; + + do_action('helpful/insert_feedback'); if (!isset($_REQUEST['post_id'])) { $message = 'Helpful Notice: Feedback was not saved because the post id is empty in %s on line %d.'; @@ -215,12 +220,14 @@ public static function insert_feedback() */ public static function send_email($feedback) { + $options = new Services\Options(); + /** * Send email to voter. */ self::send_email_voter($feedback); - if ('on' !== get_option('helpful_feedback_send_email')) { + if ('on' !== $options->get_option('helpful_feedback_send_email')) { return; } @@ -229,6 +236,8 @@ public static function send_email($feedback) if (!$post) { return; } + + do_action('helpful/send_email'); $feedback['fields'] = maybe_unserialize($feedback['fields']); @@ -253,7 +262,7 @@ public static function send_email($feedback) $tags = apply_filters('helpful_feedback_email_tags', $tags); /* email subject */ - $subject = get_option('helpful_feedback_subject'); + $subject = $options->get_option('helpful_feedback_subject'); $subject = str_replace(array_keys($tags), array_values($tags), $subject); /* unserialize feedback fields */ @@ -265,7 +274,7 @@ public static function send_email($feedback) } /* body */ - $body = get_option('helpful_feedback_email_content'); + $body = $options->get_option('helpful_feedback_email_content'); $body = str_replace(array_keys($tags), array_values($tags), $body); /* receivers by post meta */ @@ -280,8 +289,8 @@ public static function send_email($feedback) /* receivers by helpful options */ $helpful_receivers = []; - if (get_option('helpful_feedback_receivers')) { - $helpful_receivers = get_option('helpful_feedback_receivers'); + if ($options->get_option('helpful_feedback_receivers')) { + $helpful_receivers = $options->get_option('helpful_feedback_receivers'); $helpful_receivers = helpful_trim_all($helpful_receivers); $helpful_receivers = explode(',', $helpful_receivers); } @@ -325,7 +334,9 @@ public static function send_email($feedback) */ public static function send_email_voter($feedback) { - if ('on' !== get_option('helpful_feedback_send_email_voter')) { + $options = new Services\Options(); + + if ('on' !== $options->get_option('helpful_feedback_send_email_voter')) { return; } @@ -334,6 +345,8 @@ public static function send_email_voter($feedback) if (!$post) { return; } + + do_action('helpful/send_email_voter'); $feedback['fields'] = maybe_unserialize($feedback['fields']); @@ -352,7 +365,7 @@ public static function send_email_voter($feedback) $tags = apply_filters('helpful_feedback_email_tags', $tags); /* subject */ - $subject = get_option('helpful_feedback_subject_voter'); + $subject = $options->get_option('helpful_feedback_subject_voter'); $subject = str_replace(array_keys($tags), array_values($tags), $subject); /* unserialize feedback fields */ @@ -364,7 +377,7 @@ public static function send_email_voter($feedback) } /* Body */ - $body = get_option('helpful_feedback_email_content_voter'); + $body = $options->get_option('helpful_feedback_email_content_voter'); $body = str_replace(array_keys($tags), array_values($tags), $body); /* Receivers */ @@ -439,7 +452,9 @@ public static function get_feedback_count($post_id = null) */ public static function after_vote($post_id, $show_feedback = false) { - // $feedback_text = esc_html_x( 'Thank you very much. Please write us your opinion, so that we can improve ourselves.', 'form user note', 'helpful' ); + do_action('helpful/after_vote'); + + $options = new Services\Options(); $hide_feedback = get_post_meta($post_id, 'helpful_hide_feedback_on_post', true); $hide_feedback = ('on' === $hide_feedback) ? true : false; @@ -461,16 +476,16 @@ public static function after_vote($post_id, $show_feedback = false) if (true === $show_feedback) { $type = 'none'; - $feedback_text = get_option('helpful_feedback_message_voted'); + $feedback_text = $options->get_option('helpful_feedback_message_voted'); $feedback_text = apply_filters('helpful_pre_feedback_message_voted', $feedback_text, $post_id); } if ('pro' === $type) { - $feedback_text = get_option('helpful_feedback_message_pro'); + $feedback_text = $options->get_option('helpful_feedback_message_pro'); if (false === $show_feedback) { - if (!get_option('helpful_feedback_after_pro') || true === $hide_feedback) { - $content = do_shortcode(get_option('helpful_after_pro')); + if (!$options->get_option('helpful_feedback_after_pro') || true === $hide_feedback) { + $content = do_shortcode($options->get_option('helpful_after_pro')); if (get_post_meta($post_id, 'helpful_after_pro', true)) { $content = do_shortcode(get_post_meta($post_id, 'helpful_after_pro', true)); @@ -482,11 +497,11 @@ public static function after_vote($post_id, $show_feedback = false) } if ('contra' === $type) { - $feedback_text = get_option('helpful_feedback_message_contra'); + $feedback_text = $options->get_option('helpful_feedback_message_contra'); if (false === $show_feedback) { - if (!get_option('helpful_feedback_after_contra') || true === $hide_feedback) { - $content = do_shortcode(get_option('helpful_after_contra')); + if (!$options->get_option('helpful_feedback_after_contra') || true === $hide_feedback) { + $content = do_shortcode($options->get_option('helpful_after_contra')); if (get_post_meta($post_id, 'helpful_after_contra', true)) { $content = do_shortcode(get_post_meta($post_id, 'helpful_after_contra', true)); @@ -498,8 +513,8 @@ public static function after_vote($post_id, $show_feedback = false) } if ('none' === $type) { - if (!get_option('helpful_feedback_after_pro') && !get_option('helpful_feedback_after_contra') && false === $show_feedback) { - $content = do_shortcode(get_option('helpful_after_fallback')); + if (!$options->get_option('helpful_feedback_after_pro') && !$options->get_option('helpful_feedback_after_contra') && false === $show_feedback) { + $content = do_shortcode($options->get_option('helpful_after_fallback')); if (get_post_meta($post_id, 'helpful_after_fallback', true)) { $content = do_shortcode(get_post_meta($post_id, 'helpful_after_fallback', true)); diff --git a/core/helpers/class-optimize.php b/core/helpers/class-optimize.php index e6d0cdf..afcbfc0 100644 --- a/core/helpers/class-optimize.php +++ b/core/helpers/class-optimize.php @@ -8,6 +8,7 @@ namespace Helpful\Core\Helpers; use Helpful\Core\Helper; +use Helpful\Core\Services as Services; /* Prevent direct access */ if (!defined('ABSPATH')) { @@ -270,8 +271,10 @@ public static function clear_cache() */ public static function update_metas() { + $options = new Services\Options(); + $response = []; - $post_types = get_option('helpful_post_types'); + $post_types = $options->get_option('helpful_post_types'); $args = [ 'post_type' => $post_types, @@ -286,7 +289,7 @@ public static function update_metas() $percentages = false; - if (get_option('helpful_percentages')) { + if ($options->get_option('helpful_percentages')) { $percentages = true; } diff --git a/core/helpers/class-stats.php b/core/helpers/class-stats.php index 0094598..cedf13e 100644 --- a/core/helpers/class-stats.php +++ b/core/helpers/class-stats.php @@ -8,6 +8,7 @@ namespace Helpful\Core\Helpers; use Helpful\Core\Helper; +use Helpful\Core\Services as Services; /* Prevent direct access */ if (!defined('ABSPATH')) { @@ -76,13 +77,15 @@ public static function get_pro($post_id = null, $percentages = false) global $wpdb; + $options = new Services\Options(); + $post_id = absint($post_id); $helpful = $wpdb->prefix . 'helpful'; $sql = $wpdb->prepare("SELECT COUNT(*) FROM $helpful WHERE pro = 1 AND post_id = %d", intval($post_id)); $cache_name = 'helpful_pro_' . $post_id; - $cache_time = get_option('helpful_cache_time', 'minute'); - $cache_active = get_option('helpful_caching', 'off'); + $cache_time = $options->get_option('helpful_cache_time', 'minute'); + $cache_active = $options->get_option('helpful_caching', 'off'); $cache_times = Cache::get_cache_times(false); $cache_time = $cache_times[$cache_time]; $var = get_transient($cache_name); @@ -139,13 +142,15 @@ public static function get_contra($post_id = null, $percentages = false) global $wpdb; + $options = new Services\Options(); + $post_id = absint($post_id); $helpful = $wpdb->prefix . 'helpful'; $sql = $wpdb->prepare("SELECT COUNT(*) FROM $helpful WHERE contra = 1 AND post_id = %d", intval($post_id)); $cache_name = 'helpful_contra_' . $post_id; - $cache_time = get_option('helpful_cache_time', 'minute'); - $cache_active = get_option('helpful_caching', 'off'); + $cache_time = $options->get_option('helpful_cache_time', 'minute'); + $cache_active = $options->get_option('helpful_caching', 'off'); $cache_times = Cache::get_cache_times(false); $cache_time = $cache_times[$cache_time]; $var = get_transient($cache_name); @@ -191,12 +196,14 @@ public static function get_pro_all($percentages = false) { global $wpdb; + $options = new Services\Options(); + $helpful = $wpdb->prefix . 'helpful'; $sql = "SELECT COUNT(*) FROM $helpful WHERE pro = 1"; $cache_name = 'helpful_pro_all'; - $cache_time = get_option('helpful_cache_time', 'minute'); - $cache_active = get_option('helpful_caching', 'off'); + $cache_time = $options->get_option('helpful_cache_time', 'minute'); + $cache_active = $options->get_option('helpful_caching', 'off'); $cache_times = Cache::get_cache_times(false); $cache_time = $cache_times[$cache_time]; $var = get_transient($cache_name); @@ -240,12 +247,14 @@ public static function get_contra_all($percentages = false) { global $wpdb; + $options = new Services\Options(); + $helpful = $wpdb->prefix . 'helpful'; $sql = "SELECT COUNT(*) FROM $helpful WHERE contra = 1"; $cache_name = 'helpful_contra_all'; - $cache_time = get_option('helpful_cache_time', 'minute'); - $cache_active = get_option('helpful_caching', 'off'); + $cache_time = $options->get_option('helpful_cache_time', 'minute'); + $cache_active = $options->get_option('helpful_caching', 'off'); $cache_times = Cache::get_cache_times(false); $cache_time = $cache_times[$cache_time]; $var = get_transient($cache_name); @@ -286,12 +295,14 @@ public static function get_years() { global $wpdb; + $options = new Services\Options(); + $helpful = $wpdb->prefix . 'helpful'; $sql = "SELECT time FROM $helpful ORDER BY time DESC"; $cache_name = 'helpful/stats/years'; - $cache_time = get_option('helpful_cache_time', 'minute'); - $cache_active = get_option('helpful_caching', 'off'); + $cache_time = $options->get_option('helpful_cache_time', 'minute'); + $cache_active = $options->get_option('helpful_caching', 'off'); $cache_times = Cache::get_cache_times(false); $cache_time = $cache_times[$cache_time]; $results = get_transient($cache_name); @@ -333,6 +344,8 @@ public static function get_stats_today($year) { global $wpdb; + $options = new Services\Options(); + $helpful = $wpdb->prefix . 'helpful'; $query = " SELECT pro, contra, time @@ -344,8 +357,8 @@ public static function get_stats_today($year) $sql = $wpdb->prepare($query, intval($year)); $cache_name = 'helpful/stats/today/' . $year; - $cache_time = get_option('helpful_cache_time', 'minute'); - $cache_active = get_option('helpful_caching', 'off'); + $cache_time = $options->get_option('helpful_cache_time', 'minute'); + $cache_active = $options->get_option('helpful_caching', 'off'); $cache_times = Cache::get_cache_times(false); $cache_time = $cache_times[$cache_time]; $results = get_transient($cache_name); @@ -415,6 +428,8 @@ public static function get_stats_yesterday($year) { global $wpdb; + $options = new Services\Options(); + $helpful = $wpdb->prefix . 'helpful'; $query = " SELECT pro, contra, time @@ -426,8 +441,8 @@ public static function get_stats_yesterday($year) $sql = $wpdb->prepare($query, intval($year)); $cache_name = 'helpful/stats/yesterday/' . $year; - $cache_time = get_option('helpful_cache_time', 'minute'); - $cache_active = get_option('helpful_caching', 'off'); + $cache_time = $options->get_option('helpful_cache_time', 'minute'); + $cache_active = $options->get_option('helpful_caching', 'off'); $cache_times = Cache::get_cache_times(false); $cache_time = $cache_times[$cache_time]; $results = get_transient($cache_name); @@ -497,6 +512,8 @@ public static function get_stats_week($year) { global $wpdb; + $options = new Services\Options(); + $helpful = $wpdb->prefix . 'helpful'; $query = " SELECT pro, contra, time @@ -508,8 +525,8 @@ public static function get_stats_week($year) $sql = $wpdb->prepare($query, intval($year)); $cache_name = 'helpful/stats/week/' . $year; - $cache_time = get_option('helpful_cache_time', 'minute'); - $cache_active = get_option('helpful_caching', 'off'); + $cache_time = $options->get_option('helpful_cache_time', 'minute'); + $cache_active = $options->get_option('helpful_caching', 'off'); $cache_times = Cache::get_cache_times(false); $cache_time = $cache_times[$cache_time]; $results = get_transient($cache_name); @@ -606,6 +623,8 @@ public static function get_stats_month($year, $month = null) { global $wpdb; + $options = new Services\Options(); + $helpful = $wpdb->prefix . 'helpful'; if (is_null($month)) { @@ -624,8 +643,8 @@ public static function get_stats_month($year, $month = null) $sql = $wpdb->prepare($query, intval($month), intval($year)); $cache_name = 'helpful/stats/month/' . $month . '/' . $year; - $cache_time = get_option('helpful_cache_time', 'minute'); - $cache_active = get_option('helpful_caching', 'off'); + $cache_time = $options->get_option('helpful_cache_time', 'minute'); + $cache_active = $options->get_option('helpful_caching', 'off'); $cache_times = Cache::get_cache_times(false); $cache_time = $cache_times[$cache_time]; $results = get_transient($cache_name); @@ -721,6 +740,8 @@ public static function get_stats_year($year) { global $wpdb; + $options = new Services\Options(); + $helpful = $wpdb->prefix . 'helpful'; $query = " SELECT pro, contra, time @@ -731,8 +752,8 @@ public static function get_stats_year($year) $sql = $wpdb->prepare($query, intval($year)); $cache_name = 'helpful/stats/year/' . $year; - $cache_time = get_option('helpful_cache_time', 'minute'); - $cache_active = get_option('helpful_caching', 'off'); + $cache_time = $options->get_option('helpful_cache_time', 'minute'); + $cache_active = $options->get_option('helpful_caching', 'off'); $cache_times = Cache::get_cache_times(false); $cache_time = $cache_times[$cache_time]; $results = get_transient($cache_name); @@ -828,6 +849,8 @@ public static function get_stats_range($from, $to) { global $wpdb; + $options = new Services\Options(); + $helpful = $wpdb->prefix . 'helpful'; $query = " SELECT pro, contra, time @@ -839,8 +862,8 @@ public static function get_stats_range($from, $to) $sql = $wpdb->prepare($query, $from, $to); $cache_name = 'helpful/stats/range/' . $from . '/' . $to; - $cache_time = get_option('helpful_cache_time', 'minute'); - $cache_active = get_option('helpful_caching', 'off'); + $cache_time = $options->get_option('helpful_cache_time', 'minute'); + $cache_active = $options->get_option('helpful_caching', 'off'); $cache_times = Cache::get_cache_times(false); $cache_time = $cache_times[$cache_time]; $results = get_transient($cache_name); @@ -923,12 +946,14 @@ public static function get_stats_total() { global $wpdb; + $options = new Services\Options(); + $helpful = $wpdb->prefix . 'helpful'; $sql = "SELECT pro, contra, time FROM $helpful"; $cache_name = 'helpful/stats/total'; - $cache_time = get_option('helpful_cache_time', 'minute'); - $cache_active = get_option('helpful_caching', 'off'); + $cache_time = $options->get_option('helpful_cache_time', 'minute'); + $cache_active = $options->get_option('helpful_caching', 'off'); $cache_times = Cache::get_cache_times(false); $cache_time = $cache_times[$cache_time]; $results = get_transient($cache_name); @@ -996,14 +1021,16 @@ public static function get_stats_total() */ public static function get_most_helpful($limit = null, $post_type = null) { + $options = new Services\Options(); + if (is_null($limit)) { - $limit = intval(get_option('helpful_widget_amount')); + $limit = intval($options->get_option('helpful_widget_amount')); } else { $limit = intval($limit); } if (is_null($post_type)) { - $post_type = get_option('helpful_post_types'); + $post_type = $options->get_option('helpful_post_types'); } $args = [ @@ -1014,8 +1041,8 @@ public static function get_most_helpful($limit = null, $post_type = null) ]; $cache_name = 'helpful_most_helpful'; - $cache_time = get_option('helpful_cache_time', 'minute'); - $cache_active = get_option('helpful_caching', 'off'); + $cache_time = $options->get_option('helpful_cache_time', 'minute'); + $cache_active = $options->get_option('helpful_caching', 'off'); $cache_times = Cache::get_cache_times(false); $cache_time = $cache_times[$cache_time]; $query = get_transient($cache_name); @@ -1088,12 +1115,14 @@ public static function get_most_helpful($limit = null, $post_type = null) */ public static function get_least_helpful($limit = null, $post_type = null) { + $options = new Services\Options(); + if (is_null($limit)) { - $limit = absint(get_option('helpful_widget_amount')); + $limit = absint($options->get_option('helpful_widget_amount')); } if (is_null($post_type)) { - $post_type = get_option('helpful_post_types'); + $post_type = $options->get_option('helpful_post_types'); } $args = [ @@ -1104,8 +1133,8 @@ public static function get_least_helpful($limit = null, $post_type = null) ]; $cache_name = 'helpful_least_helpful'; - $cache_time = get_option('helpful_cache_time', 'minute'); - $cache_active = get_option('helpful_caching', 'off'); + $cache_time = $options->get_option('helpful_cache_time', 'minute'); + $cache_active = $options->get_option('helpful_caching', 'off'); $cache_times = Cache::get_cache_times(false); $cache_time = $cache_times[$cache_time]; $query = get_transient($cache_name); @@ -1179,8 +1208,10 @@ public static function get_least_helpful($limit = null, $post_type = null) */ public static function get_recently_pro($limit = null) { + $options = new Services\Options(); + if (is_null($limit)) { - $limit = absint(get_option('helpful_widget_amount')); + $limit = absint($options->get_option('helpful_widget_amount')); } global $wpdb; @@ -1198,8 +1229,8 @@ public static function get_recently_pro($limit = null) $sql = $wpdb->prepare($sql, 1, intval($limit)); $cache_name = 'helpful_recently_pro'; - $cache_time = get_option('helpful_cache_time', 'minute'); - $cache_active = get_option('helpful_caching', 'off'); + $cache_time = $options->get_option('helpful_cache_time', 'minute'); + $cache_active = $options->get_option('helpful_caching', 'off'); $cache_times = Cache::get_cache_times(false); $cache_time = $cache_times[$cache_time]; $results = get_transient($cache_name); @@ -1245,8 +1276,10 @@ public static function get_recently_pro($limit = null) */ public static function get_recently_contra($limit = null) { + $options = new Services\Options(); + if (is_null($limit)) { - $limit = absint(get_option('helpful_widget_amount')); + $limit = absint($options->get_option('helpful_widget_amount')); } global $wpdb; @@ -1264,8 +1297,8 @@ public static function get_recently_contra($limit = null) $sql = $wpdb->prepare($sql, 1, intval($limit)); $cache_name = 'helpful_recently_contra'; - $cache_time = get_option('helpful_cache_time', 'minute'); - $cache_active = get_option('helpful_caching', 'off'); + $cache_time = $options->get_option('helpful_cache_time', 'minute'); + $cache_active = $options->get_option('helpful_caching', 'off'); $cache_times = Cache::get_cache_times(false); $cache_time = $cache_times[$cache_time]; $results = get_transient($cache_name); @@ -1307,6 +1340,8 @@ public static function get_recently_contra($limit = null) */ public static function get_single_post_stats($post_id) { + $options = new Services\Options(); + $post = get_post($post_id); $pro = self::get_pro($post->ID) ? intval(self::get_pro($post->ID)) : 0; $contra = self::get_contra($post->ID) ? intval(self::get_contra($post->ID)) : 0; @@ -1364,20 +1399,22 @@ public static function get_single_post_stats($post_id) */ public static function get_widget_stats() { + $options = new Services\Options(); + $cache_name = 'helpful_widget_stats'; - $cache_time = get_option('helpful_cache_time', 'minute'); - $cache_active = get_option('helpful_caching', 'off'); + $cache_time = $options->get_option('helpful_cache_time', 'minute'); + $cache_active = $options->get_option('helpful_caching', 'off'); $cache_times = Cache::get_cache_times(false); $cache_time = $cache_times[$cache_time]; $results = get_transient($cache_name); if ('on' !== $cache_active) { $results = [ - 'most_helpful' => get_option('helpful_widget_pro') ? self::get_most_helpful() : null, - 'least_helpful' => get_option('helpful_widget_contra') ? self::get_least_helpful() : null, - 'recently_pro' => get_option('helpful_widget_pro_recent') ? self::get_recently_pro() : null, - 'recently_contra' => get_option('helpful_widget_contra_recent') ? self::get_recently_contra() : null, - 'feedback_items' => get_option('helpful_feedback_widget') ? Feedback::get_feedback_items() : null, + 'most_helpful' => $options->get_option('helpful_widget_pro') ? self::get_most_helpful() : null, + 'least_helpful' => $options->get_option('helpful_widget_contra') ? self::get_least_helpful() : null, + 'recently_pro' => $options->get_option('helpful_widget_pro_recent') ? self::get_recently_pro() : null, + 'recently_contra' => $options->get_option('helpful_widget_contra_recent') ? self::get_recently_contra() : null, + 'feedback_items' => $options->get_option('helpful_feedback_widget') ? Feedback::get_feedback_items() : null, 'pro_total' => intval(self::get_pro_all()), 'contra_total' => intval(self::get_contra_all()), ]; @@ -1387,11 +1424,11 @@ public static function get_widget_stats() if (false === $results) { $results = [ - 'most_helpful' => get_option('helpful_widget_pro') ? self::get_most_helpful() : null, - 'least_helpful' => get_option('helpful_widget_contra') ? self::get_least_helpful() : null, - 'recently_pro' => get_option('helpful_widget_pro_recent') ? self::get_recently_pro() : null, - 'recently_contra' => get_option('helpful_widget_contra_recent') ? self::get_recently_contra() : null, - 'feedback_items' => get_option('helpful_feedback_widget') ? Feedback::get_feedback_items() : null, + 'most_helpful' => $options->get_option('helpful_widget_pro') ? self::get_most_helpful() : null, + 'least_helpful' => $options->get_option('helpful_widget_contra') ? self::get_least_helpful() : null, + 'recently_pro' => $options->get_option('helpful_widget_pro_recent') ? self::get_recently_pro() : null, + 'recently_contra' => $options->get_option('helpful_widget_contra_recent') ? self::get_recently_contra() : null, + 'feedback_items' => $options->get_option('helpful_feedback_widget') ? Feedback::get_feedback_items() : null, 'pro_total' => intval(self::get_pro_all()), 'contra_total' => intval(self::get_contra_all()), ]; diff --git a/core/helpers/class-user.php b/core/helpers/class-user.php index 8f188eb..7ef26dd 100644 --- a/core/helpers/class-user.php +++ b/core/helpers/class-user.php @@ -24,19 +24,21 @@ class User */ public static function get_user() { + $options = new Services\Options(); + $user = self::get_user_string(); - if ('on' === get_option('helpful_user_random')) { + if ('on' === $options->get_option('helpful_user_random')) { return self::get_user_string(); } - if ('on' === get_option('helpful_wordpress_user')) { + if ('on' === $options->get_option('helpful_wordpress_user')) { if (is_user_logged_in()) { return get_current_user_id(); } } - if ('on' === get_option('helpful_ip_user')) { + if ('on' === $options->get_option('helpful_ip_user')) { if (isset($_SERVER['REMOTE_ADDR'])) { return sanitize_text_field($_SERVER['REMOTE_ADDR']); } @@ -80,15 +82,16 @@ public static function get_user_string() */ public static function set_user() { + $options = new Services\Options(); $string = self::get_user_string(); $lifetime = '+30 days'; $lifetime = apply_filters('helpful_user_cookie_time', $lifetime); - $samesite = get_option('helpful_cookies_samesite') ?: 'Strict'; + $samesite = $options->get_option('helpful_cookies_samesite') ?: 'Strict'; /** * No more user is set using sessions or cookies. */ - if ('on' === get_option('helpful_user_random')) { + if ('on' === $options->get_option('helpful_user_random')) { return; } @@ -125,7 +128,7 @@ public static function set_user() } $session_start = apply_filters('helpful_session_start', true); - $sessions_disabled = get_option('helpful_sessions_false'); + $sessions_disabled = $options->get_option('helpful_sessions_false'); if (!is_bool($session_start)) { $session_start = true; @@ -153,11 +156,13 @@ public static function set_user() */ public static function check_user($user_id, $post_id, $instance = null) { - if (get_option('helpful_multiple')) { + $options = new Services\Options(); + + if ($options->get_option('helpful_multiple')) { return false; } - if ('on' === get_option('helpful_user_random')) { + if ('on' === $options->get_option('helpful_user_random')) { return false; } @@ -265,9 +270,11 @@ public static function get_user_vote_status($user_id, $post_id) */ public static function get_avatar($email = null, $size = 55) { + $options = new Services\Options(); + $default = plugins_url('core/assets/images/avatar.jpg', HELPFUL_FILE); - if (get_option('helpful_feedback_gravatar')) { + if ($options->get_option('helpful_feedback_gravatar')) { if (!is_null($email)) { return get_avatar($email, $size, $default); } diff --git a/core/helpers/class-values.php b/core/helpers/class-values.php index ce37a3c..c214cb8 100644 --- a/core/helpers/class-values.php +++ b/core/helpers/class-values.php @@ -8,6 +8,7 @@ namespace Helpful\Core\Helpers; use Helpful\Core\Helper; +use Helpful\Core\Services as Services; /* Prevent direct access */ if (!defined('ABSPATH')) { @@ -51,27 +52,29 @@ public static function get_defaults() $post_id = $post->ID; } + $options = new Services\Options(); + $credits = Helper::get_credits_data(); $user_id = User::get_user(); $values = [ 'heading_tag' => 'h3', - 'heading' => self::convert_tags(get_option('helpful_heading'), $post_id), - 'content' => self::convert_tags(get_option('helpful_content'), $post_id), - 'button_pro' => get_option('helpful_pro'), - 'button_contra' => get_option('helpful_contra'), - 'button_pro_disabled' => ('on' === get_option('helpful_pro_disabled')) ? 1 : 0, - 'button_contra_disabled' => ('on' === get_option('helpful_contra_disabled')) ? 1 : 0, - 'counter' => (!get_option('helpful_count_hide')), + 'heading' => self::convert_tags($options->get_option('helpful_heading'), $post_id), + 'content' => self::convert_tags($options->get_option('helpful_content'), $post_id), + 'button_pro' => $options->get_option('helpful_pro'), + 'button_contra' => $options->get_option('helpful_contra'), + 'button_pro_disabled' => ('on' === $options->get_option('helpful_pro_disabled')) ? 1 : 0, + 'button_contra_disabled' => ('on' === $options->get_option('helpful_contra_disabled')) ? 1 : 0, + 'counter' => (!$options->get_option('helpful_count_hide')), 'count_pro' => Stats::get_pro($post_id), 'count_pro_percent' => Stats::get_pro($post_id, true), 'count_contra' => Stats::get_contra($post_id), 'count_contra_percent' => Stats::get_contra($post_id, true), - 'credits' => get_option('helpful_credits'), + 'credits' => $options->get_option('helpful_credits'), 'credits_html' => $credits['html'], 'exists' => User::check_user($user_id, $post_id) ? 1 : 0, - 'exists_text' => self::convert_tags(get_option('helpful_exists'), $post_id), - 'exists_hide' => ('on' === get_option('helpful_exists_hide')) ? 1 : 0, + 'exists_text' => self::convert_tags($options->get_option('helpful_exists'), $post_id), + 'exists_hide' => ('on' === $options->get_option('helpful_exists_hide')) ? 1 : 0, 'post_id' => $post_id, 'user_id' => User::get_user(), ]; @@ -377,9 +380,11 @@ public static function sync_post_meta() { $transient = 'helpful_sync_meta'; + $options = new Services\Options(); + if (false === ($query = get_transient($transient))) { - $post_types = get_option('helpful_post_types'); + $post_types = $options->get_option('helpful_post_types'); $args = [ 'post_type' => $post_types, @@ -389,7 +394,7 @@ public static function sync_post_meta() ]; $query = new \WP_Query($args); - $cache_time = get_option('helpful_cache_time', 'minute'); + $cache_time = $options->get_option('helpful_cache_time', 'minute'); $cache_times = Cache::get_cache_times(false); $cache_time = $cache_times[$cache_time]; diff --git a/core/modules/class-admin.php b/core/modules/class-admin.php index ee2081e..01726ce 100644 --- a/core/modules/class-admin.php +++ b/core/modules/class-admin.php @@ -9,6 +9,7 @@ use Helpful\Core\Helper; use Helpful\Core\Helpers as Helpers; +use Helpful\Core\Services as Services; /* Prevent direct access */ if (!defined('ABSPATH')) { @@ -57,10 +58,12 @@ public function __construct() */ public function register_admin_menu() { + $options = new Services\Options(); + add_menu_page( __('Helpful', 'helpful'), __('Helpful', 'helpful'), - get_option('helpful_capability', 'manage_options'), + $options->get_option('helpful_capability', 'manage_options'), 'helpful', [ & $this, 'callback_admin_page'], 'dashicons-thumbs-up', @@ -71,7 +74,7 @@ public function register_admin_menu() 'helpful', __('Settings', 'helpful'), __('Settings', 'helpful'), - get_option('helpful_settings_capability', 'manage_options'), + $options->get_option('helpful_settings_capability', 'manage_options'), 'helpful', [ & $this, 'callback_admin_page'] ); @@ -112,8 +115,10 @@ public function callback_admin_page() */ public function enqueue_scripts($hook_suffix) { + $options = new Services\Options(); + /* shrink admin columns */ - if ('on' === get_option('helpful_shrink_admin_columns')) { + if ('on' === $options->get_option('helpful_shrink_admin_columns')) { $file = plugins_url('core/assets/css/admin-columns.css', HELPFUL_FILE); wp_enqueue_style('helpful-admin-columns', $file); } @@ -183,8 +188,10 @@ public function init_columns() { global $pagenow; - $post_types = get_option('helpful_post_types'); - $hide_cols = get_option('helpful_hide_admin_columns'); + $options = new Services\Options(); + + $post_types = $options->get_option('helpful_post_types'); + $hide_cols = $options->get_option('helpful_hide_admin_columns'); if (isset($hide_cols) && 'on' === $hide_cols) { return; @@ -222,14 +229,16 @@ public function init_columns() */ public function register_columns($defaults) { + $options = new Services\Options(); + $columns = []; foreach ($defaults as $key => $value): $columns[$key] = $value; if ('title' === $key) { - $columns['helpful-pro'] = get_option('helpful_column_pro') ? get_option('helpful_column_pro') : _x('Pro', 'column name', 'helpful'); - $columns['helpful-contra'] = get_option('helpful_column_contra') ? get_option('helpful_column_contra') : _x('Contra', 'column name', 'helpful'); - $columns['helpful-feedback'] = get_option('helpful_column_feedback') ? get_option('helpful_column_feedback') : _x('Feedback', 'column name', 'helpful'); + $columns['helpful-pro'] = $options->get_option('helpful_column_pro') ? $options->get_option('helpful_column_pro') : _x('Pro', 'column name', 'helpful'); + $columns['helpful-contra'] = $options->get_option('helpful_column_contra') ? $options->get_option('helpful_column_contra') : _x('Contra', 'column name', 'helpful'); + $columns['helpful-feedback'] = $options->get_option('helpful_column_feedback') ? $options->get_option('helpful_column_feedback') : _x('Feedback', 'column name', 'helpful'); } endforeach; @@ -246,8 +255,10 @@ public function register_columns($defaults) */ public function populate_columns($column_name, $post_id) { + $options = new Services\Options(); + if ('helpful-pro' === $column_name) { - if (get_option('helpful_percentages')) { + if ($options->get_option('helpful_percentages')) { $percent = Helpers\Stats::get_pro($post_id, true); $pro = Helpers\Stats::get_pro($post_id); update_post_meta($post_id, 'helpful-pro', $pro); @@ -261,7 +272,7 @@ public function populate_columns($column_name, $post_id) } if ('helpful-contra' === $column_name) { - if (get_option('helpful_percentages')) { + if ($options->get_option('helpful_percentages')) { $percent = Helpers\Stats::get_contra($post_id, true); $contra = Helpers\Stats::get_contra($post_id); update_post_meta($post_id, 'helpful-contra', $contra); diff --git a/core/modules/class-core.php b/core/modules/class-core.php index 8181151..61740e7 100644 --- a/core/modules/class-core.php +++ b/core/modules/class-core.php @@ -96,7 +96,9 @@ public function set_user_cookie() */ public function setup_defaults() { - if (get_option('helpful_defaults')) { + $options = new Services\Options(); + + if ($options->get_option('helpful_defaults')) { return; } diff --git a/core/modules/class-elementor-widget.php b/core/modules/class-elementor-widget.php index 2095185..162931a 100644 --- a/core/modules/class-elementor-widget.php +++ b/core/modules/class-elementor-widget.php @@ -9,6 +9,7 @@ use Helpful\Core\Helper; use Helpful\Core\Helpers as Helpers; +use Helpful\Core\Services as Services; /* Prevent direct access */ if (!defined('ABSPATH')) { @@ -64,6 +65,8 @@ public function get_categories() */ protected function _register_controls() { + $options = new Services\Options(); + $this->start_controls_section( 'general', [ @@ -108,7 +111,7 @@ protected function _register_controls() 'label' => esc_html_x('Headline', 'elementor option name', 'helpful'), 'label_block' => true, 'type' => \Elementor\Controls_Manager::TEXT, - 'default' => get_option('helpful_heading'), + 'default' => $options->get_option('helpful_heading'), ] ); @@ -118,7 +121,7 @@ protected function _register_controls() 'label' => esc_html_x('Content', 'elementor option name', 'helpful'), 'label_block' => true, 'type' => \Elementor\Controls_Manager::TEXTAREA, - 'default' => get_option('helpful_content'), + 'default' => $options->get_option('helpful_content'), ] ); @@ -128,7 +131,7 @@ protected function _register_controls() 'label' => esc_html_x('Pro', 'elementor option name', 'helpful'), 'label_block' => true, 'type' => \Elementor\Controls_Manager::TEXT, - 'default' => get_option('helpful_pro'), + 'default' => $options->get_option('helpful_pro'), ] ); @@ -138,7 +141,7 @@ protected function _register_controls() 'label' => esc_html_x('Contra', 'elementor option name', 'helpful'), 'label_block' => true, 'type' => \Elementor\Controls_Manager::TEXT, - 'default' => get_option('helpful_contra'), + 'default' => $options->get_option('helpful_contra'), ] ); @@ -166,7 +169,7 @@ protected function _register_controls() 'description' => esc_html_x('This option overrides the Helpful theme and applies to all Helpful on the site. You will also need to reload the page to see the changes.', 'elementor option description', 'helpful'), 'type' => \Elementor\Controls_Manager::SELECT, 'options' => $choices, - 'default' => get_option('helpful_theme'), + 'default' => $options->get_option('helpful_theme'), ] ); diff --git a/core/modules/class-feedback-admin.php b/core/modules/class-feedback-admin.php index da7dc77..2be1e91 100644 --- a/core/modules/class-feedback-admin.php +++ b/core/modules/class-feedback-admin.php @@ -131,13 +131,15 @@ public function ajax_get_feedback_items() { check_ajax_referer('helpful_admin_feedback_filter'); + $options = new Services\Options(); + global $wpdb; $table_name = $wpdb->prefix . 'helpful_feedback'; $filters = ['all', 'pro', 'contra']; $sql = "SELECT * FROM $table_name"; - $limit = get_option('helpful_feedback_amount', 10); + $limit = $options->get_option('helpful_feedback_amount', 10); $limit = intval(apply_filters('helpful_feedback_limit', $limit)); $page = 1; diff --git a/core/modules/class-frontend.php b/core/modules/class-frontend.php index 9f13ae2..38ab2b2 100644 --- a/core/modules/class-frontend.php +++ b/core/modules/class-frontend.php @@ -136,7 +136,9 @@ public function enqueue_scripts() return __return_empty_string(); } - $active_theme = get_option('helpful_theme'); + $options = new Services\Options(); + + $active_theme = $options->get_option('helpful_theme'); $themes = apply_filters('helpful_themes', []); $plugin = Helper::get_plugin_data(); @@ -221,8 +223,10 @@ public function the_content($content) return $content; } + $options = new Services\Options(); + $helpful = Helpers\Values::get_defaults(); - $post_types = get_option('helpful_post_types'); + $post_types = $options->get_option('helpful_post_types'); $user_id = Helpers\User::get_user(); if ('on' === get_post_meta($helpful['post_id'], 'helpful_hide_on_post', true)) { @@ -233,7 +237,7 @@ public function the_content($content) return $content; } - if ('on' === get_option('helpful_hide_in_content')) { + if ('on' === $options->get_option('helpful_hide_in_content')) { return $content; } @@ -273,6 +277,8 @@ public function helpful($atts, $content = '') return $content; } + $options = new Services\Options(); + $defaults = Helpers\Values::get_defaults(); $defaults = apply_filters('helpful_shortcode_defaults', $defaults); @@ -283,7 +289,7 @@ public function helpful($atts, $content = '') $object = new Services\Helpful($helpful['post_id'], $helpful); - if ('on' === get_option('helpful_exists_hide') && $object->current_user_has_voted()) { + if ('on' === $options->get_option('helpful_exists_hide') && $object->current_user_has_voted()) { return $content; } @@ -308,7 +314,7 @@ public function helpful($atts, $content = '') return $content; } - if (1 === $helpful['exists'] && get_option('helpful_feedback_after_vote')) { + if (1 === $helpful['exists'] && $options->get_option('helpful_feedback_after_vote')) { if (!Helper::is_feedback_disabled()) { $content = Helpers\Feedback::after_vote($helpful['post_id'], true); $content = Helpers\Values::convert_tags($content, $helpful['post_id']); @@ -358,6 +364,8 @@ public function save_vote() $value = null; $response = ''; + $options = new Services\Options(); + if (isset($_POST['user_id'])) { $user_id = sanitize_text_field($_POST['user_id']); } @@ -370,7 +378,7 @@ public function save_vote() $value = sanitize_text_field($_POST['value']); } - if (is_user_logged_in() && 'on' === get_option('helpful_wordpress_user')) { + if (is_user_logged_in() && 'on' === $options->get_option('helpful_wordpress_user')) { $user_id = get_current_user_id(); } @@ -410,14 +418,13 @@ public function save_feedback() do_action('helpful_ajax_save_feedback'); + $options = new Services\Options(); + $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) { @@ -427,7 +434,7 @@ public function save_feedback() } if (!empty($_REQUEST['website']) && true === $spam_protection) { - $message = do_shortcode(get_option('helpful_feedback_message_spam')); + $message = do_shortcode($options->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(); @@ -437,15 +444,6 @@ public function save_feedback() 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(); @@ -454,7 +452,7 @@ public function save_feedback() $helpful_type[$post_id] = $type; if ('pro' === $type) { - $message = do_shortcode(get_option('helpful_after_pro')); + $message = do_shortcode($options->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)); @@ -462,7 +460,7 @@ public function save_feedback() $message = apply_filters('helpful_pre_after_pro', $message, $post_id); } elseif ('contra' === $type) { - $message = do_shortcode(get_option('helpful_after_contra')); + $message = do_shortcode($options->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)); @@ -470,7 +468,7 @@ public function save_feedback() $message = apply_filters('helpful_pre_after_contra', $message, $post_id); } else { - $message = do_shortcode(get_option('helpful_after_fallback')); + $message = do_shortcode($options->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)); @@ -491,11 +489,13 @@ public function save_feedback() */ public function filter_nonces() { - if ('on' === get_option('helpful_disable_frontend_nonce')) { + $options = new Services\Options(); + + if ('on' === $options->get_option('helpful_disable_frontend_nonce')) { add_filter('helpful_verify_frontend_nonce', '__return_false'); } - if ('on' === get_option('helpful_disable_feedback_nonce')) { + if ('on' === $options->get_option('helpful_disable_feedback_nonce')) { add_filter('helpful_verify_feedback_nonce', '__return_false'); } } diff --git a/core/modules/class-maintenance.php b/core/modules/class-maintenance.php index d7fd21c..f7f2ff0 100644 --- a/core/modules/class-maintenance.php +++ b/core/modules/class-maintenance.php @@ -9,6 +9,7 @@ use Helpful\Core\Helper; use Helpful\Core\Helpers as Helpers; +use Helpful\Core\Services as Services; /* Prevent direct access */ if (!defined('ABSPATH')) { @@ -102,7 +103,9 @@ public function maintenance() */ public function maintenance_after_update() { - if ('on' === get_option('helpful_notes')) { + $options = new Services\Options(); + + if ('on' === $options->get_option('helpful_notes')) { return; } @@ -114,7 +117,7 @@ public function maintenance_after_update() } $plugin = Helper::get_plugin_data(); - $option = get_option('helpful_plugin_version'); + $option = $options->get_option('helpful_plugin_version'); if ($option === $plugin['Version']) { return; diff --git a/core/modules/class-metabox.php b/core/modules/class-metabox.php index 980ec6b..59a3ff3 100644 --- a/core/modules/class-metabox.php +++ b/core/modules/class-metabox.php @@ -9,6 +9,7 @@ use Helpful\Core\Helper; use Helpful\Core\Helpers as Helpers; +use Helpful\Core\Services as Services; /* Prevent direct access */ if (!defined('ABSPATH')) { @@ -61,7 +62,9 @@ public function __construct() */ public function add_metabox() { - $post_types = get_option('helpful_post_types'); + $options = new Services\Options(); + + $post_types = $options->get_option('helpful_post_types'); if (isset($post_types) && is_array($post_types)) { add_meta_box( diff --git a/core/modules/class-widget.php b/core/modules/class-widget.php index 2ce75ff..87c45d7 100644 --- a/core/modules/class-widget.php +++ b/core/modules/class-widget.php @@ -9,6 +9,7 @@ use Helpful\Core\Helper; use Helpful\Core\Helpers as Helpers; +use Helpful\Core\Services as Services; /* Prevent direct access */ if (!defined('ABSPATH')) { @@ -62,7 +63,9 @@ public function __construct() */ public function enqueue_scripts($hook_suffix) { - if ('index.php' !== $hook_suffix || get_option('helpful_widget')) { + $options = new Services\Options(); + + if ('index.php' !== $hook_suffix || $options->get_option('helpful_widget')) { return; } @@ -90,7 +93,9 @@ public function enqueue_scripts($hook_suffix) */ public function widget_setup() { - if (get_option('helpful_widget')) { + $options = new Services\Options(); + + if ($options->get_option('helpful_widget')) { return; } diff --git a/core/services/class-csv.php b/core/services/class-csv.php index 95553dd..08903aa 100644 --- a/core/services/class-csv.php +++ b/core/services/class-csv.php @@ -9,6 +9,7 @@ use Helpful\Core\Helper; use Helpful\Core\Helpers as Helpers; +use Helpful\Core\Services as Services; /* Prevent direct access */ if (!defined('ABSPATH')) { @@ -66,6 +67,8 @@ public function create_file() return new \WP_Error(__('No csv items found.', 'csv error', 'helpful')); } + $options = new Services\Options(); + $items = $this->items; $lines = []; @@ -93,7 +96,7 @@ public function create_file() $separators = [ ';', ',' ]; $separators = apply_filters( 'helpful_export_separators', $separators ); - $option = get_option( 'helpful_export_separator' ); + $option = $options->get_option( 'helpful_export_separator' ); if ( $option && in_array( $option, $separators ) ) { $separator = esc_html( $option ); diff --git a/core/services/class-helpful.php b/core/services/class-helpful.php index c53395b..1a2c7d6 100644 --- a/core/services/class-helpful.php +++ b/core/services/class-helpful.php @@ -111,6 +111,7 @@ public function get_template() } $helpful['instance'] = $this->get_id(); + $helpful['shortcode_class'] = $this->get_css_classes(); ob_start(); do_action('helpful_before'); @@ -141,4 +142,27 @@ public function current_user_has_voted() return false; } + + /** + * @return array + */ + public function get_css_classes() + { + $helpful = $this->get_atts(); + $classes = []; + + if (isset($helpful['shortcode_class'])) { + if (is_array($helpful['shortcode_class'])) { + $classes = $helpful['shortcode_class']; + } else { + $classes[] = $helpful['shortcode_class']; + } + } + + if ($this->current_user_has_voted()) { + $classes[] = 'voted'; + } + + return implode(' ', $classes); + } } diff --git a/core/services/class-options.php b/core/services/class-options.php index 40cc9be..b6f1af4 100644 --- a/core/services/class-options.php +++ b/core/services/class-options.php @@ -82,7 +82,11 @@ public function get_option($name, $default = false) { } if (isset($this->options[$name])) { - return $this->options[$name]; + return apply_filters('helpful/get_option/' . $name, $this->options[$name]); + } + + if (get_option($name)) { + return apply_filters('helpful/get_option/' . $name, get_option($name)); } return $default; @@ -93,6 +97,6 @@ public function get_option($name, $default = false) { */ public function get_options() { - return $this->options; + return apply_filters('helpful/get_options', $this->options); } } \ No newline at end of file diff --git a/core/services/class-session.php b/core/services/class-session.php index ad05022..20e3709 100644 --- a/core/services/class-session.php +++ b/core/services/class-session.php @@ -61,6 +61,8 @@ public function should_start_session() { $start_session = true; + $options = new Options(); + if (!empty($_SERVER['REQUEST_URI'])) { $uri = ltrim($_SERVER['REQUEST_URI'], '/'); $uri = untrailingslashit($uri); @@ -78,7 +80,7 @@ public function should_start_session() } } - if (get_option('helpful_sessions_false')) { + if ($options->get_option('helpful_sessions_false')) { $start_session = false; } diff --git a/core/tabs/class-design.php b/core/tabs/class-design.php index c03559b..5803b44 100644 --- a/core/tabs/class-design.php +++ b/core/tabs/class-design.php @@ -10,6 +10,7 @@ use Helpful\Core\Helper; use Helpful\Core\Helpers as Helpers; use Helpful\Core\Vendor as Vendor; +use Helpful\Core\Services as Services; /* Prevent direct access */ if (!defined('ABSPATH')) { @@ -77,7 +78,9 @@ public function register_tab($tabs, $current) */ public function custom_css() { - $custom_css = get_option('helpful_css'); + $options = new Services\Options(); + + $custom_css = $options->get_option('helpful_css'); $parser = new Vendor\Css_Parser(); diff --git a/core/tabs/class-start.php b/core/tabs/class-start.php index d2ed4d9..777a64f 100644 --- a/core/tabs/class-start.php +++ b/core/tabs/class-start.php @@ -9,6 +9,7 @@ use Helpful\Core\Helper; use Helpful\Core\Helpers as Helpers; +use Helpful\Core\Services as Services; /* Prevent direct access */ if (!defined('ABSPATH')) { @@ -158,6 +159,8 @@ public function ajax_get_posts_data() Helpers\Values::sync_post_meta(); + $options = new Services\Options(); + $post_types = 'any'; $response = [ @@ -189,7 +192,7 @@ public function ajax_get_posts_data() if (false === ($query = get_transient($transient))) { $query = new \WP_Query($args); - $cache_time = get_option('helpful_cache_time', 'minute'); + $cache_time = $options->get_option('helpful_cache_time', 'minute'); $cache_times = Helpers\Cache::get_cache_times(false); $cache_time = $cache_times[$cache_time]; diff --git a/core/tabs/class-system.php b/core/tabs/class-system.php index f07b203..ac7aba8 100644 --- a/core/tabs/class-system.php +++ b/core/tabs/class-system.php @@ -9,6 +9,7 @@ use Helpful\Core\Helper; use Helpful\Core\Helpers as Helpers; +use Helpful\Core\Services as Services; /* Prevent direct access */ if (!defined('ABSPATH')) { @@ -44,6 +45,8 @@ public static function get_instance() */ public function __construct() { + $options = new Services\Options(); + add_action('admin_init', [ & $this, 'register_settings']); add_filter('helpful_get_admin_tabs', [ & $this, 'register_tab'], 10, 2); @@ -52,7 +55,7 @@ public function __construct() add_action('admin_init', [ & $this, 'reset_plugin']); add_action('admin_init', [ & $this, 'reset_feedback']); - if (get_option('helpful_classic_editor')) { + if ($options->get_option('helpful_classic_editor')) { add_filter('use_block_editor_for_post', '__return_false', 10); } diff --git a/helpful.php b/helpful.php index fd8798c..d9b2583 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.53 + * Version: 4.4.54 * Author: Pixelbart * Author URI: https://pixelbart.de * Text Domain: helpful diff --git a/readme.txt b/readme.txt index 38e8ffa..75d5620 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.8 Requires PHP: 5.6.20 -Stable tag: 4.4.53 +Stable tag: 4.4.54 License: MIT License License URI: https://opensource.org/licenses/MIT diff --git a/templates/feedback.php b/templates/feedback.php index 9ff8264..4267757 100644 --- a/templates/feedback.php +++ b/templates/feedback.php @@ -6,6 +6,9 @@ */ use Helpful\Core\Helper; use Helpful\Core\Helpers as Helpers; +use Helpful\Core\Services as Services; + +$options = new Services\Options(); /* Prevent direct access */ if (!defined('ABSPATH')) { @@ -20,16 +23,16 @@