1, 'post_type' => 'sv_resume' ) ); $post = array_pop( $posts ); $resume_id = $post->ID; add_submenu_page( 'edit.php?post_type=sv_resume', __( 'Edit resume', 'sparkle-vitae' ), __( 'Edit resume', 'sparkle-vitae' ), 'edit_theme_options', 'post.php?post=' . $resume_id . '&action=edit' ); } add_action( 'admin_init', 'sparkle_resume_menu' ); add_action( 'init', 'sparkle_register_cpt_resumes' ); function sparkle_register_cpt_resumes() { $labels = array( 'name' => _x( 'Resumes', 'sv_resume' ), 'singular_name' => _x( 'Resume', 'sv_resume' ), 'add_new' => _x( 'Add New', 'sv_resume' ), 'add_new_item' => _x( 'Add New Resumes', 'sv_resume' ), 'edit_item' => _x( 'Edit Resumes', 'sv_resume' ), 'new_item' => _x( 'New Resumes', 'sv_resume' ), 'view_item' => _x( 'View Resumes', 'sv_resume' ), 'search_items' => _x( 'Search Resume', 'sv_resume' ), 'not_found' => _x( 'No resume found', 'sv_resume' ), 'not_found_in_trash' => _x( 'No resume found in Trash', 'sv_resume' ), 'parent_item_colon' => _x( 'Parent Resumes:', 'sv_resume' ), 'menu_name' => _x( 'Resume', 'sv_resume' ), ); $args = array( 'labels' => $labels, 'hierarchical' => true, 'supports' => array( 'title', 'editor' ), 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 5, 'show_in_nav_menus' => true, // temp for testing 'publicly_queryable' => true, 'exclude_from_search' => false, 'has_archive' => false, 'query_var' => true, 'can_export' => true, 'capability_type' => 'post' ); register_post_type( 'sv_resume', $args ); } add_action( 'init', 'sparkle_register_cpt_jobs' ); function sparkle_register_respons_taxonomy() { register_taxonomy( 'sv_respons', 'sv_jobs', array( 'hierarchical' => true, 'labels' => array( 'name' => _x( 'Responsibilities', 'sparkle-vitae' ), 'singular_name' => __( 'Responsibility', 'sparkle-vitae' ), 'search_items' => __( 'Search Responsibilities', 'sparkle-vitae' ), 'popular_items' => __( 'Popular Responsibilities', 'sparkle-vitae' ), 'all_items' => __( 'All Responsibilities', 'sparkle-vitae' ), 'edit_item' => __( 'Edit Responsibility', 'sparkle-vitae' ), 'update_item' => __( 'Update Responsibilities', 'sparkle-vitae' ), 'add_new_item' => __( 'Add New Responsibility', 'sparkle-vitae' ), 'new_item_name' => __( 'New Responsibility Name', 'sparkle-vitae' ), 'add_or_remove_items' => __( 'Add or remove responsibility', 'sparkle-vitae' ), 'add_or_remove_items' => __( 'Add or remove responsibility', 'sparkle-vitae' ), 'choose_from_most_used' => __( 'Choose from the most used responsibilities', 'sparkle-vitae' ), 'menu_name' => __( 'Responsibilities', 'sparkle-vitae' ), ), ) ); } add_action( 'init', 'sparkle_register_respons_taxonomy' ); function sparkle_register_cpt_jobs() { $labels = array( 'name' => _x( 'Jobs', 'jobs' ), 'singular_name' => _x( 'Job', 'jobs' ), 'add_new' => _x( 'Add New', 'jobs' ), 'add_new_item' => _x( 'Add New Job', 'jobs' ), 'edit_item' => _x( 'Edit Jobs', 'jobs' ), 'new_item' => _x( 'New Jobs', 'jobs' ), 'view_item' => _x( 'View Jobs', 'jobs' ), 'search_items' => _x( 'Search Job', 'jobs' ), 'not_found' => _x( 'No job found', 'jobs' ), 'not_found_in_trash' => _x( 'No job found in Trash', 'jobs' ), 'parent_item_colon' => _x( 'Parent Jobs:', 'jobs' ), 'menu_name' => _x( 'Jobs', 'jobs' ), ); $rewrite = array( 'slug' => 'jobs', ); $args = array( 'labels' => $labels, 'hierarchical' => true, 'supports' => array( 'title', 'editor' ), 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 5, 'show_in_nav_menus' => false, 'publicly_queryable' => true, 'exclude_from_search' => false, 'has_archive' => true, 'query_var' => true, 'can_export' => true, 'rewrite' => $rewrite, 'capability_type' => 'post' ); register_post_type( 'sv_jobs', $args ); } add_action( 'init', 'sparkle_register_cpt_educations' ); function sparkle_register_cpt_educations() { $labels = array( 'name' => _x( 'Education', 'sv_schools' ), 'singular_name' => _x( 'School', 'sv_schools' ), 'add_new' => _x( 'Add School', 'sv_schools' ), 'add_new_item' => _x( 'Add New School', 'sv_schools' ), 'edit_item' => _x( 'Edit School', 'sv_schools' ), 'new_item' => _x( 'New School', 'sv_schools' ), 'view_item' => _x( 'View School', 'sv_schools' ), 'search_items' => _x( 'Search Schools', 'sv_schools' ), 'not_found' => _x( 'No school found', 'sv_schools' ), 'not_found_in_trash' => _x( 'No school found in Trash', 'sv_schools' ), 'parent_item_colon' => _x( 'Parent Schools:', 'sv_schools' ), 'menu_name' => _x( 'Education', 'sv_schools' ), ); $rewrite = array( 'slug' => 'education', ); $args = array( 'labels' => $labels, 'hierarchical' => true, 'supports' => array( 'title', 'editor' ), 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 5, 'show_in_nav_menus' => false, 'publicly_queryable' => true, 'exclude_from_search' => false, 'has_archive' => false, 'rewrite' => $rewrite, 'query_var' => true, 'can_export' => true, 'capability_type' => 'post' ); register_post_type( 'sv_schools', $args ); } function sparkle_setup_resume() { global $wpdb; $resume = sparkle_get_resume(); if ( $resume ) return $resume->ID; $resume = array( 'post_title' => 'Resume', 'post_content' => 'Resume', 'post_status' => 'publish', 'post_type' => 'sv_resume' ); return wp_insert_post( $resume ); } function sparkle_get_resume() { global $wpdb; $posts = get_posts( array( 'numberposts' => 1, 'post_type' => 'sv_resume' ) ); $resume = array_pop( $posts ); if ( !$resume ) return false; $resume->meta = array(); $meta_want = array( 'name', 'summary', 'location', 'phone', 'email', 'technical_skills', 'memberships', 'awards', 'certifications', 'publications', 'presentations', 'references_available' ); foreach ( $meta_want as $key ) $resume->meta[$key] = maybe_unserialize( get_post_meta( $resume->ID, $key, true ) ); return $resume; } function sparkle_update_resume( $resume ) { global $wpdb; $meta = $resume->meta; unset( $resume->meta ); $updated = wp_update_post( $resume ); if ( !$updated ) return false; foreach ( $meta as $key => $val ) update_post_meta( $resume->ID, $key, $val ); return true; } function sparkle_get_job( $id ) { global $wpdb; $job = get_post( $id ); if ( !$job ) return false; $meta_want = array( 'company_location', 'company_phone', 'company_website', 'accomplishments', 'job_title', 'job_description', 'job_department', 'job_supervisor_name', 'projects' ); $job->meta = array(); foreach ( $meta_want as $key ) $job->meta[$key] = maybe_unserialize( get_post_meta( $job->ID, $key, true ) ); return $job; } function sparkle_get_jobs() { global $wpdb; $jobs = get_posts( array( 'post_type' => 'jobs' ) ); if ( !$jobs ) return false; $meta_want = array( 'company_location', 'company_phone', 'company_website', 'accomplishments', 'job_title', 'job_description', 'job_department', 'job_supervisor_name', 'projects' ); foreach ( $jobs as $i => $job ) { $job->meta = array(); foreach ( $meta_want as $key ) $jobs[$i]->meta[$key] = maybe_unserialize( get_post_meta( $job->ID, $key, true ) ); } return $jobs; } function sparkle_update_job( $job ) { global $wpdb; $meta = $job->meta; unset( $job->meta ); $updated = wp_update_post( $job ); if ( !$updated ) return false; foreach ( $meta as $key => $val ) update_post_meta( $job->ID, $key, $val ); return true; } function sparkle_get_education( $id ) { global $wpdb; $education = get_post( $id ); if ( !$education ) return false; $meta_want = array( 'university_name', 'university_location', 'major', 'minor', 'degree_earned', 'advisor_name', 'advisor_title', 'advisor_department', 'clubs', 'awards', 'elected_offices', 'classes' ); $education->meta = array(); foreach ( $meta_want as $key ) $education[$i]->meta[$key] = maybe_unserialize( get_post_meta( $education->ID, $key, true ) ); return $education; } function sparkle_get_educations() { global $wpdb; $educations = get_posts( array( 'post_type' => 'sv_schools' ) ); if ( !$educations ) return false; $meta_want = array( 'university_name', 'university_location', 'major', 'minor', 'degree_earned', 'advisor_name', 'advisor_title', 'advisor_department', 'clubs', 'awards', 'elected_offices', 'classes' ); foreach ( $educations as $i => $education ) { $education->meta = array(); foreach ( $meta_want as $key ) $educations[$i]->meta[$key] = maybe_unserialize( get_post_meta( $education->ID, $key, true ) ); } return $educations; } function sparkle_update_education( $education ) { global $wpdb; $meta = $education->meta; unset( $education->meta ); $updated = wp_update_post( $education ); if ( !$updated ) return false; foreach ( $meta as $key => $val ) update_post_meta( $education->ID, $key, $val ); return true; } /** * Add support for post thumbnails on Jobs and Education pages */ function sparkle_vitae_custom_post_type_support() { add_post_type_support( 'sv_jobs', 'thumbnail' ); remove_post_type_support( 'sv_resume', 'title' ); } add_action('init', 'sparkle_vitae_custom_post_type_support'); /** * Remove slug meta box from Resume */ function sparkle_vitae_remove_slug_meta_box() { remove_meta_box( 'slugdiv' , 'sv_resume' , 'normal' ); } add_action( 'admin_menu' , 'sparkle_vitae_remove_slug_meta_box' ); /** * Define custom meta boxes on Jobs pages */ add_action( 'add_meta_boxes', 'sparkle_vitae_meta_boxes' ); function sparkle_vitae_meta_boxes() { add_meta_box( 'sparkle-vitae-job-meta-box', // HTML ID __( 'Job', 'sparkle-vitae' ), // Title, remember to i18n 'sparkle_vitae_render_job_meta', // Callback 'sv_jobs', // Custom Post Type 'normal', // Context (normal or advanced) 'high' // Priority ); add_meta_box( 'sparkle-vitae-school-meta-box', __( 'School', 'sparkle-vitae' ), 'sparkle_vitae_render_school_meta', 'sv_schools', 'normal', 'high' ); add_meta_box( 'sparkle-vitae-resume-meta-box', __( 'Resume', 'sparkle-vitae' ), 'sparkle_vitae_render_resume_meta', 'sv_resume', 'normal', 'high' ); } // sparkle_vitae_jobs_meta_box() function sparkle_vitae_render_job_meta() { global $post; $sv_job_meta = get_post_custom( $post->ID ); $sv_job_title = ( ! isset( $sv_job_meta['sv_job_title'][0] ) ) ? '' : esc_attr( $sv_job_meta[ 'sv_job_title' ][0] ); $sv_job_title = ( ! isset( $sv_job_meta['sv_job_supervisor'][0] ) ) ? '' : esc_attr( $sv_job_meta[ 'sv_job_supervisor' ][0] ); $sv_job_start_date = ( ! isset( $sv_job_meta['sv_job_start_date'][0] ) ) ? '' : esc_attr( $sv_job_meta[ 'sv_job_start_date' ][0] ); $sv_job_end_date = ( ! isset( $sv_job_meta['sv_job_end_date'][0] ) ) ? '' : esc_attr( $sv_job_meta[ 'sv_job_end_date' ][0] ); $sv_job_color = ( ! isset( $sv_job_meta['sv_job_color'][0] ) ) ? '' : esc_attr( $sv_job_meta[ 'sv_job_color' ][0] ); wp_nonce_field( 'sv_nonce_action', 'sv_meta_box_nonce' ); ?>
ID ); $sv_school_location = ( ! isset( $sv_school_meta['sv_school_location'][0] ) ) ? '' : esc_attr( $sv_school_meta[ 'sv_school_location' ][0] ); $sv_school_start_date = ( ! isset( $sv_school_meta['sv_school_start_date'][0] ) ) ? '' : esc_attr( $sv_school_meta[ 'sv_school_start_date' ][0] ); $sv_school_end_date = ( ! isset( $sv_school_meta['sv_school_end_date'][0] ) ) ? '' : esc_attr( $sv_school_meta[ 'sv_school_end_date' ][0] ); $sv_school_major = ( ! isset( $sv_school_meta['sv_school_major'][0] ) ) ? '' : esc_attr( $sv_school_meta[ 'sv_school_major' ][0] ); $sv_school_minor = ( ! isset( $sv_school_meta['sv_school_minor'][0] ) ) ? '' : esc_attr( $sv_school_meta[ 'sv_school_minor' ][0] ); $sv_school_degree = ( ! isset( $sv_school_meta['sv_school_degree'][0] ) ) ? '' : esc_attr( $sv_school_meta[ 'sv_school_degree' ][0] ); wp_nonce_field( 'sv_nonce_action', 'sv_meta_box_nonce' ); ?>
ID ); $sv_resume_name = ( ! isset( $sv_resume_meta['sv_resume_name'][0] ) ) ? '' : esc_attr( $sv_resume_meta[ 'sv_resume_name' ][0] ); wp_nonce_field( 'sv_nonce_action', 'sv_meta_box_nonce' ); ?>
ID, 'sv_job_supervisor', $_POST[ 'sparkle-vitae-job-supervisor' ] ); } // Update Job Title if( isset( $_POST[ 'sparkle-vitae-job-title' ] ) ) { update_post_meta( $post->ID, 'sv_job_title', $_POST[ 'sparkle-vitae-job-title' ] ); } // Update Job Start Date if( isset( $_POST[ 'sparkle-vitae-job-start-date' ] ) ) { update_post_meta( $post->ID, 'sv_job_start_date', $_POST[ 'sparkle-vitae-job-start-date' ] ); } // Update Job End Date if( isset( $_POST[ 'sparkle-vitae-job-end-date' ] ) ) { update_post_meta( $post->ID, 'sv_job_end_date', $_POST[ 'sparkle-vitae-job-end-date' ] ); } // Update Job Color if( isset( $_POST[ 'sparkle-vitae-job-color' ] ) ) { update_post_meta( $post->ID, 'sv_job_color', $_POST[ 'sparkle-vitae-job-color' ] ); } } // sparkle_vitae_jobs_meta_box_save() add_action( 'save_post', 'sparkle_vitae_schools_meta_box_save' ); function sparkle_vitae_schools_meta_box_save() { global $post; // Do not proceed during autosave if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; // Verify this came from the our screen and with proper authorization if( ! isset( $_POST[ 'sv_meta_box_nonce' ] ) || ! wp_verify_nonce( $_POST[ 'sv_meta_box_nonce' ], 'sv_nonce_action' ) ) return; // Check user permissions if( ! current_user_can( 'edit_post' ) ) return; // Update School Location if( isset( $_POST[ 'sparkle-vitae-school-location' ] ) ) { update_post_meta( $post->ID, 'sv_school_location', $_POST[ 'sparkle-vitae-school-location' ] ); } // Update School Start Date if( isset( $_POST[ 'sparkle-vitae-school-start-date' ] ) ) { update_post_meta( $post->ID, 'sv_school_start_date', $_POST[ 'sparkle-vitae-school-start-date' ] ); } // Update School End Date if( isset( $_POST[ 'sparkle-vitae-school-end-date' ] ) ) { update_post_meta( $post->ID, 'sv_school_end_date', $_POST[ 'sparkle-vitae-school-end-date' ] ); } // Update Major if( isset( $_POST[ 'sparkle-vitae-school-major' ] ) ) { update_post_meta( $post->ID, 'sv_school_major', $_POST[ 'sparkle-vitae-school-major' ] ); } // Update Minor if( isset( $_POST[ 'sparkle-vitae-school-minor' ] ) ) { update_post_meta( $post->ID, 'sv_school_minor', $_POST[ 'sparkle-vitae-school-minor' ] ); } // Update Degree if( isset( $_POST[ 'sparkle-vitae-school-degree' ] ) ) { update_post_meta( $post->ID, 'sv_school_degree', $_POST[ 'sparkle-vitae-school-degree' ] ); } } // sparkle_vitae_schools_meta_box_save() add_action( 'save_post', 'sparkle_vitae_resume_meta_box_save' ); function sparkle_vitae_resume_meta_box_save() { global $post; // Do not proceed during autosave if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; // Verify this came from the our screen and with proper authorization if( ! isset( $_POST[ 'sv_meta_box_nonce' ] ) || ! wp_verify_nonce( $_POST[ 'sv_meta_box_nonce' ], 'sv_nonce_action' ) ) return; // Check user permissions if( ! current_user_can( 'edit_post' ) ) return; // Update Resume Name if( isset( $_POST[ 'sparkle-vitae-resume-name' ] ) ) { update_post_meta( $post->ID, 'sv_resume_name', $_POST[ 'sparkle-vitae-resume-name' ] ); } } // sparkle_vitae_schools_meta_box_save() function add_admin_menu() { add_options_page("Resume", "Resume", 10, "Resume", "resume_admin_page"); } //add_action( 'admin_menu', 'add_admin_menu' ); /* function resume_admin_page() { include __DIR__ . '/resume-admin-page-content.php'; } */ // WPCOM Mod - rewrite rules function sparkle_rewrite_rules( $rules ) { global $default_rewrite_rules; if( empty( $rules ) ) { if( empty( $default_rewrite_rules ) ) $default_rewrite_rules = array(); $rules = $default_rewrite_rules; } $add_rules = array( 'jobs/[^/]+/attachment/([^/]+)/?$' => 'index.php?attachment=$matches[1]', 'jobs/[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1', 'jobs/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', 'jobs/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', 'jobs/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]', 'jobs/([^/]+)/trackback/?$' => 'index.php?post_type=sv_jobs&sv_jobs=$matches[1]&tb=1', 'jobs/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=sv_jobs&sv_jobs=$matches[1]&feed=$matches[2]', 'jobs/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=sv_jobs&sv_jobs=$matches[1]&feed=$matches[2]', 'jobs/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?post_type=sv_jobs&sv_jobs=$matches[1]&paged=$matches[2]', 'jobs/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=sv_jobs&sv_jobs=$matches[1]&cpage=$matches[2]', 'jobs/([^/]+)(/[0-9]+)?/?$' => 'index.php?post_type=sv_jobs&sv_jobs=$matches[1]&page=$matches[2]', 'jobs/[^/]+/([^/]+)/?$' => 'index.php?attachment=$matches[1]', 'jobs/[^/]+/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1', 'jobs/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', 'jobs/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', 'jobs/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]', 'jobs/([^/]+)/?$' => 'index.php?post_type=sv_jobs&sv_jobs=$matches[1]', 'jobs/?$' => 'index.php?post_type=sv_jobs', 'education/[^/]+/attachment/([^/]+)/?$' => 'index.php?attachment=$matches[1]', 'education/[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1', 'education/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', 'education/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', 'education/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]', 'education/([^/]+)/trackback/?$' => 'index.php?post_type=sv_schools&sv_schools=$matches[1]&tb=1', 'education/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=sv_schools&sv_schools=$matches[1]&feed=$matches[2]', 'education/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=sv_schools&sv_schools=$matches[1]&feed=$matches[2]', 'education/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?post_type=sv_schools&sv_schools=$matches[1]&paged=$matches[2]', 'education/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=sv_schools&sv_schools=$matches[1]&cpage=$matches[2]', 'education/([^/]+)(/[0-9]+)?/?$' => 'index.php?post_type=sv_schools&sv_schools=$matches[1]&page=$matches[2]', 'education/[^/]+/([^/]+)/?$' => 'index.php?attachment=$matches[1]', 'education/[^/]+/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1', 'education/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', 'education/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', 'education/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]', 'education/([^/]+)/?$' => 'index.php?post_type=sv_schools&sv_schools=$matches[1]', 'education/?$' => 'index.php?post_type=sv_schools', ); return array_merge( $add_rules, (array) $rules ); } add_filter( 'pre_transient_rewrite_rules', 'sparkle_rewrite_rules' );