Object Sync for Salesforce Code Documentation

Object_Sync_Sf_WordPress

Object_Sync_Sf_WordPress class.

Table of Contents

$debug  : string
Whether the plugin is in debug mode
$file  : string
The main plugin file
$logging  : object
Object_Sync_Sf_Logging class
$mappings  : object
Object_Sync_Sf_Mapping class
$option_prefix  : string
The plugin's prefix when saving options to the database
$options  : array<string|int, mixed>
Method call options
$sfwp_transients  : object
Object_Sync_Sf_WordPress_Transient class
$slug  : string
The plugin's slug so we can include it when necessary
$version  : string
Current version of the plugin
$wordpress_objects  : array<string|int, mixed>
Supported WordPress objects
$wpdb  : object
Global object of `$wpdb`, the WordPress database
__construct()  : mixed
Constructor for WordPress class
cache_expiration()  : 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
cache_get()  : mixed
Check to see if this API call exists in the cache if it does, return the transient for that key
cache_set()  : bool
Create a cache entry for the current result, with the url and args as the key
get_object_types()  : array<string|int, mixed>
Get WordPress object types
get_wordpress_object_data()  : array<string|int, mixed>
Get WordPress data based on what object it is
get_wordpress_object_fields()  : array<string|int, mixed>
Get WordPress fields for an object
get_wordpress_table_structure()  : array<string|int, mixed>
Get WordPress table structure for an object
object_create()  : array<string|int, mixed>
Create a new object of a given type.
object_delete()  : array<string|int, mixed>
Delete a WordPress object.
object_update()  : array<string|int, mixed>
Update an existing object. Part of CRUD for WordPress objects
object_upsert()  : array<string|int, mixed>
Create new records or update existing records.
append_tec_event_dates()  : array<string|int, mixed>
Generate date formats for The Event Calendar plugin
attachment_create()  : array<string|int, mixed>
Create a new WordPress attachment.
attachment_delete()  : mixed
Delete a WordPress attachment.
attachment_update()  : array<string|int, mixed>
Update a WordPress attachment.
attachment_upsert()  : array<string|int, mixed>
Create a new WordPress attachment or update it if a match is found.
comment_create()  : array<string|int, mixed>
Create a new WordPress comment.
comment_delete()  : bool
Delete a WordPress comment.
comment_update()  : array<string|int, mixed>
Update a WordPress comment.
comment_upsert()  : array<string|int, mixed>
Create a new WordPress comment or update it if a match is found.
create_wp_meta()  : array<string|int, mixed>
Standard method for creating meta values This works for users, posts, terms, and comments. It does not work for attachments.
object_fields()  : array<string|int, mixed>
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
post_create()  : array<string|int, mixed>
Create a new WordPress post.
post_delete()  : mixed
Delete a WordPress post.
post_update()  : array<string|int, mixed>
Update a WordPress post.
post_upsert()  : array<string|int, mixed>
Create a new WordPress post or update it if a match is found.
term_create()  : array<string|int, mixed>
Create a new WordPress term.
term_delete()  : bool
Delete a WordPress term.
term_update()  : array<string|int, mixed>
Update a WordPress term.
term_upsert()  : array<string|int, mixed>
Create a new WordPress term or update it if a match is found.
update_wp_meta()  : array<string|int, mixed>
Standard method for updating meta values This works for users, posts, terms, and comments. It does not work for attachments.
user_create()  : array<string|int, mixed>
Create a new WordPress user.
user_delete()  : bool
Delete a WordPress user.
user_update()  : array<string|int, mixed>
Update a WordPress user.
user_upsert()  : array<string|int, mixed>
Create a new WordPress user or update it if a match is found.

Properties

Methods

cache_expiration()

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

public cache_expiration(string $option_key, int $expire) : The
Parameters
$option_key : string

The cache item to keep around.

$expire : int

The default time after which to expire the cache.

Return values
The

cache expiration saved in the database.

cache_get()

Check to see if this API call exists in the cache if it does, return the transient for that key

public cache_get(string $url, array<string|int, mixed> $args) : mixed
Parameters
$url : string

The API call we'd like to make.

$args : array<string|int, mixed>

The arguents of the API call.

Return values
mixed

cache_set()

Create a cache entry for the current result, with the url and args as the key

public cache_set(string $url, array<string|int, mixed> $args, array<string|int, mixed> $data[, string $cache_expiration = '' ]) : bool
Parameters
$url : string

The API query URL.

$args : array<string|int, mixed>

The arguments passed on the API query.

$data : array<string|int, mixed>

The data received.

$cache_expiration : string = ''

How long to keep the cache result around for.

Tags
link
https://wordpress.stackexchange.com/questions/174330/transient-storage-location-database-xcache-w3total-cache
Return values
bool

whether or not the value was set

get_object_types()

Get WordPress object types

public get_object_types() : array<string|int, mixed>
Return values
array<string|int, mixed>

$wordpress_objects

get_wordpress_object_data()

Get WordPress data based on what object it is

public get_wordpress_object_data(string $object_type, int $object_id[, bool $is_deleted = false ]) : array<string|int, mixed>
Parameters
$object_type : string

The type of object.

$object_id : int

The ID of the object.

$is_deleted : bool = false

Whether the WordPress object has been deleted.

Return values
array<string|int, mixed>

$wordpress_object

get_wordpress_object_fields()

Get WordPress fields for an object

public get_wordpress_object_fields(string $wordpress_object[, string $id_field = 'ID' ]) : array<string|int, mixed>
Parameters
$wordpress_object : string

The type of WordPress object.

$id_field : string = 'ID'

The field of that object that corresponds with its ID in the database.

Return values
array<string|int, mixed>

$object_fields

get_wordpress_table_structure()

Get WordPress table structure for an object

public get_wordpress_table_structure(string $object_type) : array<string|int, mixed>
Parameters
$object_type : string

The type of object.

Return values
array<string|int, mixed>

$object_table_structure The table structure.

object_create()

Create a new object of a given type.

public object_create(string $name, array<string|int, mixed> $params) : array<string|int, mixed>
Parameters
$name : string

Object type name, E.g., user, post, comment.

$params : array<string|int, mixed>

Values of the fields to set for the object.

Return values
array<string|int, mixed>

data: id : 123, success : true errors : [ ], from_cache: cached: is_redo:

part of CRUD for WordPress objects

object_delete()

Delete a WordPress object.

public object_delete(string $name, int $id) : array<string|int, mixed>
Parameters
$name : string

Object type name, E.g., user, post, comment.

$id : int

WordPress id of the object.

Return values
array<string|int, mixed>

data: success: 1 "errors" : [ ],

part of CRUD for WordPress objects

object_update()

Update an existing object. Part of CRUD for WordPress objects

public object_update(string $name, int $id, array<string|int, mixed> $params[, array<string|int, mixed> $mapping_object = array() ]) : array<string|int, mixed>
Parameters
$name : string

Object type name, E.g., user, post, comment.

$id : int

WordPress id of the object.

$params : array<string|int, mixed>

Values of the fields to set for the object.

$mapping_object : array<string|int, mixed> = array()

is the object map connecting the records.

Return values
array<string|int, mixed>

data: success: 1 "errors" : [ ], from_cache: cached: is_redo:

object_upsert()

Create new records or update existing records.

public object_upsert(string $name, string $key, string $value[, array<string|int, mixed> $methods = array() ], array<string|int, mixed> $params[, bool $pull_to_drafts = false ][, bool $check_only = false ]) : array<string|int, mixed>

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.

Parameters
$name : string

Object type name, E.g., user, post, comment.

$key : string

The field to check if this record should be created or updated.

$value : string

The value for this record of the field specified for $key.

$methods : array<string|int, mixed> = array()

What WordPress methods do we use to get the data, if there are any. otherwise, maybe will have to do a wpdb query.

$params : array<string|int, mixed>

Values of the fields to set for the object.

$pull_to_drafts : bool = false

Whether to save to WordPress drafts when pulling from Salesforce.

$check_only : bool = false

Allows this method to only check for matching records, instead of making any data changes.

Return values
array<string|int, mixed>

data: "id" : 123, "success" : true "errors" : [ ], from_cache: cached: is_redo:

part of CRUD for WordPress objects

append_tec_event_dates()

Generate date formats for The Event Calendar plugin

private append_tec_event_dates(string $date, string $type, array<string|int, mixed> $content) : array<string|int, mixed>
Parameters
$date : string

the string value of the date from Salesforce.

$type : string

this should be start or end.

$content : array<string|int, mixed>

the other mapped params.

Return values
array<string|int, mixed>

$content

attachment_create()

Create a new WordPress attachment.

private attachment_create(array<string|int, mixed> $params[, string $id_field = 'ID' ]) : array<string|int, mixed>
Parameters
$params : array<string|int, mixed>

Array of attachment data params.

$id_field : string = 'ID'

Optional string of what the ID field is, if it is ever not ID.

Return values
array<string|int, mixed>

data: ID : 123, success: 1 "errors" : [ ],

attachment_delete()

Delete a WordPress attachment.

private attachment_delete(int $id[, bool $force_delete = false ]) : mixed
Parameters
$id : int

Attachment ID.

$force_delete : bool = false

If we should bypass the trash. We don't change this from FALSE anywhere in this plugin.

Return values
mixed

attachment object if successful, false if failed

attachment_update()

Update a WordPress attachment.

private attachment_update(string $attachment_id, array<string|int, mixed> $params[, string $id_field = 'ID' ]) : array<string|int, mixed>
Parameters
$attachment_id : string

The ID for the attachment to be updated. This value needs to be in the array that is sent to the update methods.

$params : array<string|int, mixed>

Array of attachment data params.

$id_field : string = 'ID'

Optional string of what the ID field is, if it is ever not ID.

Return values
array<string|int, mixed>

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_upsert()

Create a new WordPress attachment or update it if a match is found.

private attachment_upsert(string $key, string $value[, array<string|int, mixed> $methods = array() ], array<string|int, mixed> $params[, string $id_field = 'ID' ][, bool $check_only = false ]) : array<string|int, mixed>
Parameters
$key : string

What key we are looking at for possible matches.

$value : string

What value we are looking at for possible matches.

$methods : array<string|int, mixed> = array()

What WordPress methods do we use to get the data, if there are any. otherwise, maybe will have to do a wpdb query.

$params : array<string|int, mixed>

Array of attachment data params.

$id_field : string = 'ID'

Optional string of what the ID field is, if it is ever not ID.

$check_only : bool = false

Allows this method to only check for matching records, instead of making any data changes.

Return values
array<string|int, mixed>

data: ID : 123, success: 1 "errors" : [ ],

comment_create()

Create a new WordPress comment.

private comment_create(array<string|int, mixed> $params[, string $id_field = 'comment_ID' ]) : array<string|int, mixed>
Parameters
$params : array<string|int, mixed>

Array of comment data params.

$id_field : string = 'comment_ID'

Optional string of what the ID field is, if it is ever not comment_ID.

Return values
array<string|int, mixed>

data: ID : 123, success: 1 "errors" : [ ],

comment_delete()

Delete a WordPress comment.

private comment_delete(int $id[, bool $force_delete = false ]) : bool
Parameters
$id : int

Comment ID.

$force_delete : bool = false

If we should bypass the trash. We don't change this from FALSE anywhere in this plugin.

Return values
bool

true if successful, false if failed.

comment_update()

Update a WordPress comment.

private comment_update(int $comment_id, array<string|int, mixed> $params[, string $id_field = 'comment_ID' ]) : array<string|int, mixed>
Parameters
$comment_id : int

The ID for the comment to be updated. This value needs to be in the array that is sent to wp_update_comment.

$params : array<string|int, mixed>

Array of comment data params.

$id_field : string = 'comment_ID'

Optional string of what the ID field is, if it is ever not ID.

Return values
array<string|int, mixed>

data: success: 1 "errors" : [ ],

comment_upsert()

Create a new WordPress comment or update it if a match is found.

private comment_upsert(string $key, string $value, array<string|int, mixed> $methods, array<string|int, mixed> $params[, string $id_field = 'comment_ID' ][, bool $pull_to_drafts = false ][, bool $check_only = false ]) : array<string|int, mixed>
Parameters
$key : string

What key we are looking at for possible matches.

$value : string

What value we are looking at for possible matches.

$methods : array<string|int, mixed>

What WordPress methods do we use to get the data, if there are any. otherwise, maybe will have to do a wpdb query.

$params : array<string|int, mixed>

Array of comment data params.

$id_field : string = 'comment_ID'

Optional string of what the ID field is, if it is ever not comment_ID.

$pull_to_drafts : bool = false

Whether to save to WordPress drafts when pulling from Salesforce.

$check_only : bool = false

Allows this method to only check for matching records, instead of making any data changes.

Return values
array<string|int, mixed>

data: ID : 123, success: 1 "errors" : [ ],

create_wp_meta()

Standard method for creating meta values This works for users, posts, terms, and comments. It does not work for attachments.

private create_wp_meta(array<string|int, mixed> $params, int|wp_error $parent_object_id, string $parent_object_type) : array<string|int, mixed>
Parameters
$params : array<string|int, mixed>

the values to be saved.

$parent_object_id : int|wp_error

the WordPress object ID that this metadata is associated with. It shouldn't ever end up here as an error, but it's worth documenting.

$parent_object_type : string

the WordPress object type.

Return values
array<string|int, mixed>

$meta_result contains the success flag and the array of errors

object_fields()

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

private object_fields(string $object_name, string $id_field, string $content_table, array<string|int, mixed> $content_methods, string $meta_table, array<string|int, mixed> $meta_methods, string $where, array<string|int, mixed> $ignore_keys) : array<string|int, mixed>
Parameters
$object_name : string

THe name of the object type.

$id_field : string

The database filed that contains its ID.

$content_table : string

The table that normally contains such objects.

$content_methods : array<string|int, mixed>

Unused, but included as part of the return.

$meta_table : string

The table where meta values for this object type are contained.

$meta_methods : array<string|int, mixed>

Unused, but included as part of the return.

$where : string

SQL query.

$ignore_keys : array<string|int, mixed>

Fields to ignore from the database.

Return values
array<string|int, mixed>

$all_fields The fields for the object.

post_create()

Create a new WordPress post.

private post_create(array<string|int, mixed> $params[, string $id_field = 'ID' ][, string $post_type = 'post' ]) : array<string|int, mixed>
Parameters
$params : array<string|int, mixed>

Array of post data params.

$id_field : string = 'ID'

Optional string of what the ID field is, if it is ever not ID.

$post_type : string = 'post'

Optional string for custom post type, if applicable.

Return values
array<string|int, mixed>

data: ID : 123, success: 1 "errors" : [ ],

post_delete()

Delete a WordPress post.

private post_delete(int $id[, bool $force_delete = false ]) : mixed
Parameters
$id : int

Post ID.

$force_delete : bool = false

If we should bypass the trash. We don't change this from FALSE anywhere in this plugin.

Return values
mixed

post object if successful, false if failed

post_update()

Update a WordPress post.

private post_update(string $post_id, array<string|int, mixed> $params[, string $id_field = 'ID' ][, string $post_type = '' ]) : array<string|int, mixed>
Parameters
$post_id : string

The ID for the post to be updated. This value needs to be in the array that is sent to wp_update_post.

$params : array<string|int, mixed>

Array of post data params.

$id_field : string = 'ID'

Optional string of what the ID field is, if it is ever not ID.

$post_type : string = ''

Optional string for custom post type, if applicable.

Return values
array<string|int, mixed>

data: success: 1 "errors" : [ ],

post_upsert()

Create a new WordPress post or update it if a match is found.

private post_upsert(string $key, string $value[, array<string|int, mixed> $methods = array() ], array<string|int, mixed> $params[, string $id_field = 'ID' ][, bool $pull_to_drafts = false ][, string $post_type = 'post' ][, bool $check_only = false ]) : array<string|int, mixed>
Parameters
$key : string

What key we are looking at for possible matches.

$value : string

What value we are looking at for possible matches.

$methods : array<string|int, mixed> = array()

What WordPress methods do we use to get the data, if there are any. otherwise, maybe will have to do a wpdb query.

$params : array<string|int, mixed>

Array of post data params.

$id_field : string = 'ID'

optional string of what the ID field is, if it is ever not ID.

$pull_to_drafts : bool = false

Whether to save to WordPress drafts when pulling from Salesforce.

$post_type : string = 'post'

Optional string for custom post type, if applicable.

$check_only : bool = false

Allows this method to only check for matching records, instead of making any data changes.

Return values
array<string|int, mixed>

data: ID : 123, success: 1 "errors" : [ ],

term_create()

Create a new WordPress term.

private term_create(array<string|int, mixed> $params, string $taxonomy[, string $id_field = 'ID' ]) : array<string|int, mixed>
Parameters
$params : array<string|int, mixed>

Array of term data params.

$taxonomy : string

The taxonomy to which to add the term. this is required.

$id_field : string = 'ID'

Optional string of what the ID field is, if it is ever not ID.

Return values
array<string|int, mixed>

data: ID : 123, success: 1 "errors" : [ ],

term_delete()

Delete a WordPress term.

private term_delete(int $term_id, string $taxonomy) : bool
Parameters
$term_id : int

The ID for the term to be updated. This value needs to be in the array that is sent to wp_update_term.

$taxonomy : string

The taxonomy from which to delete the term. this is required.

Return values
bool

True if successful, false if failed.

term_update()

Update a WordPress term.

private term_update(int $term_id, array<string|int, mixed> $params, string $taxonomy[, string $id_field = 'ID' ]) : array<string|int, mixed>
Parameters
$term_id : int

The ID for the term to be updated. This value needs to be in the array that is sent to wp_update_term.

$params : array<string|int, mixed>

Array of term data params.

$taxonomy : string

The taxonomy to which to add the term. this is required.

$id_field : string = 'ID'

Optional string of what the ID field is, if it is ever not ID.

Return values
array<string|int, mixed>

data: success: 1 "errors" : [ ],

term_upsert()

Create a new WordPress term or update it if a match is found.

private term_upsert(string $key, string $value[, array<string|int, mixed> $methods = array() ], array<string|int, mixed> $params, string $taxonomy[, string $id_field = 'ID' ][, bool $pull_to_drafts = false ][, bool $check_only = false ]) : array<string|int, mixed>
Parameters
$key : string

What key we are looking at for possible matches.

$value : string

What value we are looking at for possible matches.

$methods : array<string|int, mixed> = array()

What WordPress methods do we use to get the data, if there are any. otherwise, maybe will have to do a wpdb query.

$params : array<string|int, mixed>

Array of term data params.

$taxonomy : string

The taxonomy to which to add the term. this is required..

$id_field : string = 'ID'

Optional string of what the ID field is, if it is ever not ID.

$pull_to_drafts : bool = false

Whether to save to WordPress drafts when pulling from Salesforce.

$check_only : bool = false

Allows this method to only check for matching records, instead of making any data changes.

Return values
array<string|int, mixed>

data: ID : 123, success: 1 "errors" : [ ],

update_wp_meta()

Standard method for updating meta values This works for users, posts, terms, and comments. It does not work for attachments.

private update_wp_meta(array<string|int, mixed> $params, int|wp_error $parent_object_id, string $parent_object_type) : array<string|int, mixed>
Parameters
$params : array<string|int, mixed>

the values to be saved.

$parent_object_id : int|wp_error

the WordPress object ID that this metadata is associated with. It shouldn't ever end up here as an error, but it's worth documenting.

$parent_object_type : string

the WordPress object type.

Return values
array<string|int, mixed>

$meta_result contains the success flag, the changed flag, and the array of errors

user_create()

Create a new WordPress user.

private user_create(array<string|int, mixed> $params[, string $id_field = 'ID' ]) : array<string|int, mixed>
Parameters
$params : array<string|int, mixed>

array of user data params.

$id_field : string = 'ID'

The column in the DB that holdes the user ID.

Return values
array<string|int, mixed>

data: ID : 123, success: 1 "errors" : [ ],

user_delete()

Delete a WordPress user.

private user_delete(int $id[, int $reassign = null ]) : bool
Parameters
$id : int

User ID.

$reassign : int = null

If we should reassign any posts to other users. We don't change this from NULL anywhere in this plugin.

Return values
bool

true if successful

user_update()

Update a WordPress user.

private user_update(string $user_id, array<string|int, mixed> $params[, string $id_field = 'ID' ]) : array<string|int, mixed>
Parameters
$user_id : string

The ID for the user to be updated. This value needs to be in the array that is sent to wp_update_user.

$params : array<string|int, mixed>

Array of user data params.

$id_field : string = 'ID'

Optional string of what the ID field is, if it is ever not ID.

Return values
array<string|int, mixed>

data: success: 1 "errors" : [ ],

user_upsert()

Create a new WordPress user or update it if a match is found.

private user_upsert(string $key, string $value[, array<string|int, mixed> $methods = array() ], array<string|int, mixed> $params[, string $id_field = 'ID' ][, bool $pull_to_drafts = false ][, bool $check_only = false ]) : array<string|int, mixed>
Parameters
$key : string

What key we are looking at for possible matches.

$value : string

What value we are looking at for possible matches.

$methods : array<string|int, mixed> = array()

What WordPress methods do we use to get the data, if there are any. otherwise, maybe will have to do a wpdb query.

$params : array<string|int, mixed>

Array of user data params. This is generated by Object_Sync_Sf_Mapping::map_params().

$id_field : string = 'ID'

Optional string of what the ID field is, if it is ever not ID.

$pull_to_drafts : bool = false

Whether to save to WordPress drafts when pulling from Salesforce.

$check_only : bool = false

Allows this method to only check for matching records, instead of making any data changes.

Return values
array<string|int, mixed>

data: ID : 123, success: 1 "errors" : [ ],

Search results