Exemplo n.º 1
0
 /**
  * Filter all WordPress queries.
  *
  * optimizeMember respects the query var: `suppress_filters`. 
  * If you need to make a query without it being Filtered, use  ``$wp_query->set ("suppress_filters", true);``.
  *
  * @package optimizeMember\Queries
  * @since 3.5
  *
  * @attaches-to ``add_action("pre_get_posts");``
  *
  * @param obj $wp_query Expects ``$wp_query`` by reference, from the Filter.
  * @param bool $force Optional. Defaults to false. If true, we bypass all standard conditions.
  * 	However, optimizeMember will NEVER bypass `supress_filters`.
  * @return null
  *
  * @todo For improved reliability, modify other query vars associated with exclusions/inclusions. Like `tag_slug__in`?
  * 	See: {@link http://codex.wordpress.org/Class_Reference/WP_Query#Parameters WP_Query#Parameters}
  * @todo Make it possible to force filtering, even when used in combination with Query Conditionals and ``get_posts()``, which auto-supresses.
  * 	Or, perhaps strengthen the existing ``$force`` parameter in this regard.
  */
 public static function query_level_access(&$wp_query = FALSE, $force = FALSE)
 {
     global $wpdb;
     /* Need this global DB object reference here. */
     static $initial_query = true;
     /* Tracks the initial query. */
     c_ws_plugin__optimizemember_querys::$current_wp_query =& $wp_query;
     /**/
     eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
     do_action("ws_plugin__optimizemember_before_query_level_access", get_defined_vars());
     unset($__refs, $__v);
     /* Unset defined __refs, __v. */
     /**/
     c_ws_plugin__optimizemember_querys::_query_level_access_sys($wp_query);
     /* Systematics. */
     /**/
     remove_filter("comment_feed_where", "c_ws_plugin__optimizemember_querys::_query_level_access_coms", 100, 2);
     remove_filter("wp_get_nav_menu_items", "c_ws_plugin__optimizemember_querys::_query_level_access_navs", 100);
     /**/
     if (is_object($wpdb) && is_object($wp_query) && (($o = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["filter_wp_query"]) || $force)) {
         if (!is_admin() || c_ws_plugin__optimizemember_querys::_is_admin_ajax_search($wp_query)) {
             $suppressing_filters = $wp_query->get("suppress_filters");
             /* Filter suppression on? */
             if (!$suppressing_filters && $force || !$suppressing_filters && in_array("all", $o) && !($initial_query && $wp_query->is_singular()) || !$suppressing_filters && (in_array("all", $o) || in_array("searches", $o)) && $wp_query->is_search() || !$suppressing_filters && (in_array("all", $o) || in_array("feeds", $o)) && $wp_query->is_feed() && !$wp_query->is_comment_feed() || !$suppressing_filters && (in_array("all", $o) || in_array("comment-feeds", $o)) && $wp_query->is_feed() && $wp_query->is_comment_feed() || $suppressing_filters !== "n/a" && (in_array("all", $o) || in_array("nav-menus", $o)) && in_array("wp_get_nav_menu_items", $callers = isset($callers) ? $callers : c_ws_plugin__optimizemember_utilities::callers())) {
                 if (!$suppressing_filters && (in_array("all", $o) || in_array("comment-feeds", $o)) && $wp_query->is_feed() && $wp_query->is_comment_feed()) {
                     add_filter("comment_feed_where", "c_ws_plugin__optimizemember_querys::_query_level_access_coms", 100, 2);
                 }
                 /**/
                 if ($suppressing_filters !== "n/a" && (in_array("all", $o) || in_array("nav-menus", $o))) {
                     /* Suppression irrelevant here. */
                     if (in_array("wp_get_nav_menu_items", $callers = isset($callers) ? $callers : c_ws_plugin__optimizemember_utilities::callers())) {
                         add_filter("wp_get_nav_menu_items", "c_ws_plugin__optimizemember_querys::_query_level_access_navs", 100);
                     }
                 }
                 /**/
                 if (is_user_logged_in() && is_object($user = wp_get_current_user()) && !empty($user->ID) && ($user_id = $user->ID) || !($user = false)) {
                     if (!$user && ($_lwp = (int) $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["login_welcome_page"])) {
                         $wp_query->set("post__in", array_unique(array_diff(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__in")), array($_lwp))));
                         $wp_query->set("post__not_in", array_unique(array_merge(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__not_in")), array($_lwp))));
                     }
                     /**/
                     if (!$user && ($_dep = (int) $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["file_download_limit_exceeded_page"])) {
                         $wp_query->set("post__in", array_unique(array_diff(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__in")), array($_dep))));
                         $wp_query->set("post__not_in", array_unique(array_merge(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__not_in")), array($_dep))));
                     }
                     /**/
                     if (is_array($_ccaps = c_ws_plugin__optimizemember_utils_gets::get_unavailable_singular_ids_with_ccaps($user)) && !empty($_ccaps)) {
                         $wp_query->set("post__in", array_unique(array_diff(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__in")), $_ccaps)));
                         $wp_query->set("post__not_in", array_unique(array_merge(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__not_in")), $_ccaps)));
                     }
                     /**/
                     if (is_array($_drips = c_ws_plugin__optimizemember_utils_gets::get_unavailable_singular_ids_with_dripped_content($user)) && !empty($_drips)) {
                         $wp_query->set("post__in", array_unique(array_diff(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__in")), $_drips)));
                         $wp_query->set("post__not_in", array_unique(array_merge(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__not_in")), $_drips)));
                     }
                     /**/
                     if (is_array($_sps = c_ws_plugin__optimizemember_utils_gets::get_unavailable_singular_ids_with_sp()) && !empty($_sps)) {
                         $wp_query->set("post__in", array_unique(array_diff(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__in")), $_sps)));
                         $wp_query->set("post__not_in", array_unique(array_merge(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__not_in")), $_sps)));
                     }
                     unset($_lwp, $_dep, $_ccaps, $_sps, $_drips);
                     /**/
                     for ($n = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["levels"]; $n >= 0; $n--) {
                         if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_catgs"] === "all" && (!$user || !current_user_can("access_optimizemember_level" . $n))) {
                             $wp_query->set("category__in", array());
                             /* Include no other Categories. */
                             $wp_query->set("category__not_in", $_catgs = c_ws_plugin__optimizemember_utils_gets::get_all_category_ids());
                             $wp_query->set("post__not_in", array_unique(array_merge(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__not_in")), $_singulars = c_ws_plugin__optimizemember_utils_gets::get_singular_ids_in_terms($_catgs))));
                             $wp_query->set("post__in", array_unique(array_diff(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__in")), $_singulars)));
                             break;
                             /* All Categories will be locked down. */
                         } else {
                             if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_catgs"] && (!$user || !current_user_can("access_optimizemember_level" . $n))) {
                                 foreach ($_catgs = preg_split("/[\r\n\t\\s;,]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_catgs"]) as $_catg) {
                                     $_catgs = array_merge($_catgs, c_ws_plugin__optimizemember_utils_gets::get_all_child_category_ids($_catg));
                                 }
                                 /**/
                                 $wp_query->set("category__in", array_unique(array_diff(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("category__in")), $_catgs)));
                                 $wp_query->set("category__not_in", array_unique(array_merge(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("category__not_in")), $_catgs)));
                                 $wp_query->set("post__not_in", array_unique(array_merge(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__not_in")), $_singulars = c_ws_plugin__optimizemember_utils_gets::get_singular_ids_in_terms($_catgs))));
                                 $wp_query->set("post__in", array_unique(array_diff(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__in")), $_singulars)));
                             }
                         }
                     }
                     unset($_catgs, $_catg, $_singulars);
                     /**/
                     for ($n = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["levels"]; $n >= 0; $n--) {
                         if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_ptags"] === "all" && (!$user || !current_user_can("access_optimizemember_level" . $n))) {
                             $wp_query->set("tag__in", array());
                             /* Include no other Tags. */
                             $wp_query->set("tag__not_in", $_tags = c_ws_plugin__optimizemember_utils_gets::get_all_tag_ids());
                             $wp_query->set("post__not_in", array_unique(array_merge(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__not_in")), $_singulars = c_ws_plugin__optimizemember_utils_gets::get_singular_ids_in_terms($_tags))));
                             $wp_query->set("post__in", array_unique(array_diff(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__in")), $_singulars)));
                             break;
                             /* ALL Tags will be locked down. */
                         } else {
                             if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_ptags"] && (!$user || !current_user_can("access_optimizemember_level" . $n))) {
                                 $_tags = c_ws_plugin__optimizemember_utils_gets::get_tags_converted_to_ids($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_ptags"]);
                                 /**/
                                 $wp_query->set("tag__in", array_unique(array_diff(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("tag__in")), $_tags)));
                                 $wp_query->set("tag__not_in", array_unique(array_merge(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("tag__not_in")), $_tags)));
                                 $wp_query->set("post__not_in", array_unique(array_merge(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__not_in")), $_singulars = c_ws_plugin__optimizemember_utils_gets::get_singular_ids_in_terms($_tags))));
                                 $wp_query->set("post__in", array_unique(array_diff(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__in")), $_singulars)));
                             }
                         }
                     }
                     unset($_tags, $_tag, $_singulars);
                     /**/
                     for ($n = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["levels"]; $n >= 0; $n--) {
                         if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_posts"] === "all" && (!$user || !current_user_can("access_optimizemember_level" . $n))) {
                             $wp_query->set("post__in", array_unique(array_diff(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__in")), $_posts = c_ws_plugin__optimizemember_utils_gets::get_all_post_ids())));
                             $wp_query->set("post__not_in", array_unique(array_merge(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__not_in")), $_posts)));
                             break;
                             /* ALL Posts will be locked down. */
                         } else {
                             if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_posts"] && (!$user || !current_user_can("access_optimizemember_level" . $n))) {
                                 foreach ($_posts = preg_split("/[\r\n\t\\s;,]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_posts"]) as $_p) {
                                     if (strpos($_p, "all-") === 0 && preg_match("/^all-(.+)\$/", $_p, $_m)) {
                                         if (is_array($_p_of_type = c_ws_plugin__optimizemember_utils_gets::get_all_post_ids($_m[1])) && !empty($_p_of_type)) {
                                             $_posts = array_merge($_posts, $_p_of_type);
                                         }
                                     }
                                 }
                                 /**/
                                 $_posts = array_unique(c_ws_plugin__optimizemember_utils_arrays::force_integers($_posts));
                                 /**/
                                 $wp_query->set("post__in", array_unique(array_diff(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__in")), $_posts)));
                                 $wp_query->set("post__not_in", array_unique(array_merge(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__not_in")), $_posts)));
                             }
                         }
                     }
                     unset($_posts, $_p, $_m, $_p_of_type);
                     /**/
                     for ($n = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["levels"]; $n >= 0; $n--) {
                         if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_pages"] === "all" && (!$user || !current_user_can("access_optimizemember_level" . $n))) {
                             $wp_query->set("post__in", array_unique(array_diff(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__in")), $_pages = c_ws_plugin__optimizemember_utils_gets::get_all_page_ids())));
                             $wp_query->set("post__not_in", array_unique(array_merge(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__not_in")), $_pages)));
                             break;
                             /* ALL Pages will be locked down. */
                         } else {
                             if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_pages"] && (!$user || !current_user_can("access_optimizemember_level" . $n))) {
                                 $_pages = c_ws_plugin__optimizemember_utils_arrays::force_integers(preg_split("/[\r\n\t\\s;,]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_pages"]));
                                 /**/
                                 $wp_query->set("post__in", array_unique(array_diff(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__in")), $_pages)));
                                 $wp_query->set("post__not_in", array_unique(array_merge(c_ws_plugin__optimizemember_utils_arrays::force_integers((array) $wp_query->get("post__not_in")), $_pages)));
                             }
                         }
                     }
                     unset($_pages);
                 }
                 /**/
                 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
                 do_action("ws_plugin__optimizemember_during_query_level_access", get_defined_vars());
                 unset($__refs, $__v);
                 /* Unset defined __refs, __v. */
             }
         }
     }
     /**/
     eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
     do_action("ws_plugin__optimizemember_after_query_level_access", get_defined_vars());
     unset($__refs, $__v);
     /* Unset defined __refs, __v. */
     /**/
     $initial_query = false;
     /* No longer. */
     /**/
     return;
     /* For uniformity. */
 }