summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2017-11-20 16:50:38 -0500
committerAnthony G. Basile <blueness@gentoo.org>2017-11-20 16:50:38 -0500
commit159ec5c8052e1d061a430893a4525629849e2589 (patch)
tree6613f22dab82e5c683141f53b1281e18510896ef /plugins/jetpack/sync/class.jetpack-sync-module-callables.php
parentUpdate akismet 4.0.1 (diff)
downloadblogs-gentoo-159ec5c8052e1d061a430893a4525629849e2589.tar.gz
blogs-gentoo-159ec5c8052e1d061a430893a4525629849e2589.tar.bz2
blogs-gentoo-159ec5c8052e1d061a430893a4525629849e2589.zip
Update jetpack 5.5
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'plugins/jetpack/sync/class.jetpack-sync-module-callables.php')
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-module-callables.php72
1 files changed, 68 insertions, 4 deletions
diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-callables.php b/plugins/jetpack/sync/class.jetpack-sync-module-callables.php
index 1ac7507f..f52d81fc 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-module-callables.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-module-callables.php
@@ -22,6 +22,7 @@ class Jetpack_Sync_Module_Callables extends Jetpack_Sync_Module {
public function init_listeners( $callable ) {
add_action( 'jetpack_sync_callable', $callable, 10, 2 );
+ add_action( 'admin_init', array( $this, 'set_plugin_action_links' ), 9999 ); // Should happen very late
// For some options, we should always send the change right away!
$always_send_updates_to_these_options = array(
@@ -40,7 +41,8 @@ class Jetpack_Sync_Module_Callables extends Jetpack_Sync_Module {
// get_plugins and wp_version
// gets fired when new code gets installed, updates etc.
- add_action( 'upgrader_process_complete', array( $this, 'unlock_sync_callable' ) );
+ add_action( 'upgrader_process_complete', array( $this, 'unlock_plugin_action_link_and_callables' ) );
+ add_action( 'update_option_active_plugins', array( $this, 'unlock_plugin_action_link_and_callables' ) );
}
public function init_full_sync_listeners( $callable ) {
@@ -81,7 +83,6 @@ class Jetpack_Sync_Module_Callables extends Jetpack_Sync_Module {
array_map( array( $this, 'get_callable' ), array_values( $this->get_callable_whitelist() ) )
);
wp_set_current_user( $current_user_id );
-
return $callables;
}
@@ -100,7 +101,7 @@ class Jetpack_Sync_Module_Callables extends Jetpack_Sync_Module {
do_action( 'jetpack_full_sync_callables', true );
// The number of actions enqueued, and next module state (true == done)
- return array( 1, true );
+ return array( 1, true );
}
public function estimate_full_sync_actions( $config ) {
@@ -115,6 +116,69 @@ class Jetpack_Sync_Module_Callables extends Jetpack_Sync_Module {
delete_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME );
}
+ public function unlock_plugin_action_link_and_callables() {
+ delete_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME );
+ delete_transient( 'jetpack_plugin_api_action_links_refresh' );
+ }
+
+ public function set_plugin_action_links() {
+ if (
+ ! class_exists( 'DOMDocument' ) ||
+ ! function_exists ( 'libxml_use_internal_errors' ) ||
+ ! function_exists ( 'mb_convert_encoding' )
+ ) {
+ return;
+ }
+
+ // Is the transient lock in place?
+ $plugins_lock = get_transient( 'jetpack_plugin_api_action_links_refresh', false );
+ if ( ! empty( $plugins_lock ) ) {
+ return;
+ }
+ $plugins = array_keys( Jetpack_Sync_Functions::get_plugins() );
+ foreach ( $plugins as $plugin_file ) {
+ /** This filter is documented in src/wp-admin/includes/class-wp-plugins-list-table.php */
+ $action_links = apply_filters( 'plugin_action_links', array(), $plugin_file, null, 'all' );
+ /** This filter is documented in src/wp-admin/includes/class-wp-plugins-list-table.php */
+ $action_links = apply_filters( "plugin_action_links_{$plugin_file}", $action_links, $plugin_file, null, 'all' );
+ $formatted_action_links = null;
+ if ( ! empty( $action_links ) && count( $action_links ) > 0 ) {
+ $dom_doc = new DOMDocument;
+ foreach ( $action_links as $action_link ) {
+ // The @ is not enough to suppress errors when dealing with libxml,
+ // we have to tell it directly how we want to handle errors.
+ libxml_use_internal_errors( true );
+ $dom_doc->loadHTML( mb_convert_encoding( $action_link, 'HTML-ENTITIES', 'UTF-8' ) );
+ libxml_use_internal_errors( false );
+
+ $link_elements = $dom_doc->getElementsByTagName( 'a' );
+ if ( $link_elements->length == 0 ) {
+ continue;
+ }
+
+ $link_element = $link_elements->item( 0 );
+ if ( $link_element->hasAttribute( 'href' ) && $link_element->nodeValue ) {
+ $link_url = trim( $link_element->getAttribute( 'href' ) );
+
+ // Add the full admin path to the url if the plugin did not provide it
+ $link_url_scheme = wp_parse_url( $link_url, PHP_URL_SCHEME );
+ if ( empty( $link_url_scheme ) ) {
+ $link_url = admin_url( $link_url );
+ }
+
+ $formatted_action_links[ $link_element->nodeValue ] = $link_url;
+ }
+ }
+ }
+ if ( $formatted_action_links ) {
+ $plugins_action_links[ $plugin_file ] = $formatted_action_links;
+ }
+ }
+ // Cache things for a long time
+ set_transient( 'jetpack_plugin_api_action_links_refresh', time(), DAY_IN_SECONDS );
+ update_option( 'jetpack_plugin_api_action_links', $plugins_action_links );
+ }
+
public function should_send_callable( $callable_checksums, $name, $checksum ) {
$idc_override_callables = array(
'main_network_site',
@@ -127,7 +191,7 @@ class Jetpack_Sync_Module_Callables extends Jetpack_Sync_Module {
return ! $this->still_valid_checksum( $callable_checksums, $name, $checksum );
}
-
+
public function maybe_sync_callables() {
if ( ! is_admin() || Jetpack_Sync_Settings::is_doing_cron() ) {
return;