Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an API for section groups #8

Open
mgburns opened this issue Jul 3, 2014 · 3 comments
Open

Add an API for section groups #8

mgburns opened this issue Jul 3, 2014 · 3 comments

Comments

@mgburns
Copy link
Contributor

mgburns commented Jul 3, 2014

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?
@hadamlenz
Copy link

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
Copy link

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

@inderpreet99
Copy link
Contributor

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 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants