Admin Pointers on a custom post type

Is it possible to leverage the Admin Pointers code (core, non published API) to create pointers on a custom post type? I was trying to use a plugin called Easy Admin Pointers, but it does not support pointers on a custom post type and I can’t find any examples on the web that will work with a custom post type. Any ideas or tips? Thanks!

Related posts

Leave a Reply

1 comment

  1. Ok, I found a solution, and part of it is thanks to user kaiser above. Using a combo of that function (to find the info on each of my pages), I was then able to use code found here:

    https://gist.github.com/brasofilo/6947539

    to pull it together and fill out the pointers appropriately.

    Here was my whole process:

    FIRST: I edited /wp-admin/post-new.php to add the following code just after the “//Show post form.” comment:

        $thisscreen = get_current_screen();
        var_dump($thisscreen);
    

    That gave me the info I needed on my post new page for each custom post type.

    SECOND: Then, using those values (namely “id” and “screen”), I plugged them into that github code and voila. Now I can get admin pointers that are restricted to my custom post pages!

    Thanks again to kaiser above, and hope this helps others that are having similar problems. Perhaps there is an easier way to get the ids and other info from the pages in question without modifying the code and doing a dump of variables, I will be looking into it.

    UPDATE: UGH, this is much simpler than I previously believed. You don’t need to add the code above to get that info (although it is interesting), you only actually need the “screen”, and that can be easily deduced by the url of the custom post type ie:

    post-new.php?post_type=dispatches
    

    where “dispatches” is your screen name. I am still trying to work out how to limit the pointers to just the edit or new screen, but I can live with this…

    2ND UPDATE: Able to limit to new screen by using target like so:

    'target'   => '.post-new-php #insert-media-button',
    

    3RD UPDATE (5/25/14): After working with this code for a while, and finally building a plugin based partially on it (https://wordpress.org/plugins/better-admin-pointers/), I realized that there was an error in the gist code that was preventing multiple pointers from being dismissed correctly. Instead of getting the correct item, the code would just dismiss the first pointer it found on the page if there was more than one. To correct this, I changed this:

    close: function() 
                {
                    $.post( ajaxurl, 
                    {
                        pointer: pointer.pointer_id,
                        action: 'dismiss-wp-pointer'
                    });
                }
    

    to this:

    close: $.proxy(function () {
    $.post(ajaxurl, this);
    }, {
    pointer: pointer.pointer_id,
    action: 'dismiss-wp-pointer'
    }),
    

    And now it works as expected when there are multiple pointers on a page.