Skip to content

Commit

Permalink
"Notice: Function _load_textdomain_just_in_time was called incorrectl…
Browse files Browse the repository at this point in the history
…y." (Logger class was executed before init hook in class Core)
  • Loading branch information
jcvignoli committed Nov 16, 2024
1 parent dc5b28f commit 3719415
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 68 deletions.
4 changes: 4 additions & 0 deletions dist/ACKNOWLEDGMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@
**PHP Mess detector** by [PHPMD](https://phpmd.org/ "PHPMD website")
**PHPStan** by [PHPStan](https://github.com/phpstan/phpstan "PHPStan GIT")
**PSALM** by [Vimeo](https://github.com/vimeo/psalm "Psalm GIT")

# History of core IMDbPHP libraries
Originally, this WordPress plugin originated from an IMDBPHP library created by [Andreas Itzchak Rehberg](https://izzy.rehbergs.info/ "Personal Websie"). A few years later, when Andreas got tired, T. Boothmman took over [IMDbPHP](https://github.com/tboothman/imdbphp/ "IMDbPHP GIT"). Nowadays, this plugin used a modified version of the latter with improvements brought by [Duck700](https://github.com/duck7000/imdbGraphQLPHP "IMDbGraphQLPHP GIT"). At some point, since IMDbPHP is not updated anymore, will switch completely to this new library.
Lumiere WordPress plugin has been actively developped and maintained for 20 years.
10 changes: 6 additions & 4 deletions dist/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

v.4.2.2
* [technical] Renamed get_compat_* methods in Settings to get_*_tablename, those methods return now automatically the current row name in wp_option only
* [bug] "Notice: Function _load_textdomain_just_in_time was called incorrectly." (Logger class was executed before init hook in class Core)

v.4.2.1
* [feature] Added Spouses and Children to people popups full biography section
Expand All @@ -13,6 +14,7 @@ v.4.2.1
* [technical] Taxonomy pages for people also retrieve pages written about the person (previously only posts were retrieved, added 'page' to queries in classes Polylang and Taxonomy_People_Standard)
* [technical] Renamed database table names (from imdb* to lumiere_*)
* [technical] Added notice for deprecated movie methods
* [technical] Updated to Monolog 2.10

v.4.2
* [technical] Compatible 6.7 (load_plugin_textdomain() is loaded in add_action('init') in class Core)
Expand Down Expand Up @@ -76,7 +78,7 @@ v.4.1
* [feature] The color of links to taxonomy pages is now different than to popups, for better understanding of what comes next. More respectful of plugin user css, not modifing links into the posts except in Lumière area (used to change to grey color the links)
* [feature] Pages can include Lumière widgets. Only post previously could. Exceptions to auto title widget can also be added into pages.
* [bug] Custom stylesheet added in personal theme folder wasn't working (now unregister main style and register the custom style in Core class if a parent or child theme is found)
* [bug] Frontpage and administration stylesheets standardised, less conflict should be witnessed with themes
* [bug] Frontpage and administration stylesheets standardised, less conflict is expected with themes
* [bug] If using Highslide modal window with OceanWP theme, pictures were somewhat taken between an extra box created by OceanWP (detection if OceanWP is installed and highslide is activated in oceanwp plugins class, then deactivating OceanWP boxes)
* [bug] Title in popup search were a mess with + and \ in the title (better data escaping in Popup Search class)
* [bug] Bootsrap spinner for bootstrap fixed, it correctly disappears when page is fully loaded
Expand All @@ -93,8 +95,8 @@ v.4.1
* [technical] Notifications are only shown in Lumière admin options pages. If a taxonomy file is not installed, always nag the user to install it.
* [technical] Lot of cleaning, standardised css classes, removed many unused methods in css and php, factorized and using more dedicated traits, using official WordPress way to include blocks (block.json), more standard WordPress string escaping
* [technical] The Polylang language forms in taxonomy pages for people now uses $_Get instead of $_Post, required to make the AMP form work (edited Polylang and Taxonomy_People_Standard clases in this regard)
* [technical] Replaced post metatada 'imdb-movie-widget-bymid' by 'lumiere_widget_movieid' and 'imdb-movie-widget' by 'lumiere_widget_movietitle'. Deleted obsolete post metada keys 'lumiere_queryid_widget_input' and 'lumiere_queryid_widget' The changes are done through the update numer 15.
* [technical] Moved the blueprint.json in the correct asset folder (meant to be on wordpress.org, actually).
* [technical] Replaced post metatada 'imdb-movie-widget-bymid' by 'lumiere_widget_movieid' and 'imdb-movie-widget' by 'lumiere_widget_movietitle'. Deleted obsolete post metada keys 'lumiere_queryid_widget_input' and 'lumiere_queryid_widget' The changes are done through the class update number 15.
* [technical] Moved the blueprint.json in the correct asset folder (meant to be in wordpress.org, actually).

v.4.0.2
* [feature] Thumbnail pictures (those which are displayed automatically into the posts, in cache, in popups) are now automatically resized should they weight more that 80kb, which should display all pages faster. Maintained the possiblity to click on these thumbnails to display the big posters (Cover option in Lumière admin).
Expand Down Expand Up @@ -151,7 +153,7 @@ v.4.0
* [technical] Factorization of classes: Movie class (new class Movie_Data), Cache class (new class Cache_Tools), moved Frontend popups in new folder (frontend/popups/)
* [technical] Automatized task that runs to delete oversized cache folder (option "Keep automatically cache size below a limit") runs now hourly instead of every two hours.
* [technical] Updated to bootstrap 5.3.3
* [technical] Replaced obsolete PHP functions, compatibility with PHP > 8.0 ensured, compatibility with PHP8.3 ensured ( function get_class() removed/updated ).
* [technical] Replaced obsolete PHP functions, compatibility with PHP > 8.0, compatibility with PHP8.3 too ( function get_class() removed/updated ).
* [technical] Uninstalling the plugin with the option "keep settings upon uninstall" unselected will now delete Lumiere taxonomy templates in theme directory.
* [technical] Still PHP 8.0 compatible, but expect PHP 8.1 to be standard soon.

Expand Down
70 changes: 40 additions & 30 deletions dist/class/class-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,20 @@
/**
* Main WordPress actions happen here
* Calling all actions and filters
* Since WP 6.7, getting "Notice: Function _load_textdomain_just_in_time was called incorrectly." if Logger class is executed before init hook
* -> removed a property that save it, each method initiates the class itself now. In order to get the log, it must be executed before the init,
* but as a result the notice may be thrown for each method. No solution yet.
*
* @since 4.1.2 WP Cli commands compatible
* @TODO Since 4.1.1 an update version check is now executed on every admin page, find a better hook
*/
class Core {

/**
* Lumiere\Plugins\Logger class
*/
private Logger $logger;

/**
* Constructor
*/
public function __construct () {

// Start Logger class.
$this->logger = new Logger( 'coreClass' );

/**
* Widgets fire at init priority 0, so they must either be called here with 'widgets_init' or with 'init' priority 0
* https://developer.wordpress.org/reference/hooks/widgets_init/#comment-2643
Expand Down Expand Up @@ -151,8 +146,11 @@ function( string $block ) {
*/
public function lum_on_plugin_manualupdate( \WP_Upgrader $upgrader_object, array $options ): void {

// Start Logger class.
$logger = new Logger( 'coreClass' );

// Start the logger.
$this->logger->lumiere_start_logger( 'coreClass', false /* Deactivate the onscreen log, so WordPress activation doesn't trigger any error if debug is activated */ );
$logger->lumiere_start_logger( 'coreClass', false /* Deactivate the onscreen log, so WordPress activation doesn't trigger any error if debug is activated */ );

// If an update has taken place and the updated type is plugins and the plugins element exists.
if ( $options['type'] === 'plugin' && $options['action'] === 'update' && isset( $options['plugins'] ) ) {
Expand All @@ -163,15 +161,15 @@ public function lum_on_plugin_manualupdate( \WP_Upgrader $upgrader_object, array
// It is Lumière!, so run the functions.
if ( $plugin === 'lumiere-movies/lumiere-movies.php' ) {

$this->logger->log()->debug( '[Lumiere][coreClass][manualupdate] Starting Lumière manual update' );
$logger->log()->debug( '[Lumiere][coreClass][manualupdate] Starting Lumière manual update' );
$start_update_options = new Updates();
$start_update_options->run_update_options();

// Set up WP Cron exec once if it doesn't exist.
if ( $this->lum_setup_cron_exec_once( $this->logger, 'manualupdate' ) === false ) {
$this->logger->log()->error( '[Lumiere][coreClass][autoupdate] Cron lumiere_exec_once_update was not set up (maybe an issue during activation?)' );
if ( $this->lum_setup_cron_exec_once( $logger, 'manualupdate' ) === false ) {
$logger->log()->error( '[Lumiere][coreClass][autoupdate] Cron lumiere_exec_once_update was not set up (maybe an issue during activation?)' );
}
$this->logger->log()->debug( '[Lumiere][coreClass][manualupdate] Lumière manual update processed.' );
$logger->log()->debug( '[Lumiere][coreClass][manualupdate] Lumière manual update processed.' );
}
}
}
Expand All @@ -186,8 +184,11 @@ public function lum_on_plugin_manualupdate( \WP_Upgrader $upgrader_object, array
*/
public function lum_on_plugin_autoupdate( array $results ): void {

// Start Logger class.
$logger = new Logger( 'coreClass' );

// Start the logger.
$this->logger->lumiere_start_logger( 'coreClass', false /* Deactivate the onscreen log, so WordPress activation doesn't trigger any error if debug is activated */ );
$logger->lumiere_start_logger( 'coreClass', false /* Deactivate the onscreen log, so WordPress activation doesn't trigger any error if debug is activated */ );

// Exit if not exist.
if ( ! isset( $results['plugin'] ) ) {
Expand All @@ -205,15 +206,15 @@ public function lum_on_plugin_autoupdate( array $results ): void {
) {

// It is Lumière!, so run the functions.
$this->logger->log()->debug( '[Lumiere][coreClass][autoupdate] Starting Lumière automatic update' );
$logger->log()->debug( '[Lumiere][coreClass][autoupdate] Starting Lumière automatic update' );
$start_update_options = new Updates();
$start_update_options->run_update_options();

// Set up WP Cron exec once if it doesn't exist
if ( $this->lum_setup_cron_exec_once( $this->logger, 'autoupdate' ) === false ) {
$this->logger->log()->error( '[Lumiere][coreClass][autoupdate] Cron lumiere_exec_once_update was not set up (maybe an issue during activation?)' );
if ( $this->lum_setup_cron_exec_once( $logger, 'autoupdate' ) === false ) {
$logger->log()->error( '[Lumiere][coreClass][autoupdate] Cron lumiere_exec_once_update was not set up (maybe an issue during activation?)' );
}
$this->logger->log()->debug( '[Lumiere][coreClass][autoupdate] Lumière autoupdate processed.' );
$logger->log()->debug( '[Lumiere][coreClass][autoupdate] Lumière autoupdate processed.' );
}

}
Expand All @@ -225,18 +226,21 @@ public function lum_on_plugin_autoupdate( array $results ): void {
*/
public function lumiere_on_activation(): void {

// Start Logger class.
$logger = new Logger( 'coreClass' );

// Start the logger.
$this->logger->lumiere_start_logger( 'coreClass', false /* Deactivate the onscreen log, so WordPress activation doesn't trigger any error if debug is activated */ );
$logger->lumiere_start_logger( 'coreClass', false /* Deactivate the onscreen log, so WordPress activation doesn't trigger any error if debug is activated */ );

$current_admin = get_option( Settings::get_cache_tablename() );

/* Create the value of number of updates on first install */
if ( ! isset( $current_admin['imdbHowManyUpdates'] ) ) {
// Start Settings class to create it. Not optimal.
$settings_class = new Settings();
$this->logger->log()->info( "[Lumiere][coreClass][activation] Lumière option 'imdbHowManyUpdates' successfully created." );
$logger->log()->info( "[Lumiere][coreClass][activation] Lumière option 'imdbHowManyUpdates' successfully created." );
} else {
$this->logger->log()->info( "[Lumiere][coreClass][activation] Lumière option 'imdbHowManyUpdates' already exists." );
$logger->log()->info( "[Lumiere][coreClass][activation] Lumière option 'imdbHowManyUpdates' already exists." );
}

/* Create the cache folders */
Expand All @@ -245,17 +249,17 @@ public function lumiere_on_activation(): void {
$cache_tools_class = new Cache_Tools();

if ( $cache_tools_class->lumiere_create_cache() === true ) {
$this->logger->log()->info( '[Lumiere][coreClass][activation] Lumière cache successfully created.' );
$logger->log()->info( '[Lumiere][coreClass][activation] Lumière cache successfully created.' );
} else {
$this->logger->log()->info( '[Lumiere][coreClass][activation] Lumière cache could not be created (check permissions?)' );
$logger->log()->info( '[Lumiere][coreClass][activation] Lumière cache could not be created (check permissions?)' );
}

// Set up WP Cron exec once if it doesn't exist.
if ( $this->lum_setup_cron_exec_once( $this->logger, 'activation' ) === false ) {
$this->logger->log()->error( '[Lumiere][coreClass][activation] Cron lumiere_exec_once_update was not set up (maybe an issue during activation?)' );
if ( $this->lum_setup_cron_exec_once( $logger, 'activation' ) === false ) {
$logger->log()->error( '[Lumiere][coreClass][activation] Cron lumiere_exec_once_update was not set up (maybe an issue during activation?)' );
}

$this->logger->log()->debug( '[Lumiere][coreClass][activation] Lumière plugin activated.' );
$logger->log()->debug( '[Lumiere][coreClass][activation] Lumière plugin activated.' );
}

/**
Expand All @@ -264,14 +268,17 @@ public function lumiere_on_activation(): void {
*/
public function lumiere_on_deactivation(): void {

// Start Logger class.
$logger = new Logger( 'coreClass' );

// Start the logger.
$this->logger->lumiere_start_logger( 'coreClass', false /* Deactivate the onscreen log, so WordPress activation doesn't trigger any error if debug is activated */ );
$logger->lumiere_start_logger( 'coreClass', false /* Deactivate the onscreen log, so WordPress activation doesn't trigger any error if debug is activated */ );

// Remove WP lumiere crons should they exist.
$list_crons_available = [ 'lumiere_exec_once_update', 'lumiere_cron_deletecacheoversized', 'lumiere_cron_autofreshcache' ];
foreach ( $list_crons_available as $cron_installed ) {
wp_clear_scheduled_hook( $cron_installed );
$this->logger->log()->info( '[Lumiere][coreClass][deactivation] Cron ' . $cron_installed . ' removed' );
$logger->log()->info( '[Lumiere][coreClass][deactivation] Cron ' . $cron_installed . ' removed' );
}

// Reset options related to crons, since we removed them.
Expand All @@ -280,7 +287,7 @@ public function lumiere_on_deactivation(): void {
$current_admin['imdbcachekeepsizeunder'] = '0';
update_option( Settings::get_cache_tablename(), $current_admin );

$this->logger->log()->info( '[Lumiere][coreClass][deactivation] Lumière deactivated' );
$logger->log()->info( '[Lumiere][coreClass][deactivation] Lumière deactivated' );
}

/**
Expand All @@ -291,13 +298,16 @@ public function lumiere_on_deactivation(): void {
*/
public function lum_is_update_needed() {

// Start Logger class.
$logger = new Logger( 'coreClass' );

$current_admin = get_option( Settings::get_admin_tablename() );
$files = new FilesystemIterator( plugin_dir_path( __DIR__ ) . 'class/updates/', FilesystemIterator::SKIP_DOTS );
$nb_of_files_in_updates_folder = iterator_count( $files );

// Check if the number of updates in database is greater than the number of update files in updates folder
if ( isset( $current_admin['imdbHowManyUpdates'] ) && $current_admin['imdbHowManyUpdates'] <= $nb_of_files_in_updates_folder ) {
$this->logger->log()->debug( '[Lumiere][coreClass][is_plugin_updated] An update is needed, starting the update...' );
$logger->log()->debug( '[Lumiere][coreClass][is_plugin_updated] An update is needed, starting the update...' );
$start_update_options = new Updates();
$start_update_options->run_update_options();

Expand Down
4 changes: 4 additions & 0 deletions src/ACKNOWLEDGMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@
**PHP Mess detector** by [PHPMD](https://phpmd.org/ "PHPMD website")
**PHPStan** by [PHPStan](https://github.com/phpstan/phpstan "PHPStan GIT")
**PSALM** by [Vimeo](https://github.com/vimeo/psalm "Psalm GIT")

# History of core IMDbPHP libraries
Originally, this WordPress plugin originated from an IMDBPHP library created by [Andreas Itzchak Rehberg](https://izzy.rehbergs.info/ "Personal Websie"). A few years later, when Andreas got tired, T. Boothmman took over [IMDbPHP](https://github.com/tboothman/imdbphp/ "IMDbPHP GIT"). Nowadays, this plugin used a modified version of the latter with improvements brought by [Duck700](https://github.com/duck7000/imdbGraphQLPHP "IMDbGraphQLPHP GIT"). At some point, since IMDbPHP is not updated anymore, will switch completely to this new library.
Lumiere WordPress plugin has been actively developped and maintained for 20 years.
Loading

0 comments on commit 3719415

Please sign in to comment.