MP_Addon_SMS_Leads
Class Leads.
Source Source
File: calculator-sms-add-on/inc/MP_Addon_SMS_Leads.php
class MP_Addon_SMS_Leads {
/**
* Lead Call Metabox.
*
* @since 1.0.0
* @access public
*
* @param mixed $post post
*
* @return mixed
*/
public function lead_sms( $post ) {
$phone = get_post_meta( $post->ID, MortgagePlatform::$prefix . 'lead_phone' ) ? get_post_meta( $post->ID, MortgagePlatform::$prefix . 'lead_phone', true ) : null;
$send_sms = isset( get_option( MortgagePlatform::$prefix . 'sms' )['send_sms_to_user'] ) ? get_option( MortgagePlatform::$prefix . 'sms' )['send_sms_to_user'] : false;
if ( $send_sms && $phone ) { ?>
<script>
if (jQuery('.send_message_tabs')) {
$tab = '<li data-tab="send_message_tab_phone"><?php esc_html_e( 'Send SMS', 'CalculatorSMSAddon' ); ?></li>';
jQuery('.send_message_tabs').append($tab);
}
</script>
<div class="send_message__wrapper" id="send_message_tab_phone">
<div class="sms_chat">
<?php
$sms = get_post_meta( $post->ID, MortgagePlatform::$prefix . 'sms' );
$user_name = get_post_meta( $post->ID, MortgagePlatform::$prefix . 'lead_first_name', true ) . ' ' . get_post_meta( $post->ID, MortgagePlatform::$prefix . 'lead_second_name', true );
foreach ( $sms as $message ) {
?>
<div class="sms_chat__<?php echo esc_attr( $message['from'] ); ?>">
<span class="sms_chat__name">
<?php
if ( 'user' === $message['from'] ) {
echo esc_attr( $user_name );
} else {
echo esc_attr( ucfirst( $message['from'] ) );
}
?>
</span>
<span class="sms_chat__date"><?php echo esc_attr( $message['date'] ); ?></span>
<p><?php echo esc_attr( $message['body'] ); ?></p>
</div>
<?php } ?>
</div>
<label><?php esc_html_e( 'Text SMS', 'CalculatorSMSAddon' ); ?>
<textarea name="send_message_phone_text" rows="5"></textarea>
</label>
<input type="hidden" name="send_message_phone" value="<?php echo esc_attr( $phone ); ?>">
<button data-leadid="<?php echo esc_attr( $post->ID ); ?>" id="send_sms_lead"
data-leadid="<?php echo esc_attr( $post->ID ); ?>"
class="button send_message_lead__button"><?php echo esc_html__( 'Send SMS', 'CalculatorSMSAddon' ); ?></button>
</div>
<?php
}
return $post;
}
/**
* Update status SMS on read.
*
* @since 1.0.0
* @access public
*
* @param int|string $post_id post id
*
* @return int|bool Meta ID if the key didn't exist, true on successful update,
* false on failure or if the value passed to the function
* is the same as the one that is already in the database.
*/
public function update_sms_status( $post_id ) {
wp_cache_delete('sms_addon_phone', MortgagePlatform::$domain);
return update_post_meta( $post_id, MortgagePlatform::$prefix . 'sms_status', false, '' );
}
/**
* Function sort by new SMS for lead.
*
* @since 1.0.0
* @access public
*
* @param mixed $object
*/
public function sort_by_sms_status( $object ) {
if ( 'sort_' . MortgagePlatform::$prefix . 'sms_status' !== $object->get( 'orderby' ) ) {
return;
}
$object->set( 'meta_key', MortgagePlatform::$prefix . 'sms_status' );
$object->set( 'orderby', 'meta_value' );
}
/***** Lead Page Columns *****/
/**
* Set lead columns.
*
* @since 1.0.0
* @access public
*
* @param array $columns columns
*
* @return array
*/
public function add_leads_table_column( $columns ) {
$my_columns = array(
MortgagePlatform::$prefix . 'sms_status' => '<img style="width:10px;" src="' . plugins_url( '../assets/img/dot.svg', __FILE__ ) . '" title="' . __( 'New SMS', 'CalculatorSMSAddon' ) . '"">',
);
return array_slice( $columns, 0, 2 ) + $my_columns + $columns;
}
/**
* Get data from lead to lead columns.
*
* @since 1.0.0
* @access public
*
* @param string $column_name column name
* @param int|string $post_ID post id
*/
public function get_leads_table_column( $column_name, $post_ID ) {
if ( MortgagePlatform::$prefix . 'sms_status' === $column_name ) {
if ( get_post_meta( $post_ID, MortgagePlatform::$prefix . 'sms_status', true ) ) {
echo '<img style="width:10px;" src="' . esc_url( plugins_url( '../assets/img/dot.svg', __FILE__ ) ) . '" title="' . esc_html__( 'New SMS', 'CalculatorSMSAddon' ) . '"">';
}
}
}
/**
* Sortable lead columns function.
*
* @since 1.0.0
* @access public
*
* @param array $sortable_columns columns
*
* @return mixed
*/
public function add_sortable_column( $sortable_columns ) {
$sortable_columns[ MortgagePlatform::$prefix . 'sms_status' ] = array( 'sort_' . MortgagePlatform::$prefix . 'sms_status', false ); // false = asc (default), true = desc
return $sortable_columns;
}
/**
* Set styles for columns lead.
*
* @since 1.0.0
* @access public
*/
public function style_lead_table() {
echo '<style>#' . esc_attr( MortgagePlatform::$prefix ) . 'sms_status { width: 45px }</style>';
}
}
Methods Methods
- add_leads_table_column — Set lead columns.
- add_sortable_column — Sortable lead columns function.
- get_leads_table_column — Get data from lead to lead columns.
- lead_sms — Lead Call Metabox.
- sort_by_sms_status — Function sort by new SMS for lead.
- style_lead_table — Set styles for columns lead.
- update_sms_status — Update status SMS on read.
Changelog Changelog
| Version | Description |
|---|---|
| 1.0.0 | Introduced. |