Cp_Plgn_Drctry_Plugin_Fx
in package
Uses
Cp_Plgn_Drctry_Fx, Cp_Plgn_Drctry_GitHub, Cp_Plgn_Drctry_Cp_Api, Cp_Plgn_Drctry_Cp_Api_v2
Class to handle helper Functions for Plugin Management.
Description
Adds functions for: Install Plugins Activate Plugins Deactivate Plugins Delete Plugins Update Plugins Check if has update Check if is installed Check if is active Create safe Plugin slug
Tags
Table of Contents
- $plugins_cache_file : string
- The Plugins Cache File path.
- $cp_dir_url : string
- The ClassicPress API URL.
- $cp_dir_url_v2 : string
- The ClassicPress API URL V2.
- $options : array<string|int, mixed>
- The Options of this Plugin.
- $plugin_name : string
- The ID of this plugin.
- $plugin_prefix : string
- The unique prefix of this plugin.
- $plugins_topic : string
- The Topics searched for.
- $readme_vars : array<string|int, mixed>
- The Variations of readmes supported.
- $version : string
- The version of this plugin.
- __construct() : mixed
- Initialize the class and set its properties.
- activate_cp_plugin() : mixed
- Activate a Plugin.
- check_plugin_active() : bool
- Check if plugin is active.
- check_plugin_installed() : bool
- Helper function to check if plugin is installed.
- cron_get_plugins() : mixed
- Provide a minimal function for CRON Operation. We cannot really do any safety checks here.
- deactivate_cp_plugin() : mixed
- Deactivate a Plugin.
- delete_cp_plugin() : mixed
- Delete a Plugin.
- get_plugins() : mixed
- Merge all Plugins from all APIs.
- has_update() : bool
- Helper function to check if plugin has update.
- install_cp_plugin() : mixed
- Install a Plugin.
- plugin_slug() : string
- Is Plugin active and installed.
- update_cp_plugin() : mixed
- Update a Plugin.
- adjust_v2_api() : mixed
- The new api is not like the old api.
- build_git_plugin_object() : object
- Build a CP APi compatible object of repository data.
- build_git_plugins_objects() : array<string|int, mixed>
- Build a CP APi compatible array of objects of repository data.
- encode_to_json() : mixed
- Encode data to JSON or return empty string.
- get_content_between() : string
- Get string value between delimiters.
- get_cp_pages() : array<string|int, mixed>
- Build an array of Pages of the GitHub Results.
- get_cp_pages_v2() : array<string|int, mixed>
- Build an array of Pages of the GitHub Results.
- get_cp_plugins() : array<string|int, mixed>
- Retrieve all plugins from the CP API.
- get_cp_plugins_v2() : array<string|int, mixed>
- Retrieve all plugins from the CP API.
- get_file_contents() : mixed
- CP Way of getting File Contents.
- get_gh_pages() : int
- Get all pages of the results found.
- get_git_dev_info() : array<string|int, mixed>
- Get developer info from Github.
- get_git_plugins() : mixed
- Get all Git Plugins Public function.
- get_git_release_data() : array<string|int, mixed>
- Get Release Data from GitHub
- get_git_repos() : array<string|int, mixed>
- Get Plugins stored on Git.
- get_posted_data() : mixed
- Validates any POSTed nonce by key and nonce.
- get_readme_data() : string
- Get readme data
- get_readme_name() : string
- Get the "name" of the plugin - assumed to be first text following a '# ' in the readme.
- get_remote_decoded_body() : mixed
- Get Remote body json decoded.
- get_remote_header() : mixed
- Get Remote header.
- get_remote_raw_body() : mixed
- Get Remote body json decoded.
- list_pagination() : mixed
- Create a paginated list out of an array of items
- maybe_populate_cache() : mixed
- Maybe populate cache file.
- maybe_send_json_failure() : mixed
- Validates any POSTed nonce by key and nonce.
- put_file_contents() : mixed
- CP Way of putting File Contentes.
- search_form() : mixed
- Create a safe HTML search form input
- set_auth() : mixed
- If available, get GitHub Auth Token.
- validate_get_nonce() : mixed
- Validates any GET nonce by key and nonce.
- validate_post_nonce() : mixed
- Validates any POSTed nonce by key and nonce.
- vetted_orgs() : array<string|int, mixed>
- Get a list of vetted orgs
Properties
$plugins_cache_file
The Plugins Cache File path.
public
string
$plugins_cache_file
Description
The File used by this plugin to store the Plugins in a cache.
Tags
$cp_dir_url
The ClassicPress API URL.
private
string
$cp_dir_url
Description
The URL used by ClassicPress to present its API.
Tags
$cp_dir_url_v2
The ClassicPress API URL V2.
private
string
$cp_dir_url_v2
Description
The URL used by ClassicPress to present its API since v2.
Tags
$options
The Options of this Plugin.
private
array<string|int, mixed>
$options
Description
The options stored by the user for this plugin.
Tags
$plugin_name
The ID of this plugin.
private
string
$plugin_name
Description
The ID of this plugin.
Tags
$plugin_prefix
The unique prefix of this plugin.
private
string
$plugin_prefix
Description
The string used to uniquely prefix technical functions of this plugin.
Tags
$plugins_topic
The Topics searched for.
private
string
$plugins_topic
Description
The Topic searched for in the Github repos.
Tags
$readme_vars
The Variations of readmes supported.
private
array<string|int, mixed>
$readme_vars
Description
The different variations of readme supported by the plugin.
Tags
$version
The version of this plugin.
private
string
$version
Description
The current version of this plugin.
Tags
Methods
__construct()
Initialize the class and set its properties.
public
__construct(string $plugin_name, string $plugin_prefix, string $version) : mixed
Parameters
- $plugin_name
- (string) The name of this plugin.
- $plugin_prefix
- (string) The unique prefix of this plugin.
- $version
- (string) The version of this plugin.
Tags
Return
(mixed)activate_cp_plugin()
Activate a Plugin.
public
activate_cp_plugin() : mixed
Return
(mixed)check_plugin_active()
Check if plugin is active.
public
check_plugin_active(object $plugin) : bool
Parameters
- $plugin
- (object) The Current Plugin Object.
Return
(bool) $is_active If the Plugin is active.check_plugin_installed()
Helper function to check if plugin is installed.
public
check_plugin_installed(object $plugin) : bool
Parameters
- $plugin
- (object) The Current Plugin Object.
Return
(bool) $is_installed If the plugin is installed or not.cron_get_plugins()
Provide a minimal function for CRON Operation. We cannot really do any safety checks here.
public
cron_get_plugins() : mixed
Tags
Return
(mixed)deactivate_cp_plugin()
Deactivate a Plugin.
public
deactivate_cp_plugin() : mixed
Return
(mixed)delete_cp_plugin()
Delete a Plugin.
public
delete_cp_plugin() : mixed
Return
(mixed)get_plugins()
Merge all Plugins from all APIs.
public
get_plugins() : mixed
Return
(mixed)has_update()
Helper function to check if plugin has update.
public
has_update(object $plugins) : bool
Parameters
- $plugins
- (object) All Plugin Objects in array.
Return
(bool) $is_installed If the plugin is installed or not.install_cp_plugin()
Install a Plugin.
public
install_cp_plugin([bool $overwrite = false ]) : mixed
Parameters
- $overwrite
-
(bool) Whether to overwrite the plugin or not. Default False. Defaults to:
false
Tags
Return
(mixed)plugin_slug()
Is Plugin active and installed.
public
plugin_slug(object $plugin) : string
Parameters
- $plugin
- (object) The Current Plugin Object.
Return
(string) $plugin_slug The Plugin Slug.update_cp_plugin()
Update a Plugin.
public
update_cp_plugin() : mixed
Return
(mixed)adjust_v2_api()
The new api is not like the old api.
private
adjust_v2_api(array<string|int, mixed> $data) : mixed
Description
Fix that by rebuilding the single plugin objects.
Parameters
- $data
- (array<string|int, mixed>) The raw data array from remote.
Return
(mixed)build_git_plugin_object()
Build a CP APi compatible object of repository data.
private
build_git_plugin_object(array<string|int, mixed> $repo_object, array<string|int, mixed> $_data) : object
Parameters
- $repo_object
- (array<string|int, mixed>) The repositories found by the query.
- $_data
- (array<string|int, mixed>) Array placeholder to cache remote Developer.
Return
(object) $git_plugins An object of Repo data.build_git_plugins_objects()
Build a CP APi compatible array of objects of repository data.
private
build_git_plugins_objects(array<string|int, mixed> $repos, array<string|int, mixed> $_data) : array<string|int, mixed>
Parameters
- $repos
- (array<string|int, mixed>) The repositories found by the query.
- $_data
- (array<string|int, mixed>) Array placeholder to cache remote Developer.
Return
(array<string|int, mixed>) $git_plugins An array of repository data Objects.encode_to_json()
Encode data to JSON or return empty string.
private
encode_to_json(mixed $data) : mixed
Parameters
- $data
- (mixed) The Data to encode.
Return
(mixed)get_content_between()
Get string value between delimiters.
private
get_content_between(string $str, string $start_delimiter, string $end_delimiter) : string
Parameters
- $str
- (string) The string to scan.
- $start_delimiter
- (string) The start delimiter to look for.
- $end_delimiter
- (string) The end delimiter to look for.
Return
(string) The string between.get_cp_pages()
Build an array of Pages of the GitHub Results.
private
get_cp_pages() : array<string|int, mixed>
Return
(array<string|int, mixed>) $pages The found page numbers in array.get_cp_pages_v2()
Build an array of Pages of the GitHub Results.
private
get_cp_pages_v2() : array<string|int, mixed>
Return
(array<string|int, mixed>) $pages The found page numbers in array.get_cp_plugins()
Retrieve all plugins from the CP API.
private
get_cp_plugins() : array<string|int, mixed>
Return
(array<string|int, mixed>) $all_cp_plugins An array of all plugins objects.get_cp_plugins_v2()
Retrieve all plugins from the CP API.
private
get_cp_plugins_v2() : array<string|int, mixed>
Return
(array<string|int, mixed>) $all_cp_plugins An array of all plugins objects.get_file_contents()
CP Way of getting File Contents.
private
get_file_contents(string $file) : mixed
Parameters
- $file
- (string) The file path to get contents from.
Return
(mixed)get_gh_pages()
Get all pages of the results found.
private
get_gh_pages(array<string|int, mixed> $response) : int
Parameters
- $response
- (array<string|int, mixed>) the WP Remote Get Response.
Return
(int) $last_page The last (amount of) page found.get_git_dev_info()
Get developer info from Github.
private
get_git_dev_info(string $login, string $type) : array<string|int, mixed>
Parameters
- $login
- (string) The Github "slug".
- $type
- (string) The Github domain type.
Return
(array<string|int, mixed>) $dev_array A CP API Compatible "developer" array.get_git_plugins()
Get all Git Plugins Public function.
private
get_git_plugins() : mixed
Return
(mixed)get_git_release_data()
Get Release Data from GitHub
private
get_git_release_data(string $release_url, string $repo_name, string $owner) : array<string|int, mixed>
Parameters
- $release_url
- (string) The Github API Releases URL.
- $repo_name
- (string) The repository Name.
- $owner
- (string) The name of the repo owner.
Return
(array<string|int, mixed>) $release_data A CP API Compatible "release" data array.get_git_repos()
Get Plugins stored on Git.
private
get_git_repos(string $url, string $name, string $domain) : array<string|int, mixed>
Description
Currently only supports TukuToi Org.
Parameters
- $url
- (string) The URL to get remote response from.
- $name
- (string) The name of the repository.
- $domain
- (string) the type of repository (org or name).
Return
(array<string|int, mixed>) $git_plugins A CP API Compatible array of plugin data.get_posted_data()
Validates any POSTed nonce by key and nonce.
private
get_posted_data(string $key, string $sanitization) : mixed
Parameters
- $key
- (string) The POST key where nonce is passed.
- $sanitization
- (string) The Sanitization function to use.
Return
(mixed)get_readme_data()
Get readme data
private
get_readme_data(string $item, string $login, string $branch) : string
Description
Readme can be: README.md readme.md README.txt readme.txt
Parameters
- $item
- (string) The repository slug/name.
- $login
- (string) The repo owner name.
- $branch
- (string) The default branch of the repository.
Tags
Return
(string) $readme The Readme Content.get_readme_name()
Get the "name" of the plugin - assumed to be first text following a '# ' in the readme.
private
get_readme_name(string $item, string $login, string $branch) : string
Parameters
- $item
- (string) The repository slug/name.
- $login
- (string) The repo owner name.
- $branch
- (string) The default branch of the repository.
Tags
Return
(string) $title The "name" of this plugin.get_remote_decoded_body()
Get Remote body json decoded.
private
get_remote_decoded_body(string $url[, array<string|int, mixed> $header = array() ]) : mixed
Parameters
- $url
- (string) Remote URL.
- $header
-
(array<string|int, mixed>) Array of headers to send to remote. Empty by default. Defaults to:
array()
Return
(mixed)get_remote_header()
Get Remote header.
private
get_remote_header(string $url[, array<string|int, mixed> $header = array() ], string $return) : mixed
Parameters
- $url
- (string) Remote URL.
- $header
-
(array<string|int, mixed>) Array of headers to send to remote. Empty by default. Defaults to:
array()
- $return
- (string) The header to return.
Return
(mixed)get_remote_raw_body()
Get Remote body json decoded.
private
get_remote_raw_body(string $url[, array<string|int, mixed> $header = array() ]) : mixed
Parameters
- $url
- (string) Remote URL.
- $header
-
(array<string|int, mixed>) Array of headers to send to remote. Empty by default. Defaults to:
array()
Return
(mixed)list_pagination()
Create a paginated list out of an array of items
private
list_pagination(array<string|int, mixed> $data, string $return) : mixed
Parameters
- $data
- (array<string|int, mixed>) The data to paginate.
- $return
- (string) What part of the pagination assets to return.
Return
(mixed)maybe_populate_cache()
Maybe populate cache file.
private
maybe_populate_cache(string $file) : mixed
Parameters
- $file
- (string) The Cache file path.
Return
(mixed)maybe_send_json_failure()
Validates any POSTed nonce by key and nonce.
private
maybe_send_json_failure(string $key[, string $message = 'Something went wrong' ]) : mixed
Parameters
- $key
- (string) The POST key where nonce is passed.
- $message
-
(string) The message to return on failure. Defaults to:
'Something went wrong'
Return
(mixed)put_file_contents()
CP Way of putting File Contentes.
private
put_file_contents(mixed $contents, string $file) : mixed
Parameters
- $contents
- (mixed) The content to put.
- $file
- (string) The file path to get contents from.
Return
(mixed)search_form()
Create a safe HTML search form input
private
search_form() : mixed
Return
(mixed)set_auth()
If available, get GitHub Auth Token.
private
set_auth() : mixed
Tags
Return
(mixed)validate_get_nonce()
Validates any GET nonce by key and nonce.
private
validate_get_nonce(string $key, string $nonce) : mixed
Parameters
- $key
- (string) The GET key where nonce is passed.
- $nonce
- (string) The Nonce to validate (name).
Return
(mixed)validate_post_nonce()
Validates any POSTed nonce by key and nonce.
private
validate_post_nonce(string $key, string $nonce[, string $message = 'Invalid or missing Nonce!' ]) : mixed
Parameters
- $key
- (string) The POST key where nonce is passed.
- $nonce
- (string) The Nonce to validate (name).
- $message
-
(string) The message to return on failure. Defaults to:
'Invalid or missing Nonce!'
Return
(mixed)vetted_orgs()
Get a list of vetted orgs
private
vetted_orgs() : array<string|int, mixed>