[ Index ] |
PHP Cross Reference of GlotPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Plugin Name: GlotPress 4 * Plugin URI: https://wordpress.org/plugins/glotpress/ 5 * Description: GlotPress is a tool to help translators collaborate. 6 * Version: 3.0.0-alpha.2 7 * Author: the GlotPress team 8 * Author URI: https://glotpress.blog 9 * License: GPLv2 or later 10 * Text Domain: glotpress 11 * 12 * This program is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU General Public License 14 * as published by the Free Software Foundation; either version 2 15 * of the License, or (at your option) any later version. 16 * 17 * This program is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU General Public License for more details. 21 * 22 * You should have received a copy of the GNU General Public License 23 * along with this program; if not, write to the Free Software 24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 25 * 26 * @package GlotPress 27 */ 28 29 define( 'GP_VERSION', '3.0.0-alpha.2' ); 30 define( 'GP_DB_VERSION', '980' ); 31 define( 'GP_CACHE_VERSION', '3.0' ); 32 define( 'GP_ROUTING', true ); 33 define( 'GP_PLUGIN_FILE', __FILE__ ); 34 define( 'GP_PATH', __DIR__ . '/' ); 35 define( 'GP_INC', 'gp-includes/' ); 36 define( 'GP_WP_REQUIRED_VERSION', '4.6' ); 37 define( 'GP_PHP_REQUIRED_VERSION', '7.2' ); 38 39 /** 40 * Displays an admin notice on the plugins page that GlotPress has been disabled and why.. 41 * 42 * @param string $short_notice The message to display on the first line of the notice beside "GlotPress Disabled". 43 * @param string $long_notice The message to display below the "GlotPress Disabled" line. 44 * 45 * @since 2.0.0 46 */ 47 function gp_display_disabled_admin_notice( $short_notice, $long_notice ) { 48 $screen = get_current_screen(); 49 50 if ( 'plugins' !== $screen->id ) { 51 return; 52 } 53 ?> 54 <div class="notice notice-error"> 55 <p style="max-width:800px;"> 56 <b><?php _e( 'GlotPress Disabled', 'glotpress' ); ?></b> 57 <?php 58 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped 59 echo $short_notice; 60 ?> 61 </p> 62 <p style="max-width:800px;"> 63 <?php 64 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped 65 echo $long_notice; 66 ?> 67 </p> 68 </div> 69 <?php 70 } 71 72 /** 73 * Adds a message if the required minimum PHP version is not detected. 74 * 75 * Message is only displayed on the plugin screen. 76 * 77 * @since 2.0.0 78 */ 79 function gp_unsupported_php_version_notice() { 80 $short_notice = __( '— You are running an unsupported version of PHP.', 'glotpress' ); 81 $long_notice = sprintf( 82 /* translators: %s: required PHP version */ 83 __( 'GlotPress requires PHP Version %s, please upgrade to run GlotPress.', 'glotpress' ), 84 GP_PHP_REQUIRED_VERSION 85 ); 86 87 gp_display_disabled_admin_notice( $short_notice, $long_notice ); 88 } 89 90 /* 91 * Check the PHP version, if it's not a supported version, return without running 92 * any more code as the user will not be able to access GlotPress 93 * any errors and show an admin notice. 94 */ 95 if ( version_compare( phpversion(), GP_PHP_REQUIRED_VERSION, '<' ) ) { 96 add_action( 'admin_notices', 'gp_unsupported_php_version_notice', 10, 2 ); 97 98 // Bail out now so no additional code is run. 99 return; 100 } 101 102 /** 103 * Adds a message if an incompatible version of WordPress is running. 104 * 105 * Message is only displayed on the plugin screen. 106 * 107 * @since 1.0.0 108 */ 109 function gp_unsupported_version_admin_notice() { 110 global $wp_version; 111 112 $short_notice = __( '— You are running an unsupported version of WordPress.', 'glotpress' ); 113 $long_notice = sprintf( 114 /* translators: 1: Required version of WordPress 2: Current version of WordPress */ 115 __( 'GlotPress requires WordPress %1$s or later and has detected you are running %2$s. Upgrade your WordPress install or deactivate the GlotPress plugin to remove this message.', 'glotpress' ), 116 esc_html( GP_WP_REQUIRED_VERSION ), 117 esc_html( $wp_version ) 118 ); 119 120 gp_display_disabled_admin_notice( $short_notice, $long_notice ); 121 } 122 123 /* 124 * Check the WP version, if we don't meet the minimum version to run GlotPress 125 * return so we don't cause any errors and show an admin notice. 126 */ 127 if ( version_compare( $GLOBALS['wp_version'], GP_WP_REQUIRED_VERSION, '<' ) ) { 128 add_action( 'admin_notices', 'gp_unsupported_version_admin_notice', 10, 2 ); 129 130 // Bail out now so no additional code is run. 131 return; 132 } 133 134 /** 135 * Adds a message if no permalink structure is detected . 136 * 137 * Message is only displayed on the plugin screen. 138 * 139 * @since 2.0.0 140 */ 141 function gp_unsupported_permalink_structure_admin_notice() { 142 $short_notice = __( '— You are running an unsupported permalink structure.', 'glotpress' ); 143 /* translators: %s: URL to permalink settings */ 144 $long_notice = __( 'GlotPress requires a custom permalink structure to be enabled. Please go to <a href="%s">Permalink Settings</a> and enable an option other than Plain.', 'glotpress' ); 145 $long_notice = sprintf( $long_notice, admin_url( 'options-permalink.php' ) ); 146 147 gp_display_disabled_admin_notice( $short_notice, $long_notice ); 148 } 149 150 /* 151 * Check the permalink structure, if we don't have one (aka the rewrite engine is disabled) 152 * return without running any more code as the user will not be able to access GlotPress 153 * any errors and show an admin notice. 154 */ 155 if ( ! get_option( 'permalink_structure' ) ) { 156 add_action( 'admin_notices', 'gp_unsupported_permalink_structure_admin_notice', 10, 2 ); 157 158 // Bail out now so no additional code is run. 159 return; 160 } 161 162 require_once GP_PATH . 'gp-settings.php'; 163 164 /** 165 * Perform necessary actions on activation. 166 * 167 * @since 1.0.0 168 */ 169 function gp_activate_plugin() { 170 $admins = GP::$permission->find_one( array( 'action' => 'admin' ) ); 171 if ( ! $admins ) { 172 GP::$permission->create( 173 array( 174 'user_id' => get_current_user_id(), 175 'action' => 'admin', 176 ) 177 ); 178 } 179 } 180 register_activation_hook( GP_PLUGIN_FILE, 'gp_activate_plugin' ); 181 182 /** 183 * Run the plugin de-activation code. 184 * 185 * @since 1.0.0 186 * 187 * @param bool $network_wide Whether the plugin is deactivated for all sites in the network 188 * or just the current site. 189 */ 190 function gp_deactivate_plugin( $network_wide ) { 191 /* 192 * Flush the rewrite rule option so it will be re-generated next time the plugin is activated. 193 * If network deactivating, ensure we flush the option on every site. 194 */ 195 if ( $network_wide ) { 196 $sites = get_sites(); 197 198 foreach ( $sites as $site ) { 199 switch_to_blog( $site->blog_id ); 200 update_option( 'gp_rewrite_rule', '' ); 201 restore_current_blog(); 202 } 203 } else { 204 update_option( 'gp_rewrite_rule', '' ); 205 } 206 207 } 208 register_deactivation_hook( GP_PLUGIN_FILE, 'gp_deactivate_plugin' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Jan 26 01:01:55 2021 | Cross-referenced by PHPXref 0.7.1 |