Documentation → Developer Resources
API Documentation
Public classes and methods for programmatic access.
Getting Started
Access the plugin’s services through the Kernel singleton:
use DeveloperSitemap\Application\Kernel;
// Get the kernel instance
$kernel = Kernel::getInstance();
// Access services
$generator = $kernel->getSitemapGenerator();
$config = $kernel->getConfigurationService();
$cache = $kernel->getCacheManager();
SitemapGenerator
Generate sitemaps programmatically.
generate(string $type): string
Generates XML sitemap for specified type.
$generator = $kernel->getSitemapGenerator();
// Generate specific sitemap
$xml = $generator->generate('post');
$xml = $generator->generate('page');
$xml = $generator->generate('product');
$xml = $generator->generate('taxonomy');
$xml = $generator->generate('author');
// Generate sitemap index
$xml = $generator->generate('index');
getUrls(string $type): array
Returns array of SitemapUrl objects for specified type.
$urls = $generator->getUrls('post');
foreach ($urls as $url) {
echo $url->getLoc(); // URL
echo $url->getLastmod(); // Last modified date
echo $url->getPriority(); // Priority value
}
getUrlCount(string $type): int
Returns count of URLs for specified type.
$count = $generator->getUrlCount('post');
echo "Posts in sitemap: {$count}";
ConfigurationService
Access and modify plugin settings.
get(string $key, $default = null)
Get a configuration value.
$config = $kernel->getConfigurationService();
// Get settings
$enabled = $config->get('enabled', true);
$postPriority = $config->get('post_priority', 0.6);
$cacheDuration = $config->get('cache_duration', 3600);
$excludedPosts = $config->get('excluded_posts', []);
set(string $key, $value): void
Set a configuration value.
$config->set('post_priority', 0.8);
$config->set('cache_duration', 7200);
$config->save(); // Persist changes
isTypeEnabled(string $type): bool
Check if a content type is enabled.
if ($config->isTypeEnabled('post')) {
// Posts are included in sitemap
}
if ($config->isTypeEnabled('product')) {
// Products are included (WooCommerce)
}
CacheManager
Manage sitemap cache.
clear(string $type = ‘all’): void
Clear cached sitemaps.
$cache = $kernel->getCacheManager();
// Clear all caches
$cache->clear();
// Clear specific type
$cache->clear('post');
$cache->clear('product');
has(string $type): bool
Check if cache exists.
if ($cache->has('post')) {
echo "Post sitemap is cached";
}
URL Providers
Create custom URL providers by implementing the interface.
use DeveloperSitemap\Domain\Interface\UrlProviderInterface;
use DeveloperSitemap\Domain\Entity\SitemapUrl;
class CustomUrlProvider implements UrlProviderInterface
{
public function getType(): string
{
return 'custom';
}
public function getUrls(array $config): array
{
$urls = [];
// Add your custom URLs
$urls[] = new SitemapUrl(
'https://example.com/custom-page/',
'2026-01-09',
'weekly',
0.7
);
return $urls;
}
public function getCount(array $config): int
{
return count($this->getUrls($config));
}
}
Registering Custom Providers
add_action('developer_sitemap_init', function($kernel) {
$kernel->registerUrlProvider(new CustomUrlProvider());
});
