title */ public function get_sections(): array { return [ 'adsense_module_activation' => [ 'title' => __( 'AdSense settings', 'adpresso' ), 'description' => __( 'Adjust your AdSense settings.', 'adpresso' ), ], 'adsense_auto_ads' => [ 'title' => __( 'AdSense Auto Ads', 'adpresso' ), 'description' => __( 'Connect your website to AdSense to enable Google Auto ads and verify your domain.', 'adpresso' ), 'controlled_by' => 'enable_module_' . $this->get_id(), 'initially_open' => true, ], ]; } /** * Define the options for this settings tab. * * @return array */ protected function define_options(): array { $options = []; $adsense_settings = get_option( 'adpresso_settings_adsense', [] ); $options[ 'enable_module_' . $this->get_id() ] = [ 'type' => 'checkbox', 'label' => __( 'Enable AdSense modul', 'adpresso' ), 'description' => __( 'Enables Google AdSense functionality', 'adpresso' ), 'default' => 0, 'sanitize_type' => 'uint', 'section' => 'adsense_module_activation', ]; $options['adsense_publisher_id'] = [ 'type' => 'text', 'label' => __( 'Publisher ID', 'adpresso' ), 'description' => __( 'e.g. pub-123456789', 'adpresso' ), 'section' => 'adsense_auto_ads', 'default' => '', ]; $is_auto_ads_configured = ! empty( $adsense_settings['adsense_enable_auto_ads'] ) && ! empty( $adsense_settings['auto_ads_placement_id'] ); if ( $is_auto_ads_configured ) { $options['auto_ads_status'] = [ 'type' => 'html-content', 'section' => 'adsense_auto_ads', 'label' => __( 'Auto Ads status', 'adpresso' ), 'html' => $this->get_auto_ads_status_html( $adsense_settings ), ]; } $options['adsense_enable_auto_ads'] = [ 'type' => 'checkbox', 'label' => __( 'Enable Auto Ads', 'adpresso' ), 'description' => __( 'Automatically creates the required ad and placement for AdSense Auto Ads.', 'adpresso' ), 'default' => 0, 'sanitize_type' => 'uint', 'section' => 'adsense_auto_ads', ]; return $options; } /** * Generates the HTML for the Auto Ads status section. */ private function get_auto_ads_status_html( array $settings ): string { $placement_id = $settings['auto_ads_placement_id'] ?? 0; $ad_id = $settings['auto_ads_ad_id'] ?? 0; $output = ''; if ( ! $placement_id || ! $ad_id ) { return '
'; } $placement = adpresso_get_placement( $placement_id ); $ad = adpresso_get_ad( $ad_id ); if ( $placement && $placement->get_post()->post_status === 'publish' && $ad && $ad->get_post()->post_status === 'publish' ) { $output .= '' . __( 'The following items were created automatically. You can edit them to add conditions or other settings.', 'adpresso' ) . '
'; $output .= '' . __( 'To change your Publisher ID or disable Auto Ads, uncheck the "Enable Auto Ads" option above and save settings. The fields will reappear.', 'adpresso' ) . '
'; return $output; } }