Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
<?php
namespace kantoniak {
class AboutMe {
// ...
public function __construct() {
// ...
add_action('widgets_init', function() {
register_widget('\kantoniak\AboutMeWidget');
// To pass arguments to widget, see https://wordpress.org/ideas/topic/allow-ability-to-pass-parameters-when-registering-widgets
global $wp_widget_factory;
$widget = $wp_widget_factory->widgets['\kantoniak\AboutMeWidget'];
$widget->setPlugin($this);
});
}
// ...
}
class AboutMeWidget extends \WP_Widget {
private $plugin;
// ...
public function setPlugin($plugin) {
$this->plugin = $plugin;
}
public function widget($args, $instance) {
echo '<ul>';
foreach ($this->plugin->getSocialUrlsFromDatabase() as $slug => $url) {
$name = $this->plugin->getMediaSiteBySlug($slug)['name'];
$url_prefix = $this->plugin->getMediaSiteBySlug($slug)['url_prefix'];
echo '<li class="'. $slug .'"><a href="'. $url_prefix . $url .'" alt="'. $name .'">'. $name .'</a></li>';
}
echo '</ul>';
}
// ...
}
$aboutMe = new AboutMe();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment