-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d7c46e
commit fa87abf
Showing
6 changed files
with
109 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace OWC\OpenPub\Base\Admin; | ||
|
||
use OWC\OpenPub\Base\Foundation\ServiceProvider; | ||
use OWC\OpenPub\Base\Models\Item; | ||
|
||
class AdminServiceProvider extends ServiceProvider | ||
{ | ||
public function register() | ||
{ | ||
$this->plugin->loader->addAction('preview_post_link', $this, 'filterPostLink', 10, 10, 2); | ||
$this->plugin->loader->addAction('rest_prepare_pdc-item', $this, 'restPrepareResponseLink', 10, 2); | ||
} | ||
|
||
/** | ||
* Changes the url user for live preview to the portal url. | ||
* Works in the old editor (not gutenberg) | ||
*/ | ||
public function filterPostLink($link, \WP_Post $post): string | ||
{ | ||
$itemModel = Item::makeFrom($post); | ||
$url = $itemModel->getPortalURL(); | ||
return $url . "?preview=true"; | ||
} | ||
|
||
/** | ||
* Changes the url used for live preview to the portal url. | ||
* Works in the gutenberg editor. | ||
*/ | ||
public function restPrepareResponseLink(\WP_REST_Response $response, \WP_Post $post): \WP_REST_Response | ||
{ | ||
$itemModel = Item::makeFrom($post); | ||
$response->data['link'] = $itemModel->getPortalURL() ?? ''; | ||
|
||
return $response; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace OWC\OpenPub\Base\Varnish; | ||
|
||
use OWC\OpenPub\Base\Foundation\ServiceProvider; | ||
|
||
class VarnishServiceProvider extends ServiceProvider | ||
{ | ||
public function register(): void | ||
{ | ||
$this->plugin->loader->addAction('save_post', $this, 'purgeVarnishCache', 10, 2); | ||
} | ||
|
||
public function purgeVarnishCache(int $postID, \WP_Post $post): void | ||
{ | ||
if ( ! function_exists('curl_init')){ | ||
return; | ||
} | ||
|
||
$ch = curl_init(); | ||
|
||
curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1/.*'); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PURGE'); | ||
|
||
$headers = []; | ||
$headers[] = 'Host: '. \parse_url(get_site_url(), PHP_URL_HOST); | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | ||
|
||
curl_exec($ch); | ||
curl_close($ch); | ||
} | ||
} |