| 1 |
<?php |
| 2 |
/** |
| 3 |
* Triggers |
| 4 |
* |
| 5 |
* @package GamiPress\WooCommerce_Shipstation\Triggers |
| 6 |
* @since 1.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
// Exit if accessed directly |
| 10 |
if( !defined( 'ABSPATH' ) ) exit; |
| 11 |
|
| 12 |
/** |
| 13 |
* Register plugin specific triggers |
| 14 |
* |
| 15 |
* @since 1.0.0 |
| 16 |
* |
| 17 |
* @param array $triggers |
| 18 |
* @return mixed |
| 19 |
*/ |
| 20 |
function gamipress_woocommerce_shipstation_activity_triggers( $triggers ) { |
| 21 |
|
| 22 |
$triggers[__( 'WooCommerce Shipstation', 'gamipress-woocommerce-shipstation-integration' )] = array( |
| 23 |
|
| 24 |
'gamipress_wc_shipstation_order_shipped' => __( 'Get an order shipped', 'gamipress' ), |
| 25 |
'gamipress_wc_shipstation_order_product_shipped' => __( 'Get a product shipped', 'gamipress' ), |
| 26 |
|
| 27 |
); |
| 28 |
|
| 29 |
return $triggers; |
| 30 |
|
| 31 |
} |
| 32 |
add_filter( 'gamipress_activity_triggers', 'gamipress_woocommerce_shipstation_activity_triggers' ); |
| 33 |
|
| 34 |
/** |
| 35 |
* Get user for a given trigger action. |
| 36 |
* |
| 37 |
* @since 1.0.0 |
| 38 |
* |
| 39 |
* @param integer $user_id user ID to override. |
| 40 |
* @param string $trigger Trigger name. |
| 41 |
* @param array $args Passed trigger args. |
| 42 |
* @return integer User ID. |
| 43 |
*/ |
| 44 |
function gamipress_woocommerce_shipstation_trigger_get_user_id( $user_id, $trigger, $args ) { |
| 45 |
|
| 46 |
switch ( $trigger ) { |
| 47 |
case 'gamipress_wc_shipstation_order_shipped': |
| 48 |
case 'gamipress_wc_shipstation_order_product_shipped': |
| 49 |
$user_id = $args[1]; |
| 50 |
break; |
| 51 |
} |
| 52 |
|
| 53 |
return $user_id; |
| 54 |
|
| 55 |
} |
| 56 |
add_filter( 'gamipress_trigger_get_user_id', 'gamipress_woocommerce_shipstation_trigger_get_user_id', 10, 3 ); |
| 57 |
|
| 58 |
/** |
| 59 |
* Register WooCommerce specific activity triggers |
| 60 |
* |
| 61 |
* @since 1.0.0 |
| 62 |
* |
| 63 |
* @param array $specific_activity_triggers |
| 64 |
* @return array |
| 65 |
*/ |
| 66 |
function gamipress_woocommerce_specific_activity_triggers( $specific_activity_triggers ) { |
| 67 |
|
| 68 |
$specific_activity_triggers['gamipress_wc_shipstation_order_product_shipped'] = array( 'product' ); |
| 69 |
|
| 70 |
return $specific_activity_triggers; |
| 71 |
} |
| 72 |
add_filter( 'gamipress_specific_activity_triggers', 'gamipress_woocommerce_specific_activity_triggers' ); |
| 73 |
|
| 74 |
/** |
| 75 |
* Register WooCommerce specific activity triggers labels |
| 76 |
* |
| 77 |
* @since 1.0.0 |
| 78 |
* |
| 79 |
* @param array $specific_activity_trigger_labels |
| 80 |
* @return array |
| 81 |
*/ |
| 82 |
function gamipress_woocommerce_specific_activity_trigger_label( $specific_activity_trigger_labels ) { |
| 83 |
|
| 84 |
$specific_activity_trigger_labels['gamipress_wc_shipstation_order_product_shipped'] = __( 'Get %s product shipped', 'gamipress' ); |
| 85 |
|
| 86 |
return $specific_activity_trigger_labels; |
| 87 |
} |
| 88 |
add_filter( 'gamipress_specific_activity_trigger_label', 'gamipress_woocommerce_specific_activity_trigger_label' ); |
| 89 |
|
| 90 |
/** |
| 91 |
* Get the id for a given specific trigger action. |
| 92 |
* |
| 93 |
* @since 1.0.1 |
| 94 |
* |
| 95 |
* @param integer $specific_id Specific ID to override. |
| 96 |
* @param string $trigger Trigger name. |
| 97 |
* @param array $args Passed trigger args. |
| 98 |
* |
| 99 |
* @return integer Specific ID. |
| 100 |
*/ |
| 101 |
function gamipress_woocommerce_specific_trigger_get_id( $specific_id, $trigger, $args ) { |
| 102 |
|
| 103 |
switch ( $trigger ) { |
| 104 |
case 'gamipress_wc_shipstation_order_product_shipped': |
| 105 |
$specific_id = $args[2]; |
| 106 |
break; |
| 107 |
} |
| 108 |
|
| 109 |
return $specific_id; |
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
add_filter( 'gamipress_specific_trigger_get_id', 'gamipress_woocommerce_specific_trigger_get_id', 10, 3 ); |
| 114 |
|
| 115 |
/** |
| 116 |
* Extended meta data for event trigger logging |
| 117 |
* |
| 118 |
* @since 1.0.0 |
| 119 |
* |
| 120 |
* @param array $log_meta |
| 121 |
* @param integer $user_id |
| 122 |
* @param string $trigger |
| 123 |
* @param integer $site_id |
| 124 |
* @param array $args |
| 125 |
* |
| 126 |
* @return array |
| 127 |
*/ |
| 128 |
function gamipress_woocommerce_shipstation_log_event_trigger_meta_data( $log_meta, $user_id, $trigger, $site_id, $args ) { |
| 129 |
|
| 130 |
switch ( $trigger ) { |
| 131 |
|
| 132 |
case 'gamipress_wc_shipstation_order_shipped': |
| 133 |
$log_meta['order_id'] = $args[0]; |
| 134 |
break; |
| 135 |
case 'gamipress_wc_shipstation_order_product_shipped': |
| 136 |
$log_meta['order_id'] = $args[0]; |
| 137 |
$log_meta['product_id'] = $args[2]; |
| 138 |
break; |
| 139 |
|
| 140 |
} |
| 141 |
|
| 142 |
return $log_meta; |
| 143 |
} |
| 144 |
add_filter( 'gamipress_log_event_trigger_meta_data', 'gamipress_woocommerce_shipstation_log_event_trigger_meta_data', 10, 5 ); |
| 145 |
|