-
Signed-off-by:
Kevin Cristiano <kcristiano@kcristiano.com>
Signed-off-by:
Kevin Cristiano <kcristiano@kcristiano.com>
Mailing-Hooks.php 2.73 KiB
<?php
/**
* CiviCRM Mailing_Hooks class.
*
* @since 0.1
*/
namespace CiviCRM_WP_REST\Civi;
class Mailing_Hooks {
/**
* Mailing Url endpoint.
*
* @since 0.1
* @var string
*/
public $url_endpoint;
/**
* Mailing Open endpoint.
*
* @since 0.1
* @var string
*/
public $open_endpoint;
/**
* Constructor.
*
* @since 0.1
*/
public function __construct() {
$this->url_endpoint = rest_url( 'civicrm/v3/url' );
$this->open_endpoint = rest_url( 'civicrm/v3/open' );
}
/**
* Register hooks.
*
* @since 0.1
*/
public function register_hooks() {
add_filter( 'civicrm_alterMailParams', [ $this, 'do_mailing_urls' ], 10, 2 );
}
/**
* Filters the mailing html and replaces calls to 'extern/url.php' and
* 'extern/open.php' with their REST counterparts 'civicrm/v3/url' and 'civicrm/v3/open'.
*
* @uses 'civicrm_alterMailParams'
*
* @since 0.1
* @param array &$params Mail params
* @param string $context The Context
* @return array $params The filtered Mail params
*/
public function do_mailing_urls( &$params, $context ) {
if ( $context == 'civimail' ) {
$params['html'] = $this->replace_html_mailing_tracking_urls( $params['html'] );
$params['text'] = $this->replace_text_mailing_tracking_urls( $params['text'] );