| 1 |
<?php |
| 2 |
/** |
| 3 |
* Settings Page Controller Class. |
| 4 |
* |
| 5 |
* @package ContentControl |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace ContentControl\Controllers\Admin; |
| 9 |
|
| 10 |
use ContentControl\Base\Controller; |
| 11 |
|
| 12 |
defined( 'ABSPATH' ) || exit; |
| 13 |
|
| 14 |
/** |
| 15 |
* Settings Page Controller. |
| 16 |
* |
| 17 |
* @package ContentControl\Admin |
| 18 |
*/ |
| 19 |
class SettingsPage extends Controller { |
| 20 |
|
| 21 |
/** |
| 22 |
* Initialize the settings page. |
| 23 |
*/ |
| 24 |
public function init() { |
| 25 |
add_action( 'admin_menu', [ $this, 'register_page' ], 999 ); |
| 26 |
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); |
| 27 |
// These are here to listen for incoming webhooks from the Upgrader service when user chooses to install Pro. |
| 28 |
add_action( 'wp_ajax_content_control_connect_verify_connection', [ $this, 'process_verify_connection' ] ); |
| 29 |
add_action( 'wp_ajax_nopriv_content_control_connect_verify_connection', [ $this, 'process_verify_connection' ] ); |
| 30 |
add_action( 'wp_ajax_content_control_connect_webhook', [ $this, 'process_webhook' ] ); |
| 31 |
add_action( 'wp_ajax_nopriv_content_control_connect_webhook', [ $this, 'process_webhook' ] ); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Register admin options pages. |
| 36 |
* |
| 37 |
* @return void |
| 38 |
*/ |
| 39 |
public function register_page() { |
| 40 |
add_options_page( |
| 41 |
__( 'Content Control', 'content-control' ), |
| 42 |
__( 'Content Control', 'content-control' ), |
| 43 |
'manage_options', |
| 44 |
'content-control-settings', |
| 45 |
[ $this, 'render_page' ] |
| 46 |
); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Render settings page title & container. |
| 51 |
* |
| 52 |
* @return void |
| 53 |
*/ |
| 54 |
public function render_page() { |
| 55 |
?> |
| 56 |
<div id="content-control-root-container"></div> |
| 57 |
<script>jQuery(() => window.contentControl.settingsPage.init());</script> |
| 58 |
<?php |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Enqueue assets for the settings page. |
| 63 |
* |
| 64 |
* @param string $hook Page hook name. |
| 65 |
* |
| 66 |
* @return void |
| 67 |
*/ |
| 68 |
public function enqueue_scripts( $hook ) { |
| 69 |
if ( 'settings_page_content-control-settings' !== $hook ) { |
| 70 |
return; |
| 71 |
} |
| 72 |
|
| 73 |
wp_enqueue_editor(); |
| 74 |
wp_tinymce_inline_scripts(); |
| 75 |
|
| 76 |
wp_enqueue_script( 'content-control-settings-page' ); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Verify the connection. |
| 81 |
* |
| 82 |
* @return void |
| 83 |
*/ |
| 84 |
public function process_verify_connection() { |
| 85 |
$this->container->get( 'connect' )->process_verify_connection(); |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Listen for incoming secure webhooks from the API server. |
| 90 |
* |
| 91 |
* @return void |
| 92 |
*/ |
| 93 |
public function process_webhook() { |
| 94 |
$this->container->get( 'connect' )->process_webhook(); |
| 95 |
} |
| 96 |
} |
| 97 |
|