mfwebmaster
Forum Replies Created
-
Hi All
got it working for CPT
Page and Post not working<?php
////////////////////////////////////////////////////////////////////
// Add Hooks for Changing the Group of a page
////////////////////////////////////////////////////////////////////
add_action(‘new_to_publish’, ‘set_post_to_group’);
function set_post_to_group($post){
////////////////////////////////////////////////////////////////////
// Set Variables
////////////////////////////////////////////////////////////////////
$authorId = get_the_author_meta( ‘ID’ );
$group_id = do_shortcode( ‘[groups_user_groups user_id=”‘ . $authorId . ‘”]’ );
$group_id_strip = strip_tags($group_id);
$post_id = $post->ID;
$post_type = ‘CPT Name’; //post, page, attachment or whatever other CPT you may have
////////////////////////////////////////////////////////////////////
// Call function
////////////////////////////////////////////////////////////////////
if(get_post_type($post_id) == $post_type) {
if ( $group = Groups_Group::read_by_name( $group_id_strip ) ) {
// Add user to group $post_type
Groups_Post_Access::create(
array(
‘post_id’ => $post_id,
‘group_id’ => $group -> group_id
)
);
}
}
}
?>Hi a updated code but still not working.. Please can someone assist me.
<?php
////////////////////////////////////////////////////////////////////
// Add Hooks for Changing the Group of a page
////////////////////////////////////////////////////////////////////add_action(‘future_to_publish’, ‘set_post_to_group’);
add_action(‘new_to_publish’, ‘set_post_to_group’);
add_action(‘draft_to_publish’ ,’set_post_to_group’);
add_action(‘auto-draft_to_publish’ ,’set_post_to_group’);function set_post_to_group($post){
////////////////////////////////////////////////////////////////////
// Set Variables
////////////////////////////////////////////////////////////////////
$authorGroup = get_the_author_meta( ‘ID’ );
$group_id = do_shortcode( ‘[groups_user_groups user_id=”‘ . $authorGroup . ‘”]’ );
$storeGroup_strip = strip_tags($user_group);
$post_id = $post->ID;////////////////////////////////////////////////////////////////////
// Call function
////////////////////////////////////////////////////////////////////
if(get_post_type($post_id) === ‘page’) { //post, page, attachment or whatever other CPT you may have
Groups_Post_Access::create(
array(
‘post_id’ => $post_id,
‘group_id’ => $storeGroup_strip,
)
);
}
}?>