Plugin Directory

Changeset 2578596


Ignore:
Timestamp:
08/05/2021 09:34:20 AM (4 years ago)
Author:
biztechc
Message:

compatible with 5.8

Location:
copy-or-move-comments/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • copy-or-move-comments/trunk/copy_move_comments.php

    r2273822 r2578596  
    44  Plugin URI:
    55  Description: Using Copy/Move WordPress Plugin the admin can copy or move any comment from several types of pages to any other page!
    6   Version: 5.0.1
     6  Version: 5.0.2
    77  Author: biztechc
    88  Author URI: https://www.appjetty.com/
     
    3838            if (isset($_REQUEST['settings-updated']) == 'true') {
    3939                ?>
    40                 <div class="updated notice notice-success is-dismissible" id="message"><p>Setting updated.</p><button class="notice-dismiss" type="button"><span class="screen-reader-text">Dismiss this notice.</span></button></div>
     40                <div class="updated notice notice-success is-dismissible" id="message"><p>Setting updated.</p><button class="notice-dismiss" type="button"><span class="screen-reader-text">Dismiss this notice.</span></button></div>   
    4141                <?php
    4242            }
     
    5757                                }
    5858                                ?>
    59                                 <input type="checkbox" id="all_private_post_type" name="all_private_post_type" <?php if (isset($checked)) echo $checked; ?> />
    60                                 <label for="all_private_post_type">Include Private Posts?</label><br>
     59                                <input type="checkbox" name="all_private_post_type" <?php if (isset($checked)) echo $checked; ?>><label>Include Private Posts?</label><br>
    6160                                <?php
    6261                                $checked = '';
     
    9998                    ?>
    10099                    <div class="tablenav top">
    101                         <big style="float: left; margin-top: 5px; margin-right: 7px;"><?php _e("Action"); ?>:</big>
     100                        <big style="float: left; margin-top: 5px; margin-right: 7px;"><?php _e("Action"); ?>:</big> 
    102101                        <div class="alignleft actions">
    103102                            <label class="screen-reader-text">Select Action</label>
     
    108107                            </select>
    109108                        </div>
    110                         <big style="float: left; margin-top: 5px; margin-right: 7px;"><?php _e("Source"); ?>:</big>
     109                        <big style="float: left; margin-top: 5px; margin-right: 7px;"><?php _e("Source"); ?>:</big> 
    111110                        <div class="alignleft actions">
    112111                            <?php
     
    122121                                foreach ($post_types as $post_type) {
    123122                                    ?>
    124                                     <option value="<?php echo $post_type; ?>"><?php echo $post_type; ?></option>
     123                                    <option value="<?php echo $post_type; ?>"><?php echo $post_type; ?></option> 
    125124
    126125                                <?php }
     
    137136                        </div>
    138137                        <div class="alignleft actions" id="comment_history">
    139                             <big style="float: left; margin-top: 5px; margin-right: 7px;"><?php _e("Select Comment Type"); ?>:</big>
     138                            <big style="float: left; margin-top: 5px; margin-right: 7px;"><?php _e("Select Comment Type"); ?>:</big> 
    140139                            <select id="comment_type" name="comment_type">
    141140                                <option value="0">Select Comment Type</option>
     
    150149                    <div id="get_comments"></div>
    151150                    <div class="tablenav bottom" style="display: none;">
    152                         <big style="float: left; margin-top: 5px; margin-right: 10px;"><?php _e("Target"); ?>:</big>
    153                         <div class="alignleft actions">
     151                        <big style="float: left; margin-top: 5px; margin-right: 10px;"><?php _e("Target"); ?>:</big> 
     152                        <div class="alignleft actions"> 
    154153                            <?php
    155154                            $target_post_types = get_post_types('', 'names');
     
    157156                            unset($target_post_types['revision']);
    158157                            unset($target_post_types['nav_menu_item']);
    159                             ?>
     158                            ?>                               
    160159                            <select name="target_all_post_types" id="target_all_post_types">
    161160                                <option value="0">Select Post Type</option>
     
    163162                                foreach ($target_post_types as $target_post_type) {
    164163                                    ?>
    165                                     <option value="<?php echo $target_post_type; ?>"><?php echo $target_post_type; ?></option>
     164                                    <option value="<?php echo $target_post_type; ?>"><?php echo $target_post_type; ?></option> 
    166165                                    <?php
    167166                                }
    168167                                ?>
    169                             </select>
     168                            </select> 
    170169                        </div>
    171170                        <div class="alignleft actions">
    172171                            <select id="target_post" name="target_post">
    173                                 <option value="0">Select Post</option>
     172                                <option value="0">Select Post</option>                   
    174173                            </select>
    175174                            <span id="target_bc_loader" style="display: none;"><img src="<?php echo plugins_url('ajax-loader.gif', __FILE__); ?>" alt=""></span></div>
    176                         <input type="submit" value="Perform Action" class="button action" id="doaction2" name="" onclick="return chk_val();">
     175                        <!-- <input type="submit" value="Perform Action" class="button action" id="doaction2" name="" onclick="return chk_val();"> -->
     176                        <input type="submit" value="Perform Action" class="button action" id="do_action2" name="do_action2" onclick="return chk_val();">
    177177                    </div>
    178                     <input type="hidden" name="action" value="action_move">
     178                    <input type="hidden" name="action" value="action_move">   
    179179                </form>
    180180                <script type="text/javascript">
     
    304304                $.post(ajaxurl, data, function (response) {
    305305                    jQuery("#get_comments").html(response);
    306                     //jQuery("#bc_loader").hide();
     306                    //jQuery("#bc_loader").hide(); 
    307307                });
    308308            });
    309309        });
    310     </script>
     310    </script> 
    311311    <?php
    312312}
     
    323323    <option value="">Select Post</option>
    324324    <?php foreach ($get_posts as $get_post) { ?>
    325         <option value="<?php echo $get_post->id; ?>"><?php echo $get_post->post_title; ?></option>
     325        <option value="<?php echo $get_post->id; ?>"><?php echo $get_post->post_title; ?></option>   
    326326        <?php
    327327    }
     
    366366                <tr>
    367367                    <td class="source_error" colspan="4" align="center">No Comments found. Please change Comment Type.</td>
    368                 </tr>
     368                </tr>   
    369369
    370370                <?php
     
    411411                                        if (!in_array($get_comment_ids_1[$i], $ids)) {
    412412                                            ?>
    413                                             <td></td>
     413                                            <td></td>   
    414414                                            <?php
    415415                                        } else {
     
    420420                                    } else {
    421421                                        ?>
    422                                         <td><input type="checkbox" value="<?php echo $get_comment->comment_ID; ?>" name="move_comment_id[]" class="chkbox_val"></td>
     422                                        <td><input type="checkbox" value="<?php echo $get_comment->comment_ID; ?>" name="move_comment_id[]" class="chkbox_val"></td>   
    423423                                        <?php
    424424                                    }
     
    465465                            }
    466466                        }
    467                         if ($i == count($get_comment_ids_1)) {
     467                        if ($i == count($get_comment_ids_1))
    468468                            @$get_comment_ids = array_pop($temp);
    469                         }
    470                     } while (count($get_comment_ids) > 0);
    471                 } else {
     469                    }while (count($get_comment_ids) > 0);
     470                }
     471                else {
    472472                    ?>
    473473                    <tr>
     
    546546
    547547        }
    548     </script>
     548    </script> 
    549549    <?php
    550550}
     
    564564    } else {
    565565        $ids = $get_comment_ids;
    566         $ary = array();
    567566        do {
    568567            $tem = $ids;
     
    570569            for ($i = 0; $i < count($tem); $i++) {
    571570                $s = "select * from $wpdb->comments where comment_parent = '" . $tem[$i] . "' and comment_Approved != 'trash'";
    572                 //$data = $wpdb->get_results($wpdb->prepare("", $id));
     571                $data = $wpdb->get_results($wpdb->prepare("", $id));
    573572                $res = $wpdb->get_results($s);
    574573                if ($res) {
     
    581580        } while (count($ids) > 0);
    582581
    583         //$ids = $get_comment_ids;
    584         $printed = array();
     582
     583        $ids = $get_comment_ids;
    585584        do {
    586585            $get_comment_ids_1 = $get_comment_ids;
     
    591590                else {
    592591                    $printed[] = $get_comment_ids_1[$i];
    593                    
     592                    echo "<br>";
     593                    if (!in_array($get_comment_ids_1[$i], $ids)) {
     594                        echo str_repeat(" - ", count($temp));
     595                    }
     596                    echo $get_comment_ids_1[$i];
    594597                    $all_ids[] = $get_comment_ids_1[$i];
    595                     if (isset($ary)) {
    596                         if (isset($ary[$get_comment_ids_1[$i]]) && count($ary[$get_comment_ids_1[$i]]) > 0) {
    597                             $temp[] = $get_comment_ids_1;
    598                             $get_comment_ids = $ary[$get_comment_ids_1[$i]];
    599                             break;
    600                         }
     598                    if (count($ary[$get_comment_ids_1[$i]]) > 0) {
     599                        $temp[] = $get_comment_ids_1;
     600                        $get_comment_ids = $ary[$get_comment_ids_1[$i]];
     601                        break;
    601602                    }
    602603                }
    603604            }
    604             if ($i == count($get_comment_ids_1)) {
    605                 if (isset($temp)) {
    606                     $get_comment_ids = array_pop($temp);
    607                 }
    608             }
    609         } while (count($get_comment_ids) > 0);
     605            if ($i == count($get_comment_ids_1))
     606                $get_comment_ids = array_pop($temp);
     607        }while (count($get_comment_ids) > 0);
    610608    }
    611609
     
    620618        $perform_action = new copy_move_functions();
    621619
    622         $perform_action->perform_action($get_source_id, $get_target_id, $get_action_type, $get_comment_id, $all_ids, $get_comment_type, $comment_cnt);
     620        $transfer_comments = $perform_action->perform_action($get_source_id, $get_target_id, $get_action_type, $get_comment_id, $ary, $all_ids, $get_comment_type, $comment_cnt);
    623621        $url = admin_url();
    624622        wp_redirect($url . '/admin.php?page=copy-move&success=1');
     
    640638        <div  class="notice notice-success">
    641639            <p><?php _e('Comments moved/copied successfully.  &nbsp;&nbsp;Click here to <a href="' . $all_comment . '">view.</a>'); ?></p>
    642         </div>
     640        </div>     
    643641
    644642        <?php
     
    648646        <div class="error">
    649647            <p><?php _e('Please select action OR select atleast one comment to copy/move.'); ?></p>
    650         </div>
     648        </div>     
    651649        <?php
    652650    }
  • copy-or-move-comments/trunk/copy_move_functions.php

    r1990750 r2578596  
    1 <?php
    2 
     1<?php
    32//ini_set("display_errors", "1"); if you want to debug then uncheck this commnet.
    4 class copy_move_functions {
    5 
    6     function get_posts($post_type, $set_privet_post_type) {
    7         global $wpdb;
    8         $data = array();
    9         if ($set_privet_post_type == 'on') {
    10             $data = $wpdb->get_results($wpdb->prepare("select id, post_title from $wpdb->posts where post_status in ('publish','private') and post_type = %s order by post_title asc", $post_type));
    11         } else {
    12             $data = $wpdb->get_results($wpdb->prepare("select id, post_title from $wpdb->posts where post_status = 'publish' and post_type = %s order by post_title asc", $post_type));
    13         }
    14 
     3class copy_move_functions
     4{
     5    function get_posts($post_type,$set_privet_post_type)
     6    {
     7        global $wpdb;
     8        $data = array();
     9if($set_privet_post_type == 'on'){
     10    $data = $wpdb->get_results( $wpdb->prepare( "select id, post_title from $wpdb->posts where post_status in ('publish','private') and post_type = %s order by post_title asc", $post_type ) );
     11}else{
     12    $data = $wpdb->get_results( $wpdb->prepare( "select id, post_title from $wpdb->posts where post_status = 'publish' and post_type = %s order by post_title asc", $post_type ) );
     13}
     14       
    1515        //$data = $wpdb->get_results("select id, post_title from $wpdb->posts where post_status = 'publish' and post_type='".$post_type."' order by id desc");
    1616        return $data;
    1717    }
    18 
    19     function get_all_comments_by_postid($id) {
    20         global $wpdb;
    21         $data = array();
    22 
    23         if (is_numeric($id)) {
    24             $data = $wpdb->get_results($wpdb->prepare("select comment_id from $wpdb->comments where comment_post_id = %s and comment_Approved != 'trash' and comment_parent=0 order by comment_id asc", $id));
     18   
     19    function get_all_comments_by_postid($id)
     20    {
     21        global $wpdb;
     22        $data = array();
     23
     24        if(is_numeric($id))
     25        {       
     26            $data = $wpdb->get_results( $wpdb->prepare( "select comment_id from $wpdb->comments where comment_post_id = %s and comment_Approved != 'trash' and comment_parent=0 order by comment_id asc", $id ) );
    2527            //$data = $wpdb->get_results("select comment_id, comment_author,comment_date, comment_content from $wpdb->comments where comment_post_id = $id order by comment_id desc");
    2628        }
    2729        return $data;
    2830    }
    29 
    30     function get_current_all_posts($post_type, $post_id) {
    31         global $wpdb;
    32         $post_types = get_post_types('', 'names');
    33         //unset($post_types['attachment']);
    34         unset($post_types['revision']);
    35         unset($post_types['nav_menu_item']);
    36         $post_type = "'" . implode("','", $post_types) . "'";
    37         //DebugBreak();
    38         $data = array();
    39         $data = $wpdb->get_results($wpdb->prepare("select ID, post_title from $wpdb->posts where post_status = 'publish' and post_type IN (%d) and ID NOT IN(SELECT ID FROM $wpdb->posts where ID=%s) order by id desc", $post_type, $post_id));
     31   
     32    function get_current_all_posts($post_type,$post_id)
     33    {
     34        global $wpdb;
     35        $post_types = get_post_types( '', 'names' );
     36                                //unset($post_types['attachment']);
     37                                unset($post_types['revision']);
     38                                unset($post_types['nav_menu_item']);
     39                   $post_type = "'".implode("','",$post_types)."'";
     40                        //DebugBreak();
     41        $data = array();
     42        $data = $wpdb->get_results( $wpdb->prepare("select ID, post_title from $wpdb->posts where post_status = 'publish' and post_type IN (%d) and ID NOT IN(SELECT ID FROM $wpdb->posts where ID=%s) order by id desc", $post_type,$post_id ) );
    4043        //$data = $wpdb->get_results("select ID, post_title from $wpdb->posts where post_status = 'publish' and post_type IN ($post_type) and ID NOT IN(SELECT ID FROM $wpdb->posts where ID='$post_id') order by id desc");
    4144        return $data;
    4245    }
    43 
    44     function perform_action($source_post_id, $target_post_id, $get_action_type, $comment_id, $all_ids, $get_comment_type, $comment_cnt) {
    45         global $wpdb;
    46 
    47         if ($get_action_type == 'move') {
    48 
    49             if (isset($get_comment_type) && $get_comment_type == '1') {
    50 
    51                 $all_comments = $wpdb->get_results("select * from $wpdb->comments where comment_id IN ($comment_id)");
    52 
    53                 foreach ($all_comments as $d1) {
    54                     if (in_array($d1->comment_parent, $all_ids)) {
    55                         $sql[] = "update {$wpdb->comments} set comment_post_id = $target_post_id where comment_id IN ($d1->comment_ID)";
    56 
    57                         //Decrement the comment_count in the $source_post_id
    58                         $sql[] = "update {$wpdb->posts} set comment_count = comment_count-1 where id = $source_post_id and post_status = 'publish'";
    59 
    60                         // Increment the comment_count in the $target_post_id
    61                         $sql[] = "update {$wpdb->posts} set comment_count = comment_count+1 where id = $target_post_id and post_status = 'publish'";
    62                     } else {
    63                         $sql[] = "update {$wpdb->comments} set comment_post_id = $target_post_id , comment_parent = '0' where comment_id IN ($d1->comment_ID)";
    64 
    65                         //Decrement the comment_count in the $source_post_id
    66                         $sql[] = "update {$wpdb->posts} set comment_count = comment_count-1 where id = $source_post_id and post_status = 'publish'";
    67 
    68                         // Increment the comment_count in the $target_post_id
    69                         $sql[] = "update {$wpdb->posts} set comment_count = comment_count+1 where id = $target_post_id and post_status = 'publish'";
    70                     }
     46   
     47    function perform_action($source_post_id, $target_post_id, $get_action_type,$comment_id,$ary,$all_ids,$get_comment_type,$comment_cnt)
     48    {
     49        global $wpdb;
     50       
     51        if($get_action_type == 'move')
     52            {
     53           
     54            // update the comment_post_id to $target_post_id
     55            /* if(isset($get_comment_type) && $get_comment_type == '1')
     56            {
     57                 $all_comments = $wpdb->get_results("select * from $wpdb->comments where comment_id IN ($comment_id)");
     58
     59            foreach($all_comments as $data1)
     60            {
     61               
     62                if($data1->comment_parent !='0')
     63                    {
     64                  $data = array(
     65              'comment_post_ID' => $target_post_id,
     66              'comment_author' => $data1->comment_author,
     67              'comment_author_email' => $data1->comment_author_email,
     68              'comment_author_url' => $data1->comment_author_url,
     69              'comment_content' => $data1->comment_content,
     70              'comment_type' => $data1->comment_type,
     71              'comment_parent' => '0',
     72              'user_id' => $data1->user_id,
     73              'comment_author_IP' => $data1->comment_author_IP,
     74              'comment_agent' => $data1->comment_agent,
     75              'comment_date' => $data1->comment_date,
     76              'comment_approved' => $data1->comment_approved,
     77              );   
     78              wp_insert_comment($data);
     79             
     80                 $del_qry = "DELETE FROM wp_comments WHERE comment_ID = $data1->comment_ID";     
     81                 $wpdb->query($del_qry);
     82             
     83                }else{
     84                     
     85                $sql[] = "update {$wpdb->comments} set comment_post_id = $target_post_id where comment_id IN ($data1->comment_ID)";
     86           
     87        //Decrement the comment_count in the $source_post_id
     88        $sql[] = "update {$wpdb->posts} set comment_count = comment_count-1 where id = $source_post_id and post_status = 'publish'";
     89       
     90        // Increment the comment_count in the $target_post_id
     91        $sql[] = "update {$wpdb->posts} set comment_count = comment_count+1 where id = $target_post_id and post_status = 'publish'";
     92       
     93        foreach($sql as $query)
     94        {
     95            $wpdb->query($wpdb->prepare($query));
     96        }
    7197                }
    72 
    73                 foreach ($sql as $query) {
    74                     $wpdb->query($query);
    75                 }
    76             } else {
    77 
     98               
     99            }
     100               
     101            }*/
     102            if(isset($get_comment_type) && $get_comment_type == '1')
     103                {
     104               
     105            $all_comments = $wpdb->get_results("select * from $wpdb->comments where comment_id IN ($comment_id)");
     106           
     107            foreach($all_comments as $d1){
     108                if(in_array($d1->comment_parent,$all_ids))
     109                {
     110                    $sql[] = "update {$wpdb->comments} set comment_post_id = $target_post_id where comment_id IN ($d1->comment_ID)";
     111           
     112        //Decrement the comment_count in the $source_post_id
     113        $sql[] = "update {$wpdb->posts} set comment_count = comment_count-1 where id = $source_post_id and post_status = 'publish'";
     114       
     115        // Increment the comment_count in the $target_post_id
     116        $sql[] = "update {$wpdb->posts} set comment_count = comment_count+1 where id = $target_post_id and post_status = 'publish'";
     117       
     118                }else{
     119                    $sql[] = "update {$wpdb->comments} set comment_post_id = $target_post_id , comment_parent = '0' where comment_id IN ($d1->comment_ID)";
     120           
     121        //Decrement the comment_count in the $source_post_id
     122        $sql[] = "update {$wpdb->posts} set comment_count = comment_count-1 where id = $source_post_id and post_status = 'publish'";
     123       
     124        // Increment the comment_count in the $target_post_id
     125        $sql[] = "update {$wpdb->posts} set comment_count = comment_count+1 where id = $target_post_id and post_status = 'publish'";
     126        }
     127           }
     128             
     129        foreach($sql as $query)
     130        {
     131            $wpdb->query($query);
     132        } 
     133            }
     134            else
     135            {
     136               
    78137                $sql[] = "update {$wpdb->comments} set comment_post_id = $target_post_id where comment_id IN ($comment_id)";
    79 
    80                 //Decrement the comment_count in the $source_post_id
    81                 $sql[] = "update {$wpdb->posts} set comment_count = comment_count-$comment_cnt where id = $source_post_id and post_status = 'publish'";
    82 
    83                 // Increment the comment_count in the $target_post_id
    84                 $sql[] = "update {$wpdb->posts} set comment_count = comment_count+$comment_cnt where id = $target_post_id and post_status = 'publish'";
    85 
    86                 foreach ($sql as $query) {
    87                     $wpdb->query($query);
    88                 }
    89             }
    90         }
    91         if ($get_action_type == 'copy') {
    92 
    93             if (isset($get_comment_type) && $get_comment_type == '1') {
    94                 $all_comments = $wpdb->get_results("select * from $wpdb->comments where comment_id IN ($comment_id)");
    95                 foreach ($all_comments as $data1) {
    96                     /*                     * ******************************* */
    97 
    98                     /*                     * ******************************* */
    99 
    100                     $data_new = array(
    101                         'comment_post_ID' => $target_post_id,
    102                         'comment_author' => $data1->comment_author,
    103                         'comment_author_email' => $data1->comment_author_email,
    104                         'comment_author_url' => $data1->comment_author_url,
    105                         'comment_content' => $data1->comment_content,
    106                         'comment_type' => $data1->comment_type,
    107                         'comment_parent' => '0',
    108                         'user_id' => $data1->user_id,
    109                         'comment_author_IP' => $data1->comment_author_IP,
    110                         'comment_agent' => $data1->comment_agent,
    111                         'comment_date' => $data1->comment_date,
    112                         'comment_approved' => $data1->comment_approved,
    113                     );
    114 
    115                     wp_insert_comment($data_new);
    116                 }
    117             } else {
    118                 // $all_comments = $wpdb->get_results($wpdb->prepare( "select * from $wpdb->comments where comment_id IN (%s)", $comment_id ));
    119                 $all_comments = $wpdb->get_results("select * from $wpdb->comments where comment_id IN ($comment_id)");
    120                 foreach ($all_comments as $data1) {
    121                     /*                     * ******************************* */
    122 
    123                     /*                     * ******************************* */
    124 
    125                     $data = array(
    126                         'comment_post_ID' => $target_post_id,
    127                         'comment_author' => $data1->comment_author,
    128                         'comment_author_email' => $data1->comment_author_email,
    129                         'comment_author_url' => $data1->comment_author_url,
    130                         'comment_content' => $data1->comment_content,
    131                         'comment_type' => $data1->comment_type,
    132                         'comment_parent' => $data1->comment_parent,
    133                         'user_id' => $data1->user_id,
    134                         'comment_author_IP' => $data1->comment_author_IP,
    135                         'comment_agent' => $data1->comment_agent,
    136                         'comment_date' => $data1->comment_date,
    137                         'comment_approved' => $data1->comment_approved,
    138                     );
    139 
    140                     $new_comment_ids[] = wp_insert_comment($data);
    141                 }
    142                 //if($get_comment_type == '2')
    143                 {
    144                     for ($i = 0; $i < count($all_ids); $i++) {
    145                         $sql2[$i] = "update {$wpdb->comments} set comment_parent = " . $new_comment_ids[$i] . " where comment_post_id = " . $target_post_id . " and comment_parent = " . $all_ids[$i] . "";
    146                         $wpdb->query($sql2[$i]);
    147                     }
    148                 }
    149             }
    150         }
    151     }
    152 
    153     function get_single_comment($id) {
    154         global $wpdb;
    155         $data = array();
    156 
    157         if (is_numeric($id)) {
    158             $data = $wpdb->get_row($wpdb->prepare("select * from $wpdb->comments where comment_id = %s", $id));
    159         }
    160         return $data;
    161     }
    162 
     138           
     139        //Decrement the comment_count in the $source_post_id
     140        $sql[] = "update {$wpdb->posts} set comment_count = comment_count-$comment_cnt where id = $source_post_id and post_status = 'publish'";
     141       
     142        // Increment the comment_count in the $target_post_id
     143        $sql[] = "update {$wpdb->posts} set comment_count = comment_count+$comment_cnt where id = $target_post_id and post_status = 'publish'";
     144       
     145        foreach($sql as $query)
     146        {
     147            $wpdb->query($wpdb->prepare($query));
     148        }
     149               
     150       }
     151       
     152       
     153        }
     154        if($get_action_type == 'copy')
     155        {
     156             
     157                if(isset($get_comment_type) && $get_comment_type == '1')
     158                {
     159                    $all_comments = $wpdb->get_results("select * from $wpdb->comments where comment_id IN ($comment_id)");
     160            foreach($all_comments as $data1)
     161            {
     162                /**********************************/
     163
     164                /**********************************/
     165               
     166                $data_new = array(
     167              'comment_post_ID' => $target_post_id,
     168              'comment_author' => $data1->comment_author,
     169              'comment_author_email' => $data1->comment_author_email,
     170              'comment_author_url' => $data1->comment_author_url,
     171              'comment_content' => $data1->comment_content,
     172              'comment_type' => $data1->comment_type,
     173              'comment_parent' => '0',
     174              'user_id' => $data1->user_id,
     175              'comment_author_IP' => $data1->comment_author_IP,
     176              'comment_agent' => $data1->comment_agent,
     177              'comment_date' => $data1->comment_date,
     178              'comment_approved' => $data1->comment_approved,
     179              );   
     180             
     181              wp_insert_comment($data_new);   
     182              }
     183             }
     184             else
     185                 {
     186                 // $all_comments = $wpdb->get_results($wpdb->prepare( "select * from $wpdb->comments where comment_id IN (%s)", $comment_id ));
     187            $all_comments = $wpdb->get_results("select * from $wpdb->comments where comment_id IN ($comment_id)");
     188            foreach($all_comments as $data1)
     189            {
     190                /**********************************/
     191
     192                /**********************************/
     193               
     194                $data = array(
     195              'comment_post_ID' => $target_post_id,
     196              'comment_author' => $data1->comment_author,
     197              'comment_author_email' => $data1->comment_author_email,
     198              'comment_author_url' => $data1->comment_author_url,
     199              'comment_content' => $data1->comment_content,
     200              'comment_type' => $data1->comment_type,
     201              'comment_parent' => $data1->comment_parent,
     202              'user_id' => $data1->user_id,
     203              'comment_author_IP' => $data1->comment_author_IP,
     204              'comment_agent' => $data1->comment_agent,
     205              'comment_date' => $data1->comment_date,
     206              'comment_approved' => $data1->comment_approved,
     207              );   
     208             
     209              $new_comment_ids[] = wp_insert_comment($data);
     210           
     211            }
     212            //if($get_comment_type == '2')
     213            {
     214                for($i=0;$i<count($all_ids);$i++)
     215                {
     216                    $sql2[$i] = "update {$wpdb->comments} set comment_parent = ".$new_comment_ids[$i]." where comment_post_id = ".$target_post_id." and comment_parent = ".$all_ids[$i]."";
     217                    $wpdb->query($sql2[$i]);
     218                   
     219                }   
     220            }
     221                   
     222                }           
     223
     224           
     225         
     226           
     227        }
     228    }
     229   
     230    function get_single_comment($id)
     231    {
     232        global $wpdb;
     233        $data = array();
     234
     235        if(is_numeric($id))
     236        {       
     237            $data = $wpdb->get_row( $wpdb->prepare( "select * from $wpdb->comments where comment_id = %s", $id ) );
     238        }
     239        return $data;
     240    }
    163241}
    164 
    165242?>
  • copy-or-move-comments/trunk/readme.txt

    r2273822 r2578596  
    33Tags: Copy/move all comments, migrate WP comments, Copy/Move Pages comment, Copy all comments, Move all comments
    44Requires at least: 3.5.2
    5 Tested up to: 5.4
    6 Stable tag: 5.0.1
     5Tested up to: 5.8
     6Stable tag: 5.0.2
    77License: GPLv2 or later
    88
     
    18186. Admin can have select option for target post types.
    19197. After select post type next drop down selection will displaying all the post's title in which admin can copy comments or moving comments for that selected post.
    20 
     20 
    2121
    2222== Installation ==
     
    4040* First release this pluign
    4141= 1.0.1 =
    42 * Solve vulnerability
     42* Solve vulnerability 
    4343= 2.0.0 =
    44 * For Copy/Move comments, Added Target Post Type also.
     44* For Copy/Move comments, Added Target Post Type also. 
    4545= 3.0.0 =
    46 * Release new feature that is copy/move comments whole replies history.
     46* Release new feature that is copy/move comments whole replies history. 
    4747= 3.0.1 =
    48 * Search filter in source and destination post selection
     48* Search filter in source and destination post selection 
    4949= 4.0.0 =
    5050* Add setting page which allows admin to displaying private posts/ pages into Source as well as Target section.
     
    5353= 4.0.2 =
    5454* Compatibility with word-press : 4.7.
    55 = 4.0.3 =
    56 * Solving bug on PHP7 and Compatibility with word-press : 4.8.2.
    57 = 5.0.0 =
    58 * Compatibility with word-press : 5.3.
    59 = 5.0.1 =
    60 * Compatibility with word-press : 5.4.
     55= 5.0.2 =
     56* Compatibility with word-press : 5.8.
     57* Solving Perform Action Button issue.
Note: See TracChangeset for help on using the changeset viewer.