tracking = new Tracking(); } /** * Prepare actions according to screen and post type. * * @since 1.1.0 * @since-jetpack 3.8.2 * * @uses Jetpack_Autoupdate::get_possible_failures() * * @param \WP_Screen $screen WP Core's screen object. */ public function prepare_jitms( $screen ) { parent::prepare_jitms( $screen ); if ( ! in_array( $screen->id, array( 'jetpack_page_akismet-key-config', 'admin_page_jetpack_modules', ), true ) ) { // Not really a JITM. Don't know where else to put this :) . add_action( 'admin_notices', array( $this, 'delete_user_update_connection_owner_notice' ) ); } } /** * A special filter for WooCommerce, to set a message based on local state. * * @param string $content The current message. * * @return array The new message. */ public static function jitm_woocommerce_services_msg( $content ) { if ( ! function_exists( 'wc_get_base_location' ) ) { return $content; } $base_location = wc_get_base_location(); switch ( $base_location['country'] ) { case 'US': $content->message = esc_html__( 'New free service: Show USPS shipping rates on your store! Added bonus: print shipping labels without leaving WooCommerce.', 'jetpack-jitm' ); break; case 'CA': $content->message = esc_html__( 'New free service: Show Canada Post shipping rates on your store!', 'jetpack-jitm' ); break; default: $content->message = ''; } return $content; } /** * A special filter for WooCommerce Call To Action button * * @return string The new CTA */ public static function jitm_jetpack_woo_services_install() { return wp_nonce_url( add_query_arg( array( 'wc-services-action' => 'install', ), admin_url( 'admin.php?page=wc-settings' ) ), 'wc-services-install' ); } /** * A special filter for WooCommerce Call To Action button. * * @return string The new CTA */ public static function jitm_jetpack_woo_services_activate() { return wp_nonce_url( add_query_arg( array( 'wc-services-action' => 'activate', ), admin_url( 'admin.php?page=wc-settings' ) ), 'wc-services-install' ); } /** * A special filter used in the CTA of a JITM offering to install the Creative Mail plugin. * * @return string The new CTA */ public static function jitm_jetpack_creative_mail_install() { return wp_nonce_url( add_query_arg( array( 'creative-mail-action' => 'install', ), admin_url( 'edit.php?post_type=feedback' ) ), 'creative-mail-install' ); } /** * A special filter used in the CTA of a JITM offering to activate the Creative Mail plugin. * * @return string The new CTA */ public static function jitm_jetpack_creative_mail_activate() { return wp_nonce_url( add_query_arg( array( 'creative-mail-action' => 'activate', ), admin_url( 'edit.php?post_type=feedback' ) ), 'creative-mail-install' ); } /** * A special filter used in the CTA of a JITM offering to install the Jetpack Backup plugin. * * @return string The new CTA */ public static function jitm_jetpack_backup_install() { return wp_nonce_url( add_query_arg( array( 'jetpack-backup-action' => 'install', ), admin_url( 'admin.php?page=jetpack' ) ), 'jetpack-backup-install' ); } /** * A special filter used in the CTA of a JITM offering to activate the Jetpack Backup plugin. * * @return string The new CTA */ public static function jitm_jetpack_backup_activate() { return wp_nonce_url( add_query_arg( array( 'jetpack-backup-action' => 'activate', ), admin_url( 'admin.php?page=jetpack' ) ), 'jetpack-backup-install' ); } /** * A special filter used in the CTA of a JITM offering to install the Jetpack Boost plugin. * * @return string The new CTA */ public static function jitm_jetpack_boost_install() { return wp_nonce_url( add_query_arg( array( 'jetpack-boost-action' => 'install', ), admin_url( 'admin.php?page=jetpack' ) ), 'jetpack-boost-install' ); } /** * A special filter used in the CTA of a JITM offering to activate the Jetpack Boost plugin. * * @return string The new CTA */ public static function jitm_jetpack_boost_activate() { return wp_nonce_url( add_query_arg( array( 'jetpack-boost-action' => 'activate', ), admin_url( 'admin.php?page=jetpack' ) ), 'jetpack-boost-install' ); } /** * This is an entire admin notice dedicated to messaging and handling of the case where a user is trying to delete * the connection owner. */ public function delete_user_update_connection_owner_notice() { global $current_screen; /* * phpcs:disable WordPress.Security.NonceVerification.Recommended * * This function is firing within wp-admin and checks (below) if it is in the midst of a deletion on the users * page. Nonce will be already checked by WordPress, so we do not need to check ourselves. */ if ( ! isset( $current_screen->base ) || 'users' !== $current_screen->base ) { return; } if ( ! isset( $_REQUEST['action'] ) || 'delete' !== $_REQUEST['action'] ) { return; } // Get connection owner or bail. $connection_manager = new Manager(); $connection_owner_id = $connection_manager->get_connection_owner_id(); if ( ! $connection_owner_id ) { return; } $connection_owner_userdata = get_userdata( $connection_owner_id ); // Bail if we're not trying to delete connection owner. $user_ids_to_delete = array(); if ( isset( $_REQUEST['users'] ) ) { $user_ids_to_delete = array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['users'] ) ); } elseif ( isset( $_REQUEST['user'] ) ) { $user_ids_to_delete[] = sanitize_text_field( wp_unslash( $_REQUEST['user'] ) ); } // phpcs:enable $user_ids_to_delete = array_map( 'absint', $user_ids_to_delete ); $deleting_connection_owner = in_array( $connection_owner_id, (array) $user_ids_to_delete, true ); if ( ! $deleting_connection_owner ) { return; } // Bail if they're trying to delete themselves to avoid confusion. if ( get_current_user_id() === $connection_owner_id ) { return; } // Track it! if ( method_exists( $this->tracking, 'record_user_event' ) ) { $this->tracking->record_user_event( 'delete_connection_owner_notice_view' ); } $connected_admins = $connection_manager->get_connected_users( 'jetpack_disconnect' ); $user = is_a( $connection_owner_userdata, 'WP_User' ) ? esc_html( $connection_owner_userdata->data->user_login ) : ''; echo "
' . sprintf( /* translators: WordPress User, if available. */ esc_html__( 'Warning! You are about to delete the Jetpack connection owner (%s) for this site, which may cause some of your Jetpack features to stop working.', 'jetpack-jitm' ), esc_html( $user ) ) . '
'; if ( ! empty( $connected_admins ) && count( $connected_admins ) > 1 ) { echo ''; ?> ' . esc_html__( 'Every Jetpack site needs at least one connected admin for the features to work properly. Please connect to your WordPress.com account via the button below. Once you connect, you may refresh this page to see an option to change the connection owner.', 'jetpack-jitm' ) . ''; $connect_url = $connection_manager->get_authorization_url(); $connect_url = add_query_arg( 'from', 'delete_connection_owner_notice', $connect_url ); echo "" . esc_html__( 'Connect to WordPress.com', 'jetpack-jitm' ) . ''; } echo ''; printf( wp_kses( /* translators: URL to Jetpack support doc regarding the primary user. */ __( "Learn more about the connection owner and what will break if you do not have one.", 'jetpack-jitm' ), array( 'a' => array( 'href' => true, 'target' => true, 'rel' => true, ), ) ), esc_url( Redirect::get_url( 'jetpack-support-primary-user' ) ) ); echo '
'; echo ''; printf( wp_kses( /* translators: URL to contact Jetpack support. */ __( 'As always, feel free to contact our support team if you have any questions.', 'jetpack-jitm' ), array( 'a' => array( 'href' => true, 'target' => true, 'rel' => true, ), ) ), esc_url( Redirect::get_url( 'jetpack-contact-support' ) ) ); echo '
'; echo '