Changeset 1818773
- Timestamp:
- 02/09/2018 07:55:15 AM (8 years ago)
- Location:
- tp-framework
- Files:
-
- 174 added
- 8 edited
-
tags/1.0.13 (added)
-
tags/1.0.13/LICENSE (added)
-
tags/1.0.13/addons (added)
-
tags/1.0.13/addons/importer (added)
-
tags/1.0.13/addons/importer/assets (added)
-
tags/1.0.13/addons/importer/assets/css (added)
-
tags/1.0.13/addons/importer/assets/css/style.css (added)
-
tags/1.0.13/addons/importer/assets/css/style.css.map (added)
-
tags/1.0.13/addons/importer/assets/img (added)
-
tags/1.0.13/addons/importer/assets/img/default-image.png (added)
-
tags/1.0.13/addons/importer/assets/img/no-image-preview.png (added)
-
tags/1.0.13/addons/importer/assets/js (added)
-
tags/1.0.13/addons/importer/assets/js/main.js (added)
-
tags/1.0.13/addons/importer/assets/scss (added)
-
tags/1.0.13/addons/importer/assets/scss/style.scss (added)
-
tags/1.0.13/addons/importer/dummy-data (added)
-
tags/1.0.13/addons/importer/dummy-data/theme-unit-test (added)
-
tags/1.0.13/addons/importer/dummy-data/theme-unit-test/screenshot.png (added)
-
tags/1.0.13/addons/importer/dummy-data/theme-unit-test/theme-unit-test-data.xml (added)
-
tags/1.0.13/addons/importer/dummy-data/theme-unit-test/widgets-monster.wie (added)
-
tags/1.0.13/addons/importer/dummy-data/woocommerce (added)
-
tags/1.0.13/addons/importer/dummy-data/woocommerce/dummy-data.xml (added)
-
tags/1.0.13/addons/importer/dummy-data/woocommerce/screenshot.png (added)
-
tags/1.0.13/addons/importer/dummy-data/woocommerce/widgets.wie (added)
-
tags/1.0.13/addons/importer/importer.php (added)
-
tags/1.0.13/addons/importer/includes (added)
-
tags/1.0.13/addons/importer/includes/class-importer-customize-setting.php (added)
-
tags/1.0.13/addons/importer/includes/class-importer-customizer.php (added)
-
tags/1.0.13/addons/importer/includes/class-importer-downloader.php (added)
-
tags/1.0.13/addons/importer/includes/class-importer-widgets.php (added)
-
tags/1.0.13/addons/importer/includes/helper-functions.php (added)
-
tags/1.0.13/addons/importer/templates (added)
-
tags/1.0.13/addons/importer/templates/available.php (added)
-
tags/1.0.13/addons/importer/templates/upload.php (added)
-
tags/1.0.13/addons/importer/wordpress-importer (added)
-
tags/1.0.13/addons/importer/wordpress-importer/parsers.php (added)
-
tags/1.0.13/addons/importer/wordpress-importer/wordpress-importer.php (added)
-
tags/1.0.13/assets (added)
-
tags/1.0.13/assets/css (added)
-
tags/1.0.13/assets/css/_field-textfield.css (added)
-
tags/1.0.13/assets/css/_field-textfield.css.map (added)
-
tags/1.0.13/assets/css/_field-widget.css (added)
-
tags/1.0.13/assets/css/_field-widget.css.map (added)
-
tags/1.0.13/assets/css/admin.css (added)
-
tags/1.0.13/assets/css/admin.css.map (added)
-
tags/1.0.13/assets/css/admin.min.css (added)
-
tags/1.0.13/assets/css/font-awesome.css (added)
-
tags/1.0.13/assets/css/font-awesome.min.css (added)
-
tags/1.0.13/assets/css/front.css (added)
-
tags/1.0.13/assets/css/front.css.map (added)
-
tags/1.0.13/assets/css/front.min.css (added)
-
tags/1.0.13/assets/fonts (added)
-
tags/1.0.13/assets/fonts/FontAwesome.otf (added)
-
tags/1.0.13/assets/fonts/fontawesome-webfont.eot (added)
-
tags/1.0.13/assets/fonts/fontawesome-webfont.svg (added)
-
tags/1.0.13/assets/fonts/fontawesome-webfont.ttf (added)
-
tags/1.0.13/assets/fonts/fontawesome-webfont.woff (added)
-
tags/1.0.13/assets/fonts/fontawesome-webfont.woff2 (added)
-
tags/1.0.13/assets/images (added)
-
tags/1.0.13/assets/images/add-large.png (added)
-
tags/1.0.13/assets/images/add.png (added)
-
tags/1.0.13/assets/images/move.png (added)
-
tags/1.0.13/assets/images/remove.png (added)
-
tags/1.0.13/assets/images/select2-spinner.gif (added)
-
tags/1.0.13/assets/images/select2.png (added)
-
tags/1.0.13/assets/images/select2x2.png (added)
-
tags/1.0.13/assets/js (added)
-
tags/1.0.13/assets/js/admin_fields.js (added)
-
tags/1.0.13/assets/js/admin_fields.min.js (added)
-
tags/1.0.13/assets/js/customize-fields.js (added)
-
tags/1.0.13/assets/js/customize-fields.min.js (added)
-
tags/1.0.13/assets/js/front.js (added)
-
tags/1.0.13/assets/js/front.min.js (added)
-
tags/1.0.13/assets/js/libs.js (added)
-
tags/1.0.13/assets/js/libs.min.js (added)
-
tags/1.0.13/assets/js/repeater-libs.js (added)
-
tags/1.0.13/assets/js/repeater-libs.min.js (added)
-
tags/1.0.13/assets/scss (added)
-
tags/1.0.13/assets/scss/_field-file.scss (added)
-
tags/1.0.13/assets/scss/_field-group.scss (added)
-
tags/1.0.13/assets/scss/_field-repeater.scss (added)
-
tags/1.0.13/assets/scss/_field-textfield.scss (added)
-
tags/1.0.13/assets/scss/_field-typography.scss (added)
-
tags/1.0.13/assets/scss/_field-widget.scss (added)
-
tags/1.0.13/assets/scss/_vars.scss (added)
-
tags/1.0.13/assets/scss/admin.scss (added)
-
tags/1.0.13/assets/scss/front.scss (added)
-
tags/1.0.13/assets/vendors (added)
-
tags/1.0.13/assets/vendors/datetimepicker (added)
-
tags/1.0.13/assets/vendors/datetimepicker/jquery.datetimepicker.css (added)
-
tags/1.0.13/assets/vendors/datetimepicker/jquery.datetimepicker.js (added)
-
tags/1.0.13/assets/vendors/datetimepicker/jquery.datetimepicker.min.css (added)
-
tags/1.0.13/assets/vendors/datetimepicker/jquery.datetimepicker.min.js (added)
-
tags/1.0.13/assets/vendors/dependency (added)
-
tags/1.0.13/assets/vendors/dependency/dependency.js (added)
-
tags/1.0.13/assets/vendors/dependency/dependency.min.js (added)
-
tags/1.0.13/assets/vendors/fonticonpicker (added)
-
tags/1.0.13/assets/vendors/fonticonpicker/css (added)
-
tags/1.0.13/assets/vendors/fonticonpicker/css/jquery.fonticonpicker.css (added)
-
tags/1.0.13/assets/vendors/fonticonpicker/css/jquery.fonticonpicker.min.css (added)
-
tags/1.0.13/assets/vendors/fonticonpicker/fonts (added)
-
tags/1.0.13/assets/vendors/fonticonpicker/fonts/iconpicker.eot (added)
-
tags/1.0.13/assets/vendors/fonticonpicker/fonts/iconpicker.svg (added)
-
tags/1.0.13/assets/vendors/fonticonpicker/fonts/iconpicker.ttf (added)
-
tags/1.0.13/assets/vendors/fonticonpicker/fonts/iconpicker.woff (added)
-
tags/1.0.13/assets/vendors/fonticonpicker/js (added)
-
tags/1.0.13/assets/vendors/fonticonpicker/js/jquery.fonticonpicker.js (added)
-
tags/1.0.13/assets/vendors/fonticonpicker/js/jquery.fonticonpicker.min.js (added)
-
tags/1.0.13/assets/vendors/geocomplete (added)
-
tags/1.0.13/assets/vendors/geocomplete/jquery.geocomplete.js (added)
-
tags/1.0.13/assets/vendors/geocomplete/jquery.geocomplete.min.js (added)
-
tags/1.0.13/assets/vendors/selectize (added)
-
tags/1.0.13/assets/vendors/selectize/selectize.css (added)
-
tags/1.0.13/assets/vendors/selectize/selectize.default.css (added)
-
tags/1.0.13/assets/vendors/selectize/selectize.default.min.css (added)
-
tags/1.0.13/assets/vendors/selectize/selectize.js (added)
-
tags/1.0.13/assets/vendors/selectize/selectize.legacy.css (added)
-
tags/1.0.13/assets/vendors/selectize/selectize.legacy.min.css (added)
-
tags/1.0.13/assets/vendors/selectize/selectize.min.css (added)
-
tags/1.0.13/assets/vendors/selectize/selectize.min.js (added)
-
tags/1.0.13/assets/vendors/selectize/spinner.gif (added)
-
tags/1.0.13/includes (added)
-
tags/1.0.13/includes/admin-fields (added)
-
tags/1.0.13/includes/admin-fields/field_autocomplete.php (added)
-
tags/1.0.13/includes/admin-fields/field_color_picker.php (added)
-
tags/1.0.13/includes/admin-fields/field_datetime.php (added)
-
tags/1.0.13/includes/admin-fields/field_default.php (added)
-
tags/1.0.13/includes/admin-fields/field_icon_picker.php (added)
-
tags/1.0.13/includes/admin-fields/field_image_picker.php (added)
-
tags/1.0.13/includes/admin-fields/field_image_select.php (added)
-
tags/1.0.13/includes/admin-fields/field_link.php (added)
-
tags/1.0.13/includes/admin-fields/field_map.php (added)
-
tags/1.0.13/includes/admin-fields/field_repeater.php (added)
-
tags/1.0.13/includes/admin-fields/field_typography.php (added)
-
tags/1.0.13/includes/admin-fields/field_upload.php (added)
-
tags/1.0.13/includes/class-tpfw-customizer.php (added)
-
tags/1.0.13/includes/class-tpfw-fonts.php (added)
-
tags/1.0.13/includes/class-tpfw-menu.php (added)
-
tags/1.0.13/includes/class-tpfw-metabox.php (added)
-
tags/1.0.13/includes/class-tpfw-taxonomy.php (added)
-
tags/1.0.13/includes/class-tpfw-widget.php (added)
-
tags/1.0.13/includes/customize-fields (added)
-
tags/1.0.13/includes/customize-fields/field_autocomplete.php (added)
-
tags/1.0.13/includes/customize-fields/field_datetime.php (added)
-
tags/1.0.13/includes/customize-fields/field_heading.php (added)
-
tags/1.0.13/includes/customize-fields/field_icon_picker.php (added)
-
tags/1.0.13/includes/customize-fields/field_image_select.php (added)
-
tags/1.0.13/includes/customize-fields/field_link.php (added)
-
tags/1.0.13/includes/customize-fields/field_map.php (added)
-
tags/1.0.13/includes/customize-fields/field_multicheck.php (added)
-
tags/1.0.13/includes/customize-fields/field_repeater.php (added)
-
tags/1.0.13/includes/customize-fields/field_select.php (added)
-
tags/1.0.13/includes/customize-fields/field_typography.php (added)
-
tags/1.0.13/includes/googlefonts.php (added)
-
tags/1.0.13/includes/tpfw-helpers-functions.php (added)
-
tags/1.0.13/includes/tpfw-sanitize-functions.php (added)
-
tags/1.0.13/languages (added)
-
tags/1.0.13/languages/tp-framework.pot (added)
-
tags/1.0.13/readme.txt (added)
-
tags/1.0.13/sample (added)
-
tags/1.0.13/sample/assets (added)
-
tags/1.0.13/sample/assets/opt-1.jpg (added)
-
tags/1.0.13/sample/assets/opt-2.jpg (added)
-
tags/1.0.13/sample/assets/opt-3.jpg (added)
-
tags/1.0.13/sample/assets/sidebar-left.jpg (added)
-
tags/1.0.13/sample/assets/sidebar-none.jpg (added)
-
tags/1.0.13/sample/assets/sidebar-right.jpg (added)
-
tags/1.0.13/sample/customizer.php (added)
-
tags/1.0.13/sample/menu.php (added)
-
tags/1.0.13/sample/post-meta.php (added)
-
tags/1.0.13/sample/sample.php (added)
-
tags/1.0.13/sample/taxonomy.php (added)
-
tags/1.0.13/sample/widget.php (added)
-
tags/1.0.13/tp-framework.php (added)
-
trunk/addons/importer/wordpress-importer/wordpress-importer.php (modified) (69 diffs)
-
trunk/assets/js/customize-fields.js (modified) (1 diff)
-
trunk/assets/js/customize-fields.min.js (modified) (1 diff)
-
trunk/assets/vendors/dependency/dependency.js (modified) (17 diffs)
-
trunk/assets/vendors/dependency/dependency.min.js (modified) (1 diff)
-
trunk/includes/class-tpfw-customizer.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/tp-framework.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tp-framework/trunk/addons/importer/wordpress-importer/wordpress-importer.php
r1734156 r1818773 37 37 if ( class_exists( 'WP_Importer' ) ) { 38 38 39 class WP_Import extends WP_Importer 40 { 39 class WP_Import extends WP_Importer { 41 40 42 41 var $max_wxr_version = 1.2; // max. supported WXR version … … 68 67 * Manages the three separate stages of the WXR import process 69 68 */ 70 function dispatch() 71 { 69 function dispatch() { 72 70 $this->header(); 73 71 74 $step = empty( $_GET[ 'step' ] ) ? 0 : (int)$_GET[ 'step'];72 $step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step']; 75 73 switch ( $step ) { 76 74 case 0: … … 84 82 case 2: 85 83 check_admin_referer( 'import-wordpress' ); 86 $this->fetch_attachments = ( !empty( $_POST[ 'fetch_attachments'] ) && $this->allow_fetch_attachments() );87 $this->id = (int) $_POST[ 'import_id'];84 $this->fetch_attachments = (!empty( $_POST['fetch_attachments'] ) && $this->allow_fetch_attachments() ); 85 $this->id = (int) $_POST['import_id']; 88 86 $file = get_attached_file( $this->id ); 89 87 set_time_limit( 0 ); … … 100 98 * @param string $file Path to the WXR file for importing 101 99 */ 102 function import( $file ) 103 { 100 function import( $file ) { 104 101 105 102 add_filter( 'import_post_meta_key', array( $this, 'is_valid_meta_key' ) ); … … 130 127 * @param string $file Path to the WXR file for importing 131 128 */ 132 function import_start( $file ) 133 { 129 function import_start( $file ) { 134 130 if ( !is_file( $file ) ) { 135 131 echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '</strong><br />'; … … 148 144 } 149 145 150 $this->version = $import_data[ 'version'];146 $this->version = $import_data['version']; 151 147 $this->get_authors_from_import( $import_data ); 152 $this->posts = $import_data[ 'posts'];153 $this->terms = $import_data[ 'terms'];154 $this->categories = $import_data[ 'categories'];155 $this->tags = $import_data[ 'tags'];156 $this->base_url = esc_url( $import_data[ 'base_url'] );148 $this->posts = $import_data['posts']; 149 $this->terms = $import_data['terms']; 150 $this->categories = $import_data['categories']; 151 $this->tags = $import_data['tags']; 152 $this->base_url = esc_url( $import_data['base_url'] ); 157 153 158 154 wp_defer_term_counting( true ); … … 165 161 * Performs post-import cleanup of files and the cache 166 162 */ 167 function import_end() 168 { 163 function import_end() { 169 164 wp_import_cleanup( $this->id ); 170 165 … … 190 185 * @return bool False if error uploading or invalid file, true otherwise 191 186 */ 192 function handle_upload() 193 { 187 function handle_upload() { 194 188 $file = wp_import_handle_upload(); 195 189 196 if ( isset( $file[ 'error'] ) ) {190 if ( isset( $file['error'] ) ) { 197 191 echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '</strong><br />'; 198 echo esc_html( $file[ 'error'] ) . '</p>';192 echo esc_html( $file['error'] ) . '</p>'; 199 193 return false; 200 } else if ( !file_exists( $file[ 'file'] ) ) {194 } else if ( !file_exists( $file['file'] ) ) { 201 195 echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '</strong><br />'; 202 printf( __( 'The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'wordpress-importer' ), esc_html( $file[ 'file'] ) );196 printf( __( 'The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'wordpress-importer' ), esc_html( $file['file'] ) ); 203 197 echo '</p>'; 204 198 return false; 205 199 } 206 200 207 $this->id = (int) $file[ 'id'];208 $import_data = $this->parse( $file[ 'file'] );201 $this->id = (int) $file['id']; 202 $import_data = $this->parse( $file['file'] ); 209 203 if ( is_wp_error( $import_data ) ) { 210 204 echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '</strong><br />'; … … 213 207 } 214 208 215 $this->version = $import_data[ 'version'];209 $this->version = $import_data['version']; 216 210 if ( $this->version > $this->max_wxr_version ) { 217 211 echo '<div class="error"><p><strong>'; 218 printf( __( 'This WXR file (version %s) may not be supported by this version of the importer. Please consider updating.', 'wordpress-importer' ), esc_html( $import_data[ 'version'] ) );212 printf( __( 'This WXR file (version %s) may not be supported by this version of the importer. Please consider updating.', 'wordpress-importer' ), esc_html( $import_data['version'] ) ); 219 213 echo '</strong></p></div>'; 220 214 } … … 233 227 * @param array $import_data Data returned by a WXR parser 234 228 */ 235 function get_authors_from_import( $import_data ) 236 { 237 if ( !empty( $import_data[ 'authors' ] ) ) { 238 $this->authors = $import_data[ 'authors' ]; 229 function get_authors_from_import( $import_data ) { 230 if ( !empty( $import_data['authors'] ) ) { 231 $this->authors = $import_data['authors']; 239 232 // no author information, grab it from the posts 240 233 } else { 241 foreach ( $import_data[ 'posts'] as $post ) {242 $login = sanitize_user( $post[ 'post_author'], true );234 foreach ( $import_data['posts'] as $post ) { 235 $login = sanitize_user( $post['post_author'], true ); 243 236 if ( empty( $login ) ) { 244 printf( __( 'Failed to import author %s. Their posts will be attributed to the current user.', 'wordpress-importer' ), esc_html( $post[ 'post_author'] ) );237 printf( __( 'Failed to import author %s. Their posts will be attributed to the current user.', 'wordpress-importer' ), esc_html( $post['post_author'] ) ); 245 238 echo '<br />'; 246 239 continue; 247 240 } 248 241 249 if ( !isset( $this->authors[ $login] ) )250 $this->authors[ $login] = array(251 'author_login' => $login,252 'author_display_name' => $post[ 'post_author']242 if ( !isset( $this->authors[$login] ) ) 243 $this->authors[$login] = array( 244 'author_login' => $login, 245 'author_display_name' => $post['post_author'] 253 246 ); 254 247 } … … 260 253 * fetch attachments 261 254 */ 262 function import_options() 263 { 255 function import_options() { 264 256 $j = 0; 265 257 ?> 266 <form action="<?php echo admin_url( 'admin.php?import=wordpress&step=2' ); ?>" method="post">267 <?php wp_nonce_field( 'import-wordpress' ); ?>268 <input type="hidden" name="import_id" value="<?php echo $this->id; ?>"/>269 270 <?php if ( !empty( $this->authors ) ) : ?>271 <h3><?php _e( 'Assign Authors', 'wordpress-importer' ); ?></h3>272 <p><?php _e( 'To make it easier for you to edit and save the imported content, you may want to reassign the author of the imported item to an existing user of this site. For example, you may want to import all the entries as <code>admin</code>s entries.', 'wordpress-importer' ); ?></p>273 <?php if ( $this->allow_create_users() ) : ?>274 <p><?php printf( __( 'If a new user is created by WordPress, a new password will be randomly generated and the new user’s role will be set as %s. Manually changing the new user’s details will be necessary.', 'wordpress-importer' ), esc_html( get_option( 'default_role' ) ) ); ?></p>258 <form action="<?php echo admin_url( 'admin.php?import=wordpress&step=2' ); ?>" method="post"> 259 <?php wp_nonce_field( 'import-wordpress' ); ?> 260 <input type="hidden" name="import_id" value="<?php echo $this->id; ?>"/> 261 262 <?php if ( !empty( $this->authors ) ) : ?> 263 <h3><?php _e( 'Assign Authors', 'wordpress-importer' ); ?></h3> 264 <p><?php _e( 'To make it easier for you to edit and save the imported content, you may want to reassign the author of the imported item to an existing user of this site. For example, you may want to import all the entries as <code>admin</code>s entries.', 'wordpress-importer' ); ?></p> 265 <?php if ( $this->allow_create_users() ) : ?> 266 <p><?php printf( __( 'If a new user is created by WordPress, a new password will be randomly generated and the new user’s role will be set as %s. Manually changing the new user’s details will be necessary.', 'wordpress-importer' ), esc_html( get_option( 'default_role' ) ) ); ?></p> 275 267 <?php endif; ?> 276 <ol id="authors">277 <?php foreach ( $this->authors as $author ) : ?>278 <li><?php $this->author_select( $j++, $author ); ?></li>279 <?php endforeach; ?>280 </ol>268 <ol id="authors"> 269 <?php foreach ( $this->authors as $author ) : ?> 270 <li><?php $this->author_select( $j++, $author ); ?></li> 271 <?php endforeach; ?> 272 </ol> 281 273 <?php endif; ?> 282 274 283 275 <?php if ( $this->allow_fetch_attachments() ) : ?> 284 <h3><?php _e( 'Import Attachments', 'wordpress-importer' ); ?></h3>285 <p>286 <input type="checkbox" value="1" name="fetch_attachments" id="import-attachments"/>287 <label for="import-attachments"><?php _e( 'Download and import file attachments', 'wordpress-importer' ); ?></label>288 </p>276 <h3><?php _e( 'Import Attachments', 'wordpress-importer' ); ?></h3> 277 <p> 278 <input type="checkbox" value="1" name="fetch_attachments" id="import-attachments"/> 279 <label for="import-attachments"><?php _e( 'Download and import file attachments', 'wordpress-importer' ); ?></label> 280 </p> 289 281 <?php endif; ?> 290 282 291 <p class="submit"><input type="submit" class="button"292 value="<?php esc_attr_e( 'Submit', 'wordpress-importer' ); ?>"/></p>293 </form>283 <p class="submit"><input type="submit" class="button" 284 value="<?php esc_attr_e( 'Submit', 'wordpress-importer' ); ?>"/></p> 285 </form> 294 286 <?php 295 287 } … … 302 294 * @param array $author Author information, e.g. login, display name, email 303 295 */ 304 function author_select( $n, $author ) 305 { 296 function author_select( $n, $author ) { 306 297 _e( 'Import author:', 'wordpress-importer' ); 307 echo ' <strong>' . esc_html( $author[ 'author_display_name'] );298 echo ' <strong>' . esc_html( $author['author_display_name'] ); 308 299 if ( $this->version != '1.0' ) 309 echo ' (' . esc_html( $author[ 'author_login'] ) . ')';300 echo ' (' . esc_html( $author['author_login'] ) . ')'; 310 301 echo '</strong><br />'; 311 302 … … 320 311 } else { 321 312 _e( 'as a new user:', 'wordpress-importer' ); 322 $value = esc_attr( sanitize_user( $author[ 'author_login'], true ) );313 $value = esc_attr( sanitize_user( $author['author_login'], true ) ); 323 314 } 324 315 … … 331 322 _e( 'or assign posts to an existing user:', 'wordpress-importer' ); 332 323 wp_dropdown_users( array( 'name' => "user_map[$n]", 'multi' => true, 'show_option_all' => __( '- Select -', 'wordpress-importer' ) ) ); 333 echo '<input type="hidden" name="imported_authors[' . $n . ']" value="' . esc_attr( $author[ 'author_login'] ) . '" />';324 echo '<input type="hidden" name="imported_authors[' . $n . ']" value="' . esc_attr( $author['author_login'] ) . '" />'; 334 325 335 326 if ( $this->version != '1.0' ) … … 342 333 * or falls back to the current user in case of error with either of the previous 343 334 */ 344 function get_author_mapping() 345 { 346 if ( !isset( $_POST[ 'imported_authors' ] ) ) 335 function get_author_mapping() { 336 if ( !isset( $_POST['imported_authors'] ) ) 347 337 return; 348 338 349 339 $create_users = $this->allow_create_users(); 350 340 351 foreach ( (array) $_POST[ 'imported_authors'] as $i => $old_login ) {341 foreach ( (array) $_POST['imported_authors'] as $i => $old_login ) { 352 342 // Multisite adds strtolower to sanitize_user. Need to sanitize here to stop breakage in process_posts. 353 343 $santized_old_login = sanitize_user( $old_login, true ); 354 $old_id = isset( $this->authors[ $old_login ][ 'author_id' ] ) ? intval( $this->authors[ $old_login ][ 'author_id'] ) : false;355 356 if ( !empty( $_POST[ 'user_map' ][ $i] ) ) {357 $user = get_userdata( intval( $_POST[ 'user_map' ][ $i] ) );344 $old_id = isset( $this->authors[$old_login]['author_id'] ) ? intval( $this->authors[$old_login]['author_id'] ) : false; 345 346 if ( !empty( $_POST['user_map'][$i] ) ) { 347 $user = get_userdata( intval( $_POST['user_map'][$i] ) ); 358 348 if ( isset( $user->ID ) ) { 359 349 if ( $old_id ) 360 $this->processed_authors[ $old_id] = $user->ID;361 $this->author_mapping[ $santized_old_login] = $user->ID;350 $this->processed_authors[$old_id] = $user->ID; 351 $this->author_mapping[$santized_old_login] = $user->ID; 362 352 } 363 353 } else if ( $create_users ) { 364 if ( !empty( $_POST[ 'user_new' ][ $i] ) ) {365 $user_id = wp_create_user( $_POST[ 'user_new' ][ $i], wp_generate_password() );354 if ( !empty( $_POST['user_new'][$i] ) ) { 355 $user_id = wp_create_user( $_POST['user_new'][$i], wp_generate_password() ); 366 356 } else if ( $this->version != '1.0' ) { 367 357 $user_data = array( 368 'user_login' => $old_login,369 'user_pass' => wp_generate_password(),370 'user_email' => isset( $this->authors[ $old_login ][ 'author_email' ] ) ? $this->authors[ $old_login ][ 'author_email'] : '',371 'display_name' => $this->authors[ $old_login ][ 'author_display_name'],372 'first_name' => isset( $this->authors[ $old_login ][ 'author_first_name' ] ) ? $this->authors[ $old_login ][ 'author_first_name'] : '',373 'last_name' => isset( $this->authors[ $old_login ][ 'author_last_name' ] ) ? $this->authors[ $old_login ][ 'author_last_name'] : '',358 'user_login' => $old_login, 359 'user_pass' => wp_generate_password(), 360 'user_email' => isset( $this->authors[$old_login]['author_email'] ) ? $this->authors[$old_login]['author_email'] : '', 361 'display_name' => $this->authors[$old_login]['author_display_name'], 362 'first_name' => isset( $this->authors[$old_login]['author_first_name'] ) ? $this->authors[$old_login]['author_first_name'] : '', 363 'last_name' => isset( $this->authors[$old_login]['author_last_name'] ) ? $this->authors[$old_login]['author_last_name'] : '', 374 364 ); 375 365 $user_id = wp_insert_user( $user_data ); … … 378 368 if ( !is_wp_error( $user_id ) ) { 379 369 if ( $old_id ) 380 $this->processed_authors[ $old_id] = $user_id;381 $this->author_mapping[ $santized_old_login] = $user_id;370 $this->processed_authors[$old_id] = $user_id; 371 $this->author_mapping[$santized_old_login] = $user_id; 382 372 } else { 383 printf( __( 'Failed to create new user for %s. Their posts will be attributed to the current user.', 'wordpress-importer' ), esc_html( $this->authors[ $old_login ][ 'author_display_name'] ) );373 printf( __( 'Failed to create new user for %s. Their posts will be attributed to the current user.', 'wordpress-importer' ), esc_html( $this->authors[$old_login]['author_display_name'] ) ); 384 374 if ( defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) 385 375 echo ' ' . $user_id->get_error_message(); … … 389 379 390 380 // failsafe: if the user_id was invalid, default to the current user 391 if ( !isset( $this->author_mapping[ $santized_old_login] ) ) {381 if ( !isset( $this->author_mapping[$santized_old_login] ) ) { 392 382 if ( $old_id ) 393 $this->processed_authors[ $old_id ] = (int)get_current_user_id();394 $this->author_mapping[ $santized_old_login ] = (int)get_current_user_id();383 $this->processed_authors[$old_id] = (int) get_current_user_id(); 384 $this->author_mapping[$santized_old_login] = (int) get_current_user_id(); 395 385 } 396 386 } … … 402 392 * Doesn't create a new category if its slug already exists 403 393 */ 404 function process_categories() 405 { 394 function process_categories() { 406 395 $this->categories = apply_filters( 'wp_import_categories', $this->categories ); 407 396 … … 411 400 foreach ( $this->categories as $cat ) { 412 401 // if the category already exists leave it alone 413 $term_id = term_exists( $cat[ 'category_nicename'], 'category' );402 $term_id = term_exists( $cat['category_nicename'], 'category' ); 414 403 if ( $term_id ) { 415 404 if ( is_array( $term_id ) ) 416 $term_id = $term_id[ 'term_id'];417 if ( isset( $cat[ 'term_id'] ) )418 $this->processed_terms[ intval( $cat[ 'term_id' ] ) ] = (int)$term_id;405 $term_id = $term_id['term_id']; 406 if ( isset( $cat['term_id'] ) ) 407 $this->processed_terms[intval( $cat['term_id'] )] = (int) $term_id; 419 408 continue; 420 409 } 421 410 422 $category_parent = empty( $cat[ 'category_parent' ] ) ? 0 : category_exists( $cat[ 'category_parent'] );423 $category_description = isset( $cat[ 'category_description' ] ) ? $cat[ 'category_description'] : '';411 $category_parent = empty( $cat['category_parent'] ) ? 0 : category_exists( $cat['category_parent'] ); 412 $category_description = isset( $cat['category_description'] ) ? $cat['category_description'] : ''; 424 413 $catarr = array( 425 'category_nicename' => $cat[ 'category_nicename'],426 'category_parent' => $category_parent,427 'cat_name' => $cat[ 'cat_name'],414 'category_nicename' => $cat['category_nicename'], 415 'category_parent' => $category_parent, 416 'cat_name' => $cat['cat_name'], 428 417 'category_description' => $category_description 429 418 ); … … 432 421 $id = wp_insert_category( $catarr ); 433 422 if ( !is_wp_error( $id ) ) { 434 if ( isset( $cat[ 'term_id'] ) )435 $this->processed_terms[ intval( $cat[ 'term_id' ] )] = $id;423 if ( isset( $cat['term_id'] ) ) 424 $this->processed_terms[intval( $cat['term_id'] )] = $id; 436 425 } else { 437 printf( __( 'Failed to import category %s', 'wordpress-importer' ), esc_html( $cat[ 'category_nicename'] ) );426 printf( __( 'Failed to import category %s', 'wordpress-importer' ), esc_html( $cat['category_nicename'] ) ); 438 427 if ( defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) 439 428 echo ': ' . $id->get_error_message(); … … 442 431 } 443 432 444 $this->process_termmeta( $cat, $id[ 'term_id'] );433 $this->process_termmeta( $cat, $id['term_id'] ); 445 434 } 446 435 … … 453 442 * Doesn't create a tag if its slug already exists 454 443 */ 455 function process_tags() 456 { 444 function process_tags() { 457 445 $this->tags = apply_filters( 'wp_import_tags', $this->tags ); 458 446 … … 462 450 foreach ( $this->tags as $tag ) { 463 451 // if the tag already exists leave it alone 464 $term_id = term_exists( $tag[ 'tag_slug'], 'post_tag' );452 $term_id = term_exists( $tag['tag_slug'], 'post_tag' ); 465 453 if ( $term_id ) { 466 454 if ( is_array( $term_id ) ) 467 $term_id = $term_id[ 'term_id'];468 if ( isset( $tag[ 'term_id'] ) )469 $this->processed_terms[ intval( $tag[ 'term_id' ] ) ] = (int)$term_id;455 $term_id = $term_id['term_id']; 456 if ( isset( $tag['term_id'] ) ) 457 $this->processed_terms[intval( $tag['term_id'] )] = (int) $term_id; 470 458 continue; 471 459 } 472 460 473 461 $tag = wp_slash( $tag ); 474 $tag_desc = isset( $tag[ 'tag_description' ] ) ? $tag[ 'tag_description'] : '';475 $tagarr = array( 'slug' => $tag[ 'tag_slug'], 'description' => $tag_desc );476 477 $id = wp_insert_term( $tag[ 'tag_name'], 'post_tag', $tagarr );462 $tag_desc = isset( $tag['tag_description'] ) ? $tag['tag_description'] : ''; 463 $tagarr = array( 'slug' => $tag['tag_slug'], 'description' => $tag_desc ); 464 465 $id = wp_insert_term( $tag['tag_name'], 'post_tag', $tagarr ); 478 466 if ( !is_wp_error( $id ) ) { 479 if ( isset( $tag[ 'term_id'] ) )480 $this->processed_terms[ intval( $tag[ 'term_id' ] ) ] = $id[ 'term_id'];467 if ( isset( $tag['term_id'] ) ) 468 $this->processed_terms[intval( $tag['term_id'] )] = $id['term_id']; 481 469 } else { 482 printf( __( 'Failed to import post tag %s', 'wordpress-importer' ), esc_html( $tag[ 'tag_name'] ) );470 printf( __( 'Failed to import post tag %s', 'wordpress-importer' ), esc_html( $tag['tag_name'] ) ); 483 471 if ( defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) 484 472 echo ': ' . $id->get_error_message(); … … 487 475 } 488 476 489 $this->process_termmeta( $tag, $id[ 'term_id'] );477 $this->process_termmeta( $tag, $id['term_id'] ); 490 478 } 491 479 … … 498 486 * Doesn't create a term its slug already exists 499 487 */ 500 function process_terms() 501 { 488 function process_terms() { 502 489 503 490 global $wpdb; … … 510 497 foreach ( $this->terms as $term ) { 511 498 // if the term already exists in the correct taxonomy leave it alone 512 $term_id = term_exists( $term[ 'slug' ], $term[ 'term_taxonomy'] );499 $term_id = term_exists( $term['slug'], $term['term_taxonomy'] ); 513 500 if ( $term_id ) { 514 501 if ( is_array( $term_id ) ) 515 $term_id = $term_id[ 'term_id'];516 if ( isset( $term[ 'term_id'] ) )517 $this->processed_terms[ intval( $term[ 'term_id' ] ) ] = (int)$term_id;502 $term_id = $term_id['term_id']; 503 if ( isset( $term['term_id'] ) ) 504 $this->processed_terms[intval( $term['term_id'] )] = (int) $term_id; 518 505 continue; 519 506 } 520 507 521 if ( empty( $term[ 'term_parent'] ) ) {508 if ( empty( $term['term_parent'] ) ) { 522 509 $parent = 0; 523 510 } else { 524 $parent = term_exists( $term[ 'term_parent' ], $term[ 'term_taxonomy'] );511 $parent = term_exists( $term['term_parent'], $term['term_taxonomy'] ); 525 512 if ( is_array( $parent ) ) 526 $parent = $parent[ 'term_id'];513 $parent = $parent['term_id']; 527 514 } 528 515 … … 534 521 535 522 $termmeta = ''; 536 if ( strstr( $term[ 'term_taxonomy'], 'pa_' ) ) {537 538 if ( !taxonomy_exists( $term[ 'term_taxonomy'] ) ) {539 $attribute_name = wc_sanitize_taxonomy_name( str_replace( 'pa_', '', $term[ 'term_taxonomy'] ) );523 if ( strstr( $term['term_taxonomy'], 'pa_' ) ) { 524 525 if ( !taxonomy_exists( $term['term_taxonomy'] ) ) { 526 $attribute_name = wc_sanitize_taxonomy_name( str_replace( 'pa_', '', $term['term_taxonomy'] ) ); 540 527 541 528 // Create the taxonomy 542 529 if ( !in_array( $attribute_name, wc_get_attribute_taxonomies() ) ) { 543 530 $attribute = array( 544 'attribute_label' => $attribute_name,545 'attribute_name' => $attribute_name,546 'attribute_type' => 'select',531 'attribute_label' => $attribute_name, 532 'attribute_name' => $attribute_name, 533 'attribute_type' => 'select', 547 534 'attribute_orderby' => 'menu_order', 548 'attribute_public' => 0535 'attribute_public' => 0 549 536 ); 550 537 $wpdb->insert( $wpdb->prefix . 'woocommerce_attribute_taxonomies', $attribute ); … … 554 541 // Register the taxonomy now so that the import works! 555 542 register_taxonomy( 556 $term[ 'term_taxonomy' ], apply_filters( 'woocommerce_taxonomy_objects_' . $term[ 'term_taxonomy' ], array( 'product' ) ), apply_filters( 'woocommerce_taxonomy_args_' . $term[ 'term_taxonomy'], array(557 'hierarchical' => true,558 'show_ui'=> false,559 'query_var'=> true,560 'rewrite'=> false,561 ) )543 $term['term_taxonomy'], apply_filters( 'woocommerce_taxonomy_objects_' . $term['term_taxonomy'], array( 'product' ) ), apply_filters( 'woocommerce_taxonomy_args_' . $term['term_taxonomy'], array( 544 'hierarchical' => true, 545 'show_ui' => false, 546 'query_var' => true, 547 'rewrite' => false, 548 ) ) 562 549 ); 563 550 564 if ( isset( $term[ 'termmeta'] ) ) {565 $termmeta = $term[ 'termmeta'];551 if ( isset( $term['termmeta'] ) ) { 552 $termmeta = $term['termmeta']; 566 553 } 567 554 } … … 570 557 571 558 $term = wp_slash( $term ); 572 $description = isset( $term[ 'term_description' ] ) ? $term[ 'term_description'] : '';573 $termarr = array( 'slug' => $term[ 'slug'], 'description' => $description, 'parent' => intval( $parent ) );574 575 $id = wp_insert_term( $term[ 'term_name' ], $term[ 'term_taxonomy'], $termarr );559 $description = isset( $term['term_description'] ) ? $term['term_description'] : ''; 560 $termarr = array( 'slug' => $term['slug'], 'description' => $description, 'parent' => intval( $parent ) ); 561 562 $id = wp_insert_term( $term['term_name'], $term['term_taxonomy'], $termarr ); 576 563 577 564 578 565 if ( !is_wp_error( $id ) ) { 579 566 580 if ( isset( $term[ 'term_id'] ) ) {581 $this->processed_terms[ intval( $term[ 'term_id' ] ) ] = $id[ 'term_id'];567 if ( isset( $term['term_id'] ) ) { 568 $this->processed_terms[intval( $term['term_id'] )] = $id['term_id']; 582 569 583 570 // Add woocommerce attribute termmeta data 584 571 if ( !empty( $termmeta ) && is_array( $termmeta ) ) { 585 572 foreach ( $termmeta as $meta ) { 586 add_term_meta( $id[ 'term_id' ], $meta[ 'key' ], $meta[ 'value'], false );573 add_term_meta( $id['term_id'], $meta['key'], $meta['value'], false ); 587 574 } 588 575 } 589 576 } 590 577 } else { 591 printf( __( 'Failed to import %s %s', 'wordpress-importer' ), esc_html( $term[ 'term_taxonomy' ] ), esc_html( $term[ 'term_name'] ) );578 printf( __( 'Failed to import %s %s', 'wordpress-importer' ), esc_html( $term['term_taxonomy'] ), esc_html( $term['term_name'] ) ); 592 579 if ( defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) 593 580 echo ': ' . $id->get_error_message(); … … 596 583 } 597 584 598 $this->process_termmeta( $term, $id[ 'term_id'] );585 $this->process_termmeta( $term, $id['term_id'] ); 599 586 } 600 587 … … 610 597 * @param int $term_id ID of the newly created term. 611 598 */ 612 protected function process_termmeta( $term, $term_id ) 613 { 614 if ( !isset( $term[ 'termmeta' ] ) ) { 615 $term[ 'termmeta' ] = array(); 599 protected function process_termmeta( $term, $term_id ) { 600 if ( !isset( $term['termmeta'] ) ) { 601 $term['termmeta'] = array(); 616 602 } 617 603 … … 625 611 * @param array $term Term data from the WXR import. 626 612 */ 627 $term[ 'termmeta' ] = apply_filters( 'wp_import_term_meta', $term[ 'termmeta'], $term_id, $term );628 629 if ( empty( $term[ 'termmeta'] ) ) {613 $term['termmeta'] = apply_filters( 'wp_import_term_meta', $term['termmeta'], $term_id, $term ); 614 615 if ( empty( $term['termmeta'] ) ) { 630 616 return; 631 617 } 632 618 633 foreach ( $term[ 'termmeta'] as $meta ) {619 foreach ( $term['termmeta'] as $meta ) { 634 620 /** 635 621 * Filters the meta key for an imported piece of term meta. … … 641 627 * @param array $term Term data from the WXR import. 642 628 */ 643 $key = apply_filters( 'import_term_meta_key', $meta[ 'key'], $term_id, $term );629 $key = apply_filters( 'import_term_meta_key', $meta['key'], $term_id, $term ); 644 630 if ( !$key ) { 645 631 continue; … … 647 633 648 634 // Export gets meta straight from the DB so could have a serialized string 649 $value = maybe_unserialize( $meta[ 'value'] );635 $value = maybe_unserialize( $meta['value'] ); 650 636 651 637 add_term_meta( $term_id, $key, $value ); … … 672 658 * Note that new/updated terms, comments and meta are imported for the last of the above. 673 659 */ 674 function process_posts() 675 { 660 function process_posts() { 676 661 $this->posts = apply_filters( 'wp_import_posts', $this->posts ); 677 662 … … 680 665 681 666 // Break if filter hook 'wp_import_post_data_raw' return null. 682 if (empty($post)){667 if ( empty( $post ) ) { 683 668 continue; 684 }685 686 if ( !post_type_exists( $post[ 'post_type'] ) ) {687 printf( __( 'Failed to import “%s”: Invalid post type %s', 'wordpress-importer' ), esc_html( $post[ 'post_title' ] ), esc_html( $post[ 'post_type'] ) );669 } 670 671 if ( !post_type_exists( $post['post_type'] ) ) { 672 printf( __( 'Failed to import “%s”: Invalid post type %s', 'wordpress-importer' ), esc_html( $post['post_title'] ), esc_html( $post['post_type'] ) ); 688 673 echo '<br />'; 689 674 do_action( 'wp_import_post_exists', $post ); … … 691 676 } 692 677 693 if ( isset( $this->processed_posts[ $post[ 'post_id' ] ] ) && !empty( $post[ 'post_id'] ) )678 if ( isset( $this->processed_posts[$post['post_id']] ) && !empty( $post['post_id'] ) ) 694 679 continue; 695 680 696 if ( $post[ 'status'] == 'auto-draft' )681 if ( $post['status'] == 'auto-draft' ) 697 682 continue; 698 683 699 if ( 'nav_menu_item' == $post[ 'post_type'] ) {684 if ( 'nav_menu_item' == $post['post_type'] ) { 700 685 $this->process_menu_item( $post ); 701 686 continue; 702 687 } 703 688 704 $post_type_object = get_post_type_object( $post[ 'post_type'] );705 706 $post_exists = post_exists( $post[ 'post_title' ], '', $post[ 'post_date'] );689 $post_type_object = get_post_type_object( $post['post_type'] ); 690 691 $post_exists = post_exists( $post['post_title'], '', $post['post_date'] ); 707 692 708 693 /** … … 720 705 $post_exists = apply_filters( 'wp_import_existing_post', $post_exists, $post ); 721 706 722 if ( $post_exists && get_post_type( $post_exists ) == $post[ 'post_type'] ) {723 printf( __( '%s “%s” already exists.', 'wordpress-importer' ), $post_type_object->labels->singular_name, esc_html( $post[ 'post_title'] ) );707 if ( $post_exists && get_post_type( $post_exists ) == $post['post_type'] ) { 708 printf( __( '%s “%s” already exists.', 'wordpress-importer' ), $post_type_object->labels->singular_name, esc_html( $post['post_title'] ) ); 724 709 echo '<br />'; 725 710 $comment_post_ID = $post_id = $post_exists; 726 $this->processed_posts[ intval( $post[ 'post_id' ] )] = intval( $post_exists );711 $this->processed_posts[intval( $post['post_id'] )] = intval( $post_exists ); 727 712 } else { 728 $post_parent = (int) $post[ 'post_parent'];713 $post_parent = (int) $post['post_parent']; 729 714 if ( $post_parent ) { 730 715 // if we already know the parent, map it to the new local ID 731 if ( isset( $this->processed_posts[ $post_parent] ) ) {732 $post_parent = $this->processed_posts[ $post_parent];716 if ( isset( $this->processed_posts[$post_parent] ) ) { 717 $post_parent = $this->processed_posts[$post_parent]; 733 718 // otherwise record the parent for later 734 719 } else { 735 $this->post_orphans[ intval( $post[ 'post_id' ] )] = $post_parent;720 $this->post_orphans[intval( $post['post_id'] )] = $post_parent; 736 721 $post_parent = 0; 737 722 } … … 739 724 740 725 // map the post author 741 $author = sanitize_user( $post[ 'post_author'], true );742 if ( isset( $this->author_mapping[ $author] ) )743 $author = $this->author_mapping[ $author];726 $author = sanitize_user( $post['post_author'], true ); 727 if ( isset( $this->author_mapping[$author] ) ) 728 $author = $this->author_mapping[$author]; 744 729 else 745 $author = (int) get_current_user_id();730 $author = (int) get_current_user_id(); 746 731 747 732 $postdata = array( 748 'import_id' => $post[ 'post_id'],749 'post_author' => $author,750 'post_date' => $post[ 'post_date'],751 'post_date_gmt' => $post[ 'post_date_gmt'],752 'post_content' => $post[ 'post_content'],753 'post_excerpt' => $post[ 'post_excerpt'],754 'post_title' => $post[ 'post_title'],755 'post_status' => $post[ 'status'],756 'post_name' => $post[ 'post_name'],757 'comment_status' => $post[ 'comment_status'],758 'ping_status' => $post[ 'ping_status'],759 'guid' => $post[ 'guid'],760 'post_parent' => $post_parent, 'menu_order' => $post[ 'menu_order'],761 'post_type' => $post[ 'post_type'],762 'post_password' => $post[ 'post_password']733 'import_id' => $post['post_id'], 734 'post_author' => $author, 735 'post_date' => $post['post_date'], 736 'post_date_gmt' => $post['post_date_gmt'], 737 'post_content' => $post['post_content'], 738 'post_excerpt' => $post['post_excerpt'], 739 'post_title' => $post['post_title'], 740 'post_status' => $post['status'], 741 'post_name' => $post['post_name'], 742 'comment_status' => $post['comment_status'], 743 'ping_status' => $post['ping_status'], 744 'guid' => $post['guid'], 745 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'], 746 'post_type' => $post['post_type'], 747 'post_password' => $post['post_password'] 763 748 ); 764 749 765 $original_post_ID = $post[ 'post_id'];750 $original_post_ID = $post['post_id']; 766 751 $postdata = apply_filters( 'wp_import_post_data_processed', $postdata, $post ); 767 752 768 753 $postdata = wp_slash( $postdata ); 769 754 770 if ( 'attachment' == $postdata[ 'post_type'] ) {771 $remote_url = !empty( $post[ 'attachment_url' ] ) ? $post[ 'attachment_url' ] : $post[ 'guid'];755 if ( 'attachment' == $postdata['post_type'] ) { 756 $remote_url = !empty( $post['attachment_url'] ) ? $post['attachment_url'] : $post['guid']; 772 757 773 758 // try to use _wp_attached file for upload folder placement to ensure the same location as the export site 774 759 // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload() 775 $postdata[ 'upload_date' ] = $post[ 'post_date'];776 if ( isset( $post[ 'postmeta'] ) ) {777 foreach ( $post[ 'postmeta'] as $meta ) {778 if ( $meta[ 'key'] == '_wp_attached_file' ) {779 if ( preg_match( '%^[0-9]{4}/[0-9]{2}%', $meta[ 'value'], $matches ) )780 $postdata[ 'upload_date' ] = $matches[ 0];760 $postdata['upload_date'] = $post['post_date']; 761 if ( isset( $post['postmeta'] ) ) { 762 foreach ( $post['postmeta'] as $meta ) { 763 if ( $meta['key'] == '_wp_attached_file' ) { 764 if ( preg_match( '%^[0-9]{4}/[0-9]{2}%', $meta['value'], $matches ) ) 765 $postdata['upload_date'] = $matches[0]; 781 766 break; 782 767 } … … 791 776 792 777 if ( is_wp_error( $post_id ) ) { 793 printf( __( 'Failed to import %s “%s”', 'wordpress-importer' ), $post_type_object->labels->singular_name, esc_html( $post[ 'post_title'] ) );778 printf( __( 'Failed to import %s “%s”', 'wordpress-importer' ), $post_type_object->labels->singular_name, esc_html( $post['post_title'] ) ); 794 779 if ( defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) 795 780 echo ': ' . $post_id->get_error_message(); … … 798 783 } 799 784 800 if ( $post[ 'is_sticky'] == 1 )785 if ( $post['is_sticky'] == 1 ) 801 786 stick_post( $post_id ); 802 787 } 803 788 804 789 // map pre-import ID to local ID 805 $this->processed_posts[ intval( $post[ 'post_id' ] ) ] = (int)$post_id;806 807 if ( !isset( $post[ 'terms'] ) )808 $post[ 'terms'] = array();809 810 $post[ 'terms' ] = apply_filters( 'wp_import_post_terms', $post[ 'terms'], $post_id, $post );790 $this->processed_posts[intval( $post['post_id'] )] = (int) $post_id; 791 792 if ( !isset( $post['terms'] ) ) 793 $post['terms'] = array(); 794 795 $post['terms'] = apply_filters( 'wp_import_post_terms', $post['terms'], $post_id, $post ); 811 796 812 797 // add categories, tags and other terms 813 if ( !empty( $post[ 'terms'] ) ) {798 if ( !empty( $post['terms'] ) ) { 814 799 $terms_to_set = array(); 815 foreach ( $post[ 'terms'] as $term ) {800 foreach ( $post['terms'] as $term ) { 816 801 // back compat with WXR 1.0 map 'tag' to 'post_tag' 817 $taxonomy = ( 'tag' == $term[ 'domain' ] ) ? 'post_tag' : $term[ 'domain'];818 $term_exists = term_exists( $term[ 'slug'], $taxonomy );819 $term_id = is_array( $term_exists ) ? $term_exists[ 'term_id'] : $term_exists;802 $taxonomy = ( 'tag' == $term['domain'] ) ? 'post_tag' : $term['domain']; 803 $term_exists = term_exists( $term['slug'], $taxonomy ); 804 $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : $term_exists; 820 805 if ( !$term_id ) { 821 $t = wp_insert_term( $term[ 'name' ], $taxonomy, array( 'slug' => $term[ 'slug'] ) );806 $t = wp_insert_term( $term['name'], $taxonomy, array( 'slug' => $term['slug'] ) ); 822 807 if ( !is_wp_error( $t ) ) { 823 $term_id = $t[ 'term_id'];808 $term_id = $t['term_id']; 824 809 do_action( 'wp_import_insert_term', $t, $term, $post_id, $post ); 825 810 } else { 826 printf( __( 'Failed to import %s %s', 'wordpress-importer' ), esc_html( $taxonomy ), esc_html( $term[ 'name'] ) );811 printf( __( 'Failed to import %s %s', 'wordpress-importer' ), esc_html( $taxonomy ), esc_html( $term['name'] ) ); 827 812 if ( defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) 828 813 echo ': ' . $t->get_error_message(); … … 832 817 } 833 818 } 834 $terms_to_set[ $taxonomy][] = intval( $term_id );819 $terms_to_set[$taxonomy][] = intval( $term_id ); 835 820 } 836 821 … … 839 824 do_action( 'wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id, $post ); 840 825 } 841 unset( $post[ 'terms'], $terms_to_set );842 } 843 844 if ( !isset( $post[ 'comments'] ) )845 $post[ 'comments'] = array();846 847 $post[ 'comments' ] = apply_filters( 'wp_import_post_comments', $post[ 'comments'], $post_id, $post );826 unset( $post['terms'], $terms_to_set ); 827 } 828 829 if ( !isset( $post['comments'] ) ) 830 $post['comments'] = array(); 831 832 $post['comments'] = apply_filters( 'wp_import_post_comments', $post['comments'], $post_id, $post ); 848 833 849 834 // add/update comments 850 if ( !empty( $post[ 'comments'] ) ) {835 if ( !empty( $post['comments'] ) ) { 851 836 $num_comments = 0; 852 837 $inserted_comments = array(); 853 foreach ( $post[ 'comments'] as $comment ) {854 $comment_id = $comment[ 'comment_id'];855 $newcomments[ $comment_id ][ 'comment_post_ID'] = $comment_post_ID;856 $newcomments[ $comment_id ][ 'comment_author' ] = $comment[ 'comment_author'];857 $newcomments[ $comment_id ][ 'comment_author_email' ] = $comment[ 'comment_author_email'];858 $newcomments[ $comment_id ][ 'comment_author_IP' ] = $comment[ 'comment_author_IP'];859 $newcomments[ $comment_id ][ 'comment_author_url' ] = $comment[ 'comment_author_url'];860 $newcomments[ $comment_id ][ 'comment_date' ] = $comment[ 'comment_date'];861 $newcomments[ $comment_id ][ 'comment_date_gmt' ] = $comment[ 'comment_date_gmt'];862 $newcomments[ $comment_id ][ 'comment_content' ] = $comment[ 'comment_content'];863 $newcomments[ $comment_id ][ 'comment_approved' ] = $comment[ 'comment_approved'];864 $newcomments[ $comment_id ][ 'comment_type' ] = $comment[ 'comment_type'];865 $newcomments[ $comment_id ][ 'comment_parent' ] = $comment[ 'comment_parent'];866 $newcomments[ $comment_id ][ 'commentmeta' ] = isset( $comment[ 'commentmeta' ] ) ? $comment[ 'commentmeta'] : array();867 if ( isset( $this->processed_authors[ $comment[ 'comment_user_id' ]] ) )868 $newcomments[ $comment_id ][ 'user_id' ] = $this->processed_authors[ $comment[ 'comment_user_id' ]];838 foreach ( $post['comments'] as $comment ) { 839 $comment_id = $comment['comment_id']; 840 $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID; 841 $newcomments[$comment_id]['comment_author'] = $comment['comment_author']; 842 $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email']; 843 $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP']; 844 $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url']; 845 $newcomments[$comment_id]['comment_date'] = $comment['comment_date']; 846 $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt']; 847 $newcomments[$comment_id]['comment_content'] = $comment['comment_content']; 848 $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved']; 849 $newcomments[$comment_id]['comment_type'] = $comment['comment_type']; 850 $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent']; 851 $newcomments[$comment_id]['commentmeta'] = isset( $comment['commentmeta'] ) ? $comment['commentmeta'] : array(); 852 if ( isset( $this->processed_authors[$comment['comment_user_id']] ) ) 853 $newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']]; 869 854 } 870 855 ksort( $newcomments ); … … 872 857 foreach ( $newcomments as $key => $comment ) { 873 858 // if this is a new post we can skip the comment_exists() check 874 if ( !$post_exists || !comment_exists( $comment[ 'comment_author' ], $comment[ 'comment_date'] ) ) {875 if ( isset( $inserted_comments[ $comment[ 'comment_parent' ]] ) )876 $comment[ 'comment_parent' ] = $inserted_comments[ $comment[ 'comment_parent' ]];859 if ( !$post_exists || !comment_exists( $comment['comment_author'], $comment['comment_date'] ) ) { 860 if ( isset( $inserted_comments[$comment['comment_parent']] ) ) 861 $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']]; 877 862 $comment = wp_filter_comment( $comment ); 878 $inserted_comments[ $key] = wp_insert_comment( $comment );879 do_action( 'wp_import_insert_comment', $inserted_comments[ $key], $comment, $comment_post_ID, $post );880 881 foreach ( $comment[ 'commentmeta'] as $meta ) {882 $value = maybe_unserialize( $meta[ 'value'] );883 add_comment_meta( $inserted_comments[ $key ], $meta[ 'key'], $value );863 $inserted_comments[$key] = wp_insert_comment( $comment ); 864 do_action( 'wp_import_insert_comment', $inserted_comments[$key], $comment, $comment_post_ID, $post ); 865 866 foreach ( $comment['commentmeta'] as $meta ) { 867 $value = maybe_unserialize( $meta['value'] ); 868 add_comment_meta( $inserted_comments[$key], $meta['key'], $value ); 884 869 } 885 870 … … 887 872 } 888 873 } 889 unset( $newcomments, $inserted_comments, $post[ 'comments'] );890 } 891 892 if ( !isset( $post[ 'postmeta'] ) )893 $post[ 'postmeta'] = array();894 895 $post[ 'postmeta' ] = apply_filters( 'wp_import_post_meta', $post[ 'postmeta'], $post_id, $post );874 unset( $newcomments, $inserted_comments, $post['comments'] ); 875 } 876 877 if ( !isset( $post['postmeta'] ) ) 878 $post['postmeta'] = array(); 879 880 $post['postmeta'] = apply_filters( 'wp_import_post_meta', $post['postmeta'], $post_id, $post ); 896 881 897 882 // add/update post meta 898 if ( !empty( $post[ 'postmeta'] ) ) {899 foreach ( $post[ 'postmeta'] as $meta ) {900 $key = apply_filters( 'import_post_meta_key', $meta[ 'key'], $post_id, $post );883 if ( !empty( $post['postmeta'] ) ) { 884 foreach ( $post['postmeta'] as $meta ) { 885 $key = apply_filters( 'import_post_meta_key', $meta['key'], $post_id, $post ); 901 886 $value = false; 902 887 903 888 if ( '_edit_last' == $key ) { 904 if ( isset( $this->processed_authors[ intval( $meta[ 'value' ] )] ) )905 $value = $this->processed_authors[ intval( $meta[ 'value' ] )];889 if ( isset( $this->processed_authors[intval( $meta['value'] )] ) ) 890 $value = $this->processed_authors[intval( $meta['value'] )]; 906 891 else 907 892 $key = false; … … 911 896 // export gets meta straight from the DB so could have a serialized string 912 897 if ( !$value ) 913 $value = maybe_unserialize( $meta[ 'value'] );898 $value = maybe_unserialize( $meta['value'] ); 914 899 915 900 add_post_meta( $post_id, $key, $value ); … … 918 903 // if the post has a featured image, take note of this in case of remap 919 904 if ( '_thumbnail_id' == $key ) 920 $this->featured_images[ $post_id ] = (int)$value;905 $this->featured_images[$post_id] = (int) $value; 921 906 } 922 907 } … … 937 922 * @param array $item Menu item details from WXR file 938 923 */ 939 function process_menu_item( $item ) 940 { 924 function process_menu_item( $item ) { 941 925 // skip draft, orphaned menu items 942 if ( 'draft' == $item[ 'status'] )926 if ( 'draft' == $item['status'] ) 943 927 return; 944 928 945 929 $menu_slug = false; 946 if ( isset( $item[ 'terms'] ) ) {930 if ( isset( $item['terms'] ) ) { 947 931 // loop through terms, assume first nav_menu term is correct menu 948 foreach ( $item[ 'terms'] as $term ) {949 if ( 'nav_menu' == $term[ 'domain'] ) {950 $menu_slug = $term[ 'slug'];932 foreach ( $item['terms'] as $term ) { 933 if ( 'nav_menu' == $term['domain'] ) { 934 $menu_slug = $term['slug']; 951 935 break; 952 936 } … … 967 951 return; 968 952 } else { 969 $menu_id = is_array( $menu_id ) ? $menu_id[ 'term_id' ] : $menu_id; 970 } 971 972 foreach ( $item[ 'postmeta' ] as $meta ) 973 $$meta[ 'key' ] = $meta[ 'value' ]; 974 975 if ( 'taxonomy' == $_menu_item_type && isset( $this->processed_terms[ intval( $_menu_item_object_id ) ] ) ) { 976 $_menu_item_object_id = $this->processed_terms[ intval( $_menu_item_object_id ) ]; 977 } else if ( 'post_type' == $_menu_item_type && isset( $this->processed_posts[ intval( $_menu_item_object_id ) ] ) ) { 978 $_menu_item_object_id = $this->processed_posts[ intval( $_menu_item_object_id ) ]; 953 $menu_id = is_array( $menu_id ) ? $menu_id['term_id'] : $menu_id; 954 } 955 956 $args = array(); 957 foreach ( $item['postmeta'] as $meta ) { 958 $args[$meta['key']] = $meta['value']; 959 } 960 961 extract( $args ); 962 963 if(empty($_menu_item_type)){ 964 return; 965 } 966 967 if ( 'taxonomy' == $_menu_item_type && isset( $this->processed_terms[intval( $_menu_item_object_id )] ) ) { 968 $_menu_item_object_id = $this->processed_terms[intval( $_menu_item_object_id )]; 969 } else if ( 'post_type' == $_menu_item_type && isset( $this->processed_posts[intval( $_menu_item_object_id )] ) ) { 970 $_menu_item_object_id = $this->processed_posts[intval( $_menu_item_object_id )]; 979 971 } else if ( 'custom' != $_menu_item_type ) { 980 972 // associated object is missing or not imported yet, we'll retry later … … 983 975 } 984 976 985 if ( isset( $this->processed_menu_items[ intval( $_menu_item_menu_item_parent )] ) ) {986 $_menu_item_menu_item_parent = $this->processed_menu_items[ intval( $_menu_item_menu_item_parent )];977 if ( isset( $this->processed_menu_items[intval( $_menu_item_menu_item_parent )] ) ) { 978 $_menu_item_menu_item_parent = $this->processed_menu_items[intval( $_menu_item_menu_item_parent )]; 987 979 } else if ( $_menu_item_menu_item_parent ) { 988 $this->menu_item_orphans[ intval( $item[ 'post_id' ] ) ] = (int)$_menu_item_menu_item_parent;980 $this->menu_item_orphans[intval( $item['post_id'] )] = (int) $_menu_item_menu_item_parent; 989 981 $_menu_item_menu_item_parent = 0; 990 982 } … … 996 988 997 989 $args = array( 998 'menu-item-object-id' => $_menu_item_object_id,999 'menu-item-object' => $_menu_item_object,1000 'menu-item-parent-id' => $_menu_item_menu_item_parent,1001 'menu-item-position' => intval( $item[ 'menu_order'] ),1002 'menu-item-type' => $_menu_item_type,1003 'menu-item-title' => $item[ 'post_title'],1004 'menu-item-url' => $_menu_item_url,1005 'menu-item-description' => $item[ 'post_content'],1006 'menu-item-attr-title' => $item[ 'post_excerpt'],1007 'menu-item-target' => $_menu_item_target,1008 'menu-item-classes' => $_menu_item_classes,1009 'menu-item-xfn' => $_menu_item_xfn,1010 'menu-item-status' => $item[ 'status']990 'menu-item-object-id' => $_menu_item_object_id, 991 'menu-item-object' => $_menu_item_object, 992 'menu-item-parent-id' => $_menu_item_menu_item_parent, 993 'menu-item-position' => intval( $item['menu_order'] ), 994 'menu-item-type' => $_menu_item_type, 995 'menu-item-title' => $item['post_title'], 996 'menu-item-url' => $_menu_item_url, 997 'menu-item-description' => $item['post_content'], 998 'menu-item-attr-title' => $item['post_excerpt'], 999 'menu-item-target' => $_menu_item_target, 1000 'menu-item-classes' => $_menu_item_classes, 1001 'menu-item-xfn' => $_menu_item_xfn, 1002 'menu-item-status' => $item['status'] 1011 1003 ); 1012 1004 1013 1005 $id = wp_update_nav_menu_item( $menu_id, 0, $args ); 1014 1006 if ( $id && !is_wp_error( $id ) ) 1015 $this->processed_menu_items[ intval( $item[ 'post_id' ] ) ] = (int)$id;1007 $this->processed_menu_items[intval( $item['post_id'] )] = (int) $id; 1016 1008 } 1017 1009 … … 1023 1015 * @return int|WP_Error Post ID on success, WP_Error otherwise 1024 1016 */ 1025 function process_attachment( $post, $url ) 1026 { 1017 function process_attachment( $post, $url ) { 1027 1018 if ( !$this->fetch_attachments ) 1028 1019 return new WP_Error( 'attachment_processing_error', __( 'Fetching attachments is not enabled', 'wordpress-importer' ) ); … … 1036 1027 return $upload; 1037 1028 1038 if ( $info = wp_check_filetype( $upload[ 'file'] ) )1039 $post[ 'post_mime_type' ] = $info[ 'type'];1029 if ( $info = wp_check_filetype( $upload['file'] ) ) 1030 $post['post_mime_type'] = $info['type']; 1040 1031 else 1041 1032 return new WP_Error( 'attachment_processing_error', __( 'Invalid file type', 'wordpress-importer' ) ); 1042 1033 1043 $post[ 'guid' ] = $upload[ 'url'];1034 $post['guid'] = $upload['url']; 1044 1035 1045 1036 // as per wp-admin/includes/upload.php 1046 $post_id = wp_insert_attachment( $post, $upload[ 'file'] );1047 wp_update_attachment_metadata( $post_id, wp_generate_attachment_metadata( $post_id, $upload[ 'file'] ) );1037 $post_id = wp_insert_attachment( $post, $upload['file'] ); 1038 wp_update_attachment_metadata( $post_id, wp_generate_attachment_metadata( $post_id, $upload['file'] ) ); 1048 1039 1049 1040 // remap resized image URLs, works by stripping the extension and remapping the URL stub. 1050 if ( preg_match( '!^image/!', $info[ 'type'] ) ) {1041 if ( preg_match( '!^image/!', $info['type'] ) ) { 1051 1042 $parts = pathinfo( $url ); 1052 $name = basename( $parts[ 'basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.21053 1054 $parts_new = pathinfo( $upload[ 'url'] );1055 $name_new = basename( $parts_new[ 'basename'], ".{$parts_new['extension']}" );1056 1057 $this->url_remap[ $parts[ 'dirname' ] . '/' . $name ] = $parts_new[ 'dirname'] . '/' . $name_new;1043 $name = basename( $parts['basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.2 1044 1045 $parts_new = pathinfo( $upload['url'] ); 1046 $name_new = basename( $parts_new['basename'], ".{$parts_new['extension']}" ); 1047 1048 $this->url_remap[$parts['dirname'] . '/' . $name] = $parts_new['dirname'] . '/' . $name_new; 1058 1049 } 1059 1050 … … 1068 1059 * @return array|WP_Error Local file location details on success, WP_Error otherwise 1069 1060 */ 1070 function fetch_remote_file( $url, $post ) 1071 { 1061 function fetch_remote_file( $url, $post ) { 1072 1062 // extract the file name and extension from the url 1073 1063 $file_name = basename( $url ); 1074 1064 1075 1065 // get placeholder file in the upload dir with a unique, sanitized filename 1076 $upload = wp_upload_bits( $file_name, 0, '', $post[ 'upload_date'] );1077 if ( $upload[ 'error'] )1078 return new WP_Error( 'upload_dir_error', $upload[ 'error'] );1066 $upload = wp_upload_bits( $file_name, 0, '', $post['upload_date'] ); 1067 if ( $upload['error'] ) 1068 return new WP_Error( 'upload_dir_error', $upload['error'] ); 1079 1069 1080 1070 // fetch the remote url and write it to the placeholder file 1081 $headers = tp_importer_get_http( $url, $upload[ 'file'] );1071 $headers = tp_importer_get_http( $url, $upload['file'] ); 1082 1072 1083 1073 // request failed 1084 1074 if ( !$headers ) { 1085 @unlink( $upload[ 'file'] );1075 @unlink( $upload['file'] ); 1086 1076 return new WP_Error( 'import_file_error', __( 'Remote server did not respond', 'wordpress-importer' ) ); 1087 1077 } 1088 1078 1089 1079 // make sure the fetch was successful 1090 if ( $headers[ 'response'] != '200' ) {1091 @unlink( $upload[ 'file'] );1092 return new WP_Error( 'import_file_error', sprintf( __( 'Remote server returned error response %1$d %2$s', 'wordpress-importer' ), esc_html( $headers[ 'response' ] ), get_status_header_desc( $headers[ 'response'] ) ) );1093 } 1094 1095 $filesize = filesize( $upload[ 'file'] );1096 1097 if ( isset( $headers[ 'content-length' ] ) && $filesize != $headers[ 'content-length'] ) {1098 @unlink( $upload[ 'file'] );1080 if ( $headers['response'] != '200' ) { 1081 @unlink( $upload['file'] ); 1082 return new WP_Error( 'import_file_error', sprintf( __( 'Remote server returned error response %1$d %2$s', 'wordpress-importer' ), esc_html( $headers['response'] ), get_status_header_desc( $headers['response'] ) ) ); 1083 } 1084 1085 $filesize = filesize( $upload['file'] ); 1086 1087 if ( isset( $headers['content-length'] ) && $filesize != $headers['content-length'] ) { 1088 @unlink( $upload['file'] ); 1099 1089 return new WP_Error( 'import_file_error', __( 'Remote file is incorrect size', 'wordpress-importer' ) ); 1100 1090 } 1101 1091 1102 1092 if ( 0 == $filesize ) { 1103 @unlink( $upload[ 'file'] );1093 @unlink( $upload['file'] ); 1104 1094 return new WP_Error( 'import_file_error', __( 'Zero size file downloaded', 'wordpress-importer' ) ); 1105 1095 } 1106 1096 1107 $max_size = (int) $this->max_attachment_size();1097 $max_size = (int) $this->max_attachment_size(); 1108 1098 if ( !empty( $max_size ) && $filesize > $max_size ) { 1109 @unlink( $upload[ 'file'] );1099 @unlink( $upload['file'] ); 1110 1100 return new WP_Error( 'import_file_error', sprintf( __( 'Remote file is too large, limit is %s', 'wordpress-importer' ), size_format( $max_size ) ) ); 1111 1101 } 1112 1102 1113 1103 // keep track of the old and new urls so we can substitute them later 1114 $this->url_remap[ $url ] = $upload[ 'url'];1115 $this->url_remap[ $post[ 'guid' ] ] = $upload[ 'url']; // r13735, really needed?1104 $this->url_remap[$url] = $upload['url']; 1105 $this->url_remap[$post['guid']] = $upload['url']; // r13735, really needed? 1116 1106 // keep track of the destination if the remote url is redirected somewhere else 1117 if ( isset( $headers[ 'x-final-location' ] ) && $headers[ 'x-final-location'] != $url )1118 $this->url_remap[ $headers[ 'x-final-location' ] ] = $upload[ 'url'];1107 if ( isset( $headers['x-final-location'] ) && $headers['x-final-location'] != $url ) 1108 $this->url_remap[$headers['x-final-location']] = $upload['url']; 1119 1109 1120 1110 return $upload; … … 1128 1118 * the object (e.g. post) they represent in the menu 1129 1119 */ 1130 function backfill_parents() 1131 { 1120 function backfill_parents() { 1132 1121 global $wpdb; 1133 1122 … … 1135 1124 foreach ( $this->post_orphans as $child_id => $parent_id ) { 1136 1125 $local_child_id = $local_parent_id = false; 1137 if ( isset( $this->processed_posts[ $child_id] ) )1138 $local_child_id = $this->processed_posts[ $child_id];1139 if ( isset( $this->processed_posts[ $parent_id] ) )1140 $local_parent_id = $this->processed_posts[ $parent_id];1126 if ( isset( $this->processed_posts[$child_id] ) ) 1127 $local_child_id = $this->processed_posts[$child_id]; 1128 if ( isset( $this->processed_posts[$parent_id] ) ) 1129 $local_parent_id = $this->processed_posts[$parent_id]; 1141 1130 1142 1131 if ( $local_child_id && $local_parent_id ) … … 1152 1141 foreach ( $this->menu_item_orphans as $child_id => $parent_id ) { 1153 1142 $local_child_id = $local_parent_id = 0; 1154 if ( isset( $this->processed_menu_items[ $child_id] ) )1155 $local_child_id = $this->processed_menu_items[ $child_id];1156 if ( isset( $this->processed_menu_items[ $parent_id] ) )1157 $local_parent_id = $this->processed_menu_items[ $parent_id];1143 if ( isset( $this->processed_menu_items[$child_id] ) ) 1144 $local_child_id = $this->processed_menu_items[$child_id]; 1145 if ( isset( $this->processed_menu_items[$parent_id] ) ) 1146 $local_parent_id = $this->processed_menu_items[$parent_id]; 1158 1147 1159 1148 if ( $local_child_id && $local_parent_id ) 1160 update_post_meta( $local_child_id, '_menu_item_menu_item_parent', (int) $local_parent_id );1149 update_post_meta( $local_child_id, '_menu_item_menu_item_parent', (int) $local_parent_id ); 1161 1150 } 1162 1151 } … … 1165 1154 * Use stored mapping information to update old attachment URLs 1166 1155 */ 1167 function backfill_attachment_urls() 1168 { 1156 function backfill_attachment_urls() { 1169 1157 global $wpdb; 1170 1158 // make sure we do the longest urls first, in case one is a substring of another … … 1182 1170 * Update _thumbnail_id meta to new, imported attachment IDs 1183 1171 */ 1184 function remap_featured_images() 1185 { 1172 function remap_featured_images() { 1186 1173 // cycle through posts that have a featured image 1187 1174 foreach ( $this->featured_images as $post_id => $value ) { 1188 if ( isset( $this->processed_posts[ $value] ) ) {1189 $new_id = $this->processed_posts[ $value];1175 if ( isset( $this->processed_posts[$value] ) ) { 1176 $new_id = $this->processed_posts[$value]; 1190 1177 // only update if there's a difference 1191 1178 if ( $new_id != $value ) … … 1201 1188 * @return array Information gathered from the WXR file 1202 1189 */ 1203 function parse( $file ) 1204 { 1190 function parse( $file ) { 1205 1191 $parser = new WXR_Parser(); 1206 1192 return $parser->parse( $file ); … … 1208 1194 1209 1195 // Display import page title 1210 function header() 1211 { 1196 function header() { 1212 1197 echo '<div class="wrap">'; 1213 1198 screen_icon(); … … 1216 1201 $updates = get_plugin_updates(); 1217 1202 $basename = plugin_basename( __FILE__ ); 1218 if ( isset( $updates[ $basename] ) ) {1219 $update = $updates[ $basename];1203 if ( isset( $updates[$basename] ) ) { 1204 $update = $updates[$basename]; 1220 1205 echo '<div class="error"><p><strong>'; 1221 1206 printf( __( 'A new version of this importer is available. Please update to version %s to ensure compatibility with newer export files.', 'wordpress-importer' ), $update->update->new_version ); … … 1225 1210 1226 1211 // Close div.wrap 1227 function footer() 1228 { 1212 function footer() { 1229 1213 echo '</div>'; 1230 1214 } … … 1233 1217 * Display introductory text and file upload form 1234 1218 */ 1235 function greet() 1236 { 1219 function greet() { 1237 1220 echo '<div class="narrow">'; 1238 1221 echo '<p>' . __( 'Howdy! Upload your WordPress eXtended RSS (WXR) file and we’ll import the posts, pages, comments, custom fields, categories, and tags into this site.', 'wordpress-importer' ) . '</p>'; … … 1248 1231 * @return string|bool The key if we do want to import, false if not 1249 1232 */ 1250 function is_valid_meta_key( $key ) 1251 { 1233 function is_valid_meta_key( $key ) { 1252 1234 // skip attachment metadata since we'll regenerate it from scratch 1253 1235 // skip _edit_lock as not relevant for import … … 1263 1245 * @return bool True if creating users is allowed 1264 1246 */ 1265 function allow_create_users() 1266 { 1247 function allow_create_users() { 1267 1248 return apply_filters( 'import_allow_create_users', true ); 1268 1249 } … … 1275 1256 * @return bool True if downloading attachments is allowed 1276 1257 */ 1277 function allow_fetch_attachments() 1278 { 1258 function allow_fetch_attachments() { 1279 1259 return apply_filters( 'import_allow_fetch_attachments', true ); 1280 1260 } … … 1286 1266 * @return int Maximum attachment file size to import 1287 1267 */ 1288 function max_attachment_size() 1289 { 1268 function max_attachment_size() { 1290 1269 return apply_filters( 'import_attachment_size_limit', 0 ); 1291 1270 } … … 1295 1274 * @return int 300 1296 1275 */ 1297 function bump_request_timeout( $val ) 1298 { 1276 function bump_request_timeout( $val ) { 1299 1277 return 300; 1300 1278 } 1301 1279 1302 1280 // return the difference in length between two strings 1303 function cmpr_strlen( $a, $b ) 1304 { 1281 function cmpr_strlen( $a, $b ) { 1305 1282 return strlen( $b ) - strlen( $a ); 1306 1283 } -
tp-framework/trunk/assets/js/customize-fields.js
r1703500 r1818773 141 141 wp.customize.bind('ready', function () { 142 142 143 143 144 if (typeof tpfw_customizer_dependency == 'object') { 144 145 145 $.each(tpfw_customizer_dependency, function ( master, item) {146 $.each(tpfw_customizer_dependency, function (slave, masters) { 146 147 147 wp.customize(master, function (setting) { 148 $.each(masters, function (key, value) { 149 masters['[data-customize-setting-link="' + key + '"]'] = value; 150 delete masters[key]; 151 }); 152 153 if ($('#customize-control-' + slave).length) { 154 $('#customize-control-' + slave).dependsOn(masters); 155 } 148 156 149 $.each(item.elements, function (slave, value) {150 151 wp.customize.control(slave, function (control) {152 153 var visibility = function () {154 155 var _value = setting.get();156 if (item.type == 'checkbox_multiple' && typeof _value == 'string' && _value != '') {157 _value = _value.split(',');158 }159 160 if (typeof value.values == 'object') {161 162 var flag = false;163 164 if (typeof _value != 'object') {165 if ($.inArray(_value, value.values) >= 0) {166 flag = true;167 }168 } else if (value.values.length == 1) {169 if ($.inArray(value.values[0], _value) >= 0) {170 flag = true;171 }172 } else {173 174 var arr = [];175 var arr1 = value.values;176 var arr2 = Object.values(_value);177 if (arr1.length < arr2.length) {178 arr1 = Object.values(_value);179 arr2 = value.values;180 }181 182 $.each(arr1, function (k, val) {183 184 if ($.inArray(val, arr2) == -1) {185 arr.push(val);186 }187 });188 flag = arr.length == 0 ? true : false;189 }190 191 if (flag) {192 control.container.show();193 } else {194 control.container.hide();195 }196 } else {197 if (_value == value.values) {198 control.container.show();199 } else {200 control.container.hide();201 }202 }203 204 205 };206 visibility();207 setting.bind(visibility);208 });209 });210 });211 157 }); 212 158 } -
tp-framework/trunk/assets/js/customize-fields.min.js
r1703500 r1818773 1 wp.customize.controlConstructor.tpfw_select=wp.customize.Control.extend({ready:function(){"use strict";var t,e=this,n=this.container.find("select"), i=n.data("multiple");i&&jQuery(n).selectize({plugins:["remove_button","drag_drop"]}),this.container.on("change","select",function(){t=jQuery(this).val(),i&&(t=_.extend({},jQuery(this).val())),e.setting.set(t)})}}),jQuery(function(t){"use strict";document.getElementsByClassName("tpfw-icon_picker").length&&t("#widgets-right .customize-control .tpfw-icon_picker:not(.child-field) select").fontIconPicker(),document.getElementsByClassName("tpfw-repeater").length&&t("#widgets-right .tpfw-repeater").tpfwRepeater(),document.getElementsByClassName("tpfw-map").length&&t("#widgets-right .tpfw-map").tpfwMap(),document.getElementsByClassName("tpfw-datetime").length&&t("#widgets-right .tpfw-datetime input").each(function(){var e=t(this).data();t(this).datetimepicker(e)}),document.getElementsByClassName("tpfw-link").length&&t("#widgets-right .customize-control .tpfw-link").tpfwLink(),t(".accordion-section").on("expanded",function(){t(this).find(".tpfw-map:not(.child-field)").length&&t(this).find(".tpfw-map:not(.child-field)").tpfwMap()}),document.getElementsByClassName("tpfw-typography").length&&t("#widgets-right .customize-control .tpfw-typography").tpfwTypography();var e=t("textarea.custom_code"),n=e[0];e.on("blur",function(){e.data("next-tab-blurs",!1)}),e.on("keydown",function(t){var i,o,a,s=9,c=27;return c===t.keyCode?void(e.data("next-tab-blurs")||(e.data("next-tab-blurs",!0),t.stopPropagation())):void(s!==t.keyCode||t.ctrlKey||t.altKey||t.shiftKey||e.data("next-tab-blurs")||(i=n.selectionStart,o=n.selectionEnd,a=n.value,i>=0&&(n.value=a.substring(0,i).concat(" ",a.substring(o)),e.selectionStart=n.selectionEnd=i+1),t.stopPropagation(),t.preventDefault()))}),document.getElementsByClassName("tpfw-autocomplete").length&&(t("#widgets-right .customize-control .tpfw-autocomplete:not(.child-field) select").tpfwAutocomplete(),t("#widgets-right").on("change",".customize-control .tpfw-autocomplete select",function(){t(this).closest("div").find(".tpfw_value").val(t(this).val()).trigger("change")}))}),function(t){wp.customize.bind("ready",function(){"object"==typeof tpfw_customizer_dependency&&t.each(tpfw_customizer_dependency,function(e,n){wp.customize(e,function(e){t.each(n.elements,function(i,o){wp.customize.control(i,function(i){var a=function(){var a=e.get();if("checkbox_multiple"==n.type&&"string"==typeof a&&""!=a&&(a=a.split(",")),"object"==typeof o.values){var s=!1;if("object"!=typeof a)t.inArray(a,o.values)>=0&&(s=!0);else if(1==o.values.length)t.inArray(o.values[0],a)>=0&&(s=!0);else{var c=[],l=o.values,r=Object.values(a);l.length<r.length&&(l=Object.values(a),r=o.values),t.each(l,function(e,n){-1==t.inArray(n,r)&&c.push(n)}),s=0==c.length?!0:!1}s?i.container.show():i.container.hide()}else a==o.values?i.container.show():i.container.hide()};a(),e.bind(a)})})})})})}(jQuery);1 wp.customize.controlConstructor.tpfw_select=wp.customize.Control.extend({ready:function(){"use strict";var t,e=this,n=this.container.find("select"),o=n.data("multiple");o&&jQuery(n).selectize({plugins:["remove_button","drag_drop"]}),this.container.on("change","select",function(){t=jQuery(this).val(),o&&(t=_.extend({},jQuery(this).val())),e.setting.set(t)})}}),jQuery(function(t){"use strict";document.getElementsByClassName("tpfw-icon_picker").length&&t("#widgets-right .customize-control .tpfw-icon_picker:not(.child-field) select").fontIconPicker(),document.getElementsByClassName("tpfw-repeater").length&&t("#widgets-right .tpfw-repeater").tpfwRepeater(),document.getElementsByClassName("tpfw-map").length&&t("#widgets-right .tpfw-map").tpfwMap(),document.getElementsByClassName("tpfw-datetime").length&&t("#widgets-right .tpfw-datetime input").each(function(){var e=t(this).data();t(this).datetimepicker(e)}),document.getElementsByClassName("tpfw-link").length&&t("#widgets-right .customize-control .tpfw-link").tpfwLink(),t(".accordion-section").on("expanded",function(){t(this).find(".tpfw-map:not(.child-field)").length&&t(this).find(".tpfw-map:not(.child-field)").tpfwMap()}),document.getElementsByClassName("tpfw-typography").length&&t("#widgets-right .customize-control .tpfw-typography").tpfwTypography();var e=t("textarea.custom_code"),n=e[0];e.on("blur",function(){e.data("next-tab-blurs",!1)}),e.on("keydown",function(t){var o,i,c;27!==t.keyCode?9!==t.keyCode||t.ctrlKey||t.altKey||t.shiftKey||e.data("next-tab-blurs")||(o=n.selectionStart,i=n.selectionEnd,c=n.value,o>=0&&(n.value=c.substring(0,o).concat("\t",c.substring(i)),e.selectionStart=n.selectionEnd=o+1),t.stopPropagation(),t.preventDefault()):e.data("next-tab-blurs")||(e.data("next-tab-blurs",!0),t.stopPropagation())}),document.getElementsByClassName("tpfw-autocomplete").length&&(t("#widgets-right .customize-control .tpfw-autocomplete:not(.child-field) select").tpfwAutocomplete(),t("#widgets-right").on("change",".customize-control .tpfw-autocomplete select",function(){t(this).closest("div").find(".tpfw_value").val(t(this).val()).trigger("change")}))}),function(t){wp.customize.bind("ready",function(){"object"==typeof tpfw_customizer_dependency&&t.each(tpfw_customizer_dependency,function(e,n){t.each(n,function(t,e){n['[data-customize-setting-link="'+t+'"]']=e,delete n[t]}),t("#customize-control-"+e).length&&t("#customize-control-"+e).dependsOn(n)})})}(jQuery); -
tp-framework/trunk/assets/vendors/dependency/dependency.js
r1778449 r1818773 15 15 this.qualifiers = f 16 16 }; 17 17 18 dependsOn.prototype.enabled = function (e) { 18 19 if (c(this.selector + "[disabled]").length > 0) { … … 27 28 return true 28 29 }; 30 29 31 dependsOn.prototype.checked = function (e) { 32 30 33 if (this.$dependencyObj.attr("type") === "checkbox") { 31 34 if ((!this.$dependencyObj.is(":checked") && e) || (this.$dependencyObj.is(":checked") && !e)) { … … 37 40 38 41 dependsOn.prototype.values = function (value) { 39 42 40 43 var master_value = this.$dependencyObj.val(), 41 44 flag = false; 42 45 43 46 if (this.$dependencyObj.attr('type') == 'checkbox') { 44 47 master_value = this.$dependencyObj.is(':checked') ? 1 : 0; 48 45 49 46 50 } else if (this.$dependencyObj.data('type') == 'checkbox' && typeof master_value == 'string') { … … 48 52 master_value = master_value.split(','); 49 53 } 50 } 51 52 53 if (this.$dependencyObj.attr("type") === "radio") { 54 } else if (this.$dependencyObj.attr("type") === "radio") { 54 55 master_value = this.$dependencyObj.filter(":checked").val(); 55 56 } … … 58 59 value = [value]; 59 60 } 60 61 61 62 for (var i = 0; i < value.length; i++) { 62 63 63 if (typeof (master_value) === "array" || typeof (master_value) === "object") {64 64 if (typeof master_value == 'object') { 65 65 66 if (master_value.indexOf(value[i]) >= 0) { 66 67 flag = true; 67 68 break 68 69 } 70 69 71 } else { 72 70 73 if (value[i] == master_value) { 71 74 flag = true; … … 74 77 } 75 78 } 79 76 80 return flag; 77 81 }; … … 113 117 return false 114 118 }; 119 115 120 dependsOn.prototype.email = function (f) { 116 121 var e = /^[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]+)*@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$/; … … 133 138 } else { 134 139 if (typeof (this.qualifiers[e] === "function")) { 140 135 141 return this.qualifiers[e](this.$dependencyObj.val()) 136 142 } … … 149 155 150 156 a.prototype.doesQualify = function () { 157 151 158 var f = this.dependencies.length, 152 159 g = 0, … … 175 182 this.init(g) 176 183 }; 184 177 185 b.prototype.init = function (e) { 178 186 this.addSet(e); 179 187 this.check(true) 180 188 }; 189 181 190 b.prototype.addSet = function (j) { 191 182 192 var f = this, 183 193 e = 0, … … 185 195 i = 0, 186 196 g; 197 187 198 this.dependencySets.push(new a(j)); 188 199 e = this.dependencySets.length - 1; 189 200 h = this.dependencySets[e].dependencies.length; 190 201 for (i; i < h; i += 1) { 202 191 203 g = this.dependencySets[e].dependencies[i]; 192 g.$dependencyObj.on("change", function ( ) {204 g.$dependencyObj.on("change", function (e) { 193 205 f.check() 194 206 }); 207 195 208 if (g.$dependencyObj.attr("type") === "text") { 196 209 g.$dependencyObj.on("keypress", function (k) { … … 200 213 }) 201 214 } 202 } 203 }; 215 216 } 217 }; 218 204 219 b.prototype.or = function (e) { 205 220 this.addSet(e); … … 207 222 return this 208 223 }; 224 209 225 b.prototype.enable = function (e) { 210 226 var h = this.$subject, … … 222 238 } 223 239 if (this.settings.hide) { 224 f = this.$subject.closest('.tpfw_form_row ');240 f = this.$subject.closest('.tpfw_form_row,.customize-control'); 225 241 226 242 if (f.css("display") === "none") { … … 258 274 } 259 275 if (this.settings.hide) { 260 f = this.$subject.closest('.tpfw_form_row ');276 f = this.$subject.closest('.tpfw_form_row,.customize-control'); 261 277 f.hide(); 262 278 } … … 277 293 }; 278 294 b.prototype.check = function (h) { 295 279 296 var g = this.dependencySets.length, 280 297 f = 0, 281 298 e = false; 282 299 for (f; f < g; f += 1) { 300 283 301 if (this.dependencySets[f].doesQualify()) { 284 302 e = true; … … 286 304 } 287 305 } 306 288 307 if (e) { 289 308 this.enable(h) -
tp-framework/trunk/assets/vendors/dependency/dependency.min.js
r1778449 r1818773 1 !function(e){var t=function(t,s){this.selector=t,this.$dependencyObj=e(t),this.qualifiers=s};t.prototype.enabled=function(t){if(e(this.selector+"[disabled]").length>0){if(t)return!1}else if(!t)return!1;return!0},t.prototype.checked=function(e){return"checkbox"!==this.$dependencyObj.attr("type")||!(!this.$dependencyObj.is(":checked")&&e||this.$dependencyObj.is(":checked")&&!e)},t.prototype.values=function(e){var t=this.$dependencyObj.val(),s=!1;"checkbox"==this.$dependencyObj.attr("type")?t=this.$dependencyObj.is(":checked")?1:0:"checkbox"==this.$dependencyObj.data("type")&&"string"==typeof t &&""!=t&&(t=t.split(",")),"radio"===this.$dependencyObj.attr("type")&&(t=this.$dependencyObj.filter(":checked").val()),"string"!=typeof e&&"number"!=typeof e||(e=[e]);for(var n=0;n<e.length;n++)if("array"==typeof t||"object"==typeof t){if(t.indexOf(e[n])>=0){s=!0;break}}else if(e[n]==t){s=!0;break}return s},t.prototype.not=function(e){var t=this.$dependencyObj.val(),s=e.length,n=0;for(n;n<s;n+=1)if(e[n]===t)return!1;return!0},t.prototype.match=function(e){var t=this.$dependencyObj.val();return e.test(t)},t.prototype.contains=function(t){var s=this.$dependencyObj.val(),n=0;if("array"!=typeof s&&"object"!=typeof s)return this.values(t);for(n in t)if(-1!==e.inArray(t[n],s))return!0;return!1},t.prototype.email=function(e){var t=/^[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]+)*@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$/;return this.match(t)===e},t.prototype.url=function(e){var t=/(((http|ftp|https):\/\/)|www\.)[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?\^=%&:\/~\+#!]*[\w\-\@?\^=%&\/~\+#])?/g;return this.match(t)===e},t.prototype.doesQualify=function(){var e=0;for(e in this.qualifiers)if(t.prototype.hasOwnProperty(e)&&"function"==typeof t.prototype[e]){if(!this[e](this.qualifiers[e]))return!1}else if(this.qualifiers[e],!0)return this.qualifiers[e](this.$dependencyObj.val());return!0};var s=function(e){var s=0;this.dependencies=[];for(s in e)this.dependencies.push(new t(s,e[s]))};s.prototype.doesQualify=function(){var e=this.dependencies.length,t=0,s=!0;for(t;t<e;t+=1)if(!this.dependencies[t].doesQualify()){s=!1;break}return s};var n=function(t,s,n){this.dependencySets=[],this.$subject=t,this.settings=e.extend({dependsOnisable:!1,hide:!0,dependsOnuration:200,onEnable:function(){},onDisable:function(){}},n),this.enableCallback=function(){},this.disableCallback=function(){},this.init(s)};n.prototype.init=function(e){this.addSet(e),this.check(!0)},n.prototype.addSet=function(e){var t,n=this,i=0,a=0,r=0;for(this.dependencySets.push(new s(e)),i=this.dependencySets.length-1,a=this.dependencySets[i].dependencies.length,r;r<a;r+=1)(t=this.dependencySets[i].dependencies[r]).$dependencyObj.on("change",function(){n.check()}),"text"===t.$dependencyObj.attr("type")&&t.$dependencyObj.on("keypress",function(e){e.which&&t.$dependencyObj.is(":focus")&&n.check()})},n.prototype.or=function(e){return this.addSet(e),this.check(!1),this},n.prototype.enable=function(){var t,s=this.$subject;this.$subject.attr("id");this.settings.hasOwnProperty("valueTarget")&&void 0!==this.settings.valueTarget?s=e(this.settings.valueTarget):"input"!==this.$subject[0].nodeName.toLowerCase()&&"textarea"!==this.$subject[0].nodeName.toLowerCase()&&"select"!==this.$subject[0].nodeName.toLowerCase()&&(s=this.$subject.find("input, textarea, select")),this.settings.disable&&this.$subject.removeAttr("disabled"),this.settings.hide&&"none"===(t=this.$subject.closest(".tpfw_form_row")).css("display")&&t.show(),this.settings.hasOwnProperty("valueOnEnable")&&void 0!==this.settings.valueOnEnable&&s.val(this.settings.valueOnEnable),this.settings.hasOwnProperty("checkOnEnable")&&(this.settings.checkOnEnable?s.attr("checked","checked"):s.removeAttr("checked")),this.settings.hasOwnProperty("toggleClass")&&void 0!==this.settings.toggleClass&&this.$subject.addClass(this.settings.toggleClass),this.settings.onEnable()},n.prototype.disable=function(){var t=this.$subject;this.$subject.attr("id");this.settings.hasOwnProperty("valueTarget")&&void 0!==this.settings.valueTarget?t=e(this.settings.valueTarget):"input"!==this.$subject[0].nodeName.toLowerCase()&&"textarea"!==this.$subject[0].nodeName.toLowerCase()&&"select"!==this.$subject[0].nodeName.toLowerCase()&&(t=this.$subject.find("input, textarea, select")),this.settings.disable&&this.$subject.attr("disabled","disabled"),this.settings.hide&&this.$subject.closest(".tpfw_form_row").hide(),this.settings.hasOwnProperty("valueOnDisable")&&void 0!==this.settings.valueOnDisable&&t.val(this.settings.valueOnDisable),this.settings.hasOwnProperty("checkOnDisable")&&(this.settings.checkOnDisable?t.attr("checked","checked"):t.removeAttr("checked")),this.settings.hasOwnProperty("toggleClass")&&void 0!==this.settings.toggleClass&&this.$subject.removeClass(this.settings.toggleClass),this.settings.onDisable()},n.prototype.check=function(e){var t=this.dependencySets.length,s=0,n=!1;for(s;s<t;s+=1)if(this.dependencySets[s].doesQualify()){n=!0;break}n?this.enable(e):this.disable(e)},e.fn.dependsOn=function(e,t){return new n(this,e,t)}}(jQuery);1 !function(e){var t=function(t,s){this.selector=t,this.$dependencyObj=e(t),this.qualifiers=s};t.prototype.enabled=function(t){if(e(this.selector+"[disabled]").length>0){if(t)return!1}else if(!t)return!1;return!0},t.prototype.checked=function(e){return"checkbox"!==this.$dependencyObj.attr("type")||!(!this.$dependencyObj.is(":checked")&&e||this.$dependencyObj.is(":checked")&&!e)},t.prototype.values=function(e){var t=this.$dependencyObj.val(),s=!1;"checkbox"==this.$dependencyObj.attr("type")?t=this.$dependencyObj.is(":checked")?1:0:"checkbox"==this.$dependencyObj.data("type")&&"string"==typeof t?""!=t&&(t=t.split(",")):"radio"===this.$dependencyObj.attr("type")&&(t=this.$dependencyObj.filter(":checked").val()),"string"!=typeof e&&"number"!=typeof e||(e=[e]);for(var n=0;n<e.length;n++)if("object"==typeof t){if(t.indexOf(e[n])>=0){s=!0;break}}else if(e[n]==t){s=!0;break}return s},t.prototype.not=function(e){for(var t=this.$dependencyObj.val(),s=e.length,n=0;n<s;n+=1)if(e[n]===t)return!1;return!0},t.prototype.match=function(e){var t=this.$dependencyObj.val();return e.test(t)},t.prototype.contains=function(t){var s=this.$dependencyObj.val(),n=0;if("array"!=typeof s&&"object"!=typeof s)return this.values(t);for(n in t)if(-1!==e.inArray(t[n],s))return!0;return!1},t.prototype.email=function(e){return this.match(/^[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]+)*@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$/)===e},t.prototype.url=function(e){return this.match(/(((http|ftp|https):\/\/)|www\.)[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?\^=%&:\/~\+#!]*[\w\-\@?\^=%&\/~\+#])?/g)===e},t.prototype.doesQualify=function(){var e=0;for(e in this.qualifiers){if(!t.prototype.hasOwnProperty(e)||"function"!=typeof t.prototype[e])return this.qualifiers[e],this.qualifiers[e](this.$dependencyObj.val());if(!this[e](this.qualifiers[e]))return!1}return!0};var s=function(e){var s=0;this.dependencies=[];for(s in e)this.dependencies.push(new t(s,e[s]))};s.prototype.doesQualify=function(){for(var e=this.dependencies.length,t=0,s=!0;t<e;t+=1)if(!this.dependencies[t].doesQualify()){s=!1;break}return s};var n=function(t,s,n){this.dependencySets=[],this.$subject=t,this.settings=e.extend({dependsOnisable:!1,hide:!0,dependsOnuration:200,onEnable:function(){},onDisable:function(){}},n),this.enableCallback=function(){},this.disableCallback=function(){},this.init(s)};n.prototype.init=function(e){this.addSet(e),this.check(!0)},n.prototype.addSet=function(e){var t,n,i,o=this,r=0;for(this.dependencySets.push(new s(e)),t=this.dependencySets.length-1,n=this.dependencySets[t].dependencies.length;r<n;r+=1)(i=this.dependencySets[t].dependencies[r]).$dependencyObj.on("change",function(e){o.check()}),"text"===i.$dependencyObj.attr("type")&&i.$dependencyObj.on("keypress",function(e){e.which&&i.$dependencyObj.is(":focus")&&o.check()})},n.prototype.or=function(e){return this.addSet(e),this.check(!1),this},n.prototype.enable=function(t){var s,n=this.$subject;this.$subject.attr("id");this.settings.hasOwnProperty("valueTarget")&&void 0!==this.settings.valueTarget?n=e(this.settings.valueTarget):"input"!==this.$subject[0].nodeName.toLowerCase()&&"textarea"!==this.$subject[0].nodeName.toLowerCase()&&"select"!==this.$subject[0].nodeName.toLowerCase()&&(n=this.$subject.find("input, textarea, select")),this.settings.disable&&this.$subject.removeAttr("disabled"),this.settings.hide&&"none"===(s=this.$subject.closest(".tpfw_form_row,.customize-control")).css("display")&&s.show(),this.settings.hasOwnProperty("valueOnEnable")&&void 0!==this.settings.valueOnEnable&&n.val(this.settings.valueOnEnable),this.settings.hasOwnProperty("checkOnEnable")&&(this.settings.checkOnEnable?n.attr("checked","checked"):n.removeAttr("checked")),this.settings.hasOwnProperty("toggleClass")&&void 0!==this.settings.toggleClass&&this.$subject.addClass(this.settings.toggleClass),this.settings.onEnable()},n.prototype.disable=function(t){var s=this.$subject;this.$subject.attr("id");this.settings.hasOwnProperty("valueTarget")&&void 0!==this.settings.valueTarget?s=e(this.settings.valueTarget):"input"!==this.$subject[0].nodeName.toLowerCase()&&"textarea"!==this.$subject[0].nodeName.toLowerCase()&&"select"!==this.$subject[0].nodeName.toLowerCase()&&(s=this.$subject.find("input, textarea, select")),this.settings.disable&&this.$subject.attr("disabled","disabled"),this.settings.hide&&this.$subject.closest(".tpfw_form_row,.customize-control").hide(),this.settings.hasOwnProperty("valueOnDisable")&&void 0!==this.settings.valueOnDisable&&s.val(this.settings.valueOnDisable),this.settings.hasOwnProperty("checkOnDisable")&&(this.settings.checkOnDisable?s.attr("checked","checked"):s.removeAttr("checked")),this.settings.hasOwnProperty("toggleClass")&&void 0!==this.settings.toggleClass&&this.$subject.removeClass(this.settings.toggleClass),this.settings.onDisable()},n.prototype.check=function(e){for(var t=this.dependencySets.length,s=0,n=!1;s<t;s+=1)if(this.dependencySets[s].doesQualify()){n=!0;break}n?this.enable(e):this.disable(e)},e.fn.dependsOn=function(e,t){return new n(this,e,t)}}(jQuery); -
tp-framework/trunk/includes/class-tpfw-customizer.php
r1675334 r1818773 44 44 global $tpfw_customizer_dependency; 45 45 46 $key = key( $args['dependency'] ); 47 48 if ( !isset( $tpfw_customizer_dependency[$key] ) ) { 49 $tpfw_customizer_dependency[$key] = array(); 50 51 $master = $wp_customize->get_control($key); 52 $multiple = !empty( $master->multiple) ? '_multiple' : ''; 53 $tpfw_customizer_dependency[$key]['type'] = $master->type . $multiple; 46 if ( !isset( $tpfw_customizer_dependency[$args['name']] ) ) { 47 $tpfw_customizer_dependency[$args['name']] = array(); 54 48 } 55 49 56 $tpfw_customizer_dependency[$ key]['elements'][$args['name']] = $args['dependency'][$key];50 $tpfw_customizer_dependency[$args['name']] = $args['dependency']; 57 51 } 58 52 } … … 289 283 290 284 if ( !class_exists( 'Tpfw_Customize_Panel' ) ) { 291 285 292 286 /** 293 287 * Tpfw_Customize_Panel Class … … 347 341 * Add section 348 342 * 349 * @param Tpfw_Customize_Section|array $ sectionSection Class or array settings343 * @param Tpfw_Customize_Section|array $args Section Class or array settings 350 344 */ 351 345 public function add_section( $args = array() ) { -
tp-framework/trunk/readme.txt
r1809087 r1818773 5 5 Requires at least: 4.5 6 6 Tested up to: 4.9 7 Stable tag: 1.0.1 27 Stable tag: 1.0.13 8 8 License: GPLv3 9 9 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 83 83 == Changelog == 84 84 85 = 1.0.13 (February 31, 2018): = 86 * Fix metabox in front_page, posts_page cannot saved 87 * Improve dependency in customizer 88 85 89 = 1.0.12 (January 25, 2018): = 86 90 * Fix metabox in front_page, posts_page cannot saved -
tp-framework/trunk/tp-framework.php
r1809087 r1818773 6 6 Description: Create Admin fields, metabox, widget, taxonomy, menu meta, customizer fields quickly and friendly. 7 7 Author: themespond 8 Version: 1.0.1 28 Version: 1.0.13 9 9 Author URI: https://themespond.com 10 10 Text Domain: tp-framework … … 22 22 * @var string 23 23 */ 24 public $version = '1.0.1 2';24 public $version = '1.0.13'; 25 25 26 26 /** … … 68 68 69 69 add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) ); 70 71 70 add_action( 'customize_register', array( $this, 'customize_fields' ) ); 72 71 add_action( 'customize_controls_enqueue_scripts', array( $this, 'customize_scripts' ) ); … … 319 318 wp_enqueue_style( 'wp-color-picker' ); 320 319 break; 321 case 'image_picker' ;322 case 'upload' ;320 case 'image_picker': 321 case 'upload': 323 322 $localize['upload_invalid_mime'] = esc_html__( 'The selected file has an invalid mimetype in this field.', 'tp-framework' ); 324 323 wp_enqueue_media();
Note: See TracChangeset
for help on using the changeset viewer.