';
case 'client_facebook':
return '';
case 'client_twitter':
return '';
case 'client_instagram':
return '';
case 'client_linkedin':
return '';
case 'contact_name':
return esc_html( $item[ $column_name ] );
default:
return $item[ $column_name ];
}
}
}
/**
* Get sortable columns.
*
* @return array $sortable_columns Array of sortable column names.
*/
public function get_sortable_columns() {
return array(
'client' => array( 'client', false ),
'name' => array( 'name', false ),
'client_email' => array( 'client_email', false ),
'suspended' => array( 'suspended', false ),
'tags' => array( 'tags', false ),
'websites' => array( 'websites', false ),
'contact_name' => array( 'contact_name', false ),
'address_1' => array( 'address_1', false ),
'address_2' => array( 'address_2', false ),
'city' => array( 'city', false ),
'zip' => array( 'zip', false ),
'state' => array( 'state', false ),
'created' => array( 'created', false ),
'country' => array( 'country', false ),
);
}
/**
* Gets default columns.
*
* @return array Array of default column names.
*/
public function get_default_columns() {
return array(
'cb' => '',
'image' => esc_html__( 'Image', 'mainwp' ),
'client' => esc_html__( 'Client', 'mainwp' ),
'suspended' => esc_html__( 'Status', 'mainwp' ),
'name' => esc_html__( 'Name', 'mainwp' ),
'tags' => esc_html__( 'Tags', 'mainwp' ),
'contact_name' => esc_html__( 'Primary Contact', 'mainwp' ),
'client_email' => esc_html__( 'Client Email', 'mainwp' ),
'client_phone' => '',
'client_facebook' => '',
'client_twitter' => '',
'client_instagram' => '',
'client_linkedin' => '',
'websites' => esc_html__( 'Websites', 'mainwp' ),
'address_1' => esc_html__( 'Address 1', 'mainwp' ),
'address_2' => esc_html__( 'Address 2', 'mainwp' ),
'city' => esc_html__( 'City', 'mainwp' ),
'zip' => esc_html__( 'Zip', 'mainwp' ),
'state' => esc_html__( 'State', 'mainwp' ),
'country' => esc_html__( 'Country', 'mainwp' ),
'created' => esc_html__( 'Added on', 'mainwp' ),
'notes' => esc_html__( 'Notes', 'mainwp' ),
);
}
/**
* Method get_columns()
*
* Combine all columns.
*
* @return array $columns Array of column names.
*/
public function get_columns() {
$columns = $this->get_default_columns();
/**
* Filter: mainwp_clients_sitestable_getcolumns
*
* Filters the Clients table columns. Allows user to create a new column.
*
* @param array $columns Array containing table columns.
*
* @since 4.1
*/
$columns = apply_filters( 'mainwp_clients_sitestable_getcolumns', $columns, $columns );
$columns['client_actions'] = '';
return $columns;
}
/**
* Instantiate Columns.
*
* @return array $init_cols
*/
public function get_columns_init() {
$cols = $this->get_columns();
$init_cols = array();
foreach ( $cols as $key => $val ) {
$init_cols[] = array( 'data' => esc_html( $key ) );
}
return $init_cols;
}
/**
* Method generate_tabletop()
*
* Run the render_manage_sites_table_top menthod.
*/
public function generate_tabletop() {
$this->render_manage_sites_table_top();
}
/**
* Create bulk actions drop down.
*
* @return array $actions Return actions through the mainwp_manageclients_bulk_actions filter.
*/
public function get_bulk_actions() {
$actions = array(
'delete' => esc_html__( 'Delete', 'mainwp' ),
);
/**
* Filter: mainwp_manageclients_bulk_actions
*
* Filters bulk actions on the Clients page. Allows user to hook in new actions or remove default ones.
*
* @since 4.1
*/
return apply_filters( 'mainwp_manageclients_bulk_actions', $actions );
}
/**
* Render manage sites table top.
*
* @uses \MainWP\Dashboard\MainWP_DB_Common::get_groups_for_manage_sites()
*/
public function render_manage_sites_table_top() {
$items_bulk = $this->get_bulk_actions();
$selected_group = isset( $_REQUEST['tags'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tags'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$default_filter = empty( $selected_group ) ? true : false;
?>
true,
'with_tags' => true,
);
if ( isset( $_GET['tags'] ) && ! empty( $_GET['tags'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$tags = sanitize_text_field( rawurldecode( wp_unslash( $_GET['tags'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if ( ! empty( $tags ) ) {
if ( false !== strpos( $tags, ',' ) ) {
$tags = explode( ',', $tags );
} else {
$tags = explode( ';', $tags );
}
$params['by_tags'] = array_filter( $tags );
}
}
$clients = MainWP_DB_Client::instance()->get_wp_client_by( 'all', null, ARRAY_A, $params );
$totalRecords = ( $clients ? count( $clients ) : 0 );
$clients_ids = array();
if ( is_array( $clients ) ) {
foreach ( $clients as $item ) {
if ( ! empty( $item['client_id'] ) ) {
$clients_ids[] = $item['client_id'];
}
}
}
// for compatible.
$optimize = $optimize ? true : false;
do_action( 'mainwp_clientstable_prepared_items', $clients, $clients_ids );
$this->items = $clients;
$this->total_items = $totalRecords;
}
/**
* Display the table.
*
* @param bool $optimize true|false Whether or not to optimize.
*/
public function display( $optimize = false ) {
// for compatible.
$optimize = $optimize ? true : false;
$sites_per_page = get_option( 'mainwp_default_manage_clients_per_page', 25 );
$sites_per_page = intval( $sites_per_page );
$pages_length = array(
25 => '25',
10 => '10',
50 => '50',
100 => '100',
300 => '300',
);
$pages_length = $pages_length + array( $sites_per_page => $sites_per_page );
ksort( $pages_length );
if ( isset( $pages_length[-1] ) ) {
unset( $pages_length[-1] );
}
$pagelength_val = implode( ',', array_keys( $pages_length ) );
$pagelength_title = implode( ',', array_values( $pages_length ) );
?>
', ' ' ); // NOSONAR - noopener - open safe. ?>
print_column_headers( $optimize, true ); ?>
display_rows_or_placeholder(); ?>
'true',
'paging' => 'true',
'pagingType' => 'full_numbers',
'info' => 'true',
'colReorder' => '{columns:":not(.check-column):not(.manage-client_actions-column)"}',
'stateSave' => 'true',
'stateDuration' => '0',
'order' => '[]',
'scrollX' => 'true',
'responsive' => 'true',
);
/**
* Filter: mainwp_clients_table_features
*
* Filter the Clients table features.
*
* @since 4.1
*/
$table_features = apply_filters( 'mainwp_clients_table_features', $table_features );
?>
get_column_info();
if ( ! empty( $columns['cb'] ) ) {
$columns['cb'] = '';
}
$def_columns = $this->get_default_columns();
$def_columns['client_actions'] = '';
foreach ( $columns as $column_client_key => $column_display_name ) {
$class = array( 'manage-' . $column_client_key . '-column' );
$attr = '';
if ( ! isset( $def_columns[ $column_client_key ] ) ) {
$class[] = 'extra-column';
}
if ( 'cb' === $column_client_key ) {
$class[] = 'check-column';
$class[] = 'collapsing';
}
if ( 'suspended' === $column_client_key ) {
$class[] = 'collapsing center aligned';
}
if ( 'image' === $column_client_key ) {
$class[] = 'collapsing center aligned';
}
if ( 'name' === $column_client_key ) {
$class[] = 'collapsing';
}
if ( 'websites' === $column_client_key ) {
$class[] = 'collapsing';
}
if ( 'created' === $column_client_key ) {
$class[] = 'collapsing center aligned';
}
if ( 'notes' === $column_client_key ) {
$class[] = 'collapsing center aligned';
}
if ( 'tags' === $column_client_key ) {
$class[] = 'collapsing';
}
if ( 'client_facebook' === $column_client_key ) {
$class[] = 'collapsing center aligned';
}
if ( 'client_instagram' === $column_client_key ) {
$class[] = 'collapsing center aligned';
}
if ( 'client_twitter' === $column_client_key ) {
$class[] = 'collapsing center aligned';
}
if ( 'client_linkedin' === $column_client_key ) {
$class[] = 'collapsing center aligned';
}
if ( 'client_phone' === $column_client_key ) {
$class[] = 'collapsing center aligned';
}
if ( 'client_actions' === $column_client_key ) {
$class[] = 'collapsing';
}
if ( 'contact_name' === $column_client_key ) {
$class[] = 'collapsing';
}
if ( ! isset( $sortable[ $column_client_key ] ) ) {
$class[] = 'no-sort';
}
$tag = 'th';
$id = "id='$column_client_key'";
if ( ! empty( $class ) ) {
$class = "class='" . join( ' ', $class ) . "'";
}
echo "<$tag $id $class $attr>$column_display_name$tag>"; // phpcs:ignore WordPress.Security.EscapeOutput
}
}
/**
* Get column info.
*/
protected function get_column_info() {
if ( isset( $this->column_headers ) && is_array( $this->column_headers ) ) {
$column_headers = array( array(), array(), array(), $this->get_default_primary_column_name() );
foreach ( $this->column_headers as $key => $value ) {
$column_headers[ $key ] = $value;
}
return $column_headers;
}
$columns = $this->get_columns();
$sortable_columns = $this->get_sortable_columns();
$_sortable = $sortable_columns;
$sortable = array();
foreach ( $_sortable as $id => $data ) {
if ( empty( $data ) ) {
continue;
}
$data = (array) $data;
if ( ! isset( $data[1] ) ) {
$data[1] = false;
}
$sortable[ $id ] = $data;
}
$primary = $this->get_default_primary_column_name();
$this->column_headers = array( $columns, $sortable, $primary );
return $this->column_headers;
}
/**
* Fetch single row item.
*
* @return mixed Single Row Item.
*/
public function display_rows() {
if ( $this->items ) {
foreach ( $this->items as $item ) {
$this->single_row( $item );
}
}
}
/**
* Single row.
*
* @param mixed $item Object containing the client info.
*/
public function single_row( $item ) {
echo '';
$this->single_row_columns( $item );
echo '
';
}
/**
* Columns for a single row.
*
* @param mixed $item Object containing the client info.
* @param bool $compatible to compatible param - DO NOT remove.
*/
protected function single_row_columns( $item, $compatible = true ) { // phpcs:ignore -- NOSONAR - complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated.
list( $columns ) = $this->get_column_info();
foreach ( $columns as $column_name => $column_display_name ) {
$classes = "$column_name column-$column_name";
$attributes = "class='$classes'";
?>
|
' . esc_html__( 'Active', 'mainwp' ) . '';
} elseif ( 1 === intval( $item['suspended'] ) ) {
$client_status = '' . esc_html__( 'Suspended', 'mainwp' ) . '';
} elseif ( 2 === intval( $item['suspended'] ) ) {
$client_status = '' . esc_html__( 'Lead', 'mainwp' ) . '';
} elseif ( 3 === intval( $item['suspended'] ) ) {
$client_status = '' . esc_html__( 'Lost', 'mainwp' ) . '';
}
?>
|
"; // phpcs:ignore WordPress.Security.EscapeOutput ?>
'; ?>
"; // phpcs:ignore WordPress.Security.EscapeOutput ?>
'; ?>
' . MainWP_Utility::time_elapsed_string( $item['created'] ) . '' : 'N/A'; //phpcs:ignore -- output ok. ?> |
"; // phpcs:ignore WordPress.Security.EscapeOutput ?>
'; ?>
"; // phpcs:ignore WordPress.Security.EscapeOutput ?>
'; ?>
|
"; // phpcs:ignore WordPress.Security.EscapeOutput ?>
'; ?>
"; // phpcs:ignore WordPress.Security.EscapeOutput
if ( empty( $item['note'] ) ) :
$cl_id1 = $item['client_id'];
?>
'; ?>
|
"; // phpcs:ignore WordPress.Security.EscapeOutput
echo call_user_func( array( $this, 'column_' . $column_name ), $item ); // phpcs:ignore WordPress.Security.EscapeOutput
echo '';
} else {
echo ""; // phpcs:ignore WordPress.Security.EscapeOutput
echo $this->column_default( $item, $column_name ); // phpcs:ignore WordPress.Security.EscapeOutput
echo ' | ';
}
}
if ( ! $compatible ) {
$compatible = true;
}
}
}