From 1795b419d1516191faa9e3ef0023c664a3e2f5bc Mon Sep 17 00:00:00 2001 From: John Calande Date: Fri, 13 May 2016 08:59:48 -0400 Subject: [PATCH] Added Link Guessing checkbox to Dashboard->Settings --- functions.php | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/functions.php b/functions.php index f56392c..d69c2d9 100644 --- a/functions.php +++ b/functions.php @@ -264,4 +264,77 @@ function uc_redirect_403() { add_action( 'template_redirect', 'uc_redirect_403' ); -?> \ No newline at end of file + +//==================================================== +// 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(){ + ?> + + \ No newline at end of file