Skip to content

Commit

Permalink
Added Feature to duplicate quiz with active paid theme
Browse files Browse the repository at this point in the history
  • Loading branch information
iam-pranav committed Nov 27, 2023
1 parent 10751d2 commit 5cb043b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
20 changes: 20 additions & 0 deletions php/admin/settings-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down Expand Up @@ -368,6 +369,25 @@ public function cpt_search_field() {
echo '<span class="slider round"></span></label>';
}

/**
* 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;
?>
<fieldset>
<label for="qmn-settings-duplicate_quiz_with_theme">
<input type="checkbox" name="qmn-settings[duplicate_quiz_with_theme]" id="qmn-settings-duplicate_quiz_with_theme" value="1" <?php checked( $duplicate_quiz_with_theme, 1, true ); ?> />
<?php esc_html_e( 'Enable quiz duplication along with theme settings', 'quiz-master-next'); ?>
</label>
</fieldset>
<?php
}

/**
* Generates Setting Field For Post Archive
*
Expand Down
28 changes: 28 additions & 0 deletions php/classes/class-qmn-quiz-creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,34 @@ public function duplicate_quiz( $quiz_id, $quiz_name, $is_duplicating_questions
);
$mlw_new_id = $wpdb->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'] );
Expand Down

0 comments on commit 5cb043b

Please sign in to comment.