Adding Extra Fields to AppCamera

With these snippets, you can add custom inputs fields to your AppCamera uploads buttons and then save extra meta data on the post that the picture is being uploaded to. You can add this code to your theme's functions.php file. Hopefully you are using a child theme so you won't loose these changes when you update your theme.

Create the Field

<?php
function custom_appcamera_fields() {
    //Add as many label/input combinations you need for your fields
    //These will appear ABOVE the title/content fields if you have those set to true in your shortcode.
    echo '<label for="myfield">My Label</label>';
    echo '<input type="text" name="myfield" id="myfield" value="" />';
}
add_action( 'appp_before_camera_buttons', 'custom_appcamera_fields' );

Save the fields values as meta data

function custom_appcamera_upload_handler( $post_id ) {
    //Check if we have $_POST data
    //$post_id comes from the wp_insert_post action. It will be the ID of the newly created post.
    if ( !empty( $_POST ) ) {
       //We will need to do this for each field name attribute provided in the custom_appcamera_fields function.
       if ( isset( $_POST['myfield'] ) ) {
         //absint() just to be certain. Set meta key, as necessary, for each. Sanitize the posted value
         update_post_meta( absint( $post_id ), 'my_meta_key', sanitize_text_field( $_POST['myfield'] ) );
       }
    }
}
add_action( 'wp_insert_post', 'custom_appcamera_upload_handler' );

Display the meta field as a caption

function appcamera_upload_caption( $content ) {
  global $post;

  if( $post ) {
    $caption = get_post_meta( $post->ID, 'my_meta_key', true );
    if( $caption ) {
        $content .= "\n".'<div class="my_meta_key caption">' . $caption . '</div>';
    }
  }

  return $content;

} add_action('the_content', 'appcamera_upload_caption');

Option: Post content

Another option instead of adding it to a meta field as described above, is to add it directly to the post_content. If you prefer doing it this way you won't need to add 'the_content' filter to display it, since it will already be part of the content.

function appcamera_append_caption( $post ) {
  if ( !empty( $_POST ) ) {
     //We will need to do this for each field name attribute provided in the custom_appcamera_fields function.
     if ( isset( $_POST['myfield'] ) ) {
        $post['post_content'] .= "\n" . '<div class="caption">' . sanitize_text_field( $_POST['myfield'] ). '</div>';
     }
   }

   return $post;
}
add_filter( 'appp_insert_photo_post', 'appcamera_append_caption' );