Plugin Directory

Changeset 1792532


Ignore:
Timestamp:
12/26/2017 11:02:05 AM (8 years ago)
Author:
codexdemon
Message:

Custom post type of any type of post status (like woocommerce status wc-completed) data will export now. Before file only the default status data get occur.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • all-in-one-demo-importexport/trunk/classes/class-aiodie-core.php

    r1791151 r1792532  
    190190
    191191        $status = get_post_statuses();
    192         $comment = get_comments();
     192        $comment = get_comments(array('numberposts' => -1));
    193193        $menu = get_registered_nav_menus();
    194194        $tags = get_tags(array('get'=>'all'));
     
    196196
    197197       
    198         if(!empty($_GET['aiodie-export-customize']) && !empty($_GET['aiodie-export-content'])){ /* Code for Get the customizer and all content data */
    199 
     198        if(!empty($_GET['aiodie-export-customize']) && !empty($_GET['aiodie-export-content'])){
     199
     200            /* Code for Get the customizer and all content data */
    200201            $data = array(
    201202                'template'  => $template,
     
    216217           
    217218        }else if(!empty($_GET['aiodie-export-customize']) && !empty($_GET['aiodie-post-export'])){
     219
    218220            /* Code for the customizer and all post data */
    219 
    220221            $cat = $_GET['postform'];
    221222            $postauthor = $_GET['post-author'];
     
    248249            $postcontent = $query->posts;
    249250            $tags = get_tags();
    250             $comment = get_comments();
     251            $comment = get_comments(array('numberposts' => -1));
    251252            $postcontcategory = array();
    252253            $termcontlist = array();
     
    349350            $otherargs = array(
    350351                'post_type' => $postty,
    351                 'posts_per_page' => -1
     352                'posts_per_page' => -1,
     353                'orderby'       => 'title', // or 'date', 'rand'
     354                'order'         => 'ASC', // or 'DESC'
     355                'post_status'   => 'any',
    352356            // Several more arguments could go here. Last one without a comma.
    353             );
     357            );
    354358            $query = new WP_Query( $otherargs );
    355359            $othercontent = $query->posts;
    356360            $taxonomies = get_object_taxonomies($postty);
     361            $comments = get_comments(array('numberposts' => -1));   
    357362            $customotherfields = array();
    358363            $postothercategory = array();
    359364            $postotherthumbnail_url =array();
    360            
    361365            $taxo = array();
    362366            $getterms = '';
     
    368372                $thumbnailpostother_url = wp_get_attachment_image_src(get_post_thumbnail_id($othercont->ID), array('220','220'), true );
    369373                $postotherthumbnail_url[$othercont->ID] = $thumbnailpostother_url[0];
    370            
    371                
     374
    372375                foreach ($taxonomies as $taxonomy) {
    373376                    $taxo[] = $taxonomy;
     
    392395                'post_category' => $postothercategory,
    393396                'custom_fields' => $customotherfields,
     397                'comment'   => $comments,
    394398            );
    395399           
    396400        }else if(!empty($_GET['aiodie-export-customize'])) {
    397 
    398401            /* Code for Get the customizer data */
    399402            $data = array(
     
    456459            $postcontent = $query->posts;
    457460            $tags = get_tags();
    458             $comment = get_comments();
     461            $comment = get_comments(array('numberposts' => -1));
    459462            $postcontcategory = array();
    460463            $termcontlist = array();
     
    464467
    465468            foreach($postcontent as $postcont){
    466 
    467469                $customcont = get_post_custom($postcont->ID);
    468470                $customcontfields[$postcont->ID] = $customcont;
     
    491493        }else if(!empty($_GET['aiodie-page-export'])){
    492494            /* Code for Get the all page data */
    493 
    494495            $pageauthor = $_GET['page-author'];
    495496            $pagestartdate = date( 'Y-m-d', strtotime($_GET['page_str_date']));
     
    515516            $customcontentfieldspage = array();
    516517            $pagecontentthumbnail_url = array();
     518
    517519            foreach($pagecontent as $pagecontentpost){
    518 
    519520                $customcontentfil = get_post_custom($pagecontentpost->ID);
    520521                $customcontentfieldspage[$pagecontentpost->ID] = $customcontentfil;
     
    546547
    547548            $postty = $_GET['post_type'];
    548 
    549549            $otherargs = array(
    550550                'post_type' => $postty,
    551                 'posts_per_page' => -1
     551                'posts_per_page' => -1,
     552                'orderby'       => 'title', // or 'date', 'rand'
     553                'order'         => 'ASC', // or 'DESC'
     554                'post_status'   => 'any',
    552555            // Several more arguments could go here. Last one without a comma.
    553             );
     556            );
    554557            $query = new WP_Query( $otherargs );
    555558            //$categories = get_categories($otherargs);
     
    557560            $othercontent = $query->posts;
    558561            $taxonomies = get_object_taxonomies($postty);
    559 
    560562            $customotherfields = array();
    561563            $postothercategory = array();
    562564            $postotherthumbnail_url = array();
    563        
    564565            $taxo = array();
    565566            $getterms = '';
    566 
     567            $comments = get_comments(array('numberposts' => -1));
     568           
    567569            foreach($othercontent as $othercont){
    568570
     
    571573                $thumbnailpostother_url = wp_get_attachment_image_src(get_post_thumbnail_id($othercont->ID), array('220','220'), true );
    572574                $postotherthumbnail_url[$othercont->ID] = $thumbnailpostother_url[0];
    573                
     575
    574576                foreach ($taxonomies as $taxonomy) {
    575577
     
    583585                    $postothercategory[$othercont->ID] = $postterm;
    584586                }
    585 
    586             }
    587 
     587            }
    588588            /* Code for Get the all attachment data */
    589589            $data = array(
     
    593593                'post_category' => $postothercategory,
    594594                'custom_fields' => $customotherfields,
    595             );
    596        
    597 
    598            
    599         }
    600    
     595                'comment'   => $comments,
     596            );
     597
     598        }
     599       
    601600        // Get options from the Customizer API.
    602601        $settings = $wp_customize->settings();
     
    639638        header( 'Content-Type: application/octet-stream; charset=' . $charset );
    640639
    641         //var_dump($data);
    642640        // Serialize the export data.
    643641        echo serialize($data);
     
    717715        }
    718716       
    719         if ( $data['template'] != $template ) {
    720 
    721         }   
     717        // if ( $data['template'] != $template ) { 
     718
     719        // }   
    722720        //Import images.
    723721        if ( isset( $_REQUEST['aiodie-import-images'] ) ) {
     
    733731                $post_author = $lesson->post_author;
    734732                $post_content = $lesson->post_content;
    735                 $post_type = $lesson->post_type;   
     733                $post_type = $lesson->post_type;
     734                $post_status = $lesson->post_status;   
    736735                $check_title=get_page_by_title($post_title, 'OBJECT', 'post');
    737        
     736
    738737                if (empty($check_title) ){
    739738                    $my_post = array(
    740739                        'post_title'    => $post_title,
    741740                        'post_content'  => $post_content,
    742                         'post_status'   => 'publish',
     741                        'post_status'   => $post_status,
    743742                        'post_author'   => $post_author,
    744743                        'post_type'     => $post_type,
    745744                    );
    746745                    $post_insert = wp_insert_post( $my_post );
    747                 }
    748                 else {
     746                }else{
    749747                    $my_post = array(
    750748                        'ID' =>  $check_title->ID,
    751749                        'post_title'    => $post_title,
    752750                        'post_content'  => $post_content,
    753                         'post_status'   => 'publish',
     751                        'post_status'   => $post_status,
    754752                        'post_author'   => $post_author,
    755753                        'post_type'     => $post_type,
    756 
    757754                    );
    758755                    $post_insert = wp_update_post( $my_post ); 
     
    760757
    761758                if (isset($data['tags_input'])){
    762                 wp_set_post_tags($post_insert, $data['tags_input'][$post_id], true);
     759                    wp_set_post_tags($post_insert, $data['tags_input'][$post_id], true);
    763760                }
    764761
    765762                if (isset($data['custom_fields'])){
    766763
    767                 $customdata = $data['custom_fields'][$post_id];
    768                
    769                 foreach($customdata as $metakey => $metavalue){
    770                     foreach($metavalue as $value){
    771                         add_post_meta( $post_insert, $metakey, $value, true );
    772                        
    773                     }
     764                    $customdata = $data['custom_fields'][$post_id];
     765
     766                    foreach($customdata as $metakey => $metavalue){
     767                        foreach($metavalue as $value){
     768                            add_post_meta( $post_insert, $metakey, $value, true );
     769
     770                        }
     771                    }   
    774772                }   
    775             }   
    776773
    777774                // Need to require these files
     
    832829                $post_content = $lesson->post_content;
    833830                $post_type = $lesson->post_type;
     831                $post_status = $lesson->post_status;
    834832                $check_title=get_page_by_title($post_title, 'OBJECT', 'page');
    835833
     
    839837                        'post_title'    => $post_title,
    840838                        'post_content'  => $post_content,
    841                         'post_status'   => 'publish',
     839                        'post_status'   => $post_status,
    842840                        'post_type'     => $post_type,
    843841                        'post_author'   => $post_author,
    844842                    );
    845843                    $page_insert = wp_insert_post( $my_post );
    846                 }
    847                 else {
     844                }else{
    848845                    $my_post = array(
    849846                        'ID' =>  $check_title->ID,
    850847                        'post_title'    => $post_title,
    851848                        'post_content'  => $post_content,
    852                         'post_status'   => 'publish',
     849                        'post_status'   => $post_status,
    853850                        'post_type'     => $post_type,
    854851                        'post_author'   => $post_author,
     
    858855               
    859856                if(isset($data['custom_fieldspage'])){
    860                 $custompagedata = $data['custom_fieldspage'][$page_id];         
    861                 foreach($custompagedata as $metapagekey => $metapagevalue){
    862                     foreach($metapagevalue as $val){
    863                         add_post_meta( $page_insert, $metapagekey, $val, true );       
     857                    $custompagedata = $data['custom_fieldspage'][$page_id];         
     858                    foreach($custompagedata as $metapagekey => $metapagevalue){
     859                        foreach($metapagevalue as $val){
     860                            add_post_meta( $page_insert, $metapagekey, $val, true );       
     861                        }
    864862                    }
    865                 }
    866863                }
    867864                // Need to require these files
     
    897894
    898895                // If error storing permanently, unlink
    899                 if ( is_wp_error($id) ) {
     896                if ( is_wp_error($id) ){
    900897                    @unlink($file_array['tmp_name']);
    901898                    return $id;
     
    916913
    917914            if ($data['category'] != ''){
    918 
    919             /* code for upload the category */
    920             $category_map = array();
    921             foreach($data['category'] as $key => $lesson)
    922             {   
    923                 $category = $lesson->cat_ID;
    924                 $term_id = $lesson->term_id;
    925                 $cat_name = $lesson->name;
    926                
    927                 $cat_slug = $lesson->slug;
    928                 $taxonomy = $lesson->taxonomy;
    929 
    930                 $term = term_exists($cat_name, $taxonomy);
    931                 if ($term !== 0 && $term !== null)
    932                 {
    933                     $termid = $term['term_id'];
    934                     $term = wp_update_term($termid, $taxonomy );
    935                    
    936                     $category_map[$term_id] = $term['term_id'];
    937                 }
    938                 else
    939                 {
    940                     $term_ins = wp_insert_term($cat_name, $taxonomy, array('slug' => $cat_slug) );
    941                     $category_map[$term_id] = $term_ins['term_id'];
    942                 }
    943 
    944             }
    945            
    946             foreach($postid as $key => $value1){
    947 
    948                 $post_categories = $data['post_category'][$key];       
    949                 $newcat = array();
    950                 foreach( $post_categories as $cat){
    951                     foreach($data['category'] as $key => $lesson){
    952                         $newcat[] = $category_map[$cat];   
    953                         $term_id = $lesson->term_id;
    954                         $taxonomy = $lesson->taxonomy;
    955                         if($taxonomy == 'category'){
    956                             wp_set_post_categories($value1, $newcat);
    957                         }else{
    958                             wp_set_post_terms($value1, $newcat, $taxonomy);
    959 
    960                         }
    961                     }   
    962                 }           
    963                
    964             }   
     915                /* code for upload the category */
     916                $category_map = array();
     917                foreach($data['category'] as $key => $lesson){ 
     918                    $category = $lesson->cat_ID;
     919                    $term_id = $lesson->term_id;
     920                    $cat_name = $lesson->name;
     921                    $cat_slug = $lesson->slug;
     922                    $taxonomy = $lesson->taxonomy;
     923
     924                    $term = term_exists($cat_name, $taxonomy);
     925                    if ($term !== 0 && $term !== null){
     926                        $termid = $term['term_id'];
     927                        $term = wp_update_term($termid, $taxonomy );
     928
     929                        $category_map[$term_id] = $term['term_id'];
     930                    }else{
     931                        $term_ins = wp_insert_term($cat_name, $taxonomy, array('slug' => $cat_slug) );
     932                        $category_map[$term_id] = $term_ins['term_id'];
     933                    }
     934                }
     935
     936                foreach($postid as $key => $value1){
     937
     938                    $post_categories = $data['post_category'][$key];       
     939                    $newcat = array();
     940                    foreach( $post_categories as $cat){
     941                        foreach($data['category'] as $key => $lesson){
     942                            $newcat[] = $category_map[$cat];   
     943                            $term_id = $lesson->term_id;
     944                            $taxonomy = $lesson->taxonomy;
     945                            if($taxonomy == 'category'){
     946                                wp_set_post_categories($value1, $newcat);
     947                            }else{
     948                                wp_set_post_terms($value1, $newcat, $taxonomy);
     949                            }
     950                        }   
     951                    }               
     952                }   
    965953            }       
    966954        }
    967955       
    968         if ( isset( $data['tags'] ) ) {
     956        if ( isset( $data['tags'] ) )
    969957            /* code for upload the tags */ 
    970958            $tags_map = array();
     
    977965                $term = term_exists($tag_name, 'post_tag');
    978966                if ($term !== 0 && $term !== null) {
    979                     $termid = $term['term_id'];
    980                     $term = wp_update_term($termid, $taxonomy );
    981                    
     967                    $termid = $term['term_id'];
     968                    $term = wp_update_term($termid, $taxonomy );
     969
    982970                    $tags_map[$term_id] = $term['term_id'];
    983971                }else{
     
    987975            }
    988976        }
    989         if ( isset( $data['comment'] ) ) 
     977        if ( isset( $data['comment'] ) ){   
    990978            /* code for upload the comment */
    991979            foreach($data['comment'] as $key => $lesson){
     
    10271015                $userlogin = $lesson->user_login;
    10281016                $user_id = $lesson->ID;
    1029                 if(username_exists( $user_login ))
    1030                 {
     1017                if(username_exists( $user_login )){
    10311018                    //echo '---------';
    10321019                    // echo "Username already exists";
    1033                 }
    1034                 else
    1035                 {
     1020                }else{
    10361021                    $userdata = array(
    10371022                        'user_login'  =>  $userlogin,
     
    10451030                        echo "User created : ". $user_id;
    10461031                    }
    1047 
    10481032                }           
    10491033            }
     
    10971081                    set_post_thumbnail($pagepid, $attachments[0]->ID);
    10981082                }
    1099 
    1100             }
    1101 
     1083            }
    11021084        }
    11031085
     
    11231105        // Loop through the mods.
    11241106        if(isset($data['mods'])){
    1125         foreach ( $data['mods'] as $key => $val ) {
     1107            foreach ( $data['mods'] as $key => $val ) {
    11261108
    11271109            // Call the customize_save_ dynamic action.
    1128             do_action( 'customize_save_' . $key, $wp_customize );
     1110                do_action( 'customize_save_' . $key, $wp_customize );
    11291111            // Save the mod.
    1130             set_theme_mod( $key, $val );
    1131         }
     1112                set_theme_mod( $key, $val );
     1113            }
    11321114        }
    11331115        // Call the customize_save_after action.
     
    11621144                }
    11631145            }
    1164         }
    1165        
     1146        }   
    11661147        return $mods;
    11671148    }
     
    12071188                return $id;
    12081189            }
    1209 
    12101190            // Build the object to return.
    12111191            $meta                   = wp_get_attachment_metadata( $id );
     
    12161196            $data->width            = $meta['width'];
    12171197        }
    1218 
    12191198        return $data;
    12201199    }
     
    12301209    static private function _is_image_url( $string = '' )
    12311210    {
    1232         if ( is_string( $string ) ) {
    1233            
     1211        if ( is_string( $string ) ) {   
    12341212            if ( preg_match( '/\.(jpg|jpeg|png|gif)/i', $string ) ) {
    12351213                return true;
    12361214            }
    1237         }
    1238        
     1215        }   
    12391216        return false;
    12401217    }
Note: See TracChangeset for help on using the changeset viewer.