| 1 |
<?php |
| 2 |
/** |
| 3 |
* TrustedLogin. |
| 4 |
* |
| 5 |
* @copyright (c) 2023, Code Atlantic LLC. |
| 6 |
* |
| 7 |
* @package ContentControl |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace ContentControl\Controllers; |
| 11 |
|
| 12 |
use ContentControl\Base\Controller; |
| 13 |
use ContentControl\Vendor\TrustedLogin\Client; |
| 14 |
use ContentControl\Vendor\TrustedLogin\Config; |
| 15 |
|
| 16 |
defined( 'ABSPATH' ) || exit; |
| 17 |
|
| 18 |
/** |
| 19 |
* TrustedLogin. |
| 20 |
* |
| 21 |
* @package ContentControl |
| 22 |
*/ |
| 23 |
class TrustedLogin extends Controller { |
| 24 |
|
| 25 |
/** |
| 26 |
* TrustedLogin init. |
| 27 |
*/ |
| 28 |
public function init() { |
| 29 |
add_action( 'admin_menu', [ $this, 'admin_menu' ] ); |
| 30 |
add_action( 'init', [ $this, 'initiate_trustedlogin' ] ); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Hooks. |
| 35 |
* |
| 36 |
* @return void |
| 37 |
*/ |
| 38 |
public function initiate_trustedlogin() { |
| 39 |
$license = $this->container->get( 'license' ); |
| 40 |
$license_key = is_object( $license ) && method_exists( $license, 'get_license_key' ) |
| 41 |
? $license->get_license_key() |
| 42 |
: ''; |
| 43 |
|
| 44 |
$config = [ |
| 45 |
'auth' => [ |
| 46 |
'api_key' => 'f97f5be6e02d1565', |
| 47 |
'license_key' => $license_key, |
| 48 |
], |
| 49 |
'vendor' => [ |
| 50 |
'namespace' => 'content-control', |
| 51 |
'title' => 'Content Control', |
| 52 |
'display_name' => 'Content Control Support', |
| 53 |
'logo_url' => $this->container->get_url( 'assets/images/logo.svg' ), |
| 54 |
'email' => 'support+{hash}@contentcontrolplugin.com', |
| 55 |
'website' => 'https://contentcontrolplugin.com?utm_campaign=grant-access&utm_source=plugin-settings-page&utm_medium=plugin-ui&utm_content=grant-access-title-link', |
| 56 |
'support_url' => 'https://contentcontrolplugin.com/support/?utm_campaign=grant-access&utm_source=plugin-settings-page&utm_medium=plugin-ui&utm_content=support-footer-link', |
| 57 |
], |
| 58 |
'role' => 'administrator', |
| 59 |
'caps' => [ |
| 60 |
'add' => [ |
| 61 |
$this->container->get_permission( 'manage_settings' ) => __( 'This allows us to check your global restrictions and plugin settings.', 'content-control' ), |
| 62 |
$this->container->get_permission( 'edit_block_controls' ) => __( 'This allows us to check your block control settings.', 'content-control' ), |
| 63 |
], |
| 64 |
'remove' => [ |
| 65 |
'delete_published_pages' => 'Your published posts cannot and will not be deleted by support staff', |
| 66 |
'manage_woocommerce' => 'We don\'t need to manage your shop!', |
| 67 |
], |
| 68 |
], |
| 69 |
'decay' => WEEK_IN_SECONDS, |
| 70 |
'menu' => [ |
| 71 |
'slug' => false, |
| 72 |
], |
| 73 |
'logging' => [ |
| 74 |
'enabled' => false, |
| 75 |
], |
| 76 |
'require_ssl' => false, |
| 77 |
'webhook' => [ |
| 78 |
'url' => null, |
| 79 |
'debug_data' => false, |
| 80 |
'create_ticket' => false, |
| 81 |
], |
| 82 |
'paths' => [ |
| 83 |
'js' => $this->container->get_url( 'vendor-prefixed/trustedlogin/client/src/assets/trustedlogin.js' ), |
| 84 |
'css' => $this->container->get_url( 'dist/settings-page.css' ), |
| 85 |
], |
| 86 |
]; |
| 87 |
|
| 88 |
try { |
| 89 |
new Client( |
| 90 |
new Config( $config ) |
| 91 |
); |
| 92 |
} catch ( \Exception $exception ) { |
| 93 |
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log |
| 94 |
\error_log( $exception->getMessage() ); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* Admin menu. |
| 100 |
* |
| 101 |
* @return void |
| 102 |
*/ |
| 103 |
public function admin_menu() { |
| 104 |
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only routing check. |
| 105 |
if ( ! isset( $_GET['page'] ) || ! is_string( $_GET['page'] ) || 'grant-content-control-access' !== sanitize_key( wp_unslash( $_GET['page'] ) ) ) { |
| 106 |
return; |
| 107 |
} |
| 108 |
// phpcs:enable WordPress.Security.NonceVerification.Recommended |
| 109 |
|
| 110 |
add_options_page( |
| 111 |
__( 'Content Control Support Access', 'content-control' ), |
| 112 |
__( 'Content Control Support Access', 'content-control' ), |
| 113 |
$this->container->get_permission( 'manage_settings' ), |
| 114 |
'grant-content-control-access', |
| 115 |
function () { |
| 116 |
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
| 117 |
do_action( 'trustedlogin/content-control/auth_screen' ); |
| 118 |
} |
| 119 |
); |
| 120 |
} |
| 121 |
} |
| 122 |
|