// ================== 系统通知后台管理页(v2.5.1) ================== function wmp_subscribe_render_notices_page() { if (!current_user_can('manage_options')) { return; } global $wpdb; jifen_ensure_notices_table(); $table = jifen_notices_table(); $notice_msg = ''; // 保存(新增/更新) if (isset($_POST['wmp_notice_save']) && (int) $_POST['wmp_notice_save'] === 1) { check_admin_referer('wmp_notice_action'); $id = absint(isset($_POST['nid']) ? $_POST['nid'] : 0); $title = sanitize_text_field(isset($_POST['ntitle']) ? $_POST['ntitle'] : ''); $content = wp_kses_post(isset($_POST['ncontent']) ? $_POST['ncontent'] : ''); $status = (isset($_POST['nstatus']) && (int) $_POST['nstatus'] === 1) ? 1 : 0; if ($title === '' || $content === '') { $notice_msg = '

标题和内容不能为空

'; } elseif ($id > 0) { $wpdb->update($table, array('title' => $title, 'content' => $content, 'status' => $status), array('id' => $id)); $notice_msg = '

通知已更新

'; } else { $wpdb->insert($table, array('title' => $title, 'content' => $content, 'status' => $status, 'created_at' => current_time('mysql'))); $notice_msg = '

通知已发布

'; } } // 删除 if (isset($_GET['del']) && (int) $_GET['del'] > 0) { check_admin_referer('wmp_notice_del'); $wpdb->delete($table, array('id' => absint($_GET['del']))); $notice_msg = '

通知已删除

'; } $edit = null; if (isset($_GET['edit']) && (int) $_GET['edit'] > 0) { $edit = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table WHERE id=%d", absint($_GET['edit']))); } $list = $wpdb->get_results("SELECT * FROM $table ORDER BY id DESC LIMIT 200"); echo '

系统通知

'; echo '

发布后,小程序端“个人中心 → 系统通知”即可看到启用的通知。可用来发布公告、活动、折扣码等信息。

'; if ($notice_msg) { echo $notice_msg; } echo '

' . ($edit ? '编辑通知' : '发布新通知') . '

'; echo '
'; wp_nonce_field('wmp_notice_action'); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
标题
内容

支持简单 HTML

状态
'; submit_button($edit ? '保存修改' : '发布通知'); echo '
'; echo '

通知列表

'; if ($list) { echo ''; foreach ($list as $n) { echo ''; } echo '
ID标题状态发布时间操作
' . (int) $n->id . '' . esc_html($n->title) . '' . ((int) $n->status === 1 ? '启用' : '停用') . '' . esc_html($n->created_at) . '编辑 | 删除
'; } else { echo '

暂无通知。

'; } echo '
'; } /** GET /wp-json/wmp-subscribe/v1/notices —— 小程序端获取启用的系统通知 */ function wmp_subscribe_get_notices($request) { global $wpdb; jifen_ensure_notices_table(); $table = jifen_notices_table(); $rows = $wpdb->get_results("SELECT id, title, content, created_at FROM $table WHERE status=1 ORDER BY id DESC LIMIT 50"); $list = array(); foreach ((array) $rows as $r) { $list[] = array( 'id' => (int) $r->id, 'title' => $r->title, 'content' => $r->content, 'created_at' => $r->created_at, ); } return rest_ensure_response(array('code' => 200, 'list' => $list)); }
Warning: Cannot modify header information - headers already sent by (output started at /www/wwwroot/www.iyrc.cn/wp-content/plugins/xiaocx-jifen/xiaocx-jifen.php:2957) in /www/wwwroot/www.iyrc.cn/wp-content/plugins/wp-super-cache/wp-cache-phase2.php on line 1906
wx_7c7244d7-艾瑞克网
官网-艾瑞克网
官网-艾瑞克网