is_pro = ( new WPMUDEV() )->is_pro(); $is_def_page = defender_current_page(); // Display plugin links. add_filter( 'network_admin_plugin_action_links_' . DEFENDER_PLUGIN_BASENAME, array( $this, 'settings_link' ) ); add_filter( 'plugin_action_links_' . DEFENDER_PLUGIN_BASENAME, array( $this, 'settings_link' ) ); add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 3 ); // Only for wordpress.org members. if ( ! $this->is_pro ) { // Add plugin upgrade notification. add_action( 'in_plugin_update_message-' . DEFENDER_PLUGIN_BASENAME, array( $this, 'show_upgrade_notice' ), 10, 2 ); if ( $is_def_page && ! is_multisite() ) { add_action( 'admin_notices', array( $this, 'show_rating_notice' ) ); } elseif ( $is_def_page && is_multisite() && is_main_site() ) { add_action( 'network_admin_notices', array( $this, 'show_rating_notice' ) ); } add_action( 'wp_ajax_defender_dismiss_notification', array( $this, 'dismiss_notice' ) ); add_action( 'admin_init', array( $this, 'register_free_modules' ), 20 ); } else { // For Pro version. add_action( 'load-plugins.php', function () { add_action( 'after_plugin_row_' . DEFENDER_PLUGIN_BASENAME, array( $this, 'show_upgrade_notice' ), 10, 2 ); }, 22 ); } } /** * Return URL link. * * @param string $link_for Accepts: 'docs', 'plugin', 'rate', 'support', 'roadmap'. * @param string $campaign Utm campaign tag to be used in link. Default: ''. * @param string $adv_path Advanced path. Default: ''. * * @return string */ public function get_link( $link_for, $campaign = '', $adv_path = '' ) { $domain = 'https://wpmudev.com'; $wp_org = 'https://wordpress.org'; $utm_tags = "?utm_source=defender&utm_medium=plugin&utm_campaign={$campaign}"; switch ( $link_for ) { case 'docs': $link = "{$domain}/docs/wpmu-dev-plugins/defender/{$utm_tags}"; break; case 'plugin': $link = "{$domain}/project/wp-defender/{$utm_tags}"; break; case 'rate': $link = "{$wp_org}/support/plugin/defender-security/reviews/#new-post"; break; case 'support': $link = $this->is_pro ? "{$domain}/get-support/" : "{$wp_org}/support/plugin/defender-security/"; break; case 'roadmap': $link = "{$domain}/roadmap/"; break; case 'pro_link': $link = "{$domain}/$adv_path"; break; default: $link = ''; break; } return $link; } /** * Adds a settings link on plugin page. * * @param array $links Current links. * * @return array */ public function settings_link( $links ) { $action_links = []; $wpmu_dev = new WPMUDEV(); // Settings link. $action_links['dashboard'] = '' . esc_html__( 'Settings', 'wpdef' ) . ''; // Documentation link. $action_links['docs'] = '' . esc_html__('Docs', 'wpdef') . ''; if ( ! $wpmu_dev->is_member() ) { if ( WP_DEFENDER_PRO_PATH !== DEFENDER_PLUGIN_BASENAME ) { $action_links['upgrade'] = '' . esc_html__( 'Upgrade', 'wpdef' ) . ''; } else { $action_links['renew'] = '' . esc_html__( 'Renew Membership', 'wpdef' ) . ''; } } return array_merge( $action_links, $links ); } /** * Show row meta on the plugin screen. * * @param mixed $links Plugin Row Meta. * @param mixed $file Plugin Base file. * @param array $plugin_data Plugin data. * * @return array */ public function plugin_row_meta( $links, $file, $plugin_data ) { $row_meta = []; if ( ! defined( 'DEFENDER_PLUGIN_BASENAME' ) || DEFENDER_PLUGIN_BASENAME !== $file ) { return $links; } // Change AuthorURI link. if ( isset( $links[1] ) ) { $author_uri = $this->is_pro ? 'https://wpmudev.com/' : 'https://profiles.wordpress.org/wpmudev/'; $author_uri = sprintf( '%s', $author_uri, __( 'WPMU DEV' ) ); $links[1] = sprintf( /* translators: ... */ __( 'By %s' ), $author_uri ); } if ( ! $this->is_pro ) { // Change AuthorURI link. if ( isset( $links[2] ) && false === strpos( $links[2], 'target="_blank"' ) ) { if ( ! isset( $plugin_data['slug'] ) && $plugin_data['Name'] ) { $links[2] = sprintf( '%s', esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&plugin=defender-security' . '&TB_iframe=true&width=600&height=550' ) ), /* translators: %s: Plugin name. */ esc_attr( sprintf( __( 'More information about %s' ), $plugin_data['Name'] ) ), esc_attr( $plugin_data['Name'] ), __( 'View details' ) ); } else { $links[2] = str_replace( 'href=', 'target="_blank" href=', $links[2] ); } } $row_meta['rate'] = '' . esc_html__( 'Rate Defender', 'wpdef' ) . ''; $row_meta['support'] = '' . esc_html__( 'Support', 'wpdef' ) . ''; } else { // Change 'Visit plugins' link to 'View details'. if ( isset( $links[2] ) && false !== strpos( $links[2], 'project/wp-defender' ) ) { $links[2] = sprintf( '%s', esc_url( $this->get_link( 'pro_link', '', 'project/wp-defender/' ) ), __( 'View details' ) ); } $row_meta['support'] = '' . esc_html__( 'Premium Support', 'wpdef' ) . ''; } $row_meta['roadmap'] = '' . esc_html__( 'Roadmap', 'wpdef' ) . ''; return array_merge( $links, $row_meta ); } /** * Dismiss notice. */ public function dismiss_notice() { if ( ! current_user_can( 'manage_options' ) || ! check_ajax_referer( 'defender_dismiss_notification' ) ) { wp_send_json_error( array( 'message' => __( 'Invalid request, you are not allowed to do that action.', 'wpdef' ), ) ); } $notification_name = ! empty( $_POST['prop'] ) ? sanitize_text_field( $_POST['prop'] ) : false; if ( false === $notification_name ) { wp_send_json_error( array( 'message' => __( 'Invalid request, allowed data not provided.', 'wpdef' ), ) ); } update_site_option( $notification_name, true ); wp_send_json_success(); } /** * Register sub-modules. */ public function register_free_modules() { if ( ! file_exists( defender_path( 'extra/free-dashboard/module.php' ) ) || ! file_exists( defender_path( 'extra/recommended-plugins-notice/notice.php' ) ) ) { return; } /* @noinspection PhpIncludeInspection */ require_once( defender_path( 'extra/free-dashboard/module.php' ) ); /* @noinspection PhpIncludeInspection */ require_once( defender_path( 'extra/recommended-plugins-notice/notice.php' ) ); // Register the current plugin. do_action( 'wdev_register_plugin', /* 1 Plugin ID */ DEFENDER_PLUGIN_BASENAME, /* 2 Plugin Title */ 'Defender', /* 3 https://wordpress.org */ '/plugins/defender-security/', /* 4 Email Button CTA */ __( 'Get Fast!', 'wpdef' ) /* 5 Mailchimp List id for the plugin - No */ ); // Recommended plugin notice. do_action( 'wpmudev-recommended-plugins-register-notice', DEFENDER_PLUGIN_BASENAME, // Plugin basename 'Defender', // Plugin Name array( 'toplevel_page_wp-defender', 'toplevel_page_wp-defender-network', ), array( 'after', '.sui-wrap .sui-header' ) ); } /** * Show the rating notice. */ public function show_rating_notice() { // @since 2.6.1 if ( get_site_option( 'defender_rating_success', apply_filters( 'wd_display_rating', false ) ) ) { return; } $install_date = get_site_option( 'defender_free_install_date', false ); // @since 2.6.1 $days_later_dismiss = get_site_option( 'defender_days_rating_later_dismiss', apply_filters( 'wd_dismiss_rating', false ) ); if ( $install_date && ! $days_later_dismiss && current_time( 'timestamp' ) > strtotime( '+7 days', $install_date ) ) { ?>

=' ) ) { return; } $plugin_data = (object) $response; // Preparing for the next major plugin v3.0.0 and subsequent versions. if ( isset( $plugin_data->new_version ) && '3' === substr( trim( $plugin_data->new_version ), 0, 1 ) && version_compare( DEFENDER_VERSION, '3', '<' ) ){ // Major plugin version or subsequent versions. $new_version = ( '3' === $plugin_data->new_version ) ? '3.0.0' : $plugin_data->new_version; // Collect notice. $notice = '

' . esc_html__( 'There is a new version of Defender available - Deprecating PHP version 7.1. and lower.', 'wpdef' ) . '

'; $notice .= ''; $notice .= ''; $notice .= esc_html__( 'Important Upgrade Notice:', 'wpdef' ); $notice .= ' '; $notice .= sprintf( /* translators: %s: Version number. */ esc_html__( 'The upcoming version %s is compatible only with PHP 7.2.0 and higher. Please make sure to upgrade your PHP version.', 'wpdef' ), $new_version ); $notice .= ''; echo ""; } } }