Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Chouby

    (@chouby)

    Hello,

    Plugins must also follow best practices. One of the most important in the WordPress ecoystem is “Do nothing before the plugins_loaded action is fired”. Why? Because everything done before this action can not be filtered by other plugins.

    I tested Footnotes. It loads its option before the action ‘plugins_loaded’. As Polylang waits for this action to setup the language and the options filters, teh option is not filtered.

    If I delay the initialization of the Footnotes plugin to hook it to the plugins_loaded action, then the translation of teh option works as expected.

    I did not test the other plugin, but I suppose it’s the same issue.

    Thread Starter pewgeuges

    (@pewgeuges)

    @chouby,

    Thank you very much for testing the Footnotes plugin and for your advice and insight.

    As I failed to implement the solution according to https://polylang.pro/dont-take-any-action-before-plugins_loaded-is-fired/, I’ve ended up applying the quick fix just hooking initialization on plugins_loaded in footnotes.php:

    
    /**
     * Allows other plugins to filter the options.
     *
     * @since TBD [after 2.7.3]
     * @contributor @chouby
     * @link https://www.ads-software.com/support/topic/plugin-string-translations-ineffective/#post-14714185
     */
    add_action( 'plugins_loaded', function() {
    
    	// Initialize the Plugin.
    	$g_obj_mci_footnotes = new Footnotes();
    	// Run the Plugin.
    	$g_obj_mci_footnotes->run();
    
    } );
    

    Code based on current v2.7.3 https://plugins.trac.www.ads-software.com/browser/footnotes/tags/2.7.3/footnotes.php?rev=2521062#L117

    While loading translations is already hooked on plugins_loaded, loading options surprisingly is not.

    I’ll report back on Footnotes’ forum (done, see https://www.ads-software.com/support/topic/reference-container-heading-translations-and-a-collapse-feature/#post-14717295) and just escalated it to https://github.com/markcheret/footnotes/issues/189

    Being committed to fixing Footnotes and while I hadn’t got enough time to contribute to TOC+ as well, I didn’t try the same in the latter either, hoping it will be done after reporting to TOC+.

    Many thanks.

    • This reply was modified 3 years, 2 months ago by pewgeuges.
    • This reply was modified 3 years, 2 months ago by pewgeuges.
    • This reply was modified 3 years, 2 months ago by pewgeuges. Reason: Add a docblock
    • This reply was modified 3 years, 2 months ago by pewgeuges.
    • This reply was modified 3 years, 2 months ago by pewgeuges.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Plugin string translations ineffective’ is closed to new replies.