reseller to customer
This commit is contained in:
@@ -36,6 +36,10 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
|
||||
|
||||
add_action( 'created_' . self::TAXONOMY_NAME, array( __CLASS__, 'on_organization_added' ));
|
||||
add_action( 'pre_delete_term', array( __CLASS__, 'on_taxonomy_term_will_be_deleted' ), 10, 2);
|
||||
add_action( 'delete_' . self::TAXONOMY_NAME, array( __CLASS__, 'on_organization_deleted' ));
|
||||
|
||||
add_action('acf/save_post', array(__CLASS__, 'on_organization_roles_maybe_updated'));
|
||||
|
||||
add_action('set_object_terms', array( __CLASS__, 'on_taxonomy_term_assigned' ), 10, 4);
|
||||
add_action('deleted_term_relationships', array( __CLASS__, 'on_taxonomy_term_unassigned' ), 10, 3);
|
||||
|
||||
@@ -61,6 +65,8 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
|
||||
*/
|
||||
public static function on_organization_added($organization_id) {
|
||||
self::_create_organization_access_group($organization_id);
|
||||
|
||||
do_action('wiaas_organization_created', $organization_id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,9 +79,37 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
|
||||
if ($taxonomy === self::TAXONOMY_NAME) {
|
||||
$organization_id = $term_id;
|
||||
self::_remove_organization_access_group($organization_id);
|
||||
|
||||
do_action('wiaas_organization_will_be_deleted', $organization_id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes corresponding acces group when organization term is deleted
|
||||
*
|
||||
* @param $organization_id id of the organization term
|
||||
*/
|
||||
public static function on_organization_deleted($organization_id) {
|
||||
do_action('wiaas_organization_deleted', $organization_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id acf object id for which data has been updated,
|
||||
* for organization it will be in format `term_{$organization_id}`
|
||||
*/
|
||||
public static function on_organization_roles_maybe_updated($id) {
|
||||
if ($_POST['taxonomy'] === self::TAXONOMY_NAME) {
|
||||
$roles = get_field('_wiaas_organization_roles', $id);
|
||||
|
||||
//get organization id
|
||||
$id = absint(str_replace('term_', '', $id));
|
||||
|
||||
do_action('wiaas_organization_roles_updated', $id, $roles);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds user to corresponding access groups when he is assigned to organization.
|
||||
* User will also be added to child organizations access groups.
|
||||
@@ -132,10 +166,9 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
|
||||
* to access order.
|
||||
*
|
||||
* @param $post_id - custom post id (product, order, ...)
|
||||
* @param $user_id
|
||||
* @param $organization_id
|
||||
*/
|
||||
public static function assign_post_to_user_organization($post_id, $user_id) {
|
||||
$organization_id = self::get_user_organization_id($user_id);
|
||||
public static function assign_post_to_organization($post_id, $organization_id) {
|
||||
self::_assign_post_to_organization($post_id, $organization_id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user