pods_v_set

Set a variable.

Description

pods_v_set( (mixed) $value, (mixed) $var, (string) $type = 'get' ); 

Parameters (3)

0. $value (mixed)
The value to be set
1. $var (mixed)
The variable name, or URI segment position / query var name (if $type is url)
2. $type — Optional. (string) => 'get'
Super globals, url/url-relative, constants, globals, user data, Pod field values

Usage

  1. if ( !function_exists( 'pods_v_set' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'pods-custom-content-types-and-fields/includes/data.php'; 
  3.  
  4. // The value to be set 
  5. $value = null; 
  6.  
  7. // The variable name, or URI segment position / query var name (if $type is 'url') 
  8. $var = null; 
  9.  
  10. // (optional) Super globals, url/url-relative, constants, globals, user data, Pod field values 
  11. $type = 'get'; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = pods_v_set($value, $var, $type); 
  15.  

Defined (1)

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

/includes/data.php  
  1. function pods_v_set( $value, $var, $type = 'get' ) { 
  2.  
  3. $ret = false; 
  4.  
  5. if ( null === $var || '' === $var ) { 
  6. // Invalid $var 
  7. elseif ( null === $type || '' === $type ) { 
  8. // Invalid $type 
  9. elseif ( is_array( $type ) ) { 
  10. $type[ $var ] = $value; 
  11.  
  12. $ret = $type; 
  13. elseif ( is_object( $type ) ) { 
  14. $type->{$var} = $value; 
  15.  
  16. $ret = $type; 
  17. else { 
  18. $type = strtolower( $type ); 
  19.  
  20. if ( 'get' == $type ) { 
  21. $_GET[ $var ] = $value; 
  22.  
  23. $ret = $_GET; 
  24. elseif ( 'post' == $type ) { 
  25. $_POST[ $var ] = $value; 
  26.  
  27. $ret = $_POST; 
  28. elseif ( 'request' == $type ) { 
  29. $_REQUEST[ $var ] = $value; 
  30.  
  31. $ret = $_REQUEST; 
  32. elseif ( 'url' == $type ) { 
  33. if ( is_numeric( $var ) && function_exists( 'http_build_url' ) ) { 
  34. $url = parse_url( pods_current_url() ); 
  35. $uri = trim( $url[ 'path' ], '/' ); 
  36. $uri = array_filter( explode( '/', $uri ) ); 
  37.  
  38. if ( 'first' == $var ) { 
  39. $var = 0; 
  40. elseif ( 'last' == $var ) { 
  41. $var = -1; 
  42.  
  43. if ( $var < 0 ) { 
  44. $uri[ count( $uri ) + $var ] = $value; 
  45. else { 
  46. $uri[ $var ] = $value; 
  47.  
  48. $url[ 'path' ] = '/' . implode( '/', $uri ) . '/'; 
  49. $url[ 'path' ] = trim( $url[ 'path' ], '/' ); 
  50.  
  51. $ret = http_build_url( $url ); 
  52. else { 
  53. $ret = add_query_arg( array( $var => $value ) ); 
  54. elseif ( 'server' == $type ) { 
  55. $_SERVER[ $var ] = $value; 
  56.  
  57. $ret = $_SERVER; 
  58. elseif ( in_array( $type, array( 'global', 'globals' ) ) ) { 
  59. $GLOBALS[ $var ] = $value; 
  60.  
  61. $ret = $GLOBALS; 
  62. elseif ( 'session' == $type ) { 
  63. // Session start 
  64.  
  65. $_SESSION[ $var ] = $value; 
  66.  
  67. $ret = $_SESSION; 
  68. elseif ( 'cookie' == $type && !headers_sent() ) { 
  69. setcookie( $var, $value, time() + 10 * DAY_IN_SECONDS, COOKIEPATH ); 
  70.  
  71. $ret = $_COOKIE; 
  72. elseif ( 'constant' == $type && !defined( $var ) && ( is_scalar( $value ) || null === $value ) ) { 
  73. define( $var, $value ); 
  74.  
  75. $ret = constant( $var ); 
  76. elseif ( 'user' == $type && is_user_logged_in() ) { 
  77. $user = get_userdata( get_current_user_id() ); 
  78.  
  79. if ( !pods_version_check( wp, '3.5' ) ) { 
  80. $user_data = get_object_vars( $user->data ); 
  81. else { 
  82. $user_data = $user->to_array(); 
  83.  
  84. // Role 
  85. if ( 'role' == $var ) { 
  86. $user->set_role( $value ); 
  87. // Core field 
  88. elseif ( isset( $user_data[ $var ] ) ) { 
  89. wp_update_user( array( 'ID' => $user->ID, $var => $value ) ); 
  90. // Meta field 
  91. else { 
  92. update_user_meta( $user->ID, $var, $value ); 
  93.  
  94. $ret = get_userdata( $user->ID ); 
  95. elseif ( pods == $type ) { 
  96. /** 
  97. * @var $pods Pods 
  98. */ 
  99. global $pods; 
  100.  
  101. if ( is_object( $pods ) && 'Pods' == get_class( $pods ) && $pods->exists() ) { 
  102. $ret = $pods->save( $var, $value ); 
  103. else { 
  104. $ret = apply_filters( 'pods_var_set_' . $type, $value, $var ); 
  105.  
  106. return $ret; 
  107.