Making WordPress.org

Changeset 8720


Ignore:
Timestamp:
05/02/2019 07:51:30 AM (7 years ago)
Author:
coffee2code
Message:

Markdown Importer: Add automatic handling to recognize changes to parenting of manifest items.

Can adapt to newly added, removed, or changed parent.

See #4388.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-markdown/inc/class-importer.php

    r8719 r8720  
    372372                        'post_excerpt' => sanitize_text_field( wp_slash( $excerpt ) ),
    373373                );
     374
     375                $markdown_entry = get_post_meta( $post_id, $this->manifest_entry_meta_key, true );
     376
    374377                // If no title was extracted from markdown doc, use the value defined in manifest.
    375378                if ( is_null( $title ) ) {
    376                         $markdown_entry = get_post_meta( $post_id, $this->manifest_entry_meta_key, true );
    377379                        if ( ! empty( $markdown_entry['title'] ) ) {
    378380                                $post_data['post_title'] = sanitize_text_field( wp_slash( $markdown_entry['title'] ) );
    … …  
    380382                } else {
    381383                        $post_data['post_title'] = sanitize_text_field( wp_slash( $title ) );
     384                }
     385
     386                $parent_id = wp_get_post_parent_id( $post_id );
     387
     388                if ( ! $markdown_entry ) {
     389                        // Do nothing with regards to possibly changing post parent as we know
     390                        // nothing about previous import.
     391                }
     392                // If post had a parent...
     393                elseif ( $parent_id ) {
     394                        $parent = $parent_id ? get_post( $parent_id ) : null;
     395                        // ...but no parent is now defined, unset parent.
     396                        if ( empty( $markdown_entry['parent'] ) ) {
     397                                $post_data['post_parent'] = '';
     398                        }
     399                        // ...and it appears to differ from parent now defined, find new parent.
     400                        elseif ( $markdown_entry['parent'] !== $parent->post_name ) {
     401                                $find_parent = get_page_by_path( $markdown_entry['parent'], OBJECT, $this->get_post_type() );
     402                                if ( $find_parent ) {
     403                                        $post_data['post_parent'] = $find_parent->ID;
     404                                }
     405                        }
     406                }
     407                // Does this parentless post now have one newly defined?
     408                elseif ( ! empty( $markdown_entry['parent'] ) ) {
     409                        $find_parent = get_page_by_path( $markdown_entry['parent'], OBJECT, $this->get_post_type() );
     410                        if ( $find_parent ) {
     411                                $post_data['post_parent'] = $find_parent->ID;
     412                        }
    382413                }
    383414
Note: See TracChangeset for help on using the changeset viewer.