esc_html__( 'AD - Single Listing Sidebar', 'adirectory' ),
'id' => 'adqs_single_listing',
'description' => esc_html__( 'Add widgets for the sidebar on single listing page.', 'adirectory' ),
'before_widget' => '
',
'after_widget' => '
',
'before_title' => '',
],
[
'name' => esc_html__( 'AD - Archive Listings Sidebar', 'adirectory' ),
'id' => 'adqs_archive_listings',
'description' => esc_html__( 'Add widgets for the sidebar on archive listings page.', 'adirectory' ),
'before_widget' => '',
'after_widget' => '
',
'before_title' => '',
],
];
}
/**
* Store all the classes inside an array
*
* @return array Full list of classes
*/
public static function get_widgets() {
return [
All_Widgets\Connect_Agent::class,
All_Widgets\Listings_By::class,
All_Widgets\Populer_Listings::class,
All_Widgets\Related_Listings::class,
All_Widgets\Categories::class,
All_Widgets\Locations::class,
All_Widgets\Tags::class,
All_Widgets\Advanced_Sidebar_Filter::class,
];
}
/**
* Register Widgets and Sidebar
*
* @return void
*/
public function register_widgets() {
// Register all custom widgets
foreach ( self::get_widgets() as $class ) {
if ( class_exists( $class ) ) {
try {
register_widget( $class );
} catch ( \Exception $e ) {
// Log error but continue with other widgets
error_log( 'ADirectory: Failed to register widget ' . $class . ': ' . $e->getMessage() );
}
} else {
error_log( 'ADirectory: Widget class not found: ' . $class );
}
}
// Register all custom sidebars
foreach ( self::register_sidebar() as $sidebar ) {
try {
register_sidebar( $sidebar );
} catch ( \Exception $e ) {
// Log error but continue with other sidebars
error_log( 'ADirectory: Failed to register sidebar ' . $sidebar['id'] . ': ' . $e->getMessage() );
}
}
}
}