admin.php (2310B)
1 <?php 2 namespace Elementor\Core\Common\Modules\Connect; 3 4 use Elementor\Plugin; 5 use Elementor\Settings; 6 7 if ( ! defined( 'ABSPATH' ) ) { 8 exit; // Exit if accessed directly. 9 } 10 11 class Admin { 12 13 const PAGE_ID = 'elementor-connect'; 14 15 public static $url = ''; 16 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 ); 30 31 add_action( 'load-' . $submenu_page, [ $this, 'on_load_page' ] ); 32 } 33 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 ); 40 } 41 42 /** 43 * @since 2.3.0 44 * @access public 45 */ 46 public function on_load_page() { 47 if ( isset( $_GET['action'], $_GET['app'] ) ) { 48 $manager = Plugin::$instance->common->get_component( 'connect' ); 49 $app_slug = $_GET['app']; 50 $app = $manager->get_app( $app_slug ); 51 $nonce_action = $_GET['app'] . $_GET['action']; 52 53 if ( ! $app ) { 54 wp_die( 'Unknown app: ' . esc_attr( $app_slug ) ); 55 } 56 57 if ( empty( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'], $nonce_action ) ) { 58 wp_die( 'Invalid Nonce', 'Invalid Nonce', [ 59 'back_link' => true, 60 ] ); 61 } 62 63 $method = 'action_' . $_GET['action']; 64 65 if ( method_exists( $app, $method ) ) { 66 call_user_func( [ $app, $method ] ); 67 } 68 } 69 } 70 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 86 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 } 93 94 ?> 95 </div><!-- /.wrap --> 96 <?php 97 } 98 99 /** 100 * @since 2.3.0 101 * @access public 102 */ 103 public function __construct() { 104 self::$url = admin_url( 'admin.php?page=' . self::PAGE_ID ); 105 106 add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 206 ); 107 add_action( 'admin_head', [ $this, 'hide_menu_item' ] ); 108 } 109 }