post_type_exists example

$fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'cap', 'taxonomies' ), 'wp.getPostType' );
        }

        $user = $this->login( $username$password );
        if ( ! $user ) {
            return $this->error;
        }

        /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
        do_action( 'xmlrpc_call', 'wp.getPostType', $args$this );

        if ( ! post_type_exists( $post_type_name ) ) {
            return new IXR_Error( 403, __( 'Invalid post type.' ) );
        }

        $post_type = get_post_type_object( $post_type_name );

        if ( ! current_user_can( $post_type->cap->edit_posts ) ) {
            return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type.' ) );
        }

        return $this->_prepare_post_type( $post_type$fields );
    }

    
wp_send_json_error( 'illegal_params', 400 );
        }

        $params = array_merge(
            array(
                'post_type'  => '',
                'post_title' => '',
            ),
            $params
        );

        if ( empty( $params['post_type'] ) || ! post_type_exists( $params['post_type'] ) ) {
            status_header( 400 );
            wp_send_json_error( 'missing_post_type_param' );
        }

        $post_type_object = get_post_type_object( $params['post_type'] );
        if ( ! current_user_can( $post_type_object->cap->create_posts ) || ! current_user_can( $post_type_object->cap->publish_posts ) ) {
            status_header( 403 );
            wp_send_json_error( 'insufficient_post_permissions' );
        }

        $params['post_title'] = trim( $params['post_title'] );
        
$response_format = isset( $request['response-format'] ) ? $request['response-format'] : '';

    if ( ! $response_format || ! in_array( $response_format, array( 'json', 'markup' ), true ) ) {
        $response_format = 'json';
    }

    if ( 'markup' === $response_format ) {
        $args['walker'] = new Walker_Nav_Menu_Checklist();
    }

    if ( 'get-post-item' === $type ) {
        if ( post_type_exists( $object_type ) ) {
            if ( isset( $request['ID'] ) ) {
                $object_id = (int) $request['ID'];

                if ( 'markup' === $response_format ) {
                    echo walk_nav_menu_tree(
                        array_map( 'wp_setup_nav_menu_item', array( get_post( $object_id ) ) ),
                        0,
                        (object) $args
                    );
                } elseif ( 'json' === $response_format ) {
                    echo wp_json_encode(
                        
global $pagenow$wp_importers$hook_suffix$plugin_page$typenow$taxnow;

$page_hook = null;

$editing = false;

if ( isset( $_GET['page'] ) ) {
    $plugin_page = wp_unslash( $_GET['page'] );
    $plugin_page = plugin_basename( $plugin_page );
}

if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) {
    $typenow = $_REQUEST['post_type'];
} else {
    $typenow = '';
}

if ( isset( $_REQUEST['taxonomy'] ) && taxonomy_exists( $_REQUEST['taxonomy'] ) ) {
    $taxnow = $_REQUEST['taxonomy'];
} else {
    $taxnow = '';
}


function is_post_type_hierarchical( $post_type ) {
    if ( ! post_type_exists( $post_type ) ) {
        return false;
    }

    $post_type = get_post_type_object( $post_type );
    return $post_type->hierarchical;
}

/** * Determines whether a post type is registered. * * For more information on this and similar theme functions, check out * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ * Conditional Tags} article in the Theme Developer Handbook. * * @since 3.0.0 * * @see get_post_type_object() * * @param string $post_type Post type name. * @return bool Whether post type is registered. */
$this->value[ $key ] = implode( ' ', $this->value[ $key ] );
            }
        }

        if ( ! isset( $this->value['title'] ) ) {
            $this->value['title'] = '';
        }

        if ( ! isset( $this->value['_invalid'] ) ) {
            $this->value['_invalid'] = false;
            $is_known_invalid        = (
                ( ( 'post_type' === $this->value['type'] || 'post_type_archive' === $this->value['type'] ) && ! post_type_exists( $this->value['object'] ) )
                ||
                ( 'taxonomy' === $this->value['type'] && ! taxonomy_exists( $this->value['object'] ) )
            );
            if ( $is_known_invalid ) {
                $this->value['_invalid'] = true;
            }
        }

        // Remove remaining properties available on a setup nav_menu_item post object which aren't relevant to the setting value.         $irrelevant_properties = array(
            'ID',
            

    $filename = apply_filters( 'export_wp_filename', $wp_filename$sitename$date );

    header( 'Content-Description: File Transfer' );
    header( 'Content-Disposition: attachment; filename=' . $filename );
    header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );

    if ( 'all' !== $args['content'] && post_type_exists( $args['content'] ) ) {
        $ptype = get_post_type_object( $args['content'] );
        if ( ! $ptype->can_export ) {
            $args['content'] = 'post';
        }

        $where = $wpdb->prepare( "{$wpdb->posts}.post_type = %s", $args['content'] );
    } else {
        $post_types = get_post_types( array( 'can_export' => true ) );
        $esses      = array_fill( 0, count( $post_types ), '%s' );

        // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
$in_admin        = false;
        $action          = '';
        $is_block_editor = false;

        if ( $hook_name ) {
            $id = $hook_name;
        } elseif ( ! empty( $GLOBALS['hook_suffix'] ) ) {
            $id = $GLOBALS['hook_suffix'];
        }

        // For those pesky meta boxes.         if ( $hook_name && post_type_exists( $hook_name ) ) {
            $post_type = $id;
            $id        = 'post'; // Changes later. Ends up being $base.         } else {
            if ( str_ends_with( $id, '.php' ) ) {
                $id = substr( $id, 0, -4 );
            }

            if ( in_array( $id, array( 'post-new', 'link-add', 'media-new', 'user-new' ), true ) ) {
                $id     = substr( $id, 0, -4 );
                $action = 'add';
            }
        }
$ancestors = array();

    if ( empty( $object_id ) ) {

        /** This filter is documented in wp-includes/taxonomy.php */
        return apply_filters( 'get_ancestors', $ancestors$object_id$object_type$resource_type );
    }

    if ( ! $resource_type ) {
        if ( is_taxonomy_hierarchical( $object_type ) ) {
            $resource_type = 'taxonomy';
        } elseif ( post_type_exists( $object_type ) ) {
            $resource_type = 'post_type';
        }
    }

    if ( 'taxonomy' === $resource_type ) {
        $term = get_term( $object_id$object_type );
        while ( ! is_wp_error( $term ) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors, true ) ) {
            $ancestors[] = (int) $term->parent;
            $term        = get_term( $term->parent, $object_type );
        }
    } elseif ( 'post_type' === $resource_type ) {
        
Home | Imprint | This part of the site doesn't use cookies.