array( 'name' => __( 'Adverts' ), 'singular_name' => __( 'Advert' ), 'all_items'=>'All Adverts', 'edit_item'=>'Edit Advert', 'update_item'=>'Update Advert', 'add_new_item'=>'Add New Advert', 'new_item_name'=>'New Advert', ), 'public' => true, 'exclude_from_search' => true, 'menu_position' => 5, 'supports' => array( 'title', 'thumbnail' ) ) ); } add_action( 'init', 'akp_create_post_type' ); // Add scripts to page function akp_my_scripts_method() { wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js'); wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'adkingpro-js', plugins_url('js/adkingpro-functions.js', dirname(__FILE__)), array('jquery') ); wp_localize_script( 'adkingpro-js', 'AkpAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'ajaxnonce' => wp_create_nonce( 'akpN0nc3' ), ) ); } add_action('wp_enqueue_scripts', 'akp_my_scripts_method'); // Update title field to become URL field function akp_title_text_input( $title ){ global $post; if($post->post_type == 'adverts_posts') return $title = 'Advert URL ie http://durham.net.au/wp-plugins/adkingpro'; return $title; } add_filter( 'enter_title_here', 'akp_title_text_input' ); // Update Feature Image to become Advert Image function akp_change_meta_boxes() { remove_meta_box( 'postimagediv', 'adverts_posts', 'side' ); add_meta_box('postimagediv', __('Advert Image'), 'post_thumbnail_meta_box', 'adverts_posts', 'normal', 'high'); add_meta_box('postremoveurllink', __('Remove Link from Advert?'), 'akp_remove_url_link', 'adverts_posts', 'advanced', 'high'); add_meta_box('postclickstatsdiv', __('Advert Stats'), 'akp_post_click_stats', 'adverts_posts', 'advanced', 'low'); } add_action('do_meta_boxes', 'akp_change_meta_boxes'); // Output stats for post function akp_post_click_stats($object, $box) { global $wpdb; $clicks = $wpdb->get_results("SELECT COUNT(*) as clicks FROM ".$wpdb->prefix."akp_click_log WHERE post_id = '$object->ID'"); echo "This banner has had ".$clicks[0]->clicks." since being published. View Detailed Report"; } // Add checkbox to remove URL Link off advert function akp_remove_url_link($object, $box) { global $post; $remove_url = get_post_meta( $post->ID, 'akp_remove_url', true ); // Use nonce for verification echo ''; echo ''; } // Process the custom metabox fields function akp_save_custom_fields( ) { global $post; // verify nonce if (!wp_verify_nonce($_POST['akp_meta_box_nonce'], basename(__FILE__))) { return; } if( $_POST ) { if (isset($_POST['akp_remove_url'])) update_post_meta( $post->ID, 'akp_remove_url', $_POST['akp_remove_url'] ); else update_post_meta( $post->ID, 'akp_remove_url', 0 ); } } add_action( 'save_post', 'akp_save_custom_fields' ); // Process the custom metabox fields function akp_return_fields( $id = NULL ) { global $post; if (is_null($id)) $id = $post->ID; $output = array(); $output['akp_remove_url'] = get_post_meta( $id, 'akp_remove_url' ); return $output; } // Remove the Permalinks function akp_perm($return, $id, $new_title, $new_slug){ global $post; if($post->post_type == 'adverts_posts') return ''; return $return; } add_filter('get_sample_permalink_html', 'akp_perm', '', 4); // Change text labels function akp_swap_featured_image_metabox($translation, $text, $domain) { global $post; $translations = get_translations_for_domain( $domain); switch( $post->post_type ){ case 'adverts_posts': if ( $text == 'Set featured image') return $translations->translate( 'Set Advert Image' ); if ( $text == 'Remove featured image') return $translations->translate( 'Remove Advert Image' ); break; } return $translation; } add_filter('gettext', 'akp_swap_featured_image_metabox', 10, 4); // Register Advert types taxonomy function akp_taxonomies() { register_taxonomy( 'advert_types', 'adverts_posts', array( 'hierarchical' => true, 'labels' => array( 'name'=>'Advert Types', 'singular_name'=>'Advert Type', 'all_items'=>'All Advert Types', 'edit_item'=>'Edit Advert Type', 'update_item'=>'Update Advert Type', 'add_new_item'=>'Add New Advert Type', 'new_item_name'=>'New Advert Type', 'search_items'=>'Search Advert Types', ), 'query_var' => true, 'rewrite' => array('slug' => 'adverts_slug') ) ); } add_action( 'init', 'akp_taxonomies' ); // Columns in custom post types function akp_edit_adverts_columns( $columns ) { $columns = array( 'cb' => '', 'banner_id' => __( 'Banner ID' ), 'clicks' => __( 'Clicks' ), 'title' => __( 'URL' ), 'advert_type' => __( 'Advert Type'), 'advert_image' => __( 'Advert Image'), 'date' => __( 'Date' ), ); return $columns; } add_filter( 'manage_edit-adverts_posts_columns', 'akp_edit_adverts_columns' ) ; // Update column data with custom data function akp_columns($column_name, $ID) { switch ($column_name) { case 'advert_type' : $terms = get_the_terms( $ID, 'advert_types' ); if ( !empty( $terms ) ) { $out = array(); foreach ( $terms as $term ) { $out[] = sprintf( '%s', esc_url( add_query_arg( array( 'post_type' => 'adverts_posts', 'advert_type' => $term->slug ), 'edit.php' ) ), esc_html( sanitize_term_field( 'name', $term->name, $term->term_id, 'genre', 'display' ) ) ); } echo join( ', ', $out ); } else { echo 'No Advert Types Assigned'; } break; case 'advert_image' : $post_featured_image = akp_get_featured_image($post_ID); if ($post_featured_image) { echo ''; } break; case 'banner_id' : echo $ID; break; case 'clicks' : global $wpdb; $clicks = $wpdb->get_results("SELECT COUNT(*) as clicks FROM ".$wpdb->prefix."akp_click_log WHERE post_id = '$ID'"); echo $clicks[0]->clicks; break; } } add_action('manage_adverts_posts_posts_custom_column', 'akp_columns', 10, 2); // GET FEATURED IMAGE function akp_get_featured_image($post_ID) { $post_thumbnail_id = get_post_thumbnail_id($post_ID); if ($post_thumbnail_id) { $post_thumbnail_img = wp_get_attachment_image_src($post_thumbnail_id, 'custom_thumbnail'); return $post_thumbnail_img[0]; } } // Dashboard Widget function akp_admin_register_head() { ?> ' /> 0) { foreach ($advert_types as $type) { echo "

$type->name

"; query_posts(array( 'post_type'=>'adverts_posts', 'advert_types'=>$type->slug )); echo "