get_campaigns() ) ) {
return;
}
/**
* calculate an intersection between the matched campaigns and the campaigns setup from admin for this widget
*/
$matched_ids = array();
foreach ( $matched as $campaign ) {
$matched_ids [] = $campaign->ID;
}
$diff = array_intersect( $matched_ids, $instance['campaign_ids'] );
/* if no campaign setup from widget -> bail */
if ( empty( $diff ) ) {
return;
}
/* get the height from any of the widgets from the campaign - doesn't matter which one because at this point we don't know which one will be displayed */
$widgets = array_values( array_filter( $campaign->designs, static function ( $design ) {
return ! empty( $design['post_type'] ) && $design['post_type'] === 'widget';
} ) );
if ( empty( $widgets[0]['id'] ) ) {
$placeholder_style = 'display:none';
} else {
$placeholder_style = tve_ultimatum_get_lightspeed_placeholder( $campaign->ID, $widgets[0]['id'] );
}
$class = '';
if ( $placeholder_style !== 'display:none' ) {
$class = 'tve-ult-preload-form';
}
// add id to wrapper to be used in js
echo '
';
}
/**
* Outputs the settings update form.
*
* @access public
*
* @param array $instance Current settings.
*
* @return string Default return is 'noform'.
*/
public function form( $instance ) {
$ids = empty( $instance['campaign_ids'] ) ? array() : $instance['campaign_ids'];
if ( empty( $ids ) || ! is_array( $ids ) ) {
$ids = array();
}
$campaigns = tve_ult_get_campaigns( array(
'get_settings' => false,
) );
echo '';
if ( empty( $campaigns ) ) {
echo '
' .
sprintf( __( 'You have no campaigns setup yet. %sSetup your campaigns first%s', 'thrive-ult' ), '', '' ) .
'
';
return '';
}
echo '';
?>
get_field_name( 'campaign_ids' );
foreach ( $campaigns as $c ) {
echo '';
}
return '';
}
/**
* Updates a particular instance of a widget.
*
* This function should check that `$new_instance` is set correctly. The newly-calculated
* value of `$instance` should be returned. If false is returned, the instance won't be
* saved/updated.
*
*
* @param array $new_instance New settings for this instance as input by the user via
* WP_Widget::form().
* @param array $old_instance Old settings for this instance.
*
* @return array Settings to save or bool false to cancel saving.
*/
public function update( $new_instance, $old_instance ) {
if ( ! isset( $new_instance['campaign_ids'] ) || ! is_array( $new_instance['campaign_ids'] ) ) {
$new_instance['campaign_ids'] = array();
}
return $new_instance;
}
}