@@ -391,35 +391,48 @@ function duplicate( $args, $assoc_args ) {
391391 * <form-id>
392392 * : The Form ID
393393 *
394+ * [<notification-id>]
395+ * : The ID of the notification to updated.
396+ *
394397 * --notification-json=<notification-json>
395- * : The JSON representation of the form
398+ * : The JSON representation of the notification.
396399 *
397400 * ## EXAMPLES
398401 *
399402 * wp gf form notification update 1 --notification-json='{snip}'
403+ * wp gf form notification update 1 abc1 --notification-json='{snip}'
400404 *
401- * @synopsis <form-id> --notification-json=<notification-json>
405+ * @synopsis <form-id> [<notification-id>] --notification-json=<notification-json>
402406 */
403407 function update ( $ args , $ assoc_args ) {
404408 $ form_id = $ args [0 ];
409+ $ form = GFAPI ::get_form ( $ form_id );
405410
406- $ notification_id = $ args [1 ];
407-
408- $ form = GFAPI ::get_form ( $ form_id );
409411 if ( empty ( $ form ) ) {
410412 WP_CLI ::error ( 'Form not found ' );
411413 }
412414
413- $ notifications = $ form ['notifications ' ];
414-
415- $ json_config = $ assoc_args ['notification-json ' ];
416-
415+ $ json_config = $ assoc_args ['notification-json ' ];
417416 $ new_notification = json_decode ( $ json_config , ARRAY_A );
418417
419418 if ( empty ( $ new_notification ) ) {
420419 WP_CLI ::error ( 'Notification not valid ' );
421420 }
422421
422+ $ notification_id = rgar ( $ args , 1 );
423+
424+ if ( empty ( $ notification_id ) ) {
425+ if ( empty ( $ new_notification ['id ' ] ) ) {
426+ WP_CLI ::error ( 'Please specify the ID of the notification to be updated ' );
427+ } else {
428+ $ notification_id = $ new_notification ['id ' ];
429+ }
430+ } else {
431+ $ new_notification ['id ' ] = $ notification_id ;
432+ }
433+
434+ $ notifications = $ form ['notifications ' ];
435+
423436 $ found = false ;
424437 foreach ( $ notifications as $ key => $ notification ) {
425438 if ( $ notification ['id ' ] == $ notification_id ) {
0 commit comments