add campaign tracking plugin
This commit is contained in:
142
wp/wp-content/plugins/campaign-tracking/lib/CptCampaign.php
Normal file
142
wp/wp-content/plugins/campaign-tracking/lib/CptCampaign.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
if(!class_exists('CptCampaign')) {
|
||||
|
||||
class CptCampaign
|
||||
{
|
||||
//cpt info
|
||||
const POST_TYPE = "campaign";
|
||||
const NAME = "Campaign";
|
||||
const SINGLE_NAME = "Campaign";
|
||||
const DESCRIPTION = "Post type for Campaign";
|
||||
const QUERY_VAR = "campaign";
|
||||
|
||||
//meta key
|
||||
const kMETA_CAMPAIGN_ID = "campaign_id";
|
||||
const kMETA_CAMPAIGN_START_DATE = "campaign_start_date";
|
||||
const kMETA_CAMPAIGN_END_DATE = "campaign_end_date";
|
||||
const kMETA_CAMPAIGN_PHONE = "campaign_phone_number";
|
||||
const kMETA_CAMPAIGN_SHORT_URL = "campaign_short_url";
|
||||
const kMETA_CAMPAIGN_LANDING_URL = "campaign_landing_url";
|
||||
const kMETA_CAMPAIGN_NAME = "campaign_name";
|
||||
const kMETA_DELETE = "to_delete";
|
||||
const kMETA_FIVE9 = "Five9CallbackCampaign";
|
||||
|
||||
|
||||
|
||||
|
||||
//meta array
|
||||
private $_meta = array(
|
||||
array('name'=>self::kMETA_CAMPAIGN_ID,'type'=>'input-text','title'=>'Campaign ID'),
|
||||
array('name'=>self::kMETA_CAMPAIGN_NAME,'type'=>'input-text','title'=>'Campaign name'),
|
||||
array('name'=>self::kMETA_CAMPAIGN_START_DATE,'type'=>'input-date','title'=>'Start date'),
|
||||
array('name'=>self::kMETA_CAMPAIGN_END_DATE,'type'=>'input-date','title'=>'End date'),
|
||||
array('name'=>self::kMETA_CAMPAIGN_PHONE,'type'=>'input-text','title'=>'Phone number'),
|
||||
array('name'=>self::kMETA_CAMPAIGN_SHORT_URL,'type'=>'input-text','title'=>'Friendly URL'),
|
||||
array('name'=>self::kMETA_CAMPAIGN_LANDING_URL,'type'=>'input-text','title'=>'Landing URL'),
|
||||
array('name'=>self::kMETA_FIVE9,'type'=>'input-text','title'=>'Five9 Callback Campaign'),
|
||||
|
||||
|
||||
);
|
||||
|
||||
public function __construct(){
|
||||
add_action('init', array(&$this, 'init'));
|
||||
add_action('admin_init', array(&$this, 'admin_init'));
|
||||
//add_action('admin_print_scripts', array(&$this,'load_custom_wp_admin_script') );
|
||||
add_filter('single_template',array(&$this,'single_template'));
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->create_post_type();
|
||||
add_action('save_post', array(&$this, 'save_post'));
|
||||
}
|
||||
|
||||
|
||||
public function admin_init(){
|
||||
|
||||
add_action('add_meta_boxes', array(&$this, 'add_meta_boxes'));
|
||||
}
|
||||
|
||||
public function add_meta_boxes(){
|
||||
add_meta_box(
|
||||
sprintf('campaign_plugin_%s_section', self::POST_TYPE),
|
||||
'Info',
|
||||
array(&$this, 'add_inner_meta_boxes'),
|
||||
self::POST_TYPE
|
||||
);
|
||||
}
|
||||
|
||||
public function add_inner_meta_boxes($post){
|
||||
|
||||
include(sprintf("%s/templates/%s-metabox.php",kCampaignPath, self::POST_TYPE));
|
||||
}
|
||||
|
||||
public function create_post_type(){
|
||||
|
||||
$labels = array(
|
||||
'name' => __("Campaigns"),
|
||||
'singular_name' => __("Campaign"),
|
||||
'menu_name' => __("Campaigns"),
|
||||
'name_admin_bar' => __("Campaign"),
|
||||
'add_new_item' => __( 'Add New Campaign'),
|
||||
'new_item' => __( 'New Campaign'),
|
||||
'edit_item' => __( 'Edit Campaign' ),
|
||||
'view_item' => __( 'View Campaign' ),
|
||||
'all_items' => __( 'All Campaigns' ),
|
||||
'search_items' => __( 'Search Campaigns'),
|
||||
'parent_item_colon' => __( 'Parent Campaigns:' ),
|
||||
'not_found' => __( 'No campaigns found.'),
|
||||
'not_found_in_trash' => __( 'No campaigns found in Trash.' )
|
||||
);
|
||||
|
||||
register_post_type(self::POST_TYPE,
|
||||
array(
|
||||
'labels' =>$labels,
|
||||
'public' => true,
|
||||
'has_archive' => false,
|
||||
'description' => self::DESCRIPTION,
|
||||
'supports' => array(
|
||||
'title', 'editor',
|
||||
),
|
||||
'hierarchical' => false,
|
||||
'menu_position'=> 9,
|
||||
'query_var' => self::QUERY_VAR,
|
||||
'rewrite' => array( 'slug' => '/'.self::POST_TYPE, 'with_front' => false )
|
||||
// 'rewrite' => array( 'slug' => self::POST_TYPE )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function single_template($single_template){
|
||||
global $post;
|
||||
$found = locate_template('single-'.self::POST_TYPE.'.php');
|
||||
if($post->post_type == self::POST_TYPE && $found == ''){
|
||||
$single_template = kCampaignPath.'/templates/single-'.self::POST_TYPE.'.php';
|
||||
}
|
||||
|
||||
return $single_template;
|
||||
}
|
||||
|
||||
public function rewrite_flush() {
|
||||
$this->create_post_type();
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
public function save_post($post_id){
|
||||
|
||||
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(isset($_POST['post_type']) && $_POST['post_type'] == self::POST_TYPE && current_user_can('edit_post', $post_id))
|
||||
{
|
||||
foreach($this->_meta as $field)
|
||||
{
|
||||
// Update the post's meta field
|
||||
if (isset($_POST[$field['name']]))
|
||||
update_post_meta($post_id, $field['name'], $_POST[$field['name']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user