WordPress: Benutzerdefinierte Benutzer werden nicht im Autorenfeld angezeigt

Lesezeit: 3 Minuten

Benutzer-Avatar
Sean

Ich habe eine hinzugefügt benutzerdefinierter Benutzertyp in WordPress, die benutzerdefinierter Beitragstyp unterstützt Autoren (siehe unten). Der benutzerdefinierte Benutzertyp hat alle Rechte eines Autors mit Ausnahme von „Posts veröffentlichen“, ist es aber nicht auf der Liste möglicher Autoren, die dem Beitrag zugeordnet werden können.

Was mache ich falsch?

Code:

if (!get_role('member')) {
        add_role('member', 'SFUK Member', array(
            'delete_posts' => true,
            'edit_posts' => true,
            'read' => true,
            'upload_files' => true,
            'edit_published_posts' => true,
            'delete_published_posts' => true
        ));
}

und hier ist der benutzerdefinierte Beitragstyp:

$args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => true,
    'capability_type' => 'post',
    'hierarchical' => true,
    'menu_position' => 0,
    'supports' => array('title', 'editor', 'thumbnail', 'page-attributes', 'author')
);

if (!post_type_exists('ent')) {
    register_post_type('ent', $args);
    remove_post_type_support('ent', 'editor');

}

Lassen Sie mich wissen, wenn weitere Informationen benötigt werden.

  • Funktionieren die Benutzerrechte in wp-admin? wie Sie es erwarten? … Verwenden Sie auch ein benutzerdefiniertes Thema / Widget, um den Namen des Autors bei der Veröffentlichung anzuzeigen? Zeigt es einen falschen Wert an? Oder ist es einfach leer. Es gibt viele Möglichkeiten, wie dies leider falsch gemacht werden könnte =[

    – PicoCreator

    Jun 17, 2011 at 1:08

  • Also which files your code snippets comes from =P

    – PicoCreator

    Jun 17, 2011 at 1:10

The authors dropdown is created the following call:

wp_dropdown_users( array(
    'who' => 'authors',
    'name' => 'post_author_override',
    'selected' => empty($post->ID) ? $user_ID : $post->post_author,
    'include_selected' => true
) );

The who argument means that only users with at least ‘author’ role will be listed, and the Codex page says that currently it’s either ‘authors’ or empty (meaning all users).
There is a filter for this function but it takes the HTML as input. You could create a new query for users and then output a new HTML dropdown. This is the first way to solve your problem.

However, this function with ‘who’ set to ‘authors’ searches for users whose level is not 0 which is quite strange since user levels have been deprecated long ago. I’ve found a related bug report on Trac recommending that you add a ‘level_1’ capability to your new role to fix this. This is not a clean solution but much easier than creating a filter and all HTML from scratch.

EDIT: A third and even more simple solution just came to my mind: I’ve created custom roles with plugins but never noticed this problem because I was always copying capabilities from existing roles and then modifying them. This way you won’t forget any capabilities and it will also fix this bug.

  • Okay, I added a level_1 capability, but it didn’t help. How might I copy capabilities from an existing roles. I can’t think of a neat way to do it.

    – Sean

    Jun 20, 2011 at 13:04

  • Make sure that you removed the previously created custom role because add_role does nothing if the role already exists (thus your ‘if’ isn’t needed). Anyway, here’s how I did it: wordpress.org/support/topic/…, and another example: wordpress.org/support/topic/…

    – molnarm

    Jun 20, 2011 at 13:14

  • Okay, sorted now. Thanks again!

    – Sean

    Jun 21, 2011 at 7:00

1382240cookie-checkWordPress: Benutzerdefinierte Benutzer werden nicht im Autorenfeld angezeigt

This website is using cookies to improve the user-friendliness. You agree by using the website further.

Privacy policy