Skip to content

Commit

Permalink
Optimize delete options (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records authored Oct 27, 2023
1 parent 8bcb7b1 commit 6cdc43e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
26 changes: 5 additions & 21 deletions sync-qcloud-cos.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function cos_set_options()
'secret_key' => '',
'nothumb' => 'false', // 是否上传缩略图
'nolocalsaving' => 'false', // 是否保留本地备份
'delete_options' => 'false',
'delete_options' => 'true',
'upload_url_path' => '', // URL前缀
'update_file_name' => 'false', // 是否重命名文件名
'ci_style' => '',
Expand All @@ -61,23 +61,6 @@ function cos_set_options()
add_option('cos_options', $options, '', 'yes');
}

// stop plugin
function cos_stop_option()
{
$option = get_option('cos_options');
if (esc_attr($option['delete_options']) == 'true') {
$upload_url_path = cos_get_option('upload_url_path');
$cos_upload_url_path = esc_attr($option['upload_url_path']);

if ($upload_url_path == $cos_upload_url_path) {
update_option('upload_url_path', '');
}
delete_option('cos_options');
}
}

register_deactivation_hook(__FILE__, 'cos_stop_option');

/**
* @param array $cos_options
* @return Client
Expand Down Expand Up @@ -949,7 +932,7 @@ function cos_ci_text_page($options)
<input type="checkbox" name="skip_comment_validation_on_login" {$checked_skip_comment_validation_on_login} />
<span class="slider round"></span>
</label>
<p>勾选后如果是登录态则会跳过该用户评论内容,不去验证。</p>
<p>启用后如果是登录态则会跳过该用户评论内容,不去验证。</p>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -1451,15 +1434,16 @@ function cos_setting_page()
</tr>
<tr>
<th>
<legend>是否删除配置信息</legend>
<legend>删除配置信息</legend>
</th>
<td>
<label class="switch">
<input type="checkbox" name="delete_options" <?php echo $check_delete_options; ?> />
<span class="slider round"></span>
</label>

<p>建议不勾选。勾选后禁用插件时会删除保存的配置信息和恢复默认URL前缀。不勾选卸载插件时也会进行删除和恢复。</p>
<p>默认启用,删除插件时会删除当前配置信息。</p>
<p>如果不启用,删除插件时只会重置URL前缀为空,保留当前配置信息。</p>
</td>
</tr>
<tr>
Expand Down
5 changes: 4 additions & 1 deletion uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
update_option('upload_url_path', '');
}

delete_option('cos_options');
$cos_delete_options = esc_attr($cos_options['delete_options']);
if ($cos_delete_options == 'true') {
delete_option('cos_options');
}

0 comments on commit 6cdc43e

Please sign in to comment.