/**
  * Handles Category Level Access *( for current page )*.
  *
  * @package s2Member\Categories
  * @since 3.5
  *
  * @return null Or exits script execution after redirection.
  */
 public static function check_catg_level_access()
 {
     global $post;
     /* ``get_the_ID()`` is NOT available outside The Loop. */
     /**/
     do_action("ws_plugin__s2member_before_check_catg_level_access", get_defined_vars());
     /**/
     $excluded = apply_filters("ws_plugin__s2member_check_catg_level_access_excluded", false, get_defined_vars());
     /**/
     if (!$excluded && is_category() && ($cat_id = get_query_var("cat")) && ($cat_id = (int) $cat_id) && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]) {
         if (!c_ws_plugin__s2member_systematics::is_wp_systematic_use_page()) {
             $user = is_user_logged_in() && is_object($user = wp_get_current_user()) && !empty($user->ID) ? $user : false;
             /* Current User's object. */
             /**/
             if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_redirection_override"] && ($login_redirection_uri = c_ws_plugin__s2member_login_redirects::login_redirection_uri($user, "root-returns-false")) && preg_match("/^" . preg_quote($login_redirection_uri, "/") . "\$/", $_SERVER["REQUEST_URI"]) && c_ws_plugin__s2member_no_cache::no_cache_constants(true) && (!$user || !$user->has_cap("access_s2member_level0"))) {
                 c_ws_plugin__s2member_mo_page::wp_redirect_w_mop_vars("catg", $cat_id, "level", 0, $_SERVER["REQUEST_URI"], "sys") . exit;
             } else {
                 if (!c_ws_plugin__s2member_systematics::is_systematic_use_page()) {
                     for ($n = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n >= 0; $n--) {
                         if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_catgs"] === "all" && c_ws_plugin__s2member_no_cache::no_cache_constants(true) && (!$user || !$user->has_cap("access_s2member_level" . $n))) {
                             c_ws_plugin__s2member_mo_page::wp_redirect_w_mop_vars("catg", $cat_id, "level", $n, $_SERVER["REQUEST_URI"]) . exit;
                         } else {
                             if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_catgs"] && in_array($cat_id, $catgs = preg_split("/[\r\n\t\\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_catgs"])) && c_ws_plugin__s2member_no_cache::no_cache_constants(true) && (!$user || !$user->has_cap("access_s2member_level" . $n))) {
                                 c_ws_plugin__s2member_mo_page::wp_redirect_w_mop_vars("catg", $cat_id, "level", $n, $_SERVER["REQUEST_URI"]) . exit;
                             } else {
                                 if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_catgs"]) {
                                     /* Check Category ancestry. */
                                     foreach (preg_split("/[\r\n\t\\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_catgs"]) as $catg) {
                                         if ($catg && cat_is_ancestor_of($catg, $cat_id) && c_ws_plugin__s2member_no_cache::no_cache_constants(true) && (!$user || !$user->has_cap("access_s2member_level" . $n))) {
                                             c_ws_plugin__s2member_mo_page::wp_redirect_w_mop_vars("catg", $cat_id, "level", $n, $_SERVER["REQUEST_URI"]) . exit;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     /**/
                     for ($n = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n >= 0; $n--) {
                         if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_ruris"]) {
                             /* URIs configured at this Level? */
                             /**/
                             foreach (preg_split("/[\r\n\t]+/", c_ws_plugin__s2member_ruris::fill_ruri_level_access_rc_vars($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_ruris"], $user)) as $str) {
                                 if ($str && preg_match("/" . preg_quote($str, "/") . "/", $_SERVER["REQUEST_URI"]) && c_ws_plugin__s2member_no_cache::no_cache_constants(true) && (!$user || !$user->has_cap("access_s2member_level" . $n))) {
                                     c_ws_plugin__s2member_mo_page::wp_redirect_w_mop_vars("catg", $cat_id, "level", $n, $_SERVER["REQUEST_URI"], "ruri") . exit;
                                 }
                             }
                         }
                     }
                 }
             }
             /**/
             do_action("ws_plugin__s2member_during_check_catg_level_access", get_defined_vars());
         }
     }
     /**/
     do_action("ws_plugin__s2member_after_check_catg_level_access", get_defined_vars());
     /**/
     return;
     /* For uniformity. */
 }
Example #2
0
function wp_insert_category($catarr)
{
    global $wpdb;
    extract($catarr, EXTR_SKIP);
    if (trim($cat_name) == '') {
        return 0;
    }
    $cat_ID = (int) $cat_ID;
    // Are we updating or creating?
    if (!empty($cat_ID)) {
        $update = true;
    } else {
        $update = false;
    }
    $name = $cat_name;
    $description = $category_description;
    $slug = $category_nicename;
    $parent = $category_parent;
    $parent = (int) $parent;
    if (empty($parent) || !category_exists($parent) || $cat_ID && cat_is_ancestor_of($cat_ID, $parent)) {
        $parent = 0;
    }
    $args = compact('name', 'slug', 'parent', 'description');
    if ($update) {
        $cat_ID = wp_update_term($cat_ID, 'category', $args);
    } else {
        $cat_ID = wp_insert_term($cat_name, 'category', $args);
    }
    if (is_wp_error($cat_ID)) {
        return 0;
    }
    return $cat_ID['term_id'];
}
Example #3
0
/**
 * Returns sports posts without thumbnails as a block grid
**/
function get_sports_list()
{
    $exclude_ids = array($GLOBALS['excluded_sports_1'], $GLOBALS['excluded_sports_2']);
    $args = array('posts_per_page' => 6, 'category_name' => 'sports', 'post__not_in' => $exclude_ids);
    $the_query = new WP_Query($args);
    if ($the_query->have_posts()) {
        echo '<div class="row medium-up-2 large-up-2">';
        while ($the_query->have_posts()) {
            $the_query->the_post();
            // List element
            echo '<div class="column"><h6>';
            // Subcategory
            $category = get_the_category();
            foreach (get_the_category() as $childcat) {
                if (cat_is_ancestor_of(13, $childcat)) {
                    echo '<a class="subcategory" href="' . get_category_link($childcat->cat_ID) . '">';
                    echo $childcat->cat_name . '</a>';
                    echo ' · ';
                }
            }
            // Link
            echo '<a href="' . get_permalink(get_post()->ID) . '" title="' . esc_attr(get_post()->post_title) . '">';
            // Title
            echo get_the_title(get_post()->ID);
            echo '</a></h6></div>';
        }
        echo '</div>';
    } else {
        // no posts found
    }
    wp_reset_postdata();
}
Example #4
0
function myTemplateSelect()
{
    if (is_category() && !is_feed()) {
        if (is_category(get_cat_id('projekt')) || cat_is_ancestor_of(get_cat_id('projekt'), get_query_var('cat'))) {
            load_template(STYLESHEETPATH . '/category-projekt.php');
            exit;
        }
    }
}
 /**
  * Handles Category Level Access *( for specific Categories )*.
  *
  * @package s2Member\Categories
  * @since 3.5
  *
  * @param int|str $cat_id Numeric Category ID.
  * @param bool $check_user Test permissions against the current User? Defaults to true.
  * @return null|array Non-empty array ( with details ) if access is denied, else null if access is allowed.
  */
 public static function check_specific_catg_level_access($cat_id = FALSE, $check_user = TRUE)
 {
     do_action("ws_plugin__s2member_before_check_specific_catg_level_access", get_defined_vars());
     /**/
     $excluded = apply_filters("ws_plugin__s2member_check_specific_catg_level_access_excluded", false, get_defined_vars());
     /**/
     if (!$excluded && is_numeric($cat_id) && ($cat_id = (int) $cat_id) && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]) {
         $cat_uri = c_ws_plugin__s2member_utils_urls::parse_uri(get_category_link($cat_id));
         /* Get a full valid URI for this Category. */
         /**/
         if (!c_ws_plugin__s2member_systematics_sp::is_wp_systematic_use_specific_page(null, $cat_uri)) {
             $user = is_user_logged_in() && is_object($user = wp_get_current_user()) && !empty($user->ID) ? $user : false;
             /* Current User's object. */
             /**/
             if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_redirection_override"] && ($login_redirection_uri = c_ws_plugin__s2member_login_redirects::login_redirection_uri($user, "root-returns-false")) && preg_match("/^" . preg_quote($login_redirection_uri, "/") . "\$/", $cat_uri) && (!$check_user || !$user || !$user->has_cap("access_s2member_level0"))) {
                 return apply_filters("ws_plugin__s2member_check_specific_catg_level_access", array("s2member_level_req" => 0), get_defined_vars());
             } else {
                 if (!c_ws_plugin__s2member_systematics_sp::is_systematic_use_specific_page(null, $cat_uri)) {
                     for ($n = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n >= 0; $n--) {
                         if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_catgs"] === "all" && (!$check_user || !$user || !$user->has_cap("access_s2member_level" . $n))) {
                             return apply_filters("ws_plugin__s2member_check_specific_catg_level_access", array("s2member_level_req" => $n), get_defined_vars());
                         } else {
                             if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_catgs"] && in_array($cat_id, $catgs = preg_split("/[\r\n\t\\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_catgs"])) && (!$check_user || !$user || !$user->has_cap("access_s2member_level" . $n))) {
                                 return apply_filters("ws_plugin__s2member_check_specific_catg_level_access", array("s2member_level_req" => $n), get_defined_vars());
                             } else {
                                 if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_catgs"]) {
                                     /* Check Category ancestry. */
                                     foreach (preg_split("/[\r\n\t\\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_catgs"]) as $catg) {
                                         if ($catg && cat_is_ancestor_of($catg, $cat_id) && (!$check_user || !$user || !$user->has_cap("access_s2member_level" . $n))) {
                                             return apply_filters("ws_plugin__s2member_check_specific_catg_level_access", array("s2member_level_req" => $n), get_defined_vars());
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     /**/
                     for ($n = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n >= 0; $n--) {
                         if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_ruris"]) {
                             /* URIs configured at this Level? */
                             /**/
                             foreach (preg_split("/[\r\n\t]+/", c_ws_plugin__s2member_ruris::fill_ruri_level_access_rc_vars($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_ruris"], $user)) as $str) {
                                 if ($str && preg_match("/" . preg_quote($str, "/") . "/", $cat_uri) && (!$check_user || !$user || !$user->has_cap("access_s2member_level" . $n))) {
                                     return apply_filters("ws_plugin__s2member_check_specific_catg_level_access", array("s2member_level_req" => $n), get_defined_vars());
                                 }
                             }
                         }
                     }
                 }
             }
             /**/
             do_action("ws_plugin__s2member_during_check_specific_catg_level_access", get_defined_vars());
         }
     }
     /**/
     return apply_filters("ws_plugin__s2member_check_specific_catg_level_access", null, get_defined_vars());
 }
Example #6
0
function web589_get_parrents($sep)
{
    if (is_category()) {
        $par = get_ancestors(get_query_var('cat'), 'category');
        $num = count($par);
        for ($i = $num; $i >= 1; $i--) {
            $j = $i - 1;
            $id = $par[$j];
            $array[get_category_link($id)] = get_cat_name($id);
        }
        $array[get_category_link(get_query_var('cat'))] = get_cat_name(get_query_var('cat'));
    }
    if (is_page()) {
        $par = get_ancestors(get_the_ID(), 'page');
        $num = count($par);
        for ($i = $num; $i >= 1; $i--) {
            $j = $i - 1;
            $id = $par[$j];
            $page = get_page($id);
            $array[get_page_link($id)] = $page->post_title;
        }
        $cur_page = get_page(get_the_ID());
        $array[get_page_link(get_the_ID())] = $cur_page->post_title;
    }
    if (is_single()) {
        $cats = get_the_category();
        foreach ($cats as $cat) {
            foreach ($cats as $child) {
                if (!cat_is_ancestor_of($cat, $child)) {
                    $id = $cat->cat_ID;
                }
            }
        }
        $par = get_ancestors($id, 'category');
        $num = count($par);
        for ($i = $num; $i >= 1; $i--) {
            $j = $i - 1;
            $p_id = $par[$j];
            $array[get_category_link($p_id)] = get_cat_name($p_id);
        }
        $array[get_category_link($id)] = get_cat_name($id);
        $array[get_permalink()] = get_the_title();
    }
    if (is_tag()) {
        $tag = get_tag(get_query_var('tag_id'));
        $array[] = $tag->name;
    }
    if (is_day() || is_month() || is_year()) {
        $array[] = wp_title('', false);
    }
    return $array;
}
function return_child_cat($parentslug, $link = NULL)
{
    $catslug = get_category_by_slug($parentslug);
    foreach (get_the_category() as $childcat) {
        if (cat_is_ancestor_of($catslug->term_id, $childcat)) {
            if ($link == NULL) {
                return $childcat->cat_name;
            } else {
                return '<a href="' . get_category_link($childcat->term_id) . '">' . $childcat->cat_name . '</a>';
            }
        }
    }
}
function wp_insert_category($catarr, $wp_error = false) {
	$cat_defaults = array('cat_ID' => 0, 'cat_name' => '', 'category_description' => '', 'category_nicename' => '', 'category_parent' => '');
	$cat_arr = wp_parse_args($cat_arr, $cat_defaults);
	extract($catarr, EXTR_SKIP);

	if ( trim( $cat_name ) == '' ) {
		if ( ! $wp_error )
			return 0;
		else
			return new WP_Error( 'cat_name', __('You did not enter a category name.') );
	}

	$cat_ID = (int) $cat_ID;

	// Are we updating or creating?
	if ( !empty ($cat_ID) )
		$update = true;
	else
		$update = false;

	$name = $cat_name;
	$description = $category_description;
	$slug = $category_nicename;
	$parent = $category_parent;

	$parent = (int) $parent;
	if ( $parent < 0 )
		$parent = 0;

	if ( empty($parent) || !category_exists( $parent ) || ($cat_ID && cat_is_ancestor_of($cat_ID, $parent) ) )
		$parent = 0;

	$args = compact('name', 'slug', 'parent', 'description');

	if ( $update )
		$cat_ID = wp_update_term($cat_ID, 'category', $args);
	else
		$cat_ID = wp_insert_term($cat_name, 'category', $args);

	if ( is_wp_error($cat_ID) ) {
		if ( $wp_error )
			return $cat_ID;
		else
			return 0;
	}

	return $cat_ID['term_id'];
}
Example #9
0
 /**
  * Handles Category Level Access *(for current page)*.
  *
  * @package s2Member\Categories
  * @since 3.5
  *
  * @return null Or exits script execution after redirection.
  */
 public static function check_catg_level_access()
 {
     global $post;
     // ``get_the_ID()`` is NOT available outside The Loop.
     do_action('ws_plugin__s2member_before_check_catg_level_access', get_defined_vars());
     $ci = $GLOBALS['WS_PLUGIN__']['s2member']['o']['ruris_case_sensitive'] ? '' : 'i';
     $excluded = apply_filters('ws_plugin__s2member_check_catg_level_access_excluded', FALSE, get_defined_vars());
     if (!$excluded && is_category() && ($cat_id = get_query_var('cat')) && ($cat_id = (int) $cat_id) && $GLOBALS['WS_PLUGIN__']['s2member']['o']['membership_options_page']) {
         if (!c_ws_plugin__s2member_systematics::is_wp_systematic_use_page()) {
             $user = is_user_logged_in() && is_object($user = wp_get_current_user()) && !empty($user->ID) ? $user : FALSE;
             if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['login_redirection_override'] && ($login_redirection_uri = c_ws_plugin__s2member_login_redirects::login_redirection_uri($user, 'root-returns-false')) && preg_match('/^' . preg_quote($login_redirection_uri, '/') . '$/' . $ci, $_SERVER['REQUEST_URI']) && c_ws_plugin__s2member_no_cache::no_cache_constants('restricted') && (!$user || !$user->has_cap('access_s2member_level0'))) {
                 c_ws_plugin__s2member_mo_page::wp_redirect_w_mop_vars('catg', $cat_id, 'level', 0, $_SERVER['REQUEST_URI'], 'sys') . exit;
             } else {
                 if (!c_ws_plugin__s2member_systematics::is_systematic_use_page()) {
                     for ($n = $GLOBALS['WS_PLUGIN__']['s2member']['c']['levels']; $n >= 0; $n--) {
                         if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['level' . $n . '_catgs'] === 'all' && c_ws_plugin__s2member_no_cache::no_cache_constants('restricted') && (!$user || !$user->has_cap('access_s2member_level' . $n))) {
                             c_ws_plugin__s2member_mo_page::wp_redirect_w_mop_vars('catg', $cat_id, 'level', $n, $_SERVER['REQUEST_URI']) . exit;
                         } else {
                             if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['level' . $n . '_catgs'] && in_array($cat_id, $catgs = preg_split('/[' . "\r\n\t" . '\\s;,]+/', $GLOBALS['WS_PLUGIN__']['s2member']['o']['level' . $n . '_catgs'])) && c_ws_plugin__s2member_no_cache::no_cache_constants('restricted') && (!$user || !$user->has_cap('access_s2member_level' . $n))) {
                                 c_ws_plugin__s2member_mo_page::wp_redirect_w_mop_vars('catg', $cat_id, 'level', $n, $_SERVER['REQUEST_URI']) . exit;
                             } else {
                                 if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['level' . $n . '_catgs']) {
                                     foreach (preg_split('/[' . "\r\n\t" . '\\s;,]+/', $GLOBALS['WS_PLUGIN__']['s2member']['o']['level' . $n . '_catgs']) as $catg) {
                                         if ($catg && cat_is_ancestor_of($catg, $cat_id) && c_ws_plugin__s2member_no_cache::no_cache_constants('restricted') && (!$user || !$user->has_cap('access_s2member_level' . $n))) {
                                             c_ws_plugin__s2member_mo_page::wp_redirect_w_mop_vars('catg', $cat_id, 'level', $n, $_SERVER['REQUEST_URI']) . exit;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     for ($n = $GLOBALS['WS_PLUGIN__']['s2member']['c']['levels']; $n >= 0; $n--) {
                         if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['level' . $n . '_ruris']) {
                             foreach (preg_split('/[' . "\r\n\t" . ']+/', c_ws_plugin__s2member_ruris::fill_ruri_level_access_rc_vars($GLOBALS['WS_PLUGIN__']['s2member']['o']['level' . $n . '_ruris'], $user)) as $str) {
                                 if ($str && preg_match('/' . preg_quote($str, '/') . '/' . $ci, $_SERVER['REQUEST_URI']) && c_ws_plugin__s2member_no_cache::no_cache_constants('restricted') && (!$user || !$user->has_cap('access_s2member_level' . $n))) {
                                     c_ws_plugin__s2member_mo_page::wp_redirect_w_mop_vars('catg', $cat_id, 'level', $n, $_SERVER['REQUEST_URI'], 'ruri') . exit;
                                 }
                             }
                         }
                     }
                 }
             }
             do_action('ws_plugin__s2member_during_check_catg_level_access', get_defined_vars());
         }
     }
     do_action('ws_plugin__s2member_after_check_catg_level_access', get_defined_vars());
 }
Example #10
0
 /**
  * Handles Category Level Access *(for specific Categories)*.
  *
  * @package s2Member\Categories
  * @since 3.5
  *
  * @param int|string $cat_id Numeric Category ID.
  * @param bool       $check_user Test permissions against the current User? Defaults to true.
  *
  * @return null|array Non-empty array(with details) if access is denied, else null if access is allowed.
  */
 public static function check_specific_catg_level_access($cat_id = '', $check_user = TRUE)
 {
     do_action('ws_plugin__s2member_before_check_specific_catg_level_access', get_defined_vars());
     $ci = $GLOBALS['WS_PLUGIN__']['s2member']['o']['ruris_case_sensitive'] ? '' : 'i';
     $excluded = apply_filters('ws_plugin__s2member_check_specific_catg_level_access_excluded', FALSE, get_defined_vars());
     if (!$excluded && is_numeric($cat_id) && ($cat_id = (int) $cat_id) && $GLOBALS['WS_PLUGIN__']['s2member']['o']['membership_options_page']) {
         $cat_uri = c_ws_plugin__s2member_utils_urls::parse_uri(get_category_link($cat_id));
         if (!c_ws_plugin__s2member_systematics_sp::is_wp_systematic_use_specific_page(NULL, $cat_uri)) {
             $user = is_user_logged_in() && is_object($user = wp_get_current_user()) && !empty($user->ID) ? $user : FALSE;
             if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['login_redirection_override'] && ($login_redirection_uri = c_ws_plugin__s2member_login_redirects::login_redirection_uri($user, 'root-returns-false')) && preg_match('/^' . preg_quote($login_redirection_uri, '/') . '$/' . $ci, $cat_uri) && (!$check_user || !$user || !$user->has_cap('access_s2member_level0'))) {
                 return apply_filters('ws_plugin__s2member_check_specific_catg_level_access', array('s2member_level_req' => 0), get_defined_vars());
             } else {
                 if (!c_ws_plugin__s2member_systematics_sp::is_systematic_use_specific_page(NULL, $cat_uri)) {
                     for ($n = $GLOBALS['WS_PLUGIN__']['s2member']['c']['levels']; $n >= 0; $n--) {
                         if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['level' . $n . '_catgs'] === 'all' && (!$check_user || !$user || !$user->has_cap('access_s2member_level' . $n))) {
                             return apply_filters('ws_plugin__s2member_check_specific_catg_level_access', array('s2member_level_req' => $n), get_defined_vars());
                         } else {
                             if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['level' . $n . '_catgs'] && in_array($cat_id, $catgs = preg_split('/[' . "\r\n\t" . '\\s;,]+/', $GLOBALS['WS_PLUGIN__']['s2member']['o']['level' . $n . '_catgs'])) && (!$check_user || !$user || !$user->has_cap('access_s2member_level' . $n))) {
                                 return apply_filters('ws_plugin__s2member_check_specific_catg_level_access', array('s2member_level_req' => $n), get_defined_vars());
                             } else {
                                 if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['level' . $n . '_catgs']) {
                                     foreach (preg_split('/[' . "\r\n\t" . '\\s;,]+/', $GLOBALS['WS_PLUGIN__']['s2member']['o']['level' . $n . '_catgs']) as $catg) {
                                         if ($catg && cat_is_ancestor_of($catg, $cat_id) && (!$check_user || !$user || !$user->has_cap('access_s2member_level' . $n))) {
                                             return apply_filters('ws_plugin__s2member_check_specific_catg_level_access', array('s2member_level_req' => $n), get_defined_vars());
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     for ($n = $GLOBALS['WS_PLUGIN__']['s2member']['c']['levels']; $n >= 0; $n--) {
                         if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['level' . $n . '_ruris']) {
                             foreach (preg_split('/[' . "\r\n\t" . ']+/', c_ws_plugin__s2member_ruris::fill_ruri_level_access_rc_vars($GLOBALS['WS_PLUGIN__']['s2member']['o']['level' . $n . '_ruris'], $user)) as $str) {
                                 if ($str && preg_match('/' . preg_quote($str, '/') . '/' . $ci, $cat_uri) && (!$check_user || !$user || !$user->has_cap('access_s2member_level' . $n))) {
                                     return apply_filters('ws_plugin__s2member_check_specific_catg_level_access', array('s2member_level_req' => $n), get_defined_vars());
                                 }
                             }
                         }
                     }
                 }
             }
             do_action('ws_plugin__s2member_during_check_specific_catg_level_access', get_defined_vars());
         }
     }
     return apply_filters('ws_plugin__s2member_check_specific_catg_level_access', NULL, get_defined_vars());
 }
Example #11
0
        ?>
</p>
<footer>
<span class="date">(<?php 
        echo date("Y/m/d", strtotime($item->post_date));
        ?>
)</span>
<?php 
        $category = get_the_category($item->ID);
        $color = "";
        foreach ($category as $key => $cat) {
            if ($cosmeCat->cat_ID == $cat->cat_ID || cat_is_ancestor_of($cosmeCat->cat_ID, $cat->cat_ID)) {
                $color = "yellow";
            } elseif ($troubleCat->cat_ID == $cat->cat_ID || cat_is_ancestor_of($troubleCat->cat_ID, $cat->cat_ID)) {
                $color = "blue";
            } elseif ($componentCat->cat_ID == $cat->cat_ID || cat_is_ancestor_of($componentCat->cat_ID, $cat->cat_ID)) {
                $color = "purple";
            }
        }
        ?>
<div class="tagMark <?php 
        echo $color;
        ?>
"><div><span><?php 
        if (isset($category[0])) {
            echo $category[0]->cat_name;
        }
        ?>
</span></div></div>
</footer>
</a></li>
Example #12
0
wpex_entry_thumbnail();
?>
	<h2><a href="<?php 
the_permalink();
?>
" title="<?php 
the_title();
?>
"><?php 
the_title();
?>
</a></h2>
	<div class="entry-text">
		<p>Style: <?php 
foreach (get_the_category() as $childcat) {
    if (cat_is_ancestor_of(186, $childcat)) {
        echo '<a href="' . get_category_link($childcat->cat_ID) . '">';
        echo $childcat->cat_name . '</a>';
    }
}
?>
</p>
        
        
        <p><?php 
the_tags('Mood: ', ', ');
?>
</p>
	</div><!-- /entry-text -->
	<?php 
wpex_hook_entry_bottom();
Example #13
0
 function is_category_or_sub($cat_id = 0)
 {
     foreach (get_the_category() as $cat) {
         if ($cat_id == $cat->cat_ID || cat_is_ancestor_of($cat_id, $cat)) {
             return true;
         }
     }
     return false;
 }
Example #14
0
 function events_get_listview_past_link()
 {
     global $spEvents;
     $mainEventsCat = $spEvents->eventCategory();
     $currentCat = get_query_var('cat');
     $cat_id = cat_is_ancestor_of($mainEventsCat, $currentCat) ? $currentCat : $mainEventsCat;
     $link = get_category_link($cat_id);
     if ('' == get_option('permalink_structure') || 'off' == eventsGetOptionValue('useRewriteRules', 'on')) {
         return add_query_arg(array('eventDisplay' => 'past'), $link);
     } else {
         return trailingslashit($link) . 'past';
     }
 }
Example #15
0
/**
 * Checks if a post is displayed on one column in full width
 *
 * @since Pinboard 1.0.6
 */
function pinboard_post_is_full_width() {
	global $pinboard_page_template;
	if( ( 'full-width' != pinboard_get_option( 'layout' ) && 'template-blog-full-width.php' != $pinboard_page_template && 'template-blog-four-col.php' != $pinboard_page_template && ! is_category( pinboard_get_option( 'portfolio_cat' ) ) && ! ( is_category() && cat_is_ancestor_of( pinboard_get_option( 'portfolio_cat' ), get_queried_object() ) ) ) || pinboard_is_teaser() )
		return false;
	return true;	
}
/**
 * Check if a category is an ancestor of another category.
 *
 * You can use either an id or the category object for both parameters. If you
 * use an integer the category will be retrieved.
 *
 * @since 2.1.0
 *
 * @param int|object $cat1 ID or object to check if this is the parent category.
 * @param int|object $cat2 The child category.
 * @return bool Whether $cat2 is child of $cat1
 */
function cat_is_ancestor_of($cat1, $cat2)
{
    if (is_int($cat1)) {
        $cat1 =& get_category($cat1);
    }
    if (is_int($cat2)) {
        $cat2 =& get_category($cat2);
    }
    if (!$cat1->term_id || !$cat2->parent) {
        return false;
    }
    if ($cat2->parent == $cat1->term_id) {
        return true;
    }
    return cat_is_ancestor_of($cat1, get_category($cat2->parent));
}
Example #17
0
function comicpress_all_comic_categories_array()
{
    global $comicpress_all_comic_categories_array;
    if (empty($comicpress_all_comic_categories_array)) {
        $comicpress_all_comic_categories_array[] = comicpress_themeinfo('comiccat');
        foreach (get_all_category_ids() as $cats) {
            if (cat_is_ancestor_of(comicpress_themeinfo('comiccat'), $cats)) {
                $comicpress_all_comic_categories_array[] = $cats;
            }
        }
    }
    return $comicpress_all_comic_categories_array;
}
Example #18
0
?>
</div>

<div class="tagLinks"><span>カテゴリ:</span>
<?php 
// list child categories
$this_cat = get_query_var('cat');
// get the category of this category archive page
$cat_id = $this_cat;
if (cat_is_ancestor_of($healthCat->cat_ID, get_query_var('cat'))) {
    $cat_id = $healthCat->cat_ID;
} elseif (cat_is_ancestor_of($cosmeCat->cat_ID, get_query_var('cat'))) {
    $cat_id = $cosmeCat->cat_ID;
} elseif (cat_is_ancestor_of($troubleCat->cat_ID, get_query_var('cat'))) {
    $cat_id = $troubleCat->cat_ID;
} elseif (cat_is_ancestor_of($componentCat->cat_ID, get_query_var('cat'))) {
    $cat_id = $componentCat->cat_ID;
}
$result = get_categories(array('child_of' => $cat_id));
// list child categories
foreach ($result as $key => $cat) {
    if ($cat->term_id == $this_cat) {
        echo '<a class="active" href="' . get_category_link($cat->term_id) . '">' . $cat->name . '</a>';
    } else {
        echo '<a  href="' . get_category_link($cat->term_id) . '">' . $cat->name . '</a>';
    }
}
?>

</div>
/**
 * Check if a category is an ancestor of another category.
 *
 * You can use either an id or the category object for both parameters. If you
 * use an integer the category will be retrieved.
 *
 * @since 2.1.0
 *
 * @param int|object $cat1 ID or object to check if this is the parent category.
 * @param int|object $cat2 The child category.
 * @return bool Whether $cat2 is child of $cat1
 */
function cat_is_ancestor_of($cat1, $cat2)
{
    if (!isset($cat1->term_id)) {
        $cat1 =& get_category($cat1);
    }
    if (!isset($cat2->parent)) {
        $cat2 =& get_category($cat2);
    }
    if (empty($cat1->term_id) || empty($cat2->parent)) {
        return false;
    }
    if ($cat2->parent == $cat1->term_id) {
        return true;
    }
    return cat_is_ancestor_of($cat1, get_category($cat2->parent));
}
Example #20
0
/**
 * The template for displaying archive pages.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package scientific_2016
 */
get_header();
?>

<div id="primary" class="content-area">
	<main id="main" class="site-main" role="main">

		<?php 
if (have_posts()) {
    if (cat_is_ancestor_of(ALL_ISSUES_CATEGORY_ID, get_query_var('cat'))) {
        // issues categories have a special layout
        get_template_part('category-one-issue');
    } else {
        $content_type = Scientific2016ContentType::Articles;
        if (is_tag(ARTICLES_TAG_SLUG)) {
            $content_type = Scientific2016ContentType::Articles;
        } elseif (is_tag(FAST_SCIENCE_TAG_SLUG)) {
            $content_type = Scientific2016ContentType::Fast_science;
        } elseif (is_tag(COLUMNS_OPINIONS_TAG_SLUG)) {
            $content_type = Scientific2016ContentType::Opinions;
        }
        set_query_var('content_type', $content_type);
        ?>

					<header class="page-header">
    ?>
				<?php 
    pinboard_post_thumbnail();
    ?>
			<?php 
}
?>
			<?php 
if (!is_category(pinboard_get_option('portfolio_cat')) && !cat_is_ancestor_of(pinboard_get_option('portfolio_cat'), get_queried_object())) {
    ?>
				<div class="entry-summary">
					<?php 
    pinboard_first_blockquote();
    ?>
				</div><!-- .entry-summary -->
			<?php 
}
?>
			<div class="clear"></div>
		</div><!-- .entry-container -->
		<?php 
if ('full-width' != pinboard_get_option('layout') && !is_category(pinboard_get_option('portfolio_cat')) && !(is_category() && cat_is_ancestor_of(pinboard_get_option('portfolio_cat'), get_queried_object()))) {
    ?>
			<?php 
    pinboard_entry_meta();
    ?>
		<?php 
}
?>
	</div><!-- .entry -->
</article><!-- .post -->
Example #22
0
 * @package WYSAC Wyoming Tobacco
 */
?>

<article id="post-<?php 
the_ID();
?>
" <?php 
post_class();
?>
>
	<header class="entry-header">
		<?php 
/* Get the Child Category and Print it only in Publications*/
foreach (get_the_category() as $childcat) {
    if (cat_is_ancestor_of(2, $childcat) && has_post_thumbnail()) {
        echo '<a class="category-label" href="' . get_category_link($childcat->cat_ID) . '">';
        echo $childcat->cat_name . '</a><br/>';
        echo the_post_thumbnail('entry-feature-large');
    } else {
        echo '<span class="post-format-label">' . get_post_format() . '</span>';
    }
}
?>
		<?php 
the_title('<h1 class="entry-title">', '</h1>');
?>
		<h2 class="entry-subtitle"><?php 
// display subtitle custom fields
global $wp_query;
$postid = $wp_query->post->ID;


		<?php 
// gets current category slug
/*
    if ( is_single() ) {
        $cats =  get_the_category();
        $cat = $cats[0];
    } else {
        $cat = get_category( get_query_var( 'cat' ) );
    }
    $cat_slug = $cat->slug;
*/
foreach (get_the_category() as $childcat) {
    if (cat_is_ancestor_of(31, $childcat)) {
        $childcat->cat_name;
        $subcat = $childcat->cat_name;
    }
}
$work_query = new WP_Query(array('post_type' => 'work', 'category_name' => $subcat, 'posts_per_page' => 12, 'orderby' => 'date', 'order' => 'DESC', 'paged' => $paged, 'post__not_in' => array(get_the_ID())));
if ($work_query->have_posts()) {
    ?>
		
		<?php 
    while ($work_query->have_posts()) {
        $work_query->the_post();
        ?>
		
		<span class="articleWrap">
				<article id="post-<?php 
Example #24
0
/**
 * Updates an existing Category or creates a new Category.
 *
 * @since 2.0.0
 *
 * @param mixed $catarr See defaults below. Set 'cat_ID' to a non-zero value to update an existing category. The 'taxonomy' key was added in 3.0.0.
 * @param bool $nxt_error Optional, since 2.5.0. Set this to true if the caller handles nxt_Error return values.
 * @return int|object The ID number of the new or updated Category on success.  Zero or a nxt_Error on failure, depending on param $nxt_error.
 */
function nxt_insert_category($catarr, $nxt_error = false)
{
    $cat_defaults = array('cat_ID' => 0, 'taxonomy' => 'category', 'cat_name' => '', 'category_description' => '', 'category_nicename' => '', 'category_parent' => '');
    $catarr = nxt_parse_args($catarr, $cat_defaults);
    extract($catarr, EXTR_SKIP);
    if (trim($cat_name) == '') {
        if (!$nxt_error) {
            return 0;
        } else {
            return new nxt_Error('cat_name', __('You did not enter a category name.'));
        }
    }
    $cat_ID = (int) $cat_ID;
    // Are we updating or creating?
    if (!empty($cat_ID)) {
        $update = true;
    } else {
        $update = false;
    }
    $name = $cat_name;
    $description = $category_description;
    $slug = $category_nicename;
    $parent = $category_parent;
    $parent = (int) $parent;
    if ($parent < 0) {
        $parent = 0;
    }
    if (empty($parent) || !category_exists($parent) || $cat_ID && cat_is_ancestor_of($cat_ID, $parent)) {
        $parent = 0;
    }
    $args = compact('name', 'slug', 'parent', 'description');
    if ($update) {
        $cat_ID = nxt_update_term($cat_ID, $taxonomy, $args);
    } else {
        $cat_ID = nxt_insert_term($cat_name, $taxonomy, $args);
    }
    if (is_nxt_error($cat_ID)) {
        if ($nxt_error) {
            return $cat_ID;
        } else {
            return 0;
        }
    }
    return $cat_ID['term_id'];
}
function wp_insert_category($catarr)
{
    global $wpdb;
    extract($catarr, EXTR_SKIP);
    if (trim($cat_name) == '') {
        return 0;
    }
    $cat_ID = (int) $cat_ID;
    // Are we updating or creating?
    if (!empty($cat_ID)) {
        $update = true;
    } else {
        $update = false;
    }
    $cat_name = apply_filters('pre_category_name', $cat_name);
    if (empty($category_nicename)) {
        $category_nicename = sanitize_title($cat_name);
    } else {
        $category_nicename = sanitize_title($category_nicename);
    }
    $category_nicename = apply_filters('pre_category_nicename', $category_nicename);
    if (empty($category_description)) {
        $category_description = '';
    }
    $category_description = apply_filters('pre_category_description', $category_description);
    $category_parent = (int) $category_parent;
    if (empty($category_parent) || !get_category($category_parent) || $cat_ID && cat_is_ancestor_of($cat_ID, $category_parent)) {
        $category_parent = 0;
    }
    if (isset($posts_private)) {
        $posts_private = (int) $posts_private;
    } else {
        $posts_private = 0;
    }
    if (isset($links_private)) {
        $links_private = (int) $links_private;
    } else {
        $links_private = 0;
    }
    if (!$update) {
        $wpdb->query("INSERT INTO {$wpdb->categories} (cat_ID, cat_name, category_nicename, category_description, category_parent, links_private, posts_private) VALUES ('0', '{$cat_name}', '{$category_nicename}', '{$category_description}', '{$category_parent}', '{$links_private}', '{$posts_private}')");
        $cat_ID = (int) $wpdb->insert_id;
    } else {
        $wpdb->query("UPDATE {$wpdb->categories} SET cat_name = '{$cat_name}', category_nicename = '{$category_nicename}', category_description = '{$category_description}', category_parent = '{$category_parent}', links_private = '{$links_private}', posts_private = '{$posts_private}' WHERE cat_ID = '{$cat_ID}'");
    }
    if ($category_nicename == '') {
        $category_nicename = sanitize_title($cat_name, $cat_ID);
        $wpdb->query("UPDATE {$wpdb->categories} SET category_nicename = '{$category_nicename}' WHERE cat_ID = '{$cat_ID}'");
    }
    // Keep in mind when using this filter and altering the cat_ID that the two queries above
    // have already taken place with the OLD cat_ID
    // Also note that you may have post2cat entries with the old cat_ID if this is an update
    if ($update) {
        do_action('edit_category', $cat_ID);
    } else {
        do_action('create_category', $cat_ID);
        do_action('add_category', $cat_ID);
    }
    $cat_ID = apply_filters('cat_id_filter', $cat_ID, $update);
    clean_category_cache($cat_ID);
    if ($update) {
        do_action('edited_category', $cat_ID);
    } else {
        do_action('created_category', $cat_ID);
    }
    return $cat_ID;
}
Example #26
0
function if_restrict_categories($categories)
{
    global $current_user;
    get_currentuserinfo();
    $a = get_cat_if_user_lang($current_user->ID);
    $onPostPage = strpos($_SERVER['PHP_SELF'], 'edit-tags.php');
    if (is_admin() && $onPostPage && !current_user_can('level_10')) {
        //if (is_admin() && $onPostPage) {
        $size = count($categories);
        for ($i = 0; $i < $size; $i++) {
            if (is_object($categories[$i])) {
                //if($categories[$i]->parent != $a && $categories[$i]->term_id != $a){
                if (!cat_is_ancestor_of($a, $categories[$i]->term_id) && $categories[$i]->term_id != $a) {
                    unset($categories[$i]);
                }
            }
        }
    }
    return $categories;
}
	/**
	 * @group category.php
	 */
	function test_term_is_ancestor_of( ) {
		$term = rand_str();
		$term2 = rand_str();

		$t = wp_insert_term( $term, 'category' );
		$this->assertInternalType( 'array', $t );
		$t2 = wp_insert_term( $term, 'category', array( 'parent' => $t['term_id'] ) );
		$this->assertInternalType( 'array', $t2 );
		if ( function_exists( 'term_is_ancestor_of' ) ) {
			$this->assertTrue( term_is_ancestor_of( $t['term_id'], $t2['term_id'], 'category' ) );
			$this->assertFalse( term_is_ancestor_of( $t2['term_id'], $t['term_id'], 'category' ) );
		}
		$this->assertTrue( cat_is_ancestor_of( $t['term_id'], $t2['term_id']) );
		$this->assertFalse( cat_is_ancestor_of( $t2['term_id'], $t['term_id']) );

		wp_delete_term($t['term_id'], 'category');
		wp_delete_term($t2['term_id'], 'category');
	}
function has_children_cat($parent_id)
{
    # Brute force approach, but I don't see any other way with the standard
    # wp functions. --M.Morse
    $category_ids = get_all_category_ids();
    foreach ($category_ids as $cat_id) {
        if ($cat_id == $parent_id) {
            continue;
        }
        if (cat_is_ancestor_of($parent_id, $cat_id)) {
            return 1;
        }
    }
    return 0;
}
Example #29
0
 function in_subcat($blogcat, $current_cat = '')
 {
     $in_subcategory = false;
     if (cat_is_ancestor_of($blogcat, $current_cat) || $blogcat == $current_cat) {
         $in_subcategory = true;
     }
     return $in_subcategory;
 }
<div id="content">
	<div class="hfeed">
		<?php 
if (!empty($primary_category)) {
    ?>

			<!-- Begin category section. -->
			<div id="category-highlight">

			<?php 
    /* We need to first get the blog category IDs. Category IDs are stored inside a stdClass object.
    			/* Let's cycle through get_categories() and place into an array the IDs of categories that are either the primary
    			/* featured category OR categories that are children of the primary featured category. */
    foreach (get_categories() as $object) {
        if (cat_is_ancestor_of($primary_category, $object->term_id) || $object->term_id == $primary_category) {
            array_push($categories, $object->term_id);
        }
    }
    /* Now that we have our featured categories, let's display their posts in a nice
    			/* news-like block. We're listing categories in alphabetical order and
    			/* will display up to 6 posts in each block. If a post has already appeared in the slider, it WON'T
    			/* be duplicated here. */
    foreach ($categories as $cat) {
        $loop = new WP_Query(array('category__in' => $cat, 'posts_per_page' => 6, 'post__not_in' => $do_not_duplicate));
        if ($loop->have_posts()) {
            ?>
						<div class="section category-section">
							<div class="section-wrap category-section-wrap">

							<?php