弹窗通知支持内容自定义WordPress插件

概述简介

1.0弹窗通知插件免费版,支持持内容自定义,大家复制代码去使用吧。道言就不介绍那么多了!

截图预览

20240508232209977-73f6551dly1hpgvifa2xqj20k30chdhq

插件代码

<?php
function web_notice_styles() {
    echo<style>
        .web_notice {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.3);
            z-index: 99999;
        }
        .web_notice_content {
            position: fixed;
            top: 50%;
            left: 50%;
            width: 550px;
            background: #FFF;
            transform: translate(-50%, -50%);
            border-radius: 40px;
            padding: 50px 40px;
        }
        .web_notice_title {
            font-weight: bold;
            text-align: center;
            font-size: 30px;
        }
        .web_notice_text {
            font-size: 16px;
            margin-top: 26px;
            line-height: 30px;
            color: #999;
        }
        .web_notice_close {
            display: block;
            background: #98a3ff;
            color: #FFF;
            text-align: center;
            font-weight: bold;
            font-size: 19px;
            line-height: 60px;
            margin: 0 auto;
            margin-top: 45px;
            border-radius: 32px;
            width: 80%;
        }
    </style>';
}
add_action('wp_head', 'web_notice_styles');

function web_notice_scripts() {
    echo<script>
        jQuery(document).ready(function ($) {
            var webNoticeTitle = "' . get_option('web_notice_title') . '";
            var webNoticeContent = "' . get_option('web_notice_content') . '";

            if (webNoticeTitle || webNoticeContent) {
                var webNoticeHTML =
                    \'<div class="web_notice">\' +
                    \'<div class="web_notice_content">\' +
                    \'<h3 class="web_notice_title">\' + webNoticeTitle + \'</h3>\' +
                    \'<div class="web_notice_text">\' + webNoticeContent + \'</div>\' +
                    \'<a class="web_notice_close" onclick="javascript:document.querySelector(\\\'.web_notice\\\').remove()">我知道了</ a>\' +
                    \'</div>\' +
                    \'</div>\';

                $(\'body\').append(webNoticeHTML);
            }
        });
    </script>';
}
add_action('wp_footer', 'web_notice_scripts');

function web_notice_settings_link($links) {
    $settings_link = '<a href="options-general.php?page=web-notice">' . __('Settings', 'web-notice') . '</a>';
    array_push($links, $settings_link);
    return $links;
}
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'web_notice_settings_link');

function web_notice_add_menu() {
    add_options_page('Web Notice', 'Web Notice', 'manage_options', 'web-notice', 'web_notice_options_page');
}
add_action('admin_menu', 'web_notice_add_menu');

function web_notice_options_page() {
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.', 'web-notice'));
    }
    ?>
    <div class="wrap">
        <h2>Web Notice</h2>
        <form method="post" action="options.php">
            <?php settings_fields('web_notice_settings'); ?>
            <?php do_settings_sections('web-notice'); ?>
          <table class="form-table">
                <tr valign="top">
                    <th scope="row">通知标题</th>
                    <td><input type="text" name="web_notice_title" value="<?php echo esc_attr(get_option('web_notice_title')); ?>" /></td>
                </tr>
                <tr valign="top">
                    <th scope="row">通知内容</th>
                    <td><textarea name="web_notice_content" rows="5" cols="50"><?php echo esc_attr(get_option('web_notice_content')); ?></textarea></td>
                </tr>
            </table>
            <?php submit_button(); ?>
        </form>
    </div>
    <?php
}

function web_notice_register_settings() {
    register_setting('web_notice_settings', 'web_notice_title');
    register_setting('web_notice_settings', 'web_notice_content');
}
add_action('admin_init', 'web_notice_register_settings');
© 版权声明
THE END
点赞39 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容