Developer API: Functions & Classes
Viscribe uses a modular, object-oriented architecture under the Viscribe\ namespace. These are the public methods available for programmatic use.
\Viscribe\Plugin
The singleton service container. Access it to reach any service.
get_instance() Since v1.0.0
Returns the singleton plugin instance.
- Return:
\Viscribe\Plugin
init() Since v1.0.0
Initializes all services and registers hooks. Called by viscribe.php.
- Return:
void
get_encryption_service() Since v1.0.0
- Return:
\Viscribe\Services\Encryption_Service
get_template_engine() Since v1.0.0
- Return:
\Viscribe\Services\Template_Engine
get_groq_service() Since v1.0.0
- Return:
\Viscribe\Services\Groq_Service
get_settings_page() Since v1.0.0
Returns the admin settings page instance, or null if not in admin.
- Return:
\Viscribe\Admin\Settings_Page|null
get_image_uploader() Since v1.0.0
- Return:
\Viscribe\Hooks\Image_Uploader|null
is_pro_active() Since v1.0.0
Checks if the Pro add-on is installed, active, and licensed.
- Return:
bool
Groq_Service
Communicates with the Groq Vision API. This is the service used by the free version (Pro adds support for additional AI providers).
has_api_key_constant() Since v1.0.0
Checks if VISCRIBE_API_KEY is defined in wp-config.php.
- Return:
bool(static)
is_enabled() Since v1.0.0
Checks if auto-rename is toggled on and an API key exists.
- Return:
bool
is_allowed_type( string $mime_type ) Since v1.0.0
Checks if a MIME type is allowed for processing.
- Return:
bool
test_connection( ?string $api_key = null ) Since v1.0.0
Tests connectivity to the Groq API with the given key. If no key is passed, uses the saved or constant key.
- Return:
true|string—trueon success, error message string on failure.
generate_description( string $image_path ) Since v1.0.0
Sends an image to the Groq API and returns the description.
- Return:
string|false— The description, orfalseon failure.
Encryption_Service
Handles encryption of sensitive data using defuse/php-encryption.
encrypt( string $plaintext ) Since v1.0.0
- Return:
string|false— The ciphertext, orfalseon failure.
decrypt( string $ciphertext ) Since v1.0.0
- Return:
string|false— The plaintext, orfalseon failure.
is_available() Since v1.0.0
Checks if the encryption service is ready (has a valid key loaded).
- Return:
bool
is_using_config_constant() Since v1.0.0
Checks if the encryption key comes from VISCRIBE_ENCRYPTION_KEY in wp-config.php.
- Return:
bool
maybe_show_security_notice() Since v1.0.0
Displays an admin notice if the encryption key is stored in the database rather than wp-config.php.
- Return:
void
File_Sanitizer
Converts AI descriptions into clean filenames.
sanitize( string $filename ) Since v1.0.0
Converts a raw string to a lowercase, hyphenated slug. Strips stop words, removes punctuation, and collapses hyphens.
- Return:
string
build_filename( string $basename, string $extension ) Since v1.0.0
Joins a sanitized base name with an extension.
- Return:
string— e.g.,tropical-beach-sunset.jpg
get_extension( string $filename ) Since v1.0.0
Extracts the file extension from a filename.
- Return:
string— e.g.,jpg
API_Key_Validator
Validates and masks Groq API keys.
validate_groq_key( string $api_key ) Since v1.0.0
Validates a Groq API key format and optionally tests it against the API.
- Return:
array—['valid' => bool, 'message' => string]
mask_for_display( string $api_key ) Since v1.0.0
Returns a masked version for display in the admin UI.
- Return:
string— e.g.,gsk_abc...xyz
is_masked( string $api_key ) Since v1.0.0
Checks if a key is already in masked format.
- Return:
bool
Template_Engine
Wraps Twig for rendering admin templates.
render( string $template, array $context = [] ) Since v1.0.0
Renders a .twig template relative to the views/ directory.
- Return:
string— The rendered HTML.
$engine = \Viscribe\Plugin::get_instance()->get_template_engine();
echo $engine->render( 'admin/fields/api-key.twig', [ 'placeholder' => 'gsk_...' ] );