如何编写一个WordPress插件 [英] How To Write A Wordpress Plugin

查看:92
本文介绍了如何编写一个WordPress插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是wordpress的新蜜蜂,我需要知道如何在wordpress中编写带有页面选项的简单wordpress插件.

Hi i am a new bee to wordpress i need to know that how can i write a simple wordpress plugin with a page option in wordpress.

我需要一个演示来在管理面板和前端中编辑页脚文本

I need a demo for editing footer text in admin panel and in also the front end

推荐答案

使用以下代码动态更改管理页脚文本. 将以下代码另存为.php文件在您的wordpress插件目录中.

Use the below code for changing the admin footer text dynamically. Save the below code as a .php file in your wordpress plugins directory.

<?php
/*
Plugin Name: Fancy Search Box For Your Theme
Plugin URI: http://svarun.in/
Description: Fancy Search Form
Version: 1.0.5
Author: Varun
Author URI: http://svarun.in
License: GPL
*/

register_activation_hook(__FILE__,'footer_word_install');
register_deactivation_hook( __FILE__, 'footer_word_remove' );

function footer_word_install() {
    add_option("footer_word_data", 'Default', '', 'yes');
}

function footer_word_remove() {
    delete_option('footer_word_data');
}

if (is_admin()) {
    add_action('admin_menu', 'footer_word_admin_menu');
    function footer_word_admin_menu() {
        add_options_page('footer word', 'footer word', 'administrator',
    'footer-world', 'footer_word_html_page');
    }
}

function footer_word_html_page() {
    ?>
    <div>
    <h2>footer_word Options</h2>
    <form method="post" action="options.php">
    <?php wp_nonce_field('update-options'); ?>
    <table width="510">
    <tr valign="top">
    <th width="92" scope="row">Enter Text</th>
    <td width="406">
    <input name="footer_word_data" type="text" id="footer_word_data" value="<?php echo get_option('footer_word_data'); ?>" />
    </td>  
    </tr>
    </table>
    <input type="hidden" name="action" value="update" />
    <input type="hidden" name="page_options" value="footer_word_data" />
    <p>
    <input type="submit" value="<?php _e('Save Changes') ?>" />
    </p>
    </form>
    </div>
    <?php
}

function change_footer_admin() {
    echo get_option('footer_word_data');
}

add_filter('admin_footer_text', 'change_footer_admin');
?>

这篇关于如何编写一个WordPress插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆