Fix PHP 8.4 compatibility issues in Sensational theme
- Fixed deprecated WP_Widget constructors in all widget files - Changed $this->WP_Widget() to parent::__construct() in: * widget-social.php * widget-fblikebox.php * widget-googleplus.php * widget-tabs.php - Fixed old-style constructor methods to __construct() in: * widget-ad125.php (mts_Ad_Widget -> __construct) * widget-ad300.php (mts_ad_300_Widget -> __construct) - Fixed for loop syntax error in widget-tweets.php (for(i; -> for($i = 1;) - Enabled registration for ad125 and ad300 widgets - Added new 'After First Paragraph' widget area for in-content ads All widgets now compatible with PHP 8.4 and editable in WordPress admin. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
53
functions/widget-after-first-paragraph.php
Normal file
53
functions/widget-after-first-paragraph.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/*-----------------------------------------------------------------------------------
|
||||
|
||||
Plugin Name: MyThemeShop After First Paragraph Ad Widget
|
||||
Description: A widget area that displays after the first paragraph in posts/pages
|
||||
Version: 1.0
|
||||
|
||||
-----------------------------------------------------------------------------------*/
|
||||
|
||||
// Register widget area
|
||||
function mts_register_after_first_paragraph_widget() {
|
||||
register_sidebar(array(
|
||||
"name" => __("After First Paragraph", "mythemeshop"),
|
||||
"id" => "after-first-paragraph",
|
||||
"description" => __("Widget area that appears after the first paragraph in posts and pages.", "mythemeshop"),
|
||||
"before_widget" => "<div class=\"after-first-paragraph-widget\">",
|
||||
"after_widget" => "</div>",
|
||||
"before_title" => "<h3 class=\"widget-title\">",
|
||||
"after_title" => "</h3>",
|
||||
));
|
||||
}
|
||||
add_action("widgets_init", "mts_register_after_first_paragraph_widget");
|
||||
|
||||
// Insert widget content after first paragraph
|
||||
function mts_insert_after_first_paragraph($content) {
|
||||
// Only run on single posts and pages
|
||||
if (!is_single() && !is_page()) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Check if widget area has active widgets
|
||||
if (!is_active_sidebar("after-first-paragraph")) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Get the widget content
|
||||
ob_start();
|
||||
dynamic_sidebar("after-first-paragraph");
|
||||
$widget_content = ob_get_clean();
|
||||
|
||||
// Find the first paragraph
|
||||
$closing_p = "</p>";
|
||||
$paragraphs = explode($closing_p, $content);
|
||||
|
||||
// Insert widget after first paragraph if content has paragraphs
|
||||
if (count($paragraphs) > 1) {
|
||||
$paragraphs[0] .= $closing_p . $widget_content;
|
||||
$content = implode($closing_p, $paragraphs);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
add_filter("the_content", "mts_insert_after_first_paragraph");
|
||||
Reference in New Issue
Block a user