API Reference
Key classes and helper functions available in Nyrge.
Helper Functions
| Function | Returns | Description |
|---|---|---|
nyrge_url($path = '') | string | Full URL for a path |
nyrge_admin_url($path = '') | string | Admin panel URL |
nyrge_asset($path) | string | Theme asset URL with cache-busting |
nyrge_config($key, $default) | string | Get .env config value |
nyrge_is_admin() | bool | Check if user is admin |
nyrge_current_site() | array | Get current site settings |
nyrge_site_id() | int | Get current site ID |
nyrge_verify_csrf() | bool | Verify CSRF token |
e($string) | string | HTML-escape a string |
Core Classes
Nyrge\Database\Database
PDO database wrapper (static singleton):
use Nyrge\Database\Database;
$pdo = Database::get();
$stmt = $pdo->prepare("SELECT * FROM posts WHERE post_id = ?");
$stmt->execute([$id]);
$post = $stmt->fetch();
Nyrge\Content\Post
Static methods for post operations:
use Nyrge\Content\Post;
// Get published posts
$posts = Post::getPublished($siteId, $limit, $offset);
$count = Post::countPublished($siteId);
// Get single post by slug
$post = Post::getBySlug($slug, $siteId);
Nyrge\Content\Category
use Nyrge\Content\Category;
$categories = Category::getAll($siteId);
$category = Category::getBySlug($slug, $siteId);
Nyrge\Content\Tag
use Nyrge\Content\Tag;
$tags = Tag::getAll($siteId);
$tags = Tag::getForPost($postId);
Nyrge\Content\Media
use Nyrge\Content\Media;
$files = Media::getAll($siteId, $limit, $offset);
$file = Media::getById($id);
Nyrge\Themes\ThemeLoader
use Nyrge\Themes\ThemeLoader;
$theme = new ThemeLoader();
$theme->render('home', ['posts' => $posts]);
$theme->renderPart('header', compact('site'));
Nyrge\Plugins\Hook
use Nyrge\Plugins\Hook;
// Actions
Hook::on('event_name', $callback, $priority);
Hook::fire('event_name');
// Filters
Hook::filter('filter_name', $callback, $priority);
$result = Hook::apply('filter_name', $value);
Nyrge\Shortcodes\ShortcodeEngine
use Nyrge\Shortcodes\ShortcodeEngine;
ShortcodeEngine::register('tag', function ($attrs) {
return 'output HTML';
});
$html = ShortcodeEngine::process($content);
Nyrge\Routing\Router
// Route definitions (in core/routes.php)
$router->get('/path', [Controller::class, 'method']);
$router->post('/path', [Controller::class, 'method']);
$router->group('/prefix', function ($router) {
$router->get('/sub', [Controller::class, 'method']);
}, ['middleware_name']);