Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phan: functionify and statusify exit() and die() #41167

Open
wants to merge 14 commits into
base: trunk
Choose a base branch
from
  •  
  •  
  •  
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Code: Use function-style exit() and die() with a default status code of 0.
2 changes: 1 addition & 1 deletion projects/packages/analyzer/scripts/jetpack-svn.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

if ( ! file_exists( $external_repo_path ) ) {
echo "Need a path of another codebase to compare Jetpack changes against.\n";
exit;
exit( 0 );
}

// tmp paths.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Code: Use function-style exit() and die() with a default status code of 0.
4 changes: 2 additions & 2 deletions projects/packages/autoloader/src/CustomAutoloaderPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function postAutoloadDump( Event $event ) {
$this->io->writeError( "\n<error>An error occurred while generating the autoloader files:", true );
$this->io->writeError( 'The project\'s composer.json or composer environment set a non-default vendor directory.', true );
$this->io->writeError( 'The default composer vendor directory must be used.</error>', true );
exit();
exit( 0 );
}

$installationManager = $this->composer->getInstallationManager();
Expand Down Expand Up @@ -174,7 +174,7 @@ private function isRequiredByRoot() {

if ( empty( $requires ) ) {
$this->io->writeError( "\n<error>The package is not required and this should never happen?</error>", true );
exit();
exit( 0 );
}

foreach ( $requires as $require ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Code: Use function-style exit() and die() with a default status code of 0.
2 changes: 1 addition & 1 deletion projects/packages/backup/src/class-jetpack-backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Automattic\Jetpack\Backup\V0005;

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

use Automattic\Jetpack\Admin_UI\Admin_Menu;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Code: Use function-style exit() and die() with a default status code of 0.
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ public function maybe_reorder_menu_items() {
admin_url( 'edit.php' )
);
wp_safe_redirect( $redirect );
exit;
exit( 0 );
}

/**
Expand Down Expand Up @@ -1036,7 +1036,7 @@ public function handle_menu_item_actions() {
admin_url( 'edit.php' )
);
wp_safe_redirect( $redirect );
exit;
exit( 0 );
}

/**
Expand Down Expand Up @@ -1138,7 +1138,7 @@ public function add_many_new_items_page_load() {
&& 'POST' === strtoupper( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) )
) {
$this->process_form_request();
exit;
exit( 0 );
}

$this->enqueue_many_items_scripts();
Expand Down Expand Up @@ -1234,11 +1234,11 @@ public function process_form_request() {
endforeach;

if ( $is_ajax ) {
exit;
exit( 0 );
}

wp_safe_redirect( admin_url( 'edit.php?post_type=' . self::MENU_ITEM_POST_TYPE ) );
exit;
exit( 0 );
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Code: Use function-style exit() and die() with a default status code of 0.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Disable direct access.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
exit( 0 );
}

if ( ! class_exists( IXR_Client::class ) ) {
Expand Down
4 changes: 2 additions & 2 deletions projects/packages/connection/src/class-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public function alternate_xmlrpc() {
nocache_headers();
$wp_xmlrpc_server->serve_request();

exit;
exit( 0 );
}

/**
Expand Down Expand Up @@ -935,7 +935,7 @@ public function connect_user( $user_id = null, $redirect_url = null ) {

// Using wp_redirect intentionally because we're redirecting outside.
wp_redirect( $this->get_authorization_url( $user, $redirect_url ) ); // phpcs:ignore WordPress.Security.SafeRedirect
exit();
exit( 0 );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/connection/src/class-partner-coupon.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Disable direct access.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
exit( 0 );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/connection/src/class-webhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function handle_authorize_redirect() {
* @return never
*/
protected function do_exit() {
exit;
exit( 0 );
}

/**
Expand Down
12 changes: 6 additions & 6 deletions projects/packages/connection/src/sso/class-sso.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function maybe_logout_user() {
Helpers::delete_connection_for_user( $current_user->ID );
wp_logout();
wp_safe_redirect( wp_login_url() );
exit;
exit( 0 );
}
}

Expand Down Expand Up @@ -491,7 +491,7 @@ public function login_init() {

$tracking->record_user_event( 'sso_login_redirect_success' );
wp_safe_redirect( $sso_url );
exit;
exit( 0 );
}
} elseif ( Helpers::display_sso_form_for_action( $action ) ) {

Expand All @@ -509,7 +509,7 @@ public function login_init() {
$sso_url = $this->get_sso_url_or_die( $reauth );
$tracking->record_user_event( 'sso_login_redirect_bypass_success' );
wp_safe_redirect( $sso_url );
exit;
exit( 0 );
}

$this->display_sso_login_form();
Expand Down Expand Up @@ -969,15 +969,15 @@ public function handle_login() {
admin_url()
)
);
exit;
exit( 0 );
}

add_filter( 'allowed_redirect_hosts', array( Helpers::class, 'allowed_redirect_hosts' ) );
wp_safe_redirect(
/** This filter is documented in core/src/wp-login.php */
apply_filters( 'login_redirect', $redirect_to, $_request_redirect_to, $user )
);
exit;
exit( 0 );
}

add_filter( 'jetpack_sso_default_to_sso_login', '__return_false' );
Expand Down Expand Up @@ -1207,7 +1207,7 @@ public function maybe_authorize_user_after_sso() {

add_filter( 'allowed_redirect_hosts', array( Helpers::class, 'allowed_redirect_hosts' ) );
wp_safe_redirect( $connect_url );
exit;
exit( 0 );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function ( $domains ) {

if ( ! $dest_url || ( 0 === stripos( $dest_url, 'https://jetpack.com/' ) && 0 === stripos( $dest_url, 'https://wordpress.com/' ) ) ) {
// The destination URL is missing or invalid, nothing to do here.
exit;
exit( 0 );
}

// The user is either already connected, or finished the connection process.
Expand All @@ -73,12 +73,12 @@ function ( $domains ) {
}

wp_safe_redirect( $dest_url );
exit;
exit( 0 );
} elseif ( ! empty( $_GET['done'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
// The user decided not to proceed with setting up the connection.

wp_safe_redirect( Admin_Menu::get_top_level_menu_item_url() );
exit;
exit( 0 );
}

$redirect_args = array(
Expand All @@ -94,7 +94,7 @@ function ( $domains ) {
}

wp_safe_redirect( $this->build_authorize_url( add_query_arg( $redirect_args, admin_url( 'admin.php' ) ) ) );
exit;
exit( 0 );
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Code: Use function-style exit() and die() with a default status code of 0.
8 changes: 4 additions & 4 deletions projects/packages/forms/src/contact-form/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ public function grunion_display_form_view() {
if ( current_user_can( 'edit_posts' ) ) {
Form_View::display();
}
exit;
exit( 0 );
}

/**
Expand Down Expand Up @@ -549,7 +549,7 @@ public function grunion_handle_bulk_spam() {

if ( empty( $_REQUEST['post'] ) ) {
wp_safe_redirect( wp_get_referer() );
exit;
exit( 0 );
}

$post_ids = array_map( 'intval', $_REQUEST['post'] );
Expand Down Expand Up @@ -583,7 +583,7 @@ public function grunion_handle_bulk_spam() {

$redirect_url = add_query_arg( 'message', 'marked-spam', wp_get_referer() );
wp_safe_redirect( $redirect_url );
exit;
exit( 0 );
}

/**
Expand Down Expand Up @@ -1255,7 +1255,7 @@ public function grunion_ajax_spam() {
}

echo $status_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- we're building the html to echo.
exit;
exit( 0 );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ public function ajax_request() {
);
}

die;
die( 0 );
}

/**
Expand Down Expand Up @@ -1828,7 +1828,7 @@ public function download_feedback_as_csv() {
fclose( $output ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose

$this->record_tracks_event( 'forms_export_responses', array( 'format' => 'csv' ) );
exit();
exit( 0 );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,7 @@ public function process_submission() {

// phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- We intentially allow external redirects here.
wp_redirect( $redirect );
exit;
exit( 0 );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public function handle_preferred_view() {

update_user_option( get_current_user_id(), 'jetpack_forms_admin_preferred_view', $view );
wp_safe_redirect( remove_query_arg( 'dashboard-preferred-view' ) );
exit;
exit( 0 );
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Code: Use function-style exit() and die() with a default status code of 0.
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,6 @@ function coming_soon_page( $template ) {
}

render_fallback_coming_soon_page();
die();
die( 0 );
}
add_filter( 'template_include', __NAMESPACE__ . '\coming_soon_page' );
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ public function write( $filename, $formatted = false, $doctype = 'xhtml1.1', $ex
$madedir = mkdir( 'temp' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_mkdir
if ( ! $madedir ) {
print 'Could not make directory "temp" in ' . __DIR__;
exit;
exit( 0 );
}
}
$handle = fopen( 'temp/' . $filename, 'w' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static function print_linked_custom_css() {
header( 'Content-type: text/css' );
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + YEAR_IN_SECONDS ) . ' GMT' );
echo wp_get_custom_css(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
exit;
exit( 0 );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function jetpack_matt_random_redirect() {
// @phan-suppress-next-line PhanTypeMismatchArgument
$permalink = get_permalink( $random_id );
wp_safe_redirect( $permalink );
exit;
exit( 0 );
}

add_action( 'template_redirect', 'jetpack_matt_random_redirect' );
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ private function check_iframe_cookie_setting() {

if ( isset( $_SERVER['REQUEST_URI'] ) && empty( $_GET['calypsoify_cookie_check'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
header( 'Location: ' . esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) . '&calypsoify_cookie_check=true' ) );
exit;
exit( 0 );
}

header( 'X-Frame-Options: DENY' );
exit;
exit( 0 );
}

/**
Expand Down Expand Up @@ -210,7 +210,7 @@ public function add_login_html() {
*/
public function do_redirect() {
wp_safe_redirect( $GLOBALS['redirect_to'] );
exit;
exit( 0 );
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Code: Use function-style exit() and die() with a default status code of 0.
2 changes: 1 addition & 1 deletion projects/packages/licensing/src/class-licensing.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public function handle_user_connected_redirect( $dest_url ) {
&& apply_filters( 'jetpack_connection_user_has_license', false, $licenses, $plugin_slug )
) {
wp_safe_redirect( '/wp-admin/admin.php?page=my-jetpack#/add-license' );
exit;
exit( 0 );
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Code: Use function-style exit() and die() with a default status code of 0.
Loading
Loading