Archived
Adds type
This commit is contained in:
1 parent
e0263e117b
commit
8c76a4fc08
2 files changed
+48
-35
No files matched your search
@@ -6,9 +6,7 @@ function neuf_associations_change_columns( $cols ) {
|
||||
'title' => __( 'Forening', 'trans' ),
|
||||
'image' => __( 'Bilde', 'trans' ),
|
||||
'homepage' => __( 'Hjemmeside', 'trans' ),
|
||||
/*'author' => __( 'Forfatter', 'trans' ),
|
||||
'date' => __( 'Publiseringsdato', 'trans' ),
|
||||
'type' => __( 'Type', 'trans' ),*/
|
||||
'type' => __( 'Type', 'trans' ),
|
||||
);
|
||||
return $custom_cols;
|
||||
}
|
||||
@@ -28,19 +26,19 @@ function neuf_associations_custom_columns( $column, $post_id ) {
|
||||
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'large' );
|
||||
echo '<a href="'.$large_image_url[0].'" alt="'.$large_image_url[0].'">'.$thumb.'</a>';
|
||||
break;
|
||||
case "type":
|
||||
echo get_post_meta( $post_id, '_neuf_associations_type', true );
|
||||
break;
|
||||
}
|
||||
}
|
||||
add_action( "manage_posts_custom_column" , "neuf_associations_custom_columns", 10, 2 );
|
||||
|
||||
// Make these columns sortable
|
||||
function neuf_associations_sortable_columns( $cols ) {
|
||||
/*$custom_cols = array(
|
||||
'starttime' => 'starttime',
|
||||
'endtime' => 'endtime',
|
||||
$custom_cols = array(
|
||||
'type' => 'type',
|
||||
'venue' => 'venue',
|
||||
);*/
|
||||
return $cols;
|
||||
);
|
||||
return array_merge($custom_cols, $cols);
|
||||
}
|
||||
add_filter( "manage_edit-association_sortable_columns", "neuf_associations_sortable_columns" );
|
||||
|
||||
@@ -60,11 +58,25 @@ function add_associations_metaboxes() {
|
||||
function neuf_associations_div(){
|
||||
global $post;
|
||||
|
||||
$association_types = array('Forening', 'Utvalg');
|
||||
$association_type = get_post_meta( $post->ID, '_neuf_associations_type', true );
|
||||
|
||||
$association_homepage = get_post_meta( $post->ID, '_neuf_associations_homepage', true );
|
||||
?>
|
||||
<div class="misc-pub-section misc-pub-section-last">
|
||||
<label for="_neuf_associations_homepage">Hjemmeside:</label>
|
||||
<input type="text" name="_neuf_associations_homepage" value="<?php echo $association_homepage ? $association_homepage : ""; ?>" />
|
||||
<label for="_neuf_associations_type">Type:</label>
|
||||
<select name="_neuf_associations_type">
|
||||
<?php foreach ($association_types as $type) {
|
||||
echo '<option value="'.$type.'"';
|
||||
if($type== $association_type) {
|
||||
echo ' selected="selected"';
|
||||
}
|
||||
echo '>'.$type.'</option>';
|
||||
}
|
||||
?>
|
||||
</select><br />
|
||||
<?php wp_nonce_field( 'neuf_associations_nonce', 'neuf_associations_nonce' ); ?>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
@@ -41,36 +41,37 @@ function neuf_associations_post_type() {
|
||||
}
|
||||
/* When the post is saved, saves our custom data */
|
||||
function neuf_associations_save_postdata( $post_id ) {
|
||||
// verify if this is an auto save routine.
|
||||
// If it is our form has not been submitted, so we dont want to do anything
|
||||
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
|
||||
return;
|
||||
// verify if this is an auto save routine.
|
||||
// If it is our form has not been submitted, so we dont want to do anything
|
||||
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
|
||||
return;
|
||||
|
||||
// verify this came from the our screen and with proper authorization,
|
||||
// because save_post can be triggered at other times
|
||||
// verify this came from the our screen and with proper authorization,
|
||||
// because save_post can be triggered at other times
|
||||
|
||||
if ( empty($_POST) || !wp_verify_nonce( $_POST['neuf_associations_nonce'], 'neuf_associations_nonce' ) )
|
||||
return;
|
||||
if ( empty($_POST) || !wp_verify_nonce( $_POST['neuf_associations_nonce'], 'neuf_associations_nonce' ) )
|
||||
return;
|
||||
|
||||
// Check permissions
|
||||
if ( 'page' == $_POST['post_type'] )
|
||||
{
|
||||
if ( !current_user_can( 'edit_page', $post_id ) )
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !current_user_can( 'edit_post', $post_id ) )
|
||||
return;
|
||||
}
|
||||
// OK, we're authenticated.
|
||||
// Check permissions
|
||||
if ( 'page' == $_POST['post_type'] )
|
||||
{
|
||||
if ( !current_user_can( 'edit_page', $post_id ) )
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !current_user_can( 'edit_post', $post_id ) )
|
||||
return;
|
||||
}
|
||||
// OK, we're authenticated.
|
||||
|
||||
// prefix with protocol if not present
|
||||
$mydata = esc_url( $_POST['_neuf_associations_homepage'] );
|
||||
// Note esc_url prefixes url with protocol if not present
|
||||
$meta_data['_neuf_associations_homepage'] = esc_url( $_POST['_neuf_associations_homepage'] );
|
||||
$meta_data['_neuf_associations_type'] = $_POST['_neuf_associations_type'];
|
||||
|
||||
// Do something with $mydata
|
||||
// probably using add_post_meta(), update_post_meta(), or
|
||||
// a custom table (see Further Reading section below)
|
||||
update_post_meta($post_id, '_neuf_associations_homepage', $mydata);
|
||||
// Update database with meta data
|
||||
foreach($meta_data as $key => $value) {
|
||||
update_post_meta($post_id, $key, $value);
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in new issue
Block a user