-
Notifications
You must be signed in to change notification settings - Fork 0
Directly Remove Credentials on 401 #119
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7f52e34
Directly Remove Credentials on 401
n7studios 1307cea
Added tests
n7studios 2212ee2
Remove resource tests
n7studios 2d48034
Tests: Add Resource Tests
n7studios 144a3e3
Add `access_token` method
n7studios df38eb9
Merge branch 'delete-tokens-401' into add-resource-tests
n7studios 3c0e334
Added test
n7studios 1ccef1c
Merge branch 'delete-tokens-401' into add-resource-tests
n7studios 08f0a1b
Merge pull request #118 from Kit/add-resource-tests
n7studios File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
223 changes: 223 additions & 0 deletions
223
includes/class-integrate-convertkit-wpforms-admin-notices.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,223 @@ | ||
| <?php | ||
| /** | ||
| * ConvertKit WPForms Admin Notices class. | ||
| * | ||
| * @package ConvertKit_WPForms | ||
| * @author ConvertKit | ||
| */ | ||
|
|
||
| /** | ||
| * Add and remove persistent error messages across all | ||
| * WordPress Administration screens. | ||
| * | ||
| * @package ConvertKit_WPForms | ||
| * @author ConvertKit | ||
| */ | ||
| class Integrate_ConvertKit_WPForms_Admin_Notices { | ||
|
|
||
| /** | ||
| * Holds the class object. | ||
| * | ||
| * @since 1.8.9 | ||
| * | ||
| * @var object | ||
| */ | ||
| private static $instance; | ||
|
|
||
| /** | ||
| * The key prefix to use for stored notices | ||
| * | ||
| * @since 1.8.9 | ||
| * | ||
| * @var string | ||
| */ | ||
| private $key_prefix = 'integrate-convertkit-wpforms-admin-notices'; | ||
|
|
||
| /** | ||
| * Register output function to display persistent notices | ||
| * in the WordPress Administration, if any exist. | ||
| * | ||
| * @since 1.8.9 | ||
| */ | ||
| public function __construct() { | ||
|
|
||
| add_action( 'admin_notices', array( $this, 'output' ) ); | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Output persistent notices in the WordPress Administration | ||
| * | ||
| * @since 1.8.9 | ||
| */ | ||
| public function output() { | ||
|
|
||
| // Don't output if we don't have the required capabilities to fix the issue. | ||
| if ( ! current_user_can( 'manage_options' ) ) { | ||
| return; | ||
| } | ||
|
|
||
| // Bail if no notices exist. | ||
| $notices = get_option( $this->key_prefix ); | ||
| if ( ! $notices ) { | ||
| return; | ||
| } | ||
|
|
||
| // Output notices. | ||
| foreach ( $notices as $notice ) { | ||
| switch ( $notice ) { | ||
| case 'authorization_failed': | ||
| $output = sprintf( | ||
| '%s %s', | ||
| esc_html__( 'Kit for WPForms: Authorization failed. Please', 'integrate-convertkit-wpforms' ), | ||
| sprintf( | ||
| '<a href="%s">%s</a>', | ||
| esc_url( admin_url( 'admin.php?page=wpforms-settings&view=integrations' ) ), | ||
| esc_html__( 'reconnect your Kit account.', 'integrate-convertkit-wpforms' ) | ||
| ) | ||
| ); | ||
| break; | ||
|
|
||
| default: | ||
| $output = ''; | ||
|
|
||
| /** | ||
| * Define the text to output in an admin error notice. | ||
| * | ||
| * @since 1.8.9 | ||
| * | ||
| * @param string $notice Admin notice name. | ||
| */ | ||
| $output = apply_filters( 'integrate_convertkit_wpforms_admin_notices_output_' . $notice, $output ); | ||
| break; | ||
| } | ||
|
|
||
| // If no output defined, skip. | ||
| if ( empty( $output ) ) { | ||
| continue; | ||
| } | ||
| ?> | ||
| <div class="notice notice-error"> | ||
| <p> | ||
| <?php | ||
| echo wp_kses( | ||
| $output, | ||
| wp_kses_allowed_html( 'post' ) | ||
| ); | ||
| ?> | ||
| </p> | ||
| </div> | ||
| <?php | ||
| } | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Add a persistent notice for output in the WordPress Administration. | ||
| * | ||
| * @since 1.8.9 | ||
| * | ||
| * @param string $notice Notice name. | ||
| * @return bool Notice saved successfully | ||
| */ | ||
| public function add( $notice ) { | ||
|
|
||
| // If no other persistent notices exist, add one now. | ||
| if ( ! $this->exist() ) { | ||
| return update_option( $this->key_prefix, array( $notice ) ); | ||
| } | ||
|
|
||
| // Fetch existing persistent notices. | ||
| $notices = $this->get(); | ||
|
|
||
| // Add notice to existing notices. | ||
| $notices[] = $notice; | ||
|
|
||
| // Remove any duplicate notices. | ||
| $notices = array_values( array_unique( $notices ) ); | ||
|
|
||
| // Update and return. | ||
| return update_option( $this->key_prefix, $notices ); | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Returns all notices stored in the options table. | ||
| * | ||
| * @since 1.8.9 | ||
| * | ||
| * @return array | ||
| */ | ||
| public function get() { | ||
|
|
||
| // Fetch all notices from the options table. | ||
| return get_option( $this->key_prefix ); | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Whether any persistent notices are stored in the option table. | ||
| * | ||
| * @since 1.8.9 | ||
| * | ||
| * @return bool | ||
| */ | ||
| public function exist() { | ||
|
|
||
| if ( ! $this->get() ) { | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Delete all persistent notices. | ||
| * | ||
| * @since 1.8.9 | ||
| * | ||
| * @param string $notice Notice name. | ||
| * @return bool Success | ||
| */ | ||
| public function delete( $notice ) { | ||
|
|
||
| // If no persistent notices exist, there's nothing to delete. | ||
| if ( ! $this->exist() ) { | ||
| return false; | ||
| } | ||
|
|
||
| // Fetch existing persistent notices. | ||
| $notices = $this->get(); | ||
|
|
||
| // Remove notice from existing notices. | ||
| $index = array_search( $notice, $notices, true ); | ||
| if ( $index !== false ) { | ||
| unset( $notices[ $index ] ); | ||
| } | ||
|
|
||
| // Update and return. | ||
| return update_option( $this->key_prefix, $notices ); | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Returns the singleton instance of the class. | ||
| * | ||
| * @since 1.8.9 | ||
| * | ||
| * @return object Class. | ||
| */ | ||
| public static function get_instance() { | ||
|
|
||
| if ( null === self::$instance ) { | ||
| self::$instance = new self(); | ||
| } | ||
|
|
||
| return self::$instance; | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| new Integrate_ConvertKit_WPForms_Admin_Notices(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line appears unnecessary.