| @@ -1,40 +1,47 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Plugin Name: DeepL for WordPress : translation plugin | |
| 4 | - * Description: Get DeepL translation magic right inside your WordPress editor (with a paid DeepL Pro account) | |
| 5 | - * Version: 1.7.5.1 | |
| 3 | + * Plugin Name: Translation with DeepL API | |
| 4 | + * Description: Get DeepL translation magic right inside your WordPress editor (with a paid DeepL Pro account). This plugin is not affiliated with DeepL SE. | |
| 5 | + * Version: 2.6.2 | |
| 6 | 6 | * Plugin Slug: wpdeepl |
| 7 | 7 | * Author: Fluenx |
| 8 | 8 | * Author URI: https://www.fluenx.com/ |
| 9 | - * Requires at least: 4.0.0 | |
| 10 | - * Tested up to: 6.1 | |
| 9 | + * License: GPLv2 or later | |
| 10 | + * License URI: https://www.gnu.org/licenses/gpl-2.0.html | |
| 11 | 11 | * Text Domain: wpdeepl |
| 12 | 12 | * Domain Path: /languages |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -if( !function_exists( 'is_admin' ) || !is_admin() ) | |
| 15 | +//return; | |
| 16 | + | |
| 17 | +if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
| 18 | + | |
| 19 | +// exit early | |
| 20 | +$wpdeepl_allow_front_end = filter_var( get_option('wpdeepl_allow_front_end'), FILTER_VALIDATE_BOOLEAN ); | |
| 21 | +if( ! $wpdeepl_allow_front_end ) { | |
| 22 | + if ( !function_exists( 'is_admin' ) || !is_admin() ) | |
| 16 | 23 | return; |
| 24 | +} | |
| 17 | 25 | |
| 18 | -defined( 'WPDEEPL_FLAVOR' ) or define( 'WPDEEPL_FLAVOR', 'free' ); | |
| 19 | -defined( 'WPDEEPL_NAME' ) or define( 'WPDEEPL_NAME', plugin_basename( __FILE__ ) ); // plugin name as known by WP. | |
| 20 | -defined( 'WPDEEPL_SLUG' ) or define( 'WPDEEPL_SLUG', 'wpdeepl' );// plugin slug ( should match above meta: Text Domain ). | |
| 21 | -defined( 'WPDEEPL_DIR' ) or define( 'WPDEEPL_DIR', dirname( __FILE__ ) ); // our directory. | |
| 22 | -defined( 'WPDEEPL_PATH' ) or define( 'WPDEEPL_PATH', realpath( __DIR__ ) ); // our directory. | |
| 26 | +//defined( 'WPDEEPL_DEBUG' ) or define( 'WPDEEPL_DEBUG', false ); // Uncomment AND set to true to force debug mode | |
| 27 | +defined( 'WPDEEPL_FLAVOR' ) or define( 'WPDEEPL_FLAVOR', 'free' ); | |
| 28 | +defined( 'WPDEEPL_NAME' ) or define( 'WPDEEPL_NAME', plugin_basename( __FILE__ ) ); | |
| 29 | +defined( 'WPDEEPL_SLUG' ) or define( 'WPDEEPL_SLUG', 'wpdeepl' ); | |
| 30 | +defined( 'WPDEEPL_DIR' ) or define( 'WPDEEPL_DIR', dirname( __FILE__ ) ); | |
| 31 | +defined( 'WPDEEPL_PATH' ) or define( 'WPDEEPL_PATH', realpath( __DIR__ ) ); | |
| 23 | 32 | defined( 'WPDEEPL_URL' ) or define( 'WPDEEPL_URL', plugins_url( '', __FILE__ ) ); |
| 24 | -$plugin_data = get_file_data( __FILE__, array( 'Version' => 'Version' ), false ); | |
| 25 | -defined( 'WPDEEPL_VERSION' ) or define( 'WPDEEPL_VERSION', $plugin_data['Version'] ); | |
| 33 | + | |
| 34 | +$wpdeepl_plugin_data = get_file_data( __FILE__, array( 'Version' => 'Version' ), false ); | |
| 35 | +defined( 'WPDEEPL_VERSION' ) or define( 'WPDEEPL_VERSION', $wpdeepl_plugin_data['Version'] ); | |
| 26 | 36 | |
| 27 | -defined( 'WPDEEPL_DEBUG' ) or define( 'WPDEEPL_DEBUG', 0 ); | |
| 37 | +defined( 'WPDEEPL_DEBUG' ) or define( 'WPDEEPL_DEBUG', false ); | |
| 28 | 38 | |
| 29 | -$wp_upload_dir = wp_upload_dir(); | |
| 30 | -defined( 'WPDEEPL_FILES' ) or define( 'WPDEEPL_FILES', trailingslashit( $wp_upload_dir['basedir'] ) . 'wpdeepl' ); | |
| 31 | -defined( 'WPDEEPL_FILES_URL' ) or define( 'WPDEEPL_FILES_URL', trailingslashit( $wp_upload_dir['baseurl'] ) . 'wpdeepl' ); | |
| 32 | -if( !is_dir( WPDEEPL_FILES ) ) mkdir( WPDEEPL_FILES ); | |
| 39 | +$wpdeepl_upload_dir = wp_upload_dir(); | |
| 40 | +defined( 'WPDEEPL_FILES' ) or define( 'WPDEEPL_FILES', trailingslashit( $wpdeepl_upload_dir['basedir'] ) . 'wpdeepl' ); | |
| 41 | +defined( 'WPDEEPL_FILES_URL' ) or define( 'WPDEEPL_FILES_URL', trailingslashit( $wpdeepl_upload_dir['baseurl'] ) . 'wpdeepl' ); | |
| 33 | 42 | |
| 34 | -// obs 20210422 v1.7 defined( 'DEEPL_API_URL' ) or define( 'DEEPL_API_URL', 'https://api.deepl.com/v2/' ); | |
| 35 | - | |
| 36 | -function zebench_wpdeepl_paths( $paths = array() ) { | |
| 43 | +function wpdeepl_paths( $paths = array() ) { | |
| 37 | 44 | $paths['deepl_settings'] = array( |
| 38 | 45 | 'files' => WPDEEPL_FILES |
| 39 | 46 | ); |
| 40 | 47 | return $paths; |
| @@ -40,33 +47,62 @@ | ||
| 40 | 47 | return $paths; |
| 41 | 48 | } |
| 42 | 49 | |
| 43 | 50 | try { |
| 44 | - if( is_admin() ) { | |
| 45 | - require_once( trailingslashit( WPDEEPL_PATH ) . 'deepl-configuration.class.php' ); | |
| 46 | - require_once( trailingslashit( WPDEEPL_PATH ) . 'includes/deepl-functions.php' ); | |
| 47 | - require_once( trailingslashit( WPDEEPL_PATH ) . 'includes/deepl-plugin-install.php' ); | |
| 51 | + if ( is_admin() || $wpdeepl_allow_front_end ) { | |
| 48 | 52 | |
| 49 | - require_once( trailingslashit( WPDEEPL_PATH ) . 'admin/deepl-admin-hooks.php' ); | |
| 50 | - require_once( trailingslashit( WPDEEPL_PATH ) . 'admin/deepl-admin-functions.php' ); | |
| 51 | - require_once( trailingslashit( WPDEEPL_PATH ) . 'admin/deepl-metabox.php' ); | |
| 53 | + | |
| 54 | + include_once trailingslashit( WPDEEPL_PATH ) . 'deepl-configuration.class.php'; | |
| 55 | + | |
| 56 | + include_once trailingslashit( WPDEEPL_PATH ) . 'includes/deepl-functions.php'; | |
| 57 | + include_once trailingslashit( WPDEEPL_PATH ) . 'includes/deepl-plugin-install.php'; | |
| 58 | + | |
| 52 | 59 | |
| 53 | - require_once( trailingslashit( WPDEEPL_PATH ) . 'settings/wp-improved-settings-api.class.php' ); | |
| 54 | - require_once( trailingslashit( WPDEEPL_PATH ) . 'settings/wp-improved-settings.class.php' ); | |
| 55 | - require_once( trailingslashit( WPDEEPL_PATH ) . 'settings/wp-improved-settings-wpdeepl.class.php' ); | |
| 60 | + include_once trailingslashit( WPDEEPL_PATH ) . 'modules/deepl-translate-post.php'; | |
| 56 | 61 | |
| 57 | - require_once( trailingslashit( WPDEEPL_PATH ) . 'client/deepl-data.class.php' ); | |
| 58 | - require_once( trailingslashit( WPDEEPL_PATH ) . 'client/deeplapi.class.php' ); | |
| 59 | - require_once( trailingslashit( WPDEEPL_PATH ) . 'client/deeplapi-translate.class.php' ); | |
| 60 | - require_once( trailingslashit( WPDEEPL_PATH ) . 'client/deeplapi-usage.class.php' ); | |
| 61 | - require_once( trailingslashit( WPDEEPL_PATH ) . 'client/deeplapi-functions.php' ); | |
| 62 | - add_filter('zebench_plugins_paths', 'zebench_wpdeepl_paths'); | |
| 62 | + include_once trailingslashit( WPDEEPL_PATH ) . 'settings/wp-improved-settings-api.class.php'; | |
| 63 | + include_once trailingslashit( WPDEEPL_PATH ) . 'settings/wp-improved-settings.class.php'; | |
| 64 | + include_once trailingslashit( WPDEEPL_PATH ) . 'settings/wp-improved-settings-wpdeepl.class.php'; | |
| 65 | + | |
| 66 | + include_once trailingslashit( WPDEEPL_PATH ) . 'client/deepl-data.class.php'; | |
| 67 | + include_once trailingslashit( WPDEEPL_PATH ) . 'client/deeplapi-functions.php'; | |
| 68 | + include_once trailingslashit( WPDEEPL_PATH ) . 'client/deeplapi.class.php'; | |
| 69 | + include_once trailingslashit( WPDEEPL_PATH ) . 'client/deeplapi-translate.class.php'; | |
| 70 | + include_once trailingslashit( WPDEEPL_PATH ) . 'client/deeplapi-usage.class.php'; | |
| 71 | + | |
| 72 | + if( is_admin() ) { | |
| 73 | + include_once trailingslashit( WPDEEPL_PATH ) . 'admin/deepl-admin-hooks.php'; | |
| 74 | + include_once trailingslashit( WPDEEPL_PATH ) . 'admin/deepl-admin-functions.php'; | |
| 75 | + include_once trailingslashit( WPDEEPL_PATH ) . 'admin/deepl-metabox.php'; | |
| 76 | + //if( file_exists( trailingslashit( WPDEEPL_PATH ) . 'admin/deepl-elementor.php' ) include_once trailingslashit( WPDEEPL_PATH ) . 'admin/deepl-elementor.php'; | |
| 77 | + | |
| 78 | + } | |
| 79 | + | |
| 80 | + add_filter('zebench_plugins_paths', 'wpdeepl_paths'); | |
| 81 | + | |
| 82 | + $wpdeepl_customisation_file = trailingslashit( WPDEEPL_PATH ) . 'custom-integration.php'; | |
| 83 | + //echo "\n file $wpdeepl_customisation_file / exists ? " . file_exists( $wpdeepl_customisation_file ); | |
| 84 | + if ( file_exists( $wpdeepl_customisation_file ) ) { | |
| 85 | + include_once $wpdeepl_customisation_file; | |
| 86 | + } | |
| 87 | + else { | |
| 88 | + | |
| 89 | + } | |
| 90 | + | |
| 63 | 91 | } |
| 64 | -} catch ( Exception $e ) { | |
| 65 | - if( current_user_can( 'manage_options' ) ) { | |
| 66 | - print_r( $e ); | |
| 67 | - die( __( 'Error loading WPDeepL','wpdeepl' ) ); | |
| 92 | +} catch ( Exception $exception ) { | |
| 93 | + if ( current_user_can( 'manage_options' ) ) { | |
| 94 | + // En mode debug seulement, logger les erreurs | |
| 95 | + if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { | |
| 96 | + // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- Debug mode only | |
| 97 | + error_log( 'WPDeepL Fatal Error: ' . $exception->getMessage() . ' in ' . $exception->getFile() . ' on line ' . $exception->getLine() ); | |
| 98 | + } | |
| 99 | + wp_die( | |
| 100 | + esc_html__( 'Error loading WPDeepL', 'wpdeepl' ), | |
| 101 | + array( 'response' => 500 ) | |
| 102 | + ); | |
| 68 | 103 | } |
| 104 | + return; | |
| 69 | 105 | } |
| 70 | 106 | |
| 71 | 107 | |
| 72 | 108 | //global $DeepLForWordPress; $DeepLForWordPress = new DeepLForWordPress(); |
| @@ -72,30 +108,37 @@ | ||
| 72 | 108 | //global $DeepLForWordPress; $DeepLForWordPress = new DeepLForWordPress(); |
| 73 | 109 | function deepl_is_plugin_fully_configured() { |
| 74 | 110 | $WP_Error = new WP_Error(); |
| 75 | 111 | |
| 76 | - if( count( $WP_Error->get_error_messages() ) ) { | |
| 112 | + if ( count( $WP_Error->get_error_messages() ) ) { | |
| 77 | 113 | return $WP_Error; |
| 78 | 114 | } |
| 79 | 115 | return true; |
| 80 | 116 | } |
| 81 | 117 | |
| 82 | -if( !function_exists( 'plouf' ) ) { | |
| 83 | - function plouf( $e, $txt = '' ) { | |
| 84 | - if( $txt != '' ) echo "<br />\n$txt"; | |
| 85 | - echo '<pre>'; | |
| 86 | - print_r( $e ); | |
| 87 | - echo '</pre>'; | |
| 118 | +if ( !function_exists( 'wpdeepl_debug_display' ) ) { | |
| 119 | + function wpdeepl_debug_display( $e, $txt = '' ) { | |
| 120 | + | |
| 121 | + // En mode debug seulement | |
| 122 | + if ( 1 == 1 ) { | |
| 123 | + if ( $txt != '' ) echo esc_html( "<br />\n$txt" ); | |
| 124 | + ?> | |
| 125 | + <pre><?php | |
| 126 | + // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r -- Debug mode seulement | |
| 127 | + print_r( $e ); | |
| 128 | + ?> | |
| 129 | + </pre><?php | |
| 130 | + } | |
| 88 | 131 | } |
| 89 | 132 | } |
| 90 | 133 | |
| 91 | 134 | add_action( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'wpdeepl_plugin_action_links' ); |
| 92 | 135 | function wpdeepl_plugin_action_links( $links ) { |
| 93 | - $links = array_merge( | |
| 136 | + $links = array_merge( | |
| 94 | 137 | array( |
| 95 | 138 | '<a href="' . esc_url( admin_url( '/options-general.php?page=deepl_settings' ) ) . '">' . __( 'Settings', 'wpdeepl' ) . '</a>' |
| 96 | - ), | |
| 97 | - $links | |
| 139 | + ), | |
| 140 | + $links | |
| 98 | 141 | ); |
| 99 | 142 | return $links; |
| 100 | 143 | } |
| 101 | 144 | |
| @@ -107,13 +150,10 @@ | ||
| 107 | 150 | register_deactivation_hook( __FILE__, 'deepl_plugin_deactivate' ); |
| 108 | 151 | function deepl_plugin_deactivate() { |
| 109 | 152 | } |
| 110 | 153 | |
| 111 | - | |
| 112 | 154 | add_action( 'init', 'deepl_init' ); |
| 113 | 155 | function deepl_init() { |
| 114 | - if( !is_admin() ) { | |
| 156 | + if ( !is_admin() ) { | |
| 115 | 157 | return; |
| 116 | 158 | } |
| 117 | - | |
| 118 | - load_plugin_textdomain( 'wpdeepl', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); | |
| 119 | 159 | } |