Plugin Directory

Changeset 3223894


Ignore:
Timestamp:
01/17/2025 12:27:41 AM (7 weeks ago)
Author:
Katsushi Kawamori
Message:
  • Fix - json files are not left on the server but sent to the administrator via email.
Location:
moving-users/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • moving-users/trunk/lib/class-movingusers.php

    r3045309 r3223894  
    5656        add_action( 'movingusers_update_db_hook', array( $this, 'update_db' ), 10, 2 );
    5757        add_action( 'movingusers_clear_db_hook', array( $this, 'clear_db' ), 10, 1 );
    58         add_action( 'movingusers_logs_check_files', array( $this, 'logs_check_files' ), 10, 1 );
    59         add_action( 'movingusers_logs_slice_create', array( $this, 'logs_slice_create' ), 10, 3 );
    60         add_action( 'movingusers_logs_slice_delete', array( $this, 'logs_slice_delete' ), 10, 2 );
    6158    }
    6259
     
    103100        $file = null;
    104101
    105         /* Option logs slice and file delete for create json */
    106         do_action( 'movingusers_logs_slice_create', 'moving_users_export_files', $name, get_option( 'moving_users_number_files', 5 ) );
    107 
    108         if ( get_option( 'moving_users_mail_send' ) ) {
    109             /* Send mail JSON file */
    110             $message = 'Moving Users : ' . __( 'The JSON file for the contents has been generated.', 'moving-users' );
    111             wp_mail( get_option( 'admin_email' ), $message, $message, null, $json_file );
     102        /* Send mail JSON file */
     103        $message = 'Moving Users : ' . __( 'The JSON file for the users has been generated.', 'moving-users' );
     104        $send = wp_mail( get_option( 'admin_email' ), $message, $message, null, $json_file );
     105        if ( $send ) {
     106            echo '<div class="notice notice-success is-dismissible"><ul><li>' . esc_html( __( 'Email has been sent.', 'moving-users' ) ) . '</li></ul></div>';
     107        } else {
     108            echo '<div class="notice notice-error is-dismissible"><ul><li>' . esc_html( __( 'Failed to send email.', 'moving-users' ) ) . '</li></ul></div>';
     109        }
     110        if ( file_exists( $json_file ) ) {
     111            wp_delete_file( $json_file );
    112112        }
    113113    }
     
    191191        );
    192192    }
    193 
    194     /** ==================================================
    195      * Check option logs and files
    196      *
    197      * @param string $option_name  option_name.
    198      * @since 1.00
    199      */
    200     public function logs_check_files( $option_name ) {
    201 
    202         $logs = get_option( $option_name, array() );
    203 
    204         $json_files = array();
    205         $files = glob( $this->upload_dir . '*.json' );
    206         if ( ! empty( $files ) ) {
    207             foreach ( $files as $file ) {
    208                 $json_files[] = wp_basename( $file );
    209             }
    210         }
    211         $delete_files_diff = array_diff( $logs, $json_files );
    212         if ( ! empty( $delete_files_diff ) ) {
    213             foreach ( $logs as $key => $value ) {
    214                 if ( in_array( $value, $delete_files_diff ) ) {
    215                     unset( $logs[ $key ] );
    216                 }
    217             }
    218             array_values( $logs );
    219             update_option( $option_name, $logs );
    220         }
    221     }
    222 
    223     /** ==================================================
    224      * Option logs slice and file delete for create json
    225      *
    226      * @param string $option_name  option_name.
    227      * @param string $name  name.
    228      * @param int    $number_files  number_files.
    229      * @since 1.00
    230      */
    231     public function logs_slice_create( $option_name, $name, $number_files ) {
    232 
    233         $logs = get_option( $option_name, array() );
    234 
    235         if ( ! empty( $logs ) ) {
    236             $log_files_all = array_merge( array( $name ), $logs );
    237         } else {
    238             $log_files_all = array( $name );
    239         }
    240         $log_files = array_slice( $log_files_all, 0, $number_files );
    241         $delete_files = array_slice( $log_files_all, $number_files );
    242         update_option( $option_name, $log_files );
    243         foreach ( $delete_files as $value ) {
    244             $delete_file = $this->upload_dir . $value;
    245             if ( file_exists( $delete_file ) ) {
    246                 wp_delete_file( $delete_file );
    247             }
    248         }
    249     }
    250 
    251     /** ==================================================
    252      * Option logs slice and file delete for delete json
    253      *
    254      * @param string $option_name  option_name.
    255      * @param array  $delete_files  delete_files.
    256      * @since 1.00
    257      */
    258     public function logs_slice_delete( $option_name, $delete_files ) {
    259 
    260         $logs = get_option( $option_name, array() );
    261 
    262         foreach ( $delete_files as $name ) {
    263             if ( ! empty( $logs ) ) {
    264                 foreach ( $logs as $key => $value ) {
    265                     if ( $value === $name ) {
    266                         unset( $logs[ $key ] );
    267                     }
    268                 }
    269                 array_values( $logs );
    270                 update_option( $option_name, $logs );
    271             }
    272             if ( file_exists( $this->upload_dir . $name ) ) {
    273                 wp_delete_file( $this->upload_dir . $name );
    274             }
    275         }
    276     }
    277193}
  • moving-users/trunk/lib/class-movingusersadmin.php

    r3092630 r3223894  
    8484        if ( $file == $this_plugin ) {
    8585            $links[] = '<a href="' . admin_url( 'admin.php?page=movingusers' ) . '">Moving Users</a>';
    86             $links[] = '<a href="' . admin_url( 'admin.php?page=movingusers-generate-json' ) . '">' . __( 'Export' ) . '</a>';
    87             $links[] = '<a href="' . admin_url( 'admin.php?page=movingusers-update-db' ) . '">' . __( 'Import' ) . '</a>';
     86            $links[] = '<a href="' . admin_url( 'admin.php?page=movingusers-generate-json' ) . '">' . __( 'Export', 'moving-users' ) . '</a>';
     87            $links[] = '<a href="' . admin_url( 'admin.php?page=movingusers-update-db' ) . '">' . __( 'Import', 'moving-users' ) . '</a>';
    8888        }
    8989        return $links;
     
    106106        add_submenu_page(
    107107            'movingusers',
    108             __( 'Export' ),
    109             __( 'Export' ),
     108            __( 'Export', 'moving-users' ),
     109            __( 'Export', 'moving-users' ),
    110110            'manage_options',
    111111            'movingusers-generate-json',
     
    114114        add_submenu_page(
    115115            'movingusers',
    116             __( 'Import' ),
    117             __( 'Import' ),
     116            __( 'Import', 'moving-users' ),
     117            __( 'Import', 'moving-users' ),
    118118            'manage_options',
    119119            'movingusers-update-db',
     
    130130
    131131        if ( ! current_user_can( 'manage_options' ) ) {
    132             wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) );
     132            wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'moving-users' ) );
    133133        }
    134134
    135135        $scriptname = admin_url( 'admin.php?page=movingusers-generate-json' );
    136 
    137         if ( isset( $_POST['Jsonmailsend'] ) && ! empty( $_POST['Jsonmailsend'] ) ) {
    138             if ( check_admin_referer( 'zm_file_json', 'movingusers_file_json' ) ) {
    139                 if ( ! empty( $_POST['mail_send'] ) ) {
    140                     update_option( 'moving_users_mail_send', true );
    141                 } else {
    142                     update_option( 'moving_users_mail_send', false );
    143                 }
    144                 echo '<div class="notice notice-success is-dismissible"><ul><li>' . esc_html( __( 'Settings' ) . ' --> ' . __( 'Changes saved.' ) ) . '</li></ul></div>';
    145             }
    146         }
    147 
    148         if ( isset( $_POST['Cnumber'] ) && ! empty( $_POST['Cnumber'] ) ) {
    149             if ( check_admin_referer( 'zm_file_json', 'movingusers_file_json' ) ) {
    150                 if ( ! empty( $_POST['number_files'] ) ) {
    151                     update_option( 'moving_users_number_files', absint( $_POST['number_files'] ) );
    152                     echo '<div class="notice notice-success is-dismissible"><ul><li>' . esc_html( __( 'Settings' ) . ' --> ' . __( 'Changes saved.' ) ) . '</li></ul></div>';
    153                 }
    154             }
    155         }
    156 
    157         do_action( 'movingusers_logs_check_files', 'moving_users_export_files' );
    158136
    159137        if ( isset( $_POST['Cjson'] ) && ! empty( $_POST['Cjson'] ) ) {
     
    162140            }
    163141        }
    164         if ( isset( $_POST['Djson'] ) && ! empty( $_POST['Djson'] ) ) {
    165             if ( check_admin_referer( 'zm_file_json', 'movingusers_file_json' ) ) {
    166                 if ( ! empty( $_POST['delete_files'] ) ) {
    167                     $delete_files = filter_var(
    168                         wp_unslash( $_POST['delete_files'] ),
    169                         FILTER_CALLBACK,
    170                         array(
    171                             'options' => function ( $value ) {
    172                                 return sanitize_text_field( $value );
    173                             },
    174                         )
    175                     );
    176                     do_action( 'movingusers_logs_slice_delete', 'moving_users_export_files', $delete_files );
    177                 }
    178             }
    179         }
    180142
    181143        ?>
    182144        <div class="wrap">
    183145
    184         <h2>Moving Users <a href="<?php echo esc_url( admin_url( 'admin.php?page=movingusers-generate-json' ) ); ?>" style="text-decoration: none;"><?php esc_html_e( 'Export' ); ?></a>
    185             <a href="<?php echo esc_url( admin_url( 'admin.php?page=movingusers-update-db' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Import' ); ?></a>
     146        <h2>Moving Users <a href="<?php echo esc_url( admin_url( 'admin.php?page=movingusers-generate-json' ) ); ?>" style="text-decoration: none;"><?php esc_html_e( 'Export', 'moving-users' ); ?></a>
     147            <a href="<?php echo esc_url( admin_url( 'admin.php?page=movingusers-update-db' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Import', 'moving-users' ); ?></a>
    186148            <?php
    187149            if ( class_exists( 'MovingContents' ) ) {
     
    207169        <div style="clear: both;"></div>
    208170
    209         <h3><?php esc_html_e( 'Export' ); ?></h3>
     171        <h3><?php esc_html_e( 'Export', 'moving-users' ); ?></h3>
    210172        <form method="post" action="<?php echo esc_url( $scriptname ); ?>">
    211173        <div style="margin: 5px; padding: 5px;">
     
    214176            </p>
    215177            <?php wp_nonce_field( 'zm_file_json', 'movingusers_file_json' ); ?>
    216             <div style="margin: 5px; padding: 5px; vertical-align: middle;">
    217             <input type="checkbox" name="mail_send" value="1" <?php checked( get_option( 'moving_users_mail_send' ), true ); ?>>
    218             <?php esc_html_e( 'Send the exported JSON file by e-mail', 'moving-users' ); ?>
    219             <?php submit_button( __( 'Change' ), 'large', 'Jsonmailsend', false, array( 'style' => 'vertical-align: middle;' ) ); ?>
    220             </div>
    221             <?php submit_button( __( 'Export as JSON' ), 'large', 'Cjson', true ); ?>
    222         </div>
     178            <?php submit_button( __( 'Export and send by email', 'moving-users' ), 'large', 'Cjson', true ); ?>
     179        </div>
     180        </form>
     181
     182        </div>
     183
    223184        <?php
    224         $logs = get_option( 'moving_users_export_files' );
    225         if ( ! empty( $logs ) ) {
    226             ?>
    227             <h3>JSON <?php esc_html_e( 'File', 'moving-users' ); ?></h3>
    228             <div style="margin: 5px; padding: 5px;">
    229             <?php esc_html_e( 'Number of latest files to keep', 'moving-users' ); ?> :
    230             <input type="number" name="number_files" value="<?php echo esc_attr( get_option( 'moving_users_number_files', 5 ) ); ?>" min="1" max="100" step="1" style="width: 70px;" />
    231             <?php submit_button( __( 'Change' ), 'large', 'Cnumber', false ); ?>
    232             <?php submit_button( __( 'Delete' ), 'large', 'Djson', true ); ?>
    233             <table border=1 cellspacing="0" cellpadding="5" bordercolor="#000000" style="border-collapse: collapse;">
    234             <tr>
    235             <th><?php esc_html_e( 'Delete' ); ?></th>
    236             <th><?php esc_html_e( 'Name' ); ?></th>
    237             <th><?php esc_html_e( 'Date/time' ); ?></th>
    238             <th><?php esc_html_e( 'Size' ); ?></th>
    239             <th><?php esc_html_e( 'Action' ); ?></th>
    240             </tr>
    241             <?php
    242             foreach ( $logs as $value ) {
    243                 $json_filename = $this->upload_dir . $value;
    244                 $json_fileurl = $this->upload_url . $value;
    245                 if ( file_exists( $json_filename ) ) {
    246                     if ( function_exists( 'wp_date' ) ) {
    247                         $json_time = wp_date( 'Y-m-d H:i:s', filemtime( $json_filename ) );
    248                     } else {
    249                         $json_time = date_i18n( 'Y-m-d H:i:s', filemtime( $json_filename ) );
    250                     }
    251                     $json_byte = filesize( $json_filename );
    252                     $json_size = size_format( $json_byte, 2 );
    253                     ?>
    254                     <tr>
    255                     <td>
    256                     <input type="checkbox" name="delete_files[]" value="<?php echo esc_attr( $value ); ?>">
    257                     </td>
    258                     <td>
    259                     <?php echo esc_html( $value ); ?>
    260                     </td>
    261                     <td>
    262                     <?php echo esc_html( $json_time ); ?>
    263                     </td>
    264                     <td>
    265                     <?php echo esc_html( $json_size ); ?>
    266                     </td>
    267                     <td>
    268                     <button type="button" class="button button-large" onclick="location.href='<?php echo esc_url( $json_fileurl ); ?>'"><?php esc_html_e( 'View' ); ?></button>
    269                     &nbsp;
    270                     <a href="<?php echo esc_url( $json_fileurl ); ?>" download="<?php echo esc_attr( $value ); ?>"><button type="button" class="button button-large"><?php esc_html_e( 'Download', 'moving-users' ); ?></button></a>
    271                     </td>
    272                     </tr>
    273                     <?php
    274                 }
    275             }
    276             ?>
    277             </table>
    278             <?php submit_button( __( 'Delete' ), 'large', 'Djson', true ); ?>
    279             </div>
    280             <?php
    281         }
    282         ?>
    283         </form>
    284 
    285         </div>
    286 
    287         <?php
    288185    }
    289186
     
    296193
    297194        if ( ! current_user_can( 'manage_options' ) ) {
    298             wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) );
     195            wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'moving-users' ) );
    299196        }
    300197
     
    307204        if ( isset( $_SERVER['CONTENT_LENGTH'] ) && ! empty( $_SERVER['CONTENT_LENGTH'] ) ) {
    308205            if ( 0 < $max_upload_size && $max_upload_size < intval( $_SERVER['CONTENT_LENGTH'] ) ) {
    309                 echo '<div class="notice notice-error is-dismissible"><ul><li>' . esc_html__( 'This is larger than the maximum size. Please try another.' ) . '</li></ul></div>';
     206                echo '<div class="notice notice-error is-dismissible"><ul><li>' . esc_html__( 'This is larger than the maximum size. Please try another.', 'moving-users' ) . '</li></ul></div>';
    310207            }
    311208        }
     
    331228                        $filetype = wp_check_filetype( $filename );
    332229                        if ( ! $filetype['ext'] && ! current_user_can( 'unfiltered_upload' ) ) {
    333                             echo '<div class="notice notice-error is-dismissible"><ul><li>' . esc_html__( 'Sorry, this file type is not permitted for security reasons.' ) . '</li></ul></div>';
     230                            echo '<div class="notice notice-error is-dismissible"><ul><li>' . esc_html__( 'Sorry, this file type is not permitted for security reasons.', 'moving-users' ) . '</li></ul></div>';
    334231                        } else {
    335232                            $filetype2 = wp_check_filetype( $filename, array( $filetype['ext'] => $mimetype ) );
     
    374271                                    wp_delete_file( $json_file );
    375272                                } else {
    376                                     echo '<div class="notice notice-error is-dismissible"><ul><li>' . esc_html__( 'Could not copy file.' ) . '</li></ul></div>';
     273                                    echo '<div class="notice notice-error is-dismissible"><ul><li>' . esc_html__( 'Could not copy file.', 'moving-users' ) . '</li></ul></div>';
    377274                                }
    378275                            } else {
    379                                 echo '<div class="notice notice-error is-dismissible"><ul><li>' . esc_html__( 'Sorry, this file type is not permitted for security reasons.' ) . '</li></ul></div>';
     276                                echo '<div class="notice notice-error is-dismissible"><ul><li>' . esc_html__( 'Sorry, this file type is not permitted for security reasons.', 'moving-users' ) . '</li></ul></div>';
    380277                            }
    381278                        }
    382279                    } else {
    383                         echo '<div class="notice notice-error is-dismissible"><ul><li>' . esc_html__( 'No such file exists! Double check the name and try again.' ) . '</li></ul></div>';
     280                        echo '<div class="notice notice-error is-dismissible"><ul><li>' . esc_html__( 'No such file exists! Double check the name and try again.', 'moving-users' ) . '</li></ul></div>';
    384281                    }
    385282                }
     
    390287        <div class="wrap">
    391288
    392         <h2>Moving Users <a href="<?php echo esc_url( admin_url( 'admin.php?page=movingusers-update-db' ) ); ?>" style="text-decoration: none;"><?php esc_html_e( 'Import' ); ?></a>
    393             <a href="<?php echo esc_url( admin_url( 'admin.php?page=movingusers-generate-json' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Export' ); ?></a>
     289        <h2>Moving Users <a href="<?php echo esc_url( admin_url( 'admin.php?page=movingusers-update-db' ) ); ?>" style="text-decoration: none;"><?php esc_html_e( 'Import', 'moving-users' ); ?></a>
     290            <a href="<?php echo esc_url( admin_url( 'admin.php?page=movingusers-generate-json' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Export', 'moving-users' ); ?></a>
    394291            <?php
    395292            if ( class_exists( 'MovingContents' ) ) {
     
    437334            <?php
    438335            /* translators: Maximum upload file size */
    439             echo esc_html( sprintf( __( 'Maximum upload file size: %s.' ), $limit_str ) );
     336            echo esc_html( sprintf( __( 'Maximum upload file size: %s.', 'moving-users' ), $limit_str ) );
    440337            ?>
    441338            </div>
     
    459356
    460357        if ( ! current_user_can( 'manage_options' ) ) {
    461             wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) );
     358            wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'moving-users' ) );
    462359        }
    463360
     
    466363
    467364        <h2>Moving Users
    468             <a href="<?php echo esc_url( admin_url( 'admin.php?page=movingusers-generate-json' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Export' ); ?></a>
    469             <a href="<?php echo esc_url( admin_url( 'admin.php?page=movingusers-update-db' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Import' ); ?></a>
     365            <a href="<?php echo esc_url( admin_url( 'admin.php?page=movingusers-generate-json' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Export', 'moving-users' ); ?></a>
     366            <a href="<?php echo esc_url( admin_url( 'admin.php?page=movingusers-update-db' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Import', 'moving-users' ); ?></a>
    470367            <?php
    471368            if ( class_exists( 'MovingContents' ) ) {
     
    535432            }
    536433        }
    537         $plugin_version = __( 'Version:' ) . ' ' . $plugin_ver_num;
     434        $plugin_version = __( 'Version:', 'moving-users' ) . ' ' . $plugin_ver_num;
    538435        /* translators: FAQ Link & Slug */
    539436        $faq       = sprintf( __( 'https://wordpress.org/plugins/%s/faq', 'moving-users' ), $slug );
     
    556453        <?php
    557454        /* translators: Plugin translation link */
    558         echo esc_html( sprintf( __( 'Translations for %s' ), $plugin_name ) );
     455        echo esc_html( sprintf( __( 'Translations for %s', 'moving-users' ), $plugin_name ) );
    559456        ?>
    560457        </a> | <a style="text-decoration: none;" href="<?php echo esc_url( $facebook ); ?>" target="_blank" rel="noopener noreferrer"><span class="dashicons dashicons-facebook"></span></a> | <a style="text-decoration: none;" href="<?php echo esc_url( $twitter ); ?>" target="_blank" rel="noopener noreferrer"><span class="dashicons dashicons-twitter"></span></a> | <a style="text-decoration: none;" href="<?php echo esc_url( $youtube ); ?>" target="_blank" rel="noopener noreferrer"><span class="dashicons dashicons-video-alt3"></span></a>
     
    565462        <h3><?php esc_html_e( 'Please make a donation if you like my work or would like to further the development of this plugin.', 'moving-users' ); ?></h3>
    566463        <div style="text-align: right; margin: 5px; padding: 5px;"><span style="padding: 3px; color: #ffffff; background-color: #008000">Plugin Author</span> <span style="font-weight: bold;">Katsushi Kawamori</span></div>
    567         <button type="button" style="margin: 5px; padding: 5px;" onclick="window.open('<?php echo esc_url( $donate ); ?>')"><?php esc_html_e( 'Donate to this plugin &#187;' ); ?></button>
     464        <button type="button" style="margin: 5px; padding: 5px;" onclick="window.open('<?php echo esc_url( $donate ); ?>')"><?php esc_html_e( 'Donate to this plugin &#187;', 'moving-users' ); ?></button>
    568465        </div>
    569466
     
    582479    }
    583480}
    584 
    585 
  • moving-users/trunk/movingusers.php

    r3092630 r3223894  
    44 * Plugin URI:  https://wordpress.org/plugins/moving-users/
    55 * Description: Supports the transfer of Users between servers.
    6  * Version:     1.05
     6 * Version:     1.10
    77 * Author:      Katsushi Kawamori
    88 * Author URI:  https://riverforest-wp.info/
  • moving-users/trunk/readme.txt

    r3182719 r3223894  
    66Requires PHP: 8.0
    77Tested up to: 6.7
    8 Stable tag: 1.05
     8Stable tag: 1.10
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5050== Changelog ==
    5151
     52= [1.10] 2025/01/17 =
     53* Fix - json files are not left on the server but sent to the administrator via email.
     54
    5255= [1.05] 2024/05/26 =
    5356* Fix - Fixed problem with import files not being copied.
     
    6871= 1.00 =
    6972Initial release.
     73
     74== Upgrade Notice ==
     75
     76= 1.10 =
     77Security measures.
     78
     79= 1.00 =
     80Initial release.
Note: See TracChangeset for help on using the changeset viewer.