Publish Post Action Not Working

wp_publish_post – Publish a post by transitioning the post status.

Note: This function does not do anything except transition the post status. If you want to ensure post_name is set, use wp_update_post() instead.


publish_{$custom_post_type} – publish_post is an action triggered whenever a post is published, or if it is edited and the status is changed to publish.


After running wp_publish_post a few events are triggered:

  • do_action( ‘edit_post’, $post->ID, $post );
  • do_action( “save_post_{$post->post_type}”, $post->ID, $post, true );
  • do_action( ‘save_post’, $post->ID, $post, true );
  • do_action( ‘wp_insert_post’, $post->ID, $post, true );
  • wp_transition_post_status( ‘publish’, $old_status, $post );
    • do_action( ‘transition_post_status’, $new_status, $old_status, $post );
    • do_action( “{$old_status}to{$new_status}”, $post );
    • do_action( “{$new_status}_{$post->post_type}”, $post->ID, $post );

So in theory your 'publish_link' should work because it fits the pattern

"{$new_status}_{$post->post_type}"

References


500 Error

For the sideload issue, just create a function with some default params so you have all the args required to sideload.

function sideload_media_file($url="", $post_id = NULL, $desc = NULL, $return = 'src') {
    require_once(ABSPATH . 'wp-admin/includes/media.php');
    require_once(ABSPATH . 'wp-admin/includes/file.php');
    require_once(ABSPATH . 'wp-admin/includes/image.php');

    return media_sideload_image( $url, $post_id, $desc, $return);
}

sideload_media_file($url, NULL, NULL, 'src');