Changeset 2218909
- Timestamp:
- 12/28/2019 11:02:55 AM (6 years ago)
- Location:
- category-import-reloaded/trunk
- Files:
-
- 3 added
- 5 edited
-
README.txt (modified) (2 diffs)
-
category-import-reloaded.php (modified) (2 diffs)
-
inc/admin/class-admin.php (modified) (11 diffs)
-
inc/admin/views/html-category-import-reloaded-admin-display.php (modified) (3 diffs)
-
inc/core/class-internationalization-i18n.php (modified) (1 diff)
-
languages/category-import-reloaded-ru_RU.mo (added)
-
languages/category-import-reloaded-ru_RU.po (added)
-
languages/category-import-reloaded.pot (added)
Legend:
- Unmodified
- Added
- Removed
-
category-import-reloaded/trunk/README.txt
r2088938 r2218909 1 1 === Category Import Reloaded === 2 Contributors: nir0ma 2 Contributors: nir0ma, aurovrata 3 3 Tags: category, taxonomy, import, create, bulk 4 4 Donate link: https://www.niroma.net 5 5 Requires at least: 3.0.1 6 Tested up to: 5. 26 Tested up to: 5.3.2 7 7 Requires PHP: 5.6.0 8 Stable tag: 1.1.08 Stable tag: trunk 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 71 71 = 1.1.0 = 72 72 * 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 16 16 * Plugin URI: http://wordpress.org/extend/plugins/category-import-reloaded/ 17 17 * 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. 018 * Version: 1.1.1 19 19 * Author: Niroma 20 20 * Author URI: https://www.niroma.net/ … … 40 40 define( NS . 'PLUGIN_NAME', 'category-import-reloaded' ); 41 41 42 define( NS . 'PLUGIN_VERSION', '1.1. 0' );42 define( NS . 'PLUGIN_VERSION', '1.1.1' ); 43 43 44 44 define( NS . 'PLUGIN_NAME_DIR', plugin_dir_path( __FILE__ ) ); -
category-import-reloaded/trunk/inc/admin/class-admin.php
r2073147 r2218909 103 103 104 104 } 105 105 106 106 public function display_plugin_setup_page() { 107 107 include_once( 'views/html-category-import-reloaded-admin-display.php' ); 108 108 } 109 109 110 110 public function add_plugin_admin_menu() { 111 111 … … 121 121 add_submenu_page( $this->plugin_name, 'Category Import Reloaded', 'Category Import', 'manage_categories', $this->plugin_name, array($this, 'display_plugin_setup_page') ); 122 122 } 123 124 123 124 125 125 private function termAlreadyExists($array, $key, $val, $return) { 126 126 foreach ($array as $item) { … … 132 132 return false; 133 133 } 134 135 134 135 136 136 public function check_for_event_submissions(){ 137 137 if ( isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], $this->plugin_name.'submit-taxonomies') ){ … … 147 147 $rootCategories = array(); 148 148 $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 153 152 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); 155 156 $l = count($split_line); 156 157 for ($i = 0; $i < $l; $i++) { 157 158 $new_line = $split_line[$i]; 158 159 $prev_line = ''; 159 160 160 161 if (strlen(trim($new_line)) == 0) break; 161 162 $new_line = sanitize_text_field(trim($new_line)); 162 163 163 164 if(strpos($new_line, $delimiter) !== false){ 164 165 $cat_name_slug = explode($delimiter,$new_line); … … 169 170 $cat_slug = $new_line; 170 171 } 171 172 172 173 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]; 175 177 $countErrors++; 176 178 } else { … … 178 180 if ( ! is_wp_error( $result ) ) { 179 181 $parent_id = isset( $result['term_id'] ) ? $result['term_id'] : ''; 180 $rootCategories[ ] = array('id' => $parent_id, 'name' => $cat_name);182 $rootCategories[$cat_name] = $parent_id; 181 183 $countSuccess++; 182 184 } else $countErrors++; … … 186 188 $siblingsCategories = array(); 187 189 $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]; 193 194 $countErrors++; 194 195 } else { … … 200 201 } 201 202 } else $countErrors++; 202 } 203 } 203 204 } 204 } 205 } 205 206 if ($countErrors > 0 ) { 206 207 $admin_notice = "error"; … … 210 211 $admin_notice = "success"; 211 212 $messageLog .= $countSuccess .' categories successully added ! '; 212 } 213 213 } 214 214 215 $this->custom_redirect( $admin_notice, $messageLog); 215 216 die(); … … 221 222 } 222 223 } 223 224 224 225 public function custom_redirect( $admin_notice, $response ) { 225 226 wp_redirect( esc_url_raw( add_query_arg( array( … … 227 228 'cir_response' => $response, 228 229 ), 229 admin_url('admin.php?page='. $this->plugin_name ) 230 admin_url('admin.php?page='. $this->plugin_name ) 230 231 ) ) ); 231 232 232 233 } 233 234 234 public function print_plugin_admin_notices() { 235 public function print_plugin_admin_notices() { 235 236 if ( isset( $_REQUEST['cir_admin_add_notice'] ) ) { 236 237 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"> 238 239 <p><strong>' . htmlspecialchars( print_r( $_REQUEST['cir_response'], true) ) . '</strong></p></div>'; 239 240 echo $html; 240 241 } 241 242 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"> 243 244 <p><strong>' . htmlspecialchars( print_r( $_REQUEST['cir_response'], true) ) . '</strong></p></div>'; 244 245 echo $html; -
category-import-reloaded/trunk/inc/admin/views/html-category-import-reloaded-admin-display.php
r1859595 r2218909 51 51 <td> 52 52 <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> 55 55 </td> 56 56 </tr> … … 69 69 </th> 70 70 <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> 74 74 </td> 75 75 </tr> … … 87 87 </div> 88 88 <?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> 90 90 <?php } ?> -
category-import-reloaded/trunk/inc/core/class-internationalization-i18n.php
r1859595 r2218909 47 47 $this->text_domain, 48 48 false, 49 dirname( dirname( plugin_basename( __FILE__) ) ) . '/languages/'49 dirname( dirname( dirname( plugin_basename( __FILE__ ) ) ) ) . '/languages/' 50 50 ); 51 51 }
Note: See TracChangeset
for help on using the changeset viewer.