From 02548b10aa8d446a9f7cd103bd16d114ee3edd60 Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Sun, 21 Feb 2016 01:23:03 -0600 Subject: [PATCH] Initial commit of stable, basic plugin --- contest-uploader-functions.php | 228 +++++++++++++++++++++++++++++++++ css/styles.css | 0 loader.php | 30 +++++ 3 files changed, 258 insertions(+) create mode 100644 contest-uploader-functions.php create mode 100644 css/styles.css create mode 100644 loader.php diff --git a/contest-uploader-functions.php b/contest-uploader-functions.php new file mode 100644 index 0000000..5656957 --- /dev/null +++ b/contest-uploader-functions.php @@ -0,0 +1,228 @@ +"; + echo "

My Submission

"; + // Set $args for query to grab all images by the user. + $args = array( + "post_type" => "attachment", + 'post_status' => 'inherit', + "author" => wp_get_current_user()->ID + ); + $user_images = new WP_Query($args); + if ($user_images->have_posts()): + while ($user_images->have_posts()): + $user_images->the_post(); + $approved = get_post_meta(get_the_ID(), "is_approved", true); + if ($approved === 'true') { + $status = "Approved"; + } else if ($approved === 'false') { + $status = "Denied"; + } else { + $status = "Pending"; + } + $more_info = get_post_meta(get_the_ID(), "more_info", true); +?> +
+ +
+
+

+ +

+

+ Status: +

+ +

+ Additional Information: +

+ +

+ Delete +

+
+ + + + Upload Image + + + +"; +} + +// Add a shortcode to make dropping the submissions in easily. +function display_submissions() { + $args = array( + "post_type" => "attachment", + 'post_status' => 'inherit', + 'meta_key' => 'is_approved', + 'meta_value' => 'true' + ); + $contest_entries = new WP_Query($args); + if ($contest_entries->have_posts()): + while($contest_entries->have_posts()): $contest_entries->the_post(); ?> +
+ +
+
+

+ Title: +

+

+ Author: +

+
+ +

There are no approved contest entries yet. Submit an entry

+ true, 'upload_files' => true, 'delete_posts' => true)); + +// Cool function to print out errors to the debug.log file +// located in wp-content/ +if (!function_exists('write_log')) { + function write_log($log) { + if (true === WP_DEBUG) { + if (is_array($log) || is_object($log)) { + error_log(print_r($log, true)); + } else { + error_log($log); + } + } + } +} + +//Remove Media Library Tab +function remove_medialibrary_tab($tabs) { + if ( !current_user_can( 'administrator' ) ) { + unset($tabs['library']); + return $tabs; + } else { + return $tabs; + } +} +add_filter('media_upload_tabs','remove_medialibrary_tab'); + +add_action( 'admin_menu', 'remove_menu_links' ); +function remove_menu_links() { + global $submenu; + + // Remove media menu link for non-admins + if( !current_user_can('manage_options') ) + remove_menu_page('upload.php'); + + // Still need to update cap requirements even when hidden + foreach( $submenu['upload.php'] as $position => $data ) { + $submenu['upload.php'][$position][1] = 'manage_options'; + } +} + +// Add in some more data to manage the visibility of the images on the front-end +function add_form_fields( $form_fields, $post ) { + $form_fields['is_approved'] = array( + 'label' => 'Approved?', + 'input' => 'html', + 'value' => get_post_meta( $post->ID, 'is_approved', true ), + 'helps' => 'If provided, it will determine if the image is allowed to be counted in the contest or not', + 'html' => " + " + ); + // Give admins the ability to leave some feedback for the submissions. + $form_fields['more_info'] = array( + 'label' => 'Additional Information', + 'input' => 'textarea', + 'value' => get_post_meta( $post->ID, 'more_info', true ), + 'helps' => 'If provided, this will display a message on the submissions page to the author of the submission only.', + ); + + return $form_fields; +} +add_filter( 'attachment_fields_to_edit', 'add_form_fields', 10, 2 ); + +function save_image_data( $post, $attachment ) { + if( isset( $attachment['is_approved'] ) ) + update_post_meta( $post['ID'], 'is_approved', $attachment['is_approved'] ); + + if( isset( $attachment['more_info'] ) ) + update_post_meta( $post['ID'], 'more_info', $attachment['more_info'] ); + + return $post; +} +add_filter( 'attachment_fields_to_save', 'save_image_data', 10, 2 ); \ No newline at end of file diff --git a/css/styles.css b/css/styles.css new file mode 100644 index 0000000..e69de29 diff --git a/loader.php b/loader.php new file mode 100644 index 0000000..100e18a --- /dev/null +++ b/loader.php @@ -0,0 +1,30 @@ +