base ) { return; } wp_enqueue_script( 'mspc-warning-panel', plugin_dir_url( dirname( __FILE__ ) ) . '../js/warning-panel.js', array(), '1.0.0', true ); wp_localize_script( 'mspc-warning-panel', 'mspcWarningPanel', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'action' => self::AJAX_ACTION, ) ); } /** * @param \WP_Post $post */ public function render_classic( $post ) { if ( ! $post instanceof \WP_Post ) { return; } if ( $this->is_block_editor( $post ) ) { // Block editor path renders via admin_notices to avoid double-render. return; } $this->maybe_render( (int) $post->ID ); } public function render_block() { if ( empty( $_GET['post'] ) ) { return; } $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( ! $screen || 'post' !== $screen->base ) { return; } $post_id = isset( $_GET['post'] ) ? absint( wp_unslash( $_GET['post'] ) ) : 0; if ( ! $post_id ) { return; } $post = get_post( $post_id ); if ( ! $post instanceof \WP_Post ) { return; } if ( ! $this->is_block_editor( $post ) ) { return; } $this->maybe_render( $post_id ); } private function maybe_render( $post_id ) { if ( ! current_user_can( 'edit_post', $post_id ) ) { return; } $report = Warning_Report::read( $post_id ); if ( ! $report || empty( $report['categories'] ) ) { return; } $nonce = wp_create_nonce( self::NONCE . $post_id ); //$ajax_url = admin_url( 'admin-ajax.php' ); $dismiss_text = esc_html__( 'Dismiss', '42works-multisite-cpt-migrator' ); echo '
'; printf( '%s', (int) $post_id, esc_attr( $nonce ), wp_kses_post($dismiss_text) ); echo '

'; esc_html_e( 'Some content needs to be filled in before publishing.', '42works-multisite-cpt-migrator' ); echo '

'; $this->render_section_attachments( $report['categories']['attachments'] ?? array() ); $this->render_section_references( $report['categories']['references'] ?? array() ); $this->render_section_parent( $report['categories']['post_parent'] ?? array() ); $this->render_section_taxonomies( $report['categories']['taxonomies'] ?? array() ); $this->render_section_drift( $report['categories']['drift'] ?? array() ); $this->render_section_locations( $report['categories']['locations'] ?? array() ); echo '
'; ?> ' . esc_html__( 'Images / files', '42works-multisite-cpt-migrator' ) . '

'; } private function render_section_references( array $entries ) { if ( empty( $entries ) ) { return; } $by_field = array(); foreach ( $entries as $e ) { $by_field[ $e['field_label'] ?? '' ][] = $e; } echo '

' . esc_html__( 'Linked posts', '42works-multisite-cpt-migrator' ) . '

'; } private function render_section_parent( array $entries ) { if ( empty( $entries ) ) { return; } echo '

' . esc_html__( 'Page parent', '42works-multisite-cpt-migrator' ) . '

'; } private function render_section_taxonomies( array $entries ) { if ( empty( $entries ) ) { return; } echo '

' . esc_html__( 'New taxonomy terms created', '42works-multisite-cpt-migrator' ) . '

'; } private function render_section_drift( array $entries ) { if ( empty( $entries ) ) { return; } $labels = array(); foreach ( $entries as $e ) { $labels[] = '"' . ( $e['field_label'] ?: $e['field_name'] ?? '' ) . '"'; } echo '

' . esc_html__( 'Field-group mismatch', '42works-multisite-cpt-migrator' ) . '

'; } private function render_section_locations( array $entries ) { if ( empty( $entries ) ) { return; } echo '

' . esc_html__( 'Page-specific field groups', '42works-multisite-cpt-migrator' ) . '

'; } private function label_of( $label ) { return '' !== $label ? $label : __( '(unnamed field)', '42works-multisite-cpt-migrator' ); } /** * @param string $new_status * @param string $old_status * @param \WP_Post $post */ public function maybe_clear_on_publish( $new_status, $old_status, $post ) { if ( 'publish' !== $new_status ) { return; } if ( 'publish' === $old_status ) { return; } if ( ! $post instanceof \WP_Post ) { return; } Warning_Report::clear( (int) $post->ID ); } public function handle_dismiss() { $post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0; if ( ! $post_id ) { wp_send_json_error( array( 'message' => 'no_post' ), 400 ); } check_ajax_referer( self::NONCE . $post_id ); if ( ! current_user_can( 'edit_post', $post_id ) ) { wp_send_json_error( array( 'message' => 'forbidden' ), 403 ); } Warning_Report::clear( $post_id ); wp_send_json_success(); } /** * @param \WP_Post $post * @return bool */ private function is_block_editor( $post ) { if ( ! function_exists( 'use_block_editor_for_post' ) ) { return false; } return (bool) use_block_editor_for_post( $post ); } }