init.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * Basic wrappers around WP core functions
  4. *
  5. * This file is loaded early by the theme
  6. *
  7. * @package vamtam/consulting
  8. */
  9. /**
  10. * get_option wrapper
  11. *
  12. * @uses get_option()
  13. *
  14. * @param string $name option name
  15. * @param mixed $default default value
  16. * @param bool $stripslashes whether to filter the result with stripslashes()
  17. *
  18. * @return mixed option value
  19. */
  20. function vamtam_get_option( $name, $default = null, $stripslashes = true ) {
  21. global $vamtam_defaults;
  22. $default_arg = $default;
  23. if ( $default === null ) {
  24. $default = isset( $vamtam_defaults[ $name ] ) ? $vamtam_defaults[ $name ] : false;
  25. }
  26. $option = get_option( 'vamtam_' . $name, $default );
  27. if ( is_string( $option ) ) {
  28. if ( $option === 'true' ) {
  29. return true;
  30. }
  31. if ( $option === 'false' ) {
  32. return false;
  33. }
  34. if ( $stripslashes && $option !== $default_arg ) {
  35. return stripslashes( $option );
  36. }
  37. }
  38. return $option;
  39. }
  40. function rd_vamtam_get_option( $name, $sub = null ) {
  41. global $vamtam_theme, $vamtam_defaults;
  42. $option = isset( $vamtam_theme[ $name ] ) ? $vamtam_theme[ $name ] : $vamtam_defaults[ $name ];
  43. if ( ! is_null( $sub ) && is_array( $option ) ) {
  44. $option = $option[ $sub ];
  45. }
  46. if ( is_string( $option ) ) {
  47. if ( $option === 'true' ) {
  48. $option = true;
  49. } elseif ( $option === 'false' ) {
  50. $option = false;
  51. }
  52. }
  53. return apply_filters( 'vamtam_get_option', $option, $name, $sub );
  54. }
  55. /**
  56. * Same as vamtam_get_option, but converts '1' and '0' to booleans
  57. *
  58. * @uses vamtam_get_option()
  59. *
  60. * @param string $name option name
  61. * @param mixed $default default value
  62. * @param bool $stripslashes whether to filter the result with stripslashes()
  63. *
  64. * @return mixed option value
  65. */
  66. function vamtam_get_optionb( $name, $default = null, $stripslashes = true ) {
  67. $value = vamtam_get_option( $name, $default, $stripslashes );
  68. if ( $value === '1' || $value === 'true' ) {
  69. return true;
  70. }
  71. if ( $value === '0' || $value === 'false' ) {
  72. return false;
  73. }
  74. return $value;
  75. }
  76. function rd_vamtam_get_optionb( $name, $sub = null ) {
  77. $value = rd_vamtam_get_option( $name, $sub );
  78. if ( $value === '1' || $value === 'true' ) {
  79. return true;
  80. }
  81. if ( $value === '0' || $value === 'false' ) {
  82. return false;
  83. }
  84. return is_bool( $value ) ? $value : false;
  85. }
  86. /**
  87. * update_option() wrapper
  88. *
  89. * @uses update_option()
  90. *
  91. * @param string $name option name
  92. * @param mixed $new_value option value
  93. */
  94. function vamtam_update_option( $name, $new_value ) {
  95. update_option( 'vamtam_' . $name, $new_value );
  96. }
  97. /**
  98. * delete_option wrapper
  99. *
  100. * @uses delete_option()
  101. *
  102. * @param string $name option name
  103. */
  104. function vamtam_delete_option( $name ) {
  105. delete_option( 'vamtam_' . $name );
  106. }
  107. /**
  108. * Converts '1', '0', 'true' and 'false' to booleans, otherwise returns $value
  109. * @param mixed $value original value
  110. * @return mixed sanitized value
  111. */
  112. function vamtam_sanitize_bool( $value ) {
  113. if ( $value === '1' || $value === 'true' ) {
  114. return true;
  115. }
  116. if ( $value === '0' || $value === 'false' ) {
  117. return false;
  118. }
  119. return $value;
  120. }