Make WordPress Core

#58420 closed enhancement (duplicate)

Use WP_Die instead of die

Reported by: rakibwordpress's profile rakibwordpress Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.3
Component: General Keywords: has-patch
Focuses: coding-standards Cc:

Description

In src/wp-trackback.php file the function on line 66 use die() where we can use wp_die() as this show more user friendly error message.

Attachments (2)

58420.diff (320 bytes) - added by jannathsyeda 17 months ago.
Here, I used wp_die() instead of die
58420-2.patch (15.8 KB) - added by nihar007 17 months ago.
I replaced all the "die" with "wp_die()" function

Download all attachments as: .zip

Change History (9)

This ticket was mentioned in PR #4517 on WordPress/wordpress-develop by @rakibwordpress.


17 months ago
#1

  • Keywords has-patch added

Trac ticket:

#2 follow-up: @freewebmentor
17 months ago

Hi @rakibwordpress, Welcome back to WordPress Trac!
We have to change all the wp_die; where as die; in core as per coding standards.
Also there are many files which used die; function which we have to change that from all the files.

speedyprem commented on PR #4517:


17 months ago
#3

@rakibwebdev We have to change all the wp_die; where as die; in core as per coding standards.
Also there are many files which used die; function which we have to change that from all the files.

@ankitmaru commented on PR #4517:


17 months ago
#4

@speedyprem Yes, I agree with you.

@jannathsyeda
17 months ago

Here, I used wp_die() instead of die

@nihar007
17 months ago

I replaced all the "die" with "wp_die()" function

#5 in reply to: ↑ 2 @SergeyBiryukov
17 months ago

  • Keywords close added

Hi there, thanks for the ticket!

For reference, the condition in question in wp-trackback.php was introduced in [7559].

In my testing, 58420.diff does not seem to work as expected, as the $message parameter in wp_die() is an empty string by default, so it just displays an empty page without any message. Introducing a specific message here is probably not worth it, as there are no valid uses cases for posting a trackback in the UTF-7 encoding.

Replying to freewebmentor:

We have to change all the wp_die; where as die; in core as per coding standards.
Also there are many files which used die; function which we have to change that from all the files.

Could you clarify where you saw this suggestion? The PHP Coding Standards for WordPress don't seem to mention die() or wp_die() anywhere.

Looking at 58420-2.patch, unless I'm missing something, the usage of die() is intentional in pretty much all of these instances, as the output is already handled in a different way and we only need to terminate the script.

Using wp_die() there would cause unexpected output, additional overhead, or lead to "headers already sent" warnings when called after wp_redirect(). It also does not display any helpful error messages by itself, as the message is empty by default.

Last edited 17 months ago by SergeyBiryukov (previous) (diff)

#6 @Presskopp
16 months ago

I wonder where/why we use

// Don't load directly.
if ( ! defined( 'ABSPATH' ) ) {
        die( '-1' );
}

(mostly used, having a comment)

if ( ! defined( 'ABSPATH' ) ) {
        die();
}

(not having a comment), like seen in \wp-admin\link-parse-opml.php, \wp-admin\site-health-info.php

or even

if ( ! defined( 'ABSPATH' ) ) {
        exit();
}

like seen in \wp-includes\rss-functions.php

Do we want to unify them? I opened a ticket: #58987

Last edited 15 months ago by Presskopp (previous) (diff)

#7 @SergeyBiryukov
14 months ago

  • Keywords close removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

It looks like this was previously suggested in #46418, let's continue the discussion there.

Note: See TracTickets for help on using tickets.