• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Jetpack a2z

Jetpack a2z

Jetpack a2z

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / WPCOM_JSON_API::trap_wp_die() – traps `wp_die()` calls and outputs a JSON response instead.

You appear to be a bot. Output may be restricted

Description

traps wp_die() calls and outputs a JSON response instead.

The result is always output, never returned.

Usage

WPCOM_JSON_API::trap_wp_die( $error_code, $http_status );

Parameters

$error_code
( string|null ) optional – Call with string to start the trapping. Call with null to stop.
$http_status
( int ) optional default: 400 – HTTP status code, 400 by default.

Returns

void

Source

File name: jetpack/class.json-api.php


Lines:

1 to 28 of 28
  function trap_wp_die( $error_code = null, $http_status = 400 ) {
    if ( is_null( $error_code ) ) {
      $this->trapped_error = null;
      // Stop trapping
      remove_filter( 'wp_die_handler', array( $this, 'wp_die_handler_callback' ) );
      return;
    }

    // If API called via PHP, bail: don't do our custom wp_die().  Do the normal wp_die().
    if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
      if ( ! defined( 'REST_API_REQUEST' ) || ! REST_API_REQUEST ) {
        return;
      }
    } else {
      if ( ! defined( 'XMLRPC_REQUEST' ) || ! XMLRPC_REQUEST ) {
        return;
      }
    }

    $this->trapped_error = array(
      'status'  => $http_status,
      'code'    => $error_code,
      'message' => '',
    );
    // Start trapping
    add_filter( 'wp_die_handler', array( $this, 'wp_die_handler_callback' ) );
  }
 

 View on GitHub View on Trac

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Related

Published: 27 November 2019 | Last updated: 27 November 2019

Primary Sidebar

Information

Function name: WPCOM_JSON_API::trap_wp_die
Class ref: WPCOM_JSON_API
Plugin ref: Jetpack
Version: 7.9.1
Sourcefile: class.json-api.php
File ref: class.json-api.php
Deprecated?: No
API Letters: A,J,T,W

Footer

Jetpack a2z Jetpack a2z
Jetpack a2z
WordPress 5.3
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  jetpack.wp-a2z.org
© Copyright Jetpack a2z 2014-2019. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites