add_link example

// Wrap the data in a response object.         $response = rest_ensure_response( $data );

        if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
            $links = $this->prepare_links( $post->ID );
            $response->add_links( $links );
            if ( ! empty( $links['self']['href'] ) ) {
                $actions = $this->get_available_actions();
                $self    = $links['self']['href'];
                foreach ( $actions as $rel ) {
                    $response->add_link( $rel$self );
                }
            }
        }

        return $response;
    }

    /** * Prepares links for the request. * * @since 5.9.0 * @since 6.3.0 Adds revisions count and rest URL href to version-history. * * @param integer $id ID. * @return array Links for the given post. */
if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
            $links = $this->prepare_links( $item );
            $response->add_links( $links );

            if ( ! empty( $links['self']['href'] ) ) {
                $actions = $this->get_available_actions( $item$request );

                $self = $links['self']['href'];

                foreach ( $actions as $rel ) {
                    $response->add_link( $rel$self );
                }
            }
        }

        /** * Filters the menu item data for a REST API response. * * @since 5.9.0 * * @param WP_REST_Response $response The response object. * @param object $menu_item Menu item setup by {@see wp_setup_nav_menu_item()}. * @param WP_REST_Request $request Request object. */


        wp_redirect( $this_file );
        exit;

    case 'add':
        check_admin_referer( 'add-bookmark' );

        $redir = wp_get_referer();
        if ( add_link() ) {
            $redir = add_query_arg( 'added', 'true', $redir );
        }

        wp_redirect( $redir );
        exit;

    case 'save':
        $link_id = (int) $_POST['link_id'];
        check_admin_referer( 'update-bookmark_' . $link_id );

        edit_link( $link_id );

        
'description'     => get_option( 'blogdescription' ),
            'url'             => get_option( 'siteurl' ),
            'home'            => home_url(),
            'gmt_offset'      => get_option( 'gmt_offset' ),
            'timezone_string' => get_option( 'timezone_string' ),
            'namespaces'      => array_keys( $this->namespaces ),
            'authentication'  => array(),
            'routes'          => $this->get_data_for_routes( $this->get_routes()$request['context'] ),
        );

        $response = new WP_REST_Response( $available );
        $response->add_link( 'help', 'https://developer.wordpress.org/rest-api/' );
        $this->add_active_theme_link_to_index( $response );
        $this->add_site_logo_to_index( $response );
        $this->add_site_icon_to_index( $response );

        /** * Filters the REST API root index data. * * This contains the data describing the API. This includes information * about supported authentication schemes, supported namespaces, routes * available on the API, and a small amount of data about the site. * * @since 4.4.0 * @since 6.0.0 Added `$request` parameter. * * @param WP_REST_Response $response Response data. * @param WP_REST_Request $request Request data. */

    public function add_links( $links ) {
        foreach ( $links as $rel => $set ) {
            // If it's a single link, wrap with an array for consistent handling.             if ( isset( $set['href'] ) ) {
                $set = array( $set );
            }

            foreach ( $set as $attributes ) {
                $this->add_link( $rel$attributes['href']$attributes );
            }
        }
    }

    /** * Retrieves links for the response. * * @since 4.4.0 * * @return array List of links. */
    
$data['date_floating'] = $status->date_floating;
        }

        $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
        $data    = $this->add_additional_fields_to_object( $data$request );
        $data    = $this->filter_response_by_context( $data$context );

        $response = rest_ensure_response( $data );

        $rest_url = rest_url( rest_get_route_for_post_type_items( 'post' ) );
        if ( 'publish' === $status->name ) {
            $response->add_link( 'archives', $rest_url );
        } else {
            $response->add_link( 'archives', add_query_arg( 'status', $status->name, $rest_url ) );
        }

        /** * Filters a post status returned from the REST API. * * Allows modification of the status data right before it is returned. * * @since 4.7.0 * * @param WP_REST_Response $response The response object. * @param object $status The original post status object. * @param WP_REST_Request $request Request used to generate the response. */
if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
            $links = $this->prepare_links( $post );
            $response->add_links( $links );

            if ( ! empty( $links['self']['href'] ) ) {
                $actions = $this->get_available_actions( $post$request );

                $self = $links['self']['href'];

                foreach ( $actions as $rel ) {
                    $response->add_link( $rel$self );
                }
            }
        }

        /** * Filters the post data for a REST API response. * * The dynamic portion of the hook name, `$this->post_type`, refers to the post type slug. * * Possible hook names include: * * - `rest_prepare_post` * - `rest_prepare_page` * - `rest_prepare_attachment` * * @since 4.7.0 * * @param WP_REST_Response $response The response object. * @param WP_Post $post Post object. * @param WP_REST_Request $request Request object. */
// Wrap the data in a response object.         $response = rest_ensure_response( $data );

        if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
            $links = $this->prepare_links( $template->id );
            $response->add_links( $links );
            if ( ! empty( $links['self']['href'] ) ) {
                $actions = $this->get_available_actions();
                $self    = $links['self']['href'];
                foreach ( $actions as $rel ) {
                    $response->add_link( $rel$self );
                }
            }
        }

        return $response;
    }


    /** * Prepares links for the request. * * @since 5.8.0 * * @param integer $id ID. * @return array Links for the given post. */
'raw'      => $post->post_excerpt,
                'rendered' => $this->prepare_excerpt_response( $post->post_excerpt, $post ),
            );
        }

        $context  = ! empty( $request['context'] ) ? $request['context'] : 'view';
        $data     = $this->add_additional_fields_to_object( $data$request );
        $data     = $this->filter_response_by_context( $data$context );
        $response = rest_ensure_response( $data );

        if ( ! empty( $data['parent'] ) ) {
            $response->add_link( 'parent', rest_url( rest_get_route_for_post( $data['parent'] ) ) );
        }

        /** * Filters a revision returned from the REST API. * * Allows modification of the revision right before it is returned. * * @since 4.7.0 * * @param WP_REST_Response $response The response object. * @param WP_Post $post The original revision object. * @param WP_REST_Request $request Request used to generate the response. */
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';

        $data = $this->filter_response_by_context( $data$context );

        $links = $response->get_links();

        // Wrap the data in a response object.         $response = rest_ensure_response( $data );

        foreach ( $links as $rel => $rel_links ) {
            foreach ( $rel_links as $link ) {
                $response->add_link( $rel$link['href']$link['attributes'] );
            }
        }

        /** * Filters an attachment returned from the REST API. * * Allows modification of the attachment right before it is returned. * * @since 4.7.0 * * @param WP_REST_Response $response The response object. * @param WP_Post $post The original attachment post. * @param WP_REST_Request $request Request used to generate the response. */
Home | Imprint | This part of the site doesn't use cookies.