From 9dc55c820f2f3e7aee591e1569a7b7e06b687b49 Mon Sep 17 00:00:00 2001 From: Mohammad Zubair Ali Date: Wed, 14 Jun 2023 02:29:53 +0530 Subject: [PATCH 01/15] added option to enable and disable console log --- php/admin/settings-page.php | 18 ++++++++++++++++++ php/classes/class-qmn-background-process.php | 3 ++- php/classes/class-qmn-log-manager.php | 9 ++++++--- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/php/admin/settings-page.php b/php/admin/settings-page.php index d604fbdc2..dc30b6fb8 100644 --- a/php/admin/settings-page.php +++ b/php/admin/settings-page.php @@ -72,6 +72,7 @@ public function init() { register_setting( 'qmn-settings-group', 'qmn-settings' ); add_settings_section( 'qmn-global-section', __( 'Main Settings', 'quiz-master-next' ), array( $this, 'global_section' ), 'qmn_global_settings' ); add_settings_field( 'usage-tracker', __( 'Allow Usage Tracking?', 'quiz-master-next' ), array( $this, 'usage_tracker_field' ), 'qmn_global_settings', 'qmn-global-section' ); + add_settings_field( 'enable-qsm-log', __( 'Enable QSM log', 'quiz-master-next' ), array( $this, 'enable_qsm_log' ), 'qmn_global_settings', 'qmn-global-section' ); add_settings_field( 'ip-collection', __( 'Disable collecting and storing IP addresses?', 'quiz-master-next' ), array( $this, 'ip_collection_field' ), 'qmn_global_settings', 'qmn-global-section' ); add_settings_field( 'cpt-search', __( 'Disable Quiz Posts From Being Searched?', 'quiz-master-next' ), array( $this, 'cpt_search_field' ), 'qmn_global_settings', 'qmn-global-section' ); add_settings_field( 'cpt-archive', __( 'Disable Quiz Archive?', 'quiz-master-next' ), array( $this, 'cpt_archive_field' ), 'qmn_global_settings', 'qmn-global-section' ); @@ -485,6 +486,23 @@ public function usage_tracker_field() { echo "" . esc_html__( "Allow Quiz And Survey Master to anonymously track this plugin's usage and help us make this plugin better.", 'quiz-master-next' ) . ''; } + /** + * Generates Setting Field For QSM logs + * + * @since 8.1.9 + * @return void + */ + public function enable_qsm_log() { + $settings = (array) get_option( 'qmn-settings' ); + $enable_qsm_log = ! empty( $settings['enable_qsm_log'] ) ? esc_attr( $settings['enable_qsm_log'] ) : 0; + ?> + + + really_long_running_task(); QSM_Emails::send_emails( $transient_id ); } catch ( Exception $e ) { - if ( defined('WP_DEBUG') && WP_DEBUG ) { + $settings = (array) get_option( 'qmn-settings' ); + if ( ! empty( $settings['enable_qsm_log'] ) && $settings['enable_qsm_log'] ) { trigger_error('Background email triggered fatal error for callback.', E_USER_WARNING); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error } } diff --git a/php/classes/class-qmn-log-manager.php b/php/classes/class-qmn-log-manager.php index 9e60cc84d..0164bcfe9 100644 --- a/php/classes/class-qmn-log-manager.php +++ b/php/classes/class-qmn-log-manager.php @@ -41,9 +41,10 @@ private function log_types() { */ public function register_post_type() { /* logs post type */ + $settings = (array) get_option( 'qmn-settings' ); $log_args = array( 'labels' => array( 'name' => 'QSM Logs' ), - 'public' => defined( 'WP_DEBUG' ) && WP_DEBUG, + 'public' => ! empty( $settings['enable_qsm_log'] ) && $settings['enable_qsm_log'], 'query_var' => false, 'rewrite' => false, 'capability_type' => 'post', @@ -61,7 +62,8 @@ public function register_post_type() { * @since 4.5.0 */ public function register_taxonomy() { - register_taxonomy( 'qmn_log_type', 'qmn_log', array( 'public' => defined( 'WP_DEBUG' ) && WP_DEBUG ) ); + $settings = (array) get_option( 'qmn-settings' ); + register_taxonomy( 'qmn_log_type', 'qmn_log', array( 'public' => ! empty( $settings['enable_qsm_log'] ) && $settings['enable_qsm_log'] ) ); $types = $this->log_types(); foreach ( $types as $type ) { if ( ! term_exists( $type, 'qmn_log_type' ) ) { @@ -99,7 +101,8 @@ public function add( $title = '', $message = '', $parent = 0, $type = null ) { 'post_parent' => $parent, 'log_type' => $type, ); - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { + $settings = (array) get_option( 'qmn-settings' ); + if ( ! empty( $settings['enable_qsm_log'] ) && $settings['enable_qsm_log'] ) { return $this->insert_log( $log_data ); } return false; From 214e23ecc4468647721ab6269b51255b9b4278ac Mon Sep 17 00:00:00 2001 From: Mohammad Zubair Ali Date: Thu, 15 Jun 2023 13:10:33 +0530 Subject: [PATCH 02/15] add action hook --- php/admin/functions.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/php/admin/functions.php b/php/admin/functions.php index d42b81874..18d95720a 100644 --- a/php/admin/functions.php +++ b/php/admin/functions.php @@ -1017,17 +1017,15 @@ function qsm_get_installed_theme( $saved_quiz_theme, $wizard_theme_list = '' ) {

- - - - - - + $button = ""; + if ( $saved_quiz_theme === $theme_id ) { + $button = '' . esc_html__( 'Customize', 'quiz-master-next' ) .' '; + }elseif ( 'wizard_theme_list' !== $wizard_theme_list ) { + $button = ''; + } + $button = apply_filters( 'qsm_themes_action_button', $button, $theme, $active_themes ); + echo wp_kses_post($button); + ?>
@@ -1297,7 +1295,7 @@ function qsm_quiz_theme_settings( $type, $label, $name, $value, $default_value, 'name' => "settings[". $name ."]", 'value' => $value, ); - qsm_get_input_label_selected( $param ); + qsm_get_input_label_selected( $param ); break; default: ?> From d90b75b90f801a6392812a51f519f1118c240bfa Mon Sep 17 00:00:00 2001 From: Mohammad Zubair Ali Date: Thu, 15 Jun 2023 15:08:51 +0530 Subject: [PATCH 03/15] add hook in theme list --- php/classes/class-qsm-theme-settings.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/php/classes/class-qsm-theme-settings.php b/php/classes/class-qsm-theme-settings.php index cd031f127..58071a067 100644 --- a/php/classes/class-qsm-theme-settings.php +++ b/php/classes/class-qsm-theme-settings.php @@ -225,18 +225,17 @@ public function get_active_quiz_theme_path( $quiz_id ) { $query = $wpdb->prepare( "SELECT a.theme FROM {$wpdb->prefix}$this->themes_table AS a, {$wpdb->prefix}$this->settings_table AS b WHERE b.quiz_id = %d AND b.active_theme = 1 AND b.theme_id = a.id", $quiz_id ); $result = $wpdb->get_var( $query ); $active_themes = $mlwQuizMasterNext->theme_settings->get_active_themes(); + $theme_path = 'default'; $themes = array(); if ( ! empty( $active_themes ) ) { foreach ( $active_themes as $dir ) { $themes[] = $dir['theme']; } } - if ( empty($result) || ! in_array($result, $themes, true) ) { - return 'default'; - } - else { - return $result; + if ( !empty($result) && in_array($result, $themes, true) ) { + $theme_path = $result; } + return apply_filters( 'get_active_quiz_theme_path', $theme_path, $quiz_id, $active_themes ); } /** From 5c6f97f8498a237885fd57d16878d145542521d6 Mon Sep 17 00:00:00 2001 From: Mohammad Zubair Ali Date: Thu, 15 Jun 2023 23:20:50 +0530 Subject: [PATCH 04/15] git commit fix issue with next button while using comment box --- php/classes/class-qmn-quiz-manager.php | 6 +++--- php/classes/class-qsm-theme-settings.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/php/classes/class-qmn-quiz-manager.php b/php/classes/class-qmn-quiz-manager.php index 06dd15b6b..3bceaba53 100644 --- a/php/classes/class-qmn-quiz-manager.php +++ b/php/classes/class-qmn-quiz-manager.php @@ -510,7 +510,7 @@ public function display_shortcode( $atts ) { } elseif ( isset( $_POST['complete_quiz'], $_POST['qmn_quiz_id'] ) && 'confirmation' == sanitize_text_field( wp_unslash( $_POST['complete_quiz'] ) ) && sanitize_text_field( wp_unslash( $_POST['qmn_quiz_id'] ) ) == $qmn_array_for_variables['quiz_id'] ) { $return_display .= $this->display_results( $qmn_quiz_options, $qmn_array_for_variables ); } - + $qmn_filtered_json = apply_filters( 'qmn_json_data', $qmn_json_data, $qmn_quiz_options, $qmn_array_for_variables, $shortcode_args ); $return_display .= '