name; } /** * Add a new snippet. * * @param string $code The snippet code. * @param string|null $title The snippet title. * @param string|null $description The snippet description. * @param string|null $lang The snippet language. * @param string|null $scope The snippet scope. * @param int|null $priority The snippet priority. * @return string The snippet URL. * @throws Exception If the snippet could not be added. */ public function add(string $code, ?string $title = null, ?string $description = null, ?string $lang = null, ?string $scope = null, ?int $priority = null): string { $snippet = new WPCode_Snippet( [ 'title' => $title, 'desc' => $description, 'code' => $code, 'code_type' => $lang, 'location' => $scope, 'priority' => $priority, 'active' => false, 'tags' => [], 'use_php' => $lang === 'php', ] ); $snippet_id = $snippet->save(); if (!$snippet_id) { throw new Exception('Failed to add WPCode snippet.'); } return admin_url('admin.php?page=wpcode-snippet-manager&snippet_id=' . $snippet_id); } }