register_meta(); } public function enqueue() { $hide_gutenberg = AIT_AIPSEO_Settings::get('hide_gutenberg'); $post_types = (array) AIT_AIPSEO_Settings::get('post_types'); if ( ! empty( $hide_gutenberg ) || ! $this->current_user_has_visible_role() ) { return; } $screen = get_current_screen(); if ( empty( $screen ) || $screen->base !== 'post' || ! in_array( $screen->post_type, $post_types, true ) ) { return; } wp_enqueue_style( 'ait-aipseo-editor', AIT_AIPSEO_URL . 'assets/css/ait-aipseo-editor.css', [], AIT_AIPSEO_VERSION ); wp_enqueue_script( 'ait-aipseo-editor', AIT_AIPSEO_URL . 'assets/js/ait-aipseo-editor.js', [ 'wp-plugins','wp-edit-post','wp-element','wp-data', 'wp-editor','wp-api-fetch' ], AIT_AIPSEO_VERSION, true ); $rest_base = rtrim( rest_url( 'aipseo/v1' ), '/' ); wp_localize_script( 'ait-aipseo-editor', 'AIT_AIPSEO_EDITOR', [ 'nonce' => wp_create_nonce( 'wp_rest' ), 'pro' => (bool) apply_filters('ait_aipseo/can_pro', false), 'schema_mode' => AIT_AIPSEO_Settings::get('schema_mode'), 'ai' => [ 'keywords' => $rest_base . '/ai/keywords', 'fixit' => $rest_base . '/ai/fixit', 'internal' => $rest_base . '/internal-links', 'seo_title' => $rest_base . '/ai/seo_title', 'meta_desc' => $rest_base . '/ai/meta_desc', ], 'meta_keys' => [ 'keywords' => 'ait_aipseo_target_keywords', 'title' => 'ait_aipseo_meta_title', 'description' => 'ait_aipseo_meta_description', ], ] ); } private function register_meta() { $manual_meta_disabled = AIT_AIPSEO_Settings::get('manual_meta_disabled'); $post_types = (array) AIT_AIPSEO_Settings::get('post_types'); foreach ( $post_types as $post_type ) { register_post_meta( $post_type, 'ait_aipseo_target_keywords', [ 'single' => true, 'type' => 'string', 'show_in_rest' => true, 'auth_callback'=> array( $this, 'current_user_has_visible_role' ), ] ); if ( empty( $manual_meta_disabled ) ) { register_post_meta( $post_type, 'ait_aipseo_meta_title', [ 'single' => true, 'type' => 'string', 'show_in_rest' => true, 'auth_callback'=> array( $this, 'current_user_has_visible_role' ), ] ); register_post_meta( $post_type, 'ait_aipseo_meta_description', [ 'single' => true, 'type' => 'string', 'show_in_rest' => true, 'auth_callback'=> array( $this, 'current_user_has_visible_role' ), ] ); } } } public function current_user_has_visible_role() { $allowed = AIT_AIPSEO_Settings::get('visible_roles'); $user = wp_get_current_user(); if ( empty( $user->roles ) ) { return false; } return (bool) array_intersect( $allowed, (array) $user->roles ); } }