'New team member', * 'desc' => 'Enter photo, name and role', * 'icon' => 'dashicons-groups', * 'url' => admin_url( 'post-new.php?post_type=team' ), * ); * return $actions; * } ); * * @since 0.1.0 */ class Quick_Actions { /** * Returns all registered actions (filtered by approval and capabilities). * * @since 0.1.0 * * @return array> */ public static function get() { $actions = self::registry(); /** * Filters the quick actions to add, change, or remove entries. * * @since 0.1.0 * * @param array $actions Actions, key = ID. */ $actions = apply_filters( 'quietadmin_quick_actions', $actions ); // Apply the order from the settings. $order = (array) Options::get( 'quick_actions' ); $enabled = array(); foreach ( $order as $key ) { if ( isset( $actions[ $key ] ) ) { $enabled[ $key ] = $actions[ $key ]; } } // Append actions not listed in the order (e.g. added via filter). foreach ( $actions as $key => $action ) { if ( ! isset( $enabled[ $key ] ) ) { $enabled[ $key ] = $action; } } // Check capabilities. $visible = array(); foreach ( $enabled as $key => $action ) { if ( ! empty( $action['capability'] ) && ! current_user_can( $action['capability'] ) ) { continue; } if ( isset( $action['show'] ) && ! $action['show'] ) { continue; } $action['id'] = $key; $visible[ $key ] = $action; } return array_slice( $visible, 0, 12, true ); } /** * Default actions. * * @since 0.1.0 * * @return array> */ public static function registry() { $actions = array( 'new_post' => array( 'label' => __( 'Write a new blog post', 'oms-quietadmin' ), 'desc' => __( 'Upload text and images – done.', 'oms-quietadmin' ), 'icon' => 'dashicons-edit-large', 'url' => admin_url( 'post-new.php' ), 'capability' => 'edit_posts', 'primary' => true, ), 'edit_posts' => array( 'label' => __( 'Edit existing posts', 'oms-quietadmin' ), 'desc' => __( 'All posts at a glance.', 'oms-quietadmin' ), 'icon' => 'dashicons-admin-post', 'url' => admin_url( 'edit.php' ), 'capability' => 'edit_posts', ), 'edit_pages' => array( 'label' => __( 'Change page content', 'oms-quietadmin' ), 'desc' => __( 'Adjust the texts on the home page, services and more.', 'oms-quietadmin' ), 'icon' => 'dashicons-admin-page', 'url' => admin_url( 'edit.php?post_type=page' ), 'capability' => 'edit_pages', ), 'upload_media' => array( 'label' => __( 'Upload gallery / images', 'oms-quietadmin' ), 'desc' => __( 'Drag and drop photos into the media library.', 'oms-quietadmin' ), 'icon' => 'dashicons-images-alt2', 'url' => admin_url( 'upload.php' ), 'capability' => 'upload_files', ), 'contact_data' => array( 'label' => __( 'Change contact details', 'oms-quietadmin' ), 'desc' => __( 'Address, phone, email and opening hours.', 'oms-quietadmin' ), 'icon' => 'dashicons-id-alt', 'url' => '', 'modal' => 'contact_data', 'show' => (bool) apply_filters( 'quietadmin_show_contact_action', true ), ), 'profile' => array( 'label' => __( 'My profile & password', 'oms-quietadmin' ), 'desc' => __( 'Change your name, email address and access.', 'oms-quietadmin' ), 'icon' => 'dashicons-admin-users', 'url' => admin_url( 'profile.php' ), ), 'view_site' => array( 'label' => __( 'View website', 'oms-quietadmin' ), 'desc' => __( 'This is how your visitors see the site.', 'oms-quietadmin' ), 'icon' => 'dashicons-visibility', 'url' => home_url( '/' ), 'target' => '_blank', ), 'support' => array( 'label' => __( 'I need help', 'oms-quietadmin' ), 'desc' => __( 'Send a question or request directly to your agency.', 'oms-quietadmin' ), 'icon' => 'dashicons-sos', 'url' => '', 'modal' => 'support', 'capability' => 'qa_request_support', 'primary' => true, ), ); // Only offer "contact details" if a target is defined. $contact_url = self::contact_data_url(); if ( $contact_url ) { $actions['contact_data']['url'] = $contact_url; $actions['contact_data']['modal'] = ''; } /** * Filters the complete action registry (including unapproved actions). * * @since 0.1.0 * * @param array $actions Actions. */ return apply_filters( 'quietadmin_quick_action_registry', $actions ); } /** * Target URL for "Change contact details". * * Default: a page/CPT with the slug `kontakt`/`contact-data` * or a theme options page. Freely overridable via filter, e.g. * to an ACF options page or a custom form. * * @since 0.1.0 * * @return string */ public static function contact_data_url() { $url = ''; $slugs = array( 'kontakt', 'kontakt-daten', 'contact-data', 'contact' ); foreach ( $slugs as $slug ) { $page = get_page_by_path( $slug ); if ( ! $page instanceof \WP_Post ) { continue; } $link = get_edit_post_link( $page->ID, 'raw' ); if ( $link ) { $url = $link; break; } } // ACF options page (if installed). if ( ! $url && function_exists( 'acf_options_page_exists' ) ) { $url = admin_url( 'admin.php?page=acf-options' ); } /** * Filters the URL of the "contact details" action. * * @since 0.1.0 * * @param string $url Target URL, empty = internal form modal. */ return (string) apply_filters( 'quietadmin_contact_data_url', $url ); } }