tp TouchPointWP TouchPointWP - TenthPres/TouchPoint-WP GitHub Wiki

tp\TouchPointWP\TouchPointWP

Main plugin class.


  • Full name: \tp\TouchPointWP\TouchPointWP

Constants

Constant Visibility Type Value
VERSION public "0.2.1"
TOKEN public "TouchPointWP"
SLUG public "touchpoint-wp"
DOCS_URL public "https://github.com/TenthPres/TouchPoint-WP/wiki"
API_ENDPOINT public "touchpoint-api"
API_ENDPOINT_APP_EVENTS public "app-events"
API_ENDPOINT_INVOLVEMENT public "inv"
API_ENDPOINT_GLOBAL public "global"
API_ENDPOINT_PERSON public "person"
API_ENDPOINT_MEETING public "mtg"
API_ENDPOINT_ADMIN public "admin"
API_ENDPOINT_STATS public "stats"
API_ENDPOINT_AUTH public "auth"
API_ENDPOINT_LOOKUP public "lookup"
API_ENDPOINT_REPORT public "report"
API_ENDPOINT_ADMIN_SCRIPTZIP public "admin/scriptzip"
API_ENDPOINT_CLEANUP public "cleanup"
API_ENDPOINT_BLOCKS public "blocks"
API_ENDPOINT_GEOLOCATE public "geolocate"
SHORTCODE_PREFIX public "TP-"
HOOK_PREFIX public "tp_"
INIT_ACTION_HOOK public "tp_init"
SETTINGS_PREFIX public "tp_"
TABLE_PREFIX public "tp_"
TABLE_IP_GEO public self::TABLE_PREFIX . "ipGeo"
TABLE_STATS public self::TABLE_PREFIX . "stats"
CACHE_TTL public 8 * 3600
CACHE_TTL_SHORT public 120
TTL_IP_GEO public 5
TTU_IP_GEO public 180
CACHE_PUBLIC public 0
CACHE_PRIVATE public 10
CACHE_NONE public 20
INVOLVEMENT_META_KEY public \tp\TouchPointWP\TouchPointWP::SETTINGS_PREFIX . "invId"

Properties

joiner

public static string $joiner
  • This property is static.

settings

Settings object

public ?\tp\TouchPointWP\Settings $settings

api

API object

public ?\tp\TouchPointWP\Api $api

file

The main plugin file.

public string $file

dir

The main plugin directory.

public static string $dir
  • This property is static.

assets_dir

The plugin assets directory.

public string $assets_dir

assets_url

The plugin assets URL, with trailing slash.

public string $assets_url

script_ext

Suffix for JavaScripts.

public string $script_ext

debug

public bool $debug

Methods

isApi

Indicates that the current request is being processed through the API.

public static isApi(): bool
  • This method is static.

cronAdd15Minutes

public static cronAdd15Minutes(mixed $schedules): mixed
  • This method is static. Parameters:
Parameter Type Description
$schedules mixed

pluginRowMeta

Adjust the meta info in the Plugin list with better information.

public static pluginRowMeta(mixed $pluginMeta, mixed $pluginFile, mixed $pluginData): array
  • This method is static. Parameters:
Parameter Type Description
$pluginMeta mixed array The links and stuff that gets joined by pipes.
$pluginFile mixed string Not used here, but points to the root plugin file.
$pluginData mixed array metadata from the plugin header.

capitalPyScript

Find and replace links to /pyscript with their more functional brother, /PyScript. That small typo makes bad things happen.

public static capitalPyScript(string|mixed $text): string
  • This method is static. Parameters:
Parameter Type Description
$text string|mixed The text to be modified. (should be a string, but this is WordPress, so maybe not.)

Return Value:

The modified text.


admin

public admin(): \tp\TouchPointWP\TouchPointWP_AdminAPI

scheduleCleanup

public static scheduleCleanup(): void
  • This method is static.

setCaching

public static setCaching(int $level): void
  • This method is static. Parameters:
Parameter Type Description
$level int

doCacheHeaders

Spit out headers that prevent caching. Useful for API calls.

public static doCacheHeaders(?int $cacheLevel = null): void
  • This method is static. Parameters:
Parameter Type Description
$cacheLevel ?int

postHeadersAndFiltering

public static postHeadersAndFiltering(): string
  • This method is static.

parseRequest

public parseRequest(bool $continue, \WP $wp, array|string $extraVars): bool

Parameters:

Parameter Type Description
$continue bool Whether to parse the request
$wp \WP Current WordPress environment instance
$extraVars array|string Passed query variables

Return Value:

Whether other request parsing functions should be allowed to function.


currentUserIsAdmin

Whether the current user is an admin.

public static currentUserIsAdmin(): bool
  • This method is static.

userHasEditingPermissions

Determine if the current user can edit anything and therefore may need access to wp-admin.

public static userHasEditingPermissions(?\WP_User $user = null): bool
  • This method is static. Parameters:
Parameter Type Description
$user ?\WP_User

printDynamicFooterScripts

Print Dynamic Instantiation scripts.

public printDynamicFooterScripts(): void

adminPrintStyleOverrides

Force some styling overrides into admin views.

public adminPrintStyleOverrides(): void

getJsLocalizationDir

public getJsLocalizationDir(): string

loadLocalizations

Load plugin textdomain

public loadLocalizations(): void

isTenth

A few things are only relevant for the mother ship. This is particularly for setting up telemetry.

public static isTenth(): bool
  • This method is static.

migrate

Compare the version numbers to determine if a migration is needed.

public migrate(mixed $force = false): void

Parameters:

Parameter Type Description
$force mixed

load

Load the settings, connect the references, and check that there aren't pending migrations.

public static load(mixed $file): \tp\TouchPointWP\TouchPointWP
  • This method is static. Parameters:
Parameter Type Description
$file mixed

init

Initialize the plugin.

public static init(): void
  • This method is static.

renderBaseInlineScript

Prints the inline 'base' script. This is meant to be called in the wp_head and admin_head, and should only be called once on a page, but that is not automatically validated.

public static renderBaseInlineScript(): void
  • This method is static.

registerScriptsAndStyles

public registerScriptsAndStyles(): void

requireScript

Enqueue TouchPoint Scripts. Also, always adds Base if it hasn't been added yet.

public static requireScript(?string $name = null): void
  • This method is static. Parameters:
Parameter Type Description
$name ?string

requireStyle

Enqueue TouchPoint Styles.

public static requireStyle(?string $name = null): void
  • This method is static. Parameters:
Parameter Type Description
$name ?string

filterByTag

Adds async/defer attributes to enqueued / registered scripts. If -defer or -async is present in the script's handle, the respective attribute is added.

public filterByTag(?string $tag, ?string $handle): string

DOES apply to ALL scripts, not just those in the template.

Parameters:

Parameter Type Description
$tag ?string The script tag.
$handle ?string The script handle.

Return Value:

The HTML string.


ajaxGeolocate

public ajaxGeolocate(): void

geolocate

public geolocate(bool $useApi = true, bool $includeRaw = false): \tp\TouchPointWP\Geo|false

Parameters:

Parameter Type Description
$useApi bool Set false to only use cached data, and not the IP API.
$includeRaw bool

Return Value:

An object with 'lat', 'lng', and 'human' attributes, if a location could be identified. Or, false if not available.


reverseGeocode

Get Reverse Geocode information based on a provided lat/lng.

public reverseGeocode(float $lat, float $lng, bool $includeIpLoc = true): \tp\TouchPointWP\Geo|false

Parameters:

Parameter Type Description
$lat float Latitude
$lng float Longitude
$includeIpLoc bool Whether to use IP geolocation as a fallback data source.

Return Value:

An object with a 'human' attribute, if a location could be identified. Or, false if not available.


getDivisionTermIdByDivId

public static getDivisionTermIdByDivId(int $divId): int|false
  • This method is static. Parameters:
Parameter Type Description
$divId int

Return Value:

Returns the term ID number or false (or 0) if the division is not found, or not enabled.


instance

Main TouchPointWP Instance

public static instance(mixed $file = ''): \tp\TouchPointWP\TouchPointWP

Ensures only one instance of TouchPointWP is loaded or can be loaded.

  • This method is static. Parameters:
Parameter Type Description
$file mixed

Return Value:

instance

See Also:

  • \tp\TouchPointWP\TouchPointWP()

__clone

Don't clone.

public __clone(): mixed

__wakeup

Don't deserialize.

public __wakeup(): mixed

activation

Activation. Runs on activation.

public activation(): void

deactivation

Deactivation. Runs on deactivation.

public deactivation(): void

uninstall

Runs on uninstallation.

public static uninstall(): void
  • This method is static.

useTribeCalendarPro

Indicates that Tribe Calendar Pro is enabled.

public static useTribeCalendarPro(): bool
  • This method is static.* Warning: this method is deprecated. This means that this method will likely be removed in a future version.

useTribeCalendar

Indicates that Tribe Calendar is enabled.

public static useTribeCalendar(): bool
  • This method is static.* Warning: this method is deprecated. This means that this method will likely be removed in a future version.

useTribeOrMeetingCalendars

Indicates that a calendar function is available, especially for the 2.0 mobile app option.

public static useTribeOrMeetingCalendars(): bool
  • This method is static.* Warning: this method is deprecated. This means that this method will likely be removed in a future version.

orderHierarchicalTerms

Sort a list of hierarchical terms into a list in which each parent is immediately followed by its children.

public static orderHierarchicalTerms(\WP_Term[] $terms, bool $noChildlessParents = false): \WP_Term[]
  • This method is static. Parameters:
Parameter Type Description
$terms \WP_Term[]
$noChildlessParents bool

host

public host(): ?string

Return Value:

The URL of the TouchPoint instance. Null if not set.


getMemberTypesForInvolvements

Get the member types currently in use for the given involvements.

public getMemberTypesForInvolvements(string[] $involvements = []): array

Parameters:

Parameter Type Description
$involvements string[]

getMemberTypesForDivisions

Get the member types currently in use for the named divisions.

public getMemberTypesForDivisions(string[] $divisions = [], bool $shortCache = false): array

Parameters:

Parameter Type Description
$divisions string[]
$shortCache bool Set to true to make it much more likely that the division cache will refresh.

getDivisionsAsKVArray

Format the list of divisions into an array with form-name-friendly IDs as the key.

public getDivisionsAsKVArray(bool $shortCache = false): string[]

Parameters:

Parameter Type Description
$shortCache bool

getImportedDivisions

Returns an array of objects that correspond to divisions that are actively being imported as a taxonomy. Each Division has a name and an id. The name is both the Program and Division.

public getImportedDivisions(): object[]

getDivisions

Returns an array of objects that correspond to divisions. Each Division has a name and an id. The name is both the Program and Division.

public getDivisions(bool $shortCache = false): array

Parameters:

Parameter Type Description
$shortCache bool Set to true to make it much more likely that the division cache will refresh.

getResCodes

Returns an array of objects that correspond to resident codes. Each ResCode has a name, a code, and an id.

public getResCodes(bool $shortCache = false): array

Parameters:

Parameter Type Description
$shortCache bool

getCampuses

Returns an array of objects that correspond to campuses. Each Campus has a name, a code, and an id.

public getCampuses(bool $shortCache = false): array

Parameters:

Parameter Type Description
$shortCache bool Set to true to shorten the expiry on the campus cache.

getInvolvementTypes

Returns an array of objects that correspond to TouchPoint Involvement Types. Each Involvement Type has an id and a description.

public getInvolvementTypes(): array

getGenders

Returns an array of objects that correspond to the genders. Each Gender has a name and an id.

public getGenders(): array

getKeywords

Returns an array of objects that correspond to keywords. Each Keyword has a name and an id.

public getKeywords(bool $shortCache = false): array

Parameters:

Parameter Type Description
$shortCache bool Set to true to make it much more likely that the division cache will refresh.

getKeywordsAsKVArray

Format the list of divisions into an array with form-name-friendly IDs as the key.

public getKeywordsAsKVArray(): string[]

getPersonEvFields

Returns an array of objects that correspond to Person Extra Value Fields. Each has a name and a type.

public getPersonEvFields(array|null $matches = null): array

Parameters:

Parameter Type Description
$matches array|null Provide an array of items that should be matched. If provided, only matches are
returned.

getPersonEvFieldsAsKVArray

Format the list of Person Extra Value Fields into an array with form-name-friendly IDs as the key.

public getPersonEvFieldsAsKVArray(string|null $type = null, bool $addNone = false): string[]

Parameters:

Parameter Type Description
$type string|null To limit the list to a particular data type, provide the name of the datatype.
Needs to match the type in TouchPoint.
$addNone bool Set true to add a "none" option to the list.

getFamilyEvFields

Returns an array of objects that correspond to Family Extra Value Fields. Each has a name and a type.

public getFamilyEvFields(array|null $matches = null): array

Parameters:

Parameter Type Description
$matches array|null Provide an array of items that should be matched. If provided, only matches are
returned.

getFamilyEvFieldsAsKVArray

Format the list of Family Extra Value Fields into an array with form-name-friendly IDs as the key.

public getFamilyEvFieldsAsKVArray(string|null $type = null, bool $addNone = false): string[]

Parameters:

Parameter Type Description
$type string|null To limit the list to a particular data type, provide the name of the datatype.
Needs to match the type in TouchPoint.
$addNone bool Set true to add a "none" option to the list.

currentUserPerson

Get the person that corresponds to the current user, if the current user is authenticated, and the user is associated with a PeopleId.

public static currentUserPerson(): \tp\TouchPointWP\Person|null
  • This method is static.

getSavedSearches

Get a list of saved searches pertinent to the current user. These are grouped by type: User's searches, Public, and Flags.

public getSavedSearches(?int $peopleId = null, mixed $includeValue = null): string[][]

Because these are user-specific and relatively volatile, they are NOT cached in WordPress.

Parameters:

Parameter Type Description
$peopleId ?int
$includeValue mixed

flattenArrayToKV

public static flattenArrayToKV(array $array, string $kField, string $vField, string $kPrefix = ''): array
  • This method is static. Parameters:
Parameter Type Description
$array array
$kField string
$vField string
$kPrefix string

updatePersonEvFields

Update the Person Extra Values if they're stale.

public updatePersonEvFields(): false|object

Return Value:

False on failure


updateFamilyEvFields

Update the Person Extra Values if they're stale.

public updateFamilyEvFields(): false|object

Return Value:

False on failure.


apiGet

public apiGet(string $command, ?array $parameters = null, int $timeout = 5, mixed $verbose = false): \stdClass|array
  • Warning: this method is deprecated. This means that this method will likely be removed in a future version. Parameters:
Parameter Type Description
$command string The thing to get
$parameters ?array URL parameters to be added.
$timeout int Amount of time in sec to wait before timing out.
$verbose mixed

Return Value:

An array with headers, body, and other keys Data is generally in json_decode($response['body'])->data

Throws:

Thrown if the API credentials are incomplete.


apiPost

public apiPost(string $command, ?mixed $data = null, int $timeout = 5): \stdClass|array
  • Warning: this method is deprecated. This means that this method will likely be removed in a future version. Parameters:
Parameter Type Description
$command string The thing to post
$data ?mixed Data to post
$timeout int Amount of time in sec to wait before timing out.

Return Value:

An object that corresponds to the Data python object in TouchPoint.

Throws:

If anything went wrong.


extGet

public extGet(string $url, ?array $parameters = null): array

Parameters:

Parameter Type Description
$url string The destination of the request.
$parameters ?array URL parameters to be added.

Return Value:

An array with headers, body, and other keys.

Throws:

If there's an issue.


doPersonCount

Submit a person query to TouchPoint with a structured array with the parameters.

public doPersonCount(array $q, int $timeout = 5): int

Parameters:

Parameter Type Description
$q array
$timeout int

Return Value:

The number of people returned.

Throws:

Upon failure.


doPersonQuery

Submit a person query to TouchPoint with a structured array with the parameters.

public doPersonQuery(array $q, bool $verbose = false, int $timeout = 5): \stdClass

Parameters:

Parameter Type Description
$q array
$verbose bool
$timeout int

Return Value:

The people objects are contained within ->people.

Throws:

Upon failure.


queueUpdateDeployedScripts

Cause a script update on next load.

public static queueUpdateDeployedScripts(): void
  • This method is static.

updateDeployedScripts

public updateDeployedScripts(bool $force = false): void

Parameters:

Parameter Type Description
$force bool

See Also:

  • \tp\TouchPointWP\queueUpdateDeployedScripts

queueFlushRewriteRules

Cause a flushing of rewrite rules on next load.

public static queueFlushRewriteRules(): void
  • This method is static.

flushRewriteRules

Execute a flushing of the rewrite rules, if either absolutely necessary ($force = true) or enqueued by queuing function.

public flushRewriteRules(bool $force = true): void

Parameters:

Parameter Type Description
$force bool

See Also:

  • \tp\TouchPointWP\queueFlushRewriteRules()

enqueuePartialsStyle

This function enqueues the stylesheet for the default templates, to avoid registering the style on sites where custom templates exist.

public static enqueuePartialsStyle(?string $context = null): void
  • This method is static. Parameters:
Parameter Type Description
$context ?string

includePartialsStyle

Determines if the partials style should be rendered.

public static includePartialsStyle(string|null $context = null): bool
  • This method is static. Parameters:
Parameter Type Description
$context string|null

enqueueActionsStyle

This function enqueues the stylesheet for actions (swal, basically).

public static enqueueActionsStyle(string $action): void
  • This method is static. Parameters:
Parameter Type Description
$action string This string identifies which action is being used. This should be passed to the filter so
the filter can make an informed decision about whether to exclude the stylesheet.

includeActionsStyle

Determines if the actions style should be rendered.

public static includeActionsStyle(string $action): bool
  • This method is static. Parameters:
Parameter Type Description
$action string

newQueryObject

Create a basic parameter array for doPersonQuery

public static newQueryObject(): array
  • This method is static. See Also:

  • \tp\TouchPointWP\doPersonQuery


validateThatTpWpUserExists

public validateThatTpWpUserExists(): bool

Throws:


setTpWpUserAsCurrent

Make the TPWP user the active one, so permissions are not dependent on whoever happens to be running things at the moment.

public setTpWpUserAsCurrent(): void

logoutServiceMaybe

If the current user is somehow making requests as the TouchPoint service, log out (or switch back to the proper user)

public logoutServiceMaybe(): void

unsetTpWpUserAsCurrent

Restore the actual user to the user position.

public unsetTpWpUserAsCurrent(): void

handlePhpShutdown

Deal with the fallout should PHP timeout, probably on a sync operation. This needs to be very VERY graceful since its tied into fatal error handling.

public static handlePhpShutdown(): void
  • This method is static.