deregister_hook( 'init', 'WPMUDEV_Dashboard_Notice3', 'init', 10 );
$this->deregister_hook( 'plugins_loaded', 'WPMUDEV_Dashboard_Notice3', 'init', 10 );
}
//remove version 2.0
if ( method_exists( 'WPMUDEV_Dashboard_Notice', 'init' ) ) {
$this->deregister_hook( 'init', 'WPMUDEV_Dashboard_Notice', 'init', 10 );
$this->deregister_hook( 'plugins_loaded', 'WPMUDEV_Dashboard_Notice', 'init', 10 );
}
//remove version 1.0
remove_action( 'admin_notices', 'wdp_un_check', 5 );
remove_action( 'network_admin_notices', 'wdp_un_check', 5 );
}
/* Adapted from: https://github.com/herewithme/wp-filters-extras/ - Copyright 2012 Amaury Balmer - amaury@beapi.fr */
function deregister_hook( $hook_name, $class_name, $method_name, $priority ) {
global $wp_filter;
// Take only filters on right hook name and priority
if ( ! isset( $wp_filter[ $hook_name ][ $priority ] ) || ! is_array( $wp_filter[ $hook_name ][ $priority ] ) ) {
return false;
}
// Loop on filters registered
foreach ( (array) $wp_filter[ $hook_name ][ $priority ] as $unique_id => $filter_array ) {
// Test if filter is an array ! (always for class/method)
if ( isset( $filter_array['function'] ) && is_array( $filter_array['function'] ) ) {
// Test if object is a class, class and method is equal to param !
if ( is_object( $filter_array['function'][0] ) && get_class( $filter_array['function'][0] ) && get_class( $filter_array['function'][0] ) == $class_name && $filter_array['function'][1] == $method_name ) {
if ( class_exists( 'WP_Hook' ) ) { //introduced in WP 4.7 https://make.wordpress.org/core/2016/09/08/wp_hook-next-generation-actions-and-filters/
unset( $wp_filter[ $hook_name ]->callbacks[ $priority ][ $unique_id ] );
} else {
unset( $wp_filter[ $hook_name ][ $priority ][ $unique_id ] );
}
return true;
}
}
}
return false;
}
function init() {
global $wpmudev_un;
if ( class_exists( 'WPMUDEV_Dashboard' ) || ( isset( $wpmudev_un->version ) && version_compare( $wpmudev_un->version, '3.4', '<' ) ) ) {
return;
}
// Schedule update cron on main site only
if ( is_main_site() ) {
if ( ! wp_next_scheduled( 'wpmudev_scheduled_jobs' ) ) {
wp_schedule_event( time(), 'twicedaily', 'wpmudev_scheduled_jobs' );
}
add_action( 'wpmudev_scheduled_jobs', array( $this, 'updates_check' ) );
}
add_action( 'delete_site_transient_update_plugins', array(
&$this,
'updates_check'
) ); //refresh after upgrade/install
add_action( 'delete_site_transient_update_themes', array(
&$this,
'updates_check'
) ); //refresh after upgrade/install
if ( is_admin() && current_user_can( 'install_plugins' ) ) {
add_action( 'site_transient_update_plugins', array( &$this, 'filter_plugin_count' ) );
add_action( 'site_transient_update_themes', array( &$this, 'filter_theme_count' ) );
add_filter( 'plugins_api', array(
&$this,
'filter_plugin_info'
), 101, 3 ); //run later to work with bad autoupdate plugins
add_filter( 'themes_api', array(
&$this,
'filter_plugin_info'
), 101, 3 ); //run later to work with bad autoupdate plugins
add_action( 'load-plugins.php', array( &$this, 'filter_plugin_rows' ), 21 ); //make sure it runs after WP's
add_action( 'load-themes.php', array( &$this, 'filter_plugin_rows' ), 21 ); //make sure it runs after WP's
add_action( 'core_upgrade_preamble', array( &$this, 'disable_checkboxes' ) );
add_action( 'activated_plugin', array( &$this, 'set_activate_flag' ) );
add_action( 'wp_ajax_wdpun-changelog', array( &$this, 'popup_changelog_ajax' ) );
add_action( 'wp_ajax_wdpun-dismiss', array( &$this, 'dismiss_ajax' ) );
//if dashboard is installed but not activated
if ( file_exists( WP_PLUGIN_DIR . '/wpmudev-updates/update-notifications.php' ) ) {
if ( ! get_site_option( 'wdp_un_autoactivated' ) ) {
//include plugin API if necessary
if ( ! function_exists( 'activate_plugin' ) ) {
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
$result = activate_plugin( '/wpmudev-updates/update-notifications.php', network_admin_url( 'admin.php?page=wpmudev' ), is_multisite() );
if ( ! is_wp_error( $result ) ) { //if autoactivate successful don't show notices
update_site_option( 'wdp_un_autoactivated', 1 );
return;
}
}
add_action( 'admin_print_styles', array( &$this, 'notice_styles' ) );
add_action( 'admin_print_footer_scripts', array( &$this, 'notice_scripts' ) );
add_action( 'all_admin_notices', array( &$this, 'activate_notice' ), 5 );
} else { //dashboard not installed at all
if ( get_site_option( 'wdp_un_autoactivated' ) ) {
update_site_option( 'wdp_un_autoactivated', 0 );//reset flag when dashboard is deleted
}
add_action( 'admin_print_styles', array( &$this, 'notice_styles' ) );
add_action( 'admin_print_footer_scripts', array( &$this, 'notice_scripts' ) );
add_action( 'all_admin_notices', array( &$this, 'install_notice' ), 5 );
}
}
}
function is_allowed_screen() {
global $wpmudev_notices;
$screen = get_current_screen();
if ($screen && is_object($screen)) $this->screen_id = $screen->id;
//Show special message right after plugin activation
if ( in_array( $this->screen_id, array(
'plugins',
'plugins-network'
) ) && ( isset( $_GET['activate'] ) || isset( $_GET['activate-multi'] ) )
) {
$activated = get_site_option( 'wdp_un_activated_flag' );
if ( $activated === false ) {
$activated = 1;
} //on first encounter of new installed notice show
if ( $activated ) {
if ( $activated >= 2 ) {
update_site_option( 'wdp_un_activated_flag', 0 );
} else {
update_site_option( 'wdp_un_activated_flag', 2 );
}
return true;
}
}
//check dismiss flag
$dismissed = get_site_option( 'wdp_un_dismissed' );
if ( $dismissed && $dismissed > strtotime( '-1 week' ) ) {
return false;
}
//always show on certain core pages if updates are available
$updates = get_site_option( 'wdp_un_updates_available' );
if ( is_array( $updates ) && count( $updates ) ) {
$this->update_count = count( $updates );
if ( in_array( $this->screen_id, array(
'update-core',
'update-core-network'
) ) ) {
return true;
}
}
//check our registered plugins for hooks
if ( isset( $wpmudev_notices ) && is_array( $wpmudev_notices ) ) {
foreach ( $wpmudev_notices as $product ) {
if ( isset( $product['screens'] ) && is_array( $product['screens'] ) && in_array( $this->screen_id, $product['screens'] ) ) {
$this->product_name = $product['name'];
//if this plugin needs updating flag it
if ( isset( $product['id'] ) && isset( $updates[ $product['id'] ] ) ) {
$this->product_update = true;
}
return true;
}
}
}
return false;
}
function auto_install_url() {
$function = is_multisite() ? 'network_admin_url' : 'admin_url';
return wp_nonce_url( $function( "update.php?action=install-plugin&plugin=install_wpmudev_dash" ), "install-plugin_install_wpmudev_dash" );
}
function activate_url() {
$function = is_multisite() ? 'network_admin_url' : 'admin_url';
return wp_nonce_url( $function( 'plugins.php?action=activate&plugin=wpmudev-updates%2Fupdate-notifications.php' ), 'activate-plugin_wpmudev-updates/update-notifications.php' );
}
function install_notice() {
if ( ! $this->is_allowed_screen() ) return; ?>
product_name ) {
if ( $this->product_update ) {
printf( __( 'Important updates are available for %s. Install the free WPMU DEV Dashboard plugin now for updates and support!', 'wpmudev' ), esc_html( $this->product_name ) );
} else {
printf( __( '%s is almost ready - install the free WPMU DEV Dashboard plugin for updates and support!', 'wpmudev' ), esc_html( $this->product_name ) );
}
} else if ( $this->update_count ) {
_e( 'Important updates are available for your WPMU DEV plugins/themes. Install the free WPMU DEV Dashboard plugin now for updates and support!', 'wpmudev' );
} else {
_e( 'Almost ready - install the free WPMU DEV Dashboard plugin for updates and support!', 'wpmudev' );
}
?>
is_allowed_screen() ) return; ?>
product_name ) {
if ( $this->product_update ) {
printf( __( 'Important updates are available for %s. Activate the WPMU DEV Dashboard to update now!', 'wpmudev' ), esc_html( $this->product_name ) );
} else {
printf( __( 'Just one more step to enable updates and support for %s!', 'wpmudev' ), esc_html( $this->product_name ) );
}
} else if ( $this->update_count ) {
_e( 'Important updates are available for your WPMU DEV plugins/themes. Activate the WPMU DEV Dashboard to update now!', 'wpmudev' );
} else {
_e( "Just one more step - activate the WPMU DEV Dashboard plugin and you're all done!", 'wpmudev' );
}
?>
';
printf( 'There is a new version of %1$s available on WPMU DEV. View version %4$s details or %6$s to update.', $plugin_name, esc_url( $info_url ), esc_attr( $plugin_name ), $version, esc_url( $action_url ), $message );
echo '
';
printf( 'There is a new version of %1$s available on WPMU DEV. View version %4$s details or %6$s to update.', $plugin_name, esc_url( $info_url ), esc_attr( $plugin_name ), $version, esc_url( $action_url ), $message );
echo '
';
}
}
function disable_checkboxes() {
$updates = get_site_option( 'wdp_un_updates_available' );
if ( ! is_array( $updates ) || ( is_array( $updates ) && ! count( $updates ) ) ) {
return;
}
$jquery = "\n";
echo $jquery;
}
function set_activate_flag( $plugin ) {
$data = $this->get_id_plugin( WP_PLUGIN_DIR . '/' . $plugin );
if ( isset( $data['id'] ) && ! empty( $data['id'] ) ) {
update_site_option( 'wdp_un_activated_flag', 1 );
}
}
function popup_changelog( $project_id ) {
/**
* Dashboard popup template: Project changelog
*
* Displays the changelog of a specific project.
*
* Following variables are passed into the template:
* $pid (project ID)
*
* @since 4.0.5
* @package WPMUDEV_Dashboard
*/
$url = $this->server_url . 'changelog/' . $project_id;
$options = array(
'timeout' => 15,
'sslverify' => false, // Many hosts have no updated CA bundle.
'user-agent' => 'Dashboard Notification/' . $this->version
);
$response = wp_remote_get( $url, $options );
if ( wp_remote_retrieve_response_code( $response ) == 200 ) {
$changelog = json_decode( wp_remote_retrieve_body( $response ), true );
}
$updates = get_site_option( 'wdp_un_updates_available' );
$item = $updates[ $project_id ];
if ( ! $changelog || ! is_array( $changelog ) || ! $item ) {
wp_die( __( 'We did not find any data for this plugin or theme...', 'wpmudev' ) );
}
$dlg_id = 'dlg-' . md5( time() . '-' . $project_id );
?>