1

I want to show some information in post edit screen. I found 2 hooks which allow to do this after title or after editor. Heres code with second one:

add_action( 'edit_form_after_editor', 'myprefix_edit_form_after_editor' );
function myprefix_edit_form_after_editor() {
    global $post;
    $author_id=$post->post_author;
    $email = get_the_author_meta( 'user_email', $author_id);
    $imie = get_the_author_meta( 'first_name', $author_id);
    $nazwisko = get_the_author_meta( 'last_name', $author_id);
    $nip = get_the_author_meta( 'nip', $author_id);
    $login = get_the_author_meta( 'user_login', $author_id);
    $firma = get_the_author_meta( 'nazwa_firmy', $author_id);
    echo '<h1>DANE FIRMY</h1>';
    echo '<strong>Nazwa firmy: </strong>', $firma;
    echo '<br><strong>Imię: </strong>', $imie;
    echo '<br><strong>Nazwisko: </strong>', $nazwisko;
    echo '<br><strong>NIP: </strong>', $nip;
    echo '<br><strong>E-mail: </strong>', $email;
    echo '<br><strong>Login: </strong>', $login,'<br><br>';
}

I want this information to show only on post edit pages - now it shows everywhere (custom post type edit pages, pages edit screens etc.).

Maybe theres hook which allows to show this info under featured image (right part of edit screen).

1 Answer 1

1

Often with WP, it really helps to actually locate where and how a hook is called before using it.

If you search the code base for edit_form_after_editor, you'll locate:

/**
 * Fires after the content editor.
 *
 * @since 3.5.0
 *
 * @param WP_Post $post Post object.
 */
do_action( 'edit_form_after_editor', $post );

As you can see, $post is actually passed as an argument here. To access and use it without any chance of error, pass it to your function:

function myprefix_edit_form_after_editor($post) {
    var_dump($post);

To weed out non-posts, just go something like:

function myprefix_edit_form_after_editor($post) {
    if ($post->post_type != 'post') return;
2
  • I searched before posting at codex.wordpress.org/Plugin_API/Action_Reference but hook description is inactive there... Thank you for your answer - it works. Im also searching Action Reference for hook which allows me to place some information on side of post edit screen (for example on bottom after featured image). Is there any?
    – th3rion
    Commented Nov 2, 2013 at 7:29
  • 1
    When it comes to WP, the rule of thumb is to assume and accept that there are no up to date docs or references. The only place you should be looking is the code base itself. In your editor, search in the wp folder to locate something you know will be in the file you're looking for (e.g. a known hook, a string, etc.). Open the file, and then scan through it or search for do_action and apply_filters. In your particular case, edit-form-advanced.php has a whole bunch of potential hooks, along with do_meta_boxes() calls (google Meta Boxes: I'm positive it'll be what you want in both cases). Commented Nov 2, 2013 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.