Making WordPress.org

Changeset 1866


Ignore:
Timestamp:
09/08/2015 09:04:07 PM (7 years ago)
Author:
ocean90
Message:

Translate: Clear cache for parent child relationships when a project is created/saved.

Fixes #1101.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/translate.wordpress.org/includes/gp-plugins/wporg-rosetta-roles/wporg-rosetta-roles.php

    r1834 r1866  
    4141        parent::__construct();
    4242        $this->add_filter( 'pre_can_user', array( 'args' => 2, 'priority' => 9 ) );
     43        $this->add_action( 'project_created' );
     44        $this->add_action( 'project_saved' );
    4345    }
    4446
     
    98100
    99101        return false;
     102    }
     103
     104    /**
     105     * Callback for when a project is created.
     106     */
     107    public function project_created() {
     108        $this->clear_project_cache();
     109    }
     110
     111    /**
     112     * Callback for when a project is saved.
     113     */
     114    public function project_saved() {
     115        $this->clear_project_cache();
    100116    }
    101117
     
    348364
    349365    /**
     366     * Removes all of the project ids from the cache.
     367     */
     368    public function clear_project_cache() {
     369        $projects = $this->get_all_projects();
     370
     371        foreach ( $projects as $project ) {
     372            $cache_key = 'project:' . $project->id . ':childs';
     373            wp_cache_delete( $cache_key, $this->cache_group );
     374        }
     375    }
     376
     377    /**
    350378     * Extracts project ID and locale slug from object type and ID.
    351379     *
Note: See TracChangeset for help on using the changeset viewer.