List of hooks

Posted · Add Comment

Scheduler Forums BirchPress Scheduler List of hooks

This topic contains 10 replies, has 7 voices, and was last updated by  Jason Overhulser 6 years, 10 months ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #7250

    Tas Gray
    Participant

    Have you got a list of the hooks published somewhere? I have looked through the documentation and come up empty handed.

    Thanks

    #7260

    support
    Keymaster

    Hi Tas,

    Currently there is no list of hooks published. What function do you want to achieve? We can tell you if there is a related hook.

    #7261

    Kim Snider
    Participant

    I have the same question. For example, are there hooks for when a new appointment is created? rescheduled? cancelled?

    #7268

    Tas Gray
    Participant

    With all due respect, that is ridiculous. How are we supposed to get anything done if we have to post a message on the forum every time we need to perform some customisations.

    There is a file called legacy-hooks.php in the plugin which has all of hooks, but some documentation would also be nice.

    #7269

    Kim Snider
    Participant

    Agreed Tas. The home page says “Developer Friendly” That is not very developer friendly.

    #7273

    support
    Keymaster

    Tas & Kim,

    As a WordPress developer, I know how frustrated you feel if there is no easy way to extend the plugin to meet your customers’ needs. Now I am going to give you a brief description of how to find and use hooks in our plugin.

    The hooks in the legacy-hooks.php file are legacy hooks prior to Version 2.0, since which we’ve redesigned the plugin. All the hooks within the new architecture are dynamically generated. Normally each static function in the imp.php file has 2 actions and 1 filter accompanied. The 2 actions are triggered before and after the function is called. The filter is used to override the return value of the function.

    e.g.
    There is a static function called reschedule_appointment1on1 in the includes/birchschedule/model/booking/imp.php file. If this function is called, the code will be like this.


    global $birchschedule,
    $birchschedule->model->booking->reschedule_appointment1on1($appointment1on1_id, $appointment_info);

    $birchschedule->model->booking is the package of the function, which is simulated using php objects.
    There are 2 actions for this function. One is ‘birchschedule_model_booking_reschedule_appointment1on1_before’ which is triggered before the function is called. The arguments of this action are same with the function. The other is ‘birchschedule_model_booking_reschedule_appointment1on1_after’ which is triggered after the function is called. The arguments are the ones of the function plus the return value.

    The filter name is ‘birchschedule_model_booking_reschedule_appointment1on1’. It is used to override the return value of the function. Its arguments are the return value plus the ones of the function.

    I hope this brief introduction is helpful to you. We will strive to work out more documents if we are not that busy in implementing new features:)

    Luke
    Co-founder

    #7289

    Tas Gray
    Participant

    Luke,

    Thank you for taking the time to explain. I think I may have to read that a few times before I understand it properly, but thank you!

    I look forward to seeing the documentation when it comes. You’ve written a very useful plugin which I’ll use again if the need arises.

    Thanks again,

    Tas

    #16530

    Phillip Harrington
    Participant

    Found this “How to find hooks.”

    #16756

    skinner927
    Participant

    I couldn’t find any example on how to intercept appointment creation so I’ll post my code. Essentially it just blasts a copy of the appointment to a remote endpoint. You may also want to do this for delete and edit methods but this is a good start. This all goes in /includes/model/booking/package.php

    In the ‘init’ definition, add this block:

    add_action( 'birchschedule_model_booking_make_appointment1on1_after',
    						array($ns, 'send_to_remote'));

    Then after the init block define our function:

    
    birch_defn( $ns, 'send_to_remote', function($appointment_info) use ($ns){
    
    			global $birchpress, $birchschedule;
    
    			// taken from appointments/edit/package.php 'get_appointment_info_html'
    			$appointment = $appointment_info;
    			$location_id = $appointment['_birs_appointment_location'];
    			$location = $birchschedule->model->get($location_id, array('keys' => array('post_title')));
    			$location_name = $location ? $location['post_title'] : '';
    
    			$service_id = $appointment['_birs_appointment_service'];
    			$service = $birchschedule->model->get($service_id, array('keys' => array('post_title')));
    			$service_name = $service ? $service['post_title'] : '';
    
    			$staff_id = $appointment['_birs_appointment_staff'];
    			$staff = $birchschedule->model->get($staff_id, array('keys' => array('post_title')));
    			$staff_name = $staff ? $staff['post_title'] : '';
    
    			$timestamp = $birchpress->util->get_wp_datetime( $appointment['_birs_appointment_timestamp'] );
    			$date4picker = $timestamp->format( get_option( 'date_format' ) );
    			$date = $timestamp->format( 'm/d/Y' );
    			$time = $timestamp->format( get_option( 'time_format' ) );
    
    			$appointment_data = array(
    				//'location_id' => $location_id,
    				//'location' => $location,
    				'location_name' => $location_name,
    				//'service_id' => $service_id,
    				//'service' => $service,
    				'service_name' => $service_name,
    				//'staff_id' => $staff_id,
    				//'staff' => $staff,
    				'staff_name' => $staff_name,
    				//'timestamp' => $timestamp,
    				'epoch' => $timestamp->getTimestamp(),
    				'timestamp' => $timestamp->format('c'),
    				//'date4picker' => $date4picker,
    				'date' => $date,
    				'time' => $time,
    				'notes' => $appointment['_birs_appointment_notes']
    			);
    
    			// taken from clientlist/edit/package.php 'get_client_info_html'
    			$client_id = $appointment['_birs_client_id'];
    			$client_title = get_post_meta( $client_id, '_birs_client_title', true );
    			$first_name = get_post_meta( $client_id, '_birs_client_name_first', true );
    			$last_name = get_post_meta( $client_id, '_birs_client_name_last', true );
    			$addresss1 = get_post_meta( $client_id, '_birs_client_address1', true );
    			$addresss2 = get_post_meta( $client_id, '_birs_client_address2', true );
    			$email = get_post_meta( $client_id, '_birs_client_email', true );
    			$phone = get_post_meta( $client_id, '_birs_client_phone', true );
    			$city = get_post_meta( $client_id, '_birs_client_city', true );
    			$zip = get_post_meta( $client_id, '_birs_client_zip', true );
    			$state = get_post_meta( $client_id, '_birs_client_state', true );
    			$country = get_post_meta( $client_id, '_birs_client_country', true );
    			if ( !$country ) {
    				$country = $birchschedule->model->get_default_country();
    			}
    
    			$client_data = array(
    				'client_title' => $client_title,
    				'first_name' => $first_name,
    				'last_name' => $last_name,
    				'addresss1' => $addresss1,
    				'addresss2' => $addresss2,
    				'email' => $email,
    				'phone' => $phone,
    				'city' => $city,
    				'zip' => $zip,
    				'state' => $state,
    				'country' => $country,
    			);
    
    			$result = array(
    					'appointment' => $appointment_data,
    					'client' => $client_data
    			);
    			$json = json_encode($result);
    
    			// This will async post so there is no delay
    			// Thanks: http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/
    
    			$url = 'http://test.dev/write.php';
    
    			$parts = parse_url($url);
    
    			$fp = fsockopen($parts['host'],
    					isset($parts['port'])?$parts['port']:80,
    					$errno, $errstr, 30);
    
    			if($fp){
    				$out = "POST ".$parts['path']." HTTP/1.1\r\n";
    				$out.= "Host: ".$parts['host']."\r\n";
    				$out.= "Content-Type: application/json\r\n";
    				$out.= "Content-Length: ".strlen($json)."\r\n";
    				$out.= "Connection: Close\r\n\r\n";
    				$out.= $json;
    
    				fwrite($fp, $out);
    				fclose($fp);
    			}
    
    			die("<pre>".json_encode($result, JSON_PRETTY_PRINT)."</pre>");
    		});
    

    Remove the die clause when you’re done testing. The die here lets you use the network inspector in your browser’s dev tools to see the resulting json. It also halts the creation of the appointment so you can continually click submit on the appointment form without having to fill it back out (good for testing). I would suggest NOT using a production site to test this as it probably mucks up the database pretty good.

    #29569

    Jason Overhulser
    Participant

    This works very well and I am able to access all these variables. But I cannot seem to access $appointment_info[‘_birs_appointment1on1_uid’] or ‘_birs_appointment_id’ either Everything else seems fine. Can anyone help? I really need to be able to get the unique ID of either the main appointment or the 1on1 appointment. I’m not sure why I can access ‘_birs_client_id’ but not appointment id.

    #29570

    Jason Overhulser
    Participant

    Here is my code. Line 38 is my snag. If anyone can advise me I would greatly appreciate it.
    $appoit_id = $appointment['_birs_appointment_id']; //are you kidding me whats wrong

    Full functions file:

    <?php
    // Exit if accessed directly
    if ( !defined( 'ABSPATH' ) ) exit;
    
    add_action( 'birchschedule_model_booking_make_appointment1on1_after', 'keyed_database_write', 10);
    
    function keyed_database_write($appointment_info) {
    	global $birchschedule, $birchpress, $wpdb;
    	$blog_id = get_current_blog_id();
    	$post_table = "wp_".$blog_id."_posts";
    	$meta_table = "wp_".$blog_id."_postmeta";
    	$test_table = "wp_".$blog_id."_test";
    		
    	// taken from appointments/edit/package.php 'get_appointment_info_html'
    	$appointment = $appointment_info;
    	$location_id = $appointment['_birs_appointment_location'];
    	$location = $birchschedule->model->get($location_id, array('keys' => array('post_title')));
    	$location_name = $location ? $location['post_title'] : '';
    	$service_id = $appointment['_birs_appointment_service'];
    	$service = $birchschedule->model->get($service_id, array('keys' => array('post_title')));
    	$service_name = $service ? $service['post_title'] : '';
    	
    	$staff_id = $appointment['_birs_appointment_staff'];
    	$staff = $birchschedule->model->get($staff_id, array('keys' => array('post_title')));
    	$staff_name = $staff ? $staff['post_title'] : '';
    	//$appointment_uniqueid = get_post_meta( $_POST['birs_appointment_id']);
    	//$appointment_uniqueid = $appointment['_birs_appointment_uid'];
    	
    	$wpdb->replace($test_table, array('show_me'=>$test_name, 'show_me2'=>'hook-hardcode3'));
    
    	$timestamp = $birchpress->util->get_wp_datetime( $appointment['_birs_appointment_timestamp'] );
    	$date4picker = $timestamp->format( get_option( 'date_format' ) );
    	$date = $timestamp->format( 'm/d/Y' );
    	$time = $timestamp->format( get_option( 'time_format' ) );
    	
    			// taken from clientlist/edit/package.php 'get_client_info_html'
    			$client_id = $appointment['_birs_client_id'];
    			$appoit_id = $appointment['_birs_appointment_id'];  //are you kidding me whats wrong
    									
    			$client_title = get_post_meta( $client_id, '_birs_client_title', true );
    			$first_name = get_post_meta( $client_id, '_birs_client_name_first', true );
    			$last_name = get_post_meta( $client_id, '_birs_client_name_last', true );
    			$addresss1 = get_post_meta( $client_id, '_birs_client_address1', true );
    			$addresss2 = get_post_meta( $client_id, '_birs_client_address2', true );
    			$email = get_post_meta( $client_id, '_birs_client_email', true );
    			$phone = get_post_meta( $client_id, '_birs_client_phone', true );
    			$city = get_post_meta( $client_id, '_birs_client_city', true );
    			$zip = get_post_meta( $client_id, '_birs_client_zip', true );
    			$state = get_post_meta( $client_id, '_birs_client_state', true );
    			$country = get_post_meta( $client_id, '_birs_client_country', true );
    			if ( !$country ) {
    				$country = $birchschedule->model->get_default_country();
    			}
    	
    
    	$wpdb->replace($test_table, array('show_me'=>$test_name, 'show_me2'=>'hook-hardcode'));			
    	$wpdb->replace($test_table, array('show_me'=>$appoit_id, 'show_me2'=>'try to insert appt id'));
    }
    
    
Viewing 11 posts - 1 through 11 (of 11 total)

The forum ‘BirchPress Scheduler’ is closed to new topics and replies.

Comments are closed.