mirror of
https://0xacab.org/radar/radar-wp.git
synced 2025-04-20 14:56:31 +02:00
WIP New v2 plugin with widget and shortcode, and more WP friendly markup.
This commit is contained in:
parent
5fd32fb63b
commit
649f84ad8c
557 changed files with 648 additions and 98567 deletions
90
includes/squat-radar-instance.php
Normal file
90
includes/squat-radar-instance.php
Normal file
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Manage the Squat Radar plugin.
|
||||
*
|
||||
* @package Squat_Radar
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Singleton for managing Squat Radar.
|
||||
*/
|
||||
class Squat_Radar_Instance {
|
||||
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* Creates or returns an instance of this class.
|
||||
*
|
||||
* @return A single instance of this class.
|
||||
*/
|
||||
public static function get_instance() {
|
||||
return null == self::$instance ? self::$instance = new self : self::$instance;
|
||||
}
|
||||
|
||||
private function __construct() {
|
||||
include SQUAT_RADAR_DIR . 'includes/squat-radar-widget.php';
|
||||
include SQUAT_RADAR_DIR . 'includes/squat-radar-connector.php';
|
||||
include SQUAT_RADAR_DIR . 'includes/squat-radar-formatter.php';
|
||||
|
||||
add_shortcode( 'squat_radar_sidebar', array($this, 'print_sidebar') );
|
||||
// add_shortcode( 'squat_radar_widget', array( $this, 'shortcode' ) );
|
||||
add_action( 'plugins_loaded', array( $this, 'i18n' ), 5 );
|
||||
add_action( 'widgets_init', array( $this, 'add_sidebar' ), 20 );
|
||||
add_action( 'widgets_init', array('Squat_Radar_Widget', 'register_widget') );
|
||||
|
||||
Squat_Radar_Formatter::register();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load translation files
|
||||
*
|
||||
* @since 0.2.4
|
||||
*/
|
||||
function i18n() {
|
||||
load_plugin_textdomain( 'squat-radar', false, '/languages' );
|
||||
}
|
||||
|
||||
/**
|
||||
* output a widget using 'widget' shortcode.
|
||||
*
|
||||
* Requires the widget ID.
|
||||
* You can overwrite widget args: before_widget, before_title, after_title, after_widget
|
||||
*
|
||||
* @example [widget id="text-1"]
|
||||
* @since 0.1
|
||||
*/
|
||||
public function shortcode( $atts, $content = null ) {
|
||||
$atts['echo'] = false;
|
||||
return $this->do_widget( $atts );
|
||||
}
|
||||
|
||||
function print_sidebar() {
|
||||
ob_start();
|
||||
|
||||
if (is_active_sidebar('squat_widget_gebied')) {
|
||||
dynamic_sidebar('squat_widget_gebied');
|
||||
}
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
||||
|
||||
function add_sidebar() {
|
||||
|
||||
register_sidebar(array(
|
||||
'name' => __( 'Squat Radar Shortcodes'),
|
||||
'description'=> __( 'This widget area is not by default displayed on frontend. It can be displayed with all its widgets with the [squat_radar] shortcode.', 'squat-radar' ),
|
||||
'id' => 'squat_radar_widget_shortcode',
|
||||
'before_widget' => '<div class="widget %2$s">',
|
||||
'after_widget' => '</div>',
|
||||
'before_title' => '<h3 class="widget-title">',
|
||||
'after_title' => '</h3>',
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue