Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@richardmtl
Created July 18, 2014 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save richardmtl/091dfc2f0c36636e0317 to your computer and use it in GitHub Desktop.
Save richardmtl/091dfc2f0c36636e0317 to your computer and use it in GitHub Desktop.
<?php
/*
* Plugin Name: AA Test Plugin
* Plugin URI: http://wordpress.org/extend/plugins/test
* Description: Testing all kinds of things!
* Author: Richard Archambault
* Version: 1.0
* License: GPL2+
*/
function register_custom_post_types() {
/**************************/
/* Register DOG post type */
/**************************/
register_post_type('dog', array(
'label' => 'Dogs',
'labels' => array(
'name' => 'Dogs',
'singular_name' => 'Dog',
'add_new' => 'Add New Dog',
'add_new_item' => 'Add New Dog',
'edit_item' => 'Edit Dog',
'new_item' => 'New Dog',
'view' => 'View Dog',
'view_item' => 'View Dog',
'search_items' => 'Search Dogs',
'not_found' => 'No Dogs found',
'not_found_in_trash' => 'No Dogs found in Trash'
),
'description' => 'Dogs',
'public' => true,
'menu_position' => 5,
'supports' => array(
'title',
'revisions',
'publicize',
'shortlinks'
),
'has_archive' => true,
'rewrite' => array(
'slug' => 'rescue',
'with_front' => false
),
'menu_icon' => 'dashicons-jamies-paw'
));
register_taxonomy('age', array('dog', 'success'), array(
'capabilities' => array(
'manage_terms' => '',
'edit_terms' => '',
'delete_terms' => '',
'assign_terms' => ''
),
'label' => 'Age',
'labels' => array(
'name' => 'Age',
'add_new_item' => 'Add New Age',
'new_item_name' => 'Add New Age'
),
'public' => true,
'show_admin_column' => true,
'show_in_nav_menus' => false,
'show_tagcloud' => false,
'show_ui' => true,
'hierarchical' => true
));
register_taxonomy('breed', array('dog', 'success'), array(
'capabilities' => array(
'manage_terms' => '',
'edit_terms' => '',
'delete_terms' => '',
'assign_terms' => ''
),
'label' => 'Breed',
'labels' => array(
'name' => 'Breed',
'add_new_item' => 'Add New Breed',
'new_item_name' => 'Add New Breed'
),
'public' => true,
'show_admin_column' => true,
'show_in_nav_menus' => false,
'show_tagcloud' => false,
'show_ui' => true,
'hierarchical' => true
));
register_taxonomy('sex', array('dog', 'success'), array(
'capabilities' => array(
'manage_terms' => '',
'edit_terms' => '',
'delete_terms' => '',
'assign_terms' => ''
),
'label' => 'Sex',
'labels' => array(
'name' => 'Sex',
'add_new_item' => 'Add New Sex',
'new_item_name' => 'Add New Sex'
),
'public' => true,
'show_admin_column' => true,
'show_in_nav_menus' => false,
'show_tagcloud' => false,
'show_ui' => true,
'hierarchical' => true
));
register_taxonomy('size', array('dog', 'success'), array(
'capabilities' => array(
'manage_terms' => '',
'edit_terms' => '',
'delete_terms' => '',
'assign_terms' => ''
),
'label' => 'Size',
'labels' => array(
'name' => 'Size',
'add_new_item' => 'Add New Size',
'new_item_name' => 'Add New Size'
),
'public' => true,
'show_admin_column' => true,
'show_in_nav_menus' => false,
'show_tagcloud' => false,
'show_ui' => true,
'hierarchical' => true
));
register_taxonomy_for_object_type('age', 'dog');
register_taxonomy_for_object_type('breed', 'dog');
register_taxonomy_for_object_type('sex', 'dog');
register_taxonomy_for_object_type('size', 'dog');
/******************************/
/* Register SUCCESS post type */
/******************************/
register_post_type('success', array(
'label' => 'Success Stories',
'labels' => array(
'name' => 'Success Stories',
'singular_name' => 'Success Story',
'add_new' => 'Add New Success Story',
'add_new_item' => 'Add New Success Story',
'edit_item' => 'Edit Success Story',
'new_item' => 'New Success Story',
'view' => 'View Success Story',
'view_item' => 'View Success Story',
'search_items' => 'Search Success Stories',
'not_found' => 'No Success Stories found',
'not_found_in_trash' => 'No Success Stories found in Trash'
),
'description' => 'Success Stories',
'public' => true,
'menu_position' => 5,
'supports' => array(
'title',
'revisions',
'publicize',
'shortlinks'
),
'has_archive' => true,
'rewrite' => array(
'slug' => 'success',
'with_front' => false
),
'menu_icon' => 'dashicons-format-status'
));
register_taxonomy_for_object_type('age', 'success');
register_taxonomy_for_object_type('breed', 'success');
register_taxonomy_for_object_type('sex', 'success');
register_taxonomy_for_object_type('size', 'success');
/****************************/
/* Register EVENT post type */
/****************************/
register_post_type('event', array(
'label' => 'Events/Press',
'labels' => array(
'name' => 'Events/Press',
'singular_name' => 'Event/Press',
'add_new' => 'Add New Event/Press',
'add_new_item' => 'Add New Event/Press',
'edit_item' => 'Edit Event/Press',
'new_item' => 'New Event/Press',
'view' => 'View Event/Press',
'view_item' => 'View Event/Press',
'search_items' => 'Search Events/Press',
'not_found' => 'No Events/Press found',
'not_found_in_trash' => 'No Events/Press found in Trash'
),
'description' => 'Events/Press',
'public' => true,
'menu_position' => 5,
'supports' => array(
'title',
'revisions',
'publicize',
'shortlinks'
),
'has_archive' => true,
'rewrite' => array(
'slug' => 'event',
'with_front' => false
),
'menu_icon' => 'dashicons-calendar'
));
}
add_action('init', 'register_custom_post_types', 0);
function custom_open_graph_tags($tags, $size) {
global $post;
if(isset($tags['article:author'])) {
$tags['article:author'] = home_url('/');
}
$social = get_field('icons-social', 'option');
foreach($social as $s) {
if(stristr($s['social-link'], 'twitter.com')) {
$twitter_name = basename($s['social-link']);
break;
}
}
if(is_singular('event')) {
$details = get_field('details', $post->ID);
$images = $details[0]['imgs'];
foreach($images as $i) {
$multi[] = $i['img']['url'];
}
$img = $images[0]['img']['url'];
$details = get_field('details', $post->ID);
$tags['og:description'] = esc_attr(wp_strip_all_tags($details[0]['description'], true));
} elseif(is_singular('dog') || is_singular('success')) {
$images = get_field('imgs', $post->ID);
foreach($images as $i) {
$multi[] = $i['img']['url'];
}
$img = $images[0]['img']['url'];
$tags['og:description'] = is_singular('dog') ? get_field('bio', $post->ID) : get_field('success', $post->ID);
$tags['twitter:card'] = 'summary_large_image';
$tags['twitter:description'] = $tags['og:description'];
$tags['twitter:image'] = $img;
} else {
$img = get_field('og', 'option');
}
$tags['og:image'][0] = $img;
if(isset($tags['twitter:card'])) {
$tags['twitter:site'] = '@'.$twitter_name;
}
return $tags;
}
add_filter('jetpack_open_graph_tags', 'custom_open_graph_tags', 10, 2);
function cfx_default_msg() {
return 'msg';
}
add_filter('wpas_default_message', 'cfx_default_msg');
function pre() {
return 'prefix';
}
add_filter('wpas_default_prefix', 'pre');
function suff() {
return 'suffix';
}
add_filter('wpas_default_suffix', 'suff');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment