WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Limit of setting page as "child" to own pages (7 posts)

  1. kalor
    Member
    Posted 1 year ago #

    I've set roles of WP users to limit their access (adding, edition, deleting) pages made by other users. They can work only with the pages that their've created.

    But, they still can set their pages as childs of every page that is in wordpress.

    Is there any possibility to limit it only to their own pages?

  2. linux4me2
    Member
    Posted 1 year ago #

    I'm not sure that it will handle exactly what you want, but you might take a look at Role Scoper. I have heard good things about it in the past, but haven't used it myself.

  3. kalor
    Member
    Posted 1 year ago #

    Roles won't work with this thing. I've already used it to limit the user access to their pages and posts only.

    Attaching the page to another as a child isn't limited by roles and by wordpress itself. Every user that is able to add new page can mark it as a child of every page that is already in system.

    The idea is to modify or filter the page_attributes_meta_box() function in \wp-admin\includes\meta-boxes.php

    It uses wp_dropdown_pages() and accordint to codex "It is possible, but not confirmed, some of the paramters for the function get_pages could be used for wp_dropdown_pages." One of the parameter is 'authors', and it's possible to check the author role.

    So, I think it's possible but it's to hard piece of programming for me.

  4. linux4me2
    Member
    Posted 1 year ago #

    I just took a quick look, and the first thing I would try is to add a filter for the user id like this to the $dropdown_args array which appears on line 557 of the page_attributes_meta_box() function in /wp-admin/includes/meta-boxes.php:

    $dropdown_args = array(
    			'post_type'        => $post->post_type,
    			'exclude_tree'     => $post->ID,
    			'selected'         => $post->post_parent,
    			'name'             => 'parent_id',
    			'show_option_none' => __('(no parent)'),
    			'sort_column'      => 'menu_order, post_title',
    			'echo'             => 0,
    			'post_author' => get_userdata( $userid )
    		);

    If that works to limit the pages in the dropdown to only those created by the current user, then you'll need to add a conditional statement that creates a different $dropdown_args_array that shows all pages to an administrator and maybe a publisher if you like.

  5. kalor
    Member
    Posted 1 year ago #

    It solves the problem.

    It will be better idea to remake it as a plugin, not to keep changes directly in WordPress core.

    function page_attributes_meta_box($post) {
    	$post_type_object = get_post_type_object($post->post_type);
    	if ( $post_type_object->hierarchical ) {
    /* added stuff start */
    		$_checkcurrent_user_id = get_current_user_id();
    		$authors_info_check = get_userdata($_checkcurrent_user_id);
    /* added stuff end */
    		$dropdown_args = array(
    			'post_type'        => $post->post_type,
    			'exclude_tree'     => $post->ID,
    			'selected'         => $post->post_parent,
    			'name'             => 'parent_id',
    			'show_option_none' => __('(no parent)'),
    			'sort_column'      => 'menu_order, post_title',
    			'echo'             => 0,
    /* added stuff start */
    			'authors' => $authors_info_check->user_login,
    /* added stuff end */
    		);
  6. kalor
    Member
    Posted 1 year ago #

    If you want to use it with your WP, here's how to do it without changing the code of core WP, with use of function.php file form your theme:

    http://wordpress.stackexchange.com/questions/44966/how-can-i-add-extra-attribute-in-the-page-attribute-section-in-wp-admin-for-pa

  7. linux4me2
    Member
    Posted 1 year ago #

    Great. I'm glad you got it working.

Topic Closed

This topic has been closed to new replies.

About this Topic