class.jetpack-sync-actions.php
7 years ago
class.jetpack-sync-defaults.php
7 years ago
class.jetpack-sync-functions.php
7 years ago
class.jetpack-sync-json-deflate-array-codec.php
7 years ago
class.jetpack-sync-listener.php
7 years ago
class.jetpack-sync-module-attachments.php
7 years ago
class.jetpack-sync-module-callables.php
7 years ago
class.jetpack-sync-module-comments.php
7 years ago
class.jetpack-sync-module-constants.php
7 years ago
class.jetpack-sync-module-full-sync.php
7 years ago
class.jetpack-sync-module-import.php
7 years ago
class.jetpack-sync-module-menus.php
7 years ago
class.jetpack-sync-module-meta.php
7 years ago
class.jetpack-sync-module-network-options.php
7 years ago
class.jetpack-sync-module-options.php
7 years ago
class.jetpack-sync-module-plugins.php
7 years ago
class.jetpack-sync-module-posts.php
7 years ago
class.jetpack-sync-module-protect.php
7 years ago
class.jetpack-sync-module-stats.php
9 years ago
class.jetpack-sync-module-terms.php
7 years ago
class.jetpack-sync-module-themes.php
7 years ago
class.jetpack-sync-module-updates.php
7 years ago
class.jetpack-sync-module-users.php
7 years ago
class.jetpack-sync-module-woocommerce.php
7 years ago
class.jetpack-sync-module-wp-super-cache.php
7 years ago
class.jetpack-sync-module.php
7 years ago
class.jetpack-sync-modules.php
7 years ago
class.jetpack-sync-queue.php
7 years ago
class.jetpack-sync-sender.php
7 years ago
class.jetpack-sync-server.php
7 years ago
class.jetpack-sync-settings.php
7 years ago
class.jetpack-sync-simple-codec.php
7 years ago
class.jetpack-sync-users.php
7 years ago
class.jetpack-sync-wp-replicastore.php
7 years ago
interface.jetpack-sync-codec.php
9 years ago
interface.jetpack-sync-replicastore.php
7 years ago
class.jetpack-sync-module-menus.php
79 lines
| 1 | <?php |
| 2 | |
| 3 | class Jetpack_Sync_Module_Menus extends Jetpack_Sync_Module { |
| 4 | private $nav_items_just_added = array(); |
| 5 | |
| 6 | function name() { |
| 7 | return 'menus'; |
| 8 | } |
| 9 | |
| 10 | public function init_listeners( $callable ) { |
| 11 | add_action( 'wp_create_nav_menu', $callable, 10, 2 ); |
| 12 | add_action( 'wp_update_nav_menu', array( $this, 'update_nav_menu' ), 10, 2 ); |
| 13 | add_action( 'wp_add_nav_menu_item', array( $this, 'update_nav_menu_add_item' ), 10, 3 ); |
| 14 | add_action( 'wp_update_nav_menu_item', array( $this, 'update_nav_menu_update_item' ), 10, 3 ); |
| 15 | add_action( 'post_updated', array( $this, 'remove_just_added_menu_item' ), 10, 2 ); |
| 16 | |
| 17 | add_action( 'jetpack_sync_updated_nav_menu', $callable, 10, 2 ); |
| 18 | add_action( 'jetpack_sync_updated_nav_menu_add_item', $callable, 10, 4 ); |
| 19 | add_action( 'jetpack_sync_updated_nav_menu_update_item', $callable, 10, 4 ); |
| 20 | add_action( 'delete_nav_menu', $callable, 10, 3 ); |
| 21 | } |
| 22 | |
| 23 | public function update_nav_menu( $menu_id, $menu_data = array() ) { |
| 24 | if ( empty( $menu_data ) ) { |
| 25 | return; |
| 26 | } |
| 27 | /** |
| 28 | * Helps sync log that a nav menu was updated. |
| 29 | * |
| 30 | * @since 5.0.0 |
| 31 | * |
| 32 | * @param int $menu_id, the id of the menu |
| 33 | * @param object $menu_data |
| 34 | */ |
| 35 | do_action( 'jetpack_sync_updated_nav_menu', $menu_id, $menu_data ); |
| 36 | } |
| 37 | |
| 38 | public function update_nav_menu_add_item( $menu_id, $nav_item_id, $nav_item_args ) { |
| 39 | $menu_data = wp_get_nav_menu_object( $menu_id ); |
| 40 | $this->nav_items_just_added[] = $nav_item_id; |
| 41 | /** |
| 42 | * Helps sync log that a new menu item was added. |
| 43 | * |
| 44 | * @since 5.0.0 |
| 45 | * |
| 46 | * @param int $menu_id, the id of the menu |
| 47 | * @param object $menu_data |
| 48 | * @param int $nav_item_id |
| 49 | * @param int $nav_item_args |
| 50 | */ |
| 51 | do_action( 'jetpack_sync_updated_nav_menu_add_item', $menu_id, $menu_data, $nav_item_id, $nav_item_args ); |
| 52 | } |
| 53 | |
| 54 | public function update_nav_menu_update_item( $menu_id, $nav_item_id, $nav_item_args ) { |
| 55 | if ( in_array( $nav_item_id, $this->nav_items_just_added ) ) { |
| 56 | return; |
| 57 | } |
| 58 | $menu_data = wp_get_nav_menu_object( $menu_id ); |
| 59 | /** |
| 60 | * Helps sync log that an update to the menu item happened. |
| 61 | * |
| 62 | * @since 5.0.0 |
| 63 | * |
| 64 | * @param int $menu_id, the id of the menu |
| 65 | * @param object $menu_data |
| 66 | * @param int $nav_item_id |
| 67 | * @param int $nav_item_args |
| 68 | */ |
| 69 | do_action( 'jetpack_sync_updated_nav_menu_update_item', $menu_id, $menu_data, $nav_item_id, $nav_item_args ); |
| 70 | } |
| 71 | |
| 72 | public function remove_just_added_menu_item( $nav_item_id, $post_after ) { |
| 73 | if ( 'nav_menu_item' !== $post_after->post_type ) { |
| 74 | return; |
| 75 | } |
| 76 | $this->nav_items_just_added = array_diff( $this->nav_items_just_added, array( $nav_item_id ) ); |
| 77 | } |
| 78 | } |
| 79 |