wp_remote_post example

$args['headers'] = apply_filters( 'wp_http_ixr_client_headers', $args['headers'] );

        if ( false !== $this->timeout ) {
            $args['timeout'] = $this->timeout;
        }

        // Now send the request.         if ( $this->debug ) {
            echo '<pre class="ixr_request">' . htmlspecialchars( $xml ) . "\n</pre>\n\n";
        }

        $response = wp_remote_post( $url$args );

        if ( is_wp_error( $response ) ) {
            $errno       = $response->get_error_code();
            $errorstr    = $response->get_error_message();
            $this->error = new IXR_Error( -32300, "transport error: $errno $errorstr);
            return false;
        }

        if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
            $this->error = new IXR_Error( -32301, 'transport error - HTTP status code was not 200 (' . wp_remote_retrieve_response_code( $response ) . ')' );
            return false;
        }

        else if ( $ssl_disabled ) {
            do_action( 'akismet_ssl_disabled' );
        }

        if ( ! $ssl_disabled && ( $ssl = wp_http_supports( array( 'ssl' ) ) ) ) {
            $akismet_url = set_url_scheme( $akismet_url, 'https' );

            do_action( 'akismet_https_request_pre' );
        }

        $response = wp_remote_post( $akismet_url$http_args );

        Akismet::log( compact( 'akismet_url', 'http_args', 'response' ) );

        if ( $ssl && is_wp_error( $response ) ) {
            do_action( 'akismet_https_request_failure', $response );

            // Intermittent connection problems may cause the first HTTPS             // request to fail and subsequent HTTP requests to succeed randomly.             // Retry the HTTPS request once before disabling SSL for a time.             $response = wp_remote_post( $akismet_url$http_args );
            
            
// Deactivate the REST API plugin if its version is 2.0 Beta 4 or lower.     _upgrade_440_force_deactivate_incompatible_plugins();

    // Deactivate incompatible plugins.     _upgrade_core_deactivate_incompatible_plugins();

    // Upgrade DB with separate request.     /** This filter is documented in wp-admin/includes/update-core.php */
    apply_filters( 'update_feedback', __( 'Upgrading database&#8230;' ) );

    $db_upgrade_url = admin_url( 'upgrade.php?step=upgrade_db' );
    wp_remote_post( $db_upgrade_url, array( 'timeout' => 60 ) );

    // Clear the cache to prevent an update_option() from saving a stale db_version to the cache.     wp_cache_flush();
    // Not all cache back ends listen to 'flush'.     wp_cache_delete( 'alloptions', 'options' );

    // Remove working directory.     $wp_filesystem->delete( $from, true );

    // Force refresh of update information.     if ( function_exists( 'delete_site_transient' ) ) {
        
'body'    => array(
                'wp_version' => $wp_version,
                'locale'     => get_locale(),
                'version'    => $args['version'], // Version of plugin, theme or core.             ),
        );

        if ( 'core' !== $type ) {
            $options['body']['slug'] = $args['slug']; // Plugin or theme slug.         }

        $request = wp_remote_post( $url$options );

        if ( $ssl && is_wp_error( $request ) ) {
            trigger_error(
                sprintf(
                    /* translators: %s: Support forums URL. */
                    __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
                    __( 'https://wordpress.org/support/forums/' )
                ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
                headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
            );

            
$url     = 'http://api.wordpress.org/core/browse-happy/1.1/';
        $options = array(
            'body'       => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),
            'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
        );

        if ( wp_http_supports( array( 'ssl' ) ) ) {
            $url = set_url_scheme( $url, 'https' );
        }

        $response = wp_remote_post( $url$options );

        if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
            return false;
        }

        /** * Response should be an array with: * 'platform' - string - A user-friendly platform name, if it can be determined * 'name' - string - A user-friendly browser name * 'version' - string - The version of the browser the user is using * 'current_version' - string - The most recent version of the browser * 'upgrade' - boolean - Whether the browser needs an upgrade * 'insecure' - boolean - Whether the browser is deemed insecure * 'update_url' - string - The url to visit to upgrade * 'img_src' - string - An image representing the browser * 'img_src_ssl' - string - An image (over SSL) representing the browser */
$options = array(
        'timeout'    => $doing_cron ? 30 : 3,
        'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
        'headers'    => array(
            'wp_install' => $wp_install,
            'wp_blog'    => home_url( '/' ),
        ),
        'body'       => $post_body,
    );

    $response = wp_remote_post( $url$options );

    if ( $ssl && is_wp_error( $response ) ) {
        trigger_error(
            sprintf(
                /* translators: %s: Support forums URL. */
                __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
                __( 'https://wordpress.org/support/forums/' )
            ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
            headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
        );
        $response = wp_remote_post( $http_url$options );
    }
/* * A post request is used for the wp-cron.php loopback test to cause the file * to finish early without triggering cron jobs. This has two benefits: * - cron jobs are not triggered a second time on the site health page, * - the loopback request finishes sooner providing a quicker result. * * Using a POST request causes the loopback to differ slightly to the standard * GET request WordPress uses for wp-cron.php loopback requests but is close * enough. See https://core.trac.wordpress.org/ticket/52547 */
        $r = wp_remote_post( $urlcompact( 'body', 'cookies', 'headers', 'timeout', 'sslverify' ) );

        if ( is_wp_error( $r ) ) {
            return (object) array(
                'status'  => 'critical',
                'message' => sprintf(
                    '%s<br>%s',
                    __( 'The loopback request to your site failed, this means features relying on them are not currently working as expected.' ),
                    sprintf(
                        /* translators: 1: The WordPress error message. 2: The WordPress error code. */
                        __( 'Error: %1$s (%2$s)' ),
                        $r->get_error_message(),
                        
'key'  => $doing_wp_cron,
            'args' => array(
                'timeout'   => 0.01,
                'blocking'  => false,
                /** This filter is documented in wp-includes/class-wp-http-streams.php */
                'sslverify' => apply_filters( 'https_local_ssl_verify', false ),
            ),
        ),
        $doing_wp_cron
    );

    $result = wp_remote_post( $cron_request['url']$cron_request['args'] );
    return ! is_wp_error( $result );
}

/** * Registers _wp_cron() to run on the {@see 'wp_loaded'} action. * * If the {@see 'wp_loaded'} action has already fired, this function calls * _wp_cron() directly. * * Warning: This function may return Boolean FALSE, but may also return a non-Boolean * value which evaluates to FALSE. For information about casting to booleans see the * {@link https://www.php.net/manual/en/language.types.boolean.php PHP documentation}. Use * the `===` operator for testing the return value of this function. * * @since 2.1.0 * @since 5.1.0 Return value added to indicate success or failure. * @since 5.7.0 Functionality moved to _wp_cron() to which this becomes a wrapper. * * @return bool|int|void On success an integer indicating number of events spawned (0 indicates no * events needed to be spawned), false if spawning fails for one or more events or * void if the function registered _wp_cron() to run on the action. */
Home | Imprint | This part of the site doesn't use cookies.