Functions

Common utility functions in WindPress.

WindPress have a set of public functions that can be used outside the WindPress core.

Common::is_request

Checks the type of the current request.

  • Location: src/Utils/Common.php
  • Parameters:
    • string $type: The type of the request. Available values: admin, ajax, frontend, rest, cron, json, xmlrpc, xml.
  • Returns:
    • bool: Whether the current request matches the specified type.
  • Example:
    if (Common::is_request('ajax')) {
        // Handle AJAX-specific logic
    }
    

Common::plugin_data

Retrieves the WindPress plugin's data.

  • Location: src/Utils/Common.php
  • Parameters:
    • string|null $key: The key to retrieve. If null, returns all plugin data.
  • Returns:
    • mixed: The plugin data or the value of the specified key.
  • Example:
    $plugin_version = Common::plugin_data('Version');
    

Common::is_updater_library_available

Checks if the updater library is available. WindPress uses the PluginUpdater class for plugin updates on the non WordPress.org distribution.

  • Location: src/Utils/Common.php
  • Returns:
    • bool: Whether the PluginUpdater class exists.
  • Example:
    if (Common::is_updater_library_available()) {
        // Proceed with updater logic
    }
    

Common::random_slug

Generates a random slug.

  • Location: src/Utils/Common.php
  • Parameters:
    • int $length: The length of the slug. Default is 21.
  • Returns:
    • string: A randomly generated slug.
  • Example:
    $slug = Common::random_slug(10);
    
    echo $slug; // Example output: 'a1b2c3d4e5'
    

Common::redirect

Redirects to the given location. If headers are already sent, uses a meta refresh.

  • Location: src/Utils/Common.php
  • Parameters:
    • string $location: The location to redirect to.
    • bool $safe: Whether to use wp_safe_redirect() or not.
    • int $status: The HTTP status code for the redirect. Default is 302.
    • string $x_redirect_by: The value for the X-Redirect-By header. Default is WordPress.
  • Example:
    Common::redirect('https://example.com', true);
    

Common::save_file

Saves a payload into a file.

  • Location: src/Utils/Common.php
  • Parameters:
    • mixed $content: The content to save.
    • string $file_path: The file path.
    • int $flags: Flags to pass to the file_put_contents() function.
  • Throws:
    • Exception: If the file cannot be saved or read.
  • Example:
    Common::save_file('File content', '/path/to/file.txt');
    

Common::delete_file

Deletes a file or directory.

  • Location: src/Utils/Common.php
  • Parameters:
    • string $file_path: Path to the file or directory.
    • bool $recursive: Whether to delete files and folders recursively. Default is false.
    • string|false $type: Type of resource. 'f' for file, 'd' for directory. Default is false.
  • Throws:
    • Exception: If the file cannot be deleted.
  • Example:
    Common::delete_file('/path/to/file.txt');
    

Cache::flush_cache_plugin

Clears the cache for multiple popular WordPress caching plugins, including WP Rocket, WP Super Cache, W3 Total Cache, WP Fastest Cache, LiteSpeed Cache, and SG Optimizer. It also clears the WordPress Object Cache.

Config::propertyAccessor

Provides a singleton instance of the Symfony PropertyAccessor component.

  • Location: src/Utils/Config.php
  • Returns:
    • \Symfony\Component\PropertyAccess\PropertyAccessorInterface: The property accessor instance.
  • Example:
    $accessor = Config::propertyAccessor();
    

Config::data_set

Sets a value on an array or object using dot notation.

  • Location: src/Utils/Config.php
  • Parameters:
    • mixed &$target: The target array or object.
    • string|array $key: The key or path to set.
    • mixed $value: The value to set.
    • bool $overwrite: Whether to overwrite existing values. Default is true.
  • Returns:
    • mixed: The modified target.
  • Example:
    $data = [];
    Config::data_set($data, 'user.name', 'John Doe');
    

Config::array_exists

Determines if the given key exists in the provided array or ArrayAccess object.

  • Location: src/Utils/Config.php
  • Parameters:
    • \ArrayAccess|array $array: The array or ArrayAccess object.
    • string|int $key: The key to check.
  • Returns:
    • bool: Whether the key exists.
  • Example:
    $exists = Config::array_exists(['name' => 'John'], 'name');
    

Config::get

Gets a value at the end of the property path of the WindPress' config.

  • Location: src/Utils/Config.php
  • Parameters:
    • string $path: The property path to read.
    • mixed $defaultValue: The value to return if the property path does not exist.
  • Returns:
    • mixed: The value at the end of the property path or the default value.
  • Example:
    $value = Config::get('settings.theme', 'default-theme');
    

Config::set

Sets a value at the end of the property path of the WindPress' config.

  • Location: src/Utils/Config.php
  • Parameters:
    • string $path: The property path to modify.
    • mixed $value: The value to set at the end of the property path.
  • Throws:
    • InvalidArgumentException: If the property path is invalid.
    • AccessException: If a property/index does not exist or is not public.
    • UnexpectedTypeException: If a value within the path is neither object nor array.
  • Example:
    Config::set('settings.theme', 'dark-mode');
    

Notice::get_lists

Retrieves the list of notices.

  • Location: src/Utils/Notice.php
  • Parameters:
    • ?bool $purge: Whether to clear the notices after retrieving them. Default is true.
  • Returns:
    • array: The list of notices.
  • Example:
    $notices = Notice::get_lists(false);
    

Notice::admin_notices

Callback for the admin_notices action. Prints the notices in the WordPress admin page.

  • Location: src/Utils/Notice.php
  • Example:
    add_action('admin_notices', [Notice::class, 'admin_notices']);
    

Notice::add

Adds a single notice.

  • Location: src/Utils/Notice.php
  • Parameters:
    • string $status: The status of the notice (error, success, warning, info).
    • string $message: The message to display.
    • ?string $key: An optional key to identify the notice.
    • bool $unique: Whether to ensure the notice is unique. Default is false.
  • Example:
    Notice::add('success', 'Settings saved successfully.');
    

Notice::adds

Adds multiple notices in bulk.

  • Location: src/Utils/Notice.php
  • Parameters:
    • string $status: The status of the notices (error, success, warning, info).
    • string|array $messages: A single message or an array of messages to add.
  • Example:
    Notice::adds('info', ['Message 1', 'Message 2']);
    

Notice::success

Adds a success notice.

  • Location: src/Utils/Notice.php
  • Parameters:
    • string $message: The success message.
    • ?string $key: An optional key to identify the notice.
    • bool $unique: Whether to ensure the notice is unique. Default is false.
  • Example:
    Notice::success('Operation completed successfully.');
    

Notice::warning

Adds a warning notice.

  • Location: src/Utils/Notice.php
  • Parameters:
    • string $message: The warning message.
    • ?string $key: An optional key to identify the notice.
    • bool $unique: Whether to ensure the notice is unique. Default is false.
  • Example:
    Notice::warning('This action may have unintended consequences.');
    

Notice::info

Adds an informational notice.

  • Location: src/Utils/Notice.php
  • Parameters:
    • string $message: The informational message.
    • ?string $key: An optional key to identify the notice.
    • bool $unique: Whether to ensure the notice is unique. Default is false.
  • Example:
    Notice::info('This is an informational message.');
    

Notice::error

Adds an error notice.

  • Location: src/Utils/Notice.php
  • Parameters:
    • string $message: The error message.
    • ?string $key: An optional key to identify the notice.
    • bool $unique: Whether to ensure the notice is unique. Default is false.
  • Example:
    Notice::error('An error occurred while processing your request.');