Skip to content

Commit

Permalink
Merge pull request #1209 from alleyinteractive/hotfix/issue-1208/load…
Browse files Browse the repository at this point in the history
…-textdomain-error-wordpress-6-7

issue-1208: Improve i18n support for WordPress 6.7
  • Loading branch information
renatonascalves authored Jan 28, 2025
2 parents 5cd5b7a + 31184e7 commit 77d5372
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 44 deletions.
37 changes: 10 additions & 27 deletions apple-news.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
<?php
/**
* Entry point for the plugin.
*
* This file is read by WordPress to generate the plugin information in the
* admin panel.
*
* @link http://github.com/alleyinteractive/apple-news
* @since 0.2.0
* @package WP_Plugin
*/

/*
* Plugin Name: Publish to Apple News
* Plugin Name: Publish To Apple News
* Plugin URI: http://github.com/alleyinteractive/apple-news
* Description: Export and sync posts to Apple format.
* Version: 2.6.1
* Author: Alley
* Author URI: https://alley.com
* Text Domain: apple-news
* Domain Path: lang/
* License: GPLv3 or later
* License URI: https://www.gnu.org/licenses/gpl.html
*
* @package Apple_News
*/

/**
Expand Down Expand Up @@ -79,29 +71,20 @@ function apple_news_uninstall_wp_plugin() {
require __DIR__ . '/includes/class-apple-news.php';
require __DIR__ . '/admin/class-admin-apple-news.php';

/**
* Load plugin textdomain.
*
* @since 0.9.0
*/
function apple_news_load_textdomain() {
load_plugin_textdomain( 'apple-news', false, __DIR__ . '/lang' );
}
add_action( 'plugins_loaded', 'apple_news_load_textdomain' );

/**
* Gets plugin data.
* Used to provide generator info in the metadata class.
*
* @return array
*
* @since 1.0.4
*
* @param bool $translate Whether to translate the plugin data.
* @return array
*/
function apple_news_get_plugin_data() {
function apple_news_get_plugin_data( $translate = true ) {
if ( ! function_exists( 'get_plugin_data' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
return get_plugin_data( __DIR__ . '/apple-news.php' );
return get_plugin_data( __DIR__ . '/apple-news.php', true, $translate );
}

new Admin_Apple_News();
Expand Down
34 changes: 20 additions & 14 deletions includes/class-apple-news.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,34 +365,37 @@ public static function has_uninitialized_error(): WP_Error|null {

/**
* Constructor. Registers action hooks.
*
* @access public
*/
public function __construct() {
add_action(
'admin_enqueue_scripts',
[ $this, 'action_admin_enqueue_scripts' ]
);

add_action(
'enqueue_block_editor_assets',
[ $this, 'action_enqueue_block_editor_assets' ]
);

add_action(
'plugins_loaded',
[ $this, 'action_plugins_loaded' ]
'init',
[ $this, 'action_init' ]
);

add_filter(
'update_post_metadata',
[ $this, 'filter_update_post_metadata' ],
10,
5
);

add_filter(
'author_link',
[ $this, 'filter_author_link' ],
10,
3
);

add_filter(
'the_author',
[ $this, 'filter_the_author' ],
Expand Down Expand Up @@ -471,21 +474,21 @@ public function action_enqueue_block_editor_assets(): void {
}

/**
* Action hook callback for plugins_loaded.
* Action hook callback for init.
*
* @since 1.3.0
*/
public function action_plugins_loaded(): void {
public function action_init(): void {

// Determine if the database version and code version are the same.
$current_version = get_option( 'apple_news_version' );
if ( version_compare( $current_version, self::$version, '>=' ) ) {
$current_version = get_option( 'apple_news_version', '' );
if ( is_string( $current_version ) && version_compare( $current_version, self::$version, '>=' ) ) {
return;
}

// Determine if this is a clean install (no settings set yet).
$settings = get_option( self::$option_name );
if ( ! empty( $settings ) ) {
if ( ! empty( $settings ) && is_string( $current_version ) ) {

// Handle upgrade to version 1.3.0.
if ( version_compare( $current_version, '1.3.0', '<' ) ) {
Expand Down Expand Up @@ -517,8 +520,6 @@ public function action_plugins_loaded(): void {

/**
* Create the default themes, if they do not exist.
*
* @access public
*/
public function create_default_theme(): void {

Expand All @@ -529,9 +530,14 @@ public function create_default_theme(): void {
}

// Build the theme formatting settings from the base settings array.
$theme = new Theme();
$options = Theme::get_options();
$wp_settings = get_option( self::$option_name, [] );
$theme = new Theme();
$options = Theme::get_options();
$wp_settings = get_option( self::$option_name, [] );

if ( ! is_array( $wp_settings ) ) {
$wp_settings = [];
}

$theme_settings = [];
foreach ( array_keys( $options ) as $option_key ) {
if ( isset( $wp_settings[ $option_key ] ) ) {
Expand Down
1 change: 0 additions & 1 deletion lang/apple-export.pot

This file was deleted.

10 changes: 9 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ Please visit our [wiki](https://github.com/alleyinteractive/apple-news/wiki) for

== Changelog ==

= 2.6.2 =

* Enhancement: i18n - Remove `load_plugin_textdomain`. Since WordPress 4.6, plugins no longer need to load their own textdomain.
* Enhancement: i18n - Moved some plugin initialization code to the `init` action hook.
* Bugfix: i18n - Fixed the `_load_textdomain_just_in_time` error with WordPress 6.7.
* Bugfix: Update plugin name in plugin header.
* Enhancement: Add license to plugin header.

= 2.6.1 =

* Enhancement: Ensured support for WordPress 6.7.
Expand Down Expand Up @@ -90,4 +98,4 @@ Information on previous releases can be found on the plugin's [GitHub Releases p

== Developers ==

Please visit us on [github](https://github.com/alleyinteractive/apple-news) to [submit issues](https://github.com/alleyinteractive/apple-news/issues), [pull requests](https://github.com/alleyinteractive/apple-news/pulls) or [read our wiki page about contributing](https://github.com/alleyinteractive/apple-news/wiki/contributing).
Please visit us on [GitHub](https://github.com/alleyinteractive/apple-news) to [submit issues](https://github.com/alleyinteractive/apple-news/issues), [pull requests](https://github.com/alleyinteractive/apple-news/pulls) or [read our wiki page about contributing](https://github.com/alleyinteractive/apple-news/wiki/contributing).
2 changes: 1 addition & 1 deletion tests/test-class-apple-news.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public function test_upgrade_to_2_5_0(): void {
* @see Apple_News::$version
*/
public function test_version() {
$plugin_data = apple_news_get_plugin_data();
$plugin_data = apple_news_get_plugin_data( translate: false );
$this->assertEquals( Apple_News::$version, $plugin_data['Version'] );
}
}

0 comments on commit 77d5372

Please sign in to comment.