| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\Ai\SitePlannerConnect; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; // Exit if accessed directly. |
| 7 |
} |
| 8 |
|
| 9 |
class Module { |
| 10 |
const NOT_TRANSLATED_APP_NAME = 'Site Planner'; |
| 11 |
const PLANNER_ORIGIN = 'https://planner.elementor.com'; |
| 12 |
const HIDDEN_PAGE_SLUG = ''; |
| 13 |
|
| 14 |
public function __construct() { |
| 15 |
add_action( 'rest_api_init', [ $this, 'on_rest_init' ] ); |
| 16 |
add_action( 'admin_menu', [ $this, 'register_menu_page' ], 100 ); |
| 17 |
add_filter( 'rest_prepare_application_password', function ( $response, $item, $request ) { |
| 18 |
if ( '/wp/v2/users/me/application-passwords' === $request->get_route() && is_user_logged_in() ) { |
| 19 |
$user = wp_get_current_user(); |
| 20 |
$response->data['user_login'] = $user->user_login; |
| 21 |
} |
| 22 |
return $response; |
| 23 |
}, 10, 3 ); |
| 24 |
} |
| 25 |
|
| 26 |
public function on_rest_init(): void { |
| 27 |
( new Wp_Rest_Api() )->register(); |
| 28 |
} |
| 29 |
|
| 30 |
public function register_menu_page() { |
| 31 |
add_submenu_page( |
| 32 |
self::HIDDEN_PAGE_SLUG, |
| 33 |
'App Password Generator', |
| 34 |
'App Password', |
| 35 |
'manage_options', |
| 36 |
'e-site-planner-password-generator', |
| 37 |
[ $this, 'render_menu_page' ] |
| 38 |
); |
| 39 |
} |
| 40 |
|
| 41 |
public function render_menu_page() { |
| 42 |
ob_start(); |
| 43 |
require_once __DIR__ . '/view.php'; |
| 44 |
$content = ob_get_clean(); |
| 45 |
$vars = [ |
| 46 |
'%app_name%' => self::NOT_TRANSLATED_APP_NAME, |
| 47 |
'%safe_origin%' => esc_url( self::PLANNER_ORIGIN ), |
| 48 |
'%domain%' => isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : '', |
| 49 |
'%title%' => esc_html__( 'Connect to Site Planner', 'elementor' ), |
| 50 |
'%description%' => esc_html__( 'To connect your site to Site Planner, you need to generate an app password.', 'elementor' ), |
| 51 |
'%cta%' => esc_html__( 'Approve & Connect', 'elementor' ), |
| 52 |
]; |
| 53 |
|
| 54 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 55 |
echo strtr( $content, $vars ); |
| 56 |
} |
| 57 |
} |
| 58 |
|