Astra_Addon_Theme_Builder::get_custom_layouts( WP_REST_Request $request )
Get Custom Layouts.
Description
Parameters
- $request
-
(WP_REST_Request) (Required) Full details about the request.
Return
(array) $updated_option defaults + set DB option data.
Source
File: addons/advanced-hooks/classes/class-astra-addon-theme-builder.php
public function get_custom_layouts( $request ) {
$custom_layouts = new WP_Query(
array(
'post_type' => 'astra-advanced-hook',
'orderby' => 'ID',
'post_status' => array( 'publish', 'draft', 'private', 'pending', 'future' ),
'posts_per_page' => -1,
)
);
$results = array();
foreach ( $custom_layouts->posts as $post ) {
// Get the author information for each post
$author_id = $post->post_author;
$author = get_userdata( $author_id );
// Get the author's avatar URL
$author_avatar_url = get_avatar_url( $author_id );
// Get the post link
$post_link = get_permalink( $post->ID );
// Generate the edit link manually
$edit_post_link = admin_url( 'post.php?post=' . $post->ID . '&action=edit' );
// Get the post preview link
$post_preview_link = get_preview_post_link( $post );
// Get the custom field values
$layout_value = get_post_meta( $post->ID, 'ast-advanced-hook-layout', true );
$template_type = get_post_meta( $post->ID, 'ast-advanced-hook-template-type', true );
$is_enabled = get_post_meta( $post->ID, 'ast-advanced-hook-enabled', 'yes' );
// Get the post preview link if type is template.
$post_preview_link = $this->get_template_preview_link( $post, $post_preview_link, $layout_value, $template_type );
$layout_data = array(
'ID' => $post->ID,
'post_author' => $post->post_author,
'post_title' => $post->post_title,
'author_name' => $author->display_name,
'author_image' => $author_avatar_url,
'post_modified' => date( 'Y-m-d', strtotime( $post->post_modified ) ),
'post_name' => $post->post_name,
'post_status' => $post->post_status,
'post_link' => $post_preview_link,
'edit_post_link' => $edit_post_link,
'layout_value' => $layout_value,
'template_type' => $template_type,
'enabled' => $is_enabled,
);
$results[] = $layout_data;
}
return $results;
}
Expand full source code Collapse full source code View on Trac
Changelog
| Version | Description |
|---|---|
| 4.5.0 | Introduced. |