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
* @param string $option Option name. * @return int Page id. */ 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' ), true ) ) { 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}%" ) );// no-cache ok. } 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 ) );// no-cache ok. } /** * Filters the ID of the page to be created. * * @since 3.0.0 * * @param int $page_id The WP_Post ID of the page. * @param string $slug The page slug. * @param string $content THe content of the page. */ $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}%" ) );// no-cache ok. } else { $trashed_id = $wpdb->get_var( $wpdb->prepare(
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |