Wordpress Prevent Users from posting full size image uploads - wordpress

Is there any way in Wordpress to prevent content editors from selecting the "Full size" option when uploading images to a post? I'd like them to just have the "thumbnail", "medium", and "large" options. I used to use the Scissors plugin to do this, but as of Wordpress 2.9 this plugin no longer works.

You could acheive this result by forcing WordPress not to display the full size option. The function that creates the size radio buttons is in wp-admin/includes/media.php and is called image_size_input_fields.
There's no filter or action hook for that function that I'm aware of, but the function that calls it (image_attachment_fields_to_edit) has a filter hook of attachment_fields_to_edit.
So basically we can use the filter hook to override those two functions with our own, which will only be very slightly modified.
This will work in the standard functions.php file, or I suppose you could incorporate it into a plugin.
First, add the new filter:
add_filter('attachment_fields_to_edit', 'MY_image_attachment_fields_to_edit', 11, 2);
Next we create our two functions. I've just prefixed the names with MY_ for this case:
function MY_image_attachment_fields_to_edit($form_fields, $post) {
if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
$alt = get_post_meta($post->ID, '_wp_attachment_image_alt', true);
if ( empty($alt) )
$alt = '';
$form_fields['post_title']['required'] = true;
$form_fields['image_alt'] = array(
'value' => $alt,
'label' => __('Alternate text'),
'helps' => __('Alt text for the image, e.g. “The Mona Lisa”')
);
$form_fields['align'] = array(
'label' => __('Alignment'),
'input' => 'html',
'html' => image_align_input_fields($post, get_option('image_default_align')),
);
$form_fields['image-size'] = MY_image_size_input_fields( $post, get_option('image_default_size', 'medium') );
} else {
unset( $form_fields['image_alt'] );
}
return $form_fields;
}
The only thing that's changed here from the normal WordPress function is that we're calling MY_image_size_input_fields instead of image_size_input_fields.
Now the function that does the actual hiding:
function MY_image_size_input_fields( $post, $check = '' ) {
// get a list of the actual pixel dimensions of each possible intermediate version of this image
/* $size_names = array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full size')); */
$size_names = array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'));
if ( empty($check) )
$check = get_user_setting('imgsize', 'medium');
echo '<pre>'; print_r($check); echo '</pre>';
foreach ( $size_names as $size => $label ) {
$downsize = image_downsize($post->ID, $size);
$checked = '';
// is this size selectable?
$enabled = ( $downsize[3] || 'large' == $size );
$css_id = "image-size-{$size}-{$post->ID}";
// if this size is the default but that's not available, don't select it
if ( $size == $check ) {
if ( $enabled )
$checked = " checked='checked'";
else
$check = '';
} elseif ( !$check && $enabled && 'thumbnail' != $size ) {
// if $check is not enabled, default to the first available size that's bigger than a thumbnail
$check = $size;
$checked = " checked='checked'";
}
$html = "<div class='image-size-item'><input type='radio' " . ( $enabled ? '' : "disabled='disabled' " ) . "name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'$checked />";
$html .= "<label for='{$css_id}'>$label</label>";
// only show the dimensions if that choice is available
if ( $enabled )
$html .= " <label for='{$css_id}' class='help'>" . sprintf( __("(%d × %d)"), $downsize[1], $downsize[2] ). "</label>";
$html .= '</div>';
$out[] = $html;
}
return array(
'label' => __('Size'),
'input' => 'html',
'html' => join("\n", $out),
);
}
In this last function only two things change. At the top we get rid of the reference to 'Full Size' in the $size_names array definition. Then the line that says $enabled = ( $downsize[3] || 'large' == $size );, we changed. We simply replaced 'full' == $size with 'large' == $size.
Here's a screenshot of the result:

I don't think you can disable the large size, but you can set it's width and height to be the same as the medium size. It's under Settings → Media

Related

Add different WordPress excerpt formats to different templates

I added the following code to my functions.php file in WordPress 6.1.1 to display excerpts.
function new_excerpt_length($length) {
return 100;
}
add_filter('excerpt_length', 'new_excerpt_length');
function new_excerpt_more($more) {
return '...';
}
add_filter('excerpt_more', 'new_excerpt_more');
...but I also have a use case to show the full excerpt without a read more link.
On page template 1 I add the below code to display the excerpt:
<?php echo the_excerpt(); ?>
...and it displays the excerpt as per the functions.php file but how do I create a 2nd excerpt without the read more link and apply it to page template 2?
Is there a parameter I can use within the_excerpt(parameter); or can I use something like wp_trim_excerpt https://developer.wordpress.org/reference/functions/wp_trim_excerpt/ maybe?
I came across the below code that is supposed to do what I want
function wpex_get_excerpt( $args = array() ) {
// Default arguments.
$defaults = array(
'post' => '',
'length' => 40,
'readmore' => false,
'readmore_text' => esc_html__( 'read more', 'text-domain' ),
'readmore_after' => '',
'custom_excerpts' => true,
'disable_more' => false,
);
// Apply filters to allow child themes mods.
$args = apply_filters( 'wpex_excerpt_defaults', $defaults );
// Parse arguments, takes the function arguments and combines them with the defaults.
$args = wp_parse_args( $args, $defaults );
// Apply filters to allow child themes mods.
$args = apply_filters( 'wpex_excerpt_args', $args );
// Extract arguments to make it easier to use below.
extract( $args );
// Get the current post.
$post = get_post( $post );
// Get the current post id.
$post_id = $post->ID;
// Check for custom excerpts.
if ( $custom_excerpts && has_excerpt( $post_id ) ) {
$output = $post->post_excerpt;
}
// No custom excerpt...so lets generate one.
else {
// Create the readmore link.
$readmore_link = '' . $readmore_text . $readmore_after . '';
// Check for more tag and return content if it exists.
if ( ! $disable_more && strpos( $post->post_content, '<!--more-->' ) ) {
$output = apply_filters( 'the_content', get_the_content( $readmore_text . $readmore_after ) );
}
// No more tag defined so generate excerpt using wp_trim_words.
else {
// Generate an excerpt from the post content.
$output = wp_trim_words( strip_shortcodes( $post->post_content ), $length );
// Add the readmore text to the excerpt if enabled.
if ( $readmore ) {
$output .= apply_filters( 'wpex_readmore_link', $readmore_link );
}
}
}
// Apply filters and return the excerpt.
return apply_filters( 'wpex_excerpt', $output );
}
Output using:
<?php echo wpex_get_excerpt ( $defaults = array(
'length' => 40,
'readmore' => true,
'readmore_text' => esc_html__( 'read more', 'wpex-boutique' ),
'custom_excerpts' => true,
) ); ?>
...but doesn't seem to workas intended. Outputs the excerpt with no link but the args don't see to work when changed. Would be perfect for my use otherwise. Maybe someone sees how to fix this code?
Thanks

Cannot get custom taxonomy filter in media list view to work

I have created a filter dropdown in Media list view to filter media files based on selected term. The dropdown rendered OK with the custom taxonomy item. But the filter is not working at all. Irrespective of the term I select from this dropdown, all media items are being listed. No filtration is happening.
Here is my code to create the filter dropdown (in functions.php):
function media_add_content_category_filter_dropdown()
{
$scr = get_current_screen();
if ( $scr->base !== 'upload' ) return;
$terms = get_terms('media_content_category', array('hide_empty' => false));
if ( $terms ) {
printf( '<select name="%s" class="postform">', esc_attr( 'mcfdd' ) );
print( '<option value="">All Categories</option>');
foreach ( $terms as $term ) {
printf( '<option value="%s">%s</option>', esc_attr( $term->term_id ), esc_html( $term->name ) );
}
print( '</select>' );
}
}
add_action('restrict_manage_posts', 'media_add_content_category_filter_dropdown');
And this is the code I am using to for filtration purpose:
function media_content_filter($query) {
if ( is_admin() && $query->is_main_query() ) {
if (isset($_GET['mcfdd']) && $_GET['mcfdd'] == -1) {
$query->set('mcfdd', '');
}
}
}
add_action('pre_get_posts','media_content_filter');
Working solution to display taxonomy filters on media library and filter:
//[[START] - Add custom taxonomy dropdown to media library
function media_add_content_category_filter_dropdown()
{
global $wp_query;
// check we're in the right place, otherwise return
if ( 'upload.php' != $pagenow )
return;
$tax_slug = 'media_content_category';
$tax_obj = get_taxonomy( $tax_slug );
// check if anything has been selected, else set selected to null
$selected = isset($wp_query->query[$tax_slug]) ? $wp_query->query[$tax_slug] : null;
wp_dropdown_categories( array(
'show_option_all' => __($tax_obj->label . ' - All'),
'taxonomy' => $tax_slug,
'name' => $tax_obj->name,
'orderby' => 'name',
'selected' => $selected,
'hierarchical' => true,
// 'show_count' => true,
'hide_empty' => false
) );
}
add_action('restrict_manage_posts', 'media_add_content_category_filter_dropdown');
To filter posts by custom taxonomy
function media_tsm_post_convert_id_to_term_in_query($query)
{
global $pagenow, $typenow;
// check we're in the right place, otherwise return
if ( 'upload.php' != $pagenow )
return;
$filters = get_object_taxonomies( $typenow );
foreach ( $filters as $tax_slug ) {
$var = &$query->query_vars[$tax_slug];
if ( $var != 0 ) {
$term = get_term_by( 'id', $var, $tax_slug );
$var = $term->slug;
}
}
}
add_filter('parse_query', 'media_tsm_post_convert_id_to_term_in_query');
//[END] - Add custom taxonomy dropdown to media library

How to nest 2 third-party Wordpress shortcodes

I'm looking to make a progress bar with shortcode that requires a percentage to determine its 'progress'. However, I'm getting my percentage from another piece of shortcode.
When I nest the two shortcodes, they fail. Can someone help me please?
Below is the two code snippets in the plugin's shortcode file, first is the progress bar...
function fruitful_pbar_shortcode ($atts, $content = null) {
$out = $type = $class = '';
extract(shortcode_atts(array(
'id' => 'ffs-pbar-' . rand( 1, 100 ),
'type' => '',
'active' => false,
'stripped' => false
), $atts));
if (!empty($id)) { $id = sanitize_html_class($id); }
if (!empty($type)) { $type = sanitize_html_class($type); }
if (!empty($active)) { $active = sanitize_html_class($active); }
if (!empty($stripped)) { $stripped = sanitize_html_class($stripped); }
$class .= $type;
if ($stripped) { $class .= ' progress-striped'; }
if ($active) { $class .= ' active'; }
$out .= '<div id="'.$id.'" class="progress '.$class.'">';
$out .= fruitful_sh_esc_content_pbr(do_shortcode($content));
$out .= '</div>';
$out .= '<div class="clearfix"></div>';
return $out;
}
add_shortcode ("fruitful_pbar", "fruitful_pbar_shortcode");
function fruitful_bar_shortcode ( $atts, $content = null ) {
$type = $width = '';
extract(shortcode_atts(array(
'type' => '',
'width' => '60%'
), $atts));
if (!empty($type)) { $type = sanitize_html_class($type); }
if (!empty($width)) { $width = esc_attr($width); }
return '<div class="bar '.$type.'" style="width: '.do_shortcode($width).';"></div>';
}
add_shortcode( 'fruitful_bar', 'fruitful_bar_shortcode', 99 );
And second (which is placed after the progress bar) is the get percentage function...
if( !function_exists('show_specific_product_quantity') ) {
function show_specific_product_quantity( $atts ) {
// Shortcode Attributes
$atts = shortcode_atts(
array(
'id' => '', // Product ID argument
),
$atts,
'product_qty'
);
if( empty($atts['id'])) return;
$stock_quantity = 0;
$product_obj = wc_get_product( intval( $atts['id'] ) );
$stock_quantity = ((12000 - $product_obj->get_stock_quantity()) / 12000) * 100;
if( $stock_quantity > 0 ) return $stock_quantity;
}
add_shortcode( 'product_qty', 'show_specific_product_quantity' );
}
And below is the shortcode I'm using...
[fruitful_pbar][fruitful_bar type="progress-bar-info" width=" [product_qty id="4278"]% " stripped="true"][/fruitful_bar][/fruitful_pbar]
As you can see - I'm using a shortcode inside a shortcode to create what I need.
Thanks in advance! :-)
Get first shortcode result in one variable and send for second shortcode as a attribute.

Wordpress custom metabox input value with AJAX

I am using Wordpress 3.5, I have a custom post (sp_product) with a metabox and some input field. One of those input (sp_title).
I want to Search by the custom post title name by typing in my input (sp_title) field and when i press add button (that also in my custom meta box), It will find that post by that Title name and bring some post meta data into this Meta box and show into other field.
Here in this picture (Example)
Search
Click Button
Get some value by AJAX from a custom post.
Please give me a example code (just simple)
I will search a simple custom post Title,
Click a button
Get the Title of that post (that i search or match) with any other post meta value, By AJAX (jQuery-AJAX).
Please Help me.
I was able to find the lead because one of my plugins uses something similar to Re-attach images.
So, the relevant Javascript function is findPosts.open('action','find_posts').
It doesn't seem well documented, and I could only found two articles about it:
Find Posts Dialog Box
Using Built-in Post Finder in Plugins
Tried to implement both code samples, the modal window opens but dumps a -1 error. And that's because the Ajax call is not passing the check_ajax_referer in the function wp_ajax_find_posts.
So, the following works and it's based on the second article. But it has a security breach that has to be tackled, which is wp_nonce_field --> check_ajax_referer. It is indicated in the code comments.
To open the Post Selector, double click the text field.
The jQuery Select needs to be worked out.
Plugin file
add_action( 'load-post.php', 'enqueue_scripts_so_14416409' );
add_action( 'add_meta_boxes', 'add_custom_box_so_14416409' );
add_action( 'wp_ajax_find_posts', 'replace_default_ajax_so_14416409', 1 );
/* Scripts */
function enqueue_scripts_so_14416409() {
# Enqueue scripts
wp_enqueue_script( 'open-posts-scripts', plugins_url('open-posts.js', __FILE__), array('media', 'wp-ajax-response'), '0.1', true );
# Add the finder dialog box
add_action( 'admin_footer', 'find_posts_div', 99 );
}
/* Meta box create */
function add_custom_box_so_14416409()
{
add_meta_box(
'sectionid_so_14416409',
__( 'Select a Post' ),
'inner_custom_box_so_14416409',
'post'
);
}
/* Meta box content */
function inner_custom_box_so_14416409( $post )
{
?>
<form id="emc2pdc_form" method="post" action="">
<?php wp_nonce_field( 'find-posts', '_ajax_nonce', false); ?>
<input type="text" name="kc-find-post" id="kc-find-post" class="kc-find-post">
</form>
<?php
}
/* Ajax replacement - Verbatim copy from wp_ajax_find_posts() */
function replace_default_ajax_so_14416409()
{
global $wpdb;
// SECURITY BREACH
// check_ajax_referer( '_ajax_nonce' );
$post_types = get_post_types( array( 'public' => true ), 'objects' );
unset( $post_types['attachment'] );
$s = stripslashes( $_POST['ps'] );
$searchand = $search = '';
$args = array(
'post_type' => array_keys( $post_types ),
'post_status' => 'any',
'posts_per_page' => 50,
);
if ( '' !== $s )
$args['s'] = $s;
$posts = get_posts( $args );
if ( ! $posts )
wp_die( __('No items found.') );
$html = '<table class="widefat" cellspacing="0"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th class="no-break">'.__('Type').'</th><th class="no-break">'.__('Date').'</th><th class="no-break">'.__('Status').'</th></tr></thead><tbody>';
foreach ( $posts as $post ) {
$title = trim( $post->post_title ) ? $post->post_title : __( '(no title)' );
switch ( $post->post_status ) {
case 'publish' :
case 'private' :
$stat = __('Published');
break;
case 'future' :
$stat = __('Scheduled');
break;
case 'pending' :
$stat = __('Pending Review');
break;
case 'draft' :
$stat = __('Draft');
break;
}
if ( '0000-00-00 00:00:00' == $post->post_date ) {
$time = '';
} else {
/* translators: date format in table columns, see http://php.net/date */
$time = mysql2date(__('Y/m/d'), $post->post_date);
}
$html .= '<tr class="found-posts"><td class="found-radio"><input type="radio" id="found-'.$post->ID.'" name="found_post_id" value="' . esc_attr($post->ID) . '"></td>';
$html .= '<td><label for="found-'.$post->ID.'">' . esc_html( $title ) . '</label></td><td class="no-break">' . esc_html( $post_types[$post->post_type]->labels->singular_name ) . '</td><td class="no-break">'.esc_html( $time ) . '</td><td class="no-break">' . esc_html( $stat ). ' </td></tr>' . "\n\n";
}
$html .= '</tbody></table>';
$x = new WP_Ajax_Response();
$x->add( array(
'data' => $html
));
$x->send();
}
Javascript file open-posts.js
jQuery(document).ready(function($) {
// Find posts
var $findBox = $('#find-posts'),
$found = $('#find-posts-response'),
$findBoxSubmit = $('#find-posts-submit');
// Open
$('input.kc-find-post').live('dblclick', function() {
$findBox.data('kcTarget', $(this));
findPosts.open();
});
// Insert
$findBoxSubmit.click(function(e) {
e.preventDefault();
// Be nice!
if ( !$findBox.data('kcTarget') )
return;
var $selected = $found.find('input:checked');
if ( !$selected.length )
return false;
var $target = $findBox.data('kcTarget'),
current = $target.val(),
current = current === '' ? [] : current.split(','),
newID = $selected.val();
if ( $.inArray(newID, current) < 0 ) {
current.push(newID);
$target.val( current.join(',') );
}
});
// Double click on the radios
$('input[name="found_post_id"]', $findBox).live('dblclick', function() {
$findBoxSubmit.trigger('click');
});
// Close
$( '#find-posts-close' ).click(function() {
$findBox.removeData('kcTarget');
});
});

Move custom column admin links from below "post title"

It seems I can't figure out how to add the edit, remove, view, etc... to one of my custom columns in the backend of wordpress. The idea is to get the links that are attached to title when one hovers over the title, to be attached to a different column.
This is what the below code outputs.
This is what I want the link in the authors column have when mouse is hovered over the authors, just like when you hover over the title in this screenshot; all the edit links.
This is what I have so far:
add_filter( 'manage_edit-testimonial-quotes_columns', 'view_columns' ) ;
function view_columns( $columns ) {
$columns = array(
'cb' => '',
'date' => __( 'Date' ),
'tq_author' => __( 'Author' ),
'tq_quote' => __( 'Testimonial' ),
);
return $columns;
}
add_action('manage_testimonial-quotes_posts_custom_column', 'custom_view_columns', 10, 2);
function custom_view_columns($column, $post_id){
global $post;
switch ($column){
case 'tq_author':
echo '<a href="post.php?post=' . $post->ID . '&action=edit">';
$column_content = the_field('tq_author');
echo $column_content;
echo '</a>';
break;
case 'tq_quote':
$column_content = the_field('tq_quote');
echo $column_content;
break;
default:
break;
}
}
The best way of doing this since WP 4.3.0 is using
add_filter( 'list_table_primary_column', [ $this, 'list_table_primary_column' ], 10, 2 );
public function list_table_primary_column( $default, $screen ) {
if ( 'edit-yourpostype' === $screen ) {
$default = 'yourcolumn';
}
return $default;
}
I really doubt that there's a hook to deal with that. So, I'll not even check the core and go straight to the dirty solution:
add_action( 'admin_head-edit.php', 'so_13418722_move_quick_edit_links' );
function so_13418722_move_quick_edit_links()
{
global $current_screen;
if( 'post' != $current_screen->post_type )
return;
if( current_user_can( 'delete_plugins' ) )
{
?>
<script type="text/javascript">
function so_13418722_doMove()
{
jQuery('td.post-title.page-title.column-title div.row-actions').each(function() {
var $list = jQuery(this);
var $firstChecked = $list.parent().parent().find('td.author.column-author');
if ( !$firstChecked.html() )
return;
$list.appendTo($firstChecked);
});
}
jQuery(document).ready(function ($){
so_13418722_doMove();
});
</script>
<?php
}
}
Result:
Notes:
adjust your post_type: 'post' != $current_screen->post_type
adjust your column classes: find('td.author.column-author')
Bug and solution:
You'll note that, after updating, the quick-edit menu goes back to its original position. The following AJAX interception deals with it. Refer to this WordPress Developers answer for more details.
add_action( 'wp_ajax_inline-save', 'so_13418722_ajax_inline_save' , 0 );
/**
Copy of the function wp_ajax_inline_save()
http://core.trac.wordpress.org/browser/tags/3.4.2/wp-admin/includes/ajax-actions.php#L1315
Only Modification marked at the end of the function with INTERCEPT
*/
function so_13418722_ajax_inline_save()
{
global $wp_list_table;
check_ajax_referer( 'inlineeditnonce', '_inline_edit' );
if ( ! isset($_POST['post_ID']) || ! ( $post_ID = (int) $_POST['post_ID'] ) )
wp_die();
if ( 'page' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_ID ) )
wp_die( __( 'You are not allowed to edit this page.' ) );
} else {
if ( ! current_user_can( 'edit_post', $post_ID ) )
wp_die( __( 'You are not allowed to edit this post.' ) );
}
set_current_screen( $_POST['screen'] );
if ( $last = wp_check_post_lock( $post_ID ) ) {
$last_user = get_userdata( $last );
$last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );
printf( $_POST['post_type'] == 'page' ? __( 'Saving is disabled: %s is currently editing this page.' ) : __( 'Saving is disabled: %s is currently editing this post.' ), esc_html( $last_user_name ) );
wp_die();
}
$data = &$_POST;
$post = get_post( $post_ID, ARRAY_A );
$post = add_magic_quotes($post); //since it is from db
$data['content'] = $post['post_content'];
$data['excerpt'] = $post['post_excerpt'];
// rename
$data['user_ID'] = $GLOBALS['user_ID'];
if ( isset($data['post_parent']) )
$data['parent_id'] = $data['post_parent'];
// status
if ( isset($data['keep_private']) && 'private' == $data['keep_private'] )
$data['post_status'] = 'private';
else
$data['post_status'] = $data['_status'];
if ( empty($data['comment_status']) )
$data['comment_status'] = 'closed';
if ( empty($data['ping_status']) )
$data['ping_status'] = 'closed';
// update the post
edit_post();
$wp_list_table = _get_list_table('WP_Posts_List_Table');
$mode = $_POST['post_view'];
$wp_list_table->display_rows( array( get_post( $_POST['post_ID'] ) ) );
// INTERCEPT: Check if it is our post_type, if not, do nothing
if( 'post' == $_POST['post_type'] )
{
?>
<script type="text/javascript">so_13418722_doMove();</script>
<?php
}
// end INTERCEPT
wp_die();
}
I had the same need.
Nicola's solution worked for me except I was getting an "Undefined variable" notice/error. Then I realized that the parameter has to be without the "[$this ... ]" part.
I guess that was a copy/paste from the documentation.
So this worked:
add_filter( 'list_table_primary_column', 'list_table_primary_column', 10, 2 );
function list_table_primary_column( $default, $screen ) {
if ( 'edit-your_post_type' === $screen ) {
// Set default columns to Minutes Spent.
$default = 'your_column';
}
return $default;
}
If you don't know what your_column is, just inspect the title of that column and get the ID.
You can't move the actions per se without resorting to JS, as the accepted answer does. However, you can very easily build your own version of the actions popup with php and inbuilt Wordpress functions. This version will work even if the user has JS turned off.
Presuming you use a switch to populate your custom columns, do something likes this, if not adapt to your own function:
switch ( $column ) {
case 'your_column_name':
echo "Your custom content here";
my_custom_column_actions($post_id);
break;
}
Then have a separate function that recreates the actions popup.
function my_custom_column_actions($post_id) {
if($_GET['post_status']!='trash') :
$bare_url = "/wp-admin/post.php?post=$post_id&action=trash";
$nonce_url = wp_nonce_url( $bare_url, 'trash-post_'.$post_id );
echo " <div class='row-actions'>
<span class='edit'>
<a href='/wp-admin/post.php?post=$post_id&action=edit'>Edit</a> |
</span>
<span class='trash'>
<a href='$nonce_url' class='submitdelete'>Trash</a>
</span>
<span class='edit'>
<a href='".get_the_permalink($post_id)."'>View</a> |
</span>
</div>";
else:
$bare_url = "/wp-admin/post.php?post=$post_id&action=untrash";
$nonce_url = wp_nonce_url( $bare_url, 'untrash-post_'.$post_id );
$delete_url = "/wp-admin/post.php?post=$post_id&action=delete";
$nonce_delete_url = wp_nonce_url( $delete_url, 'delete-post_'.$post_id );
echo " <div class='row-actions'>
<span class='untrash'>
<a href='$nonce_url' class='untrash'>Restore</a> |
</span>
<span class='delete'>
<a href='$nonce_delete_url' class='submitdelete'>Delete Permanently</a>
</span>
</div>";
endif;
}
All the business with nonce_urls is important for trashing, restoring or deleting; these actions won't work without it.
If you want to include this on a column that would normally appear, e.g. author or date published, you'll need to not include the standard column when you're declaring your custom columns and instead include a custom column that gets the same data (plus a call to the function above).
The same goes for if you want to include the title but not have the actions appear under it - otherwise they'll appear twice. Don't include the title column and instead include your own custom column that grabs the title but not the new function.
You can also very easily add your own actions by just editing the content that the function echoes.

Resources