37 lines
2.0 KiB
PHP
37 lines
2.0 KiB
PHP
<?php
|
|
if(!defined('ABSPATH')) exit;
|
|
class WMF_Service_Zapier extends WMF_Service {
|
|
public $id='zapier'; public $label='Zapier'; public $group='automation';
|
|
protected $credentials=array('webhook_url'=>'');
|
|
public function is_connected(){return!empty($this->credentials['webhook_url']);}
|
|
public function admin_widget($prev=array()){
|
|
$c = $this->get_credentials();
|
|
$int = wmf_get_integrations();
|
|
$act = $int->action_update;
|
|
$nonce= wp_create_nonce($act);
|
|
$conn = $this->is_connected();
|
|
echo '<div class="wmf-widget-body">';
|
|
if($conn) echo '<div class="wmf-connected-badge">✓ Verbunden</div>';
|
|
echo '<form class="wmf-int-form">';
|
|
echo '<input type="hidden" name="_wpnonce" value="'.esc_attr($nonce).'">';
|
|
echo '<input type="hidden" name="action" value="'.esc_attr($act).'">';
|
|
echo '<input type="hidden" name="services[]" value="zapier">';
|
|
|
|
echo '<p><label>Webhook-URL</label>';
|
|
echo '<input type="url" name="credentials[zapier][webhook_url]" value="'.esc_attr($c['webhook_url']??'').'" class="widefat" placeholder="https://hooks.zapier.com/hooks/catch/...">';
|
|
echo '<span class="description">In Zapier: Neuer Zap → Trigger "Webhooks by Zapier" → "Catch Hook" → URL kopieren.</span></p>';
|
|
|
|
echo '<p><button type="submit" class="button button-primary">Speichern</button></p>';
|
|
echo '</form>';
|
|
|
|
echo '</div>';
|
|
}
|
|
public function load(){add_action('wmf_form_submitted',array($this,'send'),10,5);}
|
|
public function send($form_id,$meta,$fields,$values,$sub_id){
|
|
if(!$this->is_connected()) return;
|
|
wp_remote_post($this->credentials['webhook_url'],array(
|
|
'body'=>wp_json_encode(array('form_id'=>$form_id,'submission_id'=>$sub_id,'data'=>$values,'site'=>get_site_url(),'date'=>current_time('c'))),
|
|
'headers'=>array('Content-Type'=>'application/json'),'timeout'=>5,'blocking'=>false,
|
|
));
|
|
}
|
|
} |