ui = $ui; $this->global_settings = $global_settings; } public function slug(): string { return 'global'; } public function label(): string { return __( 'Schema', 'acez-seo' ); } public function icon(): string { return 'global'; } public function enqueue(): void { // wp.media modal: the organization logo pickers (shared + per language). wp_enqueue_media(); wp_enqueue_script( 'acez-seo-media-picker', ACEZ_SEO_URL . 'assets/js/media-picker.js', array( 'media-editor' ), ACEZ_SEO_VERSION, true ); } public function handles_form_key( string $raw_tab ): bool { if ( str_starts_with( $raw_tab, 'lang_override:' ) ) { return true; } return in_array( sanitize_key( $raw_tab ), array( 'global', 'local_business' ), true ); } /** @return array */ public function save( string $raw_tab ): array { // Defence in depth: SettingsPage::handle_save() verifies this nonce // before dispatch; re-checking keeps every entry point independently safe. check_admin_referer( FormControls::NONCE_ACTION ); if ( str_starts_with( $raw_tab, 'lang_override:' ) ) { // NOT sanitize_key — locales are case-sensitive ("pl_PL") and are // validated against the multilingual plugin's own language list. $locale = sanitize_text_field( substr( $raw_tab, strlen( 'lang_override:' ) ) ); if ( in_array( $locale, \AcezSeo\Support\MultilingualPluginDetector::languages(), true ) ) { /** * Fires when a per-language Organization override form is saved. * * The base plugin only ROUTES this form key, so the settings-page * dispatcher keeps handling nonce, capability and the redirect; * since M69 Etap 2 the data itself belongs to acez-seo-pro, which * hooks this action and reads $_POST itself. With no addon active * nothing is written — and that is NOT a license gate: the base * plugin simply has nowhere to put the values any more. * * @param string $locale Already validated against the multilingual plugin's own language list. */ do_action( 'acez_seo_save_language_override', $locale ); } return array( 'tab' => 'global' ); } if ( 'local_business' === sanitize_key( $raw_tab ) ) { $this->save_local_business(); return array( 'tab' => 'global' ); } // 'global' — the Organization card. $social_raw = isset( $_POST['social_profiles'] ) ? TemplateSanitizer::sanitize_multiline( wp_strip_all_tags( wp_unslash( $_POST['social_profiles'] ) ) ) : ''; $this->global_settings->update( array( 'organization_name' => isset( $_POST['organization_name'] ) ? sanitize_text_field( wp_unslash( $_POST['organization_name'] ) ) : '', 'organization_logo_id' => isset( $_POST['organization_logo_id'] ) ? (int) $_POST['organization_logo_id'] : 0, 'organization_scope' => isset( $_POST['organization_scope'] ) ? sanitize_key( wp_unslash( $_POST['organization_scope'] ) ) : 'site', 'organization_page_ids' => isset( $_POST['organization_page_ids'] ) ? array_map( 'absint', (array) $_POST['organization_page_ids'] ) : array(), 'social_profiles' => array_filter( array_map( 'trim', explode( "\n", $social_raw ) ) ), ) ); return array(); } private function save_local_business(): void { // Defence in depth: SettingsPage::handle_save() verifies this nonce // before dispatch; re-checking keeps every entry point independently safe. check_admin_referer( FormControls::NONCE_ACTION ); $this->global_settings->update( array( 'local_business_enabled' => isset( $_POST['local_business_enabled'] ), 'local_business_scope' => isset( $_POST['local_business_scope'] ) ? sanitize_key( wp_unslash( $_POST['local_business_scope'] ) ) : 'site', 'local_business_page_ids' => isset( $_POST['local_business_page_ids'] ) ? array_map( 'absint', (array) $_POST['local_business_page_ids'] ) : array(), 'local_business_type' => isset( $_POST['local_business_type'] ) ? sanitize_text_field( wp_unslash( $_POST['local_business_type'] ) ) : '', 'local_business_street' => isset( $_POST['local_business_street'] ) ? sanitize_text_field( wp_unslash( $_POST['local_business_street'] ) ) : '', 'local_business_locality' => isset( $_POST['local_business_locality'] ) ? sanitize_text_field( wp_unslash( $_POST['local_business_locality'] ) ) : '', 'local_business_region' => isset( $_POST['local_business_region'] ) ? sanitize_text_field( wp_unslash( $_POST['local_business_region'] ) ) : '', 'local_business_postal' => isset( $_POST['local_business_postal'] ) ? sanitize_text_field( wp_unslash( $_POST['local_business_postal'] ) ) : '', 'local_business_country' => isset( $_POST['local_business_country'] ) ? sanitize_text_field( wp_unslash( $_POST['local_business_country'] ) ) : '', 'local_business_phone' => isset( $_POST['local_business_phone'] ) ? sanitize_text_field( wp_unslash( $_POST['local_business_phone'] ) ) : '', 'local_business_lat' => isset( $_POST['local_business_lat'] ) ? sanitize_text_field( wp_unslash( $_POST['local_business_lat'] ) ) : '', 'local_business_lng' => isset( $_POST['local_business_lng'] ) ? sanitize_text_field( wp_unslash( $_POST['local_business_lng'] ) ) : '', 'local_business_hours' => isset( $_POST['local_business_hours'] ) ? sanitize_textarea_field( wp_unslash( $_POST['local_business_hours'] ) ) : '', ) ); } public function render(): void { $settings = $this->global_settings->get(); echo '

' . esc_html__( 'Site-wide schema.org entities: the Organization (Organization/WebSite nodes) and LocalBusiness, with their scopes and language versions. Module settings live in the Settings tab.', 'acez-seo' ) . '

'; $this->ui->card_open( __( 'Organization', 'acez-seo' ), 'global', '', 'organization' ); $this->ui->form_open( 'global' ); echo ''; $this->ui->text_field( 'organization_name', __( 'Organization name', 'acez-seo' ), (string) $settings['organization_name'], get_bloginfo( 'name' ), 'organization' ); $this->ui->media_picker_field( 'organization_logo_id', 'organization_logo_id', __( 'Logo (Media Library)', 'acez-seo' ), (int) $settings['organization_logo_id'], 'organization_logo' ); $this->ui->textarea_field( 'social_profiles', __( 'Social profiles (one URL per line)', 'acez-seo' ), implode( "\n", (array) $settings['social_profiles'] ), __( "https://facebook.com/your-page\nhttps://x.com/your-page", 'acez-seo' ), 'social_profiles' ); $this->ui->render_node_scope_field( 'organization', (string) ( $settings['organization_scope'] ?? 'site' ), (array) ( $settings['organization_page_ids'] ?? array() ), 'organization_scope' ); echo '
'; submit_button(); $this->ui->form_close(); $this->ui->card_close(); $this->render_local_business_card( $settings ); $this->render_language_overrides_card(); } /** * @param array $settings */ private function render_local_business_card( array $settings ): void { $this->ui->card_open( __( 'LocalBusiness (optional)', 'acez-seo' ), 'global', '', 'local-business' ); echo '

' . esc_html__( 'For businesses with a physical location (shop, restaurant, office). Generates an additional schema.org node — below you choose on which pages.', 'acez-seo' ) . '

'; $this->ui->form_open( 'local_business' ); echo ''; $this->ui->checkbox_field( 'local_business_enabled', __( 'Generate LocalBusiness node', 'acez-seo' ), (bool) $settings['local_business_enabled'], 'local_business' ); $this->ui->render_node_scope_field( 'local_business', (string) ( $settings['local_business_scope'] ?? 'site' ), (array) ( $settings['local_business_page_ids'] ?? array() ), 'local_business_scope' ); $this->ui->text_field( 'local_business_type', __( 'Type (schema.org, e.g. LocalBusiness, Restaurant, Store)', 'acez-seo' ), (string) $settings['local_business_type'], 'LocalBusiness' ); $this->ui->text_field( 'local_business_street', __( 'Street and number', 'acez-seo' ), (string) $settings['local_business_street'] ); $this->ui->text_field( 'local_business_locality', __( 'City', 'acez-seo' ), (string) $settings['local_business_locality'] ); $this->ui->text_field( 'local_business_region', __( 'State/region', 'acez-seo' ), (string) $settings['local_business_region'] ); $this->ui->text_field( 'local_business_postal', __( 'Postal code', 'acez-seo' ), (string) $settings['local_business_postal'] ); $this->ui->text_field( 'local_business_country', __( 'Country (ISO code, e.g. US)', 'acez-seo' ), (string) $settings['local_business_country'] ); $this->ui->text_field( 'local_business_phone', __( 'Phone', 'acez-seo' ), (string) $settings['local_business_phone'] ); $this->ui->text_field( 'local_business_lat', __( 'Latitude', 'acez-seo' ), (string) $settings['local_business_lat'] ); $this->ui->text_field( 'local_business_lng', __( 'Longitude', 'acez-seo' ), (string) $settings['local_business_lng'] ); $this->ui->textarea_field( 'local_business_hours', __( 'Opening hours (one line per entry)', 'acez-seo' ), (string) $settings['local_business_hours'], "Mo-Fr 09:00-17:00\nSa 10:00-14:00" ); echo '
'; submit_button(); $this->ui->form_close(); $this->ui->card_close(); } /** * Per-language Organization overrides — only shown when a multilingual * plugin (WPML/Polylang/TranslatePress) is detected and exposes its * language list. */ private function render_language_overrides_card(): void { if ( ! \AcezSeo\Support\MultilingualPluginDetector::is_active() ) { return; } $locales = \AcezSeo\Support\MultilingualPluginDetector::languages(); if ( array() === $locales ) { return; } // The real card is rendered by acez-seo-pro (M69 Etap 2 — the base // plugin must not carry license-gated functionality). Base keeps only // a static signpost, which WP.org Guideline 11 explicitly allows: it // is marketing copy, not functionality behind a gate. `has_action()` // — deliberately NOT a license check — decides which of the two shows, // the same pattern the License tab already uses for its button. if ( ! has_action( 'acez_seo_schema_language_cards' ) ) { $this->ui->card_open( __( 'Organization per language', 'acez-seo' ), 'global', '', 'language-overrides' ); echo '

' . esc_html__( 'Per-language Organization overrides (name, logo, social profiles for each language version) are a Pro feature. Previously saved values remain untouched and take effect again once a license is active.', 'acez-seo' ) . '

'; $this->ui->card_close(); return; } /** * Renders the per-language Organization overrides card. * * Receives the base plugin's own FormControls instance on purpose, so * the addon draws the card with the SAME helpers (card chrome, media * picker, form_open/close and its nonce) instead of duplicating them — * the rendered UI stays identical to what the base used to output. * * @param \AcezSeo\Admin\Ui\FormControls $ui * @param array $locales */ do_action( 'acez_seo_schema_language_cards', $this->ui, $locales ); } }