From e58850d674410186fe0c80a4f98bb67b0134b20c Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Wed, 18 Dec 2024 13:44:24 +0530 Subject: [PATCH] global settings tab to modify theme default settings --- css/qsm-admin.css | 3 + js/qsm-admin.js | 34 ++++++----- php/admin/functions.php | 124 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 141 insertions(+), 20 deletions(-) diff --git a/css/qsm-admin.css b/css/qsm-admin.css index b2857b7a..c96cf4a7 100644 --- a/css/qsm-admin.css +++ b/css/qsm-admin.css @@ -4037,4 +4037,7 @@ span.qsm-insert-template-variable-text { border-color: #ccc; padding-top: 2px; padding-bottom: 2px; +} +.qsm-global-settings-theme-browser { + padding: 20px 5px; } \ No newline at end of file diff --git a/js/qsm-admin.js b/js/qsm-admin.js index a6a64a5c..488d9339 100644 --- a/js/qsm-admin.js +++ b/js/qsm-admin.js @@ -835,25 +835,29 @@ if(current_id == 'qsm_variable_text'){ jQuery(".current_variable")[0].click();} }); }) }); + } +} - jQuery(document).ready(function () { - jQuery(document).on('click', '.qsm-customize-color-settings', function (e) { - e.preventDefault(); - MicroModal.show('qsm-theme-color-settings'); - if (jQuery('.qsm-color-field').length > 0) { - jQuery('.qsm-color-field').wpColorPicker(); - jQuery('.qsm-color-field').each(function () { - if (jQuery(this).attr('data-label')) { - jQuery(this).parents('.wp-picker-container').find('.wp-color-result-text').html( jQuery(this).attr('data-label') ); - } - }); - +jQuery(document).ready(function () { + jQuery(document).on('click', '.qsm-customize-color-settings', function (e) { + e.preventDefault(); + let modalId = jQuery(this).data('modal-id'); + if ( modalId == undefined ) { + MicroModal.show('qsm-theme-color-settings'); + } else { + MicroModal.show('qsm-theme-color-settings-' + modalId); + } + if (jQuery('.qsm-color-field').length > 0) { + jQuery('.qsm-color-field').wpColorPicker(); + jQuery('.qsm-color-field').each(function () { + if (jQuery(this).attr('data-label')) { + jQuery(this).parents('.wp-picker-container').find('.wp-color-result-text').html( jQuery(this).attr('data-label') ); } }); - }); - } -} + } + }); +}); //QSM - Quizzes/Surveys Page diff --git a/php/admin/functions.php b/php/admin/functions.php index 778445bd..15a5df6f 100644 --- a/php/admin/functions.php +++ b/php/admin/functions.php @@ -1135,7 +1135,7 @@ function qsm_fetch_theme_data() { $themes_data = qsm_get_widget_data( 'themes' ); } -function qsm_get_installed_theme( $saved_quiz_theme, $wizard_theme_list = '' ) { +function qsm_get_installed_theme( $saved_quiz_theme, $wizard_theme_list = '', $caller = '' ) { global $mlwQuizMasterNext; global $pro_themes; $active_themes = $mlwQuizMasterNext->theme_settings->get_active_themes(); @@ -1148,6 +1148,7 @@ function qsm_get_installed_theme( $saved_quiz_theme, $wizard_theme_list = '' ) { } } } + if ( 'qsm_theme_defaults' !== $caller ) { ?>
> @@ -1166,12 +1167,16 @@ function qsm_get_installed_theme( $saved_quiz_theme, $wizard_theme_list = '' ) {
- + $theme ) { $theme_name = $theme['theme']; $theme_id = $theme['id']; + $default_themes = array( 'Fortune', 'Sigma', 'Pixel', 'Sapience', 'Breeze', 'Fragrance', 'Pool', 'Ivory' ); + if ( 'qsm_theme_defaults' === $caller && ! in_array( $theme['theme_name'], $default_themes, true ) ) { + continue; + } ?>
> @@ -1187,8 +1192,12 @@ function qsm_get_installed_theme( $saved_quiz_theme, $wizard_theme_list = '' ) {
' . esc_html__( 'Customize', 'quiz-master-next' ) .' '; + if ( $saved_quiz_theme === $theme_id || 'qsm_theme_defaults' === $caller ) { + if ( 'qsm_theme_defaults' === $caller ) { + $button = '' . esc_html__( 'Customize', 'quiz-master-next' ) .' '; + } else { + $button = '' . esc_html__( 'Customize', 'quiz-master-next' ) .' '; + } }elseif ( 'wizard_theme_list' !== $wizard_theme_list ) { $button = ''; } @@ -1714,4 +1723,109 @@ function qsm_advanced_assessment_quiz_page_content() { "addon_link" => qsm_get_plugin_link( 'downloads/advanced-assessment', 'quiz-documentation', 'plugin', 'advanced-assessment', 'qsm_plugin_upsell' ), ); qsm_admin_upgrade_content( $args, 'page' ); -} \ No newline at end of file +} + +function qsm_create_theme_defaults_tab() { + global $mlwQuizMasterNext, $wpdb; + $themes = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}mlw_themes", ARRAY_A ); + if ( empty( $themes ) ) { + return; + } + ?> + + update( + $wpdb->prefix . 'mlw_themes', + array( + 'default_settings' => serialize( $settings_array ), + ), + array( + 'id' => $theme_id, + ), + array('%s'), + array('%d') + ); + $mlwQuizMasterNext->alertManager->newAlert( + __( 'The theme default settings saved successfully.', 'quiz-master-next' ), + 'success' + ); + $mlwQuizMasterNext->audit_manager->new_audit( "Default theme settings have been saved", '', '' ); + } + + if ( ! empty( $_GET['tab'] ) && 'qsm-theme-defaults' === $_GET['tab'] ) { + $themes = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}mlw_themes", ARRAY_A ); + ?> +
+
+ +
+
+ + + +