بابهت: یارمەتی لە چاک کردنی پێوەکراوێک
من دەمەوێت پێوەکراوەکم ریک بخەم بەناوی subway کە کاری ئەوەیە میمبەرەکانی ماڵپەرەکەت ناچار بەچوونەژوورەوەدەکات کە پەریێکی ماڵپەرەکەت دەکاتەوە
وەک
کە لەبڕی پێشاندانی بابەتەکان فۆرمی چونەژورەوە پێشان دەدات دەمەویت لەبرێ ئەوی فۆرمیک لە فووکارەکەم بکاتەوە بروات بۆ wp-login.php
ئەوە بەستەری پێوەکراوەکە
https://wordpress.org/plugins-wp/subway/
فایڵی functions.php
<?php
/**
* Includes all the file necessary for Subway.
*
* @package Subway
*/
if ( ! defined( 'ABSPATH' ) ) { die(); }
// Redirect the user when he/she visit wp-admin or wp-login.php.
add_action( 'init', 'subway_redirect_login' );
// Redirect the user after successful logged in attempt.
add_filter( 'login_redirect', 'subway_redirect_user_after_logged_in', 10, 3 );
// Handle failed login redirection.
add_action( 'wp_login_failed', 'subway_redirect_login_handle_failure' );
/**
* Redirect all wp-login.php post
* and get request to the user assigned log-in page
*
* @return void
*/
function subway_redirect_login() {
// Only run this function when on wp-login.php.
if ( ! in_array( $GLOBALS['pagenow'], array( 'wp-login.php' ), true ) ) {
return;
}
// Bypass login if specified.
$no_redirect = filter_input( INPUT_GET, 'no_redirect', FILTER_VALIDATE_BOOLEAN );
// Bypass wp-login.php?action=*.
$has_action = filter_input( INPUT_GET, 'action', FILTER_SANITIZE_STRING );
// Has any errors?
$has_error = filter_input( INPUT_GET, 'error', FILTER_SANITIZE_STRING );
// Error Types.
$has_type = filter_input( INPUT_GET, 'type', FILTER_SANITIZE_STRING );
// Set the default to our login page.
$redirect_page = subway_get_redirect_page_url();
if ( $has_error && $has_type ) {
$redirect_to = add_query_arg( array(
'login' => 'failed',
'type' => $has_type,
), $redirect_page );
wp_safe_redirect( esc_url_raw( $redirect_to ) );
die();
}
// Bypass wp-login.php?action=* link.
if ( $has_action ) {
return;
}
if ( $no_redirect ) {
return;
}
// Check if buddypress activate page.
if ( function_exists( 'bp_is_activation_page' ) ) {
if ( bp_is_activation_page() ) {
return;
}
}
// Check if buddypress registration page.
if ( function_exists( 'bp_is_register_page' ) ) {
if ( bp_is_register_page() ) {
return;
}
}
// Store for checking if this page equals wp-login.php.
$curr_paged = basename( $_SERVER['REQUEST_URI'] );
if ( empty( $redirect_page ) ) {
return;
}
// Ff user visits wp-admin or wp-login.php, redirect them.
if ( strstr( $curr_paged, 'wp-login.php' ) ) {
if ( isset( $_GET['interim-login'] ) ) {
return;
}
// Check if there is an action present action might represent user trying to log out.
if ( isset( $_GET['action'] ) ) {
$action = $_GET['action'];
if ( 'logout' === $action ) {
return;
}
}
// Only redirect if there are no incoming post data.
if ( empty( $_POST ) ) {
wp_safe_redirect( $redirect_page );
}
// Redirect to error page if user left username and password blank.
if ( ! empty( $_POST ) ) {
if ( empty( $_POST['log'] ) && empty( $_POST['pwd'] ) ) {
$redirect_to = add_query_arg( array(
'login' => 'failed',
'type' => '__blank',
), $redirect_page );
wp_safe_redirect( esc_url_raw( $redirect_to ) );
} elseif ( empty( $_POST['log'] ) && ! empty( $_POST['pwd'] ) && ! empty( $_POST['redirect_to'] ) ) {
// Username empty.
$redirect_to = add_query_arg( array(
'login' => 'failed',
'type' => '__userempty',
), $redirect_page );
wp_safe_redirect( esc_url_raw( $redirect_to ) );
} elseif ( ! empty( $_POST['log'] ) && empty( $_POST['pwd'] ) && ! empty( $_POST['redirect_to'] ) ) {
// Password empty.
$redirect_to = add_query_arg( array(
'login' => 'failed',
'type' => '__passempty',
), $redirect_page );
wp_safe_redirect( esc_url_raw( $redirect_to ) );
} else {
// Generic.
$redirect_to = add_query_arg( array(
'login' => 'failed',
'type' => 'default',
), $redirect_page );
wp_safe_redirect( esc_url_raw( $redirect_to ) );
}
}
}
return;
}
/**
* Redirects the user to selected page or custom url.
*
* @param string $redirect_to 'login_redirect' filter callback argument that holds the current $redirect_to value.
* @param object $request 'login_redirect' filter callback argument that holds request header.
* @param object $user 'login_redirect' filter callback argument that holds logged in user info.
* @return string The final redirection url
*/
function subway_redirect_user_after_logged_in( $redirect_to, $request, $user ) {
$subway_redirect_type = get_option( 'subway_redirect_type' );
// Redirect the user to default behaviour if there are no redirect type option saved.
if ( empty( $subway_redirect_type ) ) {
return $redirect_to;
}
if ( 'default' === $subway_redirect_type ) {
return $redirect_to;
}
if ( 'page' === $subway_redirect_type ) {
// Get the page url of the selected page if the admin selected 'Custom Page' in the redirect type settings.
$selected_redirect_page = intval( get_option( 'subway_redirect_page_id' ) );
// Redirect to default WordPress behaviour if the user did not select page.
if ( empty( $selected_redirect_page ) ) {
return $redirect_to;
}
// Otherwise, get the permalink of the saved page and let the user go into that page.
return get_permalink( $selected_redirect_page );
} elseif ( 'custom_url' === $subway_redirect_type ) {
// Get the custom url saved in the redirect type settings.
$entered_custom_url = get_option( 'subway_redirect_custom_url' );
// Redirect to default WordPress behaviour if the user did enter a custom url.
if ( empty( $entered_custom_url ) ) {
return $redirect_to;
}
// Otherwise, get the custom url saved and let the user go into that page.
$current_user = wp_get_current_user();
$entered_custom_url = str_replace( '%user_id%', $user->ID, $entered_custom_url );
$entered_custom_url = str_replace( '%user_name%', $user->user_login, $entered_custom_url );
return $entered_custom_url;
}
// Otherwise, quit and redirect the user back to default WordPress behaviour.
return $redirect_to;
}
/**
* Handles the failure login attempt from customized login page.
*
* @param object $user WordPress callback function.
* @return void
*/
function subway_redirect_login_handle_failure( $user ) {
// Pull the sign-in page url.
$sign_in_page = wp_login_url();
$custom_sign_in_page_url = subway_get_redirect_page_url();
if ( ! empty( $custom_sign_in_page_url ) ) {
$sign_in_page = $custom_sign_in_page_url;
}
// Check that were not on the default login page.
if ( ! empty( $sign_in_page ) && ! strstr( $sign_in_page,'wp-login' ) && ! strstr( $sign_in_page,'wp-admin' ) && null !== $user ) {
// make sure we don't already have a failed login attempt.
if ( ! strstr( $sign_in_page, '?login=failed' ) ) {
// Redirect to the login page and append a querystring of login failed.
$permalink = add_query_arg( array(
'login' => 'failed',
'type' => 'default',
), $custom_sign_in_page_url );
wp_safe_redirect( esc_url_raw( $permalink ) );
die();
} else {
wp_safe_redirect( $sign_in_page );
die();
}
return;
}
return;
}
/**
* Helper function to return the user selected page
* inside the 'Login' under 'Reading' settings
*
* @return void
*/
function subway_get_redirect_page_url() {
$selected_login_post_id = intval( get_option( 'subway_login_page' ) );
if ( 0 === $selected_login_post_id ) {
return;
}
$login_post = get_post( $selected_login_post_id );
if ( ! empty( $login_post ) ) {
return get_permalink( $login_post->ID );
}
return false;
}
function subway_integrate_login_form_filter( $contents ) {
ob_start();
do_action('login_form');
return ob_get_clean() . $contents;
}فایڵی login-form.php
<?php
/**
* The login for shortcode template
*
* @since 1.0
*/
if ( ! defined( 'ABSPATH' ) ) { die(); }
/**
* Callback function to register 'subway_login'
* shortcode in order to display the login form
* inside the page using 'subway_login' shortcode
*
* @param array $atts shortcode callback attributes
* @return string output_buffer
*/
function subway_wp_login( $atts ) {
// begin output buffering
ob_start();
$args = array(
'echo' => true,
'form_id' => 'loginform',
'label_username' => __( 'Username', 'subway' ),
'label_password' => __( 'Password', 'subway' ),
'label_remember' => __( 'Remember Me', 'subway' ),
'label_log_in' => __( 'Log In', 'subway' ),
'id_username' => 'user_login',
'id_password' => 'user_pass',
'id_remember' => 'rememberme',
'id_submit' => 'wp-submit',
'remember' => true,
'value_username' => '',
'value_remember' => false,
'redirect' => home_url(),
);
$error_login_message = '';
$message_types = array();
add_filter('login_form_middle', 'subway_integrate_login_form_filter');
if ( isset( $_GET['login'] ) ) {
if ( 'failed' === $_GET['login'] ) {
if ( isset( $_GET['type'] ) ) {
$message_types = array(
'default' => array(
'message' => __( 'There was an error trying to sign-in to your account. Make sure the credentials below are correct.', 'subway' ),
),
'__blank' => array(
'message' => __( 'Required: Username and Password cannot be empty.', 'subway' ),
),
'__userempty' => array(
'message' => __( 'Required: Username cannot be empty.', 'subway' ),
),
'__passempty' => array(
'message' => __( 'Required: Password cannot be empty.', 'subway' ),
),
'fb_invalid_email' => array(
'message' => __( 'Facebook email address is invalid or is not yet verified.', 'subway' ),
),
'fb_error' => array(
'message' => __( 'Facebook Application Error. Misconfigured or App is rejected.', 'subway' ),
),
'app_not_live' => array(
'message' => __( 'Unable to fetch your Facebook Profile.', 'subway' ),
),
'gears_username_or_email_exists' => array(
'message' => __( 'Username or email address already exists', 'subway' ),
),
'gp_error_authentication' => array(
'message' => __( 'Google Plus Authentication Error. Invalid Client ID or Secret.', 'subway' ),
),
);
$message = $message_types['default']['message'];
if ( array_key_exists( $_GET['type'], $message_types ) ) {
$message = $message_types[ $_GET['type'] ]['message'];
}
$error_login_message = '<div id="message" class="error">'. esc_html( $message ) .'</div>';
} else {
$error_login_message = '<div id="message" class="error">'.__( 'Error: Invalid username and password combination.', 'subway' ).'</div>';
}
}
}
if ( isset( $_GET['_redirected'] ) ) {
$error_login_message = '<div id="message" class="success">'.__( 'Oops! Looks like you need to login in order to view the page.', 'subway' ).'</div>';
}
?>
<?php if ( ! is_user_logged_in() ) { ?>
<div class="mg-top-35 mg-bottom-35 subway-login-form">
<div class="subway-login-form-form">
<div class="subway-login-form__actions">
<h3>
<?php _e( 'Account Sign-in', 'subway' ); ?>
</h3>
<?php do_action( 'gears_login_form' ); ?>
</div>
<div class="subway-login-form-message">
<?php echo $error_login_message; ?>
</div>
<div class="subway-login-form__form">
<?php echo wp_login_form( $args ); ?>
</div>
</div>
</div>
<?php } else { ?>
<div class="mg-top-35 mg-bottom-35 subway-login-sucessfull" style="background: #CDDC39; padding: 15px 15px 15px 15px;border-radius: 4px;color: #616161;">
<p style="margin-bottom: 0px;">
<?php echo esc_html__( apply_filters( 'subway_login_message', 'Great! You have succesfully login.' ), 'subway' ); ?>
</p>
</div>
<?php } ?>
<script>
jQuery(document).ready(function($){
"use strict";
$(window).load( function(){
var $input = $('.subway-login-form__form p > input');
if ( $input.val().length >= 1 ) {
$input.prev('label').addClass('inactive');
}
});
$('.subway-login-form__form p > input').focusin(function(){
$(this).prev('label').addClass('inactive');
}).focusout(function(){
if ( $(this).val().length < 1 ) {
$(this).prev('label').removeClass('inactive');
}
});
});
</script>
<?php
return ob_get_clean();
}
add_action( 'login_form_middle', 'subway_add_lost_password_link' );
function subway_add_lost_password_link() {
return '<p class="subway-login-lost-password"><a href="'.esc_url( wp_lostpassword_url( $redirect = '' ) ).'">' . __( 'Forgot Password', 'subway' ) . '</a></p>';
}
/**
* callback function to 'init' hook to register
* @return void
*/
function subway_register_shortcode() {
add_shortcode( 'subway_login', 'subway_wp_login' );
return;
}
add_action( 'init', 'subway_register_shortcode' );
?>فایڵی private.php
<?php
/**
* This file contains the logic for our redirection
*
* @package subway
*/
if ( ! defined( 'ABSPATH' ) ) { die();
}
// Check if publitize is enabled inside theme option.
// Redirect all pages to login page except for selected page.
$subway_publitize_web = intval( get_option( 'subway_is_public' ) );
if ( 1 !== $subway_publitize_web ) {
add_action( 'wp', 'subway_redirect_to_login' );
}
/**
* Redirects all the pages except for few selected pages inside
* the reading settings
*
* (Front-end General)
*
* @return void
*/
function subway_redirect_to_login() {
session_start();
global $post;
$post_copy = &$post;
$login_page_id = intval( get_option( 'subway_login_page' ) );
$excluded_page = subway_get_excluded_page_id_collection();
// Already escaped inside 'subway_get_redirect_page_url'.
$redirect_page = subway_get_redirect_page_url();
// Check if redirect page is empty or not.
if ( empty( $redirect_page ) ) {
return;
}
// Check if buddypress activate page.
if ( function_exists( 'bp_is_activation_page' ) ) {
if ( bp_is_activation_page() ) {
return;
}
}
// Check if buddypress registration page.
if ( function_exists( 'bp_is_register_page' ) ) {
if ( bp_is_register_page() ) {
return;
}
}
// Assign 0 value to empty $post->ID to prevent exception.
// This applies to custom WordPress pages such as BP Members Page and Groups.
if ( empty( $post_copy ) ) {
$post_copy = new stdclass;
$post_copy->ID = 0;
}
$current_page_id = intval( $post_copy->ID );
// Check if $current_page_id && $selected_blog_id is equal to each other.
// If that is the case, get the page ID instead of global $post->ID that the query returns.
// The ID of the first post object inside the loop is not correct.
$blog_id = intval( get_option( 'page_for_posts' ) );
if ( is_home() ) {
if ( $blog_id === $login_page_id ) {
$current_page_id = $blog_id;
}
}
if ( isset( $_SESSION['redirected'] ) ) {
unset( $_SESSION['redirected'] );
return;
}
// Only execute the script for non-loggedin visitors.
if ( ! is_user_logged_in() ) {
if ( $current_page_id !== $login_page_id ) {
if ( ! in_array( $current_page_id, $excluded_page, true ) ) {
$_SESSION['redirected'] = true;
wp_safe_redirect( add_query_arg( array( '_redirected' => 'yes' ), $redirect_page ) );
die();
}
}
}
return;
}
/**
* Helper function to get the ID collection of all
* the selected pages inside the reading settings.
*
* @return array the formatted version of pages ID separated by comma
*/
function subway_get_excluded_page_id_collection() {
$subway_public_post = get_option( 'subway_public_post' );
$excluded_pages_collection = array();
if ( ! empty( $subway_public_post ) ) {
$excluded_pages_collection = explode( ',', $subway_public_post );
}
// Should filter it by integer, spaces will be ignored, other strings.
// Will be converted to zero '0'.
return array_filter( array_map( 'intval', $excluded_pages_collection ) );
}
add_action( 'admin_init', 'subway_settings_api_init' );
/**
* Register all the settings inside 'Reading' section
* of WordPress Administration Panel
*
* @return void
*/
function subway_settings_api_init() {
// Add new 'Pages Visibility Settings'.
add_settings_section(
'subway_setting_section',
__( 'Pages Visibility Settings', 'subway' ),
'subway_setting_section_callback_function',
'reading'
);
// WP Options 'subway_public_post'.
add_settings_field(
'subway_public_post',
__( 'Public Posts IDs', 'subway' ),
'subway_setting_callback_function',
'reading',
'subway_setting_section'
);
// WP Options 'subway_is_public'.
add_settings_field(
'subway_is_public',
__( 'Public Website', 'subway' ),
'subway_is_public_form',
'reading',
'subway_setting_section'
);
// WP Options 'subway_login_page'.
add_settings_field(
'subway_login_page',
__( 'Login Page', 'subway' ),
'subway_login_page_form',
'reading',
'subway_setting_section'
);
// WP Options 'subway_redirect_type'.
add_settings_field(
'subway_redirect_type',
__( 'Redirect Type', 'subway' ),
'subway_redirect_option_form',
'reading',
'subway_setting_section'
);
// WP Options 'subway_bypassing_info'.
add_settings_field(
'subway_bypassing_info',
__( 'Bypassing Redirect', 'subway' ),
'subway_bypassing_option_form',
'reading',
'subway_setting_section'
);
// Register all the callback settings id.
register_setting( 'reading', 'subway_public_post' );
register_setting( 'reading', 'subway_is_public' );
register_setting( 'reading', 'subway_login_page' );
register_setting( 'reading', 'subway_redirect_type' );
register_setting( 'reading', 'subway_redirect_page_id' );
register_setting( 'reading', 'subway_redirect_custom_url' );
}
/**
* Register a callback function that will handle
* the 'Pages Visibility Settings' Page.
*
* @return void
*/
function subway_setting_section_callback_function() {
// Do nothing.
return;
}
/**
* Callback function for 'subway_public_post' setting.
*
* @return void
*/
function subway_setting_callback_function() {
echo '<textarea id="subway_public_post" name="subway_public_post" rows="5" cols="95">' . esc_attr( trim( get_option( 'subway_public_post' ) ) ) . '</textarea>';
echo '<p class="description">' . nl2br( esc_html( "Enter the IDs of posts and pages that you wanted to show in public. You need to separate it by ',' (comma), \nfor example: 143,123,213. Alternatively, you can enable public viewing of all of your pages and posts by checking the option below.", 'subway' ) ) . '</p>';
return;
}
/**
* Callback function for 'subway_is_public' setting
*
* @return void
*/
function subway_is_public_form() {
echo '<label for="subway_is_public"><input ' . checked( 1, get_option( 'subway_is_public' ), false ) . ' value="1" name="subway_is_public" id="subway_is_public" type="checkbox" class="code" /> Check to make all of your posts and pages visible to public.</label>';
echo '<p class="description">' . esc_html__( 'Pages like user profile, members, and groups are still only available to the rightful owner of the profile.', 'subway' ) . '</p>';
return;
}
/**
* Callback function for 'subway_login_page' setting
*
* @return void
*/
function subway_login_page_form() {
$subway_login_page_id = intval( get_option( 'subway_login_page' ) );
if ( ! empty( $subway_login_page_id ) ) {
$login_page_object = get_post( $subway_login_page_id );
if ( ! empty( $login_page_object ) && isset( $login_page_object->post_content ) ) {
// Automatically prepend the login shortcode if no
// Shortcode exists in the selected login page.
if ( ! has_shortcode( $login_page_object->post_content, 'subway_login' ) ) {
$new_post_object = array(
'ID' => $login_page_object->ID,
'post_content' => '[subway_login] ' . $login_page_object->post_content,// Prepend Only.
);
wp_update_post( $new_post_object );
}
}
}
wp_dropdown_pages(
array(
'name' => 'subway_login_page',
'selected' => intval( $subway_login_page_id ),
'show_option_none' => esc_html__( '---', 'subway' ),
)
);
echo '<p class="description">' . sprintf( esc_html__( 'Select a page to use as a login page for your website. Select a login page and save the changes to make your site private. Leave blank to make your site public. %1$s.', 'subway' ), '<span style="font-weight: bold; color: #ad4a4a;">' . esc_html__( 'You need to add "[subway_login]" shortcode in the selected page to show the login form (this is automatic)', 'subway' ) ) . '</span></p>';
return;
}
/**
* Callback function for 'subway_bypassing_info' setting
*
* @return void
*/
function subway_bypassing_option_form() {
echo "<p class='description'>";
echo sprintf(
__(
"Use the following link to bypass the log-in page
and go directly to your website's wp-login URL (http://yoursiteurl.com/wp-login.php):
<br><br> <strong>%s</strong>", 'subway'
),
site_url( 'wp-login.php?no_redirect=true' )
);
echo '</p>';
return;
}
/**
* Callback function for 'subway_redirect_option' setting.
*
* @return void
*/
function subway_redirect_option_form() {
?>
<style>
.subway-redirect-option-section {
background: #fff;
padding: 15px 20px;
margin: 15px 0;
}
</style>
<p class="subway-redirect-type-choices">
<!-- Page -->
<label for="subway_use_page">
<input <?php checked( 'page', get_option( 'subway_redirect_type' ), true ); ?> value="page" name="subway_redirect_type" id="subway_use_page" type="radio" class="code" />
<?php esc_html_e( 'Custom Page', 'subway' ); ?>
</label>
<!-- Custom URL -->
<label for="subway_use_custom_url">
<input <?php checked( 'custom_url', get_option( 'subway_redirect_type' ), true ); ?> value="custom_url" name="subway_redirect_type" id="subway_use_custom_url" type="radio" class="code" />
<?php esc_html_e( 'Custom URL', 'subway' ); ?>
</label>
<!-- Default Behavior -->
<label for="subway_use_default">
<input <?php checked( 'default', get_option( 'subway_redirect_type' ), true ); ?> value="default" name="subway_redirect_type" id="subway_use_default" type="radio" class="code" />
<?php esc_html_e( 'Default Behavior', 'subway' ); ?>
</label>
</p>
<p class="description">
<?php
esc_html_e('Where do you want your members to go after logging-in? You can pick a page, a Custom URL, or just a WordPress Default behavior. Page and Custom URL has its settings.', 'subway'
);
?>
</p>
<div id="subway_redirect_page_option_section" class="hidden subway-redirect-option-section">
<label for="subway_redirect_page_id">
<?php esc_html_e( 'Select Page' ); ?>
</label>
<?php
// Choosing page for redirect.
wp_dropdown_pages(
array(
'name' => 'subway_redirect_page_id',
'selected' => intval( get_option( 'subway_redirect_page_id' ) ),
'show_option_none' => esc_html__( '-', 'subway' ),
)
);
?>
<p class="description">
<?php _e( 'The selected page will be used as the redirect endpoint for all of your users. Selecting blank (-) will redirect the user to the default redirect defined in WordPress or other plugins. Choose "Custom URL" if you want to redirect to a custom URL or domain.', 'subway' ); ?>
</p>
</div>
<div id="subway_redirect_custom_url_option_section" class="hidden subway-redirect-option-section">
<label for="subway_redirect_custom_url">
<?php esc_attr_e( 'Enter Redirect URL:', 'subway' ); ?>
</label>
<input value="<?php echo esc_attr( esc_url( get_option( 'subway_redirect_custom_url' ) ) ); ?>" type="text" name="subway_redirect_custom_url" placeholder="<?php esc_attr_e( 'http://', 'subway' ); ?>"
id="subway_redirect_custom_url" size="75" />
<p class="description"><br>
<?php
echo sprintf( __( 'When entering a custom domain, you can use a variable string such us: %1$s and %2$s. For example, http://yoursiteurl.com/members/<strong>%2$s</strong> will translate to http://yoursiteurl/members/<strong>admin</strong> where "admin" is equal to the %2$s variable; http://yoursiteurl.com/users/<strong>%1$s</strong> will translate to http://yoursiteurl.com/users/<strong>4</strong> where "4" is equal to the %1$s. Both variables refer to the current user that is logged-in.', 'subway' ), '%user_id%', '%user_name%' );
?>
</p><br>
<p class="description">
<?php esc_attr_e( 'Leave empty to use existing WordPress or other 3rd party plugin redirect option.', 'subway' ); ?>
</p><br>
<p class="description">
<?php esc_html_e( 'Warning: External URLs are not supported by WordPress Function (wp_safe_redirect) and will be redirected back to default WordPress behavior.', 'subway' ); ?>
</p>
</div>
<!-- Subway Use Default -->
<div id="subway_redirect_default_option_section" class="hidden subway-redirect-option-section">
<p>
<?php
esc_html_e( "By choosing the default behavior, the redirect type will be set to the default WordPress' behavior. For example, if you have plugins like Peter's Login Redirect. This option will disable Subway's redirect and use the Peter's Login Redirect Instead.", 'subway' );
?>
</p>
</div>
<script>
jQuery(document).ready( function( $ ) {
"use strict";
subway_toggle_use_custom_page();
subway_toggle_use_custom_url();
subway_toggle_use_default();
$("#subway_use_page").on('click', function(){
subway_toggle_use_custom_page();
});
$("#subway_use_custom_url").on('click', function(){
subway_toggle_use_custom_url();
});
$("#subway_use_default").on('click', function(){
subway_toggle_use_default();
});
function subway_toggle_use_default() {
if( $('#subway_use_default').is(':checked')) {
$('#subway_redirect_custom_url_option_section').addClass('hidden');
$('#subway_redirect_default_option_section').removeClass('hidden');
$('#subway_redirect_page_option_section').addClass('hidden');
}
return;
}
function subway_toggle_use_custom_url() {
if( $('#subway_use_custom_url').is(':checked')) {
$('#subway_redirect_custom_url_option_section').removeClass('hidden');
$('#subway_redirect_default_option_section').addClass('hidden');
$('#subway_redirect_page_option_section').addClass('hidden');
}
return;
}
function subway_toggle_use_custom_page() {
if( $('#subway_use_page').is(':checked')) {
$('#subway_redirect_custom_url_option_section').addClass('hidden');
$('#subway_redirect_default_option_section').addClass('hidden');
$('#subway_redirect_page_option_section').removeClass('hidden');
}
return;
}
});
</script>
<?php
}فایڵی README.md
[](https://insight.sensiolabs.com/projects/e85826fc-c1cb-47f1-9448-2a04b7b00eb1)
[](https://scrutinizer-ci.com/g/codehaiku/subway-2.0/?branch=master) [](https://scrutinizer-ci.com/g/codehaiku/subway-2.0/build-status/master)
<h3><strong>Subway - Private WordPress Site Option</strong></h3>
Subway is a small plugin for WordPress that allows you to hide the content of your website to non-logged in visitors and only displays them to logged in users.
This plugin redirects the users to the provided login page with a login form that allows them to type their username/email and password combination.
It validates the users’ credentials and displays a set of configurable messages if there are errors such as invalid username, empty username, wrong password, and etcetera.
The plugin has settings inside the Administration Panel (‘Settings’ > 'Subway') that allows you to configure where you want the user to be taken after he/she has successfully logged in, this can be a page, a custom URL, or just the default behavior.
<strong>Current Version: 2.0.3</strong>
<h3><strong>Caveats</strong></h3>
Subway is only built for WordPress website owners to redirect non-logged in users to a custom login form. This plugin is not a replacement for Membership websites where a complex set of configurations are allowed. There are no payments model, subscriptions, and role types.
Subway is good for Private Intranet Websites where membership is required.
<h3><strong>Installation</strong></h3>
<strong>Manual:</strong>
Download and unzip the "subway.zip" plugin.
Upload the entire "subway" directory to your '/wp-content/plugins/' directory.
Activate the "Subway" plugin through the Plugins menu in WordPress.
Go to ‘Settings’ > ‘Reading’ to set-up the plugin.
<strong>Automatic:</strong>
Click here to learn how to automatically add the plugin using the built-in plugin installer.فایڵی subway.php
<?php
/**
* Plugin Name: Subway
* Description: A WordPress plugin that will help you make your website private. Useful for intranet websites.
* Version: 1.2.0
* Author: Dunhakdis
* Author URI: http://dunhakdis.me
* Text Domain: subway
* License: GPL2
*
* Includes all the file necessary for Subway.
*
* PHP version 5
*
* @since 1.0
* @package subway
*/
if ( ! defined( 'ABSPATH' ) ) {
exit();
}
// Include our plugin login forms and shortcodes.
require_once plugin_dir_path( __FILE__ ) . 'login-form.php';
// Include our plugin functions.
require_once plugin_dir_path( __FILE__ ) . 'functions.php';
// Include the script that handles the redirections.
require_once plugin_dir_path( __FILE__ ) . 'private.php';
// Disable Thrive-Intranet plugin if this plugin is active to prevent conflicts.
register_activation_hook( __FILE__, 'subway_deactivate_thrive_intranet' );
// Plugin l10n.
add_action( 'plugins_loaded', 'subway_localize_plugin' );
/**
* Register our activation hook
* This will actually deactivate the Thrive Intranet plugin.
*
* @return void
*/
function subway_deactivate_thrive_intranet() {
// Deactivate Thrive Intranet in case it is used to prevent conflict.
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
// Deactivate the plugin.
deactivate_plugins( '/thrive-intranet/thrive-intranet.php' );
return;
}
// Enable GitHub Updater.
add_action( 'init', 'subway_plugin_updater_init' );
/**
* The callback function that wraps 'WP_GitHub_Updater'
* to init action of WordPress to check for our plugin updates.
*
* @return void
*/
function subway_plugin_updater_init() {
if ( is_admin() ) {
include_once plugin_dir_path( __FILE__ ) . '/update-check.php';
$repo_name = 'subway';
$config = array(
'slug' => plugin_basename( __FILE__ ),
'proper_folder_name' => 'subway',
'api_url' => sprintf( 'https://api.github.com/repos/codehaiku/%s', $repo_name ),
'raw_url' => sprintf( 'https://raw.github.com/codehaiku/%s/master', $repo_name ),
'github_url' => sprintf( 'https://github.com/codehaiku/%s', $repo_name ),
'zip_url' => sprintf( 'https://github.com/codehaiku/%s/zipball/master', $repo_name ),
'sslverify' => true,
'requires' => '4.0',
'tested' => '4.4.2',
'readme' => 'README.md',
'access_token' => '',
);
new WP_GitHub_Updater( $config );
}
return;
}
/**
* Subway l10n callback.
*
* @return void
*/
function subway_localize_plugin() {
$rel_path = basename( dirname( __FILE__ ) ) . '/languages';
load_plugin_textdomain( 'subway', false, $rel_path );
return;
}فایڵی update-check.php
<?php
if ( class_exists( 'WP_GitHub_Updater' ) ) {
return;
}
if ( class_exists( 'WPGitHubUpdater' ) ) {
return;
}
// Prevent loading this file directly and/or if the class is already defined
if ( ! defined( 'ABSPATH' ) ) {
return;
}
/**
*
*
* @version 1.6
* @author Joachim Kudish <info@jkudish.com>
* @link http://jkudish.com
* @package WP_GitHub_Updater
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @copyright Copyright (c) 2011-2013, Joachim Kudish
*
* GNU General Public License, Free Software Foundation
* <http://creativecommons.org/licenses/GPL/2.0/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
if ( ! class_exists( 'WP_GitHub_Updater' ) ) {
class WP_GitHub_Updater {
/**
* GitHub Updater version
*/
const VERSION = 1.6;
/**
* @var $config the config for the updater
* @access public
*/
var $config;
/**
* @var $missing_config any config that is missing from the initialization of this instance
* @access public
*/
var $missing_config;
/**
* @var $github_data temporiraly store the data fetched from GitHub, allows us to only load the data once per class instance
* @access private
*/
private $github_data;
/**
* Class Constructor
*
* @since 1.0
* @param array $config the configuration required for the updater to work
* @see has_minimum_config()
* @return void
*/
public function __construct( $config = array() ) {
$defaults = array(
'slug' => plugin_basename( __FILE__ ),
'proper_folder_name' => dirname( plugin_basename( __FILE__ ) ),
'sslverify' => true,
'access_token' => '',
);
$this->config = wp_parse_args( $config, $defaults );
// if the minimum config isn't set, issue a warning and bail
if ( ! $this->has_minimum_config() ) {
$message = 'The GitHub Updater was initialized without the minimum required configuration, please check the config in your plugin. The following params are missing: ';
$message .= implode( ',', $this->missing_config );
_doing_it_wrong( __CLASS__, $message , self::VERSION );
return;
}
$this->set_defaults();
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'api_check' ) );
// Hook into the plugin details screen
add_filter( 'plugins_api', array( $this, 'get_plugin_info' ), 10, 3 );
add_filter( 'upgrader_post_install', array( $this, 'upgrader_post_install' ), 10, 3 );
// set timeout
add_filter( 'http_request_timeout', array( $this, 'http_request_timeout' ) );
// set sslverify for zip download
add_filter( 'http_request_args', array( $this, 'http_request_sslverify' ), 10, 2 );
}
public function has_minimum_config() {
$this->missing_config = array();
$required_config_params = array(
'api_url',
'raw_url',
'github_url',
'zip_url',
'requires',
'tested',
'readme',
);
foreach ( $required_config_params as $required_param ) {
if ( empty( $this->config[$required_param] ) )
$this->missing_config[] = $required_param;
}
return ( empty( $this->missing_config ) );
}
/**
* Check wether or not the transients need to be overruled and API needs to be called for every single page load
*
* @return bool overrule or not
*/
public function overrule_transients() {
return ( defined( 'WP_GITHUB_FORCE_UPDATE' ) && WP_GITHUB_FORCE_UPDATE );
}
/**
* Set defaults
*
* @since 1.2
* @return void
*/
public function set_defaults() {
if ( !empty( $this->config['access_token'] ) ) {
// See Downloading a zipball (private repo) https://help.github.com/articles/downloading-files-from-the-command-line
extract( parse_url( $this->config['zip_url'] ) ); // $scheme, $host, $path
$zip_url = $scheme . '://api.github.com/repos' . $path;
$zip_url = add_query_arg( array( 'access_token' => $this->config['access_token'] ), $zip_url );
$this->config['zip_url'] = $zip_url;
}
if ( ! isset( $this->config['new_version'] ) )
$this->config['new_version'] = $this->get_new_version();
if ( ! isset( $this->config['last_updated'] ) )
$this->config['last_updated'] = $this->get_date();
if ( ! isset( $this->config['description'] ) )
$this->config['description'] = $this->get_description();
$plugin_data = $this->get_plugin_data();
if ( ! isset( $this->config['plugin_name'] ) )
$this->config['plugin_name'] = $plugin_data['Name'];
if ( ! isset( $this->config['version'] ) )
$this->config['version'] = $plugin_data['Version'];
if ( ! isset( $this->config['author'] ) )
$this->config['author'] = $plugin_data['Author'];
if ( ! isset( $this->config['homepage'] ) )
$this->config['homepage'] = $plugin_data['PluginURI'];
if ( ! isset( $this->config['readme'] ) )
$this->config['readme'] = 'README.md';
}
/**
* Callback fn for the http_request_timeout filter
*
* @since 1.0
* @return int timeout value
*/
public function http_request_timeout() {
return 2;
}
/**
* Callback fn for the http_request_args filter
*
* @param unknown $args
* @param unknown $url
*
* @return mixed
*/
public function http_request_sslverify( $args, $url ) {
if ( $this->config[ 'zip_url' ] == $url )
$args[ 'sslverify' ] = $this->config[ 'sslverify' ];
return $args;
}
/**
* Get New Version from GitHub
*
* @since 1.0
* @return int $version the version number
*/
public function get_new_version() {
$version = get_site_transient( md5($this->config['slug']).'_new_version' );
if ( $this->overrule_transients() || ( !isset( $version ) || !$version || '' == $version ) ) {
$raw_response = $this->remote_get( trailingslashit( $this->config['raw_url'] ) . basename( $this->config['slug'] ) );
if ( is_wp_error( $raw_response ) )
$version = false;
if (is_array($raw_response)) {
if (!empty($raw_response['body']))
preg_match( '/.*Version\:\s*(.*)$/mi', $raw_response['body'], $matches );
}
if ( empty( $matches[1] ) )
$version = false;
else
$version = $matches[1];
// back compat for older readme version handling
// only done when there is no version found in file name
if ( false === $version ) {
$raw_response = $this->remote_get( trailingslashit( $this->config['raw_url'] ) . $this->config['readme'] );
if ( is_wp_error( $raw_response ) )
return $version;
preg_match( '#^\s*`*~Current Version\:\s*([^~]*)~#im', $raw_response['body'], $__version );
if ( isset( $__version[1] ) ) {
$version_readme = $__version[1];
if ( -1 == version_compare( $version, $version_readme ) )
$version = $version_readme;
}
}
// refresh every 6 hours
if ( false !== $version )
set_site_transient( md5($this->config['slug']).'_new_version', $version, 60*60*6 );
}
return $version;
}
/**
* Interact with GitHub
*
* @param string $query
*
* @since 1.6
* @return mixed
*/
public function remote_get( $query ) {
if ( ! empty( $this->config['access_token'] ) )
$query = add_query_arg( array( 'access_token' => $this->config['access_token'] ), $query );
$raw_response = wp_remote_get( $query, array(
'sslverify' => $this->config['sslverify']
) );
return $raw_response;
}
/**
* Get GitHub Data from the specified repository
*
* @since 1.0
* @return array $github_data the data
*/
public function get_github_data() {
if ( isset( $this->github_data ) && ! empty( $this->github_data ) ) {
$github_data = $this->github_data;
} else {
$github_data = get_site_transient( md5($this->config['slug']).'_github_data' );
if ( $this->overrule_transients() || ( ! isset( $github_data ) || ! $github_data || '' == $github_data ) ) {
$github_data = $this->remote_get( $this->config['api_url'] );
if ( is_wp_error( $github_data ) )
return false;
$github_data = json_decode( $github_data['body'] );
// refresh every 6 hours
set_site_transient( md5($this->config['slug']).'_github_data', $github_data, 60*60*6 );
}
// Store the data in this class instance for future calls
$this->github_data = $github_data;
}
return $github_data;
}
/**
* Get update date
*
* @since 1.0
* @return string $date the date
*/
public function get_date() {
$_date = $this->get_github_data();
return ( !empty( $_date->updated_at ) ) ? date( 'Y-m-d', strtotime( $_date->updated_at ) ) : false;
}
/**
* Get plugin description
*
* @since 1.0
* @return string $description the description
*/
public function get_description() {
$_description = $this->get_github_data();
return ( !empty( $_description->description ) ) ? $_description->description : false;
}
/**
* Get Plugin data
*
* @since 1.0
* @return object $data the data
*/
public function get_plugin_data() {
include_once ABSPATH.'/wp-admin/includes/plugin.php';
$data = get_plugin_data( WP_PLUGIN_DIR.'/'.$this->config['slug'] );
return $data;
}
/**
* Hook into the plugin update check and connect to GitHub
*
* @since 1.0
* @param object $transient the plugin data transient
* @return object $transient updated plugin data transient
*/
public function api_check( $transient ) {
// Check if the transient contains the 'checked' information
// If not, just return its value without hacking it
if ( empty( $transient->checked ) )
return $transient;
// check the version and decide if it's new
$update = version_compare( $this->config['new_version'], $this->config['version'] );
if ( 1 === $update ) {
$response = new stdClass;
$response->new_version = $this->config['new_version'];
$response->slug = $this->config['proper_folder_name'];
$response->url = add_query_arg( array( 'access_token' => $this->config['access_token'] ), $this->config['github_url'] );
$response->package = $this->config['zip_url'];
// If response is false, don't alter the transient
if ( false !== $response )
$transient->response[ $this->config['slug'] ] = $response;
}
return $transient;
}
/**
* Get Plugin info
*
* @since 1.0
* @param bool $false always false
* @param string $action the API function being performed
* @param object $args plugin arguments
* @return object $response the plugin info
*/
public function get_plugin_info( $false, $action, $response ) {
// Check if this call API is for the right plugin
if ( !isset( $response->slug ) || $response->slug != $this->config['slug'] )
return false;
$response->slug = $this->config['slug'];
$response->plugin_name = $this->config['plugin_name'];
$response->version = $this->config['new_version'];
$response->author = $this->config['author'];
$response->homepage = $this->config['homepage'];
$response->requires = $this->config['requires'];
$response->tested = $this->config['tested'];
$response->downloaded = 0;
$response->last_updated = $this->config['last_updated'];
$response->sections = array( 'description' => $this->config['description'] );
$response->download_link = $this->config['zip_url'];
return $response;
}
/**
* Upgrader/Updater
* Move & activate the plugin, echo the update message
*
* @since 1.0
* @param boolean $true always true
* @param mixed $hook_extra not used
* @param array $result the result of the move
* @return array $result the result of the move
*/
public function upgrader_post_install( $true, $hook_extra, $result ) {
global $wp_filesystem;
// Move & Activate
$proper_destination = WP_PLUGIN_DIR.'/'.$this->config['proper_folder_name'];
$wp_filesystem->move( $result['destination'], $proper_destination );
$result['destination'] = $proper_destination;
$activate = activate_plugin( WP_PLUGIN_DIR.'/'.$this->config['slug'] );
// Output the update message
$fail = __( 'The plugin has been updated, but could not be reactivated. Please reactivate it manually.', 'github_plugin_updater' );
$success = __( 'Plugin reactivated successfully.', 'github_plugin_updater' );
echo is_wp_error( $activate ) ? $fail : $success;
return $result;
}
}
}