page_url( $this->plugin_page_setup['parent_slug'], false ); if ( empty( $url ) ) { $url = self_admin_url( $this->plugin_page_setup['parent_slug'] ); } return add_query_arg( $parameters, $url ); } /** * Redirect from the old default OCDI settings page URL to the new one. */ public function redirect_from_old_default_admin_page() { global $pagenow; if ( $pagenow == 'themes.php' && isset( $_GET['page'] ) && $_GET['page'] == 'pt-one-click-demo-import' ) { wp_safe_redirect( $this->get_plugin_settings_url() ); exit; } } /** * Add imported terms. * * Mainly it's needed for saving all imported terms and trigger terms count updates. * WP core term defer counting is not working, since import split to chunks and we are losing `$_deffered` array * items between ajax calls. */ public function add_imported_terms( $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids ){ if ( ! isset( $this->imported_terms[ $taxonomy ] ) ) { $this->imported_terms[ $taxonomy ] = array(); } $this->imported_terms[ $taxonomy ] = array_unique( array_merge( $this->imported_terms[ $taxonomy ], $tt_ids ) ); } /** * Returns an empty array if current attachment to be imported is in the failed imports list. * * This will skip the current attachment import. * * @since 3.2.0 * * @param array $data Post data to be imported. * * @return array */ public function skip_failed_attachment_import( $data ) { // Check if failed import. if ( ! empty( $data ) && ! empty( $data['post_type'] ) && $data['post_type'] === 'attachment' && ! empty( $data['attachment_url'] ) ) { // Get the previously failed imports. $failed_media_imports = Helpers::get_failed_attachment_imports(); if ( ! empty( $failed_media_imports ) && in_array( $data['attachment_url'], $failed_media_imports, true ) ) { // If the current attachment URL is in the failed imports, then skip it. return []; } } return $data; } /** * Save the failed attachment import. * * @since 3.2.0 * * @param WP_Error $post_id Error object. * @param array $data Raw data imported for the post. * @param array $meta Raw meta data, already processed. * @param array $comments Raw comment data, already processed. * @param array $terms Raw term data, already processed. */ public function handle_failed_attachment_import( $post_id, $data, $meta, $comments, $terms ) { if ( empty( $data ) || empty( $data['post_type'] ) || $data['post_type'] !== 'attachment' ) { return; } Helpers::set_failed_attachment_import( $data['attachment_url'] ); } /** * Save the information needed to process the navigation block. * * @since 3.2.0 * * @param int $post_id The new post ID. * @param int $original_id The original post ID. * @param array $postdata The post data used to insert the post. * @param array $data Post data from the WXR file. */ public function save_wp_navigation_import_mapping( $post_id, $original_id, $postdata, $data ) { if ( empty( $postdata['post_content'] ) ) { return; } if ( $postdata['post_type'] !== 'wp_navigation' ) { /* * Save the post ID that has navigation block in transient. */ if ( strpos( $postdata['post_content'], '' ] = ''; } // Loop through each the posts that needs to be updated. foreach ( $posts_nav_block as $post_id ) { $post_nav_block = get_post( $post_id ); if ( empty( $post_nav_block ) || empty( $post_nav_block->post_content ) ) { return; } wp_update_post( [ 'ID' => $post_id, 'post_content' => strtr( $post_nav_block->post_content, $replace_pairs ), ] ); } } /** * Update imported terms count. */ private function update_terms_count() { foreach ( $this->imported_terms as $tax => $terms ) { wp_update_term_count_now( $terms, $tax ); } } /** * Get the import buttons HTML for the successful import page. * * @since 3.2.0 * * @return string */ public function get_import_successful_buttons_html() { /** * Filter the buttons that are displayed on the successful import page. * * @since 3.2.0 * * @param array $buttons { * Array of buttons. * * @type string $label Button label. * @type string $class Button class. * @type string $href Button URL. * @type string $target Button target. Can be `_blank`, `_parent`, `_top`. Default is `_self`. * } */ $buttons = Helpers::apply_filters( 'ocdi/import_successful_buttons', [ [ 'label' => __( 'Theme Settings' , 'one-click-demo-import' ), 'class' => 'button button-primary button-hero', 'href' => admin_url( 'customize.php' ), 'target' => '_blank', ], [ 'label' => __( 'Visit Site' , 'one-click-demo-import' ), 'class' => 'button button-primary button-hero', 'href' => get_home_url(), 'target' => '_blank', ], ] ); if ( empty( $buttons ) || ! is_array( $buttons ) ) { return ''; } ob_start(); foreach ( $buttons as $button ) { if ( empty( $button['href'] ) || empty( $button['label'] ) ) { continue; } $target = '_self'; if ( ! empty( $button['target'] ) && in_array( strtolower( $button['target'] ), [ '_blank', '_parent', '_top' ], true ) ) { $target = $button['target']; } $class = 'button button-primary button-hero'; if ( ! empty( $button['class'] ) ) { $class = $button['class']; } printf( '%4$s', esc_url( $button['href'] ), esc_attr( $class ), esc_attr( $target ), esc_html( $button['label'] ) ); } $buttons_html = ob_get_clean(); return empty( $buttons_html ) ? '' : $buttons_html; } }