How To Write A Wordpress Plugin

2019-05-13 23:54发布

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

1条回答
Luminary・发光体
2楼-- · 2019-05-14 00:29

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');
?>
查看更多
登录 后发表回答