type = 'sale';
// Before data updates
add_action( 'pre_post_update', array( $this, 'pre_post_update' ) );
add_filter( 'wp_insert_post_data', array( $this, 'wp_insert_post_data' ) );
// Admin Columns
add_filter( 'manage_edit-sale_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sale_posts_custom_column', array( $this, 'custom_columns' ), 2 );
add_filter( 'list_table_primary_column', array( $this, 'set_primary_column' ), 10, 2 );
add_filter( 'post_row_actions', array( $this, 'remove_actions' ), 10, 2 );
add_filter( 'manage_edit-sale_sortable_columns', array( $this, 'custom_columns_sort' ) );
add_filter( 'request', array( $this, 'custom_columns_orderby' ) );
// Bulk / quick edit
add_filter( 'bulk_actions-edit-sale', array( $this, 'remove_bulk_actions') );
/*add_action( 'bulk_edit_custom_box', array( $this, 'bulk_edit' ), 10, 2 );
add_action( 'quick_edit_custom_box', array( $this, 'quick_edit' ), 10, 2 );
add_action( 'save_post', array( $this, 'bulk_and_quick_edit_save_post' ), 10, 2 );*/
// Call PH_Admin_CPT constructor
parent::__construct();
}
/**
* Check if we're editing or adding a sale
* @return boolean
*/
private function is_editing_sale() {
if ( ! empty( $_GET['post_type'] ) && 'sale' == $_GET['post_type'] ) {
return true;
}
if ( ! empty( $_GET['post'] ) && 'sale' == get_post_type( (int)$_GET['post'] ) ) {
return true;
}
if ( ! empty( $_REQUEST['post_id'] ) && 'sale' == get_post_type( (int)$_REQUEST['post_id'] ) ) {
return true;
}
return false;
}
/**
* @param int $post_id
*/
public function pre_post_update( $post_id ) {
}
/**
* @param array $data
* @return array
*/
public function wp_insert_post_data( $data ) {
return $data;
}
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
if ( empty( $existing_columns ) && ! is_array( $existing_columns ) ) {
$existing_columns = array();
}
unset( $existing_columns['title'], $existing_columns['comments'], $existing_columns['date'] );
$columns = array();
$columns['cb'] = '';
$columns['sale_date_time'] = __( 'Sale Date', 'propertyhive' );
$columns['property'] = __( 'Property', 'propertyhive' );
$columns['property_owner'] = __( 'Property Owner', 'propertyhive' );
$columns['applicant'] = __( 'Applicant(s)', 'propertyhive' );
$columns['amount'] = __( 'Amount', 'propertyhive' );
$columns['status'] = __( 'Status', 'propertyhive' );
return array_merge( $columns, $existing_columns );
}
/**
* Define our custom columns shown in admin.
* @param string $column
*/
public function custom_columns( $column ) {
global $post, $propertyhive, $the_sale;
if ( empty( $the_sale ) || $the_sale->ID != $post->ID )
{
$the_sale = new PH_Sale( $post->ID );
}
switch ( $column ) {
case 'sale_date_time' :
$edit_link = get_edit_post_link( $post->ID );
//$title = _draft_or_post_title();
$title = date("jS F Y", strtotime($the_sale->sale_date_time));
$post_type_object = get_post_type_object( $post->post_type );
$can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );
echo '' . esc_html($title) . '';
break;
case 'property' :
if ( $the_sale->property_id != '' )
{
$property = new PH_Property((int)$the_sale->property_id);
echo esc_html($property->get_formatted_full_address());
}
else
{
echo '-';
}
break;
case 'property_owner' :
$the_property = new PH_Property((int)$the_sale->property_id);
$owner_contact_ids = $the_property->_owner_contact_id;
if (
( !is_array($owner_contact_ids) && $owner_contact_ids != '' && $owner_contact_ids != 0 )
||
( is_array($owner_contact_ids) && !empty($owner_contact_ids) )
)
{
if ( !is_array($owner_contact_ids) )
{
$owner_contact_ids = array($owner_contact_ids);
}
foreach ( $owner_contact_ids as $owner_contact_id )
{
echo esc_html(get_the_title($owner_contact_id)) . '
';
if ( count($owner_contact_ids) == 1 )
{
echo '