Created
December 18, 2014 22:45
-
-
Save dtateii/f5ada2cd828794197096 to your computer and use it in GitHub Desktop.
Wordpress Widget_Context URL negation patch
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
diff --git a/wp-content/plugins/widget-context/widget-context.php b/wp-content/plugins/widget-context/widget-context.php | |
index 477574a..dd88576 100755 | |
--- a/wp-content/plugins/widget-context/widget-context.php | |
+++ b/wp-content/plugins/widget-context/widget-context.php | |
@@ -415,15 +415,47 @@ class widget_context { | |
function context_check_url( $check, $settings ) { | |
+ global $wp; | |
+ $current_path = trim( $wp->request ); | |
+ | |
$settings = wp_parse_args( | |
$settings, | |
array( | |
- 'urls' => null | |
+ 'urls' => null, | |
) | |
); | |
$urls = trim( $settings['urls'] ); | |
+ /** | |
+ * Targeted URLs, including URLs negated with "!". | |
+ */ | |
+ $urls_all = explode( "\n", $urls ); | |
+ | |
+ /** | |
+ * Holds urls negated with not (!). | |
+ */ | |
+ $urls_excluded = array(); | |
+ | |
+ /** | |
+ * Remove leading "!"" before adding to excluded URL list. | |
+ */ | |
+ $charmask = " \t\n\r\0\x0B!"; | |
+ foreach ( $urls_all as $url ) { | |
+ if ( 0 === strpos( $url, '!' ) ) { | |
+ $urls_excluded[] = trim( $url, $charmask ); | |
+ } | |
+ } | |
+ | |
+ /** | |
+ * Deny widget if current path matches an excluded URL. | |
+ */ | |
+ foreach ( $urls_excluded as $not_url ) { | |
+ if ( $current_path === $not_url ) { | |
+ return $check; | |
+ } | |
+ } | |
+ | |
if ( empty( $urls ) ) | |
return $check; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This patch is for version 1.0.3. https://wordpress.org/support/plugin/widget-context