Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WPMU Appointments+ show service list with providers in front end
<?php
if( ! class_exists( 'APP_Service_FP' ) )
{
class APP_Service_FP
{
public $app;
protected function __construct()
{
global $appointments;
if( $appointments instanceof Appointments )
{
$this->app = $appointments;
add_shortcode( 'app_services_fp', array( $this, 'app_services_fp_cb' ) );
}
}
static public function get_instance()
{
static $Inst = null;
if( null == $Inst )
{
$Inst = new self();
}
return $Inst;
}
static public function is_true( $val )
{
return in_array( $val, array( 1, true, 'true', 'yes' ) );
}
public function app_services_fp_cb( $atts )
{
$atts = shortcode_atts( array(
'name' => true,
'capacity' => true,
'duration' => true,
'price' => true,
'provider' => false,
'desc' => true,
'desc_length' => 30
), $atts, 'app_services_fp' );
$services = $this->app->get_services();
$html = '<table width="100%">';
$html .= '<tr>';
$html .= '<th>ID</th>';
if( self::is_true( $atts['name'] ) )
$html .= '<th>Name</th>';
if( self::is_true( $atts['capacity'] ) )
$html .= '<th>Capacity</th>';
if( self::is_true( $atts['duration'] ) )
$html .= '<th>Duration</th>';
if( self::is_true( $atts['price'] ) )
$html .= '<th>Price</th>';
if( self::is_true( $atts['provider'] ) )
$html .= '<th>Provider</th>';
if( self::is_true( $atts['desc'] ) )
$html .= '<th>Description</th>';
$html .= '</tr>';
foreach( $services as $service )
{
$html .= '<tr>';
$html .= '<td valign="top">' . $service->ID . '</td>';
if( self::is_true( $atts['name'] ) )
$html .= '<td valign="top">' . $service->name . '</td>';
if( self::is_true( $atts['capacity'] ) )
$html .= '<td valign="top">' . $service->capacity . '</td>';
if( self::is_true( $atts['duration'] ) )
$html .= '<td valign="top">' . $service->duration . ' mins</td>';
if( self::is_true( $atts['price'] ) )
$html .= '<td valign="top">' . $service->price . ' ' . $this->app->options['currency'] . '</td>';
if( self::is_true( $atts['provider'] ) )
{
$providers = $this->app->get_workers_by_service( $service->ID );
$names = array();
foreach( $providers as $provider )
{
$ID = $provider->ID;
$user = new WP_User( $ID );
array_push( $names, trim( $user->display_name ) == '' ? $user->user_login : $user->display_name );
}
$html .= '<td valign="top">' . implode( ', ', $names ) . '</td>';
}
if( self::is_true( $atts['desc'] ) )
{
$page = get_page( $service->page );
$content = substr( $page->post_content, 0, $atts['desc_length'] );
$html .= '<td valign="top"><a href="' . get_permalink( $page->ID ) . '">' . $content . '...</a></td>';
}
$html .= '</tr>';
}
$html .= '</table>';
return $html;
}
}
add_action( 'init', function() {
APP_Service_FP::get_instance();
} );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.