[ 'content' => '[agolegal_privacy_policy]', 'option' => 'agolegal_page_privacy', ], 'cookie-policy' => [ 'content' => '[agolegal_cookie_policy]', 'option' => 'agolegal_page_cookies', ], ]; private static function page_title( string $slug ): string { return 'privacy-policy' === $slug ? __( 'Privacy Policy', 'ago-legal' ) : __( 'Cookie Policy', 'ago-legal' ); } public static function create_pages(): void { foreach ( self::$pages as $slug => $page ) { $existing_id = (int) get_option( $page['option'], 0 ); // Check if page still exists if ( $existing_id && get_post_status( $existing_id ) ) { continue; } $id = wp_insert_post( [ 'post_title' => self::page_title( $slug ), 'post_content' => $page['content'], 'post_status' => 'publish', 'post_type' => 'page', 'post_name' => $slug, ] ); if ( $id && ! is_wp_error( $id ) ) { update_option( $page['option'], $id ); } } // Update settings with page URLs $settings = get_option( 'agolegal_settings', [] ); $privacy_id = (int) get_option( 'agolegal_page_privacy', 0 ); $cookies_id = (int) get_option( 'agolegal_page_cookies', 0 ); if ( $privacy_id && empty( $settings['privacy_policy_url'] ) ) { $settings['privacy_policy_url'] = get_permalink( $privacy_id ); } if ( $cookies_id && empty( $settings['cookie_policy_url'] ) ) { $settings['cookie_policy_url'] = get_permalink( $cookies_id ); } update_option( 'agolegal_settings', $settings ); } }