Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Template Name: Single File Upload
- */
- function UploadFile() {
- if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
- return;
- }
- acf_form_head();
- }
- add_action( 'get_header', 'UploadFile', 1 );
- /* ----------------------------------------------------------------------- */
- /* */
- /* ----------------------------------------------------------------------- */
- function UploadFileForm() {
- if ( ! ( is_user_logged_in()|| current_user_can('publish_posts') ) ) {
- }
- $new_post = array(
- 'post_id' => 'new', // Create a new post
- 'field_groups' => array(36), // Create post field group ID(s)
- 'form' => true,
- 'return' => '%post_url%', // Redirect to new post url
- 'html_before_fields' => '',
- 'html_after_fields' => '',
- 'submit_value' => 'Upload File',
- 'updated_message' => 'Success!',
- 'uploader' => 'basic'
- );
- acf_form( $new_post );
- }
- add_action( 'entry_content', 'UploadFileForm' );
- /* ----------------------------------------------------------------------- */
- /* */
- /* ----------------------------------------------------------------------- */
- function PreSaveForm( $post_id ) {
- // check if this is to be a new post
- if( $post_id != 'new' ) {
- return $post_id;
- }
- // Create a new post
- $post = array(
- 'post_type' => 'file', // Your post type ( post, page, custom post type )
- 'post_status' => 'publish', // (publish, draft, private, etc.)
- 'post_title' => wp_strip_all_tags($_POST['acf']['field_55ba5b162db22']), // Post Title ACF field key
- );
- // insert the post
- $post_id = wp_insert_post( $post );
- // Save the fields to the post
- do_action( 'acf/save_post' , $post_id );
- return $post_id;
- }
- add_filter('acf/pre_save_post' , 'PreSaveForm' );
- /* ----------------------------------------------------------------------- */
- /* */
- /* ----------------------------------------------------------------------- */
- function PostImagePreview( $post_id ) {
- if( empty($_POST['acf']) ) {
- return;
- }
- $image = $_POST['acf']['field_55ba5c632db24'];
- if ( empty($image) ) {
- return;
- }
- add_post_meta( $post_id, 'post-thumbnails', $image );
- }
- add_action( 'acf/save_post', 'PostImagePreview');
- get_header(); ?>
- <?php get_template_part('template/header/loggedin-header'); ?>
- <main id="PKA-Content">
- <?php get_template_part('template/header/header-breadcrumbs') ?>
- <div class="Page-Upload">
- <div class="container">
- <div class="row">
- <div class="col-md-8">
- <?php if ( have_posts() ) : ?>
- <?php while ( have_posts() ) : the_post(); ?>
- <?php UploadFileForm(); ?>
- <?php endwhile; endif ?>
- </div>
- <aside class="col-md-4">
- </aside><!-- Sidebar -->
- </div>
- </div>
- </div>
- </main><!-- PKA-Content End -->
- <?php get_template_part('template/footer/loggedin-footer'); ?>
- <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement