WPCOM_JSON_API_Menus_Translator

The Jetpack by WordPress.com WPCOM JSON API Menus Translator class.

Defined (1)

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

/json-endpoints/class.wpcom-json-api-menus-v1-1-endpoint.php  
  1. abstract class WPCOM_JSON_API_Menus_Translator { 
  2. protected $filter = ''; 
  3.  
  4. protected $filters = array(); 
  5.  
  6. public function __construct( $menus ) { 
  7. $this->is_single_menu = ! is_array( $menus ); 
  8. $this->menus = is_array( $menus ) ? $menus : array( $menus ); 
  9.  
  10. public function translate() { 
  11. $result = $this->menus; 
  12. foreach ( $this->filters as $f ) { 
  13. $result = call_user_func( array( $this, $f ), $result ); 
  14. if ( is_wp_error($result ) ) { 
  15. return $result; 
  16. return $this->maybe_extract( $result ); 
  17.  
  18. protected function maybe_extract( $menus ) { 
  19. return $this->is_single_menu ? $menus[0] : $menus; 
  20.  
  21. public function whitelist_and_rename_with( $object, $dict ) { 
  22. $keys = array_keys( $dict ); 
  23. $return = array(); 
  24. foreach ( (array) $object as $k => $v ) { 
  25. if ( in_array( $k, $keys ) ) { 
  26. if ( is_array( $dict[ $k ] ) ) { 
  27. settype( $v, $dict[ $k ]['type'] ); 
  28. $return[ $dict[ $k ]['name'] ] = $v; 
  29. } else { 
  30. $new_k = $dict[ $k ]; 
  31. $return[ $new_k ] = $v; 
  32. return $return;