[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/ -> glotpress.php (source)

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


Generated: Thu Nov 21 01:01:07 2024 Cross-referenced by PHPXref 0.7.1