MP_Addon_CalculatorsCallRail_Settings
Source Source
File: calculator-callrail-add-on/inc/MP_Addon_CalculatorsCallRail_Settings.php
class MP_Addon_CalculatorsCallRail_Settings{
/**
* CallRail settings.
* @var array callrail settings
* @since 1.0.0
* @access private
*/
private $settings;
/**
* Set Call Rail Settings.
* @since 1.0.0
* @access private
* @return array {
*
* Call Rail settings.
*
* @type array 'callrail_webhook' Webhook
* }
*/
private function set_settings() {
$this->settings = array(
array(
'id' => 'callrail_webhook',
'title' => __( 'Call Rail webhook', 'CalculatorsCallRailAddon' ),
'callback' => array( $this, 'callrail_webhook' ),
'args' => array(
'option_name' => MortgagePlatform::$prefix .'leads',
'label_for' => 'callrail_webhook',
'value' => admin_url('admin-ajax.php').'?action=callrail_webhook',
'description' => __( 'Use this webhook in your callrail account to receive data from callrail.com. Add this web hook to the callrail.сom setting page as Pre-Call, Post-Call and Call Modified.', 'CalculatorsCallRailAddon' ),
),
),
);
return $this->settings;
}
/**
* Callback callrail_webhook function.
*
* @since 1.0.0
* @access public
*
* @param array $args array of arguments
*/
public function callrail_webhook($args){
$name = $args['label_for'];
$option_name = $args['option_name'];
$value = $args['value'];
$description = $args['description'];
echo '<code id="' . esc_attr( $name ) . '" name="' . esc_attr( $option_name ) . '[' . esc_attr( $name ) . ']">' . esc_attr( $value ) . '</code>';
echo '<p>' . esc_html($description) . '</p>';
}
/**
* Settings.
*
* @since 1.0.0
* @access public
*
* @param array $array leads settings
*
* @return mixed contact settings
*/
public function filter_contact_settings( $array ) {
$settings = $this->set_settings();
return array_merge( $array, $settings );
}
/**
* Register callrail metabox.
*
* @access public
* @since 1.0.0
*/
public function register_callrail_metabox() {
add_meta_box(
'lead_callrail',
__( 'Call rail', 'CalculatorsCallRailAddon' ),
array( $this, 'callrail_callback' ),
array( MortgagePlatform::$lead, MortgagePlatform::$abandoned_lead ),
'normal',
'core'
);
}
/**
* Callrail metabox callback function.
*
* @access public
* @since 1.0.0
*
* @param array $post post data
*/
public function callrail_callback( $post ) {
$callrail_posts = get_post_meta( $post->ID, MortgagePlatform::$prefix . 'lead_callrail', false );
foreach($callrail_posts as $posts){
if(is_array($posts)){
foreach ($posts as $post){
$callrail = $this->get_callrail($post);
echo $callrail;
}
} else {
$callrail = $this->get_callrail($post);
echo $callrail;
}
}
}
/**
* Get Table with call rail data.
*
* @access protected
* @since 1.0.0
*
* @param string $post Callrail Post ID
*
* @return string HTML table
*/
protected function get_callrail($post){
$callrail = get_post_meta( $post, MortgagePlatform::$prefix . 'callrail', true );
$calls = array_reverse(get_post_meta( $post, MortgagePlatform::$prefix . 'callrail_calls', false ));
$callrail = array(
array(
'name'=>__( 'Name', 'CalculatorsCallRailAddon' ),
'value'=> $callrail['formatted_customer_name']
),
array(
'name'=>__( 'Phone', 'CalculatorsCallRailAddon' ),
'value'=>$callrail['customer_phone_number']
),
array(
'name'=>__( 'Location', 'CalculatorsCallRailAddon' ),
'value'=>$callrail['formatted_customer_location']
),
array(
'name'=>__( 'IP', 'CalculatorsCallRailAddon' ),
'value'=>$callrail['ip']
),
array(
'name'=>__( 'Total calls', 'CalculatorsCallRailAddon' ),
'value'=>$callrail['total_calls']
),
);
$table = '<table class="lead_table" cellpadding="0" cellspacing="0">';
foreach ( $callrail as $key=>$data ) {
$value = (0 === $key) ? '<a href="'.esc_url(get_edit_post_link( $post )).'">' . $data['value'].'</a>' : esc_attr( $data['value']);
$table .= '<tr class="lead_table_row">
<td class="lead_table_label">' . esc_attr( $data['name']). '</td>
<td style="padding: 0;" class="lead_table_value">'. $value .'</td>
</tr>';
}
foreach ( $calls as $call ) {
$table .= '<tr class="lead_table_row lead_table_heading" border="1">
<td class="lead_table_label">' . esc_attr__( 'Start time', 'CalculatorsCallRailAddon' ) . '</td>
<td class="lead_table_value">' . date_i18n('j F Y H:i',strtotime(esc_attr($call['start_time']))) . '</td>
</tr>';
if (!empty($call['recording'])){
$call_value = '<audio controls>
<source src="'.esc_url($call['recording']).'" type="audio/mp3">
Your browser does not support the audio tag.
</audio>';
} else {
$call_value = '';
}
$table .= '<tr class="lead_table_row">
<td class="lead_table_label">' . esc_attr__( 'Recording', 'CalculatorsCallRailAddon' ) . '</td>
<td style="padding: 0;" class="lead_table_value">'. $call_value .'</td>
</tr>';
}
$table .= '</table>';
return $table;
}
}
Methods Methods
- callrail_callback — Callrail metabox callback function.
- callrail_webhook — Callback callrail_webhook function.
- filter_contact_settings — Settings.
- get_callrail — Get Table with call rail data.
- register_callrail_metabox — Register callrail metabox.
- set_settings — Set Call Rail Settings.
Changelog Changelog
| Version | Description |
|---|---|
| 1.0.0 | Introduced. |