Skip to content

Commit

Permalink
1.6.1版本,优化插件激活和卸载
Browse files Browse the repository at this point in the history
  • Loading branch information
webersongao committed Mar 12, 2024
1 parent b5d7424 commit 65207ab
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 39 deletions.
1 change: 0 additions & 1 deletion microblog/includes/microblog-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ function microblog_post_title_listdate_input() {
<?php
}


function microblog_post_rss_feed_input() {
$options = get_option('microblog_setting_data');
$value = isset($options['mb_rss_feed']) ? $options['mb_rss_feed'] : false;
Expand Down
30 changes: 0 additions & 30 deletions microblog/includes/microblog-index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

require_once(plugin_dir_path(__FILE__) . 'micropost-functions.php');


add_action('init', 'create_micropost_type');
function create_micropost_type() {
$options = get_option('microblog_setting_data');
Expand Down Expand Up @@ -51,35 +50,6 @@ function customize_main_query($query) {
}
}

// 注册激活插件时,设置默认数据
register_activation_hook( __FILE__, 'microblog_plugin_data_activation' );
function microblog_plugin_data_activation() {
$options = get_option('microblog_setting_data');
if (empty($options)) {
$defaults = array(
'mb_title_show' => true,
'mb_date_format' => 'date_format_vague',
'mb_title_position' => array('titlebottom'),
);
add_option('microblog_setting_data', $defaults);
}
microblog_rewrite_flush();
}

function microblog_rewrite_flush() {
create_micropost_type();
flush_rewrite_rules();
}

// 注册卸载插件时运行的函数
register_uninstall_hook( __FILE__, 'microblog_plugin_uninstall' );
function microblog_plugin_uninstall() {
// 删除选项
delete_option('microblog_setting_data');
delete_option('widget_microblog_widget');
// 还可以执行其他清理操作,如删除数据库条目等
}

// Add rewrite rule for microblog permalink structure
add_action('init', 'custom_microblog_rewrite_rule');
function custom_microblog_rewrite_rule() {
Expand Down
1 change: 1 addition & 0 deletions microblog/includes/micropost-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function register_micropost_type($supports) {
// 'taxonomies' => array ( 'category', 'post_tag' ),
);
register_post_type('micropost', $args);
flush_rewrite_rules();
}

// 更新全局变量的示例
Expand Down
26 changes: 24 additions & 2 deletions microblog/microblog.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: 微博 MicroBlog
* Plugin URI: https://www.webersongao.com/tag/microblog
* Description: Use your WordPress site as a microblog; display the micrposts in a widget or using a shortcode.
* Version: 1.6
* Version: 1.6.1
* Author: WebersonGao
* Author URI: https://www.webersongao.com
* Based on simple-microblogging plugin developed by original Samuel Coskey, Victoria Gitman(http://boolesrings.org),obaby(https://h4ck.org.cn/) Thanks to ChatGPT.
Expand All @@ -14,7 +14,7 @@
define('MICROBLOG_PLUGIN_URL', plugin_dir_url(__FILE__));

$plugin_data = get_file_data(__FILE__, array('Version' => 'Version'));
$plugin_version = ($plugin_data && isset($plugin_data['Version'])) ? $plugin_data['Version'] : '1.6';
$plugin_version = ($plugin_data && isset($plugin_data['Version'])) ? $plugin_data['Version'] : '1.6.1';
global $plugin_version;

// 加载其他功能模块文件
Expand Down Expand Up @@ -44,4 +44,26 @@ function microblog_setting_action_links($links, $file) {
return $links;
}

// 注册激活插件时,设置默认数据
register_activation_hook( __FILE__, 'microblog_plugin_data_activation' );
function microblog_plugin_data_activation() {
$options = get_option('microblog_setting_data');
if (empty($options)) {
$defaults = array(
'mb_title_show' => true,
'mb_date_format' => 'date_format_vague',
'mb_title_position' => array('titlebottom'),
);
add_option('microblog_setting_data', $defaults);
}
}
// 注册卸载插件时运行的函数
register_uninstall_hook( __FILE__, 'microblog_plugin_uninstall' );
function microblog_plugin_uninstall() {
// 删除选项
delete_option('microblog_setting_data');
delete_option('widget_microblog_widget');
// 还可以执行其他清理操作,如删除数据库条目等
}

?>
12 changes: 9 additions & 3 deletions microblog/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Donate link: https://www.webersongao.com/ https://boolesrings.org
Tags: tweet, tweets, microblog, microblog, micropost
Requires at least: 6.0
Tested up to: 6.4.3
Stable tag: 1.6
Stable tag: 1.6.1
License: GPLv2 or later

Add a microblog to your site; display the microposts in a widget or using a shortcode.
Expand All @@ -24,8 +24,6 @@ The `[microblog]` shortcode supports several options:

* **null_text**: If no results are returned, shows this text. Defaults to `(none)`.

* **date_format**: If showing the date, this php date format will be used. The default is the Date Format value from the General Settings page. I recommend `"F j"`, which displays as "May 12".

* **use_excerpt**: If defined, use the post excerpt instead of the entire contents. We recommend writing short microposts, but if you prefer to write longer ones, this can be used to truncate them. Unfortunately, Wordpress excerpts don't allow links or other html, use the plugin [Advanced Excerpt](http://wordpress.org/extend/plugins/advanced-excerpt/) to remedy this!

* **q**: Arbitrary &-separated arguments to add to the query. See the [WP_Query](http://codex.wordpress.org/Class_Reference/WP_Query/#Parameters) page for available syntax. For example, to show only posts from author `jack` in ascending instead of descending order, you would write `[microblog q="author_name=jack&order=ASC"]`.
Expand Down Expand Up @@ -57,6 +55,14 @@ If you are having trouble viewing your microposts, try visiting your permalinks

== Changelog ==

1.6.1
Added: Time format and option to enable global feed subscription.
Optimized: Default configuration written upon plugin activation, all configuration items cleaned up upon plugin uninstallation, leaving no junk behind.

1.6
Added: Dashboard quick publishing feature.
Optimized: Changed the "Write a post" button text to "Post a microblog" and similar.

1.5
Optimization: Optimized code structure to improve query performance and reduce URL refresh.

Expand Down
8 changes: 5 additions & 3 deletions microblog/readme_zh.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Donate link: https://www.webersongao.com/ https://boolesrings.org
Tags: tweet, tweets, microblog, microblog, micropost
Requires at least: 6.0
Tested up to: 6.4.3
Stable tag: 1.6
Stable tag: 1.6.1
License: GPLv2 or later

== 核心 ==
Expand All @@ -25,8 +25,6 @@ License: GPLv2 or later

* **null_text**:如果未返回结果,则显示此文本。 默认为`(none)`。

* **date_format**:如果显示日期,则将使用此php日期格式。 默认是来自常规设置页面的日期格式值。 我建议使用`"F j"`,它显示为"May 12"。

* **use_excerpt**:如果定义,则使用帖子摘录而不是整个内容。 我们建议撰写简短的微博,但如果您更喜欢撰写较长的微博,则可以使用此选项将其截断。 不幸的是,Wordpress摘录不允许链接或其他html,请使用插件[高级摘录](http://wordpress.org/extend/plugins/advanced-excerpt/)来解决此问题!

* **q**:要添加到查询中的任意&分隔参数。 有关可用语法,请参阅[WP_Query](http://codex.wordpress.org/Class_Reference/WP_Query/#Parameters)页面。 例如,要仅按升序显示来自作者`jack`的帖子,您将写入`[microblog q="author_name=jack&order=ASC"]`。
Expand Down Expand Up @@ -57,6 +55,10 @@ License: GPLv2 or later

== 更新日志 ==

1.6.1
新增:时间格式 及 是否开启全站Feed订阅
优化:插件激活写入默认配置,插件卸载清理所有配置项,不留垃圾,不拉屎~

1.6
新增:新增仪表盘快捷发布
优化:按钮 写文章,改为 发微博等文案
Expand Down

0 comments on commit 65207ab

Please sign in to comment.