Permalink
Browse files

Added support for embedding widget as a shortcode [gknsp]

* Few small improvements in the default config array
* Improved checking of the $instance variable
  • Loading branch information...
dziudek committed Feb 25, 2014
1 parent babe1e0 commit 19a3cc9ea62ec28cfdb5e433c5972d5165da3d67
Showing with 53 additions and 6 deletions.
  1. +43 −0 gk-nsp/gk-nsp-shortcodes.php
  2. +10 −6 gk-nsp/gk-nsp.php
@@ -0,0 +1,43 @@
<?php
/*
Copyright 2013-2013 GavickPro (info@gavick.com)
this program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
if ( !defined( 'WPINC' ) ) {
die;
}
// Basic shortcode
function GK_NewsShowPro_Shortcode($params = array()) {
// create widget
$instance = new GK_NewsShowPro_Widget();
// basic widget params
$args = array(
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => ''
);
// return the widget instance
return $instance->widget($args, $params);
}
add_shortcode('gknsp', 'GK_NewsShowPro_Shortcode');
// EOF
View
@@ -42,6 +42,7 @@
include(dirname(__FILE__) . '/gk-nsp-form-walkers.php');
include(dirname(__FILE__) . '/gk-nsp-helpers.php');
include(dirname(__FILE__) . '/gk-nsp-image-filters.php');
include(dirname(__FILE__) . '/gk-nsp-shortcodes.php');
/**
* i18n
@@ -83,7 +84,7 @@ class GK_NewsShowPro_Widget extends WP_Widget {
'widget_css_suffix' => '',
'use_css' => 'on',
// data source
'data_source_type' => 'latest',
'data_source_type' => 'wp-latest',
'data_source' => '',
'wp_category_list' => array(),
'woocommerce_category_list' => array(),
@@ -125,6 +126,7 @@ class GK_NewsShowPro_Widget extends WP_Widget {
'article_image_order' => '3',
'article_image_popup' => 'on',
'article_image_filter' => 'none',
'default_image' => '',
// article info format
'article_info_state' => 'on',
'article_info_format' => '{DATE} {CATEGORY} {AUTHOR} {COMMENTS}',
@@ -391,11 +393,13 @@ function widget($args, $instance) {
//
extract($args, EXTR_SKIP);
//
foreach($instance as $key => $value) {
if($key == 'title') {
$this->config['title'] = apply_filters('widget_title', !isset($instance['title']) ? $this->config['title'] : $instance['title'], $instance, $this->id_base);
} else {
$this->config[$key] = !isset($instance[$key]) ? $this->config[$key] : $instance[$key];
if((is_array($instance) || is_object($instance)) && count($instance)) {
foreach($instance as $key => $value) {
if($key == 'title') {
$this->config['title'] = apply_filters('widget_title', !isset($instance['title']) ? $this->config['title'] : $instance['title'], $instance, $this->id_base);
} else {
$this->config[$key] = !isset($instance[$key]) ? $this->config[$key] : $instance[$key];
}
}
}

0 comments on commit 19a3cc9

Please sign in to comment.