-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* main: feat: log wp admin users into front-end preview mode (#173)
- Loading branch information
Showing
12 changed files
with
177 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
wordpress/wp-content/themes/headless/setup/helpers/dashboard-preview.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
// remove widgets from the dashboard | ||
// add a site links widget | ||
// log WP users into the website front-end so they can view live content | ||
|
||
add_action('wp_dashboard_setup', 'bubs_custom_dashboard_widgets'); | ||
|
||
function bubs_custom_dashboard_widgets() { | ||
global $wp_meta_boxes; | ||
|
||
// remove all | ||
// $wp_meta_boxes['dashboard']['normal']['core'] = array(); | ||
// $wp_meta_boxes['dashboard']['side']['core'] = array(); | ||
|
||
// add our custom one | ||
if (function_exists('build_preview_link')) { | ||
wp_add_dashboard_widget('preview_mode_widget', 'Preview Mode', 'preview_mode_widget'); | ||
} | ||
} | ||
|
||
function preview_mode_widget() { | ||
global $headless_domain; | ||
global $docs_link; | ||
?> | ||
<div> | ||
<p><strong>Site Links</strong></p> | ||
<ul> | ||
<li><a href="<?php echo $headless_domain; ?>">View Site</a></li> | ||
<? echo $docs_link ? '<li><a href="' . $docs_link . '">View Docs</a></li>' : '' ?> | ||
<li><a href="<?php echo build_preview_link(); ?>&path=/" target="_blank">Enable preview mode</a></li> | ||
<li><a href="<?php echo $headless_domain ?>/api/exit-preview" target="_blank">Disable preview mode</a></li> | ||
</ul> | ||
</div> | ||
<? if (function_exists('build_preview_link')) { | ||
echo "<iframe src=\"" . build_preview_link() . "\" style=\"width:1px;height:1px;opacity:0;\"></iframe>"; | ||
}?> | ||
<?php } |
11 changes: 11 additions & 0 deletions
11
wordpress/wp-content/themes/headless/setup/helpers/headless-redirect.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
wordpress/wp-content/themes/headless/setup/helpers/permalinks.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
// This rewrites permalinks so they point to your front-end domain, not the headless WP | ||
function bubs_next_preview_link( $link ) { | ||
global $headless_domain; | ||
|
||
return str_replace( trailingslashit( $headless_domain ), trailingslashit( get_home_url() ), $link ); | ||
} | ||
|
||
function bubs_next_post_link( $link ) { | ||
global $headless_domain; | ||
|
||
if (function_exists('is_graphql_request') && is_graphql_request()) { | ||
return $link; | ||
} elseif ($headless_domain) { | ||
return str_replace( trailingslashit( get_home_url() ), trailingslashit( $headless_domain ), $link ); | ||
} else { | ||
return $link; | ||
} | ||
} | ||
|
||
add_filter( 'page_link', 'bubs_next_post_link' ); | ||
add_filter( 'post_link', 'bubs_next_post_link' ); | ||
add_filter( 'term_link', 'bubs_next_post_link' ); | ||
add_filter( 'post_type_link', 'bubs_next_post_link' ); | ||
add_filter( 'preview_post_link', 'bubs_next_preview_link' ); |