LLMS_Forms_Admin_Bar

Add WP Admin Bar Nodes to enable editing of the currently-viewed form by a qualifying user


Source Source

File: includes/forms/class-llms-forms-admin-bar.php

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
class LLMS_Forms_Admin_Bar {
 
    /**
     * Constructor
     *
     * @since 5.0.0
     *
     * @return void
     */
    public function __construct() {
 
        add_action( 'admin_bar_menu', array( $this, 'add_menu_items' ), 999 );
 
    }
 
    /**
     * Add view links to the admin menu bar for qualifying users.
     *
     * @since 3.7.0
     * @since 3.16.0 Unknown.
     * @since 4.2.0 Updated icon.
     * @since 4.5.1 Use `should_display()` method to determine if the view manager should be added to the admin bar.
     * @since 4.16.0 Retrieve nodes to add from `get_menu_items_to_add()`.
     *
     * @param WP_Admin_Bar $wp_admin_bar Admin bar class instance.
     * @return void
     */
    public function add_menu_items( $wp_admin_bar ) {
 
        if ( ! $this->should_display() ) {
            return;
        }
 
        $args = array( $this->get_current_location() );
        $plan = llms_filter_input( INPUT_GET, 'plan', FILTER_SANITIZE_NUMBER_INT );
        if ( $plan ) {
            $args[] = array( 'plan' => llms_get_post( $plan ) );
        }
        $form = llms_get_form( ...$args );
 
        $wp_admin_bar->add_node(
            array(
                'id'     => 'llms-edit-form',
                'parent' => 'edit',
                'title'  => __( 'Edit Form', 'lifterlms' ),
                'href'   => get_edit_post_link( $form->ID ),
            )
        );
 
    }
 
    /**
     * Retrieve the form location for the current screen
     *
     * Must be on a checkout screen, the "edit account" tab of the dashboard,
     * or be viewing as a visitor on the main dashboard page with open registration enabled.
     *
     * @since 5.0.0
     *
     * @return string|boolean Returns the location id as a string or `false` if not on a form location screen.
     */
    private function get_current_location() {
 
        if ( is_llms_checkout() ) {
 
            return 'checkout';
 
        } elseif ( is_llms_account_page() ) {
 
            $tab = LLMS_Student_Dashboard::get_current_tab( 'tab' );
 
            if ( 'edit-account' === $tab ) {
                return 'account';
            }
 
            if ( 'dashboard' === $tab && 'visitor' === llms_filter_input( INPUT_GET, 'llms-view-as' ) && llms_parse_bool( llms_get_open_registration_status() ) ) {
                return 'registration';
 
            }
        }
 
        return false;
 
    }
 
    /**
     * Determine whether or an Edit Form node should be added to the admin bar.
     *
     * The user must be able to edit forms and be on a screen with a displayed form.
     *
     * @return boolean
     */
    private function should_display() {
 
        $display = ( current_user_can( LLMS_Forms::instance()->get_capability() ) && $this->get_current_location() );
 
        /**
         * Filters whether or not the "Edit Form" WP_Admin_Bar node is displayed
         *
         * @since 5.0.0
         *
         * @param boolean $display Whether or not to display the node.
         */
        return apply_filters( 'llms_should_display_wp_admin_bar_nodes_for_forms', $display );
 
    }
 
}

Top ↑

Methods Methods


Top ↑

Changelog Changelog

Changelog
Version Description
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.