' . esc_html__( 'Settings', 'hivenza' ) . '' ); return $links; } add_filter( 'plugin_action_links_' . plugin_basename( HIVENZA_FILE ), 'hivenza_action_links' ); /** * Consent mode needs the WP Consent API plugin; say so when it is missing. */ function hivenza_consent_notice() { $s = hivenza_settings(); if ( empty( $s['consent'] ) || function_exists( 'wp_has_consent' ) || ! current_user_can( 'manage_options' ) ) { return; } echo '

' . esc_html__( 'Hivenza: the chat waits for consent, but the WP Consent API plugin is not active, so the chat will never load. Install it, or turn off the consent option in Settings, Hivenza.', 'hivenza' ) . '

'; } add_action( 'admin_notices', 'hivenza_consent_notice' ); /** * Test connection: asks the public chat endpoint for the chat's look. Nonce and capability checked. */ function hivenza_handle_test() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'hivenza' ), '', array( 'response' => 403 ) ); } check_admin_referer( 'hivenza_test_connection' ); $settings = hivenza_settings(); $result = 'missing'; if ( '' !== $settings['chat_key'] ) { $response = wp_remote_get( hivenza_origin() . '/api/public/chat/' . rawurlencode( $settings['chat_key'] ), array( 'timeout' => 10, 'headers' => array( 'Accept' => 'application/json' ), ) ); if ( is_wp_error( $response ) ) { $result = 'unreachable'; } else { $code = (int) wp_remote_retrieve_response_code( $response ); $result = 200 === $code ? 'ok' : ( 404 === $code ? 'notfound' : 'error' ); } } wp_safe_redirect( add_query_arg( array( 'page' => 'hivenza', 'hivenza_test' => $result ), admin_url( 'options-general.php' ) ) ); exit; } add_action( 'admin_post_hivenza_test', 'hivenza_handle_test' ); /** * The result of the last test, as a notice. */ function hivenza_test_notice() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- only picks a message to show; nothing is changed. $result = isset( $_GET['hivenza_test'] ) ? sanitize_key( wp_unslash( $_GET['hivenza_test'] ) ) : ''; if ( '' === $result ) { return; } $messages = array( 'ok' => array( 'success', __( 'Connected. Hivenza answered for this chat key.', 'hivenza' ) ), 'notfound' => array( 'error', __( 'Hivenza does not know this chat key. Check it in Website chat, Install.', 'hivenza' ) ), 'unreachable' => array( 'error', __( 'This site could not reach hivenza.com. Check that your server allows outgoing connections.', 'hivenza' ) ), 'error' => array( 'warning', __( 'Hivenza answered with an error. Try again in a moment.', 'hivenza' ) ), 'missing' => array( 'warning', __( 'Save a chat key first, then test.', 'hivenza' ) ), ); if ( ! isset( $messages[ $result ] ) ) { return; } printf( '

%2$s

', esc_attr( $messages[ $result ][0] ), esc_html( $messages[ $result ][1] ) ); } /** * Render the settings page. */ function hivenza_render_settings_page() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'hivenza' ), '', array( 'response' => 403 ) ); } $s = hivenza_settings(); $pages = get_pages( array( 'sort_column' => 'post_title' ) ); $name = HIVENZA_OPTION; $locked = defined( 'HIVENZA_SECRET' ) && '' !== HIVENZA_SECRET; ?>

' . esc_html__( 'terms', 'hivenza' ) . '', '' . esc_html__( 'privacy policy', 'hivenza' ) . '' ); ?>