bu-section-editing icon indicating copy to clipboard operation
bu-section-editing copied to clipboard

Add an API for section groups

Open mgburns opened this issue 11 years ago • 3 comments

From WP.org (http://wordpress.org/support/topic/can-posts-be-added-to-sections-programmatically?replies=1):

We have a large site with multiple Custom Post Types. Since child pages are frequently different types, and can appear in multiple locations, we are using the Posts 2 Posts plugin, rather than parent-child hierarchy, to link posts.

I am trying to do things programmatically, so that section editors will be able to create their own pages without admins having to add every post to section groups.

Are there a functions to:

  1. determine which section(s) a user is a member of?
  2. determine which section(s) a post is in?
  3. add a post to a section group?

mgburns avatar Jul 03 '14 16:07 mgburns

I just found this, incase anyone is looking the posts have a post meta named _bu_section_group in the db. I am still looking for the user's section group

hadamlenz avatar Oct 20 '15 20:10 hadamlenz

also under post meta in the db is an entry for each group _bu_section_group_users with a list of all the user's ids in that group

hadamlenz avatar Oct 20 '15 20:10 hadamlenz

More information...

There are currently no explicit/public functions to do each of the tasks requested. The process could be made easier by having officially supported functions, but there are already ways to get at this information.

The following should answer questions 1 and 2. Each item in $groups will have 'users' and 'perms' arrays to list the users of the group and the posts/pages (sections) they're a part of. One can correlate the two pieces of information.

$gc = BU_Edit_Groups::get_instance();
$groups = $gc->get_groups();               // all group information
$gc->find_groups_for_user( $user_id ); // groups for a user
$gc->has_user( $groups, $user_id );     // if a user belongs to a set of groups

For question 3, one can update one the groups above:

$users = array( 1, 2 );
$posts = array( 3, 4 );
$pages = array( 5, 6 );
$allowedposts = array( 'allowed' => $posts );
$allowedpages = array( 'allowed' => $pages );

$updates = array(
    'name' => 'Test group',
    'description' => 'Test description',
    'users' => $users,
    'perms' => array(
        'post' => $allowedposts,
        'page' => $allowedpages,
        ),
    );
$gc = BU_Edit_Groups::get_instance();
$group = $gc->update_group( $group_id, $updates );

inderpreet99 avatar Aug 11 '16 14:08 inderpreet99