PHP Class Airplane_Mode_Core

Exibir arquivo Open project: norcross/airplane-mode Class Usage Examples

Public Properties

Property Type Description
$instance Static property to hold our singleton instance.

Public Methods

Method Description
admin_bar_toggle ( WP_Admin_Bar $wp_admin_bar ) : void Add our quick toggle to the admin bar to enable / disable
admin_body_class ( string $classes ) : string Add body class to admin pages based on plugin status.
admin_menu_items ( ) : null Remove menu items for updates from a standard WP install.
available_translations ( mixed $translations ) : array Filter for languages list transient. Returns locally available translations to avoid request into wp.org translation API.
block_oembed_html ( string $html, string $url, array $attr, integer $post_ID ) : string Block oEmbeds from displaying.
block_script_load ( string $source ) : string Check the URL of a JS file and remove any that are not on the local URL.
block_style_load ( string $source ) : string Check the URL of a stylesheet and remove any that are not on the local URL.
body_class ( array $classes ) : array Add body class to front-end pages and login based on plugin status.
bypass_theme_api_call ( false | object | array $override, string $action, object $args ) : boolean Override the API call made for pulling themes from the .org repo.
bypass_theme_api_result ( array | object | WP_Error $res, string $action, object $args ) : boolean Hijack the expected themes API result.
count_http_requests ( ) : void Increase HTTP request counter by one.
create_setting ( ) Set our initial airplane mode setting to 'on' on activation.
default_avatar ( string $avatar_list ) : string Remove avatar images from the default avatar list
disable_http_reqs ( boolean | array | WP_Error $status = false, array $args = [], string $url = '' ) : boolean | array | WP_Error Disable all the HTTP requests being made with the action happening before the status check so others can allow certain items as desired.
enabled ( ) : boolean Helper function to check the current status.
getInstance ( ) If an instance exists, this returns it. If not, it creates one and returns it.
last_checked_core ( ) : object Always send back that the latest version of WordPress is the one we're running
last_checked_plugins ( ) : object Always send back that the latest version of our plugins are the one we're running
last_checked_themes ( ) : object Always send back that the latest version of our theme is the one we're running
ms_admin_menu_items ( ) : null Remove menu items for updates from a multisite instance.
plugin_add_tabs ( array $nonmenu_tabs ) : array Remove the tabs on the plugin page to add new items since they require the WP connection and will fail.
prevent_auto_updates ( array $caps, string $cap ) : array Filter a user's meta capabilities to prevent auto-updates from being attempted.
purge_transients ( ) : void Check the new status after airplane mode has been enabled or disabled and purge related transients
remove_bulk_actions ( array $actions ) : array Remove the ability to update plugins/themes from single site and multisite bulk actions
remove_schedule_hook ( ) : null Remove all the various schedule hooks for themes, plugins, etc.
remove_setting ( ) Remove our setting on plugin deactivation.
remove_update_array ( array $items ) : array Return an empty array of items requiring update for both themes and plugins
remove_update_crons ( ) : null Remove all the various places WP does the update checks. As you can see there are a lot of them.
replace_gravatar ( string $avatar, integer | object | string $id_or_email, integer $size, string $default, string $alt ) : string Replace all instances of gravatar with a local image file to remove the call to remote service.
textdomain ( ) : void Load our textdomain for localization.
toggle_check ( ) : void Check the user action from the toggle switch to set the option to 'on' or 'off'.
toggle_css ( ) Load our small CSS file for the toggle switch.

Protected Methods

Method Description
get_redirect ( ) : string Fetch the URL to redirect to after toggling Airplane Mode.

Private Methods

Method Description
__construct ( ) This is our constructor. There are many like it, but this one is mine.
get_offline_languages ( array $installed_languages ) : array Returns list of languages installed locally with full mimicked meta data.
get_offline_translation_information ( ) : array We can't use wp_get_available_translations() offine.

Method Details

admin_bar_toggle() public method

Add our quick toggle to the admin bar to enable / disable
public admin_bar_toggle ( WP_Admin_Bar $wp_admin_bar ) : void
$wp_admin_bar WP_Admin_Bar The admin bar object.
return void if current user can't manage options and we bail early.

admin_body_class() public method

Add body class to admin pages based on plugin status.
public admin_body_class ( string $classes ) : string
$classes string The existing space-separated list of CSS classes.
return string $classes The updated space-separated list of CSS classes.

admin_menu_items() public method

Remove menu items for updates from a standard WP install.
public admin_menu_items ( ) : null
return null

available_translations() public method

Filter for languages list transient. Returns locally available translations to avoid request into wp.org translation API.
public available_translations ( mixed $translations ) : array
$translations mixed Translation data returned from transient API.
return array List of available languages.

block_oembed_html() public method

Block oEmbeds from displaying.
public block_oembed_html ( string $html, string $url, array $attr, integer $post_ID ) : string
$html string The embed HTML.
$url string The attempted embed URL.
$attr array An array of shortcode attributes.
$post_ID integer Post ID.
return string

block_script_load() public method

Check the URL of a JS file and remove any that are not on the local URL.
public block_script_load ( string $source ) : string
$source string The source URL of the JS file.
return string $source The same URL, or null.

block_style_load() public method

Check the URL of a stylesheet and remove any that are not on the local URL.
public block_style_load ( string $source ) : string
$source string The source URL of the CSS sheet.
return string $source The same URL, or null.

body_class() public method

Add body class to front-end pages and login based on plugin status.
public body_class ( array $classes ) : array
$classes array The existing array of body classes.
return array $classes The updated array of body classes.

bypass_theme_api_call() public method

Override the API call made for pulling themes from the .org repo.
public bypass_theme_api_call ( false | object | array $override, string $action, object $args ) : boolean
$override false | object | array Whether to override the WordPress.org Themes API. Default false.
$action string Requested action. Likely values are 'theme_information', 'feature_list', or 'query_themes'.
$args object Arguments used to query for installer pages from the Themes API.
return boolean True if enabled, otherwise the existng value.

bypass_theme_api_result() public method

Hijack the expected themes API result.
public bypass_theme_api_result ( array | object | WP_Error $res, string $action, object $args ) : boolean
$res array | object | WP_Error WordPress.org Themes API response.
$action string Requested action. Likely values are 'theme_information', 'feature_list', or 'query_themes'.
$args object Arguments used to query for installer pages from the WordPress.org Themes API.
return boolean An empty array if enabled, otherwise the existng result.

count_http_requests() public method

Increase HTTP request counter by one.
public count_http_requests ( ) : void
return void

create_setting() public method

Set our initial airplane mode setting to 'on' on activation.
public create_setting ( )

default_avatar() public method

Remove avatar images from the default avatar list
public default_avatar ( string $avatar_list ) : string
$avatar_list string List of default avatars.
return string Updated list with images removed

disable_http_reqs() public method

Disable all the HTTP requests being made with the action happening before the status check so others can allow certain items as desired.
public disable_http_reqs ( boolean | array | WP_Error $status = false, array $args = [], string $url = '' ) : boolean | array | WP_Error
$status boolean | array | WP_Error Whether to preempt an HTTP request return. Default false.
$args array HTTP request arguments.
$url string The request URL.
return boolean | array | WP_Error A WP_Error object if Airplane Mode is enabled. Original $status if not.

enabled() public method

Helper function to check the current status.
public enabled ( ) : boolean
return boolean True if status is 'on'; false if not.

getInstance() public static method

If an instance exists, this returns it. If not, it creates one and returns it.
public static getInstance ( )

get_redirect() protected static method

Fetch the URL to redirect to after toggling Airplane Mode.
protected static get_redirect ( ) : string
return string The URL to redirect to.

last_checked_core() public method

Always send back that the latest version of WordPress is the one we're running
public last_checked_core ( ) : object
return object the modified output with our information

last_checked_plugins() public method

Always send back that the latest version of our plugins are the one we're running
public last_checked_plugins ( ) : object
return object the modified output with our information

last_checked_themes() public method

Always send back that the latest version of our theme is the one we're running
public last_checked_themes ( ) : object
return object the modified output with our information

ms_admin_menu_items() public method

Remove menu items for updates from a multisite instance.
public ms_admin_menu_items ( ) : null
return null

plugin_add_tabs() public method

Remove the tabs on the plugin page to add new items since they require the WP connection and will fail.
public plugin_add_tabs ( array $nonmenu_tabs ) : array
$nonmenu_tabs array All the tabs displayed.
return array $nonmenu_tabs The remaining tabs.

prevent_auto_updates() public method

Filter a user's meta capabilities to prevent auto-updates from being attempted.
public prevent_auto_updates ( array $caps, string $cap ) : array
$caps array Returns the user's actual capabilities.
$cap string Capability name.
return array The user's filtered capabilities.

purge_transients() public method

Check the new status after airplane mode has been enabled or disabled and purge related transients
public purge_transients ( ) : void
return void

remove_bulk_actions() public method

Remove the ability to update plugins/themes from single site and multisite bulk actions
public remove_bulk_actions ( array $actions ) : array
$actions array All the bulk actions.
return array $actions The remaining actions

remove_schedule_hook() public method

Remove all the various schedule hooks for themes, plugins, etc.
public remove_schedule_hook ( ) : null
return null

remove_setting() public method

Remove our setting on plugin deactivation.
public remove_setting ( )

remove_update_array() public method

Return an empty array of items requiring update for both themes and plugins
public remove_update_array ( array $items ) : array
$items array All the items being passed for update.
return array An empty array, or the original items if not enabled.

remove_update_crons() public method

Remove all the various places WP does the update checks. As you can see there are a lot of them.
public remove_update_crons ( ) : null
return null

replace_gravatar() public method

Replace all instances of gravatar with a local image file to remove the call to remote service.
public replace_gravatar ( string $avatar, integer | object | string $id_or_email, integer $size, string $default, string $alt ) : string
$avatar string Image tag for the user's avatar.
$id_or_email integer | object | string A user ID, email address, or comment object.
$size integer Square avatar width and height in pixels to retrieve.
$default string URL to a default image to use if no avatar is available.
$alt string Alternative text to use in the avatar image tag.
return string `` tag for the user's avatar.

textdomain() public method

Load our textdomain for localization.
public textdomain ( ) : void
return void

toggle_check() public method

Check the user action from the toggle switch to set the option to 'on' or 'off'.
public toggle_check ( ) : void
return void if any of the sanity checks fail and we bail early.

toggle_css() public method

Load our small CSS file for the toggle switch.
public toggle_css ( )

Property Details

$instance static_oe public_oe property

Static property to hold our singleton instance.
static public $instance