Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7944191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:28:58+00:00 2026-06-04T00:28:58+00:00

I noticed in WordPress, for example, that there are multiple if statements with blank

  • 0

I noticed in WordPress, for example, that there are multiple if statements with blank returns before the action is performed:

function save_book_meta($post_id) {
    $slug = 'book';
    if($slug != $_POST['post_type']) {
        return;
    }
    if(!current_user_can('edit_post', $post_id)) {
        return;
    }
    // perform actions here
}

What is the difference between writing it like that and writing it like in the example below, where instead of returning nothing it does the checks, and then performs the action:

function save_book_meta($post_id) {
    $slug = 'book';
    if($slug == $_POST['post_type'] && current_user_can('edit_post', $post_id)) {
        // perform actions here
    }
}

My questions are:

  1. What is the purpose of the blank return?
  2. Is that a good practice to have multiple return statements (even though only one will be executed) or should the return ideally be at the end of the function?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:28:59+00:00Added an answer on June 4, 2026 at 12:28 am
    1. Stop the function from continuing.
    2. One benefit of separating the two if conditions in this case would be to prevent unnecessary processing (hitting the DB and performing business logic to determine the user’s permission levels). If you can determine a FALSE result with as little effort as possible from the beginning, there is no point in continuing to perform more complex tests.

    Generally though I would probably join 2 simple conditions. But in this case, I think it’s appropriate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I noticed that when I call the the_post() or the_content() function from my wordpress
I noticed that some wordpress themes ('Thematic' for example) adds user specific classes to
I have noticed that using the post_thumbnail() function in Wordpress inserts the image including
Just today I noticed on our Wordpress blog that the Facebook iframe is showing
I noticed that JavaScript's new Date() function is very smart in accepting dates in
I have a website with wordpress 3.0. I noticed that /wp-admin displays the following
Trying to use the new get_search_form() function on WordPress, I noticed I can't remove
I recently noticed that one of my websites (the site is a self-hosted Wordpress
I noticed that when I'm checking a wordpress blog sometimes the latest post might
I am testing Fancybox for Iframes and I noticed that on my Wordpress blog

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.