| @@ -2,8 +2,10 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Generate the XML for export for posts and form actions. |
| 4 | 4 | * |
| 5 | 5 | * @phpcs:disable Generic.WhiteSpace.ScopeIndent.Incorrect |
| 6 | + * | |
| 7 | + * @package Formidable | |
| 6 | 8 | */ |
| 7 | 9 | |
| 8 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | 11 | die( 'You are not allowed to call this page directly.' ); |
| @@ -13,11 +15,12 @@ | ||
| 13 | 15 | return; |
| 14 | 16 | } |
| 15 | 17 | |
| 16 | 18 | global $wp_query; |
| 17 | -$wp_query->in_the_loop = true; // Fake being in the loop. | |
| 19 | +// Fake being in the loop. | |
| 20 | +$wp_query->in_the_loop = true; | |
| 18 | 21 | |
| 19 | -// fetch 20 posts at a time rather than loading the entire table into memory | |
| 22 | +// Fetch 20 posts at a time rather than loading the entire table into memory | |
| 20 | 23 | while ( $next_posts = array_splice( $item_ids, 0, 20 ) ) { |
| 21 | 24 | $posts = FrmDb::get_results( $wpdb->posts, array( 'ID' => $next_posts ) ); |
| 22 | 25 | |
| 23 | 26 | // Begin Loop |
| @@ -45,12 +48,13 @@ | ||
| 45 | 48 | <post_password><?php echo FrmXMLHelper::cdata( $post->post_password ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></post_password> |
| 46 | 49 | <is_sticky><?php echo esc_html( $is_sticky ); ?></is_sticky> |
| 47 | 50 | <?php if ( 'attachment' === $post->post_type ) : ?> |
| 48 | 51 | <attachment_url><?php echo esc_url( wp_get_attachment_url( $post->ID ) ); ?></attachment_url> |
| 49 | -<?php | |
| 52 | + <?php | |
| 50 | 53 | endif; |
| 51 | 54 | |
| 52 | 55 | $postmeta = FrmDb::get_results( $wpdb->postmeta, array( 'post_id' => $post->ID ) ); |
| 56 | + | |
| 53 | 57 | foreach ( $postmeta as $meta ) : |
| 54 | 58 | if ( apply_filters( 'wxr_export_skip_postmeta', false, $meta->meta_key, $meta ) ) { |
| 55 | 59 | continue; |
| 56 | 60 | } |
| @@ -62,9 +66,10 @@ | ||
| 62 | 66 | <?php |
| 63 | 67 | endforeach; |
| 64 | 68 | |
| 65 | 69 | $taxonomies = get_object_taxonomies( $post->post_type ); |
| 66 | - if ( ! empty( $taxonomies ) ) { | |
| 70 | + | |
| 71 | + if ( $taxonomies ) { | |
| 67 | 72 | $terms = wp_get_object_terms( $post->ID, $taxonomies ); |
| 68 | 73 | |
| 69 | 74 | foreach ( (array) $terms as $term ) { |
| 70 | 75 | ?> |
| @@ -74,22 +79,25 @@ | ||
| 74 | 79 | } |
| 75 | 80 | |
| 76 | 81 | if ( 'frm_display' === $post->post_type && is_callable( 'FrmViewsLayout::get_layouts_for_view' ) ) { |
| 77 | 82 | $layouts = FrmViewsLayout::get_layouts_for_view( $post->ID ); |
| 78 | - foreach ( $layouts as $layout ) { | |
| 79 | - ?> | |
| 83 | + | |
| 84 | + if ( is_array( $layouts ) ) { | |
| 85 | + foreach ( $layouts as $layout ) { | |
| 86 | + ?> | |
| 80 | 87 | <layout> |
| 81 | 88 | <type><?php echo esc_html( $layout->type ); ?></type> |
| 82 | 89 | <data><?php echo FrmXMLHelper::cdata( $layout->data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></data> |
| 83 | 90 | </layout> |
| 84 | 91 | <?php |
| 92 | + } | |
| 85 | 93 | } |
| 86 | 94 | } |
| 87 | 95 | ?> |
| 88 | 96 | </view> |
| 89 | 97 | <?php |
| 90 | - } | |
| 91 | -} | |
| 98 | + }//end foreach | |
| 99 | +}//end while | |
| 92 | 100 | |
| 93 | 101 | if ( empty( $taxonomies ) ) { |
| 94 | 102 | return; |
| 95 | 103 | } |
| @@ -94,26 +102,33 @@ | ||
| 94 | 102 | return; |
| 95 | 103 | } |
| 96 | 104 | |
| 97 | 105 | global $frm_inc_tax; |
| 98 | -if ( empty( $frm_inc_tax ) ) { | |
| 106 | + | |
| 107 | +if ( ! $frm_inc_tax ) { | |
| 99 | 108 | $frm_inc_tax = array(); |
| 100 | 109 | } |
| 101 | 110 | |
| 111 | +$parent_slugs = FrmXMLController::get_parent_terms_slugs( $terms ); | |
| 112 | + | |
| 102 | 113 | foreach ( (array) $terms as $term ) { |
| 103 | 114 | if ( in_array( $term->term_id, $frm_inc_tax, true ) ) { |
| 104 | - return; | |
| 115 | + continue; | |
| 105 | 116 | } |
| 106 | 117 | |
| 107 | 118 | $frm_inc_tax[] = $term->term_id; |
| 108 | - $label = ( 'category' === $term->taxonomy || 'tag' === $term->taxonomy ) ? $term->taxonomy : 'term'; | |
| 109 | 119 | ?> |
| 110 | 120 | <term><term_id><?php echo esc_html( $term->term_id ); ?></term_id><term_taxonomy><?php echo esc_html( $term->taxonomy ); ?></term_taxonomy><?php |
| 121 | + if ( ! empty( $parent_slugs[ $term->parent ] ) ) { | |
| 122 | + echo '<term_parent>' . esc_html( $parent_slugs[ $term->parent ] ) . '</term_parent>'; | |
| 123 | + } | |
| 124 | + | |
| 111 | 125 | if ( ! empty( $term->name ) ) { |
| 112 | 126 | echo '<term_name>' . FrmXMLHelper::cdata( $term->name ) . '</term_name>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 113 | 127 | } |
| 128 | + | |
| 114 | 129 | if ( ! empty( $term->description ) ) { |
| 115 | 130 | echo '<term_description>' . FrmXMLHelper::cdata( $term->description ) . '</term_description>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 116 | 131 | } |
| 117 | 132 | echo '<term_slug>' . esc_html( $term->slug ) . '</term_slug>'; |
| 118 | 133 | echo '</term>'; |
| 119 | -} | |
| 134 | +}//end foreach | |