PluginProbe
Translate and Go multilingual – Automatic AI translation – wpLingua / 2.16.7
Translate and Go multilingual – Automatic AI translation – wpLingua v2.16.7
2.16.7 2.16.6 2.16.5 2.16.4 2.16.3 2.16.2 2.16.1 2.16.0 2.15.2 2.15.1 2.15.0 2.14.3 2.14.2 2.14.1 2.14.0 2.13.1 2.13.0 2.12.3 2.12.2 2.12.1 trunk 1.0.3 1.0.4 1.0.5 1.1.0 All 112 releases
wplingua / inc / dom / load-overload.php

load-overload.php in Translate and Go multilingual – Automatic AI translation – wpLingua 2.16.7, at inc/dom/load-overload.php

77 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // If this file is called directly, abort.
4 if ( ! defined( 'WPINC' ) ) {
5 die;
6 }
7
8
9 /**
10 * Overloads the DOM with a notification if the Translation API is overloaded.
11 *
12 * This function modifies the DOM to include a notification message when the
13 * Translation API is overloaded. It checks the provided arguments and user
14 * permissions before making changes to the DOM.
15 *
16 * @param object $dom The DOM object to be modified.
17 * @param array $args An array of arguments, including 'load' and 'overloaded' keys.
18 * @return object The modified DOM object.
19 */
20 function wplng_dom_load_overload( $dom, $args ) {
21
22 wplng_args_setup( $args );
23
24 if ( empty( $args['overloaded'] )
25 || ! current_user_can( 'edit_posts' )
26 ) {
27 return $dom;
28 }
29
30 $html = '<div id="wplng-overloaded-container">';
31
32 $html .= '<span class="dashicons dashicons-info-outline"></span> ';
33
34 $html .= '<span id="wplng-overloaded-text-mobile">';
35 $html .= esc_html__( 'Translation API overloaded', 'wplingua' );
36 $html .= '</span>';
37
38 $api_data = wplng_get_api_data();
39
40 if ( empty( $api_data['status'] ) || $api_data['status'] === 'FREE' ) {
41 $html .= '<span id="wplng-overloaded-text-desktop">';
42 $html .= esc_html__( 'Translation API overloaded. Retry in a few minutes or ', 'wplingua' );
43 $html .= '<a href="https://wplingua.com/pricing/" target="_blank" rel="noopener noreferrer">';
44 $html .= esc_html__( 'upgrade your API key', 'wplingua' );
45 $html .= '</a>';
46 $html .= esc_html__( ' to get priority API access.', 'wplingua' );
47 $html .= '</span>';
48 } else {
49 $html .= '<span id="wplng-overloaded-text-desktop">';
50 $html .= esc_html__( 'Translation API overloaded. Please retry in a few minutes.', 'wplingua' );
51 $html .= '</span>';
52 }
53
54 $html .= '<span';
55 $html .= ' id="wplng-overloaded-close"';
56 $html .= ' class="dashicons dashicons-no-alt"';
57 $html .= ' title="' . esc_attr__( 'Close', 'wplingua' ) . '"';
58 $html .= '></span>';
59
60 $html .= '</div>'; // End #wplng-overloaded-container
61
62 foreach ( $dom->find( 'body' ) as $body ) {
63
64 // Add body clas .wplingua-api-overloaded
65 if ( isset( $body->class ) ) {
66 $body->class .= ' wplingua-api-overloaded';
67 } else {
68 $body->class = 'wplingua-api-overloaded';
69 }
70
71 // Add "API overloaded" HTML bar to body
72 $body->innertext .= $html;
73 }
74
75 return $dom;
76 }
77