diff --git a/plugins/neuf-associations/neuf-associations-admin.php b/plugins/neuf-associations/neuf-associations-admin.php index 4ef80716..cf04d5c1 100644 --- a/plugins/neuf-associations/neuf-associations-admin.php +++ b/plugins/neuf-associations/neuf-associations-admin.php @@ -1,84 +1,90 @@ '', - 'title' => __( 'Association', 'neuf_assoc' ), - 'image' => __( 'Image', 'neuf_assoc' ), - 'homepage' => __( 'Website', 'neuf_assoc' ), - 'type' => __( 'Type', 'neuf_assoc' ), - ); - return $custom_cols; +function neuf_associations_change_columns($cols) +{ + $custom_cols = array( + 'cb' => '', + 'title' => __('Association', 'neuf_assoc'), + 'image' => __('Image', 'neuf_assoc'), + 'homepage' => __('Website', 'neuf_assoc'), + 'type' => __('Type', 'neuf_assoc'), + ); + return $custom_cols; } -add_filter( "manage_association_posts_columns", "neuf_associations_change_columns" ); +add_filter("manage_association_posts_columns", "neuf_associations_change_columns"); // Add values to the custom columns -function neuf_associations_custom_columns( $column, $post_id ) { - switch ( $column ) { - case "homepage": - $homepage = get_post_meta( $post_id, '_neuf_associations_homepage', true ); - // default to permalink if not set - $homepage = $homepage ? $homepage : get_permalink( $post_id ); - echo ''.$homepage.''; - break; - case "image": - $thumb = get_the_post_thumbnail( $post_id, array(100, 50) ); - $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'large' ); - echo ''.$thumb.''; - break; - case "type": - echo get_post_meta( $post_id, '_neuf_associations_type', true ); - break; - } +function neuf_associations_custom_columns($column, $post_id) +{ + switch ($column) { + case "homepage": + $homepage = get_post_meta($post_id, '_neuf_associations_homepage', true); + // default to permalink if not set + $homepage = $homepage ? $homepage : get_permalink($post_id); + echo '' . $homepage . ''; + break; + case "image": + $thumb = get_the_post_thumbnail($post_id, array(100, 50)); + $large_image_url = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), 'large'); + echo '' . $thumb . ''; + 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 ); +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( - 'type' => 'type', - ); - return array_merge($custom_cols, $cols); +function neuf_associations_sortable_columns($cols) +{ + $custom_cols = array( + 'type' => 'type', + ); + return array_merge($custom_cols, $cols); } -add_filter( "manage_edit-association_sortable_columns", "neuf_associations_sortable_columns" ); +add_filter("manage_edit-association_sortable_columns", "neuf_associations_sortable_columns"); /* Add metaboxes (with styles) */ -function add_associations_metaboxes() { - add_meta_box( - 'neuf_associations_div', - __('Association details', 'neuf_assoc'), - 'neuf_associations_div', - 'association', - 'side' - ); +function add_associations_metaboxes() +{ + add_meta_box( + 'neuf_associations_div', + __('Association details', 'neuf_assoc'), + 'neuf_associations_div', + 'association', + 'side' + ); } - /* Metabox with additional info. */ -function neuf_associations_div(){ - global $post; +function neuf_associations_div() +{ + global $post; - /* Static types */ - $association_types = array('Forening', 'Utvalg'); + /* Static types */ + $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 ); - ?> + $association_type = get_post_meta($post->ID, '_neuf_associations_type', true); + $association_homepage = get_post_meta($post->ID, '_neuf_associations_homepage', true); + ?>
- + " /> - +
- +
__( 'Associations', 'neuf_assoc'), - 'singular_name' => __( 'Association', 'neuf_assoc'), - 'add_new' => __( 'Add New', 'neuf_assoc'), - 'add_new_item' => __( 'Add New', 'neuf_assoc'), - 'edit_item' => __( 'Edit Association', 'neuf_assoc'), - 'new_item' => __( 'Add New Association', 'neuf_assoc'), - 'view_item' => __( 'View Association', 'neuf_assoc'), - 'search_items' => __( 'Search Associations', 'neuf_assoc'), - 'not_found' => __( 'No associations found', 'neuf_assoc'), - 'not_found_in_trash' => __( 'No associations found in trash', 'neuf_assoc') - ); - register_post_type( - 'association', - array( - 'labels' => $labels, - 'menu_position' => 5, - 'public' => true, - 'publicly_queryable' => true, - 'query_var' => 'association', - 'show_ui' => true, - 'show_in_rest' => true, - 'rest_base' => 'associations', - 'capability_type' => 'post', - 'supports' => array( - 'title', - 'editor', - 'author', - 'thumbnail', - 'excerpt', - 'comments', - 'revisions', - 'administrator', - 'custom-fields' - ), - 'register_meta_box_cb' => 'add_associations_metaboxes', - ) - ); - +function neuf_associations_post_type() +{ + $labels = array( + 'name' => __('Associations', 'neuf_assoc'), + 'singular_name' => __('Association', 'neuf_assoc'), + 'add_new' => __('Add New', 'neuf_assoc'), + 'add_new_item' => __('Add New', 'neuf_assoc'), + 'edit_item' => __('Edit Association', 'neuf_assoc'), + 'new_item' => __('Add New Association', 'neuf_assoc'), + 'view_item' => __('View Association', 'neuf_assoc'), + 'search_items' => __('Search Associations', 'neuf_assoc'), + 'not_found' => __('No associations found', 'neuf_assoc'), + 'not_found_in_trash' => __('No associations found in trash', 'neuf_assoc'), + ); + register_post_type( + 'association', + array( + 'labels' => $labels, + 'menu_position' => 5, + 'public' => true, + 'publicly_queryable' => true, + 'query_var' => 'association', + 'show_ui' => true, + 'show_in_rest' => true, + 'rest_base' => 'associations', + 'capability_type' => 'post', + 'supports' => array( + 'title', + 'editor', + 'author', + 'thumbnail', + 'excerpt', + 'comments', + 'revisions', + 'administrator', + 'custom-fields', + ), + 'register_meta_box_cb' => 'add_associations_metaboxes', + ) + ); } + /* When the post is saved, saves our custom data */ -function neuf_associations_save_postdata( $post_id ) { - // verify if this is an auto save routine. +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 ) + 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 - if ( !array_key_exists('neuf_associations_nonce', $_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; + if (!array_key_exists('neuf_associations_nonce', $_POST) || !wp_verify_nonce($_POST['neuf_associations_nonce'], 'neuf_associations_nonce')) { + return; } - else - { - if ( !current_user_can( 'edit_post', $post_id ) ) + + // 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. // 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_homepage'] = esc_url($_POST['_neuf_associations_homepage']); $meta_data['_neuf_associations_type'] = $_POST['_neuf_associations_type']; // Update database with meta data - foreach($meta_data as $key => $value) { + foreach ($meta_data as $key => $value) { update_post_meta($post_id, $key, $value); } } /** API: Add our custom fields to the events endpoint */ add_filter('rest_prepare_association', 'neuf_associations_rest_custom_fields', 10, 3); -function neuf_associations_rest_custom_fields($response, $post, $request) { +function neuf_associations_rest_custom_fields($response, $post, $request) +{ $custom_field_data = get_post_custom($post->ID); $field_map = array( '_neuf_associations_type' => 'association_type', diff --git a/plugins/neuf-associations/neuf-associations.php b/plugins/neuf-associations/neuf-associations.php index 0fc3e7d9..66adce64 100644 --- a/plugins/neuf-associations/neuf-associations.php +++ b/plugins/neuf-associations/neuf-associations.php @@ -1,29 +1,29 @@