Skip to content

Instantly share code, notes, and snippets.

@dtateii
Created December 18, 2014 22:45
Show Gist options
  • Save dtateii/f5ada2cd828794197096 to your computer and use it in GitHub Desktop.
Save dtateii/f5ada2cd828794197096 to your computer and use it in GitHub Desktop.
Wordpress Widget_Context URL negation patch
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;
@dtateii
Copy link
Author

dtateii commented Dec 18, 2014

This patch is for version 1.0.3. https://wordpress.org/support/plugin/widget-context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment