WP shortcode output always at top of page - wordpress

When placing a shortcode on a custom WordPress page the output is always displayed at the top of my page content.
I found out that the problem can be fixed by either using return instead of echo, or by using output buffering: (ob_start() / ob_get_contents())
Unfortunately my coding skills are not what I would like them to be.. And I don't know exactly where to implement these fixes.
Can someone help me out please? The plugin developer is not responding to my mails and I need to get this to work a.s.a.p.
I assume this needs to be implemented in the faulty plugin's functions file so I added it below.
<?php
/**
* Woocommerce Category Accordion Functions
*
* #author TechieResource
* #category Shortcode
* #package woocommerce-category-accordion/inc
* #version 1.2.1
*/
/**
/* Clean variables
*
* #param string $var
* #return string
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
class trwca_wc_category_accordion{
/**
* Constructor
*/
private $shortcode_tag = "WC-Category-Accordion";
public function __construct() {
add_action( 'woocommerce_category_accordion', array( $this, 'woocommerce_category_accordion_func' ), 10, 2 );
add_shortcode( $this->shortcode_tag, array( $this, 'wc_category_accordion_sc' ) );
if ( is_admin() ){
add_action('admin_head', array( $this, 'admin_head') );
add_action( 'admin_enqueue_scripts', array($this , 'admin_enqueue_scripts' ) );
}
}
/**
* Display the Woocommerce Category Accordion.
* #since 1.2.1
* #param array $instance Arguments.
* #param bool $echo Whether to display or return the output.
* #return string
*/
public function woocommerce_category_accordion_func( $instance, $echo = true ) {
extract( $instance, EXTR_SKIP );
global $wp_query;
global $post, $product;
$exclude_tree = esc_attr($exclude_tree );
$hide_empty = esc_attr($hide_empty );
$show_count = esc_attr($show_count );
$open_cat = esc_attr($open_cat );
$ac_speed = esc_attr($ac_speed );
$ac_type = esc_attr($ac_type );
$event_type = esc_attr($event_type );
$ac_icon = esc_attr($ac_icon );
$sortby = esc_attr($sortby );
$ac_theme = esc_attr($ac_theme );
$order = esc_attr($order );
$level = esc_attr($level );
$cats_id = esc_attr($ac_opencat);
$disable_parent = esc_attr($disable_parent);
$disable_aclink = esc_attr($disable_aclink);
if(!empty($instance['id'])){
$widgetid= $instance['id'];
}
else{
if($sh_id!=""){
$widgetid= "wc_category_accordion-".$sh_id;
}
else{
$widgetid= "wc_category_accordion-".$this->trwca_generate_random_code(3);
}
}
$instance_categories = get_terms( 'product_cat', '&parent=0&exclude='.$exclude_tree.'');
if (is_array($instance_categories)) {
foreach($instance_categories as $categories) {
$term_id[] = $categories->term_id;
$term_name = $categories->name;
}
}
if(!empty($post->ID)){
$terms =get_the_terms( $post->ID, 'product_cat' );
}
else {
$terms="";
}
if (is_array($terms )) {
foreach ( $terms as $term) {
$_cat=$term->term_id;
break;
}
}
/* For current category highlight */
if(is_product()){
$current_cat= array();
$cat = $wp_query->get_queried_object();
if (!empty($cat->term_id))
{
$current_cat = $cat->term_id;
}
else{
$_cat_id="1";
if (isset($term->term_id))
{
$_cat=$term->term_id;
$_cat_id = !empty($_cat) ? $_cat_id=$_cat : $_cat_id=1 ;
}
if (is_shop())
{
$_cat_id="1";
}
if (!is_shop()){
if (is_array($terms )) {
foreach($terms as $term){
$myterms[]= $term->term_id;
}
$cats_id=end($myterms);
?>
<script type="text/javascript">
var cats_id= <?php return end($myterms); ?>;
</script>
<style type="text/css">
<?php foreach((get_the_terms($post->ID, 'product_cat')) as $term) {
$myterms= $term->term_id;
return 'ul.'.$widgetid.' li.cat-item-'.$myterms.' > a{font-weight:bold;}';
}
}
}
?>
</style>
<?php
}
}
$cat = $wp_query->get_queried_object();
if (!empty($cat->term_id) && !is_product() ){
$cats_id = $cat->term_id;
return '<script type="text/javascript">
var cats_id= '.$cats_id.';
</script>';
}
else if(!is_product_category() && !is_product()){
$cats_id=$ac_opencat;
}
$ac_type = $ac_type=="toggle" ? $ac_type= "true" : $ac_type= "false";
$open_cat = $open_cat== true || $open_cat =='on' ? $open_cat=true : $open_cat=false;
/* Icon Selection */
switch ($ac_icon) {
case 'angle' :
$open_icon="angle-down";
$close_icon="angle-right";
break;
case 'doubleangle' :
$open_icon="angle-double-down";
$close_icon="angle-double-right";
break;
case 'arrow-circle1' :
$open_icon="arrow-circle-down";
$close_icon="arrow-circle-right";
break;
case 'arrow-circle2' :
$open_icon="arrow-circle-o-down";
$close_icon="arrow-circle-o-right";
break;
case 'arrow-right' :
$open_icon="arrow-down";
$close_icon="arrow-right";
break;
case 'caret' :
$open_icon="caret-down";
$close_icon="caret-right";
break;
case 'caret-square' :
$open_icon="caret-square-o-down";
$close_icon="caret-square-o-right";
break;
case 'chevron' :
$open_icon="chevron-down";
$close_icon="chevron-right";
break;
case 'chevron-circle' :
$open_icon="chevron-circle-down";
$close_icon="chevron-circle-right";
break;
case 'hand' :
$open_icon="hand-o-down";
$close_icon="hand-o-right";
break;
case 'plus' :
$open_icon="minus";
$close_icon="plus";
break;
case 'plus-circle' :
$open_icon="minus-circle";
$close_icon="plus-circle";
break;
case 'plus-square1' :
$open_icon="minus-square";
$close_icon="plus-square";
break;
case 'plus-square2' :
$open_icon="minus-square-o";
$close_icon="plus-square-o";
break;
}
if($disable_aclink==true){
$disable_aclink='true';
}
else if($disable_aclink==""){
$disable_aclink= 'false';
}
if($disable_parent==true){
$disable_parent='true';
}
else if($disable_parent==""){
$disable_parent='false';
}
$cats_id= empty($cats_id) ? 1 : $cats_id;
?>
<script type="text/javascript">
var $=jQuery.noConflict();
$(document).ready(function($){
$('.<?php echo $widgetid; ?>').trwcAccordion({
classParent : 'trwca-parent',
classActive : 'active',
classArrow : 'trwca-icon',
classCount : 'trwca-count',
classExpand : 'trwca-current-parent',
eventType : '<?php echo $event_type; ?>',
hoverDelay : 100,
menuClose : true,
cats_id: <?php echo $cats_id; ?>,
ac_type : <?php echo $ac_type; ?>,
autoExpand : true,
speed : '<?php echo $ac_speed ?>',
saveState : '<?php echo $open_cat; ?>',
disableLink : <?php echo $disable_aclink; ?>,
disableparentLink : <?php echo $disable_parent; ?>,
auto_open: 1,
showCount : true,
widget_id : "<?php echo $widgetid; ?>",
openIcon : '<?php echo $open_icon; ?>',
closeIcon : '<?php echo $close_icon; ?>',
});
});
</script>
<div class="block-content trwca-actheme <?php echo $ac_theme; ?>">
<div class="trwca-loader"></div>
<ul class="<?php echo $widgetid; ?> accordion" id="outer_ul">
<?php
$subcat_args = array(
'taxonomy' => 'product_cat',
'title_li' => '',
'orderby' => $sortby,
'order' => $order,
'depth' => $level,
'show_count' => $show_count,
'hide_empty' => $hide_empty,
'use_desc_for_title' => 1,
'echo' => false,
'exclude' => $exclude_tree,
'hierarchical' => true ,
'show_option_none' => __('No Categories Found','trwca'),
'link_after' => '',
'walker'=> new trwca_walker
);
?>
<?php $subcategories = wp_list_categories( $subcat_args );
$subcategories=preg_replace_callback(
'/<\/a> \(([0-9]+)\)/',
function ($matches) {
return ' <span class="count">('.($matches[1]).')</span></a>';
},$subcategories
);
?>
<?php if ( $subcategories ) {
echo $subcategories;
}
?>
</ul>
</div>
<?php
}
public function trwca_generate_random_code($length=3) {
$string = '';
$characters = "123456789";
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters)-1)];
}
return $string;
}
/**
* admin_head
* calls your functions into the correct filters
* #return void
*/
function admin_head() {
// check user permissions
if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
return;
}
// check if WYSIWYG is enabled
if ( 'true' == get_user_option( 'rich_editing' ) ) {
add_filter( 'mce_external_plugins', array( $this ,'mce_external_plugins' ) );
add_filter( 'mce_buttons', array($this, 'mce_buttons' ) );
}
}
/**
* mce_external_plugins
* Adds our tinymce plugin
* #param array $plugin_array
* #return array
*/
function mce_external_plugins( $plugin_array ) {
$plugin_array['WC_Category_Accordion'] = plugins_url( 'admin/js/mce-button.js' , __FILE__ );
return $plugin_array;
}
/**
* mce_buttons
* Adds our tinymce button
* #param array $buttons
* #return array
*/
function mce_buttons( $buttons ) {
array_push( $buttons, 'WC_Category_Accordion' );
return $buttons;
}
/**
* admin_enqueue_scripts
* Used to enqueue custom styles
* #return void
*/
function admin_enqueue_scripts(){
wp_enqueue_style('WC-Category-Accordion-sh', plugins_url( 'admin/css/mce-button.css' , __FILE__ ) );
}
public function wc_category_accordion_sc( $atts, $content = null ) {
$defaults = array(
'show_count' => 0,
'ac_speed' => 'fast',
'exclude_tree' =>'',
'hide_empty' => 0,
'sortby' =>'name',
'order' =>'ASC',
'level' => 0,
'event_type' => 'click',
'ac_type' => 'toggle',
'open_cat' => 0,
'ac_opencat' => 1,
'ac_icon' =>'plus',
'disable_parent' => 0,
'disable_aclink' => 0,
'ac_theme' => '',
'sh_id'=> '' );
$settings = shortcode_atts( $defaults, $atts );
return $this->woocommerce_category_accordion_func( $settings, false );
}
}
new trwca_wc_category_accordion();
function trwca_clean( $var ) {
return sanitize_text_field( $var );
}
}
?>
Thank you guys!

function your_shortcode_function(){
ob_start(); ?>
<div>
// all your stuffs here
</div>
<?php
$contents=ob_get_contents();
ob_end_clean();
return $contents;
}
add_shortcode('your_shortcode', 'your_shortcode_function');
You need ob_start and ob_end_clean() as said as above OUTPUT BUFFERING

You'll want to use ob_start() and return ob_get_clean() inside the shortcode function.
Likeso:
<?php
function my_shortcode(){ // The function that is our shortode output.
ob_start();?>
<div class="my-shortcode-output">
<em>I'm <strong>the best</strong></em>
</div>
<?php
return $ob_get_clean();
}
add_shortcode( 'my-shortcode', 'my_shortcode' );
I'd also consider not echoing js from your php, using wp_enque_script and wp_localize_script is much nicer.

This should work.
<?php
/**
* Woocommerce Category Accordion Functions
*
* #author TechieResource
* #category Shortcode
* #package woocommerce-category-accordion/inc
* #version 1.2.1
*/
/**
/* Clean variables
*
* #param string $var
* #return string
*/
if (!defined('ABSPATH')) {
exit;
} // Exit if accessed directly
if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
class trwca_wc_category_accordion
{
/**
* Constructor
*/
private $shortcode_tag = "WC-Category-Accordion";
public function __construct()
{
add_action('woocommerce_category_accordion', array(
$this,
'woocommerce_category_accordion_func'
), 10, 2);
add_shortcode($this->shortcode_tag, array(
$this,
'wc_category_accordion_sc'
));
if (is_admin()) {
add_action('admin_head', array(
$this,
'admin_head'
));
add_action('admin_enqueue_scripts', array(
$this,
'admin_enqueue_scripts'
));
}
}
/**
* Display the Woocommerce Category Accordion.
* #since 1.2.1
* #param array $instance Arguments.
* #param bool $echo Whether to display or return the output.
* #return string
*/
public function woocommerce_category_accordion_func($instance, $echo = true)
{
ob_start();
extract($instance, EXTR_SKIP);
global $wp_query;
global $post, $product;
$exclude_tree = esc_attr($exclude_tree);
$hide_empty = esc_attr($hide_empty);
$show_count = esc_attr($show_count);
$open_cat = esc_attr($open_cat);
$ac_speed = esc_attr($ac_speed);
$ac_type = esc_attr($ac_type);
$event_type = esc_attr($event_type);
$ac_icon = esc_attr($ac_icon);
$sortby = esc_attr($sortby);
$ac_theme = esc_attr($ac_theme);
$order = esc_attr($order);
$level = esc_attr($level);
$cats_id = esc_attr($ac_opencat);
$disable_parent = esc_attr($disable_parent);
$disable_aclink = esc_attr($disable_aclink);
if (!empty($instance['id'])) {
$widgetid = $instance['id'];
} else {
if ($sh_id != "") {
$widgetid = "wc_category_accordion-" . $sh_id;
} else {
$widgetid = "wc_category_accordion-" . $this->trwca_generate_random_code(3);
}
}
$instance_categories = get_terms('product_cat', '&parent=0&exclude=' . $exclude_tree . '');
if (is_array($instance_categories)) {
foreach ($instance_categories as $categories) {
$term_id[] = $categories->term_id;
$term_name = $categories->name;
}
}
if (!empty($post->ID)) {
$terms = get_the_terms($post->ID, 'product_cat');
} else {
$terms = "";
}
if (is_array($terms)) {
foreach ($terms as $term) {
$_cat = $term->term_id;
break;
}
}
/* For current category highlight */
if (is_product()) {
$current_cat = array();
$cat = $wp_query->get_queried_object();
if (!empty($cat->term_id)) {
$current_cat = $cat->term_id;
} else {
$_cat_id = "1";
if (isset($term->term_id)) {
$_cat = $term->term_id;
$_cat_id = !empty($_cat) ? $_cat_id = $_cat : $_cat_id = 1;
}
if (is_shop()) {
$_cat_id = "1";
}
if (!is_shop()) {
if (is_array($terms)) {
foreach ($terms as $term) {
$myterms[] = $term->term_id;
}
$cats_id = end($myterms);
?>
<script type="text/javascript">
var cats_id= <?php
return end($myterms);
?>;
</script>
<style type="text/css">
<?php
foreach ((get_the_terms($post->ID, 'product_cat')) as $term) {
$myterms = $term->term_id;
return 'ul.' . $widgetid . ' li.cat-item-' . $myterms . ' > a{font-weight:bold;}';
}
}
}
?>
</style>
<?php
}
}
$cat = $wp_query->get_queried_object();
if (!empty($cat->term_id) && !is_product()) {
$cats_id = $cat->term_id;
return '<script type="text/javascript">
var cats_id= ' . $cats_id . ';
</script>';
} else if (!is_product_category() && !is_product()) {
$cats_id = $ac_opencat;
}
$ac_type = $ac_type == "toggle" ? $ac_type = "true" : $ac_type = "false";
$open_cat = $open_cat == true || $open_cat == 'on' ? $open_cat = true : $open_cat = false;
/* Icon Selection */
switch ($ac_icon) {
case 'angle':
$open_icon = "angle-down";
$close_icon = "angle-right";
break;
case 'doubleangle':
$open_icon = "angle-double-down";
$close_icon = "angle-double-right";
break;
case 'arrow-circle1':
$open_icon = "arrow-circle-down";
$close_icon = "arrow-circle-right";
break;
case 'arrow-circle2':
$open_icon = "arrow-circle-o-down";
$close_icon = "arrow-circle-o-right";
break;
case 'arrow-right':
$open_icon = "arrow-down";
$close_icon = "arrow-right";
break;
case 'caret':
$open_icon = "caret-down";
$close_icon = "caret-right";
break;
case 'caret-square':
$open_icon = "caret-square-o-down";
$close_icon = "caret-square-o-right";
break;
case 'chevron':
$open_icon = "chevron-down";
$close_icon = "chevron-right";
break;
case 'chevron-circle':
$open_icon = "chevron-circle-down";
$close_icon = "chevron-circle-right";
break;
case 'hand':
$open_icon = "hand-o-down";
$close_icon = "hand-o-right";
break;
case 'plus':
$open_icon = "minus";
$close_icon = "plus";
break;
case 'plus-circle':
$open_icon = "minus-circle";
$close_icon = "plus-circle";
break;
case 'plus-square1':
$open_icon = "minus-square";
$close_icon = "plus-square";
break;
case 'plus-square2':
$open_icon = "minus-square-o";
$close_icon = "plus-square-o";
break;
}
if ($disable_aclink == true) {
$disable_aclink = 'true';
} else if ($disable_aclink == "") {
$disable_aclink = 'false';
}
if ($disable_parent == true) {
$disable_parent = 'true';
} else if ($disable_parent == "") {
$disable_parent = 'false';
}
$cats_id = empty($cats_id) ? 1 : $cats_id;
?>
<script type="text/javascript">
var $=jQuery.noConflict();
$(document).ready(function($){
$('.<?php
echo $widgetid;
?>').trwcAccordion({
classParent : 'trwca-parent',
classActive : 'active',
classArrow : 'trwca-icon',
classCount : 'trwca-count',
classExpand : 'trwca-current-parent',
eventType : '<?php
echo $event_type;
?>',
hoverDelay : 100,
menuClose : true,
cats_id: <?php
echo $cats_id;
?>,
ac_type : <?php
echo $ac_type;
?>,
autoExpand : true,
speed : '<?php
echo $ac_speed;
?>',
saveState : '<?php
echo $open_cat;
?>',
disableLink : <?php
echo $disable_aclink;
?>,
disableparentLink : <?php
echo $disable_parent;
?>,
auto_open: 1,
showCount : true,
widget_id : "<?php
echo $widgetid;
?>",
openIcon : '<?php
echo $open_icon;
?>',
closeIcon : '<?php
echo $close_icon;
?>',
});
});
</script>
<div class="block-content trwca-actheme <?php
echo $ac_theme;
?>">
<div class="trwca-loader"></div>
<ul class="<?php
echo $widgetid;
?> accordion" id="outer_ul">
<?php
$subcat_args = array(
'taxonomy' => 'product_cat',
'title_li' => '',
'orderby' => $sortby,
'order' => $order,
'depth' => $level,
'show_count' => $show_count,
'hide_empty' => $hide_empty,
'use_desc_for_title' => 1,
'echo' => false,
'exclude' => $exclude_tree,
'hierarchical' => true,
'show_option_none' => __('No Categories Found', 'trwca'),
'link_after' => '',
'walker' => new trwca_walker
);
$subcategories = wp_list_categories($subcat_args);
$subcategories = preg_replace_callback('/<\/a> \(([0-9]+)\)/', function($matches)
{
return ' <span class="count">(' . ($matches[1]) . ')</span></a>';
}, $subcategories);
if ($subcategories) {
echo $subcategories;
}
?>
</ul>
</div>
<?php
$contents=ob_get_contents();
ob_end_clean();
return $contents;
}
public function trwca_generate_random_code($length = 3)
{
$string = '';
$characters = "123456789";
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters) - 1)];
}
return $string;
}
/**
* admin_head
* calls your functions into the correct filters
* #return void
*/
function admin_head()
{
// check user permissions
if (!current_user_can('edit_posts') && !current_user_can('edit_pages')) {
return;
}
// check if WYSIWYG is enabled
if ('true' == get_user_option('rich_editing')) {
add_filter('mce_external_plugins', array(
$this,
'mce_external_plugins'
));
add_filter('mce_buttons', array(
$this,
'mce_buttons'
));
}
}
/**
* mce_external_plugins
* Adds our tinymce plugin
* #param array $plugin_array
* #return array
*/
function mce_external_plugins($plugin_array)
{
$plugin_array['WC_Category_Accordion'] = plugins_url('admin/js/mce-button.js', __FILE__);
return $plugin_array;
}
/**
* mce_buttons
* Adds our tinymce button
* #param array $buttons
* #return array
*/
function mce_buttons($buttons)
{
array_push($buttons, 'WC_Category_Accordion');
return $buttons;
}
/**
* admin_enqueue_scripts
* Used to enqueue custom styles
* #return void
*/
function admin_enqueue_scripts()
{
wp_enqueue_style('WC-Category-Accordion-sh', plugins_url('admin/css/mce-button.css', __FILE__));
}
public function wc_category_accordion_sc($atts, $content = null)
{
$defaults = array(
'show_count' => 0,
'ac_speed' => 'fast',
'exclude_tree' => '',
'hide_empty' => 0,
'sortby' => 'name',
'order' => 'ASC',
'level' => 0,
'event_type' => 'click',
'ac_type' => 'toggle',
'open_cat' => 0,
'ac_opencat' => 1,
'ac_icon' => 'plus',
'disable_parent' => 0,
'disable_aclink' => 0,
'ac_theme' => '',
'sh_id' => ''
);
$settings = shortcode_atts($defaults, $atts);
return $this->woocommerce_category_accordion_func($settings, false);
}
}
new trwca_wc_category_accordion();
function trwca_clean($var)
{
return sanitize_text_field($var);
}
}
?>

Related

can not add woocommerce order filter by vendors

woocommerce order page in, I want to filter orders by vendor. I am using the wcfm marketplace plugin.
Vendor name appears here. but when I filter, the orders are not listed.
please help :(woocommerce order page
function wcmp_admin_filter_by_vendor() {
global $typenow;
if ($typenow == 'shop_order') {
$admin_dd_html = '<select name="admin_order_vendor" id="dropdown_admin_order_vendor"><option value="">'.__("Show All Vendors", "dc-woocommerce-multi-vendor").'</option>';
$vendors = get_wcmp_vendors();
if($vendors) :
foreach ($vendors as $vendor) {
$admin_dd_html .= '<option value="'.$vendor->term_id.'">'.$vendor->page_title.'</option>';
}
endif;
$admin_dd_html .= '</select>';
echo $admin_dd_html;
}
}
add_action( 'restrict_manage_posts', 'wcmp_admin_filter_by_vendor');
function get_vendor_parent_order($id) {
$vendor_orders = get_posts( array(
'numberposts' => -1,
'meta_key' => '_vendor_id',
'meta_value' => $id,
'post_type' => 'shop_order',
'post_status' => 'any',
) );
foreach( $vendor_orders as $vendor_order ) {
$parent_order = wp_get_post_parent_id( $vendor_order->ID );
$parent_orders[] = $parent_order;
}
return $parent_orders;
}
function filter_orders_by_vendor_in_admin_dashboard( $query ) {
if (current_user_can('administrator') && !empty($_REQUEST['admin_order_vendor'])) {
$vendor_term_id = isset($_GET['admin_order_vendor'])?$_GET['admin_order_vendor']:'';
$vendor = get_wcmp_vendor_by_term($vendor_term_id);
$parent_orders = get_vendor_parent_order($vendor->id);
$query['post__in'] = $parent_orders;
return $query;
}
return $query;
}
add_filter( 'wcmp_shop_order_query_request', 'filter_orders_by_vendor_in_admin_dashboard');
function remove_wcmp_order_hook() {
global $WCMp;
remove_action( 'manage_shop_order_posts_custom_column', array($WCMp->order, 'wcmp_show_shop_order_columns'), 99, 2 );
}
add_action('init', 'remove_wcmp_order_hook');
function wcmp_show_shop_order_columns($column, $post_id) {
global $WCMp;
switch ($column) {
case 'wcmp_suborder' :
$wcmp_suborders = $WCMp->order->get_suborders($post_id);
if ($wcmp_suborders) {
echo '<ul class="wcmp-order-vendor" style="margin:0px;">';
foreach ($wcmp_suborders as $suborder) {
$vendor = get_wcmp_vendor(get_post_field('post_author', $suborder->get_id()));
$vendor->ID = get_post_field('post_author', $suborder->get_id());
$vendor_term_id = isset($_GET['admin_order_vendor'])?$_GET['admin_order_vendor']:'';
$filter_vendor = get_wcmp_vendor_by_term($vendor_term_id);
$filter_vendor_id = isset($filter_vendor->id)?$filter_vendor->id:'';
if( $vendor->ID == $filter_vendor_id || $filter_vendor_id == '' ) {
$order_uri = apply_filters('wcmp_admin_vendor_shop_order_edit_url', esc_url('post.php?post=' . $suborder->get_id() . '&action=edit'), $suborder->get_id());
printf('<li><mark class="%s tips" data-tip="%s">%s</mark> <strong>#%s</strong> – <small class="wcmp-order-for-vendor">%s %s</small></li>', sanitize_title($suborder->get_status()), $suborder->get_status(), $suborder->get_status(), $order_uri, $suborder->get_order_number(), _x('for', 'Order table details', 'dc-woocommerce-multi-vendor'), $vendor->page_title
);
}
do_action('wcmp_after_suborder_details', $suborder);
}
echo '<ul>';
} else {
echo '<span class="na">–</span>';
}
break;
}
}
add_action('manage_shop_order_posts_custom_column', 'wcmp_show_shop_order_columns', 99, 2);

WordPress page shows shortcodes

My WordPress page shows shortcodes like [vc_row][vc_column][vc_column_text] .
Help me identify the root cause.
I have migrated the wordpress sql files from one host to another.
You could modify this Utility Script Runner script to remove shortcodes that no longer exist but are in your page content. Definitely do this on staging before you do it on live. high likelyhood of wrecking up the place. This script has been sitting for close to a year and I honestly can't remember if any of it doesn't work as expected. test a lot on staging before running this on anything you really care about.
<?php if(!defined('ABSPATH')) { die(); }
/**
* Utility Name: Remove and Flatten Shortcodes
* Description: Strip Shortcodes from all posts, with several processing options
* Supports: input
* Version: 0.0.2
**/
if (!class_exists('StripShortcodes')) {
class StripShortcodes {
var $wrappers = array(),
$swaps = array();
public static function Instance() {
static $instance = null;
if ($instance === null) {
$instance = new self();
}
return $instance;
}
public function __construct() {
add_filter('wp_util_script', array($this, 'strip_shortcodes_run'), 10, 3);
add_filter('wp_util_input_html', array($this, 'strip_shortcodes_input_html'));
}
public function strip_shortcodes_input_html( $html ) {
global $shortcode_tags;
$post_types = get_post_types( array(
'exclude_from_search' => false
), 'names' );
$post_types = array_diff( $post_types, array( 'revision', 'attachment' ) );
?>
<p>
<strong>WARNING! DO NOT RUN THIS ON A LIVE SITE!</strong><br>
This utility may cause data loss. Even restoring a backup may wipe out any changes since the last run of this utility.
</p>
<label>
<input type="checkbox" name="restore" value="restore"/>
<span>Restore From Backup</span>
</label>
<label>
<span>Post Types to Process</span>
<select name="post_types[]" multiple="multiple">
<option value="none" selected="selected">none</option>
<option value="any">all</option>
<?php
foreach( $post_types as $post_type ) {
echo '<option value="' . esc_attr( $post_type ) . '">' . $post_type . '</option>';
}
?>
</select>
</label>
<hr/>
<p>
Select what you would like to do with each shortcode.
</p>
<?php
if( !empty( $shortcode_tags ) ) {
foreach( $shortcode_tags as $tag => $callable ) {
?>
<div class="shortcode-options-wrapper">
<label>
<span>[<?php echo $tag; ?>]</span>
<select class="shortcode-select" name="shortcodes[<?php echo esc_attr( $tag ); ?>]"/>
<option value="skip">Skip (do not process)</option>
<option value="strip">Remove (deletes shortcode content)</option>
<option value="unwrap">Unwrap Content</option>
<option value="parse">Flatten (parses to HTML)</option>
<option value="swap">Swap (Replace with another shortcode)</option>
</select>
</label>
</div>
<?php
}
}
echo $this->build_form_script();
return ob_get_clean();
}
private function build_form_script () {
global $shortcode_tags;
ob_start(); ?>
<script type="text/javascript">
(jQuery)(function($) {
'use strict';
var unwrap = '<div class="wrap-wrapper"><p>Wrapper for content (use "sprintf()" formatting, including the %s for the content)</p><label>Wrapper<input class="shortcode-wrap"></label></div>';
var swap = '<div class="swap-wrapper"><select class="shortcode-swap"><?php foreach ($shortcode_tags as $tag => $callable) { echo '<option value="' . $tag . '">' . esc_attr($tag) . '</option>'; }?></select></div>'
$(document).on('change', '.shortcode-select', function () {
var $this = $(this);
var name = $this.attr('name');
if ($this.val() == 'unwrap') {
$this.closest('.shortcode-options-wrapper').append(unwrap);
$this.closest('.shortcode-options-wrapper').find('.shortcode-wrap').attr('name', 'wrap_' + name);
$this.closest('.shortcode-options-wrapper').find('.swap-wrapper').remove();
}
else if ($this.val() == 'swap') {
$this.closest('.shortcode-options-wrapper').append(swap);
$this.closest('.shortcode-options-wrapper').find('.shortcode-swap').attr('name', 'swap_' + name);
$this.closest('.shortcode-options-wrapper').find('.wrap-wrapper').remove();
} else {
$this.closest('.shortcode-options-wrapper').find('.wrap-wrapper').remove();
$this.closest('.shortcode-options-wrapper').find('.swap-wrapper').remove();
}
})
});
</script>
<?php return ob_get_clean();
}
public function strip_shortcodes_run( $legacy, $state, $atts ) {
$batch = 10;
$offset = 0;
if( !empty( $state['offset'] ) ) {
$offset = $state['offset'];
}
$result = array(
'state' => 'error',
'message' => 'an unknown error has occurred',
);
$post_types = 'none';
if( !empty( $atts['post_types'] ) && !in_array( 'none', $atts['post_types'] ) ) {
$post_types = $atts['post_types'];
}
$shortcode_settings = array();
if( !empty( $atts['shortcodes'] ) ) {
$shortcode_settings['core'] = $atts['shortcodes'];
$shortcode_settings['wrap'] = $atts['wrap_shortcodes'];
$shortcode_settings['swap'] = $atts['swap_shortcodes'];
}
$restore = true;
if( empty( $atts['restore'] ) ) {
$this->replace_shortcode_functions( $shortcode_settings );
$restore = false;
}
$query = new WP_Query( array(
'posts_per_page' => $batch,
'offset' => $offset,
'post_type' => $post_types
) );
if( !$query->have_posts() ) {
$result = array(
'state' => 'complete',
'message' => 'successfully processed all posts'
);
} else {
$offset += $query->post_count;
while( $query->have_posts() ) {
$query->the_post();
$post = get_post();
$backup = get_post_meta( $post->ID, 'flatten_shortcodes_backup', true );
if( $restore ) {
if( $backup ) {
$post->post_content = $backup;
wp_update_post( $post );
delete_post_meta( $post->ID, 'flatten_shortcodes_backup' );
}
} else {
if( !$backup ) {
update_post_meta( $post->ID, 'flatten_shortcodes_backup', $post->post_content );
}
$post->post_content = do_shortcode( $post->post_content );
wp_update_post( $post );
}
}
$result = array(
'state' => array(
'offset' => $offset
),
'message' => $offset . ' posts processed'
);
}
return $result;
}
private function replace_shortcode_functions( $settings = array() ) {
global $shortcode_tags;
foreach( $shortcode_tags as $tag => $callable ) {
$setting = 'skip';
if( !empty( $settings['core'][$tag] ) ) {
$setting = $settings['core'][$tag];
}
switch( $setting ) {
case 'strip' :
$shortcode_tags[$tag] = "__return_empty_string";
break;
case 'unwrap':
$shortcode_tags[$tag] = array($this, 'replace_shortcode_unwrap');
$this->wrappers[$tag] = $settings['wrap'][$tag];
break;
case 'parse' :
// nothing needed
break;
case 'swap' :
$shortcode_tags[$tag] = array($this, 'swap_shortcode');
$this->swaps[$tag] = $settings['swap'][$tag];
break;
case 'skip' :
default :
unset( $shortcode_tags[$tag] );
}
}
}
public function replace_shortcode_unwrap( $atts=array(), $content='', $tag ) {
return sprintf($this->wrappers[$tag], $content);
}
public function swap_shortcode( $atts=array(), $content='', $tag ) {
$attString = '';
$newTag = $this->swaps[$tag];
if (!empty($atts)) {
foreach ($atts as $key => $att) {
$attString .= ' ' . $key . '="' . $att . '"';
}
}
$output = '[' . $newTag . $attString . ']';
if ($content) {
$output .= $content . '[/' . $newTag . ']';
}
return $output;
}
}
StripShortcodes::Instance();
}
I have got same result. My theme is wp baker. I activated edge core plugin and other required plug ins and it was solved.

wordpress I have class file which use for paypal express checkout Instead of express checkout i want to it replace to adaptive payment

/**
* Class PayPal
* #package Bookly\Lib\Payment
*/
class PayPal
{
// Array for cleaning PayPal request
static public $remove_parameters = array( 'action', 'token', 'PayerID', 'ab_fid', 'error_msg', 'type' );
/**
* The array of products for checkout
*
* #var array
*/
protected $products = array();
/**
* Send the Express Checkout NVP request
*
* #param $form_id
* #throws \Exception
*/
public function send_EC_Request( $form_id )
{
if ( !session_id() ) {
#session_start();
}
if ( ! count( $this->products ) ) {
throw new \Exception( 'Products not found!' );
}
$total = 0;
// create the data to send on PayPal
$data = array(
'SOLUTIONTYPE' => 'Sole',
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
'PAYMENTREQUEST_0_CURRENCYCODE' => get_option( 'ab_currency' ),
'NOSHIPPING' => 1,
'RETURNURL' => add_query_arg( array( 'action' => 'ab-paypal-return', 'ab_fid' => $form_id ), Lib\Utils\Common::getCurrentPageURL() ),
'CANCELURL' => add_query_arg( array( 'action' => 'ab-paypal-cancel', 'ab_fid' => $form_id ), Lib\Utils\Common::getCurrentPageURL() )
);
foreach ( $this->products as $index => $product ) {
$data[ 'L_PAYMENTREQUEST_0_NAME' . $index ] = $product->name;
$data[ 'L_PAYMENTREQUEST_0_AMT' . $index ] = $product->price;
$data[ 'L_PAYMENTREQUEST_0_QTY' . $index ] = $product->qty;
$total += ( $product->qty * $product->price );
}
$data['PAYMENTREQUEST_0_AMT'] = $total;
$data['PAYMENTREQUEST_0_ITEMAMT'] = $total;
echo "<pre>";
print_r($data);
exit;
// send the request to PayPal
$response = self::sendNvpRequest( 'SetExpressCheckout', $data );
// Respond according to message we receive from PayPal
if ( 'SUCCESS' == strtoupper( $response['ACK'] ) || 'SUCCESSWITHWARNING' == strtoupper( $response['ACK'] ) ) {
//$paypalurl = 'https://www' . get_option( 'ab_paypal_ec_mode' ) . '.paypal.com/cgi-bin/webscr?cmd=_express-checkout&useraction=commit&token=' . urldecode( $response['TOKEN'] );
$paypalurl = 'https://www' . get_option( 'ab_paypal_ec_mode' ) . '.paypal.com/cgi-bin/webscr?cmd=_ap-payment&useraction=commit&token=' . urldecode( $response['TOKEN'] );
header( 'Location: ' . $paypalurl );
exit;
} else {
header( 'Location: ' . wp_sanitize_redirect( add_query_arg( array( 'action' => 'ab-paypal-error', 'ab_fid' => $form_id, 'error_msg' => str_replace( ' ', '%20', $response['L_LONGMESSAGE0'] ) ), Lib\Utils\Common::getCurrentPageURL() ) ) );
exit;
}
}
/**
* Send the NVP Request to the PayPal
*
* #param $method
* #param array $data
* #return array
*/
public function sendNvpRequest( $method, array $data )
{
$url = 'https://api-3t' . get_option( 'ab_paypal_ec_mode' ) . '.paypal.com/nvp';
$curl = new Lib\Curl\Curl();
$curl->options['CURLOPT_SSL_VERIFYPEER'] = false;
$curl->options['CURLOPT_SSL_VERIFYHOST'] = false;
$data['METHOD'] = $method;
$data['VERSION'] = '76.0';
$data['USER'] = get_option( 'ab_paypal_api_username' );
$data['PWD'] = get_option( 'ab_paypal_api_password' );
$data['SIGNATURE'] = get_option( 'ab_paypal_api_signature' );
$httpResponse = $curl->post( $url, $data );
if ( ! $httpResponse ) {
exit( $curl->error() );
}
// Extract the response details.
parse_str( $httpResponse, $PayPalResponse );
if ( ! array_key_exists( 'ACK', $PayPalResponse ) ) {
exit( 'Invalid HTTP Response for POST request to ' . $url );
}
return $PayPalResponse;
}
public static function renderForm( $form_id )
{
$html = '<form method="post" class="ab-paypal-form">';
$html .= '<input type="hidden" name="action" value="ab-paypal-checkout"/>';
$html .= '<input type="hidden" name="ab_fid" value="' . $form_id . '"/>';
$html .= '<button class="ab-left ab-back-step ab-btn ladda-button" data-style="zoom-in" data-spinner-size="40"><span class="ladda-label">' . Lib\Utils\Common::getTranslatedOption( 'ab_appearance_text_button_back' ) . '</span></button>';
$html .= '<button class="ab-right ab-next-step ab-btn ladda-button" data-style="zoom-in" data-spinner-size="40"><span class="ladda-label">' . Lib\Utils\Common::getTranslatedOption( 'ab_appearance_text_button_next' ) . '</span></button>';
$html .= '</form>';
echo $html;
}
/**
* #return array
*/
public function getProducts()
{
return $this->products;
}
/**
* Add the Product for payment
*
* #param \stdClass $product
*/
public function addProduct( \stdClass $product )
{
$this->products[] = $product;
}
}

Wordpress wp_footer not loading

I'm using a theme which i've used before and the wp_footer is loading fine in there. But in the new site the wp_footer is not loading can't find the solution by myself! Is there someone who could help me?
it's in the right place before the </body> tag.
<footer>
<div class="container">
<div class="footermenu">
<?php
$footer = array(
'theme_location' => '',
'menu' => 'footer',
'container' => 'div',
'container_class' => '',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'depth' => 0,
'walker' => ''
);
wp_nav_menu($footer);
?>
<img src="http://www.web-lynx.nl/vandervalk/wp-content/uploads/2014/07/PBRB_logo-trans-300x41.png" width="300px" height="41px" class="logofooter"/>
<div class="clear"></div>
</div>
<h2><?php _e("ONZE SOCIAL MEDIA","vertaling"); ?></h2>
<div class="one_third">
<span data-icon="" class="footersocial"></span>
</div>
<div class="one_third">
<span data-icon="" class="footersocial"></span>
</div>
<div class="one_third">
<span data-icon="" class="footersocial"></span>
</div>
<div class="clear"></div>
<br>
Copyright © Van der Valk
</div>
</footer><!-- footer -->
</div><!-- site-wrapper -->
<script type="text/javascript">
jQuery('.googlemaps').click(function(){
if(jQuery('.gmap').css('display') == 'none'){
jQuery('.gmap').slideDown();
}else{
jQuery('.gmap').slideUp();
}
});
jQuery('.firstphone').click(function(){
jQuery('.otherphonenumbers').slideDown();
});
</script>
<script>
/*!
* classie v1.0.0
* class helper functions
* from bonzo https://github.com/ded/bonzo
* MIT license
*
* classie.has( elem, 'my-class' ) -> true/false
* classie.add( elem, 'my-new-class' )
* classie.remove( elem, 'my-unwanted-class' )
* classie.toggle( elem, 'my-class' )
*/
/*jshint browser: true, strict: true, undef: true, unused: true */
/*global define: false */
( function( window ) {
'use strict';
// class helper functions from bonzo https://github.com/ded/bonzo
function classReg( className ) {
return new RegExp("(^|\\s+)" + className + "(\\s+|$)");
}
// classList support for class management
// altho to be fair, the api sucks because it won't accept multiple classes at once
var hasClass, addClass, removeClass;
if ( 'classList' in document.documentElement ) {
hasClass = function( elem, c ) {
return elem.classList.contains( c );
};
addClass = function( elem, c ) {
elem.classList.add( c );
};
removeClass = function( elem, c ) {
elem.classList.remove( c );
};
}
else {
hasClass = function( elem, c ) {
return classReg( c ).test( elem.className );
};
addClass = function( elem, c ) {
if ( !hasClass( elem, c ) ) {
elem.className = elem.className + ' ' + c;
}
};
removeClass = function( elem, c ) {
elem.className = elem.className.replace( classReg( c ), ' ' );
};
}
function toggleClass( elem, c ) {
var fn = hasClass( elem, c ) ? removeClass : addClass;
fn( elem, c );
}
var classie = {
// full names
hasClass: hasClass,
addClass: addClass,
removeClass: removeClass,
toggleClass: toggleClass,
// short names
has: hasClass,
add: addClass,
remove: removeClass,
toggle: toggleClass
};
// transport
if ( typeof define === 'function' && define.amd ) {
// AMD
define( classie );
} else {
// browser global
window.classie = classie;
}
})( window );
(function( window ){
var body = document.body,
mask = document.createElement("div"),
togglePushLeft = document.querySelector( ".toggle-push-left" ),
pushMenuLeft = document.querySelector( ".push-menu-left" ),
activeNav
;
mask.className = "mask";
/* push menu left */
togglePushLeft.addEventListener( "click", function(){
classie.add( body, "pml-open" );
document.body.appendChild(mask);
activeNav = "pml-open";
} );
/* hide active menu if mask is clicked */
mask.addEventListener( "click", function(){
classie.remove( body, activeNav );
activeNav = "";
document.body.removeChild(mask);
} );
})( window );
</script>
<?php wp_footer(); ?>
</body>
</html>
Think it has something to do with this bug!
wp-content/themes/ParadiseHotel/st-framework/admin/page-builder/page-builder.php:50 - Undefined variable: ajax_nonce
this variable is set like this
<?php
#-------------------------------------------------------------
# Smooth Theme Framework Version
#-------------------------------------------------------------
function st_framework_version_init(){
$st_framework_version = '1.0';
if(get_option('st_framework_version_init') != $st_framework_version){
update_option('st_framework_version',$st_framework_version);
}
}
add_action('init','st_framework_version_init',10);
#-------------------------------------------------------------
# Define Admin Path and URL
#-------------------------------------------------------------
define('ST_ADMIN_PATH',dirname(__FILE__));
define('ST_ADMIN_URL',ST_URL.'admin');
define('ST_PAGE_TITLE',ST_THEME_NAME.' Settings Page'); // Theme Option Title
define('ST_MENU_TITLE',ST_THEME_NAME); // Theme Option Menu Title
define('ST_PAGE_SLUG','smooththemes'); // Theme Option URL Slug
#-------------------------------------------------------------
# Load the required Framework Files
#-------------------------------------------------------------
// kiểm tra tính hợp lệ của ajax
$current_user = wp_get_current_user();
$ajax_nonce = wp_create_nonce($current_user->ID);
//check_ajax_referer( $current_user->ID, 'ajax_nonce' );
if(is_admin()){
add_action( 'wp_ajax_smooththemes_save_option_action', 'smooththemes_save_option_action' );
function smooththemes_save_option_action() {
$st_default_lang_code = get_bloginfo('language'); // DO NOT REMOVE
if(isset($_POST['save']) && $_POST['save']=='Y'){
$data = array();
foreach( $_POST as $key => $arr ){
if(strpos($key, ST_SETTINGS_OPTION)!==false){
$k = str_replace(ST_SETTINGS_OPTION.'_', '', $key);
$data[$k]= $arr;
}
}
if(st_is_wpml()){
// ICL_LANGUAGE_CODE
// echo var_dump($st_default_lang_code,ICL_LANGUAGE_CODE);
if($st_default_lang_code==ICL_LANGUAGE_CODE || ICL_LANGUAGE_CODE=='' || strpos($st_default_lang_code,ICL_LANGUAGE_CODE)!==false){
// update_option(ST_FRAMEWORK_SETTINGS_OPTION,$_POST[ST_FRAMEWORK_SETTINGS_OPTION]);
update_option(ST_SETTINGS_OPTION,$data);
}
update_option(ST_SETTINGS_OPTION.'_'.ICL_LANGUAGE_CODE, $data);
do_action('st_save_options',$data);
}else{
echo ST_SETTINGS_OPTION;
update_option(ST_SETTINGS_OPTION,$data);
do_action('st_save_options', $data );
}
flush_rewrite_rules();
}
echo 1;
die();
}
// for media
function st_image_attachment_fields_to_edit($form_fields, $post){
$form_fields["st_custom"]["label"] = '';
$form_fields["st_custom"]["input"] = "html";
$image_attributes = wp_get_attachment_image_src( $post->ID ,'medium' ); // returns an array
$form_fields["st_custom"]["html"] = '
<input type="hidden" class="st_attach_btn" data-src = "'.$image_attributes[0].'" post_id ="'.$post->ID.'" >
';
return $form_fields;
}
add_filter("attachment_fields_to_edit", "st_image_attachment_fields_to_edit", null, 99);
//----------------Show image size in mediabox-------------------
function st_insert_custom_image_sizes( $sizes ) {
// get the custom image sizes
global $_wp_additional_image_sizes;
// if there are none, just return the built-in sizes
if ( empty( $_wp_additional_image_sizes ) )
return $sizes;
// add all the custom sizes to the built-in sizes
foreach ( $_wp_additional_image_sizes as $id => $data ) {
// take the size ID (e.g., 'my-name'), replace hyphens with spaces,
// and capitalise the first letter of each word
if ( !isset($sizes[$id]) )
$sizes[$id] = ucfirst( str_replace( '-', ' ', $id ) );
}
return $sizes;
}
add_filter( 'image_size_names_choose', 'st_insert_custom_image_sizes' );
include(ST_ADMIN_PATH.'/editor/editor.php');
include(ST_ADMIN_PATH.'/admin-users.php');
include(ST_ADMIN_PATH.'/admin-functions.php');
include(ST_ADMIN_PATH.'/admin-menu.php');
include(ST_ADMIN_PATH.'/admin-scripts.php');
include(ST_ADMIN_PATH.'/ajax-media.php');
// include(ST_ADMIN_PATH.'/ajax-slidebar-generator.php');
//
if(file_exists(ST_ADMIN_PATH.'/page-builder/page-builder.php')){
include(ST_ADMIN_PATH.'/page-builder/page-builder.php');
}
if(file_exists(ST_ADMIN_PATH.'/review-control/review.php')){
include(ST_ADMIN_PATH.'/review-control/review.php');
}
include(ST_ADMIN_PATH.'/admin-meta-box.php');
include(ST_DIR.'/settings/meta-box-settings.php');
include(ST_ADMIN_PATH.'/admin-post-type.php');
include(ST_ADMIN_DIR.'admin-customize.php');
include(ST_ADMIN_DIR.'post-type-meta/event.php');
include(ST_ADMIN_DIR.'post-type-meta/room.php');
include(ST_ADMIN_DIR.'post-type-meta/gallery.php');
}

Extending WP_List_Table / handling checkbox options in plugin administration

I'm working on a WordPress plugin, and part of that plugin requires extending WP_List_Table and storing any of the items which are checked in that table to an option. I've managed to figure out how to properly setup and display the required table, but how do I handle storing the checked options?
Here's what I've got so far...
class TDBar_List_Table extends WP_List_Table {
// Reference parent constructor
function __construct() {
global $status, $page;
// Set defaults
parent::__construct( array(
'singular' => 'theme',
'plural' => 'themes',
'ajax' => false
));
}
// Set table classes
function get_table_classes() {
return array('widefat', 'wp-list-table', 'themes');
}
// Setup default column
function column_default($item, $column_name) {
switch($column_name) {
case 'Title':
case 'URI':
case'Description':
return $item[$column_name];
default:
return print_r($item, true);
}
}
// Displaying checkboxes!
function column_cb($item) {
return sprintf(
'<input type="checkbox" name="%1$s" id="%2$s" value="checked" />',
//$this->_args['singular'],
$item['Stylesheet'] . '_status',
$item['Stylesheet'] . '_status'
);
}
// Display theme title
function column_title($item) {
return sprintf(
'<strong>%1$s</strong>',
$item['Title']
);
}
// Display theme preview
function column_preview($item) {
if (file_exists(get_theme_root() . '/' . $item['Stylesheet'] . '/screenshot.png')) {
$preview = get_theme_root_uri() . '/' . $item['Stylesheet'] . '/screenshot.png';
} else {
$preview = '';
}
return sprintf(
'<img src="%3$s" style="width: 150px;" />',
$preview,
$item['Title'],
$preview
);
}
// Display theme description
function column_description($item) {
if (isset($item['Version'])) {
$version = 'Version ' . $item['Version'];
if (isset($item['Author']) || isset($item['URI']))
$version .= ' | ';
} else {
$version = '';
}
if (isset($item['Author'])) {
$author = 'By ' . $item['Author'];
if (isset($item['URI']))
$author .= ' | ';
} else {
$author = '';
}
if (isset($item['URI'])) {
$uri = $item['URI'];
} else {
$uri = '';
}
return sprintf(
'<div class="theme-description"><p>%1$s</p></div><div class="second theme-version-author-uri">%2$s%3$s%4$s',
$item['Description'],
$version,
$author,
$uri
);
}
// Setup columns
function get_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => 'Theme',
'preview' => 'Preview',
'description' => 'Description'
);
return $columns;
}
// Make title column sortable
function get_sortable_columns() {
$sortable_columns = array(
'title' => array('Title', true)
);
return $sortable_columns;
}
// Setup bulk actions
function get_bulk_actions() {
$actions = array(
'update' => 'Update'
);
return $actions;
}
// Handle bulk actions
function process_bulk_action() {
// Define our data source
if (defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE == true) {
$themes = get_allowed_themes();
} else {
$themes = get_themes();
}
if ('update' === $this->current_action()) {
foreach ($themes as $theme) {
if ($theme['Stylesheet'] . '_status' == 'checked') {
// Do stuff - here's the problem
}
}
}
}
// Handle data preparation
function prepare_items() {
// How many records per page?
$per_page = 10;
// Define column headers
$columns = $this->get_columns();
$hidden = array();
$sortable = $this->get_sortable_columns();
// Build the array
$this->_column_headers = array($columns, $hidden, $sortable);
// Pass off bulk action
$this->process_bulk_action();
// Define our data source
if (defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE == true) {
$themes = get_allowed_themes();
} else {
$themes = get_themes();
}
// Handle sorting
function usort_reorder($a,$b) {
$orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'Title';
$order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'asc';
$result = strcmp($a[$orderby], $b[$orderby]);
return ($order === 'asc') ? $result : -$result;
}
usort($themes, 'usort_reorder');
//MAIN STUFF HERE
//for ($i = 0; i < count($themes); $i++) {
//}
// Figure out the current page and how many items there are
$current_page = $this->get_pagenum();
$total_items = count($themes);
// Only show the current page
$themes = array_slice($themes,(($current_page-1)*$per_page),$per_page);
// Display sorted data
$this->items = $themes;
// Register pagination options
$this->set_pagination_args( array(
'total_items' => $total_items,
'per_page' => $per_page,
'total_pages' => ceil($total_items/$per_page)
));
}
}
Problem is, I can't get it to save properly. I select the rows I want, hit save and it just resets.
I assume you are talking about the checkboxes in your table listing, so this will be how to process bulk actions.
All you need to do is add two new methods to your class and initialize it in the prepare_items method. I use the code below in one of my plugins to delete or export, but you can just as easily run an update.
/**
* Define our bulk actions
*
* #since 1.2
* #returns array() $actions Bulk actions
*/
function get_bulk_actions() {
$actions = array(
'delete' => __( 'Delete' , 'visual-form-builder'),
'export-all' => __( 'Export All' , 'visual-form-builder'),
'export-selected' => __( 'Export Selected' , 'visual-form-builder')
);
return $actions;
}
/**
* Process our bulk actions
*
* #since 1.2
*/
function process_bulk_action() {
$entry_id = ( is_array( $_REQUEST['entry'] ) ) ? $_REQUEST['entry'] : array( $_REQUEST['entry'] );
if ( 'delete' === $this->current_action() ) {
global $wpdb;
foreach ( $entry_id as $id ) {
$id = absint( $id );
$wpdb->query( "DELETE FROM $this->entries_table_name WHERE entries_id = $id" );
}
}
}
Now, call this method inside prepare_items() like so:
function prepare_items() {
//Do other stuff in here
/* Handle our bulk actions */
$this->process_bulk_action();
}
There's a fantastic helper plugin called Custom List Table Example that makes figuring out the WP_List_Table class much easier.

Resources