diff --git a/php/admin/settings-page.php b/php/admin/settings-page.php index 884b32cb0..3cd1e4058 100644 --- a/php/admin/settings-page.php +++ b/php/admin/settings-page.php @@ -76,6 +76,7 @@ public function init() { 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', __( 'Quiz Archive Settings', 'quiz-master-next' ), array( $this, 'cpt_archive_field' ), 'qmn_global_settings', 'qmn-global-section' ); + add_settings_field( 'duplicate-quiz-with-theme', __( 'Duplicate Quiz Controls', 'quiz-master-next' ), array( $this, 'qsm_duplicate_quiz_with_theme' ), 'qmn_global_settings', 'qmn-global-section' ); add_settings_field( 'detele-qsm-data', __( 'Delete all the data related to QSM on deletion?', 'quiz-master-next' ), array( $this, 'qsm_delete_data' ), 'qmn_global_settings', 'qmn-global-section' ); add_settings_field( 'background-quiz-email-process', __( 'Process emails in background?', 'quiz-master-next' ), array( $this, 'qsm_background_quiz_email_process' ), 'qmn_global_settings', 'qmn-global-section' ); add_settings_field( 'cpt-slug', __( 'Quiz Url Slug', 'quiz-master-next' ), array( $this, 'cpt_slug_field' ), 'qmn_global_settings', 'qmn-global-section' ); @@ -368,6 +369,25 @@ public function cpt_search_field() { echo ''; } + /** + * Generates Setting Field To Duplicate Quiz with Theme Settings + * + * @since 8.1.19 + * @return void + */ + public function qsm_duplicate_quiz_with_theme() { + $settings = (array) get_option( 'qmn-settings' ); + $duplicate_quiz_with_theme = ! empty( $settings['duplicate_quiz_with_theme'] ) ? esc_attr( $settings['duplicate_quiz_with_theme'] ) : 0; + ?> +
+ insert_id; + $settings = (array) get_option('qmn-settings'); + $duplicate_quiz_with_theme = !empty($settings['duplicate_quiz_with_theme']) ? esc_attr($settings['duplicate_quiz_with_theme']) : 0; + + if ('1' === $duplicate_quiz_with_theme) { + $theme_table = $wpdb->prefix . 'mlw_quiz_theme_settings'; + $old_quiz_theme_data = $wpdb->get_row($wpdb->prepare("SELECT * FROM $theme_table WHERE quiz_id = %d AND active_theme = 1", $quiz_id)); + + if ($old_quiz_theme_data) { + $new_quiz_theme_data = array( + 'theme_id' => $old_quiz_theme_data->theme_id, + 'quiz_id' => $mlw_new_id, + 'quiz_theme_settings' => $old_quiz_theme_data->quiz_theme_settings, + 'active_theme' => 1, + ); + + $format = array( + '%d', + '%d', + '%s', + '%d', + ); + + $wpdb->insert($theme_table, $new_quiz_theme_data, $format); + $mlwQuizMasterNext->alertManager->newAlert(__('There has been an error in this action. Please share this with the developer. Error Code: 0051', 'quiz-master-next'), 'error'); + $mlwQuizMasterNext->log_manager->add('Error 0051', $wpdb->last_error . ' from ' . $wpdb->last_query, 0, 'error'); + } + } + // Update quiz settings $update_quiz_settings = maybe_unserialize( $mlw_qmn_duplicate_data->quiz_settings ); $update_pages = maybe_unserialize( $update_quiz_settings['pages'] );