/wp-includes/customize/class-wp-customize-nav-menu-setting.php

  1. <?php 
  2. /** 
  3. * Customize API: WP_Customize_Nav_Menu_Setting class 
  4. * 
  5. * @package WordPress 
  6. * @subpackage Customize 
  7. * @since 4.4.0 
  8. */ 
  9.  
  10. /** 
  11. * Customize Setting to represent a nav_menu. 
  12. * 
  13. * Subclass of WP_Customize_Setting to represent a nav_menu taxonomy term, and 
  14. * the IDs for the nav_menu_items associated with the nav menu. 
  15. * 
  16. * @since 4.3.0 
  17. * 
  18. * @see wp_get_nav_menu_object() 
  19. * @see WP_Customize_Setting 
  20. */ 
  21. class WP_Customize_Nav_Menu_Setting extends WP_Customize_Setting { 
  22.  
  23. const ID_PATTERN = '/^nav_menu\[(?P<id>-?\d+)\]$/'; 
  24.  
  25. const TAXONOMY = 'nav_menu'; 
  26.  
  27. const TYPE = 'nav_menu'; 
  28.  
  29. /** 
  30. * Setting type. 
  31. * 
  32. * @since 4.3.0 
  33. * @access public 
  34. * @var string 
  35. */ 
  36. public $type = self::TYPE; 
  37.  
  38. /** 
  39. * Default setting value. 
  40. * 
  41. * @since 4.3.0 
  42. * @access public 
  43. * @var array 
  44. * 
  45. * @see wp_get_nav_menu_object() 
  46. */ 
  47. public $default = array( 
  48. 'name' => '',  
  49. 'description' => '',  
  50. 'parent' => 0,  
  51. 'auto_add' => false,  
  52. ); 
  53.  
  54. /** 
  55. * Default transport. 
  56. * 
  57. * @since 4.3.0 
  58. * @access public 
  59. * @var string 
  60. */ 
  61. public $transport = 'postMessage'; 
  62.  
  63. /** 
  64. * The term ID represented by this setting instance. 
  65. * 
  66. * A negative value represents a placeholder ID for a new menu not yet saved. 
  67. * 
  68. * @since 4.3.0 
  69. * @access public 
  70. * @var int 
  71. */ 
  72. public $term_id; 
  73.  
  74. /** 
  75. * Previous (placeholder) term ID used before creating a new menu. 
  76. * 
  77. * This value will be exported to JS via the {@see 'customize_save_response'} filter 
  78. * so that JavaScript can update the settings to refer to the newly-assigned 
  79. * term ID. This value is always negative to indicate it does not refer to 
  80. * a real term. 
  81. * 
  82. * @since 4.3.0 
  83. * @access public 
  84. * @var int 
  85. * 
  86. * @see WP_Customize_Nav_Menu_Setting::update() 
  87. * @see WP_Customize_Nav_Menu_Setting::amend_customize_save_response() 
  88. */ 
  89. public $previous_term_id; 
  90.  
  91. /** 
  92. * Whether or not update() was called. 
  93. * 
  94. * @since 4.3.0 
  95. * @access protected 
  96. * @var bool 
  97. */ 
  98. protected $is_updated = false; 
  99.  
  100. /** 
  101. * Status for calling the update method, used in customize_save_response filter. 
  102. * 
  103. * See {@see 'customize_save_response'}. 
  104. * 
  105. * When status is inserted, the placeholder term ID is stored in `$previous_term_id`. 
  106. * When status is error, the error is stored in `$update_error`. 
  107. * 
  108. * @since 4.3.0 
  109. * @access public 
  110. * @var string updated|inserted|deleted|error 
  111. * 
  112. * @see WP_Customize_Nav_Menu_Setting::update() 
  113. * @see WP_Customize_Nav_Menu_Setting::amend_customize_save_response() 
  114. */ 
  115. public $update_status; 
  116.  
  117. /** 
  118. * Any error object returned by wp_update_nav_menu_object() when setting is updated. 
  119. * 
  120. * @since 4.3.0 
  121. * @access public 
  122. * @var WP_Error 
  123. * 
  124. * @see WP_Customize_Nav_Menu_Setting::update() 
  125. * @see WP_Customize_Nav_Menu_Setting::amend_customize_save_response() 
  126. */ 
  127. public $update_error; 
  128.  
  129. /** 
  130. * Constructor. 
  131. * 
  132. * Any supplied $args override class property defaults. 
  133. * 
  134. * @since 4.3.0 
  135. * @access public 
  136. * 
  137. * @param WP_Customize_Manager $manager Bootstrap Customizer instance. 
  138. * @param string $id An specific ID of the setting. Can be a 
  139. * theme mod or option name. 
  140. * @param array $args Optional. Setting arguments. 
  141. * 
  142. * @throws Exception If $id is not valid for this setting type. 
  143. */ 
  144. public function __construct( WP_Customize_Manager $manager, $id, array $args = array() ) { 
  145. if ( empty( $manager->nav_menus ) ) { 
  146. throw new Exception( 'Expected WP_Customize_Manager::$nav_menus to be set.' ); 
  147.  
  148. if ( ! preg_match( self::ID_PATTERN, $id, $matches ) ) { 
  149. throw new Exception( "Illegal widget setting ID: $id" ); 
  150.  
  151. $this->term_id = intval( $matches['id'] ); 
  152.  
  153. parent::__construct( $manager, $id, $args ); 
  154.  
  155. /** 
  156. * Get the instance data for a given widget setting. 
  157. * 
  158. * @since 4.3.0 
  159. * @access public 
  160. * 
  161. * @see wp_get_nav_menu_object() 
  162. * 
  163. * @return array Instance data. 
  164. */ 
  165. public function value() { 
  166. if ( $this->is_previewed && $this->_previewed_blog_id === get_current_blog_id() ) { 
  167. $undefined = new stdClass(); // Symbol. 
  168. $post_value = $this->post_value( $undefined ); 
  169.  
  170. if ( $undefined === $post_value ) { 
  171. $value = $this->_original_value; 
  172. } else { 
  173. $value = $post_value; 
  174. } else { 
  175. $value = false; 
  176.  
  177. // Note that a term_id of less than one indicates a nav_menu not yet inserted. 
  178. if ( $this->term_id > 0 ) { 
  179. $term = wp_get_nav_menu_object( $this->term_id ); 
  180.  
  181. if ( $term ) { 
  182. $value = wp_array_slice_assoc( (array) $term, array_keys( $this->default ) ); 
  183.  
  184. $nav_menu_options = (array) get_option( 'nav_menu_options', array() ); 
  185. $value['auto_add'] = false; 
  186.  
  187. if ( isset( $nav_menu_options['auto_add'] ) && is_array( $nav_menu_options['auto_add'] ) ) { 
  188. $value['auto_add'] = in_array( $term->term_id, $nav_menu_options['auto_add'] ); 
  189.  
  190. if ( ! is_array( $value ) ) { 
  191. $value = $this->default; 
  192. return $value; 
  193.  
  194. /** 
  195. * Handle previewing the setting. 
  196. * 
  197. * @since 4.3.0 
  198. * @since 4.4.0 Added boolean return value 
  199. * @access public 
  200. * 
  201. * @see WP_Customize_Manager::post_value() 
  202. * 
  203. * @return bool False if method short-circuited due to no-op. 
  204. */ 
  205. public function preview() { 
  206. if ( $this->is_previewed ) { 
  207. return false; 
  208.  
  209. $undefined = new stdClass(); 
  210. $is_placeholder = ( $this->term_id < 0 ); 
  211. $is_dirty = ( $undefined !== $this->post_value( $undefined ) ); 
  212. if ( ! $is_placeholder && ! $is_dirty ) { 
  213. return false; 
  214.  
  215. $this->is_previewed = true; 
  216. $this->_original_value = $this->value(); 
  217. $this->_previewed_blog_id = get_current_blog_id(); 
  218.  
  219. add_filter( 'wp_get_nav_menus', array( $this, 'filter_wp_get_nav_menus' ), 10, 2 ); 
  220. add_filter( 'wp_get_nav_menu_object', array( $this, 'filter_wp_get_nav_menu_object' ), 10, 2 ); 
  221. add_filter( 'default_option_nav_menu_options', array( $this, 'filter_nav_menu_options' ) ); 
  222. add_filter( 'option_nav_menu_options', array( $this, 'filter_nav_menu_options' ) ); 
  223.  
  224. return true; 
  225.  
  226. /** 
  227. * Filters the wp_get_nav_menus() result to ensure the inserted menu object is included, and the deleted one is removed. 
  228. * 
  229. * @since 4.3.0 
  230. * @access public 
  231. * 
  232. * @see wp_get_nav_menus() 
  233. * 
  234. * @param array $menus An array of menu objects. 
  235. * @param array $args An array of arguments used to retrieve menu objects. 
  236. * @return array 
  237. */ 
  238. public function filter_wp_get_nav_menus( $menus, $args ) { 
  239. if ( get_current_blog_id() !== $this->_previewed_blog_id ) { 
  240. return $menus; 
  241.  
  242. $setting_value = $this->value(); 
  243. $is_delete = ( false === $setting_value ); 
  244. $index = -1; 
  245.  
  246. // Find the existing menu item's position in the list. 
  247. foreach ( $menus as $i => $menu ) { 
  248. if ( (int) $this->term_id === (int) $menu->term_id || (int) $this->previous_term_id === (int) $menu->term_id ) { 
  249. $index = $i; 
  250. break; 
  251.  
  252. if ( $is_delete ) { 
  253. // Handle deleted menu by removing it from the list. 
  254. if ( -1 !== $index ) { 
  255. array_splice( $menus, $index, 1 ); 
  256. } else { 
  257. // Handle menus being updated or inserted. 
  258. $menu_obj = (object) array_merge( array( 
  259. 'term_id' => $this->term_id,  
  260. 'term_taxonomy_id' => $this->term_id,  
  261. 'slug' => sanitize_title( $setting_value['name'] ),  
  262. 'count' => 0,  
  263. 'term_group' => 0,  
  264. 'taxonomy' => self::TAXONOMY,  
  265. 'filter' => 'raw',  
  266. ), $setting_value ); 
  267.  
  268. array_splice( $menus, $index, ( -1 === $index ? 0 : 1 ), array( $menu_obj ) ); 
  269.  
  270. // Make sure the menu objects get re-sorted after an update/insert. 
  271. if ( ! $is_delete && ! empty( $args['orderby'] ) ) { 
  272. $menus = wp_list_sort( $menus, array( 
  273. $args['orderby'] => 'ASC',  
  274. ) ); 
  275. // @todo add support for $args['hide_empty'] === true 
  276.  
  277. return $menus; 
  278.  
  279. /** 
  280. * Temporary non-closure passing of orderby value to function. 
  281. * 
  282. * @since 4.3.0 
  283. * @access protected 
  284. * @var string 
  285. * 
  286. * @see WP_Customize_Nav_Menu_Setting::filter_wp_get_nav_menus() 
  287. * @see WP_Customize_Nav_Menu_Setting::_sort_menus_by_orderby() 
  288. */ 
  289. protected $_current_menus_sort_orderby; 
  290.  
  291. /** 
  292. * Sort menu objects by the class-supplied orderby property. 
  293. * 
  294. * This is a workaround for a lack of closures. 
  295. * 
  296. * @since 4.3.0 
  297. * @deprecated 4.7.0 Use wp_list_sort() 
  298. * @access protected 
  299. * 
  300. * @param object $menu1 
  301. * @param object $menu2 
  302. * @return int 
  303. * 
  304. * @see WP_Customize_Nav_Menu_Setting::filter_wp_get_nav_menus() 
  305. */ 
  306. protected function _sort_menus_by_orderby( $menu1, $menu2 ) { 
  307. _deprecated_function( __METHOD__, '4.7.0', 'wp_list_sort' ); 
  308.  
  309. $key = $this->_current_menus_sort_orderby; 
  310. return strcmp( $menu1->$key, $menu2->$key ); 
  311.  
  312. /** 
  313. * Filters the wp_get_nav_menu_object() result to supply the previewed menu object. 
  314. * 
  315. * Requesting a nav_menu object by anything but ID is not supported. 
  316. * 
  317. * @since 4.3.0 
  318. * @access public 
  319. * 
  320. * @see wp_get_nav_menu_object() 
  321. * 
  322. * @param object|null $menu_obj Object returned by wp_get_nav_menu_object(). 
  323. * @param string $menu_id ID of the nav_menu term. Requests by slug or name will be ignored. 
  324. * @return object|null 
  325. */ 
  326. public function filter_wp_get_nav_menu_object( $menu_obj, $menu_id ) { 
  327. $ok = ( 
  328. get_current_blog_id() === $this->_previewed_blog_id 
  329. && 
  330. is_int( $menu_id ) 
  331. && 
  332. $menu_id === $this->term_id 
  333. ); 
  334. if ( ! $ok ) { 
  335. return $menu_obj; 
  336.  
  337. $setting_value = $this->value(); 
  338.  
  339. // Handle deleted menus. 
  340. if ( false === $setting_value ) { 
  341. return false; 
  342.  
  343. // Handle sanitization failure by preventing short-circuiting. 
  344. if ( null === $setting_value ) { 
  345. return $menu_obj; 
  346.  
  347. $menu_obj = (object) array_merge( array( 
  348. 'term_id' => $this->term_id,  
  349. 'term_taxonomy_id' => $this->term_id,  
  350. 'slug' => sanitize_title( $setting_value['name'] ),  
  351. 'count' => 0,  
  352. 'term_group' => 0,  
  353. 'taxonomy' => self::TAXONOMY,  
  354. 'filter' => 'raw',  
  355. ), $setting_value ); 
  356.  
  357. return $menu_obj; 
  358.  
  359. /** 
  360. * Filters the nav_menu_options option to include this menu's auto_add preference. 
  361. * 
  362. * @since 4.3.0 
  363. * @access public 
  364. * 
  365. * @param array $nav_menu_options Nav menu options including auto_add. 
  366. * @return array (Kaybe) modified nav menu options. 
  367. */ 
  368. public function filter_nav_menu_options( $nav_menu_options ) { 
  369. if ( $this->_previewed_blog_id !== get_current_blog_id() ) { 
  370. return $nav_menu_options; 
  371.  
  372. $menu = $this->value(); 
  373. $nav_menu_options = $this->filter_nav_menu_options_value( 
  374. $nav_menu_options,  
  375. $this->term_id,  
  376. false === $menu ? false : $menu['auto_add'] 
  377. ); 
  378.  
  379. return $nav_menu_options; 
  380.  
  381. /** 
  382. * Sanitize an input. 
  383. * 
  384. * Note that parent::sanitize() erroneously does wp_unslash() on $value, but 
  385. * we remove that in this override. 
  386. * 
  387. * @since 4.3.0 
  388. * @access public 
  389. * 
  390. * @param array $value The value to sanitize. 
  391. * @return array|false|null Null if an input isn't valid. False if it is marked for deletion. 
  392. * Otherwise the sanitized value. 
  393. */ 
  394. public function sanitize( $value ) { 
  395. // Menu is marked for deletion. 
  396. if ( false === $value ) { 
  397. return $value; 
  398.  
  399. // Invalid. 
  400. if ( ! is_array( $value ) ) { 
  401. return null; 
  402.  
  403. $default = array( 
  404. 'name' => '',  
  405. 'description' => '',  
  406. 'parent' => 0,  
  407. 'auto_add' => false,  
  408. ); 
  409. $value = array_merge( $default, $value ); 
  410. $value = wp_array_slice_assoc( $value, array_keys( $default ) ); 
  411.  
  412. $value['name'] = trim( esc_html( $value['name'] ) ); // This sanitization code is used in wp-admin/nav-menus.php. 
  413. $value['description'] = sanitize_text_field( $value['description'] ); 
  414. $value['parent'] = max( 0, intval( $value['parent'] ) ); 
  415. $value['auto_add'] = ! empty( $value['auto_add'] ); 
  416.  
  417. if ( '' === $value['name'] ) { 
  418. $value['name'] = _x( '(unnamed)', 'Missing menu name.' ); 
  419.  
  420. /** This filter is documented in wp-includes/class-wp-customize-setting.php */ 
  421. return apply_filters( "customize_sanitize_{$this->id}", $value, $this ); 
  422.  
  423. /** 
  424. * Storage for data to be sent back to client in customize_save_response filter. 
  425. * 
  426. * See {@see 'customize_save_response'}. 
  427. * 
  428. * @access protected 
  429. * @since 4.3.0 
  430. * @var array 
  431. * 
  432. * @see WP_Customize_Nav_Menu_Setting::amend_customize_save_response() 
  433. */ 
  434. protected $_widget_nav_menu_updates = array(); 
  435.  
  436. /** 
  437. * Create/update the nav_menu term for this setting. 
  438. * 
  439. * Any created menus will have their assigned term IDs exported to the client 
  440. * via the {@see 'customize_save_response'} filter. Likewise, any errors will be exported 
  441. * to the client via the customize_save_response() filter. 
  442. * 
  443. * To delete a menu, the client can send false as the value. 
  444. * 
  445. * @since 4.3.0 
  446. * @access protected 
  447. * 
  448. * @see wp_update_nav_menu_object() 
  449. * 
  450. * @param array|false $value { 
  451. * The value to update. Note that slug cannot be updated via wp_update_nav_menu_object(). 
  452. * If false, then the menu will be deleted entirely. 
  453. * 
  454. * @type string $name The name of the menu to save. 
  455. * @type string $description The term description. Default empty string. 
  456. * @type int $parent The id of the parent term. Default 0. 
  457. * @type bool $auto_add Whether pages will auto_add to this menu. Default false. 
  458. * } 
  459. * @return null|void 
  460. */ 
  461. protected function update( $value ) { 
  462. if ( $this->is_updated ) { 
  463. return; 
  464.  
  465. $this->is_updated = true; 
  466. $is_placeholder = ( $this->term_id < 0 ); 
  467. $is_delete = ( false === $value ); 
  468.  
  469. add_filter( 'customize_save_response', array( $this, 'amend_customize_save_response' ) ); 
  470.  
  471. $auto_add = null; 
  472. if ( $is_delete ) { 
  473. // If the current setting term is a placeholder, a delete request is a no-op. 
  474. if ( $is_placeholder ) { 
  475. $this->update_status = 'deleted'; 
  476. } else { 
  477. $r = wp_delete_nav_menu( $this->term_id ); 
  478.  
  479. if ( is_wp_error( $r ) ) { 
  480. $this->update_status = 'error'; 
  481. $this->update_error = $r; 
  482. } else { 
  483. $this->update_status = 'deleted'; 
  484. $auto_add = false; 
  485. } else { 
  486. // Insert or update menu. 
  487. $menu_data = wp_array_slice_assoc( $value, array( 'description', 'parent' ) ); 
  488. $menu_data['menu-name'] = $value['name']; 
  489.  
  490. $menu_id = $is_placeholder ? 0 : $this->term_id; 
  491. $r = wp_update_nav_menu_object( $menu_id, wp_slash( $menu_data ) ); 
  492. $original_name = $menu_data['menu-name']; 
  493. $name_conflict_suffix = 1; 
  494. while ( is_wp_error( $r ) && 'menu_exists' === $r->get_error_code() ) { 
  495. $name_conflict_suffix += 1; 
  496. /** translators: 1: original menu name, 2: duplicate count */ 
  497. $menu_data['menu-name'] = sprintf( __( '%1$s (%2$d)' ), $original_name, $name_conflict_suffix ); 
  498. $r = wp_update_nav_menu_object( $menu_id, wp_slash( $menu_data ) ); 
  499.  
  500. if ( is_wp_error( $r ) ) { 
  501. $this->update_status = 'error'; 
  502. $this->update_error = $r; 
  503. } else { 
  504. if ( $is_placeholder ) { 
  505. $this->previous_term_id = $this->term_id; 
  506. $this->term_id = $r; 
  507. $this->update_status = 'inserted'; 
  508. } else { 
  509. $this->update_status = 'updated'; 
  510.  
  511. $auto_add = $value['auto_add']; 
  512.  
  513. if ( null !== $auto_add ) { 
  514. $nav_menu_options = $this->filter_nav_menu_options_value( 
  515. (array) get_option( 'nav_menu_options', array() ),  
  516. $this->term_id,  
  517. $auto_add 
  518. ); 
  519. update_option( 'nav_menu_options', $nav_menu_options ); 
  520.  
  521. if ( 'inserted' === $this->update_status ) { 
  522. // Make sure that new menus assigned to nav menu locations use their new IDs. 
  523. foreach ( $this->manager->settings() as $setting ) { 
  524. if ( ! preg_match( '/^nav_menu_locations\[/', $setting->id ) ) { 
  525. continue; 
  526.  
  527. $post_value = $setting->post_value( null ); 
  528. if ( ! is_null( $post_value ) && $this->previous_term_id === intval( $post_value ) ) { 
  529. $this->manager->set_post_value( $setting->id, $this->term_id ); 
  530. $setting->save(); 
  531.  
  532. // Make sure that any nav_menu widgets referencing the placeholder nav menu get updated and sent back to client. 
  533. foreach ( array_keys( $this->manager->unsanitized_post_values() ) as $setting_id ) { 
  534. $nav_menu_widget_setting = $this->manager->get_setting( $setting_id ); 
  535. if ( ! $nav_menu_widget_setting || ! preg_match( '/^widget_nav_menu\[/', $nav_menu_widget_setting->id ) ) { 
  536. continue; 
  537.  
  538. $widget_instance = $nav_menu_widget_setting->post_value(); // Note that this calls WP_Customize_Widgets::sanitize_widget_instance(). 
  539. if ( empty( $widget_instance['nav_menu'] ) || intval( $widget_instance['nav_menu'] ) !== $this->previous_term_id ) { 
  540. continue; 
  541.  
  542. $widget_instance['nav_menu'] = $this->term_id; 
  543. $updated_widget_instance = $this->manager->widgets->sanitize_widget_js_instance( $widget_instance ); 
  544. $this->manager->set_post_value( $nav_menu_widget_setting->id, $updated_widget_instance ); 
  545. $nav_menu_widget_setting->save(); 
  546.  
  547. $this->_widget_nav_menu_updates[ $nav_menu_widget_setting->id ] = $updated_widget_instance; 
  548.  
  549. /** 
  550. * Updates a nav_menu_options array. 
  551. * 
  552. * @since 4.3.0 
  553. * @access protected 
  554. * 
  555. * @see WP_Customize_Nav_Menu_Setting::filter_nav_menu_options() 
  556. * @see WP_Customize_Nav_Menu_Setting::update() 
  557. * 
  558. * @param array $nav_menu_options Array as returned by get_option( 'nav_menu_options' ). 
  559. * @param int $menu_id The term ID for the given menu. 
  560. * @param bool $auto_add Whether to auto-add or not. 
  561. * @return array (Maybe) modified nav_menu_otions array. 
  562. */ 
  563. protected function filter_nav_menu_options_value( $nav_menu_options, $menu_id, $auto_add ) { 
  564. $nav_menu_options = (array) $nav_menu_options; 
  565. if ( ! isset( $nav_menu_options['auto_add'] ) ) { 
  566. $nav_menu_options['auto_add'] = array(); 
  567.  
  568. $i = array_search( $menu_id, $nav_menu_options['auto_add'] ); 
  569. if ( $auto_add && false === $i ) { 
  570. array_push( $nav_menu_options['auto_add'], $this->term_id ); 
  571. } elseif ( ! $auto_add && false !== $i ) { 
  572. array_splice( $nav_menu_options['auto_add'], $i, 1 ); 
  573.  
  574. return $nav_menu_options; 
  575.  
  576. /** 
  577. * Export data for the JS client. 
  578. * 
  579. * @since 4.3.0 
  580. * @access public 
  581. * 
  582. * @see WP_Customize_Nav_Menu_Setting::update() 
  583. * 
  584. * @param array $data Additional information passed back to the 'saved' event on `wp.customize`. 
  585. * @return array Export data. 
  586. */ 
  587. public function amend_customize_save_response( $data ) { 
  588. if ( ! isset( $data['nav_menu_updates'] ) ) { 
  589. $data['nav_menu_updates'] = array(); 
  590. if ( ! isset( $data['widget_nav_menu_updates'] ) ) { 
  591. $data['widget_nav_menu_updates'] = array(); 
  592.  
  593. $data['nav_menu_updates'][] = array( 
  594. 'term_id' => $this->term_id,  
  595. 'previous_term_id' => $this->previous_term_id,  
  596. 'error' => $this->update_error ? $this->update_error->get_error_code() : null,  
  597. 'status' => $this->update_status,  
  598. 'saved_value' => 'deleted' === $this->update_status ? null : $this->value(),  
  599. ); 
  600.  
  601. $data['widget_nav_menu_updates'] = array_merge( 
  602. $data['widget_nav_menu_updates'],  
  603. $this->_widget_nav_menu_updates 
  604. ); 
  605. $this->_widget_nav_menu_updates = array(); 
  606.  
  607. return $data; 
.