From 6bf18bc28d60e3ebaf1d8d613ef6c4004fe143d9 Mon Sep 17 00:00:00 2001 From: Norcross Date: Mon, 18 Nov 2024 12:15:32 -0500 Subject: [PATCH 1/3] initial rebuild this is the initial rebuild. it needed it. --- CHANGELOG.md | 10 ++ LICENSE | 2 +- README.md | 19 +++- extra-authors-redirect.php | 219 ++++++++----------------------------- includes/helpers.php | 117 ++++++++++++++++++++ includes/process.php | 124 +++++++++++++++++++++ includes/settings-api.php | 74 +++++++++++++ includes/user-settings.php | 92 ++++++++++++++++ languages/default.mo | Bin 436 -> 0 bytes languages/default.po | 22 ---- readme.txt | 64 ----------- 11 files changed, 478 insertions(+), 265 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 includes/helpers.php create mode 100644 includes/process.php create mode 100644 includes/settings-api.php create mode 100644 includes/user-settings.php delete mode 100644 languages/default.mo delete mode 100644 languages/default.po delete mode 100644 readme.txt diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..1fe881d --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,10 @@ + +#### Version 2.0.0 - 2024/11/18 +* total rewrite because the previous version was ugly + +#### Version 1.2.0 - 2019/03/19 +* adding bbPress support + +#### Version 1.1 / Version 1.0 - the before times +* the history is ugly so who cares + diff --git a/LICENSE b/LICENSE index 57b0fef..746c2de 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 Andrew Norcross +Copyright (c) 2019 Andrew Norcross Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 69ef254..a6fef68 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,19 @@ -# Extra Authors Redirect -Adds a checkbox to author profiles for redirecting to other parts of the site. +Extra Authors Redirect +======================== +## Contributors +* [Andrew Norcross](https://github.com/norcross) + +## About + +Adds a checkbox to redirect author profiles. Useful for sites that have occasional authors or user accounts not intended for display. + +### Features + +* a checkbox on each author profile +* filterable redirect location +* includes bbPress support ### To Do -* this readme file, clearly. + +* add a global settings diff --git a/extra-authors-redirect.php b/extra-authors-redirect.php index 1826766..46719d7 100644 --- a/extra-authors-redirect.php +++ b/extra-authors-redirect.php @@ -1,175 +1,44 @@ -ID, 'author_redirect', true ); - ?> - - - - - -
- -
- 'string', + 'show_in_rest' => false, + 'default' => 'no', + 'sanitize_callback' => __NAMESPACE__ . '\sanitize_global_setting', + ]; + + // Add out checkbox with a sanitiation callback. + register_setting( 'reading', Core\OPTION_KEY, $setup_args ); + + // Load the actual checkbox field itself. + add_settings_field( 'exar-global-enable', __( 'Redirect All Authors', 'extra-authors-redirect' ), __NAMESPACE__ . '\display_field', 'reading', 'default', [ 'class' => 'exar-global-enable-wrapper' ] ); +} + +/** + * Display a basic checkbox for our setting. + * + * @return HTML + */ +function display_field( $args ) { + + // Add a legend output for screen readers. + echo '' . esc_html__( 'Redirect All Authors', 'extra-authors-redirect' ) . ''; + + // We are wrapping the entire thing in a label. + echo ''; +} + +/** + * Make sure the setting is valid. + * + * @param string $input The data entered in a settings field. + * + * @return string $input Our cleaned up data. + */ +function sanitize_global_setting( $input ) { + return ! empty( $input ) && 'yes' === sanitize_text_field( $input ) ? 'yes' : 'no'; +} diff --git a/includes/user-settings.php b/includes/user-settings.php new file mode 100644 index 0000000..8c7c86b --- /dev/null +++ b/includes/user-settings.php @@ -0,0 +1,92 @@ +ID ) ) { + return; + } + + // Check the user meta. + $maybe_enabled = Helpers\check_user_enable( $profileuser->ID ); + + // Now display the field. + echo ''; + + // Show our label side. + echo '' . esc_html__( 'Redirect Author Template', 'extra-authors-redirect' ) . ''; + + // Show the checkbox portion. + echo ''; + + // Handle the markup like core does. + echo ''; + + // And add a nonce field. + wp_nonce_field( 'exar_user_action', 'exar-user-meta-save', false ); + + // Close the checkbox portion. + echo ''; + + // Close out field. + echo ''; +} + +/** + * Update the meta and the overall array. + * + * @param integer $user_id User ID. + * @param WP_User $old_user_data Object containing user's data prior to update. + * @param array $userdata The array of raw data that was passed. + * + * @return void + */ +function save_user_meta_setting( $user_id, $old_user_data, $userdata ) { + + // Make sure we have a nonce. + $confirm_nonce = filter_input( INPUT_POST, 'exar-user-meta-save', FILTER_SANITIZE_SPECIAL_CHARS ); // phpcs:ignore -- the nonce check is happening after this. + + // Handle the nonce check. + if ( ! empty( $confirm_nonce ) && ! wp_verify_nonce( $confirm_nonce, 'exar_user_action' ) ) { + + // Let them know they had a failure. + wp_die( esc_html__( 'There was an error validating the nonce.', 'extra-authors-redirect' ), esc_html__( 'Extra Authors Redirect User Meta', 'extra-authors-redirect' ), [ 'back_link' => true ] ); + } + + // Check if the user meta key was provided. + $check_usermeta = filter_input( INPUT_POST, 'exar_enable_user', FILTER_SANITIZE_SPECIAL_CHARS ); + + // Either update or delete the meta. + if ( ! empty( $check_usermeta ) && 'yes' === $check_usermeta ) { + update_user_meta( $user_id, Core\UMETA_KEY, 'yes' ); + } else { + delete_user_meta( $user_id, Core\UMETA_KEY ); + } +} diff --git a/languages/default.mo b/languages/default.mo deleted file mode 100644 index 61aebd358a5426c5aaa4b300cb492b7b0a1d93fd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 436 zcmaJ*!A=4(5XIM+E{8uo|1x^NQ9sB29i!#}L%Ts6=#H0M*)rXz|8 zI#1#FA-{yQ&Q(ob$U)B(w$x^\n" -"Language-Team: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"X-Generator: Poedit 1.5.5\n" -"X-Poedit-KeywordsList: _;__;_e\n" -"X-Poedit-Basepath: ../\n" -"X-Poedit-SearchPath-0: .\n" - -#: extra-authors-redirect.php:102 -msgid "Author Redirect" -msgstr "" - -#: extra-authors-redirect.php:105 -msgid "Redirect this author template page to the home page" -msgstr "" diff --git a/readme.txt b/readme.txt deleted file mode 100644 index 30f3f35..0000000 --- a/readme.txt +++ /dev/null @@ -1,64 +0,0 @@ -=== Extra Authors Redirect === -Contributors: norcross -Website Link: http://andrewnorcross.com/plugins/ -Donate link: http://andrewnorcross.com/donate -Tags: author-page, authors, redirects -Requires at least: 3.3 -Tested up to: 3.9 -Stable tag: 1.2 -License: MIT -License URI: http://www.gnu.org/licenses/gpl-2.0.html - -Adds a checkbox to author profiles for redirecting to other parts of the site. - -== Description == - -Adds a checkbox to author profiles to redirect. Useful for sites that have occasional authors or user accounts not intended for display. - -== Installation == - -This section describes how to install the plugin and get it working. - -1. Upload `extra-authors-redirect` to the `/wp-content/plugins/` directory. -2. Activate the plugin through the 'Plugins' menu in WordPress. -3. Check the author(s) you want redirected. - -== Frequently Asked Questions == - - -= Does this affect posts / pages / admin / ??? = - -No. this only affects people going to the /author/ template page on a site, and only affects those that have been marked to redirect. - -= Can I change where the redirect goes? = - -Yes. There is a filter to change the default behavior. In your functions file, include the following: - -`function new_auth_url($location) { - $location = 'http://google.com'; - return $location; -} -add_filter( 'extra_author_redirect_url', 'new_auth_url' );` - -== Screenshots == - -1. The checkbox - - -== Changelog == - -= 1.2 = -* Will also redirect for bbPress profile pages - -= 1.1 = -* Cleaner meta check for adding author meta entry - -= 1.0 = -* First release! - - -== Upgrade Notice == - - -= 1.0 = -* First release! From 9665112cd9ce928bc7b244e1e4e2f419afb98c15 Mon Sep 17 00:00:00 2001 From: Norcross Date: Mon, 18 Nov 2024 12:22:22 -0500 Subject: [PATCH 2/3] nicer readme a nicer readme --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a6fef68..6d06c34 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,44 @@ Adds a checkbox to redirect author profiles. Useful for sites that have occasion * filterable redirect location * includes bbPress support -### To Do +### Frequenty Asked Questions -* add a global settings +##### Does this affect posts / pages / admin / ??? + +No. this only affects people going to the /author/ template page on a site, and only affects those that have been marked to redirect or if the global settings is enabled. + +##### Can I change where the redirect goes? + +Yes. There is a filter to change the default behavior. Example: + +~~~php +/** + * Change the URL that a redirected author profile goes to. + * + * @param string $location The current URL set. + * + * @return string The new updated one. + */ +function set_custom_redirect_url( $location ) { + return 'https://www.google.com'; +} +add_filter( 'exar_redirect_url', 'set_custom_redirect_url' ); +~~~ + +##### Can the redirect be something other than a 301? + +Sure can. Change it to whatever you want. Example: + +~~~php +/** + * Change the HTTP response code. + * + * @param integer $response_code The current HTTP response. + * + * @return integer The new updated one. + */ +function set_custom_http_response( $response_code ) { + return 302; +} +add_filter( 'exar_redirect_http_code', 'set_custom_http_response' ); +~~~ From 40b2c62f4ed2cb9cc68f19f1ba7ecd9cc0b388c6 Mon Sep 17 00:00:00 2001 From: Norcross Date: Mon, 18 Nov 2024 12:23:29 -0500 Subject: [PATCH 3/3] more MOAR --- README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6d06c34..9591d9f 100644 --- a/README.md +++ b/README.md @@ -8,19 +8,18 @@ Extra Authors Redirect Adds a checkbox to redirect author profiles. Useful for sites that have occasional authors or user accounts not intended for display. -### Features +## Features * a checkbox on each author profile +* a global setting for site-wide redirect * filterable redirect location * includes bbPress support -### Frequenty Asked Questions - -##### Does this affect posts / pages / admin / ??? +#### Does this affect posts / pages / admin / ??? No. this only affects people going to the /author/ template page on a site, and only affects those that have been marked to redirect or if the global settings is enabled. -##### Can I change where the redirect goes? +#### Can I change where the redirect goes? Yes. There is a filter to change the default behavior. Example: @@ -38,7 +37,7 @@ function set_custom_redirect_url( $location ) { add_filter( 'exar_redirect_url', 'set_custom_redirect_url' ); ~~~ -##### Can the redirect be something other than a 301? +#### Can the redirect be something other than a 301? Sure can. Change it to whatever you want. Example: