I edited the plugin WP User Frontend (for editing posts from frontend) to have two different edit pages for two different post types. Here's the original function which handles the edit_link.
function wpuf_edit_post_link( $url, $post_id ) {
if ( is_admin() ) {
return $url;
}
$override = wpuf_get_option( 'override_editlink', 'yes' );
if ( $override == 'yes' ) {
$url = '';
if ( wpuf_get_option( 'enable_post_edit' ) == 'yes' ) {
$edit_page = (int) wpuf_get_option( 'edit_page_id' );
$url = get_permalink( $edit_page );
$url = wp_nonce_url( $url . '?pid=' . $post_id, 'wpuf_edit' );
}
}
return $url;
}
add_filter( 'get_edit_post_link', 'wpuf_edit_post_link', 10, 2 );
How can I call the current post parameters inside the function? I used get_post
but it doesn't work (I guess because it's not inside the loop...). Here's the piece of function I edited. 201 and 203 are correct edit pages IDs: inside the pages there is some shortcode which turns them into an edit page.
$override = wpuf_get_option( 'override_editlink', 'yes' );
if ( $override == 'yes' ) {
$url = '';
if ( wpuf_get_option( 'enable_post_edit' ) == 'yes' ) {
$post = get_post($post_id);
if ($post->post_type == 'type1') {
$url = get_permalink( 201 );
$url = wp_nonce_url( $url . '?pid=' . $post_id, 'wpuf_edit' );
}
if ($post->post_type == 'type2') {
$url = get_permalink( 203 );
$url = wp_nonce_url( $url . '?pid=' . $post_id, 'wpuf_edit' );
}
}
}
What's wrong with this code?