Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I ran into a strange Problem today developing a new Plugin.

I set it up as usual, creating the f711-roomprice folder in the Plugindirectory, and creating the f711-roomprice.php as well as an inc directory in there.

Everything worked fine with the activation hook and the included functions, until i created an include:

include('inc/filter-savepost.php');

this file contained the following code:

add_action( 'save_post', 'f711_roomprice_meta_box_save' );  
function f711_roomprice_meta_box_save( $post_id ) {

    if( !isset( $_POST['f711_roomprice_prices'] ) ) return;

    if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; 

    if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'f711_roomprice_box_nonce' ) ) return; 

    if( !current_user_can( 'edit_post', $post_id ) ) return;

    foreach( $_POST['f711_roomprice_prices'] as $room => $seasons ) {
        foreach( $seasons as $season => $price ) {

            f711_roomprice_insert( $room, $season, $price );

        }

    }

}  

After including the file in my main plugin file, I got an Error resulting in a white screen on Saving a post, everything else worked fine.

The function f711_roomprice_meta_box_save is called, confirmed this with an wp_die('f711_roomprice_meta_box_saveis called') in there.

Now the strangest thing is, i placed the code (exactly the same as in the include file) in my main Plugin file, and skipped the include of course. Now it works just as I want it to.

I also tried just adding the save_post action in the main Plugin file and including the function from inc/filter-savepost.php, still got the wrong result as before.

What am I doing wrong here? Is the placement of the Code (Hooks, Functions) really important in a Plugin, or is it just something on my part gone wrong?

share|improve this question
Is debug on? Is it showing any messages? – Vinod Dalvi Mar 1 at 8:45
Yep, had debug on - showed some information about a fancyboxplugin i used. Funny thing, I deactivated all other Plugins, and it worked with the include. How can this affect the way I use my plugin? I call the exact same functions as before, just from a different file. – fischi Mar 1 at 8:54
Try deactivating fancyboxplugin only? – Vinod Dalvi Mar 1 at 9:01
Yeah, that was the bad one. But nevertheless, I don't get why this affected my Plugin in a way that I needed to change the file structure. That's the odd thing.. – fischi Mar 1 at 9:03
Send me the plugin link i will check it out. – Vinod Dalvi Mar 1 at 9:04
show 1 more comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.