Created
January 15, 2022 00:47
-
-
Save pstoute/aacd8447addcc3336051e7f90e79deda to your computer and use it in GitHub Desktop.
Add a custom post type to your WordPress site to add the functionality for Funnel Packs as a Post Type. This does require Metabox.io FREE to function but you could replicate the same process using ACF or any other method.
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: Stoute Funnels | |
* Description: Adds the custom post type and metabox.io fields for funnelpacks.com funnels. Plugin requires the metabox.io free plugin. | |
* Version: 1.0.12 | |
* Author: Paul Stoute | |
* Author URI: https://paulstoute.com | |
* Text Domain: stoute_funnel | |
**/ | |
/** | |
* Register the CPT for the Funnels | |
* Since @1.0.8 | |
**/ | |
add_action( 'init', 'stoute_funnel_register_post_type' ); | |
function stoute_funnel_register_post_type() { | |
$args = [ | |
'label' => esc_html__( 'Funnels', 'stoute_funnel' ), | |
'labels' => [ | |
'menu_name' => esc_html__( 'Funnels', 'stoute_funnel' ), | |
'name_admin_bar' => esc_html__( 'Funnel', 'stoute_funnel' ), | |
'add_new' => esc_html__( 'Add Funnel', 'stoute_funnel' ), | |
'add_new_item' => esc_html__( 'Add new Funnel', 'stoute_funnel' ), | |
'new_item' => esc_html__( 'New Funnel', 'stoute_funnel' ), | |
'edit_item' => esc_html__( 'Edit Funnel', 'stoute_funnel' ), | |
'view_item' => esc_html__( 'View Funnel', 'stoute_funnel' ), | |
'update_item' => esc_html__( 'View Funnel', 'stoute_funnel' ), | |
'all_items' => esc_html__( 'All Funnels', 'stoute_funnel' ), | |
'search_items' => esc_html__( 'Search Funnels', 'stoute_funnel' ), | |
'parent_item_colon' => esc_html__( 'Parent Funnel', 'stoute_funnel' ), | |
'not_found' => esc_html__( 'No Funnels found', 'stoute_funnel' ), | |
'not_found_in_trash' => esc_html__( 'No Funnels found in Trash', 'stoute_funnel' ), | |
'name' => esc_html__( 'Funnels', 'stoute_funnel' ), | |
'singular_name' => esc_html__( 'Funnel', 'stoute_funnel' ), | |
], | |
'public' => true, | |
'exclude_from_search' => true, | |
'publicly_queryable' => true, | |
'show_ui' => true, | |
'show_in_nav_menus' => true, | |
'show_in_admin_bar' => true, | |
'show_in_rest' => true, | |
'capability_type' => 'post', | |
'hierarchical' => false, | |
'has_archive' => true, | |
'query_var' => true, | |
'can_export' => true, | |
'rewrite_no_front' => false, | |
'show_in_menu' => true, | |
'menu_position' => 20, | |
'menu_icon' => 'dashicons-editor-contract', | |
'supports' => [ | |
'title', | |
'thumbnail', | |
'editor', | |
'revisions', | |
], | |
'taxonomies' => [ | |
'category', | |
], | |
'rewrite' => [ 'slug' => 'fun', ] | |
]; | |
register_post_type( 'funnel', $args ); | |
} | |
/** | |
* Add the metabox info for the Funnels CPT | |
* Since @1.0.12 | |
**/ | |
add_filter( 'rwmb_meta_boxes', 'stoute_funnel_register_meta_boxes' ); | |
function stoute_funnel_register_meta_boxes( $meta_boxes ) { | |
$prefix = 'funnel_'; | |
$meta_boxes[] = [ | |
'title' => esc_html__( 'Funnel Settings', 'stoute_funnel' ), | |
'id' => 'funnel_meta', | |
'post_types' => 'funnel', | |
'context' => 'normal', | |
'autosave' => true, | |
'fields' => [ | |
[ | |
'type' => 'heading', | |
'name' => esc_html__( 'Hero Section', 'stoute_funnel' ), | |
], | |
[ | |
'type' => 'text', | |
'name' => esc_html__( 'Hero Headline', 'stoute_funnel' ), | |
'id' => $prefix . 'hero_headline', | |
], | |
[ | |
'type' => 'textarea', | |
'name' => esc_html__( 'Hero Subheading', 'stoute_funnel' ), | |
'id' => $prefix . 'hero_subheading', | |
], | |
[ | |
'type' => 'text', | |
'name' => esc_html__( 'Call to Action Button Text', 'stoute_funnel' ), | |
'id' => $prefix . 'call_to_action_button_text', | |
'std' => 'SEND ME MY FREE GUIDE', | |
], | |
[ | |
'type' => 'divider', | |
], | |
[ | |
'type' => 'heading', | |
'name' => esc_html__( 'Body Section', 'stoute_funnel' ), | |
], | |
[ | |
'type' => 'text', | |
'name' => esc_html__( 'Body Headline', 'stoute_funnel' ), | |
'id' => $prefix . 'body_headline', | |
], | |
[ | |
'type' => 'wysiwyg', | |
'name' => esc_html__( 'Body Copy', 'stoute_funnel' ), | |
'id' => $prefix . 'body_copy', | |
], | |
[ | |
'type' => 'text', | |
'name' => esc_html__( 'Bullet Point #1', 'stoute_funnel' ), | |
'id' => $prefix . 'bullet_point_1', | |
], | |
[ | |
'type' => 'text', | |
'name' => esc_html__( 'Bullet Point #2', 'stoute_funnel' ), | |
'id' => $prefix . 'bullet_point_2', | |
], | |
[ | |
'type' => 'text', | |
'name' => esc_html__( 'Bullet Point #3', 'stoute_funnel' ), | |
'id' => $prefix . 'bullet_point_3', | |
], | |
[ | |
'type' => 'text', | |
'name' => esc_html__( 'Bullet Point #4', 'stoute_funnel' ), | |
'id' => $prefix . 'bullet_point_4', | |
], | |
[ | |
'type' => 'text', | |
'name' => esc_html__( 'Bullet Point #5', 'stoute_funnel' ), | |
'id' => $prefix . 'bullet_point_5', | |
], | |
[ | |
'type' => 'text', | |
'name' => esc_html__( 'Bullet Point #6', 'stoute_funnel' ), | |
'id' => $prefix . 'bullet_point_6', | |
], | |
[ | |
'type' => 'divider', | |
], | |
[ | |
'type' => 'heading', | |
'name' => esc_html__( 'Popup Modal Section', 'stoute_funnel' ), | |
], | |
[ | |
'type' => 'text', | |
'name' => esc_html__( 'Popup Headline', 'stoute_funnel' ), | |
'id' => $prefix . 'popup_headline', | |
], | |
[ | |
'type' => 'textarea', | |
'name' => esc_html__( 'Popup Sub-text', 'stoute_funnel' ), | |
'id' => $prefix . 'popup_sub-text', | |
'rows' => 3, | |
], | |
[ | |
'type' => 'text', | |
'name' => esc_html__( 'Popup Footer Text', 'stoute_funnel' ), | |
'id' => $prefix . 'popup_footer_text', | |
'std' => 'We hate SPAM and promise to keep your email address safe. Here’s our privacy policy.', | |
], | |
[ | |
'type' => 'divider', | |
], | |
[ | |
'type' => 'heading', | |
'name' => esc_html__( 'Fluent Form Section', 'stoute_funnel' ), | |
], | |
[ | |
'type' => 'text', | |
'name' => esc_html__( 'Fluent Form Data', 'stoute_funnel' ), | |
'id' => $prefix . 'fluent_form_id', | |
'desc' => esc_html__( 'Enter the unique slug for this ebook request.', 'stoute_funnel' ), | |
], | |
], | |
]; | |
return $meta_boxes; | |
} | |
/** | |
* Add Fluent Forms Custom Smart Code | |
* Since @1.0.11 | |
**/ | |
add_filter('fluentform_editor_shortcodes', function ($smartCodes) { | |
$smartCodes[0]['shortcodes']['{stoute_funnels_form_data}'] = 'Funnel Form Data'; | |
return $smartCodes; | |
}); | |
add_filter('fluentform_editor_shortcode_callback_stoute_funnels_form_data', function ($value, $form) { | |
$dynamicValue = get_post_meta( get_the_ID(), 'funnel_fluent_form_id', true ); | |
return $dynamicValue; | |
}, 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment