Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Added Link Guessing checkbox to Dashboard->Settings
  • Loading branch information
jjc16105 committed May 13, 2016
1 parent 3dc6260 commit 1795b41
Showing 1 changed file with 74 additions and 1 deletion.
75 changes: 74 additions & 1 deletion functions.php
Expand Up @@ -264,4 +264,77 @@ function uc_redirect_403() {

add_action( 'template_redirect', 'uc_redirect_403' );

?>

//====================================================
// WordPress Link Guessing Option adds a checkbox
// to the Settings page
//====================================================

add_action( 'admin_init', 'link_guessing_settings_init' );

//====================================================
// Link Guessing - ON or OFF ?
//====================================================

add_action( 'wp_loaded', function ()
{
$checked = get_option( 'link_guessing' );
if ( empty( $checked ) ){
remove_filter('template_redirect', 'redirect_canonical');
}else{
add_filter('template_redirect', 'redirect_canonical');
}
});

//====================================================
// Link Guessing init
//====================================================

function link_guessing_settings_init(){

/* Register Settings */
register_setting(
'general', // Options group
'link_guessing', // Option name/database
'link_guessing_sanitize' // sanitize callback function
);

/* Create settings section */
add_settings_section(
'link_guessing_section_id', // Section ID
'', // Section title - leave it blank
null, // Section description callback function - we don't need it
'general' // Settings page slug
);

/* Create settings field */
add_settings_field(
'link_guessing_field_id', // Field ID
'Link Guessing', // Field title
'link_guessing_field_callback', // Field callback function
'general', // Settings page slug
'link_guessing_section_id' // Section ID
);
}

//====================================================
/* Sanitize Callback Function */
//====================================================

function link_guessing_sanitize( $input ){
return isset( $input ) ? true : false;
}

//====================================================
/* Settings Field Callback */
//====================================================

function link_guessing_field_callback(){
?>
<label for="link_guessing">
<?php
$checked = get_option( 'link_guessing' );
?>
<input id="link_guessing" type="checkbox" name="link_guessing" <?php checked($checked) ?>> Check to enable Wordpress link guessing
</label>
<?php } ?>

0 comments on commit 1795b41

Please sign in to comment.