Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Jim

Best way to add to ‘Actions’ column?

I really like your ‘Actions’ column and I’m quite interested in adding my own actions, too. I have a custom post type for a course, and I want add an button that basically opens up registration for the course via my own php code. I looked into your code and couldn’t obviously tell how I might extend it or to get the right filters. Can you please suggest how I might go about this – point me in the right direction? Or maybe you might counsel me that this approach is full of badness.
Big Screen Shot and mockup

10 years, 3 months ago
Jim

Ok – found something, the cac/column/value & cac/column/meta/value filters

see:


// =========================== Modify 'Actions' column -BEGIN- ===================================================
add_filter( 'cac/column/value', 'CustomizeCPACActionOptions', 10, 4 ); // All columns for all content types

function CustomizeCPACActionOptions( $value, $object_id, $column, $storage_type ) {
    // FYI: Our Custom Post Type has a slug of 'ascenrichpt_course'
    // This removes the 'Trash' option
    // This adds a link for adding and 'Offer' link that will, in a separate file, do something with this row
    //
    // Here are some typical values for 'get_class($column)'
    // CPAC_Column_Post_Actions
    // CPAC_Column_Post_Featured_Image
    // CPAC_Column_Post_Title_Raw
    // CPAC_ACF_Column_ACF_Field_ACF5
    // CPAC_Column_Post_Actions

    if ($storage_type == 'ascenrichpt_course') {
        if (get_class($column) == 'CPAC_Column_Post_Actions') {
            // todo: handle case when set to 'icons' vs. text
            $arrChunks = explode ('|',$value);
            // They look like this...  <a href="http://mini.local/~jjrohrer/wordpress_stuff/TmpWordpressPlayaround/wp-admin/post.php?post=319&action=edit" title="Edit this item">Edit</a>
            $asrChunks['edit'] = $arrChunks[0];
            $asrChunks['trash'] = $arrChunks[1];
            $asrChunks['view'] = $arrChunks[2];

            // ---- don't let user accidentally delete here ----
            unset($asrChunks['trash']);

            // ----- If published, then let offer as a class ----
            // Our custom URL here...
            $Url = "http://mini.local/~jjrohrer/wordpress_stuff/TmpWordpressPlayaround/wp-admin/admin.php?page=offerCourse&post={$object_id}&action=offer";
            $asrChunks['offer'] = "
            <br>
            <a
                href='$Url'
                title='Offer as class'
                >
                Offer this as an enrichment class
                </a>";

            // ---- end modding
            $value = implode('|',$asrChunks);

        }
    }
    return $value;
}
// =========================== Modify 'Actions' column -BEGIN- ===================================================
10 years, 3 months ago
Jim

As a follow-up, the previous post manipulates HTML, which is ugly, so I started looking at cac-column-meta-value, but I couldn’t get the supplied example to get called.


add_filter( 'cac/column/meta/value', 'myplugin_column_meta_value', 10, 4 ); // Meta (custom field) columns for all content types
 
function myplugin_column_meta_value( $value, $object_id, $column, $storage_type ) {
	
        print "$value"; // this isn't getting called
        exit;
	
	return $value;
}

I’m using Advanced Custom Fields Pro for my data, so maybe that is why this isn’t triggered. It would be sweet to work with pre-html data.

10 years, 3 months ago
Jesper

Heya Jim!

I’ve been searching a bit for you, and the proper way to do this would be to change the actions through the actions array. In the title column, you can do this through the post_row_actions filter. However, this isn’t supported by the actions column: we’ll be sure to add this in the next release. When we’ve done that, I’ll post an update here!

Cheers!
Jesper

10 years, 3 months ago
Jesper

Hi Jim,

We’ve added the filter cac/column/actions/action_links, which allows you to properly modify these action links. You can find the documentation for the filter here.

Cheers!
Jesper

10 years, 2 months ago
Jim

Thanks – looking forward to upgrading.

10 years, 2 months ago
Jim

Ok – I’ve gotten around to implementing your new filter – since it isn’t quite clear in the docs, the value should be html, like.
The $actions var should look like:

(
    [trash] => Trash
    [view] => View
    [goog] => "<a href='http://www.google.com'>Search</a>"

)
9 years, 12 months ago
Jim

So, I’m quite interested in doing something with the post_id of the row. Is there a smart way to get the post id from the filter call? I couldn’t tell if the id was stored somewhere in the passed column object.

As a temporary work-around, I hacked the method as seen below to also pass $post_id, but that is obviously very temporary.

public function get_raw_value( $post_id ) {

		
		return apply_filters( 'cac/column/actions/action_links', $this->get_actions( $post_id ), $this , $post_id);
	}
9 years, 12 months ago
Tobias Schutter
Developer

You’re right. The $post_id should be added to that filter. I will add this change to the next release.

9 years, 12 months ago
Jim

oh – cool.

9 years, 12 months ago

You must be logged in to reply to this topic.