Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //-------------------------------------------------------------------
- // posting via front-end
- //-------------------------------------------------------------------
- //-------------------------------------
- // functions.php
- //-------------------------------------
- /*-------------------------------*/
- /* Includes
- /*-------------------------------*/
- include('include/post-meta.php');
- /*-------------------------------*/
- /* WP3.0+ Menus
- /*-------------------------------*/
- function register_menu() {
- register_nav_menu('navigation', __('Primary Menu'));
- }
- //------------------------------
- add_action('init', 'register_menu');
- /*-------------------------------*/
- /* Edit Excerpt
- /*-------------------------------*/
- function vsip_excerpt_length($length) {
- return 25; }
- //------------------------------
- add_filter('excerpt_length', 'vsip_excerpt_length');
- //------------------------------
- function vsip_excerpt_more($excerpt) {
- return str_replace('[...]', '...', $excerpt); }
- //------------------------------
- add_filter('wp_trim_excerpt', 'vsip_excerpt_more');
- /*-------------------------------*/
- /* Register JS
- /*-------------------------------*/
- function vsip_enqeue_scripts()
- {
- wp_deregister_script('jquery');
- wp_register_script('jquery',
- 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js');
- wp_register_script('validation',
- 'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js',
- 'jquery');
- wp_register_script('custom_js', get_template_directory_uri() .
- '/js/jquery.custom.js', 'jquery', '1.0', TRUE);
- wp_enqueue_script('jquery');
- wp_enqueue_script('validation');
- wp_enqueue_script('custom_js');
- }
- //---------------------------------------
- add_action('wp_enqueue_scripts', 'vsip_enqeue_scripts');
- /*-------------------------------*/
- /* Browser Detection
- /*-------------------------------*/
- function browser_body_class($classes) {
- global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari,
- $is_chrome, $is_iphone;
- if($is_lynx) $classes[] = 'lynx';
- elseif($is_gecko) $classes[] = 'gecko';
- elseif($is_opera) $classes[] = 'opera';
- elseif($is_NS4) $classes[] = 'ns4';
- elseif($is_safari) $classes[] = 'safari';
- elseif($is_chrome) $classes[] = 'chrome';
- elseif($is_IE) $classes[] = 'ie';
- else $classes[] = 'unknown';
- if($is_iphone) $classes[] = 'iphone';
- return $classes;
- }
- //-------------------------------------
- add_filter('body_class','browser_body_class');
- ?>
- <?php
- //--------------------------------------------------
- // include/post-meta.php
- //--------------------------------------------------
- //-----------------------
- add_action( 'add_meta_boxes',
- 'vsip_project_add_meta');
- add_action('save_post',
- 'vsip_post_save_data');
- //-----------------------
- $prefix = 'vsip_';
- //-------------------------
- $vsip_post_meta_box = array(
- //-------------------------
- 'id' => 'vsip-post-meta-box',
- 'title' => __('Custom Meta', 'framework'),
- 'page' => 'post',
- 'context' => 'normal',
- 'priority' => 'high',
- 'fields' => array(
- array(
- 'name' => __('Custom Input One: ', 'framework'),
- 'desc' => __('Enter your custom meta 1', 'framework'),
- 'id' => $prefix.'custom_one',
- 'type' => 'text'
- ),
- array(
- 'name' => __('Custom Input Two: ', 'framework'),
- 'desc' => __('Enter your custom meta 2', 'framework'),
- 'id' => $prefix.'custom_two',
- 'type' => 'text'
- ),
- )
- );
- //------------------------------------------
- // Custom Meta Box
- //------------------------------------------
- add_action( 'add_meta_boxes',
- 'vsip_project_add_meta');
- //-----------------------------------
- function vsip_project_add_meta()
- //-----------------------------------
- {
- global $vsip_post_meta_box;
- add_meta_box( $vsip_post_meta_box['id'],
- $vsip_post_meta_box['title'],
- //---------------------------
- 'vsip_display_post_meta',
- //---------------------------
- $vsip_post_meta_box['page'],
- $vsip_post_meta_box['context'],
- $vsip_post_meta_box['priority']);
- }
- //-----------------------------------
- function vsip_display_post_meta()
- //-----------------------------------
- {
- global $vsip_post_meta_box, $post;
- echo '<input type="hidden" name="vsip_meta_box_nonce" value="',
- wp_create_nonce(basename(__FILE__)), '" />';
- echo '<table class="form-table">';
- //------------------------------------------------
- foreach ($vsip_post_meta_box['fields'] as $field)
- //------------------------------------------------
- {
- $meta = get_post_meta($post->ID, $field['id'], true);
- switch($field['type'])
- {
- case 'text':
- echo '<tr style="border-top:1px solid #eeeeee;">',
- '<th style="width:25%"><label for="', $field['id'], '"><strong>',
- $field['name'],
- '</strong>'.
- '<span style=" display:block; '.
- 'color:#999; line-height: 20px; margin:5px 0 0 0;">'.
- $field['desc'].'</span></label></th><td>';
- echo '<input type="text" name="',
- $field['id'],
- '" id="', $field['id'], '" value="',
- $meta ? $meta :
- stripslashes(htmlspecialchars(( $field['std']),ENT_QUOTES)),
- '" size="30" style="width:75%; margin-right: 20px; float:left;" />','</td>';
- break;
- }
- }
- echo '</table>';
- }
- //--------------------------------------
- function vsip_post_save_data($post_id)
- //--------------------------------------
- {
- global $vsip_post_meta_box;
- if (!isset($_POST['vsip_meta_box_nonce']) ||
- !wp_verify_nonce($_POST['vsip_meta_box_nonce'], basename(__FILE__))) {
- return $post_id;
- }
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
- return $post_id;
- }
- if ('page' == $_POST['post_type']) {
- if (!current_user_can('edit_page', $post_id)) {
- return $post_id;
- }
- } elseif (!current_user_can('edit_post', $post_id)) {
- return $post_id;
- }
- //------------------------------------------------
- foreach ($vsip_post_meta_box['fields'] as $field)
- //------------------------------------------------
- {
- $old = get_post_meta($post_id, $field['id'], true);
- $new = $_POST[$field['id']];
- if ($new && $new != $old) {
- update_post_meta($post_id, $field['id'], $new);
- } elseif ('' == $new && $old) {
- delete_post_meta($post_id, $field['id'], $old);
- }
- }
- }
- //--------------------------------------
- function vsip_project_scripts()
- //--------------------------------------
- {
- wp_enqueue_script('media-upload');
- wp_enqueue_script('thickbox');
- }
- //--------------------------------------
- function vsip_project_styles()
- //--------------------------------------
- {
- wp_enqueue_style('thickbox');
- }
- //--------------------------------------
- add_action('admin_print_scripts', 'vsip_project_scripts');
- add_action('admin_print_styles', 'vsip_project_styles');
- //--------------------------------------
- //--------------------------------------------------
- // template-view-posts.php
- //--------------------------------------------------
- ?>
- <?php /* Template Name: View Posts */ ?>
- <?php get_header(); ?>
- <div id="primary">
- <?php if(isset($_GET['result'])) : ?>
- <?php if($_GET['result'] == 'success') : ?>
- <div class="client_success">
- <span class="success">Successfully Added
- <span class="cross"><a href="#">X</a></span></span>
- </div>
- <?php endif; ?>
- <?php endif; ?>
- <table>
- <tr>
- <th>Post Title</th>
- <th>Post Excerpt</th>
- <th>Post Status</th>
- <th>Actions</th>
- </tr>
- <?php $query = new WP_Query(array('post_type' => 'post',
- 'posts_per_page' =>'-1',
- 'post_status' =>
- array(
- 'publish', 'pending', 'draft', 'private', 'trash') ) ); ?>
- <?php if ($query->have_posts()) :
- while ($query->have_posts()) : $query->the_post(); ?>
- <tr>
- <td><?php echo get_the_title(); ?></td>
- <td><?php the_excerpt(); ?></td>
- <td><?php echo get_post_status( get_the_ID() ) ?></td>
- <?php $edit_post = add_query_arg('post', get_the_ID(),
- get_permalink(61 + $_POST['_wp_http_referer'])); ?>
- <td>
- <a href="<?php echo $edit_post; ?>">Edit</a>
- <?php if( !(get_post_status() == 'trash') ) : ?>
- <a onclick="return confirm('Are you sure you wish to delete post:
- <?php echo get_the_title()
- ?>?')"href="<?php echo get_delete_post_link( get_the_ID() );
- ?>">Delete</a>
- <?php endif; ?>
- </td>
- </tr>
- <?php endwhile; endif; ?>
- </table>
- </div>
- <?php get_footer(); ?>
- <?php
- //--------------------------------------------------
- // template-insert-posts.php
- //--------------------------------------------------
- ?>
- <?php /* Template Name: Insert Posts */
- $postTitleError = '';
- if(isset($_POST['submitted']) &&
- isset($_POST['post_nonce_field']) &&
- wp_verify_nonce($_POST['post_nonce_field'], 'post_nonce')) {
- if(trim($_POST['postTitle']) === '') {
- $postTitleError = 'Please enter a title.';
- $hasError = true;
- } else {
- $postTitle = trim($_POST['postTitle']);
- }
- $post_information = array(
- 'post_title' => esc_attr(strip_tags($_POST['postTitle'])),
- 'post_content' => esc_attr(strip_tags($_POST['postContent'])),
- 'post-type' => 'post',
- 'post_status' => 'pending'
- );
- $post_id = wp_insert_post($post_information);
- if($post_id)
- {
- update_post_meta($post_id, 'vsip_custom_one',
- esc_attr(strip_tags($_POST['customMetaOne'])));
- update_post_meta($post_id, 'vsip_custom_two',
- esc_attr(strip_tags($_POST['customMetaTwo'])));
- wp_redirect( home_url() ); exit;
- }
- }
- //--------------------------------------
- ?>
- <?php get_header(); ?>
- <div id="primary">
- <form action="" id="primaryPostForm" method="POST">
- <fieldset>
- <label for="postTitle"><?php _e('Post\'s Title:', 'framework') ?>
- </label>
- <input type="text" name="postTitle" id="postTitle" value="<?php
- if(isset($_POST['postTitle'])) echo $_POST['postTitle'];
- ?>" class="required" />
- </fieldset>
- <?php if($postTitleError != '') { ?>
- <span class="error"><?php echo $postTitleError; ?></span>
- <div class="clearfix"></div>
- <?php } ?>
- <fieldset>
- <label for="postContent"><?php _e('Post\'s Content:', 'framework') ?>
- </label>
- <textarea name="postContent" id="postContent" rows="8" cols="30"><?php
- if(isset($_POST['postContent'])) {
- if(function_exists('stripslashes')) {
- echo stripslashes($_POST['postContent']); }
- else {
- echo $_POST['postContent']; } } ?>
- </textarea>
- </fieldset>
- <fieldset>
- <label for="customMetaOne"><?php _e('Custom Meta One:', 'framework') ?>
- </label>
- <input type="text" name="customMetaOne" id="customMetaOne" value="<?php
- if(isset($_POST['customMetaOne'])) echo $_POST['customMetaOne'];?>" />
- </fieldset>
- <fieldset>
- <label for="customMetaTwo"><?php _e('Custom Meta Two:', 'framework') ?>
- </label>
- <input type="text" name="customMetaTwo" id="customMetaTwo" value="<?php
- if(isset($_POST['customMetaTwo'])) echo $_POST['customMetaTwo'];?>" />
- </fieldset>
- <fieldset>
- <?php wp_nonce_field('post_nonce', 'post_nonce_field'); ?>
- <input type="hidden" name="submitted" id="submitted" value="true" />
- <button type="submit"><?php _e('Add Post', 'framework') ?></button>
- </fieldset>
- </form>
- </div>
- <?php get_footer(); ?>
- <?php
- //--------------------------------------------------
- // template-edit-posts.php
- //--------------------------------------------------
- ?>
- <?php /* Template Name: Edit Posts */
- //----------------------------------------
- $query = new WP_Query(array('post_type' => 'post',
- 'posts_per_page' =>'-1',
- 'post_status' =>
- array('publish','pending', 'draft', 'private', 'trash') ) );
- //----------------------------------------
- if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();
- if(isset($_GET['post'])) {
- if($_GET['post'] == $post->ID)
- {
- $current_post = $post->ID;
- $title = get_the_title();
- $content = get_the_content();
- $custom_one = get_post_meta($current_post, 'vsip_custom_one', true);
- $custom_two = get_post_meta($current_post, 'vsip_custom_two', true);
- }
- }
- endwhile; endif;
- //----------------------------------------
- wp_reset_query();
- //----------------------------------------
- global $current_post;
- $postTitleError = '';
- //----------------------------------------
- if (isset($_POST['submitted']) &&
- isset($_POST['post_nonce_field']) &&
- wp_verify_nonce($_POST['post_nonce_field'], 'post_nonce')) {
- //----------------------------------------
- if(trim($_POST['postTitle']) === '') {
- $postTitleError = 'Please enter a title.';
- $hasError = true;
- } else {
- $postTitle = trim($_POST['postTitle']);
- }
- //----------------------------------------
- $post_information = array(
- 'ID' => $current_post,
- 'post_title' => esc_attr(strip_tags($_POST['postTitle'])),
- 'post_content' => esc_attr(strip_tags($_POST['postContent'])),
- 'post-type' => 'post',
- 'post_status' => 'pending'
- );
- //----------------------------------------
- $post_id = wp_update_post($post_information);
- //----------------------------------------
- if($post_id)
- {
- update_post_meta($post_id, 'vsip_custom_one',
- esc_attr(strip_tags($_POST['customMetaOne'])));
- update_post_meta($post_id, 'vsip_custom_two',
- esc_attr(strip_tags($_POST['customMetaTwo'])));
- wp_redirect( home_url() ); exit;
- }
- }
- //----------------------------------------
- get_header(); ?>
- <div id="primary">
- <form action="" id="primaryPostForm" method="POST">
- <fieldset>
- <label for="postTitle"><?php _e('Post\'s Title:', 'framework') ?></label>
- <input type="text" name="postTitle" id="postTitle" value="<?php
- echo $title; ?>" class="required" />
- </fieldset>
- <?php if($postTitleError != '') { ?>
- <span class="error"><?php echo $postTitleError; ?></span>
- <div class="clearfix"></div>
- <?php } ?>
- <fieldset>
- <label for="postContent"><?php _e('Post\'s Content:', 'framework') ?>
- </label>
- <textarea name="postContent" id="postContent" rows="8" cols="30"><?php
- echo $content; ?></textarea>
- </fieldset>
- <fieldset>
- <label for="customMetaOne"><?php _e('Custom Meta One:', 'framework')
- ?></label>
- <input type="text" name="customMetaOne" id="customMetaOne" value="<?php
- echo $custom_one; ?>" />
- </fieldset>
- <fieldset>
- <label for="customMetaTwo"><?php _e('Custom Meta Two:', 'framework')
- ?></label>
- <input type="text" name="customMetaTwo" id="customMetaTwo" value="<?php
- echo $custom_two; ?>" />
- </fieldset>
- <fieldset>
- <?php wp_nonce_field('post_nonce', 'post_nonce_field'); ?>
- <input type="hidden" name="submitted" id="submitted" value="true" />
- <button type="submit"><?php _e('Update Post', 'framework') ?></button>
- </fieldset>
- </form>
- </div>
- <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement