[wp-trac] [WordPress Trac] #37542: Taxonomies in cron jobs cause problems

WordPress Trac noreply at wordpress.org
Tue Aug 2 05:51:07 UTC 2016


#37542: Taxonomies in cron jobs cause problems
--------------------------+-----------------------------
 Reporter:  blatan        |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Taxonomy      |    Version:  4.5.3
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 The problem is similiar to this one:
 https://core.trac.wordpress.org/ticket/19373

 I had figured out the workaround for my issue before I found the above
 ticket.

 I created an import data from an external database. It can be called by
 admin manually or in daily cron jobs.
 In the cron job I have to check if a taxonomy exists in my DB, so I get it
 with
 {{{
 get_term_by('slug', ... );
 }}}

 If user calls it everything worked fine, but in cron job didn't. I noticed
 the problem is in get_term_by -> taxonomy_exists.

 Taxonomy_exists checks if the given taxonomy is in global $wp_taxonomies
 array.

 I tried to use set_current_user in beginning of the cron job, but it does
 not work. It seems to $wp_taxonomies is set before the job.

 I searched if there a hook like 'before_cron_job', but I haven't found
 any.

 My workaround is quite silly but it works. In the beginning of my cron job
 callback I call:
 {{{
 function updateTaxonomiesForCron() {
     global $wp_taxonomies;
     if ( defined('DOING_CRON') ){
         $wp_taxonomies['region'] = [];
     }
 }
 }}}

 I can see the problem with current_user_can for taxonomies is quite old
 and probably my ticket will be set as duplicated but I just want to show
 my case of the issue.

 Best regards
 Bernard

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


More information about the wp-trac mailing list