Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Created February 5, 2018 12:45
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 wpmudev-sls/88ce46b3fb45086d4f4522d5289d5387 to your computer and use it in GitHub Desktop.
Save wpmudev-sls/88ce46b3fb45086d4f4522d5289d5387 to your computer and use it in GitHub Desktop.
Specify default appointment service from shortcode
<?php
/**
* Plugin Name: Specify Default Appointment Service
* Plugin URI: https://premium.wpmudev.org/
* Description: Specify default appointment service from shortcode
* Author: Ariful Islam @ WPMUDEV
* Author URI: https://premium.wpmudev.org/profile/itsarifulislam
* License: GPLv2 or later
*/
/*
*
* Example of use: [app_services default="2"]
*
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Appointment_Default_Service' ) ) {
class Appointment_Default_Service {
private static $_instance = null;
public static function get_instance() {
if( is_null( self::$_instance ) ) {
self::$_instance = new Appointment_Default_Service();
}
return self::$_instance;
}
private function __construct() {
add_filter('appointments_services_shortcode_selected_service', array( $this, 'appointments_services_shortcode_selected_service' ), 10, 2);
}
public function appointments_services_shortcode_selected_service( $selected_service, $args ) {
if ( isset( $args['default'] ) ) {
$selected_service = $args['default'];
}
return $selected_service;
}
}
function render_appointment_default_service(){
$GLOBALS['Appointment_Default_Service'] = Appointment_Default_Service::get_instance();
}
add_action( 'plugins_loaded', 'render_appointment_default_service' );
}
@wpmudev-sls
Copy link
Author

Example of use: [app_services default="2"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment