__( 'ACS Forms', 'acs-contact-form' ), 'singular_name' => __( 'ACS Form', 'acs-contact-form' ), 'menu_name' => __( 'ACS Forms', 'acs-contact-form' ), 'name_admin_bar' => __( 'ACS Form', 'acs-contact-form' ), 'add_new' => __( 'Add New', 'acs-contact-form' ), 'add_new_item' => __( 'Add New Form', 'acs-contact-form' ), 'new_item' => __( 'New form', 'acs-contact-form' ), 'edit_item' => __( 'Edit Form', 'acs-contact-form' ), 'view_item' => __( 'View Form', 'acs-contact-form' ), 'all_items' => __( 'All forms', 'acs-contact-form' ), 'search_items' => __( 'Search Forms', 'acs-contact-form' ), 'not_found' => __( 'No forms found.', 'acs-contact-form' ), 'not_found_in_trash' => __( 'No forms found in Trash.', 'acs-contact-form' ), ); $args = array( 'labels' => $labels, 'public' => false, 'publicly_queryable' => false, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => false, 'rewrite' => false, 'capability_type' => 'post', // Forms send e-mail (notifications, auto-replies, test e-mails), so // creating and editing them is limited to Editors and above. 'capabilities' => acscf_form_capabilities(), 'map_meta_cap' => true, 'has_archive' => false, 'hierarchical' => false, 'menu_position' => 30, 'menu_icon' => 'dashicons-email-alt', 'supports' => array( 'title' ), 'show_in_rest' => false, ); register_post_type( 'acscf_form', $args ); } add_action( 'init', 'acscf_register_post_type' ); /** * Primitive capabilities of the form post type. * * Every capability that would let a user create, edit or publish a form is * mapped to edit_others_posts (Editors and above), and deleting a form to * delete_others_posts. Contributors and Authors can no longer create forms * or change the recipients and texts of the e-mails a form sends. * * @return array */ function acscf_form_capabilities() { $capabilities = array( 'edit_posts' => 'edit_others_posts', 'edit_others_posts' => 'edit_others_posts', 'edit_published_posts' => 'edit_others_posts', 'edit_private_posts' => 'edit_others_posts', 'publish_posts' => 'edit_others_posts', 'create_posts' => 'edit_others_posts', 'read_private_posts' => 'edit_others_posts', 'delete_posts' => 'delete_others_posts', 'delete_others_posts' => 'delete_others_posts', 'delete_published_posts' => 'delete_others_posts', 'delete_private_posts' => 'delete_others_posts', ); /** * Filters the primitive capabilities of the form post type. * * @param array $capabilities Capability map. */ return (array) apply_filters( 'acscf_form_capabilities', $capabilities ); } /** * Columns of the form list. * * @param array $columns Existing columns. * @return array */ function acscf_set_custom_edit_acscf_form_columns( $columns ) { $new = array(); if ( isset( $columns['cb'] ) ) { $new['cb'] = $columns['cb']; } $new['title'] = __( 'Form name', 'acs-contact-form' ); $new['shortcode'] = __( 'Shortcode', 'acs-contact-form' ); $new['date'] = __( 'Created', 'acs-contact-form' ); return $new; } add_filter( 'manage_acscf_form_posts_columns', 'acscf_set_custom_edit_acscf_form_columns' ); /** * Content of the shortcode column. * * @param string $column Column name. * @param int $post_id Post ID. * @return void */ function acscf_custom_acscf_form_column( $column, $post_id ) { if ( 'shortcode' !== $column ) { return; } $shortcode = '[acscf_form id="' . (int) $post_id . '"]'; printf( '%1$s', esc_attr( $shortcode ), esc_attr__( 'Click to copy', 'acs-contact-form' ) ); } add_action( 'manage_acscf_form_posts_custom_column', 'acscf_custom_acscf_form_column', 10, 2 ); /** * Small helper that copies the shortcode to the clipboard. * * @param string $hook Current admin page. * @return void */ function acscf_list_page_scripts( $hook ) { global $post_type; if ( 'edit.php' !== $hook || 'acscf_form' !== $post_type ) { return; } wp_enqueue_style( 'acscf-admin', ACSCF_PLUGIN_URL . 'assets/css/admin.css', array(), ACSCF_VERSION ); wp_enqueue_script( 'acscf-shortcode-copy', ACSCF_PLUGIN_URL . 'assets/js/shortcode-copy.js', array(), ACSCF_VERSION, true ); wp_localize_script( 'acscf-shortcode-copy', 'acscfCopy', array( 'copied' => __( 'Copied!', 'acs-contact-form' ) ) ); } add_action( 'admin_enqueue_scripts', 'acscf_list_page_scripts' );