pods_query_arg

Create a new URL off of the current one, with updated parameters.

Description

pods_query_arg( (constant) $array = null, (constant) $allowed = null, (constant) $excluded = null, (null) $url = null ); 

Parameters (4)

0. $array — Optional. (constant) => null
Parameters to be set (empty will remove it)
1. $allowed — Optional. (constant) => null
Parameters to keep (if empty, all are kept)
2. $excluded — Optional. (constant) => null
Parameters to always remove
3. $url — Optional. (null) => null
URL to base update off of

Usage

  1. if ( !function_exists( 'pods_query_arg' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'pods-custom-content-types-and-fields/includes/data.php'; 
  3.  
  4. // Parameters to be set (empty will remove it) 
  5. $array = null; 
  6.  
  7. // Parameters to keep (if empty, all are kept) 
  8. $allowed = null; 
  9.  
  10. // Parameters to always remove 
  11. $excluded = null; 
  12.  
  13. // URL to base update off of 
  14. $url = null; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = pods_query_arg($array, $allowed, $excluded, $url); 
  18.  

Defined (1)

The function is defined in the following location(s).

/includes/data.php  
  1. function pods_query_arg( $array = null, $allowed = null, $excluded = null, $url = null ) { 
  2.  
  3. $array = (array) $array; 
  4. $allowed = (array) $allowed; 
  5. $excluded = (array) $excluded; 
  6.  
  7. if ( !isset( $_GET ) ) { 
  8. $query_args = array(); 
  9. else { 
  10. $query_args = pods_unsanitize( $_GET ); 
  11.  
  12. foreach ( $query_args as $key => $val ) { 
  13. if ( is_array( $val ) && empty( $val ) ) { 
  14. $query_args[ $key ] = false; 
  15. elseif ( !is_array( $val ) && strlen( $val ) < 1 ) { 
  16. $query_args[ $key ] = false; 
  17. elseif ( !empty( $allowed ) ) { 
  18. $allow_it = false; 
  19.  
  20. foreach ( $allowed as $allow ) { 
  21. if ( $allow == $key ) { 
  22. $allow_it = true; 
  23. elseif ( false !== strpos( $allow, '*' ) && 0 === strpos( $key, trim( $allow, '*' ) ) ) { 
  24. $allow_it = true; 
  25.  
  26. if ( !$allow_it ) { 
  27. $query_args[ $key ] = false; 
  28.  
  29. if ( !empty( $excluded ) ) { 
  30. foreach ( $excluded as $exclusion ) { 
  31. if ( isset( $query_args[ $exclusion ] ) && !in_array( $exclusion, $allowed ) ) { 
  32. $query_args[ $exclusion ] = false; 
  33.  
  34. if ( !empty( $array ) ) { 
  35. foreach ( $array as $key => $val ) { 
  36. if ( null !== $val || false === strpos( $key, '*' ) ) { 
  37. if ( is_array( $val ) && !empty( $val ) ) { 
  38. $query_args[ $key ] = $val; 
  39. elseif ( !is_array( $val ) && 0 < strlen( $val ) ) { 
  40. $query_args[ $key ] = $val; 
  41. elseif ( isset( $query_args[ $key ] ) ) { 
  42. $query_args[ $key ] = false; 
  43. else { 
  44. $key = str_replace( '*', '', $key ); 
  45.  
  46. foreach ( $query_args as $k => $v ) { 
  47. if ( false !== strpos( $k, $key ) ) { 
  48. $query_args[ $k ] = false; 
  49.  
  50. if ( null === $url ) { 
  51. $url = add_query_arg( $query_args ); 
  52. else { 
  53. $url = add_query_arg( $query_args, $url ); 
  54.  
  55. return $url; 
  56.