[wp-trac] [WordPress Trac] #30859: Capability limit on custom taxonomy does not allow editors to preview

WordPress Trac noreply at wordpress.org
Mon Dec 29 22:32:41 UTC 2014


#30859: Capability limit on custom taxonomy does not allow editors to preview
----------------------------------------+-----------------------------
 Reporter:  MikeNGarrett                |      Owner:
     Type:  defect (bug)                |     Status:  new
 Priority:  normal                      |  Milestone:  Awaiting Review
Component:  Taxonomy                    |    Version:  trunk
 Severity:  normal                      |   Keywords:
  Focuses:  javascript, administration  |
----------------------------------------+-----------------------------
 This is a super-niche bug, but I believe my potential solution makes
 post.js more hardy.

 I'm registering a custom taxonomy with capabilities to limit it in the
 following way:

 {{{
         'capabilities'      => array(
                 'manage_terms'  => 'manage_options',
                 'edit_terms'    => 'manage_options',
                 'delete_terms'  => 'manage_options',
                 'assign_terms'  => 'manage_options'
         ),
 }}}
 This allows admins to manage the terms and all other users to view any
 terms that have been set.

 The full register taxonomy:
 {{{
 register_taxonomy( 'migrated_category', array( 'post' ), array(
         'hierarchical'               => false,
         'public'                     => false,
         'show_ui'                    => true,
         'show_admin_column'          => false,
         'show_in_nav_menus'          => true,
         'show_tagcloud'              => false,
         'capabilities'      => array(
                 'manage_terms'  => 'manage_options',
                 'edit_terms'    => 'manage_options',
                 'delete_terms'  => 'manage_options',
                 'assign_terms'  => 'manage_options'
         ),
         'labels'            => array(
                 'name'                       => 'Migrated Categories',
                 'singular_name'              => 'Migrated Category',
                 'menu_name'                  => 'Migrated Categories',
         ),
 ) );
 }}}

 As an editor, when you publish or save a new post, the terms for migrated
 categories are not set. This works fine except when attempting to preview
 this published or saved content. The following error is thrown in post.js
 {{{
 line 30: Uncaught TypeError: Cannot read property 'replace' of undefined
 }}}

 tagBox.flushTags() is not expecting both the existing tags and new tags to
 be undefined. There isn't a check here, so it errors out as tagBox.clean()
 gets called, expecting tags to be passed to it.

 I'm attaching a patch that checks for typeof undefined on both
 tagBox.flushTags() and tagBox.clean(). It may be redundant since it seems
 like the flush and parse are the only things that call clean, but I'd
 rather be safe.

 To note, removing capabilities from the taxonomy works as does having a
 term already set. Oddly enough, for admins in the same situation this is
 not a problem at all.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/30859>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list