Plugin Directory

Changeset 1664767


Ignore:
Timestamp:
05/25/2017 02:37:58 PM (9 years ago)
Author:
GregLone
Message:

Move Login 2.5.2.

Location:
sf-move-login/trunk
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • sf-move-login/trunk/inc/activate.php

    r1622279 r1664767  
    1313 */
    1414function sfml_activate() {
    15     global $is_apache, $is_iis7;
    16 
    17     $is_nginx = sfml_is_nginx();
    18     $dies     = array();
     15    $dies = array();
    1916
    2017    // The plugin needs the request URI.
     
    2421
    2522    // Apache.
    26     if ( $is_apache ) {
     23    if ( sfml_is_apache() ) {
    2724        require_once( ABSPATH . WPINC . '/functions.php' );
    2825
     
    3229    }
    3330    // IIS7.
    34     elseif ( $is_iis7 ) {
     31    elseif ( sfml_is_iis7() ) {
    3532        require_once( ABSPATH . 'wp-admin/includes/misc.php' );
    3633
     
    4037    }
    4138    // None.
    42     elseif ( ! $is_iis7 && ! $is_apache && ! $is_nginx ) {
     39    elseif ( ! sfml_is_iis7() && ! sfml_is_apache() && ! sfml_is_nginx() ) {
    4340        $dies[] = 'error_unknown_server_conf';
    4441    }
     
    105102 */
    106103function sfml_notice_message( $message_id ) {
    107     global $is_iis7;
    108104    static $messages;
    109105
    110     if ( ! isset( $messages ) ) {
    111         $file = $is_iis7 ? '<code>web.config</code>' : '<code>.htaccess</code>';
    112         $link = '<a href="' . esc_url( is_multisite() ? network_admin_url( 'settings.php?page=move-login' ) : admin_url( 'options-general.php?page=move-login' ) ) . '">Move Login</a>';
     106    if ( isset( $messages ) ) {
     107        return isset( $messages[ $message_id ] ) ? $messages[ $message_id ] : '';
     108    }
    113109
    114         $messages = array(
    115             /** Translators: 1 is the plugin name. */
    116             'error_no_request_uri'      => sprintf( __( 'It seems your server configuration prevents the plugin to work properly. %s won\'t work.', 'sf-move-login' ), '<strong>Move Login</strong>' ),
    117             /** Translators: 1 is the plugin name. */
    118             'error_no_mod_rewrite'      => sprintf( __( 'It seems the url rewrite module is not activated on your server. %s won\'t work.', 'sf-move-login' ), '<strong>Move Login</strong>' ),
    119             /** Translators: 1, 2, and 3 are server technologies (Apache, Nginx, IIS7), 4 is the plugin name. */
    120             'error_unknown_server_conf' => sprintf( __( 'It seems your server does not use %1$s, %2$s, nor %3$s. %4$s won\'t work.', 'sf-move-login' ), '<i>Apache</i>', '<i>Nginx</i>', '<i>IIS7</i>', '<strong>Move Login</strong>' ),
    121             /** Translators: 1 is the plugin name, 2 is a file name, 3 is a "Move Login" link. */
    122             'error_file_not_writable'   => sprintf( __( '%1$s needs access to the %2$s file. Please visit the %3$s settings page and copy/paste the given code into the %2$s file.', 'sf-move-login' ), '<strong>Move Login</strong>', $file, $link ),
    123             /** Translators: 1 is a server technology (Nginx), 2 is a "Move Login" link, 3 is the plugin name. */
    124             'updated_is_nginx'          => sprintf( __( 'It seems your server uses a %1$ system. You have to edit the rewrite rules by yourself in the configuration file. Please visit the %2$s settings page and take a look at the rewrite rules. %3$s is running but won\'t work correctly until you deal with those rewrite rules.', 'sf-move-login' ), '<i>Nginx</i>', $link, '<strong>Move Login</strong>' ),
    125         );
    126     }
     110    $file = sfml_is_iis7() ? '<code>web.config</code>' : '<code>.htaccess</code>';
     111    $link = '<a href="' . esc_url( is_multisite() ? network_admin_url( 'settings.php?page=move-login' ) : admin_url( 'options-general.php?page=move-login' ) ) . '">Move Login</a>';
     112
     113    $messages = array(
     114        /** Translators: 1 is the plugin name. */
     115        'error_no_request_uri'      => sprintf( __( 'It seems your server configuration prevents the plugin to work properly. %s won\'t work.', 'sf-move-login' ), '<strong>Move Login</strong>' ),
     116        /** Translators: 1 is the plugin name. */
     117        'error_no_mod_rewrite'      => sprintf( __( 'It seems the url rewrite module is not activated on your server. %s won\'t work.', 'sf-move-login' ), '<strong>Move Login</strong>' ),
     118        /** Translators: 1, 2, and 3 are server technologies (Apache, Nginx, IIS7), 4 is the plugin name. */
     119        'error_unknown_server_conf' => sprintf( __( 'It seems your server does not use %1$s, %2$s, nor %3$s. %4$s won\'t work.', 'sf-move-login' ), '<i>Apache</i>', '<i>Nginx</i>', '<i>IIS7</i>', '<strong>Move Login</strong>' ),
     120        /** Translators: 1 is the plugin name, 2 is a file name, 3 is a "Move Login" link. */
     121        'error_file_not_writable'   => sprintf( __( '%1$s needs access to the %2$s file. Please visit the %3$s settings page and copy/paste the given code into the %2$s file.', 'sf-move-login' ), '<strong>Move Login</strong>', $file, $link ),
     122        /** Translators: 1 is a server technology (Nginx), 2 is a "Move Login" link, 3 is the plugin name. */
     123        'updated_is_nginx'          => sprintf( __( 'It seems your server uses a %1$ system. You have to edit the rewrite rules by yourself in the configuration file. Please visit the %2$s settings page and take a look at the rewrite rules. %3$s is running but won\'t work correctly until you deal with those rewrite rules.', 'sf-move-login' ), '<i>Nginx</i>', $link, '<strong>Move Login</strong>' ),
     124    );
    127125
    128126    return isset( $messages[ $message_id ] ) ? $messages[ $message_id ] : '';
  • sf-move-login/trunk/inc/admin.php

    r1569866 r1664767  
    327327 */
    328328function sfml_notices() {
    329     global $is_apache, $is_iis7;
    330 
    331329    // Get previous notices.
    332330    $user_id = get_current_user_id();
     
    341339    delete_transient( 'sfml_activation-' . $user_id );
    342340
    343     $notices  = array();
    344     $is_nginx = sfml_is_nginx();
     341    $notices = array();
    345342
    346343    // IIS7.
    347     if ( $is_iis7 && ! sfml_can_write_file() ) {
     344    if ( sfml_is_iis7() && ! sfml_can_write_file() ) {
    348345        $notices[] = 'error_file_not_writable';
    349346    }
    350347    // Apache.
    351     elseif ( $is_apache && ! sfml_can_write_file() ) {
     348    elseif ( sfml_is_apache() && ! sfml_can_write_file() ) {
    352349        $notices[] = 'error_file_not_writable';
    353350    }
    354351    // Nginx.
    355     elseif ( $is_nginx ) {
     352    elseif ( sfml_is_nginx() ) {
    356353        $notices[] = 'updated_is_nginx';
    357354    }
  • sf-move-login/trunk/inc/classes/class-sfml-options.php

    r1566761 r1664767  
    1111class SFML_Options extends SFML_Singleton {
    1212
    13     const VERSION      = '1.2';
     13    const VERSION      = '1.3';
    1414    const OPTION_NAME  = 'sfml';
    1515    const OPTION_GROUP = 'sfml_settings';
     
    1717
    1818    /**
    19      * Options.
     19     * All options.
    2020     *
    2121     * @var (array)
     
    2424
    2525    /**
    26      * Default options.
     26     * All default options.
    2727     *
    2828     * @var (array)
     
    3838
    3939    /**
    40      * Setting labels.
     40     * Slug setting labels.
    4141     *
    4242     * @var (array)
    43      */
    44     protected $labels;
     43     * @since 2.5.2 Renamed from $labels to $slug_labels.
     44     */
     45    protected $slug_labels;
    4546
    4647
     
    5758    }
    5859
     60
     61    /**
     62     * An improved version of `register_setting()`, that always exists and that works for network options.
     63     */
     64    protected function register_setting() {
     65        global $new_whitelist_options;
     66
     67        $sanitize_callback = array( $this, 'sanitize_options' );
     68
     69        if ( ! is_multisite() ) {
     70            if ( function_exists( 'register_setting' ) ) {
     71                register_setting( static::OPTION_GROUP, static::OPTION_NAME, $sanitize_callback );
     72                return;
     73            }
     74
     75            $new_whitelist_options = isset( $new_whitelist_options ) && is_array( $new_whitelist_options ) ? $new_whitelist_options : array(); // WPCS: override ok.
     76            $new_whitelist_options[ static::OPTION_GROUP ]   = isset( $new_whitelist_options[ static::OPTION_GROUP ] ) && is_array( $new_whitelist_options[ static::OPTION_GROUP ] ) ? $new_whitelist_options[ static::OPTION_GROUP ] : array();
     77            $new_whitelist_options[ static::OPTION_GROUP ][] = static::OPTION_NAME;
     78        } elseif ( is_admin() ) {
     79            $whitelist = sfml_cache_data( 'new_whitelist_network_options' );
     80            $whitelist = is_array( $whitelist ) ? $whitelist : array();
     81            $whitelist[ static::OPTION_GROUP ]   = isset( $whitelist[ static::OPTION_GROUP ] ) ? $whitelist[ static::OPTION_GROUP ] : array();
     82            $whitelist[ static::OPTION_GROUP ][] = static::OPTION_NAME;
     83            sfml_cache_data( 'new_whitelist_network_options', $whitelist );
     84        }
     85
     86        if ( $sanitize_callback ) {
     87            add_filter( 'sanitize_option_' . static::OPTION_NAME, $sanitize_callback );
     88        }
     89    }
     90
     91
     92    /*--------------------------------------------------------------------------------------------*/
     93    /* !DEFAULT OPTIONS ========================================================================= */
     94    /*--------------------------------------------------------------------------------------------*/
    5995
    6096    /**
     
    93129        }
    94130
    95         // Options.
    96         $this->options_default = array_merge( $this->options_default, array(
     131        // Other options.
     132        $this->options_default = array_merge( $this->options_default, $this->get_other_default_options() );
     133
     134        return $this->options_default;
     135    }
     136
     137
     138    /**
     139     * Get "other" default options (the radio groups).
     140     *
     141     * @since 2.5.2
     142     *
     143     * @return (array)
     144     */
     145    public function get_other_default_options() {
     146        return array(
    97147            'deny_wp_login_access' => 1,
    98148            'deny_admin_access'    => 0,
    99         ) );
    100 
    101         return $this->options_default;
    102     }
    103 
     149        );
     150    }
     151
     152
     153    /*--------------------------------------------------------------------------------------------*/
     154    /* !GET OPTIONS ============================================================================= */
     155    /*--------------------------------------------------------------------------------------------*/
    104156
    105157    /**
     
    115167        }
    116168
    117         $this->options = array();
    118         $old_options   = get_site_option( static::OPTION_NAME );
    119         $defaults      = $this->get_default_options();
    120 
    121         if ( is_array( $old_options ) ) {
    122             $default_slugs = static::get_sub_options( 'slugs', $defaults );
    123 
     169        $this->options   = array();
     170        $raw_options     = get_site_option( static::OPTION_NAME );
     171        $default_options = $this->get_default_options();
     172
     173        if ( is_array( $raw_options ) ) {
    124174            // Add and escape slugs.
     175            $default_slugs = static::get_sub_options( 'slugs', $default_options );
     176
    125177            foreach ( $default_slugs as $slug_key => $default_slug ) {
    126                 $this->options[ 'slugs.' . $slug_key ] = ! empty( $old_options[ 'slugs.' . $slug_key ] ) ? sanitize_title( $old_options[ 'slugs.' . $slug_key ], $default_slug, 'display' ) : $default_slug;
     178                $this->options[ 'slugs.' . $slug_key ] = ! empty( $raw_options[ 'slugs.' . $slug_key ] ) ? sanitize_title( $raw_options[ 'slugs.' . $slug_key ], $default_slug, 'display' ) : $default_slug;
    127179            }
    128180
    129181            // Add and escape other options.
    130             if ( isset( $defaults['deny_wp_login_access'] ) ) {
    131                 $this->options['deny_wp_login_access'] = isset( $old_options['deny_wp_login_access'] ) ? min( 3, max( 1, (int) $old_options['deny_wp_login_access'] ) ) : $defaults['deny_wp_login_access'];
    132             }
    133 
    134             if ( isset( $defaults['deny_admin_access'] ) ) {
    135                 $this->options['deny_admin_access'] = isset( $old_options['deny_admin_access'] ) ? min( 3, max( 0, (int) $old_options['deny_admin_access'] ) ) : $defaults['deny_admin_access'];
     182            $default_options = $this->get_other_default_options();
     183
     184            foreach ( $default_options as $option_name => $default_value ) {
     185                if ( ! isset( $raw_options[ $option_name ] ) ) {
     186                    $this->options[ $option_name ] = $default_value;
     187                    continue;
     188                }
     189
     190                $choices                       = $this->get_field_labels( $option_name );
     191                $this->options[ $option_name ] = (int) $raw_options[ $option_name ];
     192
     193                if ( ! isset( $choices[ $this->options[ $option_name ] ] ) ) {
     194                    $this->options[ $option_name ] = $default_value;
     195                }
    136196            }
    137197        } else {
    138             $this->options = $defaults;
    139         }
    140 
    141         // Generic filter, change the values.
    142         $options_tmp   = apply_filters( 'sfml_options', $this->options );
     198            $this->options = $default_options;
     199        }
     200
     201        $filtered_options = $this->options;
     202
     203        /**
     204         * Filter the plugin options before retrieving them.
     205         *
     206         * @param (array) $filtered_options The plugin options.
     207         */
     208        $filtered_options = apply_filters( 'sfml_options', $filtered_options );
     209
    143210        // Make sure no keys have been added or removed.
    144         $this->options = array_intersect_key( array_merge( $this->options, $options_tmp ), $this->options );
     211        $this->options    = array_intersect_key( array_merge( $this->options, $filtered_options ), $this->options );
    145212
    146213        return $this->options;
     
    180247
    181248    /**
     249     * Get sub-options.
     250     *
     251     * For example:
     252     * static::get_sub_options( 'foo', array(
     253     *     'option1'     => 'value1',
     254     *     'foo.option2' => 'value2',
     255     *     'foo.option3' => 'value3',
     256     * ) );
     257     * Will return:
     258     * array(
     259     *     'option2' => 'value2',
     260     *     'option3' => 'value3',
     261     * )
     262     *
     263     * @param (string) $name    The sub-option name.
     264     * @param (array)  $options Array of options.
     265     *
     266     * @return (array)
     267     */
     268    public static function get_sub_options( $name, $options ) {
     269        if ( ! $options || ! $name ) {
     270            return array();
     271        }
     272
     273        $options = (array) $options;
     274
     275        if ( isset( $options[ $name ] ) ) {
     276            return $options[ $name ];
     277        }
     278
     279        $group = array();
     280        $name  = rtrim( $name, '.' ) . '.';
     281
     282        foreach ( $options as $k => $v ) {
     283            if ( 0 === strpos( $k, $name ) ) {
     284                $group[ substr( $k, strlen( $name ) ) ] = $v;
     285            }
     286        }
     287
     288        return ! empty( $group ) ? $group : null;
     289    }
     290
     291
     292    /*--------------------------------------------------------------------------------------------*/
     293    /* !FIELD LABELS ==========+++=============================================================== */
     294    /*--------------------------------------------------------------------------------------------*/
     295
     296    /**
     297     * Get the possible choices for a specific option.
     298     *
     299     * @since 1.5.2
     300     *
     301     * @param (string) $option  The option name.
     302     *
     303     * @return (array)
     304     */
     305    public function get_field_labels( $option ) {
     306        if ( 'slugs' === $option ) {
     307            return $this->get_slug_field_labels();
     308        }
     309
     310        $choices = array(
     311            'deny_wp_login_access' => array(
     312                1 => __( 'Display an error message', 'sf-move-login' ),
     313                4 => __( 'Trigger a &laquo;Page not found&raquo; error', 'sf-move-login' ),
     314                2 => __( 'Redirect to a "WordPress" &laquo;Page not found&raquo; error page', 'sf-move-login' ),
     315                3 => __( 'Redirect to the home page', 'sf-move-login' ),
     316            ),
     317            'deny_admin_access'    => array(
     318                0 => __( 'Do nothing, redirect to the new login page (not recommended)', 'sf-move-login' ),
     319                1 => __( 'Display an error message', 'sf-move-login' ),
     320                4 => __( 'Trigger a &laquo;Page not found&raquo; error', 'sf-move-login' ),
     321                2 => __( 'Redirect to a "WordPress" &laquo;Page not found&raquo; error page', 'sf-move-login' ),
     322                3 => __( 'Redirect to the home page', 'sf-move-login' ),
     323            ),
     324        );
     325
     326        $choices = isset( $choices[ $option ] ) ? $choices[ $option ] : array();
     327
     328        /**
     329         * Filter the possible choices for a specific option.
     330         *
     331         * @param (array)  $choices The possible choices.
     332         * @param (string) $option  The option name.
     333         */
     334        return apply_filters( 'sfml_option_choices', $choices, $option );
     335    }
     336
     337
     338    /**
    182339     * Setting field labels for the slugs.
    183340     *
     
    187344        $this->maybe_clear_options_cache();
    188345
    189         if ( isset( $this->labels ) ) {
    190             return $this->labels;
    191         }
    192 
    193         $this->labels = array(
     346        if ( isset( $this->slug_labels ) ) {
     347            return $this->slug_labels;
     348        }
     349
     350        $this->slug_labels = array(
    194351            'login'        => __( 'Log in' ),
    195352            'logout'       => __( 'Log out' ),
     
    202359
    203360        if ( $new_actions ) {
    204             $new_actions  = array_diff_key( $new_actions, $this->labels );
    205             $this->labels = array_merge( $this->labels, $new_actions );
    206         }
    207 
    208         return $this->labels;
    209     }
    210 
     361            $new_actions       = array_diff_key( $new_actions, $this->slug_labels );
     362            $this->slug_labels = array_merge( $this->slug_labels, $new_actions );
     363        }
     364
     365        return $this->slug_labels;
     366    }
     367
     368
     369    /**
     370     * Get custom labels (added by other plugins).
     371     *
     372     * @since 2.4
     373     *
     374     * @return (array)
     375     */
     376    public static function get_additional_labels() {
     377        $new_actions = array();
     378        /**
     379         * Plugins can add their own actions.
     380         *
     381         * @param (array) $new_actions Custom actions.
     382         */
     383        return apply_filters( 'sfml_additional_slugs', $new_actions );
     384    }
     385
     386
     387    /*--------------------------------------------------------------------------------------------*/
     388    /* !SANITIZATION ============================================================================ */
     389    /*--------------------------------------------------------------------------------------------*/
     390
     391    /**
     392     * Sanitize options on save.
     393     *
     394     * @param (array) $options Options to sanitize.
     395     *
     396     * @return (array)
     397     */
     398    public function sanitize_options( $options = array() ) {
     399        $sanitized_options = array();
     400        $old_options       = get_site_option( static::OPTION_NAME );
     401        $errors            = array( 'forbidden' => array(), 'duplicates' => array() );
     402
     403        // Add and sanitize slugs.
     404        $default_slugs = $this->get_default_options();
     405        $default_slugs = static::get_sub_options( 'slugs', $default_slugs );
     406        $exclude       = $this->get_other_actions();
     407
     408        foreach ( $default_slugs as $slug_key => $default_slug ) {
     409
     410            if ( isset( $exclude[ $slug_key ] ) ) {
     411                $sanitized_options[ 'slugs.' . $slug_key ] = $exclude[ $slug_key ];
     412                continue;
     413            }
     414
     415            $sanitized_options[ 'slugs.' . $slug_key ] = false;
     416
     417            if ( ! empty( $options[ 'slugs.' . $slug_key ] ) ) {
     418                $tmp_slug = sanitize_title( $options[ 'slugs.' . $slug_key ], $default_slug );
     419
     420                // 'postpass', 'retrievepassword' and 'rp' are forbidden.
     421                if ( in_array( $tmp_slug, $exclude, true ) ) {
     422                    $errors['forbidden'][] = $tmp_slug;
     423                }
     424                // Make sure the slug is not already set for another action.
     425                elseif ( in_array( $tmp_slug, $sanitized_options, true ) ) {
     426                    $errors['duplicates'][] = $tmp_slug;
     427                }
     428                // Yay!
     429                else {
     430                    $sanitized_options[ 'slugs.' . $slug_key ] = $tmp_slug;
     431                }
     432            }
     433
     434            // Fallback to old value or default value.
     435            if ( ! $sanitized_options[ 'slugs.' . $slug_key ] ) {
     436                if ( ! isset( $exclude[ $slug_key ] ) && ! empty( $old_options[ 'slugs.' . $slug_key ] ) ) {
     437                    $sanitized_options[ 'slugs.' . $slug_key ] = sanitize_title( $old_options[ 'slugs.' . $slug_key ], $default_slug );
     438                } else {
     439                    $sanitized_options[ 'slugs.' . $slug_key ] = $default_slug;
     440                }
     441            }
     442        }
     443
     444        // Add and sanitize other options.
     445        $default_options = $this->get_other_default_options();
     446
     447        foreach ( $default_options as $option_name => $default_value ) {
     448
     449            if ( isset( $options[ $option_name ] ) ) {
     450                $sanitized_options[ $option_name ] = (int) $options[ $option_name ];
     451            } elseif ( isset( $old_options[ $option_name ] ) ) {
     452                $sanitized_options[ $option_name ] = (int) $old_options[ $option_name ];
     453            } else {
     454                $sanitized_options[ $option_name ] = $default_value;
     455                continue;
     456            }
     457
     458            $choices = $this->get_field_labels( $option_name );
     459
     460            if ( ! isset( $choices[ $sanitized_options[ $option_name ] ] ) ) {
     461                $sanitized_options[ $option_name ] = $default_value;
     462            }
     463        }
     464
     465        $filtered_options = $sanitized_options;
     466
     467        /**
     468         * Filter the options after being sanitized.
     469         *
     470         * @param (array) $filtered_options The new options, sanitized.
     471         * @param (array) $options          The submitted options.
     472         */
     473        $filtered_options  = apply_filters( 'sfml_sanitize_options', $filtered_options, $options );
     474
     475        // Make sure no keys have been removed.
     476        $sanitized_options = array_merge( $sanitized_options, $filtered_options );
     477
     478        // Clear options cache.
     479        $this->maybe_clear_options_cache( true );
     480
     481        // Add the rewrite rules to the `.htaccess`/`web.config` file.
     482        $old_slugs = static::get_sub_options( 'slugs', $old_options );
     483        $new_slugs = static::get_sub_options( 'slugs', $sanitized_options );
     484
     485        if ( $old_slugs !== $new_slugs ) {
     486            sfml_include_rewrite_file();
     487            sfml_write_rules( sfml_rules( $new_slugs ) );
     488        }
     489
     490        // Trigger errors.
     491        if ( is_admin() ) {
     492            $errors['forbidden']  = array_unique( $errors['forbidden'] );
     493            $errors['duplicates'] = array_unique( $errors['duplicates'] );
     494
     495            if ( $nbr_forbidden = count( $errors['forbidden'] ) ) {
     496                /** Translators: %s is an URL slug name. */
     497                add_settings_error( 'sfml_settings', 'forbidden-slugs', sprintf( _n( 'The slug %s is forbidden.', 'The slugs %s are forbidden.', $nbr_forbidden, 'sf-move-login' ), wp_sprintf( '<code>%l</code>', $errors['forbidden'] ) ) );
     498            }
     499            if ( ! empty( $errors['duplicates'] ) ) {
     500                add_settings_error( 'sfml_settings', 'duplicates-slugs', __( 'The links can\'t have the same slugs.', 'sf-move-login' ) );
     501            }
     502        }
     503
     504        return $sanitized_options;
     505    }
     506
     507
     508    /*--------------------------------------------------------------------------------------------*/
     509    /* !VARIOUS ================================================================================= */
     510    /*--------------------------------------------------------------------------------------------*/
    211511
    212512    /**
     
    239539            $this->options_default = null;
    240540            $this->slugs           = null;
    241             $this->labels          = null;
     541            $this->slug_labels     = null;
    242542            remove_all_filters( static::OPTION_NAME . '_clear_options_cache' );
    243543        }
    244544    }
    245 
    246 
    247     /**
    248      * An improved version of `register_setting()`, that always exists and that works for network options.
    249      */
    250     protected function register_setting() {
    251         global $new_whitelist_options;
    252 
    253         $sanitize_callback = array( $this, 'sanitize_options' );
    254 
    255         if ( ! is_multisite() ) {
    256             if ( function_exists( 'register_setting' ) ) {
    257                 register_setting( static::OPTION_GROUP, static::OPTION_NAME, $sanitize_callback );
    258                 return;
    259             }
    260 
    261             $new_whitelist_options = isset( $new_whitelist_options ) && is_array( $new_whitelist_options ) ? $new_whitelist_options : array(); // WPCS: override ok.
    262             $new_whitelist_options[ static::OPTION_GROUP ]   = isset( $new_whitelist_options[ static::OPTION_GROUP ] ) && is_array( $new_whitelist_options[ static::OPTION_GROUP ] ) ? $new_whitelist_options[ static::OPTION_GROUP ] : array();
    263             $new_whitelist_options[ static::OPTION_GROUP ][] = static::OPTION_NAME;
    264         } elseif ( is_admin() ) {
    265             $whitelist = sfml_cache_data( 'new_whitelist_network_options' );
    266             $whitelist = is_array( $whitelist ) ? $whitelist : array();
    267             $whitelist[ static::OPTION_GROUP ]   = isset( $whitelist[ static::OPTION_GROUP ] ) ? $whitelist[ static::OPTION_GROUP ] : array();
    268             $whitelist[ static::OPTION_GROUP ][] = static::OPTION_NAME;
    269             sfml_cache_data( 'new_whitelist_network_options', $whitelist );
    270         }
    271 
    272         if ( $sanitize_callback ) {
    273             add_filter( 'sanitize_option_' . static::OPTION_NAME, $sanitize_callback );
    274         }
    275     }
    276 
    277 
    278     /**
    279      * Sanitize options on save.
    280      *
    281      * @param (array) $options Options to sanitize.
    282      *
    283      * @return (array)
    284      */
    285     public function sanitize_options( $options = array() ) {
    286         $errors            = array( 'forbidden' => array(), 'duplicates' => array() );
    287         $old_options       = get_site_option( static::OPTION_NAME );
    288         $default_options   = $this->get_default_options();
    289         $sanitized_options = array();
    290 
    291         // Add and sanitize slugs.
    292         $default_slugs = static::get_sub_options( 'slugs', $default_options );
    293         $exclude       = $this->get_other_actions();
    294 
    295         foreach ( $default_slugs as $slug_key => $default_slug ) {
    296 
    297             if ( isset( $exclude[ $slug_key ] ) ) {
    298                 $sanitized_options[ 'slugs.' . $slug_key ] = $exclude[ $slug_key ];
    299                 continue;
    300             }
    301 
    302             $sanitized_options[ 'slugs.' . $slug_key ] = false;
    303 
    304             if ( ! empty( $options[ 'slugs.' . $slug_key ] ) ) {
    305                 $tmp_slug = sanitize_title( $options[ 'slugs.' . $slug_key ], $default_slug );
    306 
    307                 // 'postpass', 'retrievepassword' and 'rp' are forbidden.
    308                 if ( in_array( $tmp_slug, $exclude, true ) ) {
    309                     $errors['forbidden'][] = $tmp_slug;
    310                 }
    311                 // Make sure the slug is not already set for another action.
    312                 elseif ( in_array( $tmp_slug, $sanitized_options, true ) ) {
    313                     $errors['duplicates'][] = $tmp_slug;
    314                 }
    315                 // Yay!
    316                 else {
    317                     $sanitized_options[ 'slugs.' . $slug_key ] = $tmp_slug;
    318                 }
    319             }
    320 
    321             // Fallback to old value or default value.
    322             if ( ! $sanitized_options[ 'slugs.' . $slug_key ] ) {
    323                 if ( ! isset( $exclude[ $slug_key ] ) && ! empty( $old_options[ 'slugs.' . $slug_key ] ) ) {
    324                     $sanitized_options[ 'slugs.' . $slug_key ] = sanitize_title( $old_options[ 'slugs.' . $slug_key ], $default_slug );
    325                 } else {
    326                     $sanitized_options[ 'slugs.' . $slug_key ] = $default_slug;
    327                 }
    328             }
    329         }
    330 
    331         // Add and sanitize other options.
    332         if ( isset( $default_options['deny_wp_login_access'] ) ) {
    333             if ( isset( $options['deny_wp_login_access'] ) ) {
    334 
    335                 $sanitized_options['deny_wp_login_access'] = min( 3, max( 1, (int) $options['deny_wp_login_access'] ) );
    336 
    337             } elseif ( isset( $old_options['deny_wp_login_access'] ) ) {
    338 
    339                 $sanitized_options['deny_wp_login_access'] = min( 3, max( 1, (int) $old_options['deny_wp_login_access'] ) );
    340 
    341             } else {
    342                 $sanitized_options['deny_wp_login_access'] = $default_options['deny_wp_login_access'];
    343             }
    344         }
    345 
    346         if ( isset( $default_options['deny_admin_access'] ) ) {
    347             if ( isset( $options['deny_admin_access'] ) ) {
    348 
    349                 $sanitized_options['deny_admin_access'] = min( 3, max( 0, (int) $options['deny_admin_access'] ) );
    350 
    351             } elseif ( isset( $old_options['deny_admin_access'] ) ) {
    352 
    353                 $sanitized_options['deny_admin_access'] = min( 3, max( 0, (int) $old_options['deny_admin_access'] ) );
    354 
    355             } else {
    356                 $sanitized_options['deny_admin_access'] = $default_options['deny_admin_access'];
    357             }
    358         }
    359 
    360         /**
    361          * Filter the options after being sanitized.
    362          *
    363          * @param (array) $sanitized_options The new options, sanitized.
    364          * @param (array) $options           The submitted options.
    365          */
    366         $options_tmp       = apply_filters( 'sfml_sanitize_options', $sanitized_options, $options );
    367         // Make sure no keys have been removed.
    368         $sanitized_options = array_merge( $sanitized_options, $options_tmp );
    369 
    370         // Clear options cache.
    371         $this->maybe_clear_options_cache( true );
    372 
    373         // Add the rewrite rules to the `.htaccess`/`web.config` file.
    374         $old_slugs = static::get_sub_options( 'slugs', $old_options );
    375         $new_slugs = static::get_sub_options( 'slugs', $sanitized_options );
    376 
    377         if ( $old_slugs !== $new_slugs ) {
    378             sfml_include_rewrite_file();
    379             sfml_write_rules( sfml_rules( $new_slugs ) );
    380         }
    381 
    382         // Trigger errors.
    383         if ( is_admin() ) {
    384             $errors['forbidden']  = array_unique( $errors['forbidden'] );
    385             $errors['duplicates'] = array_unique( $errors['duplicates'] );
    386 
    387             if ( $nbr_forbidden = count( $errors['forbidden'] ) ) {
    388                 /** Translators: %s is an URL slug name. */
    389                 add_settings_error( 'sfml_settings', 'forbidden-slugs', sprintf( _n( 'The slug %s is forbidden.', 'The slugs %s are forbidden.', $nbr_forbidden, 'sf-move-login' ), wp_sprintf( '<code>%l</code>', $errors['forbidden'] ) ) );
    390             }
    391             if ( ! empty( $errors['duplicates'] ) ) {
    392                 add_settings_error( 'sfml_settings', 'duplicates-slugs', __( 'The links can\'t have the same slugs.', 'sf-move-login' ) );
    393             }
    394         }
    395 
    396         return $sanitized_options;
    397     }
    398 
    399 
    400     /**
    401      * Get sub-options.
    402      *
    403      * For example:
    404      * static::get_sub_options( 'foo', array(
    405      *     'option1'     => 'value1',
    406      *     'foo.option2' => 'value2',
    407      *     'foo.option3' => 'value3',
    408      * ) );
    409      * Will return:
    410      * array(
    411      *     'option2' => 'value2',
    412      *     'option3' => 'value3',
    413      * )
    414      *
    415      * @param (string) $name    The sub-option name.
    416      * @param (array)  $options Array of options.
    417      *
    418      * @return (array)
    419      */
    420     public static function get_sub_options( $name, $options ) {
    421         if ( ! $options || ! $name ) {
    422             return array();
    423         }
    424 
    425         $options = (array) $options;
    426 
    427         if ( isset( $options[ $name ] ) ) {
    428             return $options[ $name ];
    429         }
    430 
    431         $group = array();
    432         $name  = rtrim( $name, '.' ) . '.';
    433 
    434         foreach ( $options as $k => $v ) {
    435             if ( 0 === strpos( $k, $name ) ) {
    436                 $group[ substr( $k, strlen( $name ) ) ] = $v;
    437             }
    438         }
    439 
    440         return ! empty( $group ) ? $group : null;
    441     }
    442 
    443 
    444     /**
    445      * Get custom labels (added by other plugins).
    446      *
    447      * @since 2.4
    448      *
    449      * @return (array)
    450      */
    451     public static function get_additional_labels() {
    452         $new_actions = array();
    453         /**
    454          * Plugins can add their own actions.
    455          *
    456          * @param (array) $new_actions Custom actions.
    457          */
    458         return apply_filters( 'sfml_additional_slugs', $new_actions );
    459     }
    460545}
  • sf-move-login/trunk/inc/functions/compat.php

    r1656995 r1664767  
    208208    }
    209209endif;
     210
     211
     212if ( ! function_exists( 'do_action_deprecated' ) ) :
     213    /**
     214     * Fires functions attached to a deprecated action hook.
     215     *
     216     * When an action hook is deprecated, the do_action() call is replaced with do_action_deprecated(), which triggers a deprecation notice and then fires the original hook.
     217     *
     218     * @since 2.5.2
     219     * @since WP 4.6.0
     220     *
     221     * @see _deprecated_hook()
     222     *
     223     * @param (string) $tag         The name of the action hook.
     224     * @param (array)  $args        Array of additional function arguments to be passed to do_action().
     225     * @param (string) $version     The version of WordPress that deprecated the hook.
     226     * @param (string) $replacement Optional. The hook that should have been used.
     227     * @param (string) $message     Optional. A message regarding the change.
     228     */
     229    function do_action_deprecated( $tag, $args, $version, $replacement = false, $message = null ) {
     230        if ( ! has_action( $tag ) ) {
     231            return;
     232        }
     233
     234        _deprecated_hook( $tag, $version, $replacement, $message );
     235
     236        do_action_ref_array( $tag, $args );
     237    }
     238endif;
     239
     240
     241if ( ! function_exists( '_deprecated_hook' ) ) :
     242    /**
     243     * Marks a deprecated action or filter hook as deprecated and throws a notice.
     244     *
     245     * Use the {@see 'deprecated_hook_run'} action to get the backtrace describing where the deprecated hook was called.
     246     *
     247     * Default behavior is to trigger a user error if `WP_DEBUG` is true.
     248     *
     249     * This function is called by the do_action_deprecated() and apply_filters_deprecated() functions, and so generally does not need to be called directly.
     250     *
     251     * @since 2.5.2
     252     * @since WP 4.6.0
     253     *
     254     * @param (string) $hook        The hook that was used.
     255     * @param (string) $version     The version of WordPress that deprecated the hook.
     256     * @param (string) $replacement Optional. The hook that should have been used.
     257     * @param (string) $message     Optional. A message regarding the change.
     258     */
     259    function _deprecated_hook( $hook, $version, $replacement = null, $message = null ) {
     260        /**
     261         * Fires when a deprecated hook is called.
     262         *
     263         * @since 2.5.2
     264         * @since WP 4.6.0
     265         *
     266         * @param (string) $hook        The hook that was called.
     267         * @param (string) $replacement The hook that should be used as a replacement.
     268         * @param (string) $version     The version of WordPress that deprecated the argument used.
     269         * @param (string) $message     A message regarding the change.
     270         */
     271        do_action( 'deprecated_hook_run', $hook, $replacement, $version, $message );
     272
     273        /**
     274         * Filters whether to trigger deprecated hook errors.
     275         *
     276         * @since 2.5.2
     277         * @since WP 4.6.0
     278         *
     279         * @param (bool) $trigger Whether to trigger deprecated hook errors. Requires `WP_DEBUG` to be defined true.
     280         */
     281        if ( WP_DEBUG && apply_filters( 'deprecated_hook_trigger_error', true ) ) {
     282            $message = empty( $message ) ? '' : ' ' . $message;
     283            if ( ! is_null( $replacement ) ) {
     284                /* Translators: 1: WordPress hook name, 2: version number, 3: alternative hook name. */
     285                trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', 'sf-move-login' ), $hook, $version, $replacement ) . $message );
     286            } else {
     287                /* Translators: 1: WordPress hook name, 2: version number. */
     288                trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', 'sf-move-login' ), $hook, $version ) . $message );
     289            }
     290        }
     291    }
     292endif;
  • sf-move-login/trunk/inc/functions/rewrite.php

    r1653817 r1664767  
    4646 */
    4747function sfml_write_rules( $rules = null ) {
    48     global $is_apache, $is_iis7;
    49 
    5048    $rules = isset( $rules ) ? $rules : sfml_rules();
    5149
     
    5957    }
    6058    // Apache.
    61     elseif ( $is_apache ) {
     59    elseif ( sfml_is_apache() ) {
    6260        $success = sfml_insert_apache_rewrite_rules( $rules );
    6361    }
    6462    // IIS.
    65     elseif ( $is_iis7 ) {
     63    elseif ( sfml_is_iis7() ) {
    6664        $success = sfml_insert_iis7_rewrite_rules( $rules );
    6765    }
     
    9997 */
    10098function sfml_get_rewrite_bases() {
    101     global $is_apache, $is_nginx, $is_iis7;
    10299    static $bases;
    103100
     
    119116
    120117    // Apache.
    121     if ( $is_apache ) {
     118    if ( sfml_is_apache() ) {
    122119        /**
    123120         * In the `*_from` fields, we don't add `$base` because we use `RewriteBase $base` in the rewrite rules.
     
    145142
    146143    // Nginx.
    147     if ( $is_nginx ) {
     144    if ( sfml_is_nginx() ) {
    148145        if ( $is_sub ) {
    149146            // MultiSite by sub-folders.
     
    167164
    168165    // IIS7.
    169     if ( $is_iis7 ) {
     166    if ( sfml_is_iis7() ) {
    170167        $base     = ltrim( $base, '/' );     // No heading slash for IIS: '' or 'sub-dir/'.
    171168        $site_dir = ltrim( $site_dir, '/' ); // No heading slash for IIS: '', 'wp-dir/', 'sub-dir/', or 'sub-dir/wp-dir/'.
  • sf-move-login/trunk/inc/functions/settings-page.php

    r1653817 r1664767  
    1212 */
    1313function sfml_settings_fields() {
    14     $labels   = SFML_Options::get_instance()->get_slug_field_labels();
     14    $instance = SFML_Options::get_instance();
     15    $labels   = $instance->get_field_labels( 'slugs' );
    1516    $defaults = sfml_get_default_options();
    1617    $options  = sfml_get_options();
     
    5758            'value'     => $options['deny_wp_login_access'],
    5859            'default'   => $defaults['deny_wp_login_access'],
    59             'values'    => array(
    60                 1 => __( 'Display an error message', 'sf-move-login' ),
    61                 2 => __( 'Redirect to a &laquo;Page not found&raquo; error page', 'sf-move-login' ),
    62                 3 => __( 'Redirect to the home page', 'sf-move-login' ),
    63             ),
     60            'values'    => $instance->get_field_labels( 'deny_wp_login_access' ),
    6461            'label'     => '<strong>' . __( 'When a logged out user attempts to access the old login page.', 'sf-move-login' ) . '</strong>',
    6562        )
     
    7774            'value'     => $options['deny_admin_access'],
    7875            'default'   => $defaults['deny_admin_access'],
    79             'values'    => array(
    80                 0 => __( 'Do nothing, redirect to the new login page (not recommended)', 'sf-move-login' ),
    81                 1 => __( 'Display an error message', 'sf-move-login' ),
    82                 2 => __( 'Redirect to a &laquo;Page not found&raquo; error page', 'sf-move-login' ),
    83                 3 => __( 'Redirect to the home page', 'sf-move-login' ),
    84             ),
     76            'values'    => $instance->get_field_labels( 'deny_admin_access' ),
    8577            'label'     => '<strong>' . __( 'Instead of redirecting a logged out user to the new login page:', 'sf-move-login' ) . '</strong>',
    8678        )
     
    10496
    10597/**
    106  * The settings page
     98 * The settings page.
    10799 */
    108100function sfml_settings_page() {
     
    217209 */
    218210function sfml_rewrite_rules_textarea() {
    219     global $is_apache, $is_iis7;
    220 
    221211    sfml_include_rewrite_file();
    222212
    223     $is_nginx = sfml_is_nginx();
    224     $rules    = sfml_rules();
     213    $rules = sfml_rules();
    225214
    226215    // Message.
     
    231220
    232221    // IIS.
    233     if ( $is_iis7 ) {
     222    if ( sfml_is_iis7() ) {
    234223        $file          = 'web.config';
    235224        $file_content  = implode( "\n", sfml_iis7_rewrite_rules( $rules ) );
     
    246235    }
    247236    // Nginx.
    248     elseif ( $is_nginx ) {
     237    elseif ( sfml_is_nginx() ) {
    249238        $file          = 'nginx.conf';
    250239        $file_content  = implode( "\n", sfml_nginx_rewrite_rules( $rules ) );
     
    261250    }
    262251    // Apache.
    263     elseif ( $is_apache ) {
     252    elseif ( sfml_is_apache() ) {
    264253        $file          = '.htaccess';
    265254        $file_content  = "\n# BEGIN SF Move Login\n";
  • sf-move-login/trunk/inc/functions/utilities.php

    r1653817 r1664767  
    9090
    9191/**
     92 * Tell if the server runs Apache.
     93 *
     94 * @since 2.5.2
     95 *
     96 * @return (bool) True if the server runs Apache. False otherwize.
     97 */
     98function sfml_is_apache() {
     99    global $is_apache;
     100    static $is;
     101
     102    if ( isset( $is ) ) {
     103        return $is;
     104    }
     105
     106    if ( isset( $is_apache ) ) {
     107        $is = (bool) $is_apache;
     108    } else {
     109        $is = ! empty( $_SERVER['SERVER_SOFTWARE'] ) && ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) !== false );
     110    }
     111
     112    /**
     113     * Filters the value returned by `sfml_is_apache()`.
     114     *
     115     * @since 2.5.2
     116     *
     117     * @param (bool) $is True if the server runs Apache. False otherwize.
     118     */
     119    return apply_filters( 'sfml_is_apache', $is );
     120}
     121
     122
     123/**
     124 * Tell if the server runs IIS7.
     125 *
     126 * @since 2.5.2
     127 *
     128 * @return (bool) True if the server runs IIS7. False otherwize.
     129 */
     130function sfml_is_iis7() {
     131    global $is_iis7;
     132    static $is;
     133
     134    if ( isset( $is ) ) {
     135        return $is;
     136    }
     137
     138    if ( isset( $is_iis7 ) ) {
     139        $is = (bool) $is_iis7;
     140    } else {
     141        $is = ! sfml_is_apache() && ! empty( $_SERVER['SERVER_SOFTWARE'] ) && ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer' ) !== false );
     142        $is = $is && intval( substr( $_SERVER['SERVER_SOFTWARE'], strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/' ) + 14 ) ) >= 7;
     143    }
     144
     145    /**
     146     * Filters the value returned by `sfml_is_iis7()`.
     147     *
     148     * @since 2.5.2
     149     *
     150     * @param (bool) $is True if the server runs IIS7. False otherwize.
     151     */
     152    return apply_filters( 'sfml_is_iis7', $is );
     153}
     154
     155
     156/**
    92157 * Tell if the server runs Nginx.
    93158 *
     
    96161function sfml_is_nginx() {
    97162    global $is_nginx;
    98 
    99     if ( is_null( $is_nginx ) ) {
    100         $is_nginx = ! empty( $_SERVER['SERVER_SOFTWARE'] ) && strpos( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) !== false;
    101     }
    102 
    103     return $is_nginx;
     163    static $is;
     164
     165    if ( isset( $is ) ) {
     166        return $is;
     167    }
     168
     169    if ( isset( $is_nginx ) ) {
     170        $is = (bool) $is_nginx;
     171    } else {
     172        $is = ! empty( $_SERVER['SERVER_SOFTWARE'] ) && strpos( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) !== false;
     173    }
     174
     175    /**
     176     * Filters the value returned by `sfml_is_nginx()`.
     177     *
     178     * @since 2.5.2
     179     *
     180     * @param (bool) $is True if the server runs Nginx. False otherwize.
     181     */
     182    return apply_filters( 'sfml_is_nginx', $is );
    104183}
    105184
     
    342421 */
    343422function sfml_can_write_file() {
    344     global $is_apache, $is_iis7;
    345 
    346423    $home_path = sfml_get_home_path();
    347424
    348425    // Apache.
    349     if ( $is_apache ) {
     426    if ( sfml_is_apache() ) {
    350427        if ( ! got_mod_rewrite() ) {
    351428            return false;
     
    358435
    359436    // IIS7.
    360     if ( $is_iis7 ) {
     437    if ( sfml_is_iis7() ) {
    361438        if ( ! iis7_supports_permalinks() ) {
    362439            return false;
  • sf-move-login/trunk/inc/redirections-and-dies.php

    r1653817 r1664767  
    9999    switch ( $do ) {
    100100        case 2:
    101             $redirect = home_url( '404' );
    102             /**
    103              * Filter the 404 page URL.
    104              *
    105              * @param (string) $redirect An URL that leads to a 404 response.
    106              */
    107             $redirect = apply_filters( 'sfml_404_error_page', $redirect );
    108             wp_redirect( esc_url_raw( user_trailingslashit( $redirect ) ) );
     101            wp_redirect( esc_url_raw( sfml_get_404_error_url() ) );
    109102            exit;
    110103        case 3:
    111104            wp_redirect( esc_url_raw( user_trailingslashit( home_url() ) ) );
     105            exit;
     106        case 4:
     107            sfml_maybe_trigger_404_error();
     108            // Fallback in case headers were already sent.
     109            wp_redirect( esc_url_raw( sfml_get_404_error_url() ) );
    112110            exit;
    113111        default:
     
    162160    $redirect = false;
    163161    /**
    164      * If you want to trigger a custom action (redirect, message, die...), add it here.
     162     * Filters the redirection location.
     163     * You can also trigger a custom action, like a `wp_die()` with a custom message.
    165164     *
    166165     * @since 2.5
     
    174173    }
    175174
    176     if ( function_exists( 'do_action_deprecated' ) ) {
    177         do_action_deprecated( 'sfml_wp_admin_error', array(), '2.5', 'sfml_login_redirect_location' );
    178     } else {
    179         /**
    180          * If you want to trigger a custom action (redirect, message, die...), add it here.
    181          * Don't forget to exit/die.
    182          */
    183         do_action( 'sfml_wp_admin_error' );
    184     }
     175    do_action_deprecated( 'sfml_wp_admin_error', array(), '2.5', 'sfml_login_redirect_location' );
    185176
    186177    $do = sfml_get_deny_admin_access();
     
    188179    switch ( $do ) {
    189180        case 1:
    190             sfml_lang_init();
    191181            wp_die( __( 'Cheatin&#8217; uh?', 'sf-move-login' ), __( 'Nope :)', 'sf-move-login' ), array( 'response' => 403 ) );
    192182        case 2:
    193             $redirect = home_url( '404' );
    194             /** This filter is documented in inc/redirections-and-dies.php */
    195             $redirect = apply_filters( 'sfml_404_error_page', $redirect );
    196             return esc_url_raw( user_trailingslashit( $redirect ) );
     183            return esc_url_raw( sfml_get_404_error_url() );
    197184        case 3:
    198185            return esc_url_raw( user_trailingslashit( home_url() ) );
    199     }
    200 }
     186        case 4:
     187            sfml_maybe_trigger_404_error();
     188            // Fallback in case headers were already sent.
     189            return esc_url_raw( sfml_get_404_error_url() );
     190        default:
     191            return $location;
     192    }
     193}
     194
     195
     196/**
     197 * Trigger a 404 error if headers have not been sent yet.
     198 * Be aware that if the headers have been sent, the request won't be killed: provide a fallback!
     199 *
     200 * @since 2.5.2
     201 */
     202function sfml_maybe_trigger_404_error() {
     203    if ( headers_sent() ) {
     204        return;
     205    }
     206
     207    status_header( 404 );
     208
     209    $headers = wp_get_nocache_headers();
     210    $headers['Content-Type'] = get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' );
     211
     212    foreach ( $headers as $name => $field_value ) {
     213        @header( "{$name}: {$field_value}" );
     214    }
     215
     216    exit;
     217}
     218
     219
     220/**
     221 * Get the URL of the "WordPress" 404 error page we'll redirect to.
     222 *
     223 * @since 2.5.2
     224 *
     225 * @return (string) A URL.
     226 */
     227function sfml_get_404_error_url() {
     228    global $wp_rewrite;
     229
     230    if ( $wp_rewrite && $wp_rewrite->using_permalinks() ) {
     231        $redirect = user_trailingslashit( home_url( '404' ) );
     232    } else {
     233        $redirect = add_query_arg( 'p', '404', user_trailingslashit( home_url() ) );
     234    }
     235    /**
     236     * Filter the 404 page URL.
     237     *
     238     * @param (string) $redirect An URL that leads to a 404 response.
     239     */
     240    return apply_filters( 'sfml_404_error_page', $redirect );
     241}
  • sf-move-login/trunk/languages/sf-move-login-fr_FR.po

    r1653817 r1664767  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Move Login 2.4.3\n"
     5"Project-Id-Version: SF Move Login\n"
    66"Report-Msgid-Bugs-To: Grégory Viguier <[email protected]>\n"
    7 "POT-Creation-Date: 2017-05-09 22:18+0200\n"
    8 "PO-Revision-Date: 2017-05-09 22:24+0200\n"
    9 "Last-Translator: WP Media <[email protected]>\n"
    10 "Language-Team: French (France)\n"
     7"POT-Creation-Date: 2017-05-25 15:27+0200\n"
     8"PO-Revision-Date: 2017-05-25 16:09+0200\n"
     9"Last-Translator: Grégory Viguier <[email protected]>\n"
     10"Language-Team: Grégory Viguier <[email protected]>\n"
    1111"Language: fr_FR\n"
    1212"MIME-Version: 1.0\n"
    13 "Content-Type: text/plain; charset=utf-8\n"
     13"Content-Type: text/plain; charset=UTF-8\n"
    1414"Content-Transfer-Encoding: 8bit\n"
    1515"Plural-Forms: nplurals=2; plural=(n > 1);\n"
    1616"X-Generator: Poedit 1.8.12\n"
    1717"X-Poedit-Basepath: ..\n"
    18 "X-Poedit-KeywordsList: _x:1,2c;__;_e;_ex:1,2c;_n:1,2;_nx:1,2;esc_html__;"
    19 "esc_html_e;_n_noop:1,2\n"
     18"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
    2019"X-Poedit-SourceCharset: UTF-8\n"
    2120"X-Textdomain-Support: yes\n"
     21"X-Poedit-WPHeader: sf-move-login.php\n"
    2222"X-Poedit-SearchPath-0: .\n"
     23"X-Poedit-SearchPathExcluded-0: *.js\n"
    2324
    2425#. Translators: 1 is the plugin name.
    25 #: inc/activate.php:53
     26#: inc/activate.php:50
    2627#, php-format
    2728msgid "%s has not been activated."
    2829msgstr "%s n&rsquo;a pas été activé."
    2930
    30 #: inc/activate.php:55
     31#: inc/activate.php:52
    3132msgid "Error"
    3233msgstr "Erreur"
    3334
    3435#. Translators: 1 is the plugin name.
    35 #: inc/activate.php:116
     36#: inc/activate.php:115
    3637#, php-format
    37 msgid ""
    38 "It seems your server configuration prevents the plugin to work properly. %s "
    39 "won't work."
    40 msgstr ""
    41 "Il semble que votre configuration serveur empêche l&rsquo;extension de "
    42 "fonctionner correctement. %s ne pourra pas fonctionner."
     38msgid "It seems your server configuration prevents the plugin to work properly. %s won't work."
     39msgstr "Il semble que votre configuration serveur empêche l&rsquo;extension de fonctionner correctement. %s ne pourra pas fonctionner."
    4340
    4441#. Translators: 1 is the plugin name.
    45 #: inc/activate.php:118
     42#: inc/activate.php:117
    4643#, php-format
    47 msgid ""
    48 "It seems the url rewrite module is not activated on your server. %s won't "
    49 "work."
    50 msgstr ""
    51 "Il semble que le module de réécriture d&rsquo;url n&rsquo;est pas activé sur "
    52 "votre serveur. %s ne pourra pas fonctionner."
     44msgid "It seems the url rewrite module is not activated on your server. %s won't work."
     45msgstr "Il semble que le module de réécriture d&rsquo;url n&rsquo;est pas activé sur votre serveur. %s ne pourra pas fonctionner."
    5346
    5447#. Translators: 1, 2, and 3 are server technologies (Apache, Nginx, IIS7), 4 is the plugin name.
    55 #: inc/activate.php:120
     48#: inc/activate.php:119
    5649#, php-format
    57 msgid ""
    58 "It seems your server does not use %1$s, %2$s, nor %3$s. %4$s won't work."
    59 msgstr ""
    60 "Il semble que votre serveur n&rsquo;utilise ni %1$s, %2$s, ou %3$s. %4$s ne "
    61 "pourra pas fonctionner."
     50msgid "It seems your server does not use %1$s, %2$s, nor %3$s. %4$s won't work."
     51msgstr "Il semble que votre serveur n&rsquo;utilise ni %1$s, %2$s, ou %3$s. %4$s ne pourra pas fonctionner."
    6252
    6353#. Translators: 1 is the plugin name, 2 is a file name, 3 is a "Move Login" link.
    64 #: inc/activate.php:122
     54#: inc/activate.php:121
    6555#, php-format
    66 msgid ""
    67 "%1$s needs access to the %2$s file. Please visit the %3$s settings page and "
    68 "copy/paste the given code into the %2$s file."
    69 msgstr ""
    70 "%1$s a besoin d&rsquo;accéder au fichier %2$s. Veuillez vous rendre sur la "
    71 "page de réglages de %3$s et veuillez copier/coller le code fourni dans le "
    72 "fichier %2$s."
     56msgid "%1$s needs access to the %2$s file. Please visit the %3$s settings page and copy/paste the given code into the %2$s file."
     57msgstr "%1$s a besoin d&rsquo;accéder au fichier %2$s. Veuillez vous rendre sur la page de réglages de %3$s et veuillez copier/coller le code fourni dans le fichier %2$s."
    7358
    7459#. Translators: 1 is a server technology (Nginx), 2 is a "Move Login" link, 3 is the plugin name.
    75 #: inc/activate.php:124
     60#: inc/activate.php:123
    7661#, php-format
    77 msgid ""
    78 "It seems your server uses a %1$ system. You have to edit the rewrite rules "
    79 "by yourself in the configuration file. Please visit the %2$s settings page "
    80 "and take a look at the rewrite rules. %3$s is running but won't work "
    81 "correctly until you deal with those rewrite rules."
    82 msgstr ""
    83 "Il semble que votre serveur utilise un système %1$s. Vous devez éditer les "
    84 "règles de réécriture par vous-même dans le fichier de configuration. "
    85 "Veuillez vous rendre sur la page de réglages de %2$s et jetez un œil aux "
    86 "règles de réécriture. %3$s fonctionne mais ne pourra pas le faire "
    87 "correctement tant que vous ne vous serez pas occupé de ces règles."
     62msgid "It seems your server uses a %1$ system. You have to edit the rewrite rules by yourself in the configuration file. Please visit the %2$s settings page and take a look at the rewrite rules. %3$s is running but won't work correctly until you deal with those rewrite rules."
     63msgstr "Il semble que votre serveur utilise un système %1$s. Vous devez éditer les règles de réécriture par vous-même dans le fichier de configuration. Veuillez vous rendre sur la page de réglages de %2$s et jetez un œil aux règles de réécriture. %3$s fonctionne mais ne pourra pas le faire correctement tant que vous ne vous serez pas occupé de ces règles."
    8864
    8965#: inc/admin.php:152 inc/functions/deprecated.php:87
    90 #: inc/redirections-and-dies.php:190
     66#: inc/redirections-and-dies.php:181
    9167msgid "Cheatin&#8217; uh?"
    9268msgstr "Alors, on triche&nbsp;?"
    9369
     70#: inc/classes/class-sfml-options.php:312
     71#: inc/classes/class-sfml-options.php:319
     72msgid "Display an error message"
     73msgstr "Afficher un message d'erreur"
     74
     75#: inc/classes/class-sfml-options.php:313
     76#: inc/classes/class-sfml-options.php:320
     77msgid "Trigger a &laquo;Page not found&raquo; error"
     78msgstr "Déclencher une erreur &laquo;&#160;Page non trouvée&#160;&raquo;"
     79
     80#: inc/classes/class-sfml-options.php:314
     81#: inc/classes/class-sfml-options.php:321
     82msgid "Redirect to a \"WordPress\" &laquo;Page not found&raquo; error page"
     83msgstr "Rediriger vers une page d&rsquo;erreur &laquo;&#160;Page non trouvée&#160;&raquo; de WordPress"
     84
     85#: inc/classes/class-sfml-options.php:315
     86#: inc/classes/class-sfml-options.php:322
     87msgid "Redirect to the home page"
     88msgstr "Rediriger vers la page d&rsquo;accueil"
     89
     90#: inc/classes/class-sfml-options.php:318
     91msgid "Do nothing, redirect to the new login page (not recommended)"
     92msgstr "Ne rien faire, rediriger vers la nouvelle page de connexion (non recommandé)"
     93
    9494#. Translators: %s is an URL slug name.
    95 #: inc/classes/class-sfml-options.php:389
     95#: inc/classes/class-sfml-options.php:497
    9696#, php-format
    9797msgid "The slug %s is forbidden."
     
    100100msgstr[1] "Les identifiants %s sont interdits."
    101101
    102 #: inc/classes/class-sfml-options.php:392
     102#: inc/classes/class-sfml-options.php:500
    103103msgid "The links can't have the same slugs."
    104104msgstr "Les liens ne peuvent pas avoir les mêmes identifiants."
    105105
    106 #: inc/functions/deprecated.php:87 inc/redirections-and-dies.php:114
    107 #: inc/redirections-and-dies.php:190
     106#. Translators: 1: WordPress hook name, 2: version number, 3: alternative hook name.
     107#: inc/functions/compat.php:285
     108#, php-format
     109msgid "%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead."
     110msgstr "%1$s est <strong>déprécié</strong> depuis la version %2$s ! Utilisez %3$s à la place."
     111
     112#. Translators: 1: WordPress hook name, 2: version number.
     113#: inc/functions/compat.php:288
     114#, php-format
     115msgid "%1$s is <strong>deprecated</strong> since version %2$s with no alternative available."
     116msgstr "%1$s est <strong>déprécié</strong> depuis la version %2$s, aucune alternative n&rsquo;est disponible."
     117
     118#: inc/functions/deprecated.php:87 inc/redirections-and-dies.php:112
     119#: inc/redirections-and-dies.php:181
    108120msgid "Nope :)"
    109121msgstr "Raté :)"
    110122
    111 #: inc/functions/settings-page.php:19
     123#: inc/functions/settings-page.php:20
    112124msgid "Choose your new URLs"
    113125msgstr "Choisissez vos nouvelles adresses"
    114126
    115 #: inc/functions/settings-page.php:20
     127#: inc/functions/settings-page.php:21
    116128msgid "Access"
    117129msgstr "Accès"
    118130
    119 #: inc/functions/settings-page.php:42
     131#: inc/functions/settings-page.php:43
    120132msgid "Only lowercase letters, digits, - and _"
    121133msgstr "Seulement des lettres minuscules, chiffres, - et _"
    122134
    123 #: inc/functions/settings-page.php:60 inc/functions/settings-page.php:81
    124 msgid "Display an error message"
    125 msgstr "Afficher un message d'erreur"
     135#: inc/functions/settings-page.php:61
     136msgid "When a logged out user attempts to access the old login page."
     137msgstr "Quand un utilisateur non connecté tente d'accéder à l'ancienne page de connexion."
    126138
    127 #: inc/functions/settings-page.php:61 inc/functions/settings-page.php:82
    128 msgid "Redirect to a &laquo;Page not found&raquo; error page"
    129 msgstr ""
    130 "Rediriger vers une page d&rsquo;erreur &laquo;&#160;Page non trouvée&#160;"
    131 "&raquo;"
    132 
    133 #: inc/functions/settings-page.php:62 inc/functions/settings-page.php:83
    134 msgid "Redirect to the home page"
    135 msgstr "Rediriger vers la page d&rsquo;accueil"
    136 
    137 #: inc/functions/settings-page.php:64
    138 msgid "When a logged out user attempts to access the old login page."
    139 msgstr ""
    140 "Quand un utilisateur non connecté tente d'accéder à l'ancienne page de "
    141 "connexion."
    142 
    143 #: inc/functions/settings-page.php:71
     139#: inc/functions/settings-page.php:68
    144140msgctxt "noun"
    145141msgid "Redirects"
    146142msgstr "Redirections"
    147143
    148 #: inc/functions/settings-page.php:80
    149 msgid "Do nothing, redirect to the new login page (not recommended)"
    150 msgstr ""
    151 "Ne rien faire, rediriger vers la nouvelle page de connexion (non recommandé)"
    152 
    153 #: inc/functions/settings-page.php:85
     144#: inc/functions/settings-page.php:77
    154145msgid "Instead of redirecting a logged out user to the new login page:"
    155 msgstr ""
    156 "Plutôt que de rediriger un utilisateur non connecté vers la nouvelle page de "
    157 "connexion&nbsp;:"
     146msgstr "Plutôt que de rediriger un utilisateur non connecté vers la nouvelle page de connexion&nbsp;:"
    158147
    159148#. Translators: %s is an option value.
    160 #: inc/functions/settings-page.php:167 inc/functions/settings-page.php:210
     149#: inc/functions/settings-page.php:159 inc/functions/settings-page.php:202
    161150#, php-format
    162151msgctxt "default value"
     
    165154
    166155#. Translators: 1 is a file name, 2 is a file path, 3 and 4 are small parts of code.
    167 #: inc/functions/settings-page.php:240 inc/functions/settings-page.php:272
     156#: inc/functions/settings-page.php:229 inc/functions/settings-page.php:261
    168157#, php-format
    169 msgid ""
    170 "If the plugin fails to add the new rewrite rules to your %1$s file, add the "
    171 "following to your %1$s file in %2$s, replacing other %3$s rules if they "
    172 "exist, <strong>above</strong> the line reading %4$s:"
    173 msgstr ""
    174 "Si l&rsquo;extension ne peut ajouter les nouvelles règles de réécriture à "
    175 "votre fichier %1$s, ajoutez les lignes suivantes à votre fichier %1$s dans "
    176 "%2$s, en remplacement des autres règles liées à %3$s si elles existent, "
    177 "<strong>au-dessus</strong> de la ligne %4$s&#160;:"
     158msgid "If the plugin fails to add the new rewrite rules to your %1$s file, add the following to your %1$s file in %2$s, replacing other %3$s rules if they exist, <strong>above</strong> the line reading %4$s:"
     159msgstr "Si l&rsquo;extension ne peut ajouter les nouvelles règles de réécriture à votre fichier %1$s, ajoutez les lignes suivantes à votre fichier %1$s dans %2$s, en remplacement des autres règles liées à %3$s si elles existent, <strong>au-dessus</strong> de la ligne %4$s&#160;:"
    178160
    179161#. Translators: 1 is a file name, 2 is a small part of code.
    180 #: inc/functions/settings-page.php:255
     162#: inc/functions/settings-page.php:244
    181163#, php-format
    182 msgid ""
    183 "The plugin can't add the new rewrite rules to your %1$s file by itself, you "
    184 "will need to add them manually inside the %2$s block."
    185 msgstr ""
    186 "L&rsquo;extension ne peut ajouter les nouvelles règles de réécriture à votre "
    187 "fichier %1$s, vous devrez les ajouter manuellement à l&rsquo;intérieur du "
    188 "bloc %2$s."
     164msgid "The plugin can't add the new rewrite rules to your %1$s file by itself, you will need to add them manually inside the %2$s block."
     165msgstr "L&rsquo;extension ne peut ajouter les nouvelles règles de réécriture à votre fichier %1$s, vous devrez les ajouter manuellement à l&rsquo;intérieur du bloc %2$s."
    189166
    190167#. Translators: %s is a file name.
    191 #: inc/functions/settings-page.php:288
     168#: inc/functions/settings-page.php:277
    192169#, php-format
    193170msgid "Your %s file is not writable."
     
    195172
    196173#. Translators: 1 is a constant name, 2 is a constant value.
    197 #: inc/functions/settings-page.php:296
     174#: inc/functions/settings-page.php:285
    198175#, php-format
    199 msgid ""
    200 "The constant %1$s is defined to %2$s, the settings below won't take effect."
    201 msgstr ""
    202 "La constante %1$s est définie à %2$s, les réglages ci-dessous ne prendront "
    203 "pas effet."
     176msgid "The constant %1$s is defined to %2$s, the settings below won't take effect."
     177msgstr "La constante %1$s est définie à %2$s, les réglages ci-dessous ne prendront pas effet."
    204178
    205 #: inc/redirections-and-dies.php:114
     179#: inc/redirections-and-dies.php:112
    206180msgid "No no no, the login form is not here."
    207181msgstr "Non non non, le formulaire de connexion ne se trouve pas ici."
    208182
    209183#. Translators: Description of the plugin/theme
    210 #: sf-move-login.php:92
     184#. Description of the plugin/theme
     185#: sf-move-login.php:93
    211186msgid "Change your login URL."
    212187msgstr "Changez l&rsquo;url de votre page de connexion."
    213 
    214 #~ msgid "Administration area"
    215 #~ msgstr "Zone d'administration"
    216 
    217 #~ msgid ""
    218 #~ "When a not connected user attempts to access the administration area."
    219 #~ msgstr ""
    220 #~ "Lorsqu&rsquo;un utilisateur non connecté tente d&rsquo;accéder à la zone "
    221 #~ "d&rsquo;administration."
    222 
    223 #~ msgid ""
    224 #~ "It seems your server does not use <i>Apache</i>, <i>Nginx</i>, nor "
    225 #~ "<i>IIS7</i>. <strong>Move Login</strong> won't work."
    226 #~ msgstr ""
    227 #~ "Il semble que votre serveur n&rsquo;utilise ni <i>Apache</i>, <i>Nginx</"
    228 #~ "i>, ou <i>IIS7</i>. <strong>Move Login</strong> ne pourra pas fonctionner."
    229 
    230 #~ msgid ""
    231 #~ "Change your login URL for something like <code>http://example.com/login</"
    232 #~ "code> and stop login brute force attempts."
    233 #~ msgstr ""
    234 #~ "Changez l&rsquo;url de votre page de connexion pour quelque chose comme "
    235 #~ "<code>http://example.com/login</code> et stoppez les tentatives de "
    236 #~ "connexion par brute force."
  • sf-move-login/trunk/readme.txt

    r1656995 r1664767  
    6868== Changelog ==
    6969
     70= 2.5.2 =
     71
     72* 2017/05/25
     73* New: a new option is available. Instead of redirecting to the a "WordPress" 404 error page, you can choose to directly trigger the 404 error. Pro: the user is not directed, the URL doesn't change. Con: the user sees the browser error page, it probably is ugly (but do we really care?).
     74* Fixed the blank page that was displaying instead of redirecting the user to the new login URL.
     75* Dev stuff: in case the plugin has trouble determining your server technology, take a look at `sfml_is_apache()`, `sfml_is_iis7()`, and `sfml_is_nginx()`: returned values can be filtered with a MU plugin.
     76
    7077= 2.5.1 =
    7178
     
    7683
    7784* 2017/05/09
    78 * Some files from WordPress core were still able to redirect a logged out user to the new login URL. Now Move Login filters every redirection to prevent it.
     85* New: some files from WordPress core were still able to redirect a logged out user to the new login URL. Now Move Login filters every redirection to prevent it.
     86* Dev stuff: the hook `sfml_wp_admin_error` is now deprecated. Please use the filter `sfml_login_redirect_location` instead.
    7987
    8088= 2.4.3 =
  • sf-move-login/trunk/sf-move-login.php

    r1656995 r1664767  
    44 * Plugin URI: https://www.screenfeed.fr/plugin-wp/move-login/
    55 * Description: Change your login URL.
    6  * Version: 2.5.1
     6 * Version: 2.5.2
    77 * Author: Grégory Viguier
    88 * Author URI: https://www.screenfeed.fr/
     
    2626/*------------------------------------------------------------------------------------------------*/
    2727
    28 define( 'SFML_VERSION',         '2.5.1' );
     28define( 'SFML_VERSION',         '2.5.2' );
    2929define( 'SFML_FILE',            __FILE__ );
    3030define( 'SFML_PLUGIN_BASENAME', plugin_basename( SFML_FILE ) );
     
    5151 */
    5252function sfml_init() {
     53    sfml_lang_init();
     54
    5355    SFML_Options::get_instance();
    5456
     
    7375/*------------------------------------------------------------------------------------------------*/
    7476
    75 add_action( 'init', 'sfml_lang_init' );
    7677/**
    7778 * Load translations.
Note: See TracChangeset for help on using the changeset viewer.