Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $portfoliourl_1_metabox = array(
- 'id' => 'portfoliourl',
- 'title' => 'Portfolio URL',
- 'page' => array('portfolio'),
- 'context' => 'side',
- 'priority' => 'low',
- 'fields' => array(
- array(
- 'name' => 'Portfolio Meta URL',
- 'desc' => 'Enter a URL you want to use somewhere in the portfolio for a link',
- 'id' => 'nick_portfolio_url',
- 'class' => 'nick_portfolio_url',
- 'type' => 'text',
- 'rich_editor' => 0,
- 'max' => 0 ),
- )
- );
- add_action('admin_menu', 'nick_add_portfoliourl_1_meta_box');
- function nick_add_portfoliourl_1_meta_box() {
- global $portfoliourl_1_metabox;
- foreach($portfoliourl_1_metabox['page'] as $page) {
- add_meta_box($portfoliourl_1_metabox['id'], $portfoliourl_1_metabox['title'], 'nick_show_portfoliourl_1_box', $page, 'side', 'low', $portfoliourl_1_metabox);
- }
- }
- // function to show meta boxes
- function nick_show_portfoliourl_1_box() {
- global $post;
- global $portfoliourl_1_metabox;
- global $nick_prefix;
- global $wp_version;
- // Use nonce for verification
- echo '<input type="hidden" name="nick_portfoliourl_1_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';
- echo '<table class="form-table">';
- foreach ($portfoliourl_1_metabox['fields'] as $field) {
- // get current post meta data
- $meta = get_post_meta($post->ID, $field['id'], true);
- echo '<tr>',
- '<th style="width:20%"><label for="', $field['id'], '">', stripslashes($field['name']), '</label></th>',
- '<td class="nick_field_type_' . str_replace(' ', '_', $field['type']) . '">';
- switch ($field['type']) {
- case 'text':
- echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" size="30" style="width:97%" /><br/>', '', stripslashes($field['desc']);
- break;
- }
- echo '<td>',
- '</tr>';
- }
- echo '</table>';
- }
- // Save data from meta box
- add_action('save_post', 'nick_portfoliourl_1_save');
- function nick_portfoliourl_1_save($post_id) {
- global $post;
- global $portfoliourl_1_metabox;
- // verify nonce
- if ( ! isset( $_POST['nick_portfoliourl_1_meta_box_nonce'] ) || ! wp_verify_nonce($_POST['nick_portfoliourl_1_meta_box_nonce'], basename(__FILE__))) {
- return $post_id;
- }
- // check autosave
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
- return $post_id;
- }
- // check permissions
- 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 ($portfoliourl_1_metabox['fields'] as $field) {
- $old = get_post_meta($post_id, $field['id'], true);
- $new = $_POST[$field['id']];
- if ($new && $new != $old) {
- if($field['type'] == 'date') {
- $new = nick_format_date($new);
- update_post_meta($post_id, $field['id'], $new);
- } else {
- if(is_string($new)) {
- $new = $new;
- }
- update_post_meta($post_id, $field['id'], $new);
- }
- } elseif ('' == $new && $old) {
- delete_post_meta($post_id, $field['id'], $old);
- }
- }
- }
- function nick_export_ui_scripts() {
- global $nick_options, $post;
- ?>
- <script type="text/javascript">
- jQuery(document).ready(function($)
- {
- if($('.form-table .nick_upload_field').length > 0 ) {
- // Media Uploader
- window.formfield = '';
- $('.nick_upload_image_button').live('click', function() {
- window.formfield = $('.nick_upload_field',$(this).parent());
- tb_show('', 'media-upload.php?type=file&post_id=<?php echo $post->ID; ?>&TB_iframe=true');
- return false;
- });
- window.original_send_to_editor = window.send_to_editor;
- window.send_to_editor = function(html) {
- if (window.formfield) {
- imgurl = $('a','<div>'+html+'</div>').attr('href');
- window.formfield.val(imgurl);
- tb_remove();
- }
- else {
- window.original_send_to_editor(html);
- }
- window.formfield = '';
- window.imagefield = false;
- }
- }
- });
- </script>
- <?php
- }
- function nick_export_datepicker_ui_scripts() {
- global $nick_base_dir;
- wp_enqueue_script('jquery-ui-datepicker');
- wp_enqueue_script('jquery-ui-slider');
- }
- function nick_export_datepicker_ui_styles() {
- global $nick_base_dir;
- wp_enqueue_style('jquery-ui-css', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css', false, '1.8', 'all');
- }
- // these are for newest versions of WP
- add_action('admin_print_scripts-post.php', 'nick_export_datepicker_ui_scripts');
- add_action('admin_print_scripts-edit.php', 'nick_export_datepicker_ui_scripts');
- add_action('admin_print_scripts-post-new.php', 'nick_export_datepicker_ui_scripts');
- add_action('admin_print_styles-post.php', 'nick_export_datepicker_ui_styles');
- add_action('admin_print_styles-edit.php', 'nick_export_datepicker_ui_styles');
- add_action('admin_print_styles-post-new.php', 'nick_export_datepicker_ui_styles');
- if ((isset($_GET['post']) && (isset($_GET['action']) && $_GET['action'] == 'edit') ) || (strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php')))
- {
- add_action('admin_head', 'nick_export_ui_scripts');
- }
- // converts a time stamp to date string for meta fields
- if(!function_exists('nick_timestamp_to_date')) {
- function nick_timestamp_to_date($date) {
- return date('m/d/Y', $date);
- }
- }
- if(!function_exists('nick_format_date')) {
- function nick_format_date($date) {
- $date = strtotime($date);
- return $date;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement