Collection of useful functions. All functions are static.

public count_authors($status = array(“publish”))

  • $status: statuses to include.

Count posts authors.
Function returns: int number of authors.

public unload_jquery()

Unload all jQueryUI components on the page.

public scan_dir($path, $filter = “files”, $extensions = array(), $reg_expr = “”)

  • $path: path of the folder to scan.
  • $filter: what to include: all, files, folders.
  • $extensions: list of estensions to include, empty includes all.
  • $reg_expr: regular expression to match names.

Scans the folder and returns all the files and folder in it.
Function returns: array list of files and folders in the folder.

public dir_size($path, $extensions = array())

  • $path:
  • $extensions: list of estensions to include, empty includes all.

Get size of the path with recursion.
Function returns: array size, count and directory count.

public fill_length($text, $len, $character = “0”, $before = true)

  • $text: original number.
  • $len: max number of zeroes.
  • $character: chracter to use for fill.
  • $before: add it before (true) or after (false).

Adds characters to set length before or after main text.
Function returns: string filled text.

public is_writable($path)

  • $path: file path to check.

Check if the file is writeable and attempt to correct it.
Function returns: bool true if the file is writable.

public is_bot()

Detect if visitor is a bot.
Function returns: bool is spider bot or not.

public visitor_ip()

Get IP address of the visitor.
Function returns: string IP address.

public get_image_from_text($text)

  • $text: text to search.

Finds image url from text.
Function returns: string image url.

public get_caller_backtrace()

Get the function call backtrace.
Function returns: array all functions calls leading to the place of call to this one.

public size_format($size)

  • $size: size in bytes.

Formats byte based size into readable string.
Function returns: string formated string.

public recalculate_size($size)

  • $size: input string with k/m/g/t ending.

Recalcuates size from weight based string.
Function returns: int resulting size.

public trim_to_words($text, $words_count = 10)

  • $text: text to trim.
  • $words_count: words to trim to.

Trims the text to given number of words.
Function returns: string trimmed text.

public unset_by_value($arr, $val, $preserve_keys = true)

  • $arr: start array.
  • $val: value to remove.
  • $preserve_keys: preserve keys or reindex.

Remove element value from the array.
Function returns: array new array.

public upgrade_settings($old, $new, $skip = array(“__core__”, “__date__”))

  • $old: old settings.
  • $new: new settings.
  • $skip: elements to skip during unset.

Adds all new settings array elements and remove obsolete ones.
Function returns: array upgraded array.

public db_insert_meta($table, $id, $data, $id_name = “post_id”, $key_name = “meta_key”, $value_name = “meta_value”)

  • $table: database table to insert into.
  • $id: id value for the owner record.
  • $data: array with data to insert.
  • $id_name: id column name.
  • $key_name: key column name.
  • $value_name: value column name.

Insert into meta data table array with meta key/value pairs.

public deactivate_plugin($plugin_name)

  • $plugin_name: name of the plugin to deactivate.

Deactivates any plugin.

public get_users_with_role($role)

  • $role: role to find.

Finds all users with specified role.
Function returns: array found users.

public get_current_category_id()

  • $wp_query: WP query object.

Gets current category id.
Function returns: int category id.

public get_current_category_ids($cat, $hide_empty = true)

  • $cat: category id.
  • $hide_empty: hid or show empty categories.

Get all subcategories of a category.
Function returns: array subcatories.

public get_all_custom_fieds($hidden = true)

  • $wpdb: database object.
  • $hidden: include hidden fields.

Get all custom fields from post meta.
Function returns: array field names.

public php_in_safe_mode()

Checks if the php is running in safe mode.
Function returns: bool.

public mysql_version($full = false)

  • $full: return full version string or only main version number.

Returns mySQL version.
Function returns: string mySQL version.

public array_filter($input, $filter, $trim_filter = false)

  • $input: array to process.
  • $filter: string to use to filter array.
  • $trim_filter: new array keys should contain filter part.

Get only array elements with keys starting with filter.
Function returns: array filtered array.

public php_version($full = false)

  • $full: return full version string or only main version number.

Returns PHP version.
Function returns: string PHP version.


Leave a Reply