Plugin Directory

Changeset 2535299


Ignore:
Timestamp:
05/21/2021 08:35:48 AM (5 years ago)
Author:
john1302
Message:

Move base plugin action to wp shutdown action

Location:
wp-lozad/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wp-lozad/trunk/classes/FrontPageProcessing.php

    r2400514 r2535299  
    1414    private function handle()
    1515    {
    16         add_action('wp_enqueue_scripts', [$this, 'includeLozadJs']);
     16        add_action('wp_enqueue_scripts', function () {
     17            $pluginOptions = get_option(SettingsConstants::PAGE_SETTING_OPTION_NAME);
    1718
    18         //add_filter('the_content', [$this, 'lozadContentProcessing']);
    19         add_filter('final_output', [$this, 'lozadContentProcessing']);
    20     }
     19            $pluginDirUrl = plugin_dir_url(__DIR__);
     20            $includeInFooter = isset($pluginOptions[SettingsConstants::SETTING_WHERE_INCLUDE_SCRIPT])
     21                && $pluginOptions[SettingsConstants::SETTING_WHERE_INCLUDE_SCRIPT];
    2122
    22     public function lozadContentProcessing($content)
    23     {
    24         return (new ContentProcessing($content))->handle();
    25     }
     23            wp_enqueue_script('jquery');
     24            wp_register_script('lozad_script', "{$pluginDirUrl}js/lozad.js", ['jquery'], false, $includeInFooter);
     25            wp_enqueue_script('lozad_script');
     26            wp_register_script('lozad_init_script', "{$pluginDirUrl}js/initLozad.js", ['jquery','lozad_script'], false, $includeInFooter);
     27            wp_enqueue_script('lozad_init_script');
     28        });
    2629
    27     public function includeLozadJs()
    28     {
    29         $pluginOptions = get_option(SettingsConstants::PAGE_SETTING_OPTION_NAME);
     30        ob_start();
     31        add_action('shutdown', function() {
     32            $finalBuffer = '';
     33            for ($i = 0, $levels = ob_get_level(); $i < $levels; $i++) {
     34                $finalBuffer .= ob_get_clean();
     35            }
    3036
    31         $pluginDirUrl = plugin_dir_url(__DIR__);
    32         $includeInFooter = isset($pluginOptions[SettingsConstants::SETTING_WHERE_INCLUDE_SCRIPT])
    33             && $pluginOptions[SettingsConstants::SETTING_WHERE_INCLUDE_SCRIPT];
    34 
    35         wp_enqueue_script('jquery');
    36         wp_register_script('lozad_script', "{$pluginDirUrl}js/lozad.js", ['jquery'], false, $includeInFooter);
    37         wp_enqueue_script('lozad_script');
    38         wp_register_script('lozad_init_script', "{$pluginDirUrl}js/initLozad.js", ['jquery','lozad_script'], false, $includeInFooter);
    39         wp_enqueue_script('lozad_init_script');
     37            echo is_admin() ? $finalBuffer : (new ContentProcessing($finalBuffer))->handle();
     38        }, 0);
    4039    }
    4140}
  • wp-lozad/trunk/lozad.php

    r2530037 r2535299  
    44Description: lazy loading of images by baroda algorithm
    55Author: Evgeniy Kozenok
    6 Version: 1.4.3
     6Version: 1.4.4
    77*/
    88
  • wp-lozad/trunk/readme.txt

    r2530037 r2535299  
    44Requires at least: 5.0
    55Tested up to: 5.5
    6 Stable tag: 1.4.3
     6Stable tag: 1.4.4
    77License: GPL2
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    2424
    2525== Changelog ==
     26= 1.4.4 =
     27* 2021-05-21: Move base plugin action to wp shutdown action
     28
    2629= 1.4.3 =
    2730* 2021-05-11: Fix space
Note: See TracChangeset for help on using the changeset viewer.