WPDK  1.5.0
WordPress Development Kit
 All Data Structures Files Functions Variables Pages
wpdk-functions.php File Reference

Very useful functions for common cases. More...

Go to the source code of this file.

Functions

 wpdk_is_bool ($str)
 
 wpdk_is_url ($url)
 
 wpdk_is_infinity ($value)
 
 wpdk_is_ajax ()
 Ajax validation. More...
 
 wpdk_is_child ($parent= '')
 
 wpdk_sanitize_function ($key)
 Sanitize for function name. More...
 
 wpdk_get_image_size ($name)
 
 wpdk_checked ($haystack, $current, $echo=true)
 
 wpdk_selected ($haystack, $current, $echo=true)
 
 wpdk_content_page_with_slug ($slug, $post_type, $alternative_slug= '')
 
 wpdk_permalink_page_with_slug ($slug, $post_type= 'page')
 
 wpdk_delta_object ($last_version, $old_version)
 Object delta compare for combine. More...
 
 wpdk_get_image_in_post_content ($id_post)
 Get an img tag from the content. More...
 
 wpdk_get_image_from_post_thumbnail ($id_post)
 Get thumbnail image. More...
 
 wpdk_get_image_from_attachments ($id_post)
 Get image from post attachment. More...
 
 is_wpdk_error ($thing)
 Check whether variable is a WPDK result error. More...
 
 is_wpdk_warning ($thing)
 Check whether variable is a WPDK result warning. More...
 
 is_wpdk_status ($thing)
 Check whether variable is a WPDK result status. More...
 
 wpdk_add_page ($page_slug, $page_title, $capability, $function= '', $hook_head= '', $hook_load= '')
 Add a page. More...
 
 wpdk_enqueue_script_page ($pages, $handle, $src=false, $deps=array(), $ver=false, $in_footer=false)
 Enqueue script. More...
 
 wpdk_enqueue_script_page_template ($page_templates, $handle, $src=false, $deps=array(), $ver=false, $in_footer=false)
 Enqueue script. More...
 
 wpdk_set_user_transient ($transient, $value, $expiration=0, $user_id=null)
 Set. More...
 
 wpdk_get_user_transient ($transient, $user_id=null)
 Get. More...
 
 wpdk_delete_user_transient ($transient, $user_id=null)
 Delete. More...
 
 wpdk_is_request ($verb)
 Check request. More...
 
 wpdk_is_request_get ()
 Check if request is get. More...
 
 wpdk_is_request_post ()
 Check if request is post. More...
 

Detailed Description

Very useful functions for common cases.

Infinity.

Check URI.

Check for generic boolean.

Very useful functions for common cases. All that is missing in WordPress

Overview

This file contains the pure inline function without class wrapper. You can use these function directly from code.

Author
=undo= info@.nosp@m.wpxt.nosp@m.re.me
Date
2013-01-21
Version
0.9.0

Return TRUE if the string NOT contains '', 'false', '0', 'no', 'n', 'off', null.

Parameters
string$strString to check
Returns
bool

Return TRUE if a url is a URI

Since
1.0.0.b2
Parameters
string$url
Returns
bool

Check if infinity

Parameters
float | string$valueCheck value
Returns
bool TRUE if $value is equal to INF (php) or WPDKMath::INFINITY
Deprecated:
Since 1.2.0 Use WPDKMath::isInfinity() instead

Definition in file wpdk-functions.php.

Function Documentation

is_wpdk_error (   $thing)

Check whether variable is a WPDK result error.

Looks at the object and if a WPDKError class. Does not check to see if the parent is also WPDKError or a WPDKResult, so can't inherit both the classes and still use this function.

Parameters
mixed$thingCheck if unknown variable is WPDKError object.
Returns
bool TRUE, if WPDKError. FALSE, if not WPDKError.
Deprecated:
Since 1.2.0 Use WPDKResult::isError() instead

Definition at line 425 of file wpdk-functions.php.

is_wpdk_status (   $thing)

Check whether variable is a WPDK result status.

Looks at the object and if a WPDKStatus class. Does not check to see if the parent is also WPDKStatus or a WPDKResult, so can't inherit both the classes and still use this function.

Parameters
mixed$thingCheck if unknown variable is WPDKStatus object.
Returns
bool TRUE, if WPDKStatus. FALSE, if not WPDKStatus.
Deprecated:
Since 1.2.0 Use WPDKResult::isStatus() instead

Definition at line 461 of file wpdk-functions.php.

is_wpdk_warning (   $thing)

Check whether variable is a WPDK result warning.

Looks at the object and if a WPDKWarning class. Does not check to see if the parent is also WPDKWarning or a WPDKResult, so can't inherit both the classes and still use this function.

Parameters
mixed$thingCheck if unknown variable is WPDKWarning object.
Returns
bool TRUE, if WPDKWarning. FALSE, if not WPDKWarning.
Deprecated:
Since 1.2.0 Use WPDKResult::isWarning() instead

Definition at line 443 of file wpdk-functions.php.

wpdk_add_page (   $page_slug,
  $page_title,
  $capability,
  $function = '',
  $hook_head = '',
  $hook_load = '' 
)

Add a page.

Add a custom hidden (without menu) page in the admin backend area and return the page's hook_suffix.

Parameters
string$page_slugThe slug name to refer to this hidden pahe by (should be unique)
string$page_titleThe text to be displayed in the title tags of the page when the page is selected
string$capabilityThe capability required for this page to be displayed to the user.
callback | string$functionOptional. The function to be called to output the content for this page.
string$hook_headOptional. Callback when head is loaded
string$hook_loadOptional. Callback when loaded
Returns
string

Definition at line 485 of file wpdk-functions.php.

wpdk_checked (   $haystack,
  $current,
  $echo = true 
)

Commodity to extends checked() WordPress function with array check

Parameters
string | array$haystackSingle value or array
mixed$current(true) The other value to compare if not just true
bool$echoWhether to echo or just return the string
Returns
string html attribute or empty string

Definition at line 178 of file wpdk-functions.php.

wpdk_content_page_with_slug (   $slug,
  $post_type,
  $alternative_slug = '' 
)

Get the post content from the slug.

Parameters
string$slugPost slug
string$post_typePost type
string$alternative_slugAlternative slug if post not found
Note
WPML compatible
See Also
get_page_by_path()
Returns
string Text/html content post. FALSE not found or error.

Definition at line 226 of file wpdk-functions.php.

wpdk_delete_user_transient (   $transient,
  $user_id = null 
)

Delete.

Delete a user transient.

Since
1.1.0

do_action() Calls 'delete_user_transient_$transient' hook before transient is deleted. do_action() Calls 'deleted_user_transient' hook on success.

Parameters
string$transientTransient name. Expected to not be SQL-escaped.
int$user_idOptional. User ID. If null the current user id is used instead
Returns
bool true if successful, false otherwise

Definition at line 630 of file wpdk-functions.php.

wpdk_delta_object (   $last_version,
  $old_version 
)

Object delta compare for combine.

Do a merge/combine between two object tree. If the old version not contains an object or property, that is added. If the old version contains an object or property less in last version, that is deleted.

Parameters
mixed$last_versionObject tree with new or delete object/value
mixed$old_versionCurrent Object tree, loaded from serialize or database for example
Returns
Object the delta Object tree
Deprecated:
Since 1.2.0 Use WPDKObject::__delta() instead

Definition at line 320 of file wpdk-functions.php.

wpdk_enqueue_script_page (   $pages,
  $handle,
  $src = false,
  $deps = array(),
  $ver = false,
  $in_footer = false 
)

Enqueue script.

Enqueue script for list of page template

Deprecated:
since 1.4.21 Use WPDKScripts::enqueue_scripts_page_template() instead
Parameters
array$pagesArray of page slug
string$handleThe script /unique) handle
bool$srcOptional. Source URI
array$depsOptional. Array of other handle
bool$verOptional. Version to avoid cache
bool$in_footerOptional. Load in footer

Definition at line 525 of file wpdk-functions.php.

wpdk_enqueue_script_page_template (   $page_templates,
  $handle,
  $src = false,
  $deps = array(),
  $ver = false,
  $in_footer = false 
)

Enqueue script.

Enqueue script for list of page template. Return FALSE if $page_templates is empty

Deprecated:
since 1.4.21 Use WPDKScripts::enqueue_scripts_page_template() instead
Parameters
array$page_templatesArray of page slug template
string$handleThe script /unique) handle
bool$srcOptional. Source URI
array$depsOptional. Array of other handle
bool$verOptional. Version to avoid cache
bool$in_footerOptional. Load in footer
Returns
bool

Definition at line 550 of file wpdk-functions.php.

wpdk_get_image_from_attachments (   $id_post)

Get image from post attachment.

Get src url image from first image attachment post

Parameters
int$id_postID post
Returns
array|bool

Definition at line 380 of file wpdk-functions.php.

wpdk_get_image_from_post_thumbnail (   $id_post)

Get thumbnail image.

Function to find image using WP available function get_the_post_thumbnail().

Deprecated:
Since 1.3.1 Use _WPDKPost::thumbnail() or _WPDKPost::thumbnailWithID()
Parameters
int$id_postID post
Returns
mixed|null

Definition at line 359 of file wpdk-functions.php.

wpdk_get_image_in_post_content (   $id_post)

Get an img tag from the content.

Get the img src value fron content of a post or page.

Parameters
int$id_postID post
Returns
mixed

Definition at line 335 of file wpdk-functions.php.

wpdk_get_image_size (   $name)

Return registered image size information

Parameters
string$nameImage size ID
Returns
bool|array FALSE if not found Image size ID

Definition at line 160 of file wpdk-functions.php.

wpdk_get_user_transient (   $transient,
  $user_id = null 
)

Get.

Get the value of a user transient. If the transient does not exist or does not have a value, then the return value will be false.

Since
1.0.0
Deprecated:
since 1.4.8 - Use WPDKUser::getTransientWithUser()

apply_filters() Calls 'pre_user_transient_$transient' hook before checking the transient. Any value other than false will "short-circuit" the retrieval of the transient and return the returned value. apply_filters() Calls 'user_transient_$transient' hook, after checking the transient, with the transient value.

Parameters
string$transientTransient name. Expected to not be SQL-escaped
int$user_idOptional. User ID. If null the current user id is used instead
Returns
mixed Value of transient

Definition at line 610 of file wpdk-functions.php.

wpdk_is_ajax ( )

Ajax validation.

Return TRUE if we are called by Ajax. Used to be sure that we are responding to an HTTPRequest request and that the WordPress define DOING_AJAX is defined.

Returns
bool TRUE if Ajax trusted

Definition at line 87 of file wpdk-functions.php.

wpdk_is_bool (   $str)

Definition at line 33 of file wpdk-functions.php.

wpdk_is_child (   $parent = '')

Returns TRUE if the current page is a child of another.

Parameters
array | int | string$parentMixed format for parent page
Returns
bool TRUE if the current page is a child of another

Definition at line 109 of file wpdk-functions.php.

wpdk_is_infinity (   $value)

Definition at line 73 of file wpdk-functions.php.

wpdk_is_request (   $verb)

Check request.

Return true if the $verb param in input match with REQUEST METHOD

Since
1.1.0
Parameters
string$verbThe verb, for instance; GET, post, delete, etc...
Returns
bool

Definition at line 658 of file wpdk-functions.php.

wpdk_is_request_get ( )

Check if request is get.

Return true if the REQUEST METHOD is GET

Returns
bool

Definition at line 671 of file wpdk-functions.php.

wpdk_is_request_post ( )

Check if request is post.

Return true if the REQUEST METHOD is POST

Returns
bool

Definition at line 683 of file wpdk-functions.php.

wpdk_is_url (   $url)

Definition at line 51 of file wpdk-functions.php.

wpdk_permalink_page_with_slug (   $slug,
  $post_type = 'page' 
)

Get the post permalink from the slug.

Parameters
string$slugPost slug
string$post_typePost type. Default 'page'
Note
WPML compatible
See Also
get_page_by_path()
Returns
mixed|string Return the post permalink trailed. FLASE if not found

Definition at line 272 of file wpdk-functions.php.

wpdk_sanitize_function (   $key)

Sanitize for function name.

Return a possibile function name

Since
1.0.0.b3
Parameters
string$keyString key
Returns
mixed

Definition at line 148 of file wpdk-functions.php.

wpdk_selected (   $haystack,
  $current,
  $echo = true 
)

Commodity to extends selected() WordPress function with array check

Parameters
string | array$haystackSingle value or array
mixed$current(true) The other value to compare if not just true
bool$echoWhether to echo or just return the string
Returns
string html attribute or empty string
Deprecated:
Since 1.2.0 Use WPDKHTMLTagSelect::selected() instead

Definition at line 196 of file wpdk-functions.php.

wpdk_set_user_transient (   $transient,
  $value,
  $expiration = 0,
  $user_id = null 
)

Set.

Set/update the value of a user transient.

You do not need to serialize values. If the value needs to be serialized, then it will be serialized before it is set.

Since
1.0.0
Deprecated:
since 1.3.0 - Use WPDKUser::setTransientWithUser()

apply_filters() Calls 'pre_set_user_transient_$transient' hook to allow overwriting the transient value to be stored. do_action() Calls 'set_user_transient_$transient' and 'setted_transient' hooks on success.

Parameters
string$transientTransient name. Expected to not be SQL-escaped.
mixed$valueTransient value. Expected to not be SQL-escaped.
int$expirationTime until expiration in seconds, default 0
int$user_idOptional. User ID. If null the current user id is used instead
Returns
bool False if value was not set and true if value was set.

Definition at line 587 of file wpdk-functions.php.