[ 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: 2.4.0-alpha
   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', '2.4.0-alpha' );
  30  define( 'GP_DB_VERSION', '990' );
  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.4' );
  37  define( 'GP_PHP_REQUIRED_VERSION', '5.6' );
  38  
  39  // Load the plugin's translated strings.
  40  load_plugin_textdomain( 'glotpress' );
  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;"><b><?php _e( 'GlotPress Disabled', 'glotpress' );?></b> <?php echo $short_notice; // WPCS: xss ok. ?></p>
  59          <p style="max-width:800px;"><?php echo $long_notice; // WPCS: xss ok. ?></p>
  60      </div>
  61  <?php
  62  }
  63  
  64  /**
  65   * Adds a message if the required minimum PHP version is not detected.
  66   *
  67   * Message is only displayed on the plugin screen.
  68   *
  69   * @since 2.0.0
  70   */
  71  function gp_unsupported_php_version_notice() {
  72      $short_notice = __( '&#151; You are running an unsupported version of PHP.', 'glotpress' );
  73      $long_notice = sprintf(
  74          /* translators: %s: required PHP version */
  75          __( 'GlotPress requires PHP Version %s, please upgrade to run GlotPress.', 'glotpress' ),
  76          GP_PHP_REQUIRED_VERSION
  77      );
  78  
  79      gp_display_disabled_admin_notice( $short_notice, $long_notice );
  80  }
  81  
  82  /*
  83   * Check the PHP version, if it's not a supported version, return without running
  84   * any more code as the user will not be able to access GlotPress
  85   * any errors and show an admin notice.
  86   */
  87  if ( version_compare( phpversion(), GP_PHP_REQUIRED_VERSION, '<' ) ) {
  88      add_action( 'admin_notices', 'gp_unsupported_php_version_notice', 10, 2 );
  89  
  90      // Bail out now so no additional code is run.
  91      return;
  92  }
  93  
  94  /**
  95   * Adds a message if an incompatible version of WordPress is running.
  96   *
  97   * Message is only displayed on the plugin screen.
  98   *
  99   * @since 1.0.0
 100   */
 101  function gp_unsupported_version_admin_notice() {
 102      global $wp_version;
 103  
 104      $short_notice = __( '&#151; You are running an unsupported version of WordPress.', 'glotpress' );
 105      $long_notice = sprintf(
 106          /* translators: 1: Required version of WordPress 2: Current version of WordPress */
 107          __( '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' ),
 108          esc_html( GP_WP_REQUIRED_VERSION ),
 109          esc_html( $wp_version )
 110      );
 111  
 112      gp_display_disabled_admin_notice( $short_notice, $long_notice );
 113  }
 114  
 115  /*
 116   * Check the WP version, if we don't meet the minimum version to run GlotPress
 117   * return so we don't cause any errors and show an admin notice.
 118   */
 119  if ( version_compare( $GLOBALS['wp_version'], GP_WP_REQUIRED_VERSION, '<' ) ) {
 120      add_action( 'admin_notices', 'gp_unsupported_version_admin_notice', 10, 2 );
 121  
 122      // Bail out now so no additional code is run.
 123      return;
 124  }
 125  
 126  /**
 127   * Adds a message if no permalink structure is detected .
 128   *
 129   * Message is only displayed on the plugin screen.
 130   *
 131   * @since 2.0.0
 132   */
 133  function gp_unsupported_permalink_structure_admin_notice() {
 134      $short_notice = __( '&#151; You are running an unsupported permalink structure.', 'glotpress' );
 135      /* translators: %s: URL to permalink settings */
 136      $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' );
 137      $long_notice = sprintf( $long_notice, admin_url( 'options-permalink.php' ) );
 138  
 139      gp_display_disabled_admin_notice( $short_notice, $long_notice );
 140  }
 141  
 142  /*
 143   * Check the permalink structure, if we don't have one (aka the rewrite engine is disabled)
 144   * return without running any more code as the user will not be able to access GlotPress
 145   * any errors and show an admin notice.
 146   */
 147  if ( ! get_option( 'permalink_structure' ) ) {
 148      add_action( 'admin_notices', 'gp_unsupported_permalink_structure_admin_notice', 10, 2 );
 149  
 150      // Bail out now so no additional code is run.
 151      return;
 152  }
 153  
 154  require_once  GP_PATH . 'gp-settings.php';
 155  
 156  /**
 157   * Perform necessary actions on activation.
 158   *
 159   * @since 1.0.0
 160   */
 161  function gp_activate_plugin() {
 162      $admins = GP::$permission->find_one( array( 'action' => 'admin' ) );
 163      if ( ! $admins ) {
 164          GP::$permission->create( array( 'user_id' => get_current_user_id(), 'action' => 'admin' ) );
 165      }
 166  }
 167  register_activation_hook( GP_PLUGIN_FILE, 'gp_activate_plugin' );
 168  
 169  /**
 170   * Run the plugin de-activation code.
 171   *
 172   * @since 1.0.0
 173   *
 174   * @param bool $network_wide Whether the plugin is deactivated for all sites in the network
 175   *                           or just the current site.
 176   */
 177  function gp_deactivate_plugin( $network_wide ) {
 178      /*
 179       * Flush the rewrite rule option so it will be re-generated next time the plugin is activated.
 180       * If network deactivating, ensure we flush the option on every site.
 181       */
 182      if ( $network_wide ) {
 183          $sites = get_sites();
 184  
 185          foreach ( $sites as $site ) {
 186              switch_to_blog( $site->blog_id );
 187              update_option( 'gp_rewrite_rule', '' );
 188              restore_current_blog();
 189          }
 190      } else {
 191          update_option( 'gp_rewrite_rule', '' );
 192      }
 193  
 194  }
 195  register_deactivation_hook( GP_PLUGIN_FILE, 'gp_deactivate_plugin' );


Generated: Sat Dec 15 01:02:18 2018 Cross-referenced by PHPXref 0.7.1