我正在使用[插件:展示台:图表和图表] 在这个插件中有课
class Visualizer_Module_Frontend extends Visualizer_Module {
const NAME = __CLASS__;
private $_charts = array();
public function __construct( Visualizer_Plugin $plugin ) {
parent::__construct( $plugin );
$this->_addAction( 'wp_enqueue_scripts', 'enqueueScripts' );
$this->_addShortcode( 'visualizer', 'renderChart' );
// add do_shortocde hook for widget_text filter
if ( !has_filter( 'widget_text', 'do_shortcode' ) ) {
add_filter( 'widget_text', 'do_shortcode' );
}
// add do_shortcode hook for term_description filter
if ( !has_filter( 'term_description', 'do_shortcode' ) ) {
add_filter( 'term_description', 'do_shortcode' );
}
}
public function enqueueScripts() {
wp_register_script( 'visualizer-google-jsapi', '//www.google.com/jsapi', array(), null, true );
wp_register_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( 'visualizer-google-jsapi', 'jquery' ), Visualizer_Plugin::VERSION, true );
}
public function renderChart( $atts ) {
$atts = shortcode_atts( array(
'id' => false, // chart id
'class' => false, // chart class
'series' => false, // series filter hook
'data' => false, // data filter hook
'settings' => false, // data filter hook
), $atts );
// if empty id or chart does not exists, then return empty string
if ( !$atts['id'] || !( $chart = get_post( $atts['id'] ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
return '';
}
$id = 'visualizer-' . $atts['id'];
$class = apply_filters( Visualizer_Plugin::FILTER_CHART_WRAPPER_CLASS, $atts['class'], $atts['id'] );
$class = !empty( $class ) ? ' class="' . $class . '"' : '';
$type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
// faetch and update settings
$settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
if ( empty( $settings['height'] ) ) {
$settings['height'] = '400';
}
// handle series filter hooks
$series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type );
if ( !empty( $atts['series'] ) ) {
$series = apply_filters( $atts['series'], $series, $chart->ID, $type );
}
// handle settings filter hooks
$settings = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SETTINGS, $settings, $chart->ID, $type );
if ( !empty( $atts['settings'] ) ) {
$settings = apply_filters( $atts['settings'], $settings, $chart->ID, $type );
}
// handle data filter hooks
$data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( $chart->post_content ), $chart->ID, $type );
if ( !empty( $atts['data'] ) ) {
$data = apply_filters( $atts['data'], $data, $chart->ID, $type );
}
// add chart to the array
$this->_charts[$id] = array(
'type' => $type,
'series' => $series,
'settings' => $settings,
'data' => $data,
);
// enqueue visualizer render and update render localizations
wp_enqueue_script( 'visualizer-render' );
wp_localize_script( 'visualizer-render', 'visualizer', array( 'charts' => $this->_charts ) );
return '<div id="' . $id . '"' . $class . '></div>';
} }
我想扩展这个类,以便我可以覆盖函数renderChart()。 但是我想用另一个自定义插件来做这件事。