llms_create_page( string $slug, string $title = '', string $content = '', string $option = '' )
Create a Page & save it’s id as an option
Parameters Parameters
- $slug
-
(string) (Required) page slug
- $title
-
(string) (Optional) page title
Default value: ''
- $content
-
(string) (Optional) page content
Default value: ''
- $option
-
(string) (Optional) option name
Default value: ''
Return Return
(int) page id
Source Source
File: includes/admin/llms.functions.admin.php
function llms_create_page( $slug, $title = '', $content = '', $option = '' ) { $option_val = get_option( $option ); // See if there's a valid page already stored for the option we're trying to create. if ( $option_val && is_numeric( $option_val ) ) { $page_object = get_post( $option_val ); if ( $page_object && 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) { return $page_object->ID; } } global $wpdb; // Search for an existing page with the specified page content like a shortcode. if ( strlen( $content ) > 0 ) { $page_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$content}%" ) ); } else { $page_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug ) ); } $page_id = apply_filters( 'llms_create_page_id', $page_id, $slug, $content ); if ( $page_id ) { if ( $option ) { update_option( $option, $page_id ); } return $page_id; } // Look in the trashed page by content. if ( strlen( $content ) > 0 ) { $trashed_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$content}%" ) ); } else { $trashed_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) ); } // If we find it in the trash move it out of the trash. if ( $trashed_id ) { $page_id = $trashed_id; $page_data = array( 'ID' => $page_id, 'post_status' => 'publish', ); wp_update_post( $page_data ); } else { $page_data = array( 'post_status' => 'publish', 'post_type' => 'page', 'post_author' => get_current_user_id() ? get_current_user_id() : 1, 'post_name' => $slug, 'post_title' => $title, 'post_content' => $content, 'comment_status' => 'closed', ); $page_id = wp_insert_post( apply_filters( 'llms_create_page', $page_data ) ); } if ( $option ) { update_option( $option, $page_id ); } return $page_id; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |