LLMS_Admin_Post_Types

Admin Post Types.


Description Description

Sets up post type custom messages and includes base metabox class.


Top ↑

Source Source

File: includes/admin/class.llms.admin.post-types.php

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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
class LLMS_Admin_Post_Types {
 
    /**
     * Constructor
     *
     * Adds functions to actions and sets filter on post_updated_messages.
     *
     * @since Unknown
     * @since 6.0.0 Disable the block editor for legacy certificates.
     *
     * @return void
     */
    public function __construct() {
 
        add_action( 'use_block_editor_for_post', array( $this, 'use_block_editor_for_post' ), 20, 2 );
 
        add_action( 'admin_init', array( $this, 'include_post_type_metabox_class' ) );
 
        add_filter( 'post_updated_messages', array( $this, 'llms_post_updated_messages' ) );
 
    }
 
    /**
     * Admin Menu
     *
     * Includes base metabox class
     *
     * @return void
     */
    public function include_post_type_metabox_class() {
        include 'post-types/class.llms.meta.boxes.php';
    }
 
    /**
     * Disables the block editor for legacy certificates.
     *
     * @since 6.0.0
     *
     * @param boolean $use_block_editor Whether or not to use the block editor.
     * @param WP_Post $post             Post object.
     * @return boolean
     */
    public function use_block_editor_for_post( $use_block_editor, $post ) {
        $cert = llms_get_certificate( $post, true );
        if ( $cert && 1 === $cert->get_template_version() ) {
            $use_block_editor = false;
        }
 
        return $use_block_editor;
 
    }
 
    /**
     * Initializes core for metaboxes.
     *
     * @since Unknown
     * @deprecated 6.0.0 `LLMS_Admin_Post_Types::meta_metabox_init()` is deprecated with no replacement.
     *
     * @return void
     */
    public function meta_metabox_init() {
 
        llms_deprecated_function( __METHOD__, '6.0.0' );
 
        include_once 'llms.class.admin.metabox.php';
    }
 
    /**
     * Customize post type messages.
     *
     * @since Unknown.
     * @since 3.35.0 Fix l10n calls.
     * @since 4.7.0 Added `publicly_queryable` check for permalink and preview.
     * @since 6.0.0 Handle `llms_my_certificate` and `llms_my_achievement` post types.
     * @since 6.7.0 Fixed too few arguments passed to sprintf, when building restore from revision message.
     *
     * @return array $messages Post updated messages.
     */
    public function llms_post_updated_messages( $messages ) {
 
        global $post;
 
        $llms_post_types = array(
            'course',
            'section',
            'lesson',
            'llms_order',
            'llms_email',
            'llms_email',
            'llms_certificate',
            'llms_my_certificate',
            'llms_achievement',
            'llms_my_achievement',
            'llms_engagement',
            'llms_quiz',
            'llms_question',
            'llms_coupon',
        );
 
        foreach ( $llms_post_types as $type ) {
 
            $obj  = get_post_type_object( $type );
            $name = $obj->labels->singular_name;
 
            $permalink_html    = '';
            $preview_link_html = '';
 
            if ( $obj->publicly_queryable ) {
 
                $permalink    = get_permalink( $post->ID );
                $preview_link = add_query_arg( 'preview', 'true', $permalink );
 
                $link_format = ' <a href="%1$s">%2$s</a>.';
 
                $permalink_html    = sprintf( $link_format, $permalink, sprintf( __( 'View %s', 'lifterlms' ), $name ) );
                $preview_link_html = sprintf( $link_format, $permalink, sprintf( __( 'Preview %s', 'lifterlms' ), $name ) );
            }
 
            $messages[ $type ] = array(
                0  => '',
                1  => sprintf( __( '%s updated.', 'lifterlms' ), $name ) . $permalink_html,
                2  => __( 'Custom field updated.', 'lifterlms' ),
                3  => __( 'Custom field deleted.', 'lifterlms' ),
                4  => sprintf( __( '%s updated.', 'lifterlms' ), $name ),
                5  => isset( $_GET['revision'] ) ? // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No need to verify the nonce here.
                    sprintf(
                        __( '%1$s restored to revision from %2$s.', 'lifterlms' ),
                        $name,
                        wp_post_revision_title( llms_filter_input( INPUT_GET, 'revision', FILTER_SANITIZE_NUMBER_INT ), false )
                    )
                    :
                    false,
                6  => sprintf( __( '%s published.', 'lifterlms' ), $name ) . $permalink_html,
                7  => sprintf( __( '%s saved.', 'lifterlms' ), $name ),
                8  => sprintf( __( '%s submitted.', 'lifterlms' ), $name ) . $preview_link_html,
                9  => sprintf(
                    __( '%1$s scheduled for: <strong>%2$s</strong>.', 'lifterlms' ),
                    $name,
                    date_i18n( __( 'M j, Y @ G:i', 'lifterlms' ), strtotime( $post->post_date ) )
                ) . $preview_link_html,
                10 => sprintf( __( '%1$s draft updated.', 'lifterlms' ), $name ) . $preview_link_html,
            );
 
        }
 
        return $messages;
    }
 
}

Top ↑

Methods Methods


Top ↑

Changelog Changelog

Changelog
Version Description
6.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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