82 | | |
| 82 | if ( isset( $_GET['postId'] ) ) { |
| 83 | $postId = (int) $_GET['postId']; |
| 84 | $postType = sanitize_key( $_GET['postType'] ); |
| 85 | |
| 86 | switch ( $postType ) { |
| 87 | case 'page': |
| 88 | $post = get_post( $postId ); |
| 89 | |
| 90 | if ( null === $post ) { |
| 91 | wp_die( __( 'Invalid post ID.' ) ); |
| 92 | } |
| 93 | |
| 94 | // Check the post status |
| 95 | switch ( $post->post_status ) { |
| 96 | case 'draft': |
| 97 | wp_die( sprintf( __( 'This page is currently a draft. Please <a href="%s">publish it</a> to edit.' ), get_edit_post_link( $postId, 'edit' ) ) ); |
| 98 | case 'trash': |
| 99 | wp_die( sprintf( __( 'This page is in the trash. Please <a href="%s">restore it</a> before editing.' ), get_edit_post_link( $postId, 'edit' ) ) ); |
| 100 | case 'publish': |
| 101 | // Continue if the post is published |
| 102 | break; |
| 103 | default: |
| 104 | wp_die( __( 'This page has an invalid status.' ) ); |
| 105 | } |
| 106 | break; |
| 107 | |
| 108 | case 'wp_block': |
| 109 | $post = get_post( $postId ); |
| 110 | |
| 111 | if ( null === $post ) { |
| 112 | wp_die( __( 'Invalid pattern ID.' ) ); |
| 113 | } |
| 114 | break; |
| 115 | |
| 116 | case 'wp_template': |
| 117 | $block_template = get_block_template( $postId ); |
| 118 | |
| 119 | if ( null === $block_template ) { |
| 120 | wp_die( __( 'Invalid template ID.' ) ); |
| 121 | } |
| 122 | break; |
| 123 | |
| 124 | case 'wp_template_part': |
| 125 | $block_template = get_block_template( $postId, 'wp_template_part' ); |
| 126 | |
| 127 | if ( null === $block_template ) { |
| 128 | wp_die( __( 'Invalid template part ID.' ) ); |
| 129 | } |
| 130 | break; |
| 131 | |
| 132 | default: |
| 133 | wp_die( __( 'Invalid post type.' ) ); |
| 134 | } |
| 135 | } |