Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get actual site screenshot #170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions includes/class-boldgrid-inspirations-deploy-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,32 @@ public function __construct( $configs ) {
$this->configs = $configs;
}

/**
* Get Screenshot.
*
* @param array $args
*/
public function get_screenshot( $args ) {
$api_url = $this->configs['asset_server'] . $this->configs['ajax_calls']['get_screenshot'];

$remote_post_args = array(
'method' => 'POST',
'body' => $args,
'timeout' => 20,
);

$response = wp_remote_retrieve_body( wp_remote_post( $api_url, $remote_post_args ) );
$response = json_decode( $response ? $response : '', true );

if ( $response && ! empty( $response['result']['data']['asset_id'] ) ) {
$asset_id = $response['result']['data']['asset_id'];
$key = get_option( 'boldgrid_api_key' );
$url = $this->configs['asset_server'] . '/api/asset/get?key=' . $key . '&id=' . $asset_id;

update_option( 'boldgrid_site_screenshot', $url );
}
}

/**
* Get install options.
*
Expand Down
19 changes: 19 additions & 0 deletions includes/class-boldgrid-inspirations-deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,25 @@ public function finish_deployment() {
* may have added a Crio Premium service for the user. Delete license data so it can be refreshed.
*/
Boldgrid_Inspirations_Update::delete_license();

// Get a screenshot of the new site.
$this->get_screenshot();
}

/**
* Get the screenshot.
*/
public function get_screenshot() {
$site_url = get_site_url();

$api_key_hash = $this->asset_manager->api->get_api_key_hash();

$args = array(
'site_url' => $site_url,
'key' => $api_key_hash,
);

$this->api->get_screenshot( $args );
}

/**
Expand Down
8 changes: 6 additions & 2 deletions includes/class-boldgrid-inspirations-my-inspiration.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,13 @@ public function box_support() {
* @since 1.7.0
*/
public function box_theme() {
$theme = wp_get_theme(); ?>
$theme = wp_get_theme();
$screenshot_url = get_option( 'boldgrid_site_screenshot', $theme->get_screenshot() );
?>



<p><img src="<?php echo esc_url( $theme->get_screenshot() ); ?>" style="max-width:100%; border:1px solid #ddd;" /></p>
<p><img src="<?php echo esc_url( $screenshot_url ); ?>" style="max-width:100%; border:1px solid #ddd;" /></p>

<?php }

Expand Down
1 change: 1 addition & 0 deletions includes/config/config.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
'get_install_details' => '/api/build/get-install-details',
'get_build_profile_using_in_progress_theme' => '/api/build/get-using-in-progress-theme',
'get_generic' => '/api/build/get-generic',
'get_screenshot' => '/api/build/get-screenshot',
// Pde.
'get_curated' => '/api/pde/get-curated-asset',
// Theme.
Expand Down