Plugin Directory

Changeset 3111167


Ignore:
Timestamp:
07/02/2024 12:58:00 PM (21 months ago)
Author:
axeptio
Message:

version 2.4.2 release

Location:
axeptio-sdk-integration
Files:
1774 added
3 edited

Legend:

Unmodified
Added
Removed
  • axeptio-sdk-integration/trunk/axeptio-wordpress-plugin.php

    r3109261 r3111167  
    44    Plugin URI: https://www.axeptio.eu/
    55    Description: Axeptio allows you to make your website compliant with GDPR.
    6     Version: 2.4.1
     6    Version: 2.4.2
    77    Author: axeptio
    88    License: GPLv3
     
    1414use Axeptio\Plugin\Models\Settings;
    1515
    16 define( 'XPWP_VERSION', '2.4.1' );
     16define( 'XPWP_VERSION', '2.4.2' );
    1717define( 'XPWP_URL', plugin_dir_url( __FILE__ ) );
    1818define( 'XPWP_PATH', plugin_dir_path( __FILE__ ) );
  • axeptio-sdk-integration/trunk/includes/classes/frontend/class-hook-modifier.php

    r3108716 r3111167  
    1313use Axeptio\Plugin\Models\Settings;
    1414use Axeptio\Plugin\Module;
     15use Axeptio\Plugin\Utils\Search_Callback_File_Location;
    1516use Axeptio\Plugin\Utils\User_Hook_Parser;
    1617use Closure;
     
    1920use ReflectionMethod;
    2021
    21 class Hook_Modifier extends Module {
     22class Hook_Modifier extends Module
     23{
    2224
    2325    /**
     
    9294     * @return true
    9395     */
    94     public function can_register() {
     96    public function can_register()
     97    {
    9598        return true;
    9699    }
     
    101104     * @return void
    102105     */
    103     public function register() {
    104         if ( ! Sdk::is_active() ) {
     106    public function register()
     107    {
     108        if (!Sdk::is_active()) {
    105109            return;
    106110        }
    107111
    108         add_action( 'template_redirect', array( $this, 'on_template_redirect' ) );
    109         add_action( 'shutdown', array( $this, 'on_shutdown' ) );
     112        add_action('template_redirect', array($this, 'on_template_redirect'));
     113        add_action('shutdown', array($this, 'on_shutdown'));
    110114    }
    111115
     
    115119     * @return void
    116120     */
    117     public function on_template_redirect() {
     121    public function on_template_redirect()
     122    {
    118123        $this->process_shortcode_tags();
    119124        $this->process_wp_filter();
     
    125130     * @return void
    126131     */
    127     public function on_shutdown() {
     132    public function on_shutdown()
     133    {
    128134        $_SESSION['axeptio_intercepted_content'] = $this->plugins_contents;
    129135    }
     
    138144     * @return void
    139145     */
    140     public function add_error( string $plugin, string $filter, string $error ) {
    141         $this->plugins_errors[ $plugin ][] = array(
    142             'error'  => $error,
     146    public function add_error(string $plugin, string $filter, string $error)
     147    {
     148        $this->plugins_errors[$plugin][] = array(
     149            'error' => $error,
    143150            'filter' => $filter,
    144151        );
     
    154161     * @return void
    155162     */
    156     public function add_content( $plugin, $filter, $content ) {
    157         $this->plugins_contents[ $plugin ][] = array(
     163    public function add_content($plugin, $filter, $content)
     164    {
     165        $this->plugins_contents[$plugin][] = array(
    158166            'content' => $content,
    159             'filter'  => $filter,
     167            'filter' => $filter,
    160168        );
    161169    }
     
    166174     * @return array
    167175     */
    168     private function process_shortcode_tags() {
     176    private function process_shortcode_tags()
     177    {
    169178        global $shortcode_tags;
    170179
    171         $stats   = array();
     180        $stats = array();
    172181        $plugins = array();
    173         foreach ( $shortcode_tags as $tag => $function ) {
    174             $stats[ $tag ] = $this->process_function( $function );
    175             if ( isset( $stats[ $tag ]['plugin'] ) ) {
    176                 $plugins[ $stats[ $tag ]['plugin'] ][] = array(
    177                     'name'     => $tag,
    178                     'plugin'   => $stats[ $tag ]['plugin'],
     182        foreach ($shortcode_tags as $tag => $function) {
     183            $stats[$tag] = $this->process_function($function, $tag);
     184            if (isset($stats[$tag]['plugin'])) {
     185                $plugins[$stats[$tag]['plugin']][] = array(
     186                    'name' => $tag,
     187                    'plugin' => $stats[$tag]['plugin'],
    179188                    'function' => $function,
    180189                );
     
    185194        // maybe optimize since now $this->plugin_configurations is a map
    186195        // with plugin as keys.
    187         $cookies_version       = Settings::get_option( 'version', false );
    188         $cookies_version       = '' === $cookies_version ? 'all' : $cookies_version;
    189         $plugin_configurations = Plugins::all( $cookies_version );
    190 
    191         foreach ( $plugin_configurations as $plugin_configuration ) {
    192 
    193             $configuration = 'all' === $cookies_version || ! isset( $plugin_configuration['Metas']['Merged'] ) ? $plugin_configuration['Metas'] : $plugin_configuration['Metas']['Merged'];
     196        $cookies_version = Settings::get_option('version', false);
     197        $cookies_version = '' === $cookies_version ? 'all' : $cookies_version;
     198        $plugin_configurations = Plugins::all($cookies_version);
     199
     200        foreach ($plugin_configurations as $plugin_configuration) {
     201
     202            $configuration = 'all' === $cookies_version || !isset($plugin_configuration['Metas']['Merged']) ? $plugin_configuration['Metas'] : $plugin_configuration['Metas']['Merged'];
    194203
    195204            // consent has been given for this plugin,
    196205            // no need to add it to the interception.
    197             if ( ! isset( $configuration['enabled'] ) || ! (bool) $configuration['enabled'] || $this->is_cookie_authorized( $configuration['plugin'] ) ) {
     206            if (!isset($configuration['enabled']) || !(bool)$configuration['enabled'] || $this->is_cookie_authorized($configuration['plugin'])) {
    198207                continue;
    199208            }
    200209
    201             if ( isset( $configuration['shortcode_tags_mode'] ) && 'none' !== $configuration['shortcode_tags_mode'] ) {
     210            if (isset($configuration['shortcode_tags_mode']) && 'none' !== $configuration['shortcode_tags_mode']) {
    202211
    203212                $configuration['shortcode_tags_list'] = 'inherit' === $configuration['shortcode_tags_mode'] ? $plugin_configuration['Metas']['Parent']['shortcode_tags_list'] : $configuration['shortcode_tags_list'];
    204213                $configuration['shortcode_tags_mode'] = 'inherit' === $configuration['shortcode_tags_mode'] ? $plugin_configuration['Metas']['Parent']['shortcode_tags_mode'] : $configuration['shortcode_tags_mode'];
    205214
    206                 $configuration = $this->maybe_apply_recommended_settings( $configuration, 'shortcode_tags' );
     215                $configuration = $this->maybe_apply_recommended_settings($configuration, 'shortcode_tags');
    207216
    208217                // We store the whitelisted tags in the intercepted_plugins array
    209218                // and use the plugin name as key. By doing so, we're able to determine
    210219                // if the plugin should be intercepted AND if there are tags to avoid.
    211                 $intercepted_plugins[ $configuration['plugin'] ] = array(
    212                     'mode'         => $configuration['shortcode_tags_mode'],
    213                     'list'         => explode( "\n", $configuration['shortcode_tags_list'] ),
    214                     'placeholder'  => $configuration['shortcode_tags_placeholder'],
    215                     'vendor_title' => isset( $configuration['vendor_title'] ) && '' !== $configuration['vendor_title'] ? $configuration['vendor_title'] : $plugin_configuration['Name'],
     220                $intercepted_plugins[$configuration['plugin']] = array(
     221                    'mode' => $configuration['shortcode_tags_mode'],
     222                    'list' => explode("\n", $configuration['shortcode_tags_list']),
     223                    'placeholder' => $configuration['shortcode_tags_placeholder'],
     224                    'vendor_title' => isset($configuration['vendor_title']) && '' !== $configuration['vendor_title'] ? $configuration['vendor_title'] : $plugin_configuration['Name'],
    216225                );
    217226            }
    218227        }
    219228
    220         foreach ( $plugins as $plugin => $tags ) {
     229        foreach ($plugins as $plugin => $tags) {
    221230            // The plugin has no key in the $intercepted_plugins array,
    222231            // meaning it should not be intercepted.
    223             if ( ! isset( $intercepted_plugins[ $plugin ] ) ) {
     232            if (!isset($intercepted_plugins[$plugin])) {
    224233                continue;
    225234            }
    226235
    227             foreach ( $tags as $tag ) {
    228                 if ( $this->should_load_shortcode( $intercepted_plugins[ $plugin ], $tag['name'] ) ) {
     236            foreach ($tags as $tag) {
     237                if ($this->should_load_shortcode($intercepted_plugins[$plugin], $tag['name'])) {
    229238                    continue;
    230239                }
    231                 $shortcode_tags[ $tag['name'] ] = $this->wrap_tag( $tag['function'], $plugin, $intercepted_plugins[ $plugin ], $tag['name'] ); // PHPCS:Ignore WordPress.WP.GlobalVariablesOverride.Prohibited
     240                $shortcode_tags[$tag['name']] = $this->wrap_tag($tag['function'], $plugin, $intercepted_plugins[$plugin], $tag['name']); // PHPCS:Ignore WordPress.WP.GlobalVariablesOverride.Prohibited
    232241            }
    233242        }
     
    239248     * Should the shortcode be loaded or not?
    240249     *
    241      * @param array  $intercepted_plugin Axeptio plugin settings intercepted.
     250     * @param array $intercepted_plugin Axeptio plugin settings intercepted.
    242251     * @param string $name Shortcode tag name.
    243252     *
    244253     * @return bool
    245254     */
    246     private function should_load_shortcode( $intercepted_plugin, $name ) {
     255    private function should_load_shortcode($intercepted_plugin, $name)
     256    {
    247257        // If the  name is found in the $intercepted_plugins list
    248258        // and the current mode is whitelist, it should be skipped.
    249259
    250         if ( 'none' === $intercepted_plugin['mode'] ) {
     260        if ('none' === $intercepted_plugin['mode']) {
    251261            return true;
    252262        }
    253263
    254         if ( 'whitelist' === $intercepted_plugin['mode'] && in_array( $name, $intercepted_plugin['list'], true ) ) {
     264        if ('whitelist' === $intercepted_plugin['mode'] && in_array($name, $intercepted_plugin['list'], true)) {
    255265            return true;
    256266        }
     
    259269        // and the current mode is blacklist, it should be skipped as well.
    260270
    261         if ( 'blacklist' === $intercepted_plugin['mode'] && ! in_array( $name, $intercepted_plugin['list'], true ) ) {
     271        if ('blacklist' === $intercepted_plugin['mode'] && !in_array($name, $intercepted_plugin['list'], true)) {
    262272            return true;
    263273        }
     
    272282     * @return bool Returns true if the hook is whitelisted, false otherwise.
    273283     */
    274     protected function is_whitelisted_hook( string $hook ): bool {
     284    protected function is_whitelisted_hook(string $hook): bool
     285    {
    275286        return array_reduce(
    276287            self::WHITELISTED_HOOK,
    277             function ( $carry, $whitelisted_hook ) use ( $hook ) {
    278                 if ( true === $carry ) {
     288            function ($carry, $whitelisted_hook) use ($hook) {
     289                if (true === $carry) {
    279290                    return true;
    280291                }
    281292
    282                 if ( strpos( $whitelisted_hook, '*' ) !== false ) {
    283                     $whitelisted_hook = preg_quote( $whitelisted_hook, '/' );
    284                     $pattern          = '/^' . str_replace( '\*', '.*', $whitelisted_hook ) . '$/';
    285                     return (bool) preg_match( $pattern, $hook );
     293                if (strpos($whitelisted_hook, '*') !== false) {
     294                    $whitelisted_hook = preg_quote($whitelisted_hook, '/');
     295                    $pattern = '/^' . str_replace('\*', '.*', $whitelisted_hook) . '$/';
     296                    return (bool)preg_match($pattern, $hook);
    286297                }
    287298
     
    302313     * @return bool
    303314     */
    304     private function should_load_hook( $intercepted_plugin, $hook, $callback = false, $priority = 10 ) {
     315    private function should_load_hook($intercepted_plugin, $hook, $callback = false, $priority = 10)
     316    {
    305317        // If the  name is found in the $intercepted_plugins list
    306318        // and the current mode is whitelist, it should be skipped.
    307319
    308320        $default = array(
    309             'hook'     => null,
    310             'class'    => null,
     321            'hook' => null,
     322            'class' => null,
    311323            'callback' => null,
    312324            'priority' => null,
     
    315327        $matching_hook = false;
    316328
    317         if ( 'none' === $intercepted_plugin['mode'] ) {
     329        if ('none' === $intercepted_plugin['mode']) {
    318330            return true;
    319331        }
    320332
    321         if ( $this->is_whitelisted_hook( $hook ) ) {
     333        if ($this->is_whitelisted_hook($hook)) {
    322334            return true;
    323335        }
    324336
    325         foreach ( $intercepted_plugin['list'] as $intercepted_hook ) {
     337        foreach ($intercepted_plugin['list'] as $intercepted_hook) {
    326338            $current_hook = $default;
    327339
    328             if ( isset( $intercepted_hook['hook'] ) ) {
     340            if (isset($intercepted_hook['hook'])) {
    329341                $current_hook['hook'] = $hook;
    330342            }
    331343
    332             if ( isset( $intercepted_hook['callback'] ) ) {
    333                 if ( isset( $intercepted_hook['class'] ) && is_array( $callback['function'] ) ) {
    334                     $current_hook['class']    = is_string( $callback['function'][0] ) ? $callback['function'][0] : get_class( $callback['function'][0] );
     344            if (isset($intercepted_hook['callback'])) {
     345                if (isset($intercepted_hook['class']) && is_array($callback['function'])) {
     346                    $current_hook['class'] = is_string($callback['function'][0]) ? $callback['function'][0] : get_class($callback['function'][0]);
    335347                    $current_hook['callback'] = $callback['function'][1];
    336348                } else {
     
    339351            }
    340352
    341             if ( isset( $intercepted_hook['priority'] ) ) {
     353            if (isset($intercepted_hook['priority'])) {
    342354                $current_hook['priority'] = $priority;
    343355            }
    344356
    345             if ( $intercepted_hook === $current_hook ) {
     357            if ($intercepted_hook === $current_hook) {
    346358                $matching_hook = true;
    347359                break;
     
    349361        }
    350362
    351         if ( 'whitelist' === $intercepted_plugin['mode'] && $matching_hook ) {
     363        if ('whitelist' === $intercepted_plugin['mode'] && $matching_hook) {
    352364            return true;
    353365        }
     
    355367        // Vice versa, if the name is not found in the $intercepted_plugins list
    356368        // and the current mode is blacklist, it should be skipped as well.
    357         if ( 'blacklist' === $intercepted_plugin['mode'] && ! $matching_hook ) {
     369        if ('blacklist' === $intercepted_plugin['mode'] && !$matching_hook) {
    358370            return true;
    359371        }
     
    368380     * @return bool
    369381     */
    370     private function is_cookie_authorized( string $plugin ) {
    371         $cookie = isset( $_COOKIE[ Axeptio_Sdk::OPTION_JSON_COOKIE_NAME ] ) ? json_decode( wp_unslash( $_COOKIE[ Axeptio_Sdk::OPTION_JSON_COOKIE_NAME ] ), JSON_OBJECT_AS_ARRAY ) : array();  // PHPCS:Ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
    372         return isset( $cookie[ "wp_{$plugin}" ] ) && true === $cookie[ "wp_{$plugin}" ];
     382    private function is_cookie_authorized(string $plugin)
     383    {
     384        $cookie = isset($_COOKIE[Axeptio_Sdk::OPTION_JSON_COOKIE_NAME]) ? json_decode(wp_unslash($_COOKIE[Axeptio_Sdk::OPTION_JSON_COOKIE_NAME]), JSON_OBJECT_AS_ARRAY) : array();  // PHPCS:Ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
     385        return isset($cookie["wp_{$plugin}"]) && true === $cookie["wp_{$plugin}"];
    373386    }
    374387
     
    380393     * @return array
    381394     */
    382     protected function maybe_apply_recommended_settings( $configuration, $setting ) {
    383         $merged_setting  = $configuration['Merged'][ $setting . '_mode' ] ?? null;
    384         $current_setting = $configuration[ $setting . '_mode' ] ?? null;
    385 
    386         if ( 'recommended' === $current_setting || 'recommended' === $merged_setting ) {
    387             $recommended_settings = Recommended_Plugin_Settings::find( $configuration['plugin'] );
    388 
    389             $recommended_mode = $recommended_settings[ $setting . '_mode' ];
    390             $recommended_list = is_array( $recommended_settings[ $setting . '_list' ] ) ? implode( PHP_EOL, $recommended_settings[ $setting . '_list' ] ) : $recommended_settings[ $setting . '_list' ];
    391 
    392             $configuration[ $setting . '_mode' ] = $recommended_mode;
    393             $configuration[ $setting . '_list' ] = $recommended_list;
    394 
    395             $configuration['Merged'][ $setting . '_mode' ] = $recommended_mode;
    396             $configuration['Merged'][ $setting . '_list' ] = $recommended_list;
     395    protected function maybe_apply_recommended_settings($configuration, $setting)
     396    {
     397        $merged_setting = $configuration['Merged'][$setting . '_mode'] ?? null;
     398        $current_setting = $configuration[$setting . '_mode'] ?? null;
     399
     400        if ('recommended' === $current_setting || 'recommended' === $merged_setting) {
     401            $recommended_settings = Recommended_Plugin_Settings::find($configuration['plugin']);
     402
     403            $recommended_mode = $recommended_settings[$setting . '_mode'];
     404            $recommended_list = is_array($recommended_settings[$setting . '_list']) ? implode(PHP_EOL, $recommended_settings[$setting . '_list']) : $recommended_settings[$setting . '_list'];
     405
     406            $configuration[$setting . '_mode'] = $recommended_mode;
     407            $configuration[$setting . '_list'] = $recommended_list;
     408
     409            $configuration['Merged'][$setting . '_mode'] = $recommended_mode;
     410            $configuration['Merged'][$setting . '_list'] = $recommended_list;
    397411        }
    398412
     
    400414    }
    401415
     416
     417
    402418    /**
    403419     * Wrap the function in a tag
     
    405421     * @return array $stats
    406422     */
    407     private function process_wp_filter() {
     423    private function process_wp_filter()
     424    {
    408425        /*
    409426         * WP_filter is a massive array containing all the functions
     
    412429        global $wp_filter;
    413430
    414         $stats   = array();
     431        $stats = array();
    415432        $plugins = array();
    416         foreach ( $wp_filter as $filter => $hook ) {
    417             foreach ( $hook->callbacks as $priority => $functions ) {
    418                 foreach ( $functions as $name => $function ) {
    419                     $stats[ $filter ][ $name ] = $this->process_function( $function['function'] );
    420 
    421                     if ( isset( $stats[ $filter ][ $name ]['plugin'] ) ) {
    422                         $plugins[ $stats[ $filter ][ $name ]['plugin'] ][] = array(
    423                             'filter'   => $filter,
     433        foreach ($wp_filter as $filter => $hook) {
     434            foreach ($hook->callbacks as $priority => $functions) {
     435                foreach ($functions as $name => $function) {
     436                    $stats[$filter][$name] = $this->process_function($function['function'], $name, $filter, $priority);
     437
     438                    if (isset($stats[$filter][$name]['plugin'])) {
     439                        $plugins[$stats[$filter][$name]['plugin']][] = array(
     440                            'filter' => $filter,
    424441                            'priority' => $priority,
    425                             'name'     => $name,
     442                            'name' => $name,
    426443                            'function' => $function,
    427444                        );
     
    433450        $intercepted_plugins = array();
    434451
    435         $cookies_version = Settings::get_option( 'version', 'all' );
     452        $cookies_version = Settings::get_option('version', 'all');
    436453        $cookies_version = '' === $cookies_version ? 'all' : $cookies_version;
    437454
    438         $plugin_configurations = Plugins::all( $cookies_version );
    439 
    440         foreach ( $plugin_configurations as $plugin_configuration ) {
    441 
    442             $configuration = 'all' === $cookies_version || ! isset( $plugin_configuration['Metas']['Merged'] ) ? $plugin_configuration['Metas'] : $plugin_configuration['Metas']['Merged'];
     455        $plugin_configurations = Plugins::all($cookies_version);
     456
     457        foreach ($plugin_configurations as $plugin_configuration) {
     458
     459            $configuration = 'all' === $cookies_version || !isset($plugin_configuration['Metas']['Merged']) ? $plugin_configuration['Metas'] : $plugin_configuration['Metas']['Merged'];
    443460
    444461            // consent has been given for this plugin,
    445462            // no need to add it to the interception.
    446463
    447             if ( ! isset( $configuration['enabled'] ) || ! (bool) $configuration['enabled'] || $this->is_cookie_authorized( $configuration['plugin'] ) ) {
     464            if (!isset($configuration['enabled']) || !(bool)$configuration['enabled'] || $this->is_cookie_authorized($configuration['plugin'])) {
    448465                continue;
    449466            }
    450467
    451             if ( isset( $configuration['wp_filter_mode'] ) && 'none' !== $configuration['wp_filter_mode'] ) {
     468            if (isset($configuration['wp_filter_mode']) && 'none' !== $configuration['wp_filter_mode']) {
    452469                // We store the whitelisted hooks in the intercepted_plugins array
    453470                // and use the plugin name as key. By doing so, we're able to determine
     
    457474                $configuration['wp_filter_mode'] = 'inherit' === $configuration['wp_filter_mode'] ? $plugin_configuration['Metas']['Parent']['wp_filter_mode'] : $configuration['wp_filter_mode'];
    458475
    459                 $configuration = $this->maybe_apply_recommended_settings( $configuration, 'wp_filter' );
    460 
    461                 $parser = new User_Hook_Parser( $configuration['wp_filter_list'] );
    462                 $hooks  = $parser->get_hooks();
    463 
    464                 if ( 0 === count( $hooks ) && ( 'whitelist' === $configuration['wp_filter_mode'] || 'blacklist' === $configuration['wp_filter_mode'] ) ) {
     476                $configuration = $this->maybe_apply_recommended_settings($configuration, 'wp_filter');
     477
     478                $parser = new User_Hook_Parser($configuration['wp_filter_list']);
     479                $hooks = $parser->get_hooks();
     480
     481                if (0 === count($hooks) && ('whitelist' === $configuration['wp_filter_mode'] || 'blacklist' === $configuration['wp_filter_mode'])) {
    465482                    continue;
    466483                }
    467484
    468                 $intercepted_plugins[ $configuration['plugin'] ] = array(
     485                $intercepted_plugins[$configuration['plugin']] = array(
    469486                    'mode' => $configuration['wp_filter_mode'],
    470487                    'list' => $hooks,
     
    473490        }
    474491
    475         foreach ( $plugins as $plugin => $configs ) {
     492        foreach ($plugins as $plugin => $configs) {
    476493            // The plugin has no key in the $intercepted_plugins array,
    477494            // meaning it should not be intercepted.
    478             if ( ! isset( $intercepted_plugins[ $plugin ] ) ) {
     495            if (!isset($intercepted_plugins[$plugin])) {
    479496                continue;
    480497            }
    481498
    482             foreach ( $configs as $config ) {
    483                 list($filter, $priority, $name, $function) = array_values( $config );
    484 
    485                 if ( $this->should_load_hook( $intercepted_plugins[ $plugin ], $filter, $function, $priority ) ) {
     499            foreach ($configs as $config) {
     500                list($filter, $priority, $name, $function) = array_values($config);
     501
     502                if ($this->should_load_hook($intercepted_plugins[$plugin], $filter, $function, $priority)) {
    486503                    continue;
    487504                }
    488505
    489506                // We decide to prevent admin hooks to be intercepted.
    490                 if ( str_contains( $filter, 'admin' ) ) {
     507                if (str_contains($filter, 'admin')) {
    491508                    continue;
    492509                }
    493510
    494511                // Otherwise we will wrap and overwrite the filter.
    495                 $wp_filter[ $filter ]->callbacks[ $priority ][ $name ]['function'] = $this->wrap_filter( $function['function'], $plugin, $filter );
     512                $wp_filter[$filter]->callbacks[$priority][$name]['function'] = $this->wrap_filter($function['function'], $plugin, $filter);
    496513            }
    497514        }
     
    505522     * for later.
    506523     *
    507      * @param mixed  $callback_function Function to wrap.
     524     * @param mixed $callback_function Function to wrap.
    508525     * @param string $plugin Plugin name.
    509526     * @param string $plugin_settings Plugin Settings.
     
    512529     * @return Closure
    513530     */
    514     private function wrap_tag( $callback_function, $plugin, $plugin_settings, $tag ) {
    515         return function () use ( $callback_function, $plugin, $plugin_settings, $tag ) {
    516             $args        = func_get_args();
    517             $return      = call_user_func_array( $callback_function, $args );
    518             $pattern     = '/<!--(.*?)-->/s';
    519             $return      = preg_replace( $pattern, '', $return );
     531    private function wrap_tag($callback_function, $plugin, $plugin_settings, $tag)
     532    {
     533        return function () use ($callback_function, $plugin, $plugin_settings, $tag) {
     534            $args = func_get_args();
     535            $return = call_user_func_array($callback_function, $args);
     536            $pattern = '/<!--(.*?)-->/s';
     537            $return = preg_replace($pattern, '', $return);
    520538            $placeholder = \Axeptio\Plugin\get_template_part(
    521539                'frontend/shortcode-placeholder',
    522540                array(
    523                     'plugin'          => $plugin,
     541                    'plugin' => $plugin,
    524542                    'plugin_settings' => $plugin_settings,
    525543                ),
     
    536554     * for later.
    537555     *
    538      * @param mixed  $callback_function Callback function to wrap.
     556     * @param mixed $callback_function Callback function to wrap.
    539557     * @param string $plugin Plugin name.
    540558     * @param string $filter Filter name.
     
    542560     * @return Closure
    543561     */
    544     private function wrap_filter( $callback_function, $plugin, $filter ) {
    545         return function () use ( $callback_function, $plugin, $filter ) {
     562    private function wrap_filter($callback_function, $plugin, $filter)
     563    {
     564        return function () use ($callback_function, $plugin, $filter) {
    546565            // noop for the moment. ob_start seems to break :
    547566            // "Cannot use output buffering in output buffering display handlers".
     
    550569
    551570    /**
    552      * Callback function to analyse.
    553      *
    554      * @param mixed $callback_function The Callback function.
    555      * @return array
    556      *
    557      * @throws \ReflectionException If invalid reflection output.
    558      */
    559     private function process_function( $callback_function ) {
    560         try {
    561             if ( is_string( $callback_function ) || $callback_function instanceof Closure ) {
    562                 $reflection = new ReflectionFunction( $callback_function );
    563             } elseif ( is_array( $callback_function ) && count( $callback_function ) === 2 ) {
    564                 $reflection = new ReflectionMethod( $callback_function[0], $callback_function[1] );
    565             } elseif ( is_object( $callback_function ) ) {
    566                 $reflection = new ReflectionMethod( $callback_function, '__construct' );
    567             } else {
    568                 \ob_start();
    569                 \var_dump( $callback_function ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_dump
    570                 throw new \ReflectionException( 'Invalid reflection callback function.' . ob_get_clean() );
    571             }
    572 
    573             $filename              = $reflection->getFileName();
    574             $plugin_regexp_matches = array();
    575 
    576             preg_match( '#' . preg_quote( WP_PLUGIN_DIR, '#' ) . '[/\\\]([a-zA-Z0-9_-]+)[/\\\]#', $filename, $plugin_regexp_matches );
    577 
    578             $plugin = isset( $plugin_regexp_matches[1] ) ? $plugin_regexp_matches[1] : null;
    579 
    580             if ( null === $plugin && str_contains( $filename, WP_PLUGIN_DIR ) ) {
    581                 $plugin = str_replace( '.php', '', basename( $filename ) );
    582             }
    583 
    584             return array(
    585                 'filename' => $filename,
    586                 'plugin'   => $plugin,
    587             );
    588         } catch ( ReflectionException $e ) {
    589             if ( XPWP_SHOW_ALL_ERRORS && ! (bool) Settings::get_option( 'disable_send_datas', false ) ) {
    590                 \Sentry\captureException( $e );
    591             }
    592         }
     571     * Analyse a callback function and extract information.
     572     *
     573     * @param mixed $callback_function The callback function to analyze.
     574     * @return array|null Information about the callback or null if analysis fails.
     575     */
     576    private function process_function($callback_function, string $name = null, string $filter = null, int $priority = null) {
     577        $filename = Search_Callback_File_Location::get_filename($callback_function, $name, $filter, $priority);
     578
     579        if (!$filename) {
     580            return null;
     581        }
     582
     583        return [
     584            'filename' => $filename,
     585            'plugin'   => $this->extract_plugin_name($filename),
     586        ];
     587    }
     588
     589    /**
     590     * Extract the plugin name from a given filename.
     591     *
     592     * @param string $filename The full path to the file.
     593     * @return string|null The plugin name or null if not found.
     594     */
     595    private function extract_plugin_name($filename) {
     596        $plugin_dir = wp_normalize_path(WP_PLUGIN_DIR);
     597        $filename = wp_normalize_path($filename);
     598
     599        if (strpos($filename, $plugin_dir) === 0) {
     600            $relative_path = substr($filename, strlen($plugin_dir) + 1);
     601            $parts = explode('/', $relative_path);
     602            return $parts[0] ?? null;
     603        }
     604
     605        return null;
    593606    }
    594607
     
    602615     * @return string
    603616     */
    604     private function getCookiesVersion() {
     617    private function getCookiesVersion()
     618    {
    605619        return 'not implemented';
    606620    }
  • axeptio-sdk-integration/trunk/readme.txt

    r3109327 r3111167  
    44Requires at least: 5.0
    55Tested up to: 6.5.5
    6 Stable tag: 2.4.1
     6Stable tag: 2.4.2
    77Requires PHP: 7.4
    88License: GPLv3
     
    8585== Changelog ==
    8686
     87### 🌟 2.4.2 🌟 ###
     88
     89**Enhanced Plugin Hook Detection 🕵️‍♂️**
     90Discover the source of plugin hooks with our improved detection system. Faster, smarter, and quieter than ever—enjoy streamlined debugging without the noise!
     91
     92- **Quick and Quiet Error Handling 🔇**
     93We've made error handling whisper-quiet. Bugs are logged without interrupting your workflow, keeping things smooth and serene.
     94
     95- **Efficient Search with Smart Caching 🚀**
     96Our new caching system speeds up the search process, so you spend less time waiting and more time creating.
     97
    8798### 🐞 2.4.1 🐞 ###
    8899
Note: See TracChangeset for help on using the changeset viewer.