WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
add_action( 'admin_init', 'register_mysettings' );
function register_mysettings() {
//register our settings
register_setting( 'plugin_options', 'plugin_options', 'plugin_options_validate' );
add_settings_section('plugin_main', '', 'plugin_section_text', 'plugin');
add_settings_field('plugin_text_string', '', 'plugin_setting_string', 'plugin', 


function poly_admin_form() {

<div class="wrap">
<h2>Change who the email and name is from</h2>
<?php if ($_REQUEST['settings-updated'] == 'true' ) : ?>
<div id="message" class="updated fade"><p><strong><?php _e( 'Options saved' ); ?></strong></p></div>
<?php endif; // If the form has just been submitted, this shows the notification ?>
<form method="post" action="options.php">
<?php settings_fields('plugin_options'); ?>
<?php do_settings_sections('plugin'); ?>

<?php submit_button(); ?>

<?php } 

function plugin_section_text() {
echo '';

function plugin_setting_string() {
$options = get_option('plugin_options');
echo "
<tr valign='top'>
<th scope='row'>Admin Email</th>
<td><input type='text' id='plugin_text_string' name='plugin_options[text_string]' value='{$options['text_string']}' /></td>

    <tr valign='top'>
    <th scope='row'>Website Name or Person Name</th>
    <td><input type='text' id='plugin_text_string' name='plugin_options[text_string_name]' value='{$options['text_string_name']}' /></td>

        // validate our options
    function plugin_options_validate($input) {
    $options = get_option('plugin_options');
    $options['text_string'] = trim($input['text_string']);
    $options['text_string_name'] = trim($input['text_string_name']);
    if(empty($options)) {
    $options['text_string'] = 'nadogrand@gmail.com';
    $options['text_string_name'] = 'Polyindustry';

return $options;

        //Sends bulk email
        function bulk_mail(){

    add_filter('wp_mail_from', 'new_mail_from');
    add_filter('wp_mail_from_name', 'new_mail_from_name');

    function new_mail_from($old) {
     return $options['text_string'];
    function new_mail_from_name($old) {
     return $options['text_string_name'];
share|improve this question
it returns some value i think from the database: dbe07810 – youngdeveloper Oct 24 '13 at 6:16
Please describe your problem, rather than just dropping a big block of code and expecting others to dig through it to figure out what the problem is. – Chip Bennett Oct 24 '13 at 12:55
up vote 0 down vote accepted

In the plugin_options_validate() function the return value of get_option( 'plugin_options' ) is never used.

Let's step through the function by adding some comments:

// Retrieve the options.
$options = get_option('plugin_options');

// Replace the options without checking if
// trim( $input['text_string'] ) and trim( $input['text_string_name'] )
// actually return strings and if $input['text_string'] and 
// $input['text_string_name'] have anything in them.
$options['text_string'] = trim($input['text_string']);
$options['text_string_name'] = trim($input['text_string_name']);

// This part never runs. `$options` will never be empty!
if ( empty( $options ) ) {
    $options['text_string'] = 'nadogrand@gmail.com';
    $options['text_string_name'] = 'Polyindustry';

Effectively, this function is the same thing you have written:

// Validate options.
function plugin_options_validate( $input ) {

    $options['text_string'] = trim( $input['text_string'] );
    $options['text_string_name'] = trim( $input['text_string_name'] );

    return $options;
share|improve this answer
No sure i get what you are saying i removed the if statement but i still get the same result what i am trying to do is use the inputed values from the form in the functions below: add_filter('wp_mail_from', 'new_mail_from'); add_filter('wp_mail_from_name', 'new_mail_from_name'); function new_mail_from($old) { return $options['text_string']; } function new_mail_from_name($old) { return $options['text_string_name']; } – youngdeveloper Oct 24 '13 at 22:28
I don't understand your comment. Please use punctuation. Like periods and commas. so I can tell where your sentences begin and end. Code in comments should go between back ticks. In code in your comment code, $options['text_string'] and $options['text_string_name'] have not been defined inside the functions, so they will always be empty. You are returning emptiness. And you should be seeing undefined index warnings in your PHP error logs. – Charles Clarkson Oct 25 '13 at 8:07
ok i understand the it's empty in the bulk_mail() function but i use the same method in the plugin_setting_string() function and i get the correct values. I just don't see why the values are returning empty in the bulk_mail() function – youngdeveloper Oct 25 '13 at 16:54
In the plugin_setting_string() function you set the value of $options with $options = get_option('plugin_options');. You have to do that again in each function you want to use the $options array in. PHP is a stupid list processor. It only does what you tell it to do in a list of PHP statements. In the bulk_mail() function, you are not are telling PHP to put any values in the $options array, so it spits out a PHP Warning (which you are probably ignoring) and does the best that it can to guess what the heck you want. – Charles Clarkson Oct 25 '13 at 18:40
Thanks man that worked, Could i have done it a better way? – youngdeveloper Oct 26 '13 at 1:36

Your Answer


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.