| @@ -1,13 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor\Core\Common\Modules\Connect; |
| 3 | 3 | |
| 4 | -use Elementor\Core\Admin\Menu\Admin_Menu_Manager; | |
| 5 | 4 | use Elementor\Plugin; |
| 6 | 5 | use Elementor\Settings; |
| 7 | -use Elementor\Utils; | |
| 8 | -use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider; | |
| 9 | -use Elementor\Core\Common\Modules\Connect\AdminMenuItems\Editor_One_Connect_Menu; | |
| 10 | 6 | |
| 11 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | 8 | exit; // Exit if accessed directly. |
| 13 | 9 | } |
| @@ -17,34 +13,31 @@ | ||
| 17 | 13 | const PAGE_ID = 'elementor-connect'; |
| 18 | 14 | |
| 19 | 15 | public static $url = ''; |
| 20 | 16 | |
| 21 | - private function get_valid_redirect_to_from_request() { | |
| 22 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Only reading a URL parameter. | |
| 23 | - $raw = Utils::get_super_global_value( $_GET, 'redirect_to' ); | |
| 17 | + /** | |
| 18 | + * @since 2.3.0 | |
| 19 | + * @access public | |
| 20 | + */ | |
| 21 | + public function register_admin_menu() { | |
| 22 | + $submenu_page = add_submenu_page( | |
| 23 | + Settings::PAGE_ID, | |
| 24 | + __( 'Connect', 'elementor' ), | |
| 25 | + __( 'Connect', 'elementor' ), | |
| 26 | + 'edit_posts', | |
| 27 | + self::PAGE_ID, | |
| 28 | + [ $this, 'render_page' ] | |
| 29 | + ); | |
| 24 | 30 | |
| 25 | - if ( ! $raw ) { | |
| 26 | - return ''; | |
| 27 | - } | |
| 28 | - | |
| 29 | - $raw = esc_url_raw( $raw ); | |
| 30 | - | |
| 31 | - $validated = wp_validate_redirect( $raw, '' ); | |
| 32 | - if ( ! $validated ) { | |
| 33 | - return ''; | |
| 34 | - } | |
| 35 | - | |
| 36 | - $admin_host = wp_parse_url( admin_url(), PHP_URL_HOST ); | |
| 37 | - $dest_host = wp_parse_url( $validated, PHP_URL_HOST ); | |
| 38 | - if ( $dest_host && $admin_host && ! hash_equals( $admin_host, $dest_host ) ) { | |
| 39 | - return ''; | |
| 40 | - } | |
| 41 | - | |
| 42 | - return $validated; | |
| 31 | + add_action( 'load-' . $submenu_page, [ $this, 'on_load_page' ] ); | |
| 43 | 32 | } |
| 44 | 33 | |
| 45 | - public function register_editor_one_menu( Menu_Data_Provider $menu_data_provider ) { | |
| 46 | - $menu_data_provider->register_menu( new Editor_One_Connect_Menu() ); | |
| 34 | + /** | |
| 35 | + * @since 2.3.0 | |
| 36 | + * @access public | |
| 37 | + */ | |
| 38 | + public function hide_menu_item() { | |
| 39 | + remove_submenu_page( Settings::PAGE_ID, self::PAGE_ID ); | |
| 47 | 40 | } |
| 48 | 41 | |
| 49 | 42 | /** |
| 50 | 43 | * @since 2.3.0 |
| @@ -50,43 +43,25 @@ | ||
| 50 | 43 | * @since 2.3.0 |
| 51 | 44 | * @access public |
| 52 | 45 | */ |
| 53 | 46 | public function on_load_page() { |
| 54 | - if ( ! $this->user_has_enough_permissions() ) { | |
| 55 | - wp_die( 'You do not have sufficient permissions to access this page.', 'You do not have sufficient permissions to access this page.', [ | |
| 56 | - 'back_link' => true, | |
| 57 | - ] ); | |
| 58 | - } | |
| 59 | - | |
| 60 | - // Allow a per-request default landing URL when provided via a safe `redirect_to` parameter. | |
| 61 | - $maybe_redirect_to = $this->get_valid_redirect_to_from_request(); | |
| 62 | - if ( $maybe_redirect_to ) { | |
| 63 | - self::$url = $maybe_redirect_to; | |
| 64 | - } | |
| 65 | - | |
| 66 | 47 | if ( isset( $_GET['action'], $_GET['app'] ) ) { |
| 67 | 48 | $manager = Plugin::$instance->common->get_component( 'connect' ); |
| 68 | - | |
| 69 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 70 | - $app_slug = Utils::get_super_global_value( $_GET, 'app' ); | |
| 49 | + $app_slug = $_GET['app']; | |
| 71 | 50 | $app = $manager->get_app( $app_slug ); |
| 51 | + $nonce_action = $_GET['app'] . $_GET['action']; | |
| 72 | 52 | |
| 73 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 74 | - $action = Utils::get_super_global_value( $_GET, 'action' ); | |
| 75 | - | |
| 76 | - $nonce_action = $app_slug . $action; | |
| 77 | - | |
| 78 | 53 | if ( ! $app ) { |
| 79 | 54 | wp_die( 'Unknown app: ' . esc_attr( $app_slug ) ); |
| 80 | 55 | } |
| 81 | 56 | |
| 82 | - if ( ! wp_verify_nonce( Utils::get_super_global_value( $_GET, 'nonce' ), $nonce_action ) ) { | |
| 57 | + if ( empty( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'], $nonce_action ) ) { | |
| 83 | 58 | wp_die( 'Invalid Nonce', 'Invalid Nonce', [ |
| 84 | 59 | 'back_link' => true, |
| 85 | 60 | ] ); |
| 86 | 61 | } |
| 87 | 62 | |
| 88 | - $method = 'action_' . $action; | |
| 63 | + $method = 'action_' . $_GET['action']; | |
| 89 | 64 | |
| 90 | 65 | if ( method_exists( $app, $method ) ) { |
| 91 | 66 | call_user_func( [ $app, $method ] ); |
| 92 | 67 | } |
| @@ -92,18 +67,34 @@ | ||
| 92 | 67 | } |
| 93 | 68 | } |
| 94 | 69 | } |
| 95 | 70 | |
| 96 | - private function user_has_enough_permissions() { | |
| 97 | - if ( current_user_can( 'manage_options' ) ) { | |
| 98 | - return true; | |
| 99 | - } | |
| 71 | + /** | |
| 72 | + * @since 2.3.0 | |
| 73 | + * @access public | |
| 74 | + */ | |
| 75 | + public function render_page() { | |
| 76 | + $apps = Plugin::$instance->common->get_component( 'connect' )->get_apps(); | |
| 77 | + ?> | |
| 78 | + <style> | |
| 79 | + .elementor-connect-app-wrapper{ | |
| 80 | + margin-bottom: 50px; | |
| 81 | + overflow: hidden; | |
| 82 | + } | |
| 83 | + </style> | |
| 84 | + <div class="wrap"> | |
| 85 | + <?php | |
| 100 | 86 | |
| 101 | - if ( 'library' === Utils::get_super_global_value( $_GET, 'app' ) ) { | |
| 102 | - return current_user_can( 'edit_posts' ); | |
| 103 | - } | |
| 87 | + /** @var \Elementor\Core\Common\Modules\Connect\Apps\Base_App $app */ | |
| 88 | + foreach ( $apps as $app ) { | |
| 89 | + echo '<div class="elementor-connect-app-wrapper">'; | |
| 90 | + $app->render_admin_widget(); | |
| 91 | + echo '</div>'; | |
| 92 | + } | |
| 104 | 93 | |
| 105 | - return false; | |
| 94 | + ?> | |
| 95 | + </div><!-- /.wrap --> | |
| 96 | + <?php | |
| 106 | 97 | } |
| 107 | 98 | |
| 108 | 99 | /** |
| 109 | 100 | * @since 2.3.0 |
| @@ -111,13 +102,8 @@ | ||
| 111 | 102 | */ |
| 112 | 103 | public function __construct() { |
| 113 | 104 | self::$url = admin_url( 'admin.php?page=' . self::PAGE_ID ); |
| 114 | 105 | |
| 115 | - add_action( 'elementor/editor-one/menu/register', [ $this, 'register_editor_one_menu' ] ); | |
| 116 | - | |
| 117 | - add_action( 'elementor/editor-one/menu/after_register_hidden_submenus', function ( array $hooks ) { | |
| 118 | - if ( ! empty( $hooks[ static::PAGE_ID ] ) ) { | |
| 119 | - add_action( 'load-' . $hooks[ static::PAGE_ID ], [ $this, 'on_load_page' ] ); | |
| 120 | - } | |
| 121 | - } ); | |
| 106 | + add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 206 ); | |
| 107 | + add_action( 'admin_head', [ $this, 'hide_menu_item' ] ); | |
| 122 | 108 | } |
| 123 | 109 | } |