Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for env, add link for backend #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# bea-redirection

A very simple WordPress theme for make a redirection to an another URL. Useful for WordPress multisite, when the first site is not used !
22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "bea/bea-redirection",
"desciption": "A very simple WordPress theme for make a redirection to an another URL. Useful for WordPress multisite, when the first site is not used !",
"type": "wordpress-theme",
"homepage": "https://github.com/BeAPI/bea-redirection",
"authors": [
{
"name": "BeAPI",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.4"
}
"authors": [
{
"name": "BeAPI",
"email": "[email protected]"
}
],
"homepage": "https://github.com/BeAPI/bea-redirection",
"require": {
"php": ">=7.0"
},
"desciption": "A very simple WordPress theme for make a redirection to an another URL. Useful for WordPress multisite, when the first site is not used !"
}
20 changes: 20 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 20 additions & 17 deletions functions.php
herewithme marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,44 +1,47 @@
<?php
add_action('admin_menu', 'add_page_template' );
add_action( 'admin_menu', 'add_page_template' );

function add_page_template() {
add_theme_page('Redirection settings', __('Redirection settings', 'redirection'), 'manage_options', 'redirection-theme-settings', 'redirection_theme_page' );
add_theme_page( 'Redirection settings', __( 'Redirection settings', 'bea-redirection' ), 'manage_options', 'redirection-theme-settings', 'redirection_theme_page' );
}

function redirection_theme_page() {
$text = '';
if ( isset($_POST['update_theme_options']) ) {
if (
! isset( $_POST['update_theme_options_field'] )
|| ! wp_verify_nonce( $_POST['update_theme_options_field'], 'update_theme_options' )
if ( isset( $_POST['update_theme_options'] ) ) {
if (
! isset( $_POST['update_theme_options_field'] )
|| ! wp_verify_nonce( $_POST['update_theme_options_field'], 'update_theme_options' )
) {
wp_die('Sorry, your nonce did not verify.');
wp_die( __( 'Sorry, your nonce did not verify.', 'bea-redirection' ) );
}

$_POST['redirection_url'] = stripslashes($_POST['redirection_url']);
update_option('redirection_url', sanitize_text_field( $_POST['redirection_url'] ) );
update_option( 'redirection_url', esc_url_raw( stripslashes( $_POST['redirection_url'] ) ) );

$text = '<div id="setting-error-settings_updated" class="updated settings-error notice is-dismissible"><p><strong>Settings saved.</strong></p></div>';
$text = '<div id="setting-error-settings_updated" class="updated settings-error notice is-dismissible"><p><strong>';
$text .= esc_html__( 'Settings saved.', 'bea-redirection' );
$text .= '</strong></p></div>';
}

$redirection = get_option('redirection_url');
$redirection = get_option( 'redirection_url' );
?>
<div class="wrap">
<h2><?php _e('Redirection settings', 'redirection'); ?></h2>
<h2><?php esc_html_e( 'Redirection settings', 'bea-redirection' ); ?></h2>
<?php echo $text; ?>
<form action="" method="POST">
<form action="" method="POST">
<table class="form-table">
<tr>
<th scope="row"><?php _e('Redirection URL', 'redirection'); ?></th>
<th scope="row"><?php esc_html_e( 'Redirection URL', 'bea-redirection' ); ?></th>
<td>
<input type="text" name="redirection_url" value="<?php echo esc_attr($redirection);?>" class="widefat" />
<input type="text" name="redirection_url" value="<?php echo esc_attr( $redirection ); ?>"
class="widefat"/>
</td>
</tr>
</tr>
</table>

<?php wp_nonce_field( 'update_theme_options', 'update_theme_options_field' ); ?>
<p class="submit">
<input class="button-primary" type="submit" name="update_theme_options" value="<?php _e('Update settings', 'redirection'); ?>" /></p>
<input class="button-primary" type="submit" name="update_theme_options"
value="<?php esc_attr_e( 'Update settings', 'bea-redirection' ); ?>"/></p>
</form>
</div>
<?php
Expand Down
14 changes: 10 additions & 4 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@
*/

$redirect = get_option( 'redirection_url' );

// Exec redirection only on production, otherwise only display a user message
if ( defined( 'WP_ENV' ) && ! in_array( constant( 'WP_ENV' ), array( 'production', 'PROD' ) ) ) {
wp_die( sprintf( __( 'This theme make a 301 redirection on production to this URL: %s', 'bea-redirection' ), $redirect ) );
}

if ( ! empty( $redirect ) ) {
/** Hack : striclty redirect to wanted url */
wp_redirect( $redirect, 301, 'bea-redirection' );
/** Hack : strictly redirect to wanted url */
wp_redirect( esc_url_raw( $redirect ), 301, 'bea-redirection' );
exit;
}
}

wp_die( 'Configure theme redirection on BO please' );
wp_die( sprintf( __( 'Please configure theme redirection on <a href="%s">back-end settings page</a>', 'bea-redirection' ), admin_url( 'themes.php?page=redirection-theme-settings' ) ) );
8 changes: 4 additions & 4 deletions style.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
Theme Name: Redirection
Theme URI: http://www.beapi.fr/
Description: Thème "Redirection"
Theme URI: https://github.com/BeAPI/bea-redirection
Description: this theme allows to redirect in front-office to a URL configured in the back-office
Version: 1.0.1
Author: The BeAPI Team
Author URI: http://beapi.fr/
Author: Be API
Author URI: https://beapi.fr
*/