Last active
August 27, 2019 21:46
-
-
Save marktenney/93eff61433f64360d0c85a1918867d57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Connect Cards | |
Plugin URI: https://digitalchurchplatform.com | |
Description: Enable the Connect Card Content Library. | |
Version: 2.0 | |
Author: Digital Church | |
Author URI: https://digitalchurchplatform.com | |
License: GPL2 | |
*/ | |
// Register Custom Post Type | |
function custom_post_type_connect_card() { | |
$labels = array( | |
'name' => _x( 'Connect Cards', 'Post Type General Name', 'text_domain' ), | |
'singular_name' => _x( 'Connect Card', 'Post Type Singular Name', 'text_domain' ), | |
'menu_name' => __( 'Connect Cards', 'text_domain' ), | |
'name_admin_bar' => __( 'Connect Card', 'text_domain' ), | |
'archives' => __( 'Connect Card Archives', 'text_domain' ), | |
'attributes' => __( 'Connect Card Attributes', 'text_domain' ), | |
'parent_item_colon' => __( 'Parent Connect Card:', 'text_domain' ), | |
'all_items' => __( 'All Connect Cards', 'text_domain' ), | |
'add_new_item' => __( 'Add New Connect Card', 'text_domain' ), | |
'add_new' => __( 'Add New', 'text_domain' ), | |
'new_item' => __( 'New Connect Card', 'text_domain' ), | |
'edit_item' => __( 'Edit Connect Card', 'text_domain' ), | |
'update_item' => __( 'Update Connect Card', 'text_domain' ), | |
'view_item' => __( 'View Connect Card', 'text_domain' ), | |
'view_items' => __( 'View Connect Cards', 'text_domain' ), | |
'search_items' => __( 'Search Connect Cards', 'text_domain' ), | |
'not_found' => __( 'Not found', 'text_domain' ), | |
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ), | |
'featured_image' => __( 'Featured Image', 'text_domain' ), | |
'set_featured_image' => __( 'Set featured image', 'text_domain' ), | |
'remove_featured_image' => __( 'Remove featured image', 'text_domain' ), | |
'use_featured_image' => __( 'Use as featured image', 'text_domain' ), | |
'insert_into_item' => __( 'Insert into Connect Card', 'text_domain' ), | |
'uploaded_to_this_item' => __( 'Uploaded to this Connect Card', 'text_domain' ), | |
'items_list' => __( 'Connect Cards list', 'text_domain' ), | |
'items_list_navigation' => __( 'Connect Cards list navigation', 'text_domain' ), | |
'filter_items_list' => __( 'Filter Connect Cards list', 'text_domain' ), | |
); | |
$args = array( | |
'label' => __( 'Connect Card', 'text_domain' ), | |
'description' => __( 'Connect Card Description', 'text_domain' ), | |
'labels' => $labels, | |
'supports' => array( 'title', 'editor', 'page-attributes' ), | |
'taxonomies' => array( 'category', 'post_tag' ), | |
'hierarchical' => false, | |
'public' => true, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'menu_position' => 5, | |
'menu_icon' => 'dashicons-screenoptions', | |
'show_in_admin_bar' => true, | |
'show_in_nav_menus' => true, | |
'can_export' => true, | |
'has_archive' => false, | |
'exclude_from_search' => false, | |
'publicly_queryable' => true, | |
'capability_type' => 'page', | |
); | |
register_post_type( 'connections', $args ); | |
} | |
add_action( 'init', 'custom_post_type_connect_card', 0 ); | |
add_post_type_support( 'connections', 'thumbnail' ); post_type_supports( 'connections', 'thumbnail' ); | |
/** add order column to admin listing screen for CPT <-- Did we do this because of the drag and drop sorting? **/ | |
function add_new_connect_card_column($connect_card_columns) { | |
$connect_card_columns['menu_order'] = "Order"; | |
return $connect_card_columns; | |
} | |
add_action('manage_edit-connect_card_columns', 'add_new_connect_card_column'); | |
/** show custom order column values **/ | |
function show_order_column($name){ | |
global $post; | |
switch ($name) { | |
case 'menu_order': | |
$order = $post->menu_order; | |
echo $order; | |
break; | |
default: | |
break; | |
} | |
} | |
add_action('manage_connect_card_posts_custom_column','show_order_column'); | |
/** make column sortable **/ | |
function order_column_register_sortable($columns){ | |
$columns['menu_order'] = 'menu_order'; | |
return $columns; | |
} | |
add_filter('manage_edit-connect_card_sortable_columns','order_column_register_sortable'); | |
/** Add Custom Fields to the Post Type **/ | |
add_filter( 'rwmb_meta_boxes', 'dgtl_connect_cards_register_meta_boxes' ); | |
function dgtl_connect_cards_register_meta_boxes( $meta_boxes ) { | |
if ( class_exists('GFForms') ) { | |
// AllFormsTable.php Line: 114 | |
$forms = RGFormsModel::get_forms( 1, 'title' ); | |
$key = array(); | |
$value = array(); | |
foreach ( $forms as $form ) : | |
$key[] = absint( $form->id ); | |
$value[] = esc_html( $form->title ); | |
endforeach; | |
$option = array_combine($key, $value); | |
} else { | |
$option = array('no_forms' => 'ACTIVATE FORM PLUGIN!!'); | |
} | |
$meta_boxes[] = array ( | |
'title' => 'Connect Card', | |
'id' => 'connect-card', | |
'post_types' => array( | |
0 => 'connections', | |
), | |
'context' => 'normal', | |
'priority' => 'high', | |
'fields' => array( | |
array ( | |
'id' => 'cc_cover_photo', | |
'type' => 'single_image', | |
'name' => 'Cover Photo', | |
'tooltip' => 'This cover photo will serve as a background image for the connect card. Featured Image will be used if a cover image is not set.', | |
), | |
array ( | |
'id' => 'dgtl_cc_excerpt', | |
'type' => 'text', | |
'name' => 'Short Description', | |
'tooltip' => 'This description can be displayed on the connect card for this connection as well as in the header of the single connection under the title.', | |
), | |
array ( | |
'id' => 'cc_call_to_action', | |
'name' => 'Call to Action', | |
'type' => 'button_group', | |
'std' => 'None', | |
'options' => array( | |
'None' => 'None', | |
'Button' => 'Button', | |
'Form' => 'Form', | |
'Redirect' => 'Redirect', | |
'Latest' => 'Latest', | |
), | |
'inline' => 1, | |
), | |
array ( | |
'id' => 'cc_button_text', | |
'type' => 'text', | |
'name' => 'Button Text', | |
'visible' => array( | |
'when' => array( | |
array ( | |
0 => 'cc_call_to_action', | |
1 => '=', | |
2 => 'Button', | |
), | |
), | |
'relation' => 'and', | |
), | |
), | |
array ( | |
'id' => 'cc_button_url', | |
'type' => 'text', | |
'name' => 'Button URL', | |
'visible' => array( | |
'when' => array( | |
array ( | |
0 => 'cc_call_to_action', | |
1 => '=', | |
2 => 'Button', | |
), | |
), | |
'relation' => 'and', | |
), | |
), | |
array( | |
'name' => 'Select a Form', | |
'id' => 'cc_gravity_form', | |
'type' => 'select_advanced', | |
'options' => $option, | |
'multiple' => false, | |
'placeholder' => 'Select a Form', | |
'visible' => array( | |
'when' => array( | |
array ( | |
0 => 'cc_call_to_action', | |
1 => '=', | |
2 => 'Form', | |
), | |
), | |
'relation' => 'and', | |
) | |
), | |
array ( | |
'id' => 'cc_redirect_url', | |
'type' => 'text', | |
'name' => 'Redirect URL', | |
'admin_columns' => 'replace categories', | |
'visible' => array( | |
'when' => array( | |
array ( | |
0 => 'cc_call_to_action', | |
1 => '=', | |
2 => 'Redirect', | |
), | |
), | |
'relation' => 'and', | |
), | |
), | |
array ( | |
'id' => 'cc_latest_post_type', | |
'type' => 'select', | |
'options' => array( | |
//'post' => 'Blog Post', | |
'sermon' => 'Sermon', | |
), | |
'name' => 'Post Type', | |
'admin_columns' => 'replace categories', | |
'visible' => array( | |
'when' => array( | |
array ( | |
0 => 'cc_call_to_action', | |
1 => '=', | |
2 => 'Latest', | |
), | |
), | |
'relation' => 'and', | |
), | |
) | |
), | |
); | |
return $meta_boxes; | |
} | |
/**** Add a Shortcode to Display Form [form-connect] ****/ | |
function dgtl_form_connect($atts, $content=null){ | |
$gravity_form = rwmb_meta("cc_gravity_form"); | |
return do_shortcode('[gravityform id=' . $gravity_form . ' title="false" description="false"]'); | |
} | |
add_shortcode('form-connect', 'dgtl_form_connect'); | |
/**** Redirect to URL if Redirect is set****/ | |
function build_connect_card_redirect(){ | |
if( is_single() && get_post_type()=='connections' ){ | |
if( get_field('cc_call_to_action', $curauth) == 'Redirect' ): | |
$redirect_link = get_field('cc_redirect_url'); | |
wp_redirect($redirect_link); | |
exit; | |
endif; | |
} | |
} | |
add_action('wp_enqueue_scripts', 'build_connect_card_redirect'); | |
/** Redirect if the latest post field is true **/ | |
function build_connect_card_latest(){ | |
if( is_single() && get_post_type()=='connections' ){ | |
if( get_field('cc_call_to_action', $curauth) == 'Latest' ): | |
//$posttype = get_field('cc_latest_post_type'); | |
$getpost = get_posts( array( | |
'number' => 1, | |
'post_type' => get_field('cc_latest_post_type'), | |
) | |
); | |
$getpost = $getpost[0]; | |
$link = get_post_permalink($getpost->ID); | |
wp_redirect($link); | |
exit; | |
endif; | |
} | |
} | |
add_action('wp_enqueue_scripts', 'build_connect_card_latest'); | |
/*** END ***/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment