Plugin Directory

Changeset 1119133


Ignore:
Timestamp:
03/23/2015 08:19:17 PM (11 years ago)
Author:
george_michael
Message:

Bug fix for redirect and browser cache issue. 1.2.0. Also tagged support for WP 4.1.1

Location:
simple-permissions
Files:
2 edited
3 copied

Legend:

Unmodified
Added
Removed
  • simple-permissions/tags/1.2.0/readme.txt

    r1085570 r1119133  
    44Tags:
    55Requires at least: 3.5.2
    6 Tested up to: 4.1.0
    7 Stable tag: 1.1.4
     6Tested up to: 4.1.1
     7Stable tag: 1.2.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3434
    3535== Changelog ==
     36
     37= 1.2.0 =
     38* Fixed (hopefully!) an issue where you would not be redirected to the proper page after login when presented with a protected page notice. I'm getting around this by not redirecting at all. Instead, I'm replacing the requested pages content with the content of the protected page notice.
    3639
    3740= 1.1.4 =
     
    6467== Upgrade Notice ==
    6568
     69= 1.2.0 =
     70* Pretty significant bug fix. Upgrade suggested.
     71
    6672= 1.1.4 =
    6773* Minor bug fix. Upgrade if you were having trouble auto saving drafts.
  • simple-permissions/tags/1.2.0/simple-permissions.php

    r1085570 r1119133  
    22/**
    33 * @package Simple-Permissions
    4  * @version 1.1.4
     4 * @version 1.2.0
    55 */
    66/*
     
    99Description: Create simple permission groups for reading or editing posts.
    1010Author: Michael George
    11 Version: 1.1.4
     11Version: 1.2.0
    1212
    1313    This program is free software; you can redistribute it and/or modify
     
    169169        //                        [2] Associated object ID
    170170        function spUserCanDo( $allcaps, $cap, $args ) {
     171            //error_log( "userCanDo cap: " . print_r( $cap, true ) . " args: " . print_r( $args, true ) );
    171172            $protectedOperations = array(
    172173                                        'delete_page'
     
    180181            //if we are not checking for a specific post, do nothing
    181182            if ( ! isset( $args[2] ) || ! is_numeric( $args[2] ) ) {
    182                 error_log( "here" );
    183183                return $allcaps;
    184184            }
     
    186186            //Bail out if operation isn't protected
    187187            if ( ! in_array( $args[0], $protectedOperations ) ) {
    188                 error_log( "here2" );
    189188                return $allcaps;
    190189            }
     
    193192            //available to admins and super admins
    194193            if ( $allcaps['activate_plugins'] ) {
    195                 error_log( "here3" );
    196194                return $allcaps;
    197195            }
     
    243241        }
    244242
     243        //Since 1.2.0
     244        //Re-wrote this function as I was seeing wonky things with browswers not actually giving up cached
     245        //versions of the redirect page. When someone would hit a protected page, they could then login, but
     246        //the browser would navigate back to the protected warning because that's what it did last time, so
     247        //why would it be different this time?
     248        //My solution is to override the content of the post with the content of the protection page.
    245249        function spOverride404() {
    246250            global $wp_query;
     
    253257                $postid = url_to_postid( "http" . ( isset($_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] != 'off' ? "s" : "" ) . "://" . $_SERVER["SERVER_NAME"] . $_SERVER['REQUEST_URI'] );
    254258                if ( $postid != 0 ) {
    255                     $redirecturl = get_permalink( $devOptions['redirectPageID'] );
    256                     if ( $redirecturl !== false ) {
    257                         $is404Check = false;
    258                         wp_redirect( $redirecturl, 301 );
    259                         exit;
    260                     }
    261                 }
    262             }
     259                    $is404Check = false;
     260                    $redirectID = $devOptions['redirectPageID'];
     261                    //error_log( "redirectID: $redirectID" );
     262                    if ( ! empty( $redirectID ) && is_numeric( $redirectID ) ) {
     263                        $redirectPost = get_post( $redirectID );
     264                        $wp_query->is_404 = false;
     265                        $wp_query->is_single = true;
     266                        $wp_query->found_posts = 1;
     267                        $redirectPost = get_post( $devOptions['redirectPageID'] );
     268                        $post->post_content_filtered = apply_filters( 'the_content', $redirectPost->post_content );
     269                        $post = get_post( $postid );
     270                        $post->post_content = $redirectPost->post_content;
     271                        $post->comment_status = 'closed';
     272                        $post->comment_count = 0;
     273                        $post->ID = $devOptions['redirectPageID'];
     274                        $wp_query->posts[] = $post;
     275                        $wp_query->post = $post;
     276                        $wp_query->in_the_loop = true;
     277                        $wp_query->current_post = -1;
     278                        $wp_query->comment_count = 0;
     279                        $wp_query->post_count = 1;
     280                    } else {
     281                        //error_log( "empty: " . print_r( ! empty( $redirectID ), true ) . " - numeric: " . print_r( is_numeric( $redirectID ), true ) );
     282                        //If no page id is specified in the SP settings, then let the standard 404 action happen
     283                        //This may be affected by themes or other plugins
     284                    }
     285                }
     286            }
     287        }
     288
     289        function spCustom404( $standard_404 ) {
     290            global $wp_query;
     291            global $post;
     292            global $is404Check;
     293
     294            if ( $wp_query->is_404 == true ) {
     295                $is404Check = true;
     296                $devOptions = $this->spGetAdminOptions();
     297                $postid = url_to_postid( "http" . ( isset($_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] != 'off' ? "s" : "" ) . "://" . $_SERVER["SERVER_NAME"] . $_SERVER['REQUEST_URI'] );
     298                if ( $postid != 0 ) {
     299                    $redirectPost = get_post( $devOptions['redirectPageID'] );
     300                    $post->post_content = apply_filters( 'the_content', $redirectPost->post_content );
     301                    error_log( "post2: " . print_r( $post, true ) );
     302                    return ( "echo \"" . $post->post_content . "\";" );
     303                }
     304            }
     305
     306            return $standard_404;
    263307        }
    264308
  • simple-permissions/trunk/readme.txt

    r1085570 r1119133  
    44Tags:
    55Requires at least: 3.5.2
    6 Tested up to: 4.1.0
    7 Stable tag: 1.1.4
     6Tested up to: 4.1.1
     7Stable tag: 1.2.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3434
    3535== Changelog ==
     36
     37= 1.2.0 =
     38* Fixed (hopefully!) an issue where you would not be redirected to the proper page after login when presented with a protected page notice. I'm getting around this by not redirecting at all. Instead, I'm replacing the requested pages content with the content of the protected page notice.
    3639
    3740= 1.1.4 =
     
    6467== Upgrade Notice ==
    6568
     69= 1.2.0 =
     70* Pretty significant bug fix. Upgrade suggested.
     71
    6672= 1.1.4 =
    6773* Minor bug fix. Upgrade if you were having trouble auto saving drafts.
  • simple-permissions/trunk/simple-permissions.php

    r1085570 r1119133  
    22/**
    33 * @package Simple-Permissions
    4  * @version 1.1.4
     4 * @version 1.2.0
    55 */
    66/*
     
    99Description: Create simple permission groups for reading or editing posts.
    1010Author: Michael George
    11 Version: 1.1.4
     11Version: 1.2.0
    1212
    1313    This program is free software; you can redistribute it and/or modify
     
    169169        //                        [2] Associated object ID
    170170        function spUserCanDo( $allcaps, $cap, $args ) {
     171            //error_log( "userCanDo cap: " . print_r( $cap, true ) . " args: " . print_r( $args, true ) );
    171172            $protectedOperations = array(
    172173                                        'delete_page'
     
    180181            //if we are not checking for a specific post, do nothing
    181182            if ( ! isset( $args[2] ) || ! is_numeric( $args[2] ) ) {
    182                 error_log( "here" );
    183183                return $allcaps;
    184184            }
     
    186186            //Bail out if operation isn't protected
    187187            if ( ! in_array( $args[0], $protectedOperations ) ) {
    188                 error_log( "here2" );
    189188                return $allcaps;
    190189            }
     
    193192            //available to admins and super admins
    194193            if ( $allcaps['activate_plugins'] ) {
    195                 error_log( "here3" );
    196194                return $allcaps;
    197195            }
     
    243241        }
    244242
     243        //Since 1.2.0
     244        //Re-wrote this function as I was seeing wonky things with browswers not actually giving up cached
     245        //versions of the redirect page. When someone would hit a protected page, they could then login, but
     246        //the browser would navigate back to the protected warning because that's what it did last time, so
     247        //why would it be different this time?
     248        //My solution is to override the content of the post with the content of the protection page.
    245249        function spOverride404() {
    246250            global $wp_query;
     
    253257                $postid = url_to_postid( "http" . ( isset($_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] != 'off' ? "s" : "" ) . "://" . $_SERVER["SERVER_NAME"] . $_SERVER['REQUEST_URI'] );
    254258                if ( $postid != 0 ) {
    255                     $redirecturl = get_permalink( $devOptions['redirectPageID'] );
    256                     if ( $redirecturl !== false ) {
    257                         $is404Check = false;
    258                         wp_redirect( $redirecturl, 301 );
    259                         exit;
    260                     }
    261                 }
    262             }
     259                    $is404Check = false;
     260                    $redirectID = $devOptions['redirectPageID'];
     261                    //error_log( "redirectID: $redirectID" );
     262                    if ( ! empty( $redirectID ) && is_numeric( $redirectID ) ) {
     263                        $redirectPost = get_post( $redirectID );
     264                        $wp_query->is_404 = false;
     265                        $wp_query->is_single = true;
     266                        $wp_query->found_posts = 1;
     267                        $redirectPost = get_post( $devOptions['redirectPageID'] );
     268                        $post->post_content_filtered = apply_filters( 'the_content', $redirectPost->post_content );
     269                        $post = get_post( $postid );
     270                        $post->post_content = $redirectPost->post_content;
     271                        $post->comment_status = 'closed';
     272                        $post->comment_count = 0;
     273                        $post->ID = $devOptions['redirectPageID'];
     274                        $wp_query->posts[] = $post;
     275                        $wp_query->post = $post;
     276                        $wp_query->in_the_loop = true;
     277                        $wp_query->current_post = -1;
     278                        $wp_query->comment_count = 0;
     279                        $wp_query->post_count = 1;
     280                    } else {
     281                        //error_log( "empty: " . print_r( ! empty( $redirectID ), true ) . " - numeric: " . print_r( is_numeric( $redirectID ), true ) );
     282                        //If no page id is specified in the SP settings, then let the standard 404 action happen
     283                        //This may be affected by themes or other plugins
     284                    }
     285                }
     286            }
     287        }
     288
     289        function spCustom404( $standard_404 ) {
     290            global $wp_query;
     291            global $post;
     292            global $is404Check;
     293
     294            if ( $wp_query->is_404 == true ) {
     295                $is404Check = true;
     296                $devOptions = $this->spGetAdminOptions();
     297                $postid = url_to_postid( "http" . ( isset($_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] != 'off' ? "s" : "" ) . "://" . $_SERVER["SERVER_NAME"] . $_SERVER['REQUEST_URI'] );
     298                if ( $postid != 0 ) {
     299                    $redirectPost = get_post( $devOptions['redirectPageID'] );
     300                    $post->post_content = apply_filters( 'the_content', $redirectPost->post_content );
     301                    error_log( "post2: " . print_r( $post, true ) );
     302                    return ( "echo \"" . $post->post_content . "\";" );
     303                }
     304            }
     305
     306            return $standard_404;
    263307        }
    264308
Note: See TracChangeset for help on using the changeset viewer.