$wpdb
$wpdb :
Work with the WordPress $wpdb object. This class can make read and write calls to the WordPress database, and also cache the responses.
__construct(object $wpdb, string $version, string $slug, object $mappings, object $logging, string $option_prefix = '')
Constructor which discovers objects in WordPress
| object | $wpdb | A wpdb object. |
| string | $version | The plugin version. |
| string | $slug | The plugin slug. |
| object | $mappings | Mapping objects. |
| object | $logging | a Object_Sync_Sf_Logging instance. |
| string | $option_prefix | The plugin's option prefix |
get_object_types() : array
Get WordPress object types
Warning: count(): Parameter must be an array or an object that implements Countable in phar:///Users/jstegall/Sites/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1293 Warning: count(): Parameter must be an array or an object that implements Countable in phar:///Users/jstegall/Sites/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1293$wordpress_objects
get_wordpress_table_structure(string $object_type) : array
Get WordPress table structure for an object
| string | $object_type | The type of object. |
$object_table_structure The table structure.
get_wordpress_object_fields(string $wordpress_object, string $id_field = 'ID') : array
Get WordPress fields for an object
| string | $wordpress_object | The type of WordPress object. |
| string | $id_field | The field of that object that corresponds with its ID in the database. |
$object_fields
get_wordpress_object_data(string $object_type, string $object_id, boolean $is_deleted = false) : array
Get WordPress data based on what object it is
| string | $object_type | The type of object. |
| string | $object_id | The ID of the object. |
| boolean | $is_deleted | Whether the WordPress object has been deleted |
$wordpress_object
cache_get(string $url, array $args) : \$this->sfwp_transients->get
Check to see if this API call exists in the cache if it does, return the transient for that key
| string | $url | The API call we'd like to make. |
| array | $args | The arguents of the API call. |
$cachekey
cache_set(string $url, array $args, array $data, string $cache_expiration = '') : Bool
Create a cache entry for the current result, with the url and args as the key
| string | $url | The API query URL. |
| array | $args | The arguments passed on the API query. |
| array | $data | The data received. |
| string | $cache_expiration | How long to keep the cache result around for. |
whether or not the value was set
cache_expiration(string $option_key, integer $expire) : \The
If there is a WordPress setting for how long to keep this specific cache, return it and set the object property Otherwise, return seconds in 24 hours
| string | $option_key | The cache item to keep around. |
| integer | $expire | The default time after which to expire the cache. |
cache expiration saved in the database.
object_create(string $name, array $params) : array
Create a new object of a given type.
| string | $name | Object type name, E.g., user, post, comment. |
| array | $params | Values of the fields to set for the object. |
data: id : 123, success : true errors : [ ], from_cache: cached: is_redo:
part of CRUD for WordPress objects
object_upsert(string $name, string $key, string $value, array $methods = array(), array $params, boolean $pull_to_drafts = false, boolean $check_only = false) : array
Create new records or update existing records.
The new records or updated records are based on the value of the specified field. If the value is not unique, REST API returns a 300 response with the list of matching records.
| string | $name | Object type name, E.g., user, post, comment. |
| string | $key | The field to check if this record should be created or updated. |
| string | $value | The value for this record of the field specified for $key. |
| array | $methods | What WordPress methods do we use to get the data, if there are any. otherwise, maybe will have to do a wpdb query. |
| array | $params | Values of the fields to set for the object. |
| boolean | $pull_to_drafts | Whether to save to WordPress drafts when pulling from Salesforce. |
| boolean | $check_only | Allows this method to only check for matching records, instead of making any data changes. |
data: "id" : 123, "success" : true "errors" : [ ], from_cache: cached: is_redo:
part of CRUD for WordPress objects
object_update(string $name, string $id, array $params) : array
Update an existing object.
| string | $name | Object type name, E.g., user, post, comment. |
| string | $id | WordPress id of the object. |
| array | $params | Values of the fields to set for the object. part of CRUD for WordPress objects |
data: success: 1 "errors" : [ ], from_cache: cached: is_redo:
object_delete(string $name, string $id) : array
Delete a WordPress object.
| string | $name | Object type name, E.g., user, post, comment. |
| string | $id | WordPress id of the object. |
data: success: 1 "errors" : [ ],
part of CRUD for WordPress objects
object_fields(string $object_name, string $id_field, string $content_table, array $content_methods, string $meta_table, array $meta_methods, string $where, array $ignore_keys) : array
Get all the fields for an object The important thing here is returning the fields as an array: $all_fields = array( 'key' => 'key name', 'table' => 'table name', 'methods' => array( 'create' => '', 'read' => '', 'update' => '', 'delete' => '' ) ); if there's a better way to do this than the mess of queries below, we should switch to that when we can we just need to make sure we get all applicable fields for the object itself, as well as its meta fields
| string | $object_name | THe name of the object type. |
| string | $id_field | The database filed that contains its ID. |
| string | $content_table | The table that normally contains such objects. |
| array | $content_methods | Unused, but included as part of the return. |
| string | $meta_table | The table where meta values for this object type are contained. |
| array | $meta_methods | Unused, but included as part of the return. |
| string | $where | SQL query. |
| array | $ignore_keys | Fields to ignore from the database. |
$all_fields The fields for the object.
user_create(array $params, string $id_field = 'ID') : array
Create a new WordPress user.
| array | $params | array of user data params. |
| string | $id_field | The column in the DB that holdes the user ID. |
data: ID : 123, success: 1 "errors" : [ ],
user_upsert(string $key, string $value, array $methods = array(), array $params, string $id_field = 'ID', boolean $pull_to_drafts = false, boolean $check_only = false) : array
Create a new WordPress user or update it if a match is found.
| string | $key | What key we are looking at for possible matches. |
| string | $value | What value we are looking at for possible matches. |
| array | $methods | What WordPress methods do we use to get the data, if there are any. otherwise, maybe will have to do a wpdb query. |
| array | $params | Array of user data params. This is generated by Object_Sync_Sf_Mapping::map_params(). |
| string | $id_field | Optional string of what the ID field is, if it is ever not ID. |
| boolean | $pull_to_drafts | Whether to save to WordPress drafts when pulling from Salesforce. |
| boolean | $check_only | Allows this method to only check for matching records, instead of making any data changes. |
data: ID : 123, success: 1 "errors" : [ ],
user_update(string $user_id, array $params, string $id_field = 'ID') : array
Update a WordPress user.
| string | $user_id | The ID for the user to be updated. This value needs to be in the array that is sent to wp_update_user. |
| array | $params | Array of user data params. |
| string | $id_field | Optional string of what the ID field is, if it is ever not ID. |
data: success: 1 "errors" : [ ],
user_delete(integer $id, integer $reassign = null) : boolean
Delete a WordPress user.
| integer | $id | User ID. |
| integer | $reassign | If we should reassign any posts to other users. We don't change this from NULL anywhere in this plugin. |
true if successful
post_create(array $params, string $id_field = 'ID', string $post_type = 'post') : array
Create a new WordPress post.
| array | $params | Array of post data params. |
| string | $id_field | Optional string of what the ID field is, if it is ever not ID. |
| string | $post_type | Optional string for custom post type, if applicable. |
data: ID : 123, success: 1 "errors" : [ ],
post_upsert(string $key, string $value, array $methods = array(), array $params, string $id_field = 'ID', boolean $pull_to_drafts = false, string $post_type = 'post', boolean $check_only = false) : array
Create a new WordPress post or update it if a match is found.
| string | $key | What key we are looking at for possible matches. |
| string | $value | What value we are looking at for possible matches. |
| array | $methods | What WordPress methods do we use to get the data, if there are any. otherwise, maybe will have to do a wpdb query. |
| array | $params | Array of post data params. |
| string | $id_field | optional string of what the ID field is, if it is ever not ID. |
| boolean | $pull_to_drafts | Whether to save to WordPress drafts when pulling from Salesforce. |
| string | $post_type | Optional string for custom post type, if applicable. |
| boolean | $check_only | Allows this method to only check for matching records, instead of making any data changes. |
data: ID : 123, success: 1 "errors" : [ ],
post_update(string $post_id, array $params, string $id_field = 'ID', string $post_type = '') : array
Update a WordPress post.
| string | $post_id | The ID for the post to be updated. This value needs to be in the array that is sent to wp_update_post. |
| array | $params | Array of post data params. |
| string | $id_field | Optional string of what the ID field is, if it is ever not ID. |
| string | $post_type | Optional string for custom post type, if applicable. |
data: success: 1 "errors" : [ ],
post_delete(integer $id, boolean $force_delete = false) : mixed
Delete a WordPress post.
| integer | $id | Post ID. |
| boolean | $force_delete | If we should bypass the trash. We don't change this from FALSE anywhere in this plugin. |
post object if successful, false if failed
attachment_create(array $params, string $id_field = 'ID') : array
Create a new WordPress attachment.
| array | $params | Array of attachment data params. |
| string | $id_field | Optional string of what the ID field is, if it is ever not ID. |
data: ID : 123, success: 1 "errors" : [ ],
attachment_upsert(string $key, string $value, array $methods = array(), array $params, string $id_field = 'ID', boolean $check_only = false) : array
Create a new WordPress attachment or update it if a match is found.
| string | $key | What key we are looking at for possible matches. |
| string | $value | What value we are looking at for possible matches. |
| array | $methods | What WordPress methods do we use to get the data, if there are any. otherwise, maybe will have to do a wpdb query. |
| array | $params | Array of attachment data params. |
| string | $id_field | Optional string of what the ID field is, if it is ever not ID. |
| boolean | $check_only | Allows this method to only check for matching records, instead of making any data changes. |
data: ID : 123, success: 1 "errors" : [ ],
attachment_update(string $attachment_id, array $params, string $id_field = 'ID') : array
Update a WordPress attachment.
| string | $attachment_id | The ID for the attachment to be updated. This value needs to be in the array that is sent to the update methods. |
| array | $params | Array of attachment data params. |
| string | $id_field | Optional string of what the ID field is, if it is ever not ID. |
data: success: 1 "errors" : [ ],
Note: this method uses wp_insert_attachment for core content fields as there isn't a corresponding method for updating these rows it does use wp_update_attachment_metadata for the meta fields, though. Developers should use hooks to change this, if it does not meet their needs.
attachment_delete(integer $id, boolean $force_delete = false) : mixed
Delete a WordPress attachment.
| integer | $id | Attachment ID. |
| boolean | $force_delete | If we should bypass the trash. We don't change this from FALSE anywhere in this plugin. |
attachment object if successful, false if failed
term_create(array $params, string $taxonomy, string $id_field = 'ID') : array
Create a new WordPress term.
| array | $params | Array of term data params. |
| string | $taxonomy | The taxonomy to which to add the term. this is required. |
| string | $id_field | Optional string of what the ID field is, if it is ever not ID. |
data: ID : 123, success: 1 "errors" : [ ],
term_upsert(string $key, string $value, array $methods = array(), array $params, string $taxonomy, string $id_field = 'ID', boolean $pull_to_drafts = false, boolean $check_only = false) : array
Create a new WordPress term or update it if a match is found.
| string | $key | What key we are looking at for possible matches. |
| string | $value | What value we are looking at for possible matches. |
| array | $methods | What WordPress methods do we use to get the data, if there are any. otherwise, maybe will have to do a wpdb query. |
| array | $params | Array of term data params. |
| string | $taxonomy | The taxonomy to which to add the term. this is required.. |
| string | $id_field | Optional string of what the ID field is, if it is ever not ID. |
| boolean | $pull_to_drafts | Whether to save to WordPress drafts when pulling from Salesforce. |
| boolean | $check_only | Allows this method to only check for matching records, instead of making any data changes. |
data: ID : 123, success: 1 "errors" : [ ],
term_update(string $term_id, array $params, string $taxonomy, string $id_field = 'ID') : array
Update a WordPress term.
| string | $term_id | The ID for the term to be updated. This value needs to be in the array that is sent to wp_update_term. |
| array | $params | Array of term data params. |
| string | $taxonomy | The taxonomy to which to add the term. this is required. |
| string | $id_field | Optional string of what the ID field is, if it is ever not ID. |
data: success: 1 "errors" : [ ],
term_delete(string $term_id, string $taxonomy) : boolean
Delete a WordPress term.
| string | $term_id | The ID for the term to be updated. This value needs to be in the array that is sent to wp_update_term. |
| string | $taxonomy | The taxonomy from which to delete the term. this is required. |
True if successful, false if failed.
comment_create(array $params, string $id_field = 'comment_ID') : array
Create a new WordPress comment.
| array | $params | Array of comment data params. |
| string | $id_field | Optional string of what the ID field is, if it is ever not comment_ID. |
data: ID : 123, success: 1 "errors" : [ ],
comment_upsert(string $key, string $value, array $methods, array $params, string $id_field = 'comment_ID', boolean $pull_to_drafts = false, boolean $check_only = false) : array
Create a new WordPress comment or update it if a match is found.
| string | $key | What key we are looking at for possible matches. |
| string | $value | What value we are looking at for possible matches. |
| array | $methods | What WordPress methods do we use to get the data, if there are any. otherwise, maybe will have to do a wpdb query. |
| array | $params | Array of comment data params. |
| string | $id_field | Optional string of what the ID field is, if it is ever not comment_ID. |
| boolean | $pull_to_drafts | Whether to save to WordPress drafts when pulling from Salesforce. |
| boolean | $check_only | Allows this method to only check for matching records, instead of making any data changes. |
data: ID : 123, success: 1 "errors" : [ ],
comment_update(string $comment_id, array $params, string $id_field = 'comment_ID') : array
Update a WordPress comment.
| string | $comment_id | The ID for the comment to be updated. This value needs to be in the array that is sent to wp_update_comment. |
| array | $params | Array of comment data params. |
| string | $id_field | Optional string of what the ID field is, if it is ever not ID. |
data: success: 1 "errors" : [ ],
comment_delete(integer $id, boolean $force_delete = false) : boolean
Delete a WordPress comment.
| integer | $id | Comment ID. |
| boolean | $force_delete | If we should bypass the trash. We don't change this from FALSE anywhere in this plugin. |
true if successful, false if failed.