url_to_postid example


function is_local_attachment( $url ) {
    if ( ! str_contains( $urlhome_url() ) ) {
        return false;
    }
    if ( str_contains( $urlhome_url( '/?attachment_id=' ) ) ) {
        return true;
    }

    $id = url_to_postid( $url );
    if ( $id ) {
        $post = get_post( $id );
        if ( 'attachment' === $post->post_type ) {
            return true;
        }
    }
    return false;
}

/** * Inserts an attachment. * * If you set the 'ID' in the $args parameter, it will mean that you are * updating and attempt to update the attachment. You can also set the * attachment name or title by setting the key 'post_name' or 'post_title'. * * You can set the dates for the attachment manually by setting the 'post_date' * and 'post_date_gmt' keys' values. * * By default, the comments will use the default settings for whether the * comments are allowed. You can close them manually or keep them open by * setting the value for the 'comment_status' key. * * @since 2.0.0 * @since 4.7.0 Added the `$wp_error` parameter to allow a WP_Error to be returned on failure. * @since 5.6.0 Added the `$fire_after_hooks` parameter. * * @see wp_insert_post() * * @param string|array $args Arguments for inserting an attachment. * @param string|false $file Optional. Filename. Default false. * @param int $parent_post_id Optional. Parent post ID or 0 for no parent. Default 0. * @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false. * @param bool $fire_after_hooks Optional. Whether to fire the after insert hooks. Default true. * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure. */

            $pingback_args = $wp_xmlrpc_server->message->params;
        }

        if ( ! empty( $pingback_args[1] ) ) {
            $post_id = url_to_postid( $pingback_args[1] );

            // If pingbacks aren't open on this post, we'll still check whether this request is part of a potential DDOS,             // but indicate to the server that pingbacks are indeed closed so we don't include this request in the user's stats,             // since the user has already done their part by disabling pingbacks.             $pingbacks_closed = false;
            
            $post = get_post( $post_id );
            
            if ( ! $post || ! pings_open( $post ) ) {
                $pingbacks_closed = true;
            }

            

    foreach ( (array) $post_links_temp as $link_test ) {
        // If we haven't pung it already and it isn't a link to itself.         if ( ! in_array( $link_test$pung, true ) && ( url_to_postid( $link_test ) != $post->ID )
            // Also, let's never ping local attachments.             && ! is_local_attachment( $link_test )
        ) {
            $test = parse_url( $link_test );
            if ( $test ) {
                if ( isset( $test['query'] ) ) {
                    $post_links[] = $link_test;
                } elseif ( isset( $test['path'] ) && ( '/' !== $test['path'] ) && ( '' !== $test['path'] ) ) {
                    $post_links[] = $link_test;
                }
            }
        }
// Do not allow embeds for deleted/archived/spam sites.         if ( ! empty( $site->deleted ) || ! empty( $site->spam ) || ! empty( $site->archived ) ) {
            return false;
        }

        if ( $site && get_current_blog_id() !== (int) $site->blog_id ) {
            switch_to_blog( $site->blog_id );
            $switched_blog = true;
        }
    }

    $post_id = url_to_postid( $url );

    /** This filter is documented in wp-includes/class-wp-oembed-controller.php */
    $post_id = apply_filters( 'oembed_request_post_id', $post_id$url );

    if ( ! $post_id ) {
        if ( $switched_blog ) {
            restore_current_blog();
        }

        return false;
    }

    
return new IXR_Error( 403, __( 'Sorry, you must be logged in to comment.' ) );
            } elseif ( ! $allow_anon ) {
                return $this->error;
            }
        } else {
            $logged_in = true;
        }

        if ( is_numeric( $post ) ) {
            $post_id = absint( $post );
        } else {
            $post_id = url_to_postid( $post );
        }

        if ( ! $post_id ) {
            return new IXR_Error( 404, __( 'Invalid post ID.' ) );
        }

        if ( ! get_post( $post_id ) ) {
            return new IXR_Error( 404, __( 'Invalid post ID.' ) );
        }

        if ( ! comments_open( $post_id ) ) {
            
/** * Callback for the embed API endpoint. * * Returns the JSON object for the post. * * @since 4.4.0 * * @param WP_REST_Request $request Full data about the request. * @return array|WP_Error oEmbed response data or WP_Error on failure. */
    public function get_item( $request ) {
        $post_id = url_to_postid( $request['url'] );

        /** * Filters the determined post ID. * * @since 4.4.0 * * @param int $post_id The post ID. * @param string $url The requested URL. */
        $post_id = apply_filters( 'oembed_request_post_id', $post_id$request['url'] );

        
Home | Imprint | This part of the site doesn't use cookies.