Skip to content

Commit

Permalink
Cleanup and some minor adjustments.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauteri committed Dec 18, 2023
2 parents e706966 + d454721 commit bc5f51e
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 26 deletions.
37 changes: 13 additions & 24 deletions gatherpress.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php
/**
* Plugin Name: GatherPress
* Plugin URI: https://gatherpress.org/
* Description: Powering Communities with WordPress.
* Author: The GatherPress Community
* Author URI: https://gatherpress.org/
* Version: 0.26.0
* Minimum PHP Version: 7.4
* Text Domain: gatherpress
* Domain Path: /languages
* License: GPLv2 or later (license.txt)
* Plugin Name: GatherPress
* Plugin URI: https://gatherpress.org/
* Description: Powering Communities with WordPress.
* Author: The GatherPress Community
* Author URI: https://gatherpress.org/
* Version: 0.26.0
* Requires PHP: 7.4
* Text Domain: gatherpress
* License: GPLv2 or later (license.txt)
*
* This file serves as the main plugin file for GatherPress. It defines the plugin's basic information,
* constants, and initializes the plugin.
Expand All @@ -18,29 +17,19 @@
*/

// Constants.
define( 'GATHERPRESS_VERSION', current( get_file_data( __FILE__, array( 'Version' ), 'plugin' ) ) );
define( 'GATHERPRESS_MINIMUM_PHP_VERSION', current( get_file_data( __FILE__, array( 'Minimum PHP Version' ), 'plugin' ) ) );
define( 'GATHERPRESS_CORE_PATH', __DIR__ );
define( 'GATHERPRESS_CORE_FILE', __FILE__ );
define( 'GATHERPRESS_CORE_PATH', __DIR__ );
define( 'GATHERPRESS_CORE_URL', plugin_dir_url( __FILE__ ) );
define( 'GATHERPRESS_DIR_NAME', dirname( plugin_basename( __FILE__ ) ) );
define( 'GATHERPRESS_REQUIRES_PHP', current( get_file_data( __FILE__, array( 'Requires PHP' ), 'plugin' ) ) );
define( 'GATHERPRESS_REST_NAMESPACE', 'gatherpress/v1' );
define( 'GATHERPRESS_VERSION', current( get_file_data( __FILE__, array( 'Version' ), 'plugin' ) ) );

// Check if the minimum plugin requirements are not met and prevent further execution if necessary.
if ( ! require_once GATHERPRESS_CORE_PATH . '/includes/core/requirements-check.php' ) {
return;
}

// Load the plugin textdomain 'gatherpress' and find language files in gatherpress/languages when missing in wp-content/languages/plugins/
function gatherpress_load_textdomain( $mofile, $domain ) {
if ( 'gatherpress' === $domain && false !== strpos( $mofile, WP_LANG_DIR . '/plugins/' ) ) {
$locale = apply_filters( 'plugin_locale', determine_locale(), $domain );
$mofile = WP_PLUGIN_DIR . '/' . dirname( plugin_basename( __FILE__ ) ) . '/languages/' . $domain . '-' . $locale . '.mo';
}
return $mofile;
}

load_plugin_textdomain( 'gatherpress', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );

// Include and register the autoloader class for automatic loading of plugin classes.
require_once GATHERPRESS_CORE_PATH . '/includes/core/classes/class-autoloader.php';
GatherPress\Core\Autoloader::register();
Expand Down
39 changes: 39 additions & 0 deletions includes/core/classes/class-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ protected function setup_hooks(): void {
register_activation_hook( GATHERPRESS_CORE_FILE, array( $this, 'activate_gatherpress_plugin' ) );
register_deactivation_hook( GATHERPRESS_CORE_FILE, array( $this, 'deactivate_gatherpress_plugin' ) );

add_action( 'init', array( $this, 'load_textdomain' ) );
add_action( 'init', array( $this, 'register' ) );
add_action( 'delete_post', array( $this, 'delete_event' ) );
add_action(
Expand Down Expand Up @@ -119,6 +120,44 @@ protected function setup_hooks(): void {
),
array( $this, 'filter_plugin_action_links' )
);
add_filter( 'load_textdomain_mofile', array( $this, 'load_mofile' ), 10, 2 );
}

/**
* Loads gatherpress for GatherPress.
*
* @todo needed until plugin is added to wordpress.org plugin directory.
*
* @return void
*/
public function load_textdomain(): void {
load_plugin_textdomain( 'gatherpress', false, GATHERPRESS_DIR_NAME . '/languages' );
}

/**
* Find language files in gatherpress/languages when missing in wp-content/languages/plugins/
*
* The translation files will be in wp-content/languages/plugins/ once the plugin on the
* repository and translated in translate.wordpress.org.
*
* @todo needed until plugin is added to wordpress.org plugin directory.
*
* Until that, we need to load from /languages folder and load the textdomain.
* See https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#plugins-on-wordpress-org.
*
* @since 1.0.0
*
* @param string $mofile The path to the translation file.
* @param string $domain The text domain of the translation file.
* @return string The updated path to the translation file based on the locale
*/
public function load_mofile( string $mofile, string $domain ): string {
if ( 'gatherpress' === $domain && false !== strpos( $mofile, WP_LANG_DIR . '/plugins/' ) ) {
$locale = apply_filters( 'plugin_locale', determine_locale(), $domain ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
$mofile = WP_PLUGIN_DIR . '/' . GATHERPRESS_DIR_NAME . '/languages/' . $domain . '-' . $locale . '.mo';
}

return $mofile;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions includes/core/requirements-check.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
$gatherpress_activation = true;

// Check the PHP version to ensure compatibility with the plugin.
if ( version_compare( PHP_VERSION_ID, GATHERPRESS_MINIMUM_PHP_VERSION, '<' ) ) {
if ( version_compare( PHP_VERSION_ID, GATHERPRESS_REQUIRES_PHP, '<' ) ) {
add_action(
'admin_notices',
static function () {
Expand All @@ -25,7 +25,7 @@ static function () {
'GatherPress requires PHP %1$s or higher. Your current PHP version is %2$s. Please upgrade.',
'gatherpress'
),
esc_html( GATHERPRESS_MINIMUM_PHP_VERSION ),
esc_html( GATHERPRESS_REQUIRES_PHP ),
esc_html( phpversion() )
);
?>
Expand Down
40 changes: 40 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
=== GatherPress ===
Contributors: mauteri,hrmervin,jmarx,meaganhanes,pbrocks
Tags: events, event, meetup, community
License: GNU General Public License v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Requires PHP: 7.4
Requires at least: 6.4
Tested up to: 6.4
Stable tag: 0.26.0

GatherPress, a plugin created by and for the WordPress community, is a response to the community's desire for novel event management tools. Its agenda and roadmap align with that of the WordPress community, ensuring that it evolves in tandem with our collective wants and needs.

== Description ==

Lipsum

= Contribute to GatherPress =

If you wish to share in the collaborative of work to build GatherPress, please drop us a line either via WordPress Slack, or message us directly on our site https://gatherpress.org/get-involved

Lipsum

== Installation ==

= Requirements =

To run GatherPress, we recommend your host supports:

* PHP version 7.4 or greater.
* MySQL version 5.6 or greater, or, MariaDB version 10.0 or greather.
* HTTPS support.

= Automatic installation =

Lipsum

== Upgrade Notice ==

= 1.0.0 =
See: https://gatherpress.org/releases/version-1-0-0

0 comments on commit bc5f51e

Please sign in to comment.