Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I found an interesting concepts of adding an additional option to the "General Options" in Wordpress.

/**
 * Custom Theme Settings
 * see http://digwp.com/2009/09/global-custom-fields-take-two/
 */

add_action('admin_menu', 'add_gcf_interface');

function add_gcf_interface() {
    add_options_page('Other', 'Other', '8', 'functions', 'otherGlobalOptions');
}

function otherGlobalOptions() {
    ?>
    <div class='wrap'>
    <h2>Sonstiges</h2>
    <form method="post" action="options.php">
        <?php wp_nonce_field('update-options') ?>
        <p><strong>Welcome Message</strong><br />
        <textarea name="welcomemessage" cols="100%" rows="7"><?php echo get_option('welcomemessage'); ?></textarea></p>
        <p><input type="submit" name="Submit" value="Save" /></p>
        <input type="hidden" name="action" value="update" />
        <input type="hidden" name="page_options" value="welcomemessage" />
    </form>
    </div>
    <?php
}

This works just fine.

I'm just wondering now if there is a chance to apply a filter to that input?

Like I can do add_filter('the_content', 'wr_replace_text', 100); I want to do

add_filter('welcomemessage', 'wr_replace_text', 100);

Is that somehow possible, because this doesn't work for me at the moment.

Kind regards, Matt

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

You can create a custom filter using filter functions of Plugin API. I have changed you code as following to create and use custom filter.

function add_gcf_interface() {
add_options_page('Other', 'Other', '8', 'functions', 'otherGlobalOptions');
}

function otherGlobalOptions() {
?>
<div class='wrap'>
<h2>Sonstiges</h2>
<form method="post" action="options.php">
    <?php wp_nonce_field('update-options') ?>
    <p><strong>Welcome Message</strong><br />
    <textarea name="welcomemessage" cols="100%" rows="7"><?php echo apply_filters('welcomemessage',get_option('welcomemessage')); ?></textarea></p>
    <p><input type="submit" name="Submit" value="Save" /></p>
    <input type="hidden" name="action" value="update" />
    <input type="hidden" name="page_options" value="welcomemessage" />
</form>
</div>
<?php
}
// Create custom filter
function add_welcomemessage($welcomemessage) {   
return $welcomemessage;
}
add_filter('welcomemessage', 'add_welcomemessage');

Tell me whether it worked for you or i will provide another solution.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.