Plugin causes hook ‘wp’ to fire twice
-
Hi
I noticed while debugging my own plugin that this plugin is causing the ‘wp’ hook to fire twice on the same post. Is this intentional?
I’ve traced it as far as this line on Version: 2.3.17:
ad-inserter.php 1588:
add_action (‘loop_end’, ‘ai_hook_function_loop_end’);Removing this line will stop it from happening, but I’m guessing this will screw up other functionality.
Would be great if you could fix this, as it is causing performance issues for me.
Thanks!
Best regards Naoell
-
Hello,
Ad Inserter does not fire wp hook, it only adds action on this hook:
add_action ('wp', 'ai_wp_hook');loop_end is a hook used to insert After post.
add_action ('loop_end', 'ai_hook_function_loop_end');Can you please check?
Hi
Well I did not read through the ai_hook_function_loop_end function. But I noticed that it does not call do_action, so something else must be happening.
I can reproduced it by writing a small log plugin:
<?php /* Plugin Name: Log wp hook Description: Test Author: Naoell */ function log_message($msg, $type) { $d = $time = date('H:i'); $today = date('Y-m-d'); $line = $time . ' - ' . $type . ' - ' . $msg . PHP_EOL; $file_path = __DIR__ . '/' . $today . '-import-log.txt'; $file = fopen($file_path, "a"); fwrite($file, $line); fclose($file); } function random_wp_hook() { log_message('wp hook loaded', 'info'); } add_action('wp', 'random_wp_hook');If you browse a single post it will log two entries when ad-inserter is activated, and once if not.
-
This reply was modified 7 years, 9 months ago by
Naoell.
Can’t reproduce the issue.
I get only one call.It must be something with the settings.
Is the website live – can you enable remote debugging?
If it is not live please paste processing log – HTML comment from the bottom of page source.Hmm, thats wierd.
The site I’m testing on is not live, I’m using the Worpdress Docker container on my development computer. Could you explain a bit more where I can find the processing log? Cannot see any HTML comment on single post page source.
There might be something special about my setup. I’ll try to reproduce it using a clean installation tomorrow.
Thanks for looking into the issue so far!
OK.
You need to enable Log processing and then check page source:
https://adinserter.pro/documentation/debuggingProcessing log(I’ve removed som site information details, since all this is public):
—
Ad Inserter 2.3.17INSTALLED: 2018-04-24 09:50:34 (0000-03-22 11:22:34, 113 days)
GENERATED (WP time): 2018-08-15 21:13:08
GENERATED (Server time): 2018-08-15 21:13:08
PLUGIN CODE PROCESSING: 5.39 ms
USER CODE PROCESSING: 0.00 ms
TOTAL PROCESSING TIME: 5.39 ms
SETTINGS: 2.3.11
SETTINGS TIMESTAMP: 2018-07-04 10:48:34
SETTINGS EXTRACT: NO
MULTISITE: NO
USER: LOGGED-IN ADMINISTRATOR
USERNAME: [TextRemoved]
USER ROLES: administrator
MIN.USER FOR EXCEPTIONS: administrator
PAGE TYPE: POST
ID: 276
POST TYPE: post
CATEGORIES: [TextRemoved]
TAGS:
TAXONOMIES: category:[TextRemoved]
POST META: yuzo_related_post_metabox:a:3:{s:17:”yuzo_include_post”;s:0:””;s:17:”yuzo_exclude_post”;s:0:””;s:21:”yuzo_disabled_related”;N;}, _edit_last:1, _edit_lock:1527084489:1, _thumbnail_id:277, _encloseme:1, _adinserter_block_exceptions:, article_availability:subscription, _genesis_scripts_body_position:bottom
AMP PAGE: NO
URL: [TextRemoved]
REFERER:
VIEWPORT 1: Desktop min width 980 px
VIEWPORT 2: Tablet min width 768 px
VIEWPORT 3: Phone min width 0 px
SERVER-SIDE DETECTION: NOT USED
CLIENT-SIDE DETECTION: NOT USED
CLIENT-SIDE INSERTION: NOT USED
BLOCK CLASS NAME: code-block
INLINE STYLES: ENABLED
DYNAMIC BLOCKS: Server-side
PARAGRAPH COUNTING: Standard
NO PAR. COUNTING INSIDE: blockquote, figure, li
OUTPUT BUFFERING: Disabled
AD LABEL: Advertisements
MAIN CONTENT:
PLUGIN PRIORITY: 99999
HEADER CODE: DISABLED
FOOTER CODE: DISABLED
AD BLOCKING DETECTION: DISABLEDBLOCK SETTINGS Po Pa Hp Cp Ap Sp AM Aj Fe 404 Wi Sh PHP
1 Strossle o . . . . . . o . . x . . [After Post][Center]
2 Midtbanner Artikkel o . . . . . . o . . x . . [After Paragraph][Center]
3 Toppbanner mobil arti o . . . . . . o . . x . . [After Paragraph][Default][paragraph_number: 6]
4 Block 4 o . . . . . . o . . x . . [After Post][Default]EXCEPTIONS FOR BLOCKS ID TYPE TITLE URL
TOTAL BLOCKS
CONTENT HOOK: 2, 3
LOOP END HOOK: 1, 4BLOCKS FOR THIS PAGE TYPE
CONTENT HOOK: 2, 3
LOOP END HOOK: 1, 4TIME EVENT
======================================
0 INITIALIZATION START
1 LOAD SETTINGS START
0 LOAD OPTIONS START
0 LOAD OPTIONS END
0 LOAD SETTINGS END
0 INITIALIZATION END45 WP LOADED HOOK START
0 EXTRACT GENERATED
0 WP LOADED HOOK END3 WP HOOK START
0 WP HOOK END18 HEAD HOOK START
1 HEAD HOOK END15 BEFORE POST HOOK START
0 BEFORE POST HOOK END1 CONTENT HOOK START [1]
0 <h4>…</p>*n [354 words]
0 BLOCK 2 INSERTION POSITIONS: 1
0 BLOCK 2 INSERTED
0 BLOCK 3 INSERTION POSITIONS: 6
0 BLOCK 3 INSERTED
0 CONTENT HOOK END0 AFTER POST HOOK START
0 BLOCK 1 INSERTED
0 BLOCK 4 INSERTED
0 AFTER POST HOOK END4 FOOTER HOOK START
0 FOOTER HOOK END0 FOOTER HOOK START
0 FOOTER HOOK ENDINSERTION SUMMARY
======================================
BLOCK 1 INSERTED
BLOCK 2 INSERTED
BLOCK 3 INSERTED
BLOCK 4 INSERTEDPHP: 7.2.3
Memory Limit: 128M
Upload Max Filesize: 2M
Post Max Size: 8M
Max Execution Time: 30
Max Input Vars: 1000
Display Errors: 1
cURL: ENABLED
fsockopen: ENABLED
DOMDocument: YESWordpress: 4.9.4
Current Theme: [TextRemoved]A INSTALLED PLUGINS
======================================
* Ad Inserter 2.3.17
Akismet Anti-Spam 4.0.2
AMO Team Showcase 1.1.4
Autoptimize 2.3.4
Clean Image Filenames 1.2.1
Contact Form 7 5.0.2
Easy FancyBox 1.8.5
Genesis Translations 2.5.0
Genesis Widget Column Classes 1.2.4.1
Google Tag Manager for WordPress 1.8.1
Hello Dolly 1.6
Imsanity 2.3.10
* Log wp hook
Related Posts 5.12.75
Simple 301 Redirects 1.07
User Role Editor 4.43
Widget CSS Classes 1.5.2.1
WordPress Importer 0.6.4
WP All Import 3.4.9
WP Mail SMTP 1.3.2
WP User Avatars 1.4.0
Yoast SEO 7.7.3–>
I can’t recreate the same environment without knowing the theme used.
It seems that your theme calls
wp_footerhook two times.
And the log shows thatwphook is called only once.Please try to reproduce the problem with some default WP theme and as few plugins as possible.
Hi
I’ve solved the issue.
It had nothing to do with your plugin.There was a third-party script that sent an image request to the same URL that the user was browsing, causing the server to render the whole page twice. The script was loaded through the ad-inserter plugin, and I assumed there was something todo with the plugin since it worked when I switched it off.
Thanks for the help, and sorry for the inconvenience!
Best regards Naoell.π
-
This reply was modified 7 years, 9 months ago by
The topic ‘Plugin causes hook ‘wp’ to fire twice’ is closed to new replies.