| @@ -35,9 +35,8 @@ | ||
| 35 | 35 | add_action( 'init', [ $this, 'register_post_types' ] ); |
| 36 | 36 | add_action( 'init', [ $this, 'register_post_metas' ] ); |
| 37 | 37 | add_shortcode( 'sureforms', [ $this, 'forms_shortcode' ] ); |
| 38 | 38 | add_action( 'manage_posts_extra_tablenav', [ $this, 'maybe_render_blank_form_state' ] ); |
| 39 | - add_action( 'admin_bar_menu', [ $this, 'remove_admin_bar_menu_item' ], 80, 1 ); | |
| 40 | 39 | add_action( 'template_redirect', [ $this, 'srfm_instant_form_redirect' ] ); |
| 41 | 40 | add_action( 'template_redirect', [ $this, 'disable_sureforms_archive_page' ], 9 ); |
| 42 | 41 | add_action( 'load-edit.php', [ $this, 'redirect_forms_listing_page' ] ); |
| 43 | 42 | |
| @@ -42,8 +41,9 @@ | ||
| 42 | 41 | add_action( 'load-edit.php', [ $this, 'redirect_forms_listing_page' ] ); |
| 43 | 42 | |
| 44 | 43 | add_filter( 'rest_prepare_sureforms_form', [ $this, 'sureforms_normalize_meta_for_rest' ], 10, 2 ); |
| 45 | 44 | add_action( 'admin_bar_menu', [ $this, 'add_edit_form_to_admin_bar_menu' ], 100 ); |
| 45 | + add_action( 'admin_bar_menu', [ $this, 'add_new_form_to_admin_bar_menu' ], 100 ); | |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * Redirect the forms listing page to the updated forms page. |
| @@ -103,8 +103,47 @@ | ||
| 103 | 103 | ); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
| 107 | + * Add a "Form" shortcut to the admin bar "+ New" menu (#3026). | |
| 108 | + * | |
| 109 | + * Mirrors how core post types appear under "+ New", but added manually rather | |
| 110 | + * than via `show_in_admin_bar` so it does not also register a second front-end | |
| 111 | + * "Edit" node alongside the custom one in add_edit_form_to_admin_bar_menu(). | |
| 112 | + * Gated on the form CPT's own create capability (manage_options for this CPT), | |
| 113 | + * so it only shows for users who can actually create a form. | |
| 114 | + * | |
| 115 | + * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance. | |
| 116 | + * @since 2.12.4 | |
| 117 | + * @return void | |
| 118 | + */ | |
| 119 | + public function add_new_form_to_admin_bar_menu( $wp_admin_bar ) { | |
| 120 | + if ( ! is_admin_bar_showing() || ! $wp_admin_bar instanceof WP_Admin_Bar ) { | |
| 121 | + return; | |
| 122 | + } | |
| 123 | + | |
| 124 | + $post_type = get_post_type_object( SRFM_FORMS_POST_TYPE ); | |
| 125 | + | |
| 126 | + if ( ! $post_type || empty( $post_type->cap->create_posts ) || ! current_user_can( $post_type->cap->create_posts ) ) { | |
| 127 | + return; | |
| 128 | + } | |
| 129 | + | |
| 130 | + // Core registers the "+ New" (new-content) group at priority 70, so running at | |
| 131 | + // 100 places this node inside it. If core skipped the group (the user can create | |
| 132 | + // nothing else), WP_Admin_Bar::_bind() drops this orphan node silently. | |
| 133 | + // name_admin_bar is the label core uses for "+ New" children; escaped because | |
| 134 | + // WP_Admin_Bar echoes node titles unescaped. | |
| 135 | + $wp_admin_bar->add_node( | |
| 136 | + [ | |
| 137 | + 'id' => 'new-' . SRFM_FORMS_POST_TYPE, | |
| 138 | + 'parent' => 'new-content', | |
| 139 | + 'title' => esc_html( $post_type->labels->name_admin_bar ), | |
| 140 | + 'href' => esc_url( admin_url( 'post-new.php?post_type=' . SRFM_FORMS_POST_TYPE ) ), | |
| 141 | + ] | |
| 142 | + ); | |
| 143 | + } | |
| 144 | + | |
| 145 | + /** | |
| 107 | 146 | * Remove this method in the future once _srfm_form_confirmation meta is updated. |
| 108 | 147 | * Normalize the _srfm_form_confirmation meta before it's sent to the REST API. |
| 109 | 148 | * Ensures the meta data is type-safe and includes necessary defaults like `hide_copy`. |
| 110 | 149 | * |
| @@ -292,20 +331,8 @@ | ||
| 292 | 331 | } |
| 293 | 332 | } |
| 294 | 333 | |
| 295 | 334 | /** |
| 296 | - * Remove add new form menu item. | |
| 297 | - * | |
| 298 | - * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance. | |
| 299 | - * | |
| 300 | - * @return void | |
| 301 | - * @since 0.0.1 | |
| 302 | - */ | |
| 303 | - public function remove_admin_bar_menu_item( $wp_admin_bar ) { | |
| 304 | - $wp_admin_bar->remove_node( 'new-sureforms_form' ); | |
| 305 | - } | |
| 306 | - | |
| 307 | - /** | |
| 308 | 335 | * Show blank slate styles. |
| 309 | 336 | * |
| 310 | 337 | * @return void |
| 311 | 338 | * @since 0.0.1 |
| @@ -419,8 +446,13 @@ | ||
| 419 | 446 | // post meta to store if the form is AI generated. |
| 420 | 447 | '_srfm_is_ai_generated' => 'boolean', |
| 421 | 448 | ] |
| 422 | 449 | ); |
| 450 | + | |
| 451 | + // NOTE: `_srfm_form_views` is intentionally NOT registered here. It is a | |
| 452 | + // server-side counter written only by Form_Views (get/add_post_meta + atomic | |
| 453 | + // SQL). Exposing it to the block editor via show_in_rest let a form save / | |
| 454 | + // autosave round-trip a stale value and clobber the live count back to 0. | |
| 423 | 455 | |
| 424 | 456 | // Form Custom CSS meta. |
| 425 | 457 | register_post_meta( |
| 426 | 458 | 'sureforms_form', |