Skip to content

Instantly share code, notes, and snippets.

@bappi-d-great
Created February 7, 2017 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bappi-d-great/120d30b614f41fca6648b774dcf81ed1 to your computer and use it in GitHub Desktop.
Save bappi-d-great/120d30b614f41fca6648b774dcf81ed1 to your computer and use it in GitHub Desktop.
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