Payments_Tab::create_page_with_shortcode( string $page_slug, string $page_name, string $shortcode_name )
Create a page with given properties.
Contents
Parameters
- $page_slug
-
(string) (Required) URL slug of the page.
- $page_name
-
(string) (Required) Name for page title.
- $shortcode_name
-
(string) (Required) Shortcode name that needs to be inserted in page content.
Return
(int|bool|WP_Error)
Source
File: src/Tickets/Commerce/Payments_Tab.php
public function create_page_with_shortcode( $page_slug, $page_name, $shortcode_name ) {
if ( ! current_user_can( 'edit_pages' ) ) {
return false;
};
$page_data = [
'post_status' => 'publish',
'post_type' => 'page',
'post_author' => get_current_user_id(),
'post_name' => $page_slug,
'post_title' => $page_name,
'post_content' => '<!-- wp:shortcode -->[' . $shortcode_name . ']<!-- /wp:shortcode -->',
'post_parent' => 0,
'comment_status' => 'closed',
'meta_input' => [
static::$option_page_created_meta_key => $shortcode_name,
],
];
return wp_insert_post( $page_data );
}
Changelog
| Version | Description |
|---|---|
| 5.2.1 | Introduced. |