Plugin Directory

Changeset 2218909


Ignore:
Timestamp:
12/28/2019 11:02:55 AM (6 years ago)
Author:
nir0ma
Message:

1.1.1

Location:
category-import-reloaded/trunk
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • category-import-reloaded/trunk/README.txt

    r2088938 r2218909  
    11=== Category Import Reloaded ===
    2 Contributors: nir0ma
     2Contributors: nir0ma, aurovrata
    33Tags: category, taxonomy, import, create, bulk
    44Donate link: https://www.niroma.net
    55Requires at least: 3.0.1
    6 Tested up to: 5.2
     6Tested up to: 5.3.2
    77Requires PHP: 5.6.0
    8 Stable tag: 1.1.0
     8Stable tag: trunk
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    7171= 1.1.0 =
    7272* Taxonomies support fixed (Was not working in v1.0.0)
     73
     74= 1.1.1 =
     75* Mutliples fixes thanks to aurovrata
  • category-import-reloaded/trunk/category-import-reloaded.php

    r2073147 r2218909  
    1616 * Plugin URI:        http://wordpress.org/extend/plugins/category-import-reloaded/
    1717 * Description:       This plug-in allows user to bulk create categories and taxonomies with a custom input format. This plugin is an update of the no more maintained "Category Import" plugin originally developped by Jiayu (James) Ji.
    18  * Version:           1.1.0
     18 * Version:           1.1.1
    1919 * Author:            Niroma
    2020 * Author URI:        https://www.niroma.net/
     
    4040define( NS . 'PLUGIN_NAME', 'category-import-reloaded' );
    4141
    42 define( NS . 'PLUGIN_VERSION', '1.1.0' );
     42define( NS . 'PLUGIN_VERSION', '1.1.1' );
    4343
    4444define( NS . 'PLUGIN_NAME_DIR', plugin_dir_path( __FILE__ ) );
  • category-import-reloaded/trunk/inc/admin/class-admin.php

    r2073147 r2218909  
    103103
    104104    }
    105    
     105
    106106    public function display_plugin_setup_page() {
    107107        include_once( 'views/html-category-import-reloaded-admin-display.php' );
    108108    }
    109    
     109
    110110    public function add_plugin_admin_menu() {
    111111
     
    121121        add_submenu_page( $this->plugin_name, 'Category Import Reloaded', 'Category Import', 'manage_categories', $this->plugin_name, array($this, 'display_plugin_setup_page') );
    122122    }
    123    
    124    
     123
     124
    125125    private function termAlreadyExists($array, $key, $val, $return) {
    126126        foreach ($array as $item) {
     
    132132        return false;
    133133    }
    134    
    135    
     134
     135
    136136    public function check_for_event_submissions(){
    137137            if ( isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], $this->plugin_name.'submit-taxonomies') ){
     
    147147                $rootCategories = array();
    148148                $rootTerms = get_terms( array( 'taxonomy' => $taxonomyActive, 'parent' => 0, 'hide_empty' => false ) );
    149                 foreach ($rootTerms as $rootTerm) {
    150                     $rootCategories[] = array('id' => $rootTerm->term_id, 'name' => $rootTerm->name);
    151                 }
    152                
     149                //use wp_list_pluck for cleaner code.
     150                $rootCategories = wp_list_pluck($rootTerms, 'term_id','name');
     151
    153152                foreach($lines as $line){
    154                     $split_line = explode('/', $line);
     153                    //use str_getcsv to enable eclosure with quotes.
     154                    $split_line = str_getcsv(stripslashes($line), '/','"');
     155                    // $split_line = explode('/', $line);
    155156                    $l =  count($split_line);
    156157                    for ($i = 0; $i < $l; $i++) {
    157158                        $new_line = $split_line[$i];
    158159                        $prev_line = '';
    159                        
     160
    160161                        if (strlen(trim($new_line)) == 0) break;
    161162                        $new_line = sanitize_text_field(trim($new_line));
    162                        
     163
    163164                        if(strpos($new_line, $delimiter) !== false){
    164165                            $cat_name_slug = explode($delimiter,$new_line);
     
    169170                            $cat_slug = $new_line;
    170171                        }
    171                        
     172
    172173                        if ($i == 0) {
    173                             if ( $this->termAlreadyExists($rootCategories, 'name', $cat_name, 'id') ) {
    174                                 $parent_id = $this->termAlreadyExists($rootCategories, 'name', $cat_name, 'id');
     174                            //use isset rather than separate method, simpler.
     175                            if ( isset($rootCategories[$cat_name]) ) {
     176                                $parent_id = $rootCategories[$cat_name];
    175177                                $countErrors++;
    176178                            } else {
     
    178180                                if ( ! is_wp_error( $result ) ) {
    179181                                    $parent_id = isset( $result['term_id'] ) ? $result['term_id'] : '';
    180                                     $rootCategories[] = array('id' => $parent_id, 'name' => $cat_name);
     182                                    $rootCategories[$cat_name] = $parent_id;
    181183                                    $countSuccess++;
    182184                                } else $countErrors++;
     
    186188                                $siblingsCategories = array();
    187189                                $parentChildren = get_terms( array('taxonomy' => $taxonomyActive, 'parent' => $parent_id, 'hide_empty' => false ) );
    188                                 foreach ($parentChildren as $child) {
    189                                     $siblingsCategories[] = array('id' => $child->term_id, 'name' => $child->name);
    190                                 }
    191                                 if ( $this->termAlreadyExists($siblingsCategories, 'name', $cat_name, 'id') ) {
    192                                     $parent_id = $this->termAlreadyExists($siblingsCategories, 'name', $cat_name, 'id');
     190                $siblingsCategories = wp_list_pluck($parentChildren, 'term_id','name');
     191                                //using isset for simpler code.
     192                                if ( isset($siblingsCategories[$cat_name]) ) {
     193                                    $parent_id = $siblingsCategories[$cat_name];
    193194                                    $countErrors++;
    194195                                } else {
     
    200201                                }
    201202                            } else $countErrors++;
    202                         }   
     203                        }
    203204                    }
    204                 } 
     205                }
    205206                if ($countErrors > 0 ) {
    206207                    $admin_notice = "error";
     
    210211                    $admin_notice = "success";
    211212                    $messageLog .= $countSuccess .' categories successully added ! ';
    212                 } 
    213                
     213                }
     214
    214215                $this->custom_redirect( $admin_notice, $messageLog);
    215216                die();
     
    221222            }
    222223    }
    223    
     224
    224225    public function custom_redirect( $admin_notice, $response ) {
    225226        wp_redirect( esc_url_raw( add_query_arg( array(
     
    227228                                    'cir_response' => $response,
    228229                                    ),
    229                             admin_url('admin.php?page='. $this->plugin_name ) 
     230                            admin_url('admin.php?page='. $this->plugin_name )
    230231                    ) ) );
    231232
    232233    }
    233234
    234     public function print_plugin_admin_notices() {             
     235    public function print_plugin_admin_notices() {
    235236          if ( isset( $_REQUEST['cir_admin_add_notice'] ) ) {
    236237            if( $_REQUEST['cir_admin_add_notice'] === "success") {
    237                 $html = '<div class="notice notice-success is-dismissible"> 
     238                $html = '<div class="notice notice-success is-dismissible">
    238239                            <p><strong>' . htmlspecialchars( print_r( $_REQUEST['cir_response'], true) ) . '</strong></p></div>';
    239240                echo $html;
    240241            }
    241242            if( $_REQUEST['cir_admin_add_notice'] === "error") {
    242                 $html = '<div class="notice notice-error is-dismissible"> 
     243                $html = '<div class="notice notice-error is-dismissible">
    243244                            <p><strong>' . htmlspecialchars( print_r( $_REQUEST['cir_response'], true) ) . '</strong></p></div>';
    244245                echo $html;
  • category-import-reloaded/trunk/inc/admin/views/html-category-import-reloaded-admin-display.php

    r1859595 r2218909  
    5151                <td>                               
    5252                    <input type="text" id="<?php echo $this->plugin_name; ?>-delimiter" name="<?php echo $this->plugin_name; ?>-delimiter" maxlength="2" size="2" class="regular-text" />
    53                     <p  id="<?php echo $this->plugin_name; ?>-delimiter-description" class="description">Define a delimiter here to split the category name and slug. (default: $).</p>
    54                     <p class="example">Example : Level A / Level B$level-b1 / Level C$level-c1</p> 
     53                    <p id="<?php echo $this->plugin_name; ?>-delimiter-description" class="description"><?php esc_attr_e('Define a delimiter here to split the category name and slug. (default: $).', $this->plugin_name); ?></p> 
     54                    <p class="example"><?php esc_attr_e('Example : Level A / Level B$level-b1 / Level C$level-c1', $this->plugin_name); ?></p> 
    5555                </td>
    5656            </tr>   
     
    6969                </th>
    7070                <td>
    71                     <p class="description">Enter the categories you want to add.</p>
    72                     <p class="description">If you want to make a hierarchy, put a slash between the category and the sub-category in one line.</p>
    73                     <p class="example">Example : Level A/Level B/Level C</p>
     71                    <p class="description"><?php esc_attr_e('Enter the categories you want to add.', $this->plugin_name); ?></p>
     72                    <p class="description"><?php esc_attr_e('If you want to make a hierarchy, put a slash between the category and the sub-category in one line.', $this->plugin_name); ?></p>
     73                    <p class="example"><?php esc_attr_e('Example : Level A/Level B/Level C', $this->plugin_name); ?></p>
    7474                </td>
    7575            </tr>
     
    8787</div>
    8888<?php } else { ?>
    89     <p><?php __("You are not authorized to perform this operation.", $this->plugin_name); ?></p>
     89    <p><?php esc_attr_e('You are not authorized to perform this operation.', $this->plugin_name); ?></p>
    9090<?php  } ?>
  • category-import-reloaded/trunk/inc/core/class-internationalization-i18n.php

    r1859595 r2218909  
    4747            $this->text_domain,
    4848            false,
    49             dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
     49      dirname( dirname( dirname( plugin_basename( __FILE__ ) ) ) ) . '/languages/'
    5050        );
    5151    }
Note: See TracChangeset for help on using the changeset viewer.