Skip to content
JayWood edited this page Jun 17, 2016 · 3 revisions

Below is a good bit of hooks and filters, if you have any questions just open an issue.

Hide the dialog on certain pages, regardless of cookies

/**
 * Maybe Show Dialog
 * @param  bool $bool    Default true
 * @param  WP_Post  $post_ob A WP_Post object
 * @return bool           True to show the dialog, false to hide it.
 */
function maybe_show_dialog( $bool = true, $post_ob = null ) {
	if ( isset( $post_obj->ID ) && 1 == $post_obj->ID ) {
		return false;
	}

	return $bool;
}
add_filter( 'cwv3_should_gate', 'maybe_show_dialog', 10, 2 );

Support Multiple Post Types

/**
 * Adds custom post types to protect
 * @param array $defaults Default is post & page
 */
function add_my_post_types( $defaults ) {
	// First make sure the defaults is set how it SHOULD be.
	$defaults = empty( $defaults ) || ! is_array( $defaults ) ? array() : $defaults;

	// Now add your post type to the available types
	$defaults[] = 'my_awesome_post_type_name';
	return $defaults;
}
add_action( 'cwv3_post_types', 'add_my_post_types' );

Override CSS completely

/**
 * Completely override ALL css data
 * @param  string $original_css CSS style content
 * @return string               Filtered result
 */
function override_css( $original_css ) {
	ob_start();?>
	<style type="text/css">
		.cwv3{ /** Some awesome css here **/ }
	</style>
	<?php
	return ob_get_clean();
}
add_filter( 'cwv3_custom_css', 'override_css' );

Add to the CSS that's generated

/**
 * Adds properties to the CSS class
 */
function add_css_styles() {
	// Will hide cwv3 entirely
	?>
	.cwv3{ display: none; }
	<?php
}
add_action( 'cwv3_css', 'add_css_styles' );

Edit dialog HTML content

/**
 * Overrides HTML content of the dialog
 * @param  string $output Original output
 * @param  array  $params Params from the filter
 * @return string         HTML content output
 */
function re_build_html( $output = '', $params = array() ) {
	$defaults = array(
		'title'          => '',
		'message'        => '',
		'enter_url'      => '',
		'exit_url'       => '',
		'enter_text'     => '',
		'exit_text'      => '',
		'denial_title'   => '',
		'denial_message' => '',
	);

	$params = wp_parse_args( $params, $defaults );
	ob_start();

	/**
	 * The following HTML is taken from the core of the plugin.  The only requirements for editing the HTML output is that you
	 * keep the classes the same in relation to the content.
	 *
	 * I really recommend not editing the HTML content unless you KNOW what you are doing, I will not help you in this.
	 */
	?>
	<!-- CWV3 JS Dialog -->
	<div class="cwv3 dialog-overlay" style="display:none;">&nbsp;</div>
	<div id="cwv3_dialog" class="cwv3_dialog js" style="display:none;">
		<div class="cwv3 auth">
			<div class="cwv3_title"><?php echo esc_attr( $params['title'] ); ?></div>
			<div class="cwv3_content"><?php echo $params['message'] ?></div>
			<div class="cwv3_btns">
				<div class="cwv3_enter">
					<a href="<?php echo esc_url( $params['enter_url'] ); ?>"><?php echo esc_attr( $params['enter_text'] ); ?></a>
				</div>
				<div class="cwv3_exit">
					<a href="<?php echo esc_url( $params['exit_url'] ); ?>"><?php echo esc_attr( $params['exit_text'] ); ?></a>
				</div>
			</div>
		</div>
		<div class="cwv3 denied">
			<div class="cwv3_title"><?php echo esc_attr( $params['denial_title'] ); ?></div>
			<div class="cwv3_content"><?php echo $params['denial_message']; ?></div>
			<div class="cwv3_btns">
				<div class="cwv3_exit">
					<a href="<?php echo esc_url( $params['exit_url'] ); ?>"><?php echo esc_attr( $params['exit_text'] ); ?></a>
				</div>
			</div>
		</div>
	</div>
	<!-- END CWV3 JS Dialog -->
	<?php
}
add_filter( 'cwv3_js_dialog_output', 're_build_html', 10, 2 );