function popmake_popup_targeting_condition_meta_box_fields($popup_id)
{
    $targeting_condition = popmake_get_popup_targeting_condition($popup_id);
    /**
     * Create nonce used for post type and taxonomy ajax searches. Copied from wp-admin/includes/nav-menu.php
     */
    wp_nonce_field('add-menu_item', 'menu-settings-column-nonce');
    /**
     * Render Load on entire site toggle.
     */
    ?>
	<div id="targeting_condition-on_entire_site" class="targeting_condition form-table">
		<input type="checkbox"
		       id="popup_targeting_condition_on_entire_site"
		       name="popup_targeting_condition_on_entire_site"
		       value="true"
			<?php 
    if (!empty($targeting_condition['on_entire_site'])) {
        echo 'checked="checked" ';
    }
    ?>
			/>
		<label for="popup_targeting_condition_on_entire_site"><?php 
    _e('On Entire Site', 'popup-maker');
    ?>
</label>

		<div class="options">
			<?php 
    do_action("popmake_popup_targeting_condition_on_entire_site_options", $targeting_condition);
    ?>
		</div>
	</div>
	<div id="targeting_condition-on_home" class="targeting_condition form-table">
		<input type="checkbox"
		       id="popup_targeting_condition_on_home"
		       name="popup_targeting_condition_on_home"
		       value="true"
			<?php 
    if (!empty($targeting_condition['on_home'])) {
        echo 'checked="checked" ';
    }
    ?>
			/>
		<label for="popup_targeting_condition_on_home"><?php 
    _e('On Home Page', 'popup-maker');
    ?>
</label>

		<div class="options">
			<?php 
    do_action("popmake_popup_targeting_condition_on_home_options", $targeting_condition);
    ?>
		</div>
	</div>
	<div id="targeting_condition-exclude_on_home" class="targeting_condition form-table">
		<input type="checkbox"
		       id="popup_targeting_condition_exclude_on_home"
		       name="popup_targeting_condition_exclude_on_home"
		       value="true"
			<?php 
    if (!empty($targeting_condition['exclude_on_home'])) {
        echo 'checked="checked" ';
    }
    ?>
			/>
		<label for="popup_targeting_condition_exclude_on_home"><?php 
    _e('Exclude on Home Page', 'popup-maker');
    ?>
</label>

		<div class="options">
			<?php 
    do_action("popmake_popup_targeting_condition_exclude_on_home_options", $targeting_condition);
    ?>
		</div>
	</div>
	<div id="targeting_condition-on_blog" class="targeting_condition form-table">
		<input type="checkbox"
		       id="popup_targeting_condition_on_blog"
		       name="popup_targeting_condition_on_blog"
		       value="true"
			<?php 
    if (!empty($targeting_condition['on_blog'])) {
        echo 'checked="checked" ';
    }
    ?>
			/>
		<label for="popup_targeting_condition_on_blog"><?php 
    _e('On Blog Index', 'popup-maker');
    ?>
</label>

		<div class="options">
			<?php 
    do_action("popmake_popup_targeting_condition_on_blog_options", $targeting_condition);
    ?>
		</div>
	</div>
	<div id="targeting_condition-exclude_on_blog" class="targeting_condition form-table">
	<input type="checkbox"
	       id="popup_targeting_condition_exclude_on_blog"
	       name="popup_targeting_condition_exclude_on_blog"
	       value="true"
		<?php 
    if (!empty($targeting_condition['exclude_on_blog'])) {
        echo 'checked="checked" ';
    }
    ?>
		/>
	<label for="popup_targeting_condition_exclude_on_blog"><?php 
    _e('Exclude on Blog Index', 'popup-maker');
    ?>
</label>

	<div class="options">
		<?php 
    do_action("popmake_popup_targeting_condition_exclude_on_blog_options", $targeting_condition);
    ?>
	</div>
	</div><?php 
    do_action('popmake_before_post_type_targeting_conditions', $targeting_condition);
    $includes = popmake_get_popup_targeting_condition_includes($popup_id);
    $excludes = popmake_get_popup_targeting_condition_excludes($popup_id);
    foreach (popmake_get_supported_types() as $pt) {
        $is_post_type = get_post_type_object($pt);
        $labels = $is_post_type ? $is_post_type : get_taxonomy($pt);
        if (!$labels) {
            continue;
        }
        $plural = esc_attr(strtolower($labels->labels->name));
        foreach (array('include', 'exclude') as $include_exclude) {
            $key = ($include_exclude != 'include' ? 'exclude_' : '') . "on_{$pt}s";
            $current = $include_exclude == 'include' ? !empty($includes[$pt]) ? $includes[$pt] : array() : (!empty($excludes[$pt]) ? $excludes[$pt] : array());
            ?>
		<div id="targeting_condition-<?php 
            echo $key;
            ?>
" class="targeting_condition form-table">
			<input type="checkbox"
			       id="popup_targeting_condition_<?php 
            echo $key;
            ?>
"
			       name="popup_targeting_condition_<?php 
            echo $key;
            ?>
"
			       value="true"
				<?php 
            if (!empty($targeting_condition[$key])) {
                echo 'checked="checked" ';
            }
            ?>
				/><?php 
            $label = ($include_exclude != 'include' ? 'Exclude ' : '') . 'On ';
            ?>
			<label for="popup_targeting_condition_<?php 
            echo $key;
            ?>
"><?php 
            echo __($label, 'popup-maker') . $labels->labels->name;
            ?>
</label>

			<div class="options">
				<p style="margin:0;"><?php 
            $key = ($include_exclude != 'include' ? 'exclude_' : '') . "on_specific_{$pt}s";
            ?>
					<input type="checkbox" style="display:none" name="popup_targeting_condition_<?php 
            echo $key;
            ?>
" value="true" <?php 
            if (isset($targeting_condition[$key])) {
                echo 'checked';
            }
            ?>
/>
					<label><?php 
            $label = ($include_exclude == 'include' ? 'Load' : 'Exclude') . ' on All ';
            echo __($label, 'popup-maker') . $labels->labels->name;
            ?>
						<input type="radio"
						       name="<?php 
            echo $key;
            ?>
"
						       id="popup_targeting_condition_<?php 
            echo $key;
            ?>
"
						       value=""
							<?php 
            if (!isset($targeting_condition[$key])) {
                echo 'checked';
            }
            ?>
							/>
					</label><br/>
					<label><?php 
            $label = ($include_exclude == 'include' ? 'Load' : 'Exclude') . ' on Specific ';
            echo __($label, 'popup-maker') . $labels->labels->name;
            ?>
						<input type="radio"
						       name="<?php 
            echo $key;
            ?>
"
						       id="popup_targeting_condition_<?php 
            echo $key;
            ?>
"
						       value="true"
							<?php 
            if (isset($targeting_condition[$key])) {
                echo 'checked';
            }
            ?>
							/>
					</label>
				</p>

				<div id="<?php 
            echo $key;
            ?>
">
					<div class="nojs-tags hide-if-js">
							<textarea
								name="popup_targeting_condition_<?php 
            echo $include_exclude == 'exclude' ? 'exclude_' : '';
            ?>
on_<?php 
            echo $pt;
            ?>
"
								rows="3" cols="20"
								id="popup_targeting_condition_<?php 
            echo $include_exclude == 'exclude' ? 'exclude_' : '';
            ?>
on_<?php 
            echo $pt;
            ?>
"
								><?php 
            esc_html_e(trim(implode(',', $current)));
            ?>
</textarea>
					</div>
					<div class="hide-if-no-js"><?php 
            if ($is_post_type) {
                popmake_post_type_item_metabox($pt);
            } else {
                popmake_taxonomy_item_metabox($pt);
            }
            ?>
						<div class="tagchecklist"><?php 
            foreach ($current as $post_id) {
                ?>
								<span><a class="ntdelbutton" data-id="<?php 
                echo $post_id;
                ?>
">X</a>
								<?php 
                echo $is_post_type ? get_the_title($post_id) : get_term_name($post_id, $pt);
                ?>
								</span><?php 
            }
            ?>
						</div>
					</div>
					<hr/>
				</div>
			</div>
			</div><?php 
        }
    }
    ?>
	<div id="targeting_condition-on_search" class="targeting_condition form-table">
		<input type="checkbox"
		       id="popup_targeting_condition_on_search"
		       name="popup_targeting_condition_on_search"
		       value="true"
			<?php 
    if (!empty($targeting_condition['on_search'])) {
        echo 'checked="checked" ';
    }
    ?>
			/>
		<label for="popup_targeting_condition_on_search"><?php 
    _e('On Search Pages', 'popup-maker');
    ?>
</label>

		<div class="options">
			<?php 
    do_action("popmake_popup_targeting_condition_on_search_options", $targeting_condition);
    ?>
		</div>
	</div>
	<div id="targeting_condition-exclude_on_search" class="targeting_condition form-table">
		<input type="checkbox"
		       id="popup_targeting_condition_exclude_on_search"
		       name="popup_targeting_condition_exclude_on_search"
		       value="true"
			<?php 
    if (!empty($targeting_condition['exclude_on_search'])) {
        echo 'checked="checked" ';
    }
    ?>
			/>
		<label for="popup_targeting_condition_exclude_on_search"><?php 
    _e('Exclude on Search Pages', 'popup-maker');
    ?>
</label>

		<div class="options">
			<?php 
    do_action("popmake_popup_targeting_condition_exclude_on_search_options", $targeting_condition);
    ?>
		</div>
	</div>
	<div id="targeting_condition-on_404" class="targeting_condition form-table">
		<input type="checkbox"
		       id="popup_targeting_condition_on_404"
		       name="popup_targeting_condition_on_404"
		       value="true"
			<?php 
    if (!empty($targeting_condition['on_404'])) {
        echo 'checked="checked" ';
    }
    ?>
			/>
		<label for="popup_targeting_condition_on_404"><?php 
    _e('On 404 Pages', 'popup-maker');
    ?>
</label>

		<div class="options">
			<?php 
    do_action("popmake_popup_targeting_condition_on_404_options", $targeting_condition);
    ?>
		</div>
	</div>
	<div id="targeting_condition-exclude_on_404" class="targeting_condition form-table">
	<input type="checkbox"
	       id="popup_targeting_condition_exclude_on_404"
	       name="popup_targeting_condition_exclude_on_404"
	       value="true"
		<?php 
    if (!empty($targeting_condition['exclude_on_404'])) {
        echo 'checked="checked" ';
    }
    ?>
		/>
	<label for="popup_targeting_condition_exclude_on_404"><?php 
    _e('Exclude on 404 Pages', 'popup-maker');
    ?>
</label>

	<div class="options">
		<?php 
    do_action("popmake_popup_targeting_condition_exclude_on_404_options", $targeting_condition);
    ?>
	</div>
	</div><?php 
}
Esempio n. 2
0
function popmake_popup_is_loadable($popup_id)
{
    global $post, $wp_query;
    $conditions = popmake_get_popup_targeting_condition($popup_id);
    $sitewide = false;
    $is_loadable = false;
    if (array_key_exists('on_entire_site', $conditions)) {
        $sitewide = true;
        $is_loadable = true;
    }
    /**
     * Front Page Checks
     */
    if (is_front_page()) {
        if (!$sitewide && array_key_exists('on_home', $conditions)) {
            $is_loadable = true;
        } elseif ($sitewide && array_key_exists('exclude_on_home', $conditions)) {
            $is_loadable = false;
        }
    }
    /**
     * Blog Index Page Checks
     */
    if (is_home()) {
        if (!$sitewide && array_key_exists('on_blog', $conditions)) {
            $is_loadable = true;
        } elseif ($sitewide && array_key_exists('exclude_on_blog', $conditions)) {
            $is_loadable = false;
        }
    } elseif (is_page()) {
        if (!$sitewide) {
            // Load on all pages
            if (array_key_exists('on_pages', $conditions) && !array_key_exists('on_specific_pages', $conditions)) {
                $is_loadable = true;
            } elseif (array_key_exists('on_specific_pages', $conditions) && array_key_exists('on_page_' . $post->ID, $conditions)) {
                $is_loadable = true;
            }
        } else {
            // Exclude on all pages.
            if (array_key_exists('exclude_on_pages', $conditions) && !array_key_exists('exclude_on_specific_pages', $conditions)) {
                $is_loadable = false;
            } elseif (array_key_exists('exclude_on_specific_pages', $conditions) && array_key_exists('exclude_on_page_' . $post->ID, $conditions)) {
                $is_loadable = false;
            }
        }
    } elseif (is_single() && $post->post_type == 'post') {
        if (!$sitewide) {
            // Load on all posts`1
            if (array_key_exists('on_posts', $conditions) && !array_key_exists('on_specific_posts', $conditions)) {
                $is_loadable = true;
            } elseif (array_key_exists('on_specific_posts', $conditions) && array_key_exists('on_post_' . $post->ID, $conditions)) {
                $is_loadable = true;
            }
        } else {
            // Exclude on all posts.
            if (array_key_exists('exclude_on_posts', $conditions) && !array_key_exists('exclude_on_specific_posts', $conditions)) {
                $is_loadable = false;
            } elseif (array_key_exists('exclude_on_specific_posts', $conditions) && array_key_exists('exclude_on_post_' . $post->ID, $conditions)) {
                $is_loadable = false;
            }
        }
    } elseif (is_category()) {
        $category_id = $wp_query->get_queried_object_id();
        if (!$sitewide) {
            // Load on all categories
            if (array_key_exists('on_categorys', $conditions) && !array_key_exists('on_specific_categorys', $conditions)) {
                $is_loadable = true;
            } elseif (array_key_exists('on_specific_categorys', $conditions) && array_key_exists('on_category_' . $category_id, $conditions)) {
                $is_loadable = true;
            }
        } else {
            // Exclude on all categories.
            if (array_key_exists('exclude_on_categorys', $conditions) && !array_key_exists('exclude_on_specific_categorys', $conditions)) {
                $is_loadable = false;
            } elseif (array_key_exists('exclude_on_specific_categorys', $conditions) && array_key_exists('exclude_on_category_' . $category_id, $conditions)) {
                $is_loadable = false;
            }
        }
    } elseif (is_tag()) {
        $tag_id = $wp_query->get_queried_object_id();
        if (!$sitewide) {
            // Load on all tags
            if (array_key_exists('on_tags', $conditions) && !array_key_exists('on_specific_tags', $conditions)) {
                $is_loadable = true;
            } elseif (array_key_exists('on_specific_tags', $conditions) && array_key_exists('on_tag_' . $tag_id, $conditions)) {
                $is_loadable = true;
            }
        } else {
            // Exclude on all tags.
            if (array_key_exists('exclude_on_tags', $conditions) && !array_key_exists('exclude_on_specific_tags', $conditions)) {
                $is_loadable = false;
            } elseif (array_key_exists('exclude_on_specific_tags', $conditions) && array_key_exists('exclude_on_tag_' . $tag_id, $conditions)) {
                $is_loadable = false;
            }
        }
    } elseif (is_single() && !in_array($post->post_type, array('post', 'page'))) {
        $pt = $post->post_type;
        if (!$sitewide) {
            // Load on all post type items
            if (array_key_exists("on_{$pt}s", $conditions) && !array_key_exists("on_specific_{$pt}s", $conditions)) {
                $is_loadable = true;
            } elseif (array_key_exists("on_specific_{$pt}s", $conditions) && array_key_exists("on_{$pt}_" . $post->ID, $conditions)) {
                $is_loadable = true;
            }
        } else {
            // Exclude on all post type items.
            if (array_key_exists("exclude_on_{$pt}s", $conditions) && !array_key_exists("exclude_on_specific_{$pt}s", $conditions)) {
                $is_loadable = false;
            } elseif (array_key_exists("exclude_on_specific_{$pt}s", $conditions) && array_key_exists("exclude_on_{$pt}_" . $post->ID, $conditions)) {
                $is_loadable = false;
            }
        }
    } elseif (is_tax()) {
        $term_id = $wp_query->get_queried_object_id();
        $tax = get_query_var('taxonomy');
        if (!$sitewide) {
            // Load on all custom tax terms.
            if (array_key_exists("on_{$tax}s", $conditions) && !array_key_exists("on_specific_{$tax}s", $conditions)) {
                $is_loadable = true;
            } elseif (array_key_exists("on_specific_{$tax}s", $conditions) && array_key_exists("on_{$tax}_" . $term_id, $conditions)) {
                $is_loadable = true;
            }
        } else {
            // Exclude on all custom tax terms.
            if (array_key_exists("exclude_on_{$tax}s", $conditions) && !array_key_exists("exclude_on_specific_{$tax}s", $conditions)) {
                $is_loadable = false;
            } elseif (array_key_exists("exclude_on_specific_{$tax}s", $conditions) && array_key_exists("exclude_on_{$tax}_" . $term_id, $conditions)) {
                $is_loadable = false;
            }
        }
    }
    /**
     * Search Checks
     */
    if (is_search()) {
        if (!$sitewide && array_key_exists('on_search', $conditions)) {
            $is_loadable = true;
        } elseif ($sitewide && array_key_exists('exclude_on_search', $conditions)) {
            $is_loadable = false;
        }
    }
    /**
     * 404 Page Checks
     */
    if (is_404()) {
        if (!$sitewide && array_key_exists('on_404', $conditions)) {
            $is_loadable = true;
        } elseif ($sitewide && array_key_exists('exclude_on_404', $conditions)) {
            $is_loadable = false;
        }
    }
    /*
    	// An Archive is a Category, Tag, Author or a Date based pages.
    	elseif( is_archive() ) {
    		if( array_key_exists("on_entire_site", $conditions)) {
    			$is_loadable = true;
    		}
    	}
    */
    return apply_filters('popmake_popup_is_loadable', $is_loadable, $popup_id, $conditions, $sitewide);
}