diff --git a/wp-content/themes/score/functions.php b/wp-content/themes/score/functions.php index b607f9c..66853b1 100644 --- a/wp-content/themes/score/functions.php +++ b/wp-content/themes/score/functions.php @@ -701,9 +701,12 @@ function make_encoded_dedications_visible_for_nonusers($visibility) { add_filter('pbp_login_required_check', 'make_encoded_dedications_visible_for_nonusers', 1); function gp_encoded_dedication_redirect_for_nonusers($current_uri, $redirect_to) { + $args = array(); wp_parse_str($_SERVER['QUERY_STRING'], $args); + if (key_exists('refid', $args)) { setcookie("refid", 1, time()+60, SITECOOKIEPATH); // Cookie con 1 minuto de validez + $decoded_url = bp_dedication_decode($args['refid']); if (key_exists('y', $args)) { $decoded_url = add_query_arg('fs', 2, $decoded_url); // Para usuarios que están registrados @@ -718,8 +721,10 @@ add_filter('pbp_redirect_login_page', 'gp_encoded_dedication_redirect_for_nonuse function gp_encoded_dedication_redirect_for_users() { + $args = array(); if ( true == is_user_logged_in() ) { - wp_parse_str($_SERVER['QUERY_STRING'], $args); + wp_parse_str($_SERVER['QUERY_STRING'], $args); + if (key_exists('refid', $args)) { $decoded_url = bp_dedication_decode($args['refid']); if (key_exists('y', $args)) { @@ -727,12 +732,36 @@ function gp_encoded_dedication_redirect_for_users() { } else { $decoded_url = add_query_arg('fs', 1, $decoded_url); // Para usuarios no registrados } + wp_redirect($decoded_url); } } } add_action('wp', 'gp_encoded_dedication_redirect_for_users', 2); +function gp_encoded_private_dedication_specials($posts = array()) { + global $wp_query; + + if ($wp_query->is_single && $wp_query->is_singular && $wp_query->query_vars && $posts) { + /* TODO: do we need to ensure wp_query->query_vars['post_type'] == $_first_post->post_type ? */ + $_first_post = reset($posts); + + /* the hack: only do this if it is of type special and the status is draft */ + if ($_first_post->post_status == 'private') { + $wp_query->post = $_first_post; /* quick and dirty hack so that you don't get a 404 */ + $wp_query->post->post_status = 'publish'; + + $wp_query->post_count = sizeof($posts); /* these 3 lines probably aren't necessary */ + $wp_query->found_posts = sizeof($posts); + $wp_query->is_404 = false; + } + } + return $posts; +} + +if (!is_admin() && isset($_COOKIE['refid'])) { + add_filter('posts_results', 'gp_encoded_private_dedication_specials'); +} function asociate_dedications_to_new_user($user_id) {