简体   繁体   中英

Wrong WordPress Theme Option Page PHP - stuck

OK... I've been looking at this thing forever and I have to admit defeat.

I'm piecing together an Options Page for a WordPress Theme, and I'm getting a

"Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'flaunt_one_theme_options' was given in /home/bahia001/public_html/test/wp-includes/plugin.php on line 405" Error.

I know that this is probably due to incorrect nomenclature between the code snippets I used to put this together, but I need a little guidance. I'm kinda new to PHP.


This is my code:

<?php
//Theme Options 
function my_admin_scripts(){
wp_enqueue_script('media-upload');
}

if (isset($_GET['page']) && $_GET['page'] == 'folio-themes-setup') {
add_action('admin_print_scripts', 'my_admin_scripts');

add_action('admin_print_styles', 'my_admin_styles');

}

add_action('admin_menu', 'flaunt_one_create_menu');
function flaunt_one_create_menu() {
add_menu_page('Flaunt One Options', 'Flaunt One Options', 'administrator','folio-themes-setup', 'flaunt_one_theme_options',get_bloginfo('stylesheet_directory')."/images/flaunt16.png",63);
add_action( 'admin_init', 'register_mysettings' );
}
function register_mysettings() {
register_setting( 'flaunt-one-settings-group', 'flaunt_one_logo');
register_setting( 'flaunt-one-settings-group', 'flaunt_one_favico');
}
function sw_settings_page() {
?>





<div class="wrap">
    <?php screen_icon(); echo "<h2>" . get_current_theme() . __( 'Options', 'flaunt_one' ) . "</h2>"; ?>    

<div id="flaunt-options" style="width:800px; float:left;">

    <?php if ( false !== $_REQUEST['settings-updated'] ) : ?>
    <div class="updated fade"><p><strong><?php _e( 'Options saved', 'flaunt_one' ); ?></strong></p></div>
    <?php endif; ?>

    <form method="post" action="options.php">
        <?php settings_fields( 'flaunt_one_options' ); ?>
        <?php $options = get_option( 'flaunt_one_theme_options' ); ?>

        <table class="form-table">


             <tr valign="top">
    <th scope="row"><h3>Style Options:</h3></th>
    <td></td>
    </tr>

    <tr valign="top">
    <th scope="row">Logo:</th>
    <td><input size="53" type="text" name="sw_logo" value="<?php echo get_option('flaunt_one_logo'); ?>" /><input class="upload_image_button" type="button" value="Upload" />
    </td>
    </tr>
    <? if(get_option('flaunt_one_logo')){ ?>
          <tr valign="top">
          <th scope="row"></th>
          <td><img src="<?php echo get_option('flaunt_one_logo'); ?>" alt="" /></td>
          </tr>

    <? } ?>
    <tr valign="top">
    <th scope="row">Favicon:</th>
    <td><input size="53" type="text" name="favico" value="<?php echo get_option('flaunt_one_favico'); ?>" /><input class="upload_image_button"  type="button" value="Upload" /></td>
    </tr>
        </table>

    <h3>Social Media Icons:</h3>
    <p><?php _e( 'These options will let you setup the social icons at the top of the theme. You can enter the URLs of your profiles to have the icons show up.', 'flaunt_one' ); ?></p>

        <table class="form-table">
            <?php
            /**
             * Facebook Icon
             */
            ?>
            <tr valign="top"><th scope="row"><?php _e( 'Enter your Facebook URL', 'flaunt_one' ); ?></th>
                <td>
                    <input id="flaunt_one_theme_options[facebookurl]" class="regular-text" type="text" name="flaunt_one_theme_options[facebookurl]" value="<?php esc_attr_e( $options['facebookurl'] ); ?>" />
                    <label class="description" for="flaunt_one_theme_options[facebookurl]"><?php _e( 'Leave blank to hide Facebook Icon', 'flaunt_one' ); ?></label>
                </td>
            </tr>

            <?php
            /**
             * Twitter URL
             */
            ?>
            <tr valign="top"><th scope="row"><?php _e( 'Enter your Twitter URL', 'flaunt_one' ); ?></th>
                <td>
                    <input id="flaunt_one_theme_options[twitterurl]" class="regular-text" type="text" name="flaunt_one_theme_options[twitterurl]" value="<?php esc_attr_e( $options['twitterurl'] ); ?>" />
                    <label class="description" for="flaunt_one_theme_options[twitterurl]"><?php _e( 'Leave blank to hide Twitter Icon', 'flaunt_one' ); ?></label>
                </td>
            </tr>

            <?php
            /**
             * Google+ URL
             */
            ?>
            <tr valign="top"><th scope="row"><?php _e( 'Enter your Google+ URL', 'flaunt_one' ); ?></th>
                <td>
                    <input id="flaunt_one_theme_options[googleplusurl]" class="regular-text" type="text" name="flaunt_one_theme_options[googleplusurl]" value="<?php esc_attr_e( $options['googleplusurl'] ); ?>" />
                    <label class="description" for="flaunt_one_theme_options[googleplusurl]"><?php _e( 'Leave blank to hide Google+ Icon', 'flaunt_one' ); ?></label>
                </td>
            </tr>

                            <?php
            /**
             * Pinterest URL
             */
            ?>
            <tr valign="top"><th scope="row"><?php _e( 'Enter your Pinterest URL', 'flaunt_one' ); ?></th>
                <td>
                    <input id="flaunt_one_theme_options[pinteresturl]" class="regular-text" type="text" name="flaunt_one_theme_options[pinteresturl]" value="<?php esc_attr_e( $options['pinteresturl'] ); ?>" />
                    <label class="description" for="flaunt_one_theme_options[pinteresturl]"><?php _e( 'Leave blank to hide Pinterest Icon', 'flaunt_one' ); ?></label>
                </td>
            </tr>           

            <?php
            /**
             * RSS Icon
             */
            ?>
            <tr valign="top"><th scope="row"><?php _e( 'Enter your RSS URL', 'flaunt_one' ); ?></th>
                <td>
                    <input id="flaunt_one_theme_options[rssurl]" class="regular-text" type="text" name="flaunt_one_theme_options[rssurl]" value="<?php esc_attr_e( $options['rssurl'] ); ?>" />
                    <label class="description" for="flaunt_one_theme_options[rssurl]"><?php _e( 'Enter your Feedburner url. If you dont have one use "http://yoursitename.com/feed/"', 'flaunt_one' ); ?></label>
                </td>
            </tr>

        </table>

        <p class="submit">
            <input type="submit" class="button-primary" value="<?php _e( 'Save Options', 'flaunt_one' ); ?>" />
        </p>
    </form>
</div>

    <!-- End Social Share Buttons -->       

    <!-- Sharing Column -->
<div id="share-column" style="float:right;">

<!-- Begin MailChimp Signup Form -->
<div id="flaunt-mc-signup">
    <link href="http://cdn-images.mailchimp.com/embedcode/slim-081711.css" rel="stylesheet" type="text/css">
    <div id="mc_embed_signup">
    <form action="http://flauntyoursite.us2.list-manage.com/subscribe/post?u=9d1d3626942e4f97eb4bb6699&amp;id=b85f19e2d3" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank">
    <label for="mce-EMAIL">Subscribe to our mailing list</label>
    <input type="email" value="" name="EMAIL" class="email" id="mce-EMAIL" placeholder="email address" required>
        <div class="clear"><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button-primary"></div>
    </form>
    </div>
</div>
<!--End mc_embed_signup-->


<!-- Begin Sharing Section -->
<div class="flaunt-share">
<p>Could you do me a <strong>huge</strong> favor and share this plugin with others. Thank you so much!</p>                          
                        <ul style="list-style:none;">
                                    <li><?php echo flaunt_like_facebook(); ?>
                                        <?php
    }
    //Render Facebook Like button
    //http://developers.facebook.com/docs/reference/plugins/like/
    //TODO Not using since correct image isn't coming up for now
    function flaunt_like_facebook() {
?>

<div id="fb-root">
</div>
    <script>(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=237425446277620";
    fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>

<div class="fb-like" data-href="http://flauntyoursite.com" data-send="false" data-layout="button_count" data-width="150" data-show-faces="false"></div>

                                    </li>


                                    <li><?php echo flaunt_share_twitter(); ?>
                                        <?     php
     }
     //Render Twitter button
     //https://twitter.com/about/resources/buttons
     function flaunt_share_twitter() {
 ?>
 <a href="https://twitter.com/share" class="twitter-share-button" data-url="http://flauntyoursite.com/" data-text="Flaunt Your Site - We Get Photographers Noticed!" alt="Tweet this!">Tweet</a>
 <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s) [0];if(!d.getElementById(id)) {js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>  

                                    </li>


                                    <li><?php echo flaunt_share_google_plus(); ?>
                                        <?php
     }
     //Render Google +1 button
     //http://www.google.com/intl/en/webmasters/+1/button/index.html
     function flaunt_share_google_plus() {
 ?>

 <!-- Place this tag where you want the +1 button to render -->
 <div class="g-plusone" data-size="medium" data-href="http://flauntyoursite.com/">
 </div>
 <!-- Place this render call where appropriate -->
 <script type="text/javascript">
  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
</script>
                                    </li>


                                    <li>(Or <a href="http://wordpress.org/extend/plugins/#/" target="_blank">rate it on WordPress</a>)      </li>
                        </ul>

</div><!-- End Sharing Section -->
    </div>  <!-- End Sharing Column -->
    </div> <!-- End Wrapper -->

    <?php
    }

    /**
    * Sanitize and validate input. Accepts an array, return a sanitized array.
    */
    function flaunt_one_options_validate( $input ) {

// Our text option must be safe text with no HTML tags
$input['twitterurl'] = wp_filter_nohtml_kses( $input['twitterurl'] );
$input['facebookurl'] = wp_filter_nohtml_kses( $input['facebookurl'] );
$input['googleplusurl'] = wp_filter_nohtml_kses( $input['googleplusurl'] );
    $input['pinteresturl'] = wp_filter_nohtml_kses( $input['pinteresturl'] );   
$input['feedurl'] = wp_filter_nohtml_kses( $input['feedurl'] );


// Encode URLs
$input['twitterurl'] = esc_url_raw( $input['twitterurl'] );
$input['facebookurl'] = esc_url_raw( $input['facebookurl'] );
$input['googleplusurl'] = esc_url_raw( $input['googleplusurl'] );
$input['pinteresturl'] = esc_url_raw( $input['pinteresturl'] );
$input['feedurl'] = esc_url_raw( $input['feedurl'] );
return $input;
    }

it looks like the error is occurring because when you cann the flaunt_one_options_validate function at the end of your code, the function is not receiving what you are trying to send via the $input variable.

function flaunt_one_options_validate( $input ) 

On the page, the input variable must be declared and have some value, I presume. This then needs to be readable and in the right format (strong or number etc) before the function is called.

Try testing the function with a static value in there first, so that you know that the function is working. Then try and make the variable dynamic.

Hope this helps, update this post once you've done that.

Rick

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM