| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPPIZZA_POSTS Class |
| 4 |
* |
| 5 |
* @package WPPIZZA |
| 6 |
* @subpackage WPPIZZA_POSTS |
| 7 |
* @copyright Copyright (c) 2015, Oliver Bach |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 3.0 |
| 10 |
* |
| 11 |
*/ |
| 12 |
if ( ! defined( 'ABSPATH' ) ) exit;/*Exit if accessed directly*/ |
| 13 |
|
| 14 |
|
| 15 |
/************************************************************************************************************************ |
| 16 |
* |
| 17 |
* |
| 18 |
* WPPIZZA_POSTS filters |
| 19 |
* |
| 20 |
* |
| 21 |
************************************************************************************************************************/ |
| 22 |
class WPPIZZA_POSTS{ |
| 23 |
|
| 24 |
private $class_key = 'menu_items';/*to help consistency throughout class in various places*/ |
| 25 |
private $submenu_caps_title ; |
| 26 |
private $submenu_priority = 0; /* only relevant here for caps */ |
| 27 |
/****************************************************************************************************************** |
| 28 |
* |
| 29 |
* [CONSTRUCTOR] |
| 30 |
* |
| 31 |
* |
| 32 |
* @since 3.0 |
| 33 |
* |
| 34 |
******************************************************************************************************************/ |
| 35 |
function __construct() { |
| 36 |
|
| 37 |
/*titles/labels throughout class*/ |
| 38 |
add_action('init', array( $this, 'init_admin_lables') ); |
| 39 |
|
| 40 |
/*register capabilities for this page*/ |
| 41 |
add_filter('wppizza_filter_define_caps', array( $this, 'wppizza_filter_define_caps'), $this->submenu_priority); |
| 42 |
|
| 43 |
/*metaboxes in single post edit**/ |
| 44 |
/*add metaboxes*/ |
| 45 |
add_action('add_meta_boxes', array( $this, 'wppizza_add_metaboxes') ); |
| 46 |
/*save metaboxes*/ |
| 47 |
add_action('save_post', array( $this, 'wppizza_save_metaboxes'), 10, 2 ); |
| 48 |
|
| 49 |
/**sort menu item column in admin by name**/ |
| 50 |
add_filter('request', array( $this, 'wppizza_items_sort') ); |
| 51 |
|
| 52 |
|
| 53 |
/*add order/prices columns**/ |
| 54 |
add_action('manage_edit-wppizza_columns', array( $this, 'wppizza_new_wppizza_column')); |
| 55 |
add_action('manage_wppizza_posts_custom_column',array( $this, 'wppizza_show_order_column'), 10, 2 ); |
| 56 |
|
| 57 |
/*add thumbnail columns in wppizza post type list**/ |
| 58 |
add_action('manage_wppizza_posts_custom_column', array( $this, 'wppizza_featured_image_column'), 10, 2); |
| 59 |
add_filter('manage_wppizza_posts_columns', array( $this, 'wppizza_add_featured_image_column')); |
| 60 |
|
| 61 |
//add_filter('manage_edit-wppizza_sortable_columns',array( $this, 'wppizza_order_column_register_sortable'));//currently not in use |
| 62 |
|
| 63 |
/*add prices to quickedit*/ |
| 64 |
add_action('quick_edit_custom_box', array( $this, 'wppizza_add_quick_edit'), 10, 2); |
| 65 |
add_action('admin_footer', array( $this, 'wppizza_quick_edit_js')); |
| 66 |
add_filter('post_row_actions', array( $this, 'wppizza_expand_quick_edit_link'), 10, 2); |
| 67 |
add_action('save_post', array( $this, 'wppizza_save_quick_edit_data'), 10, 2); |
| 68 |
|
| 69 |
/*execute some helper functions once to use their return multiple times */ |
| 70 |
add_action('current_screen', array( $this, 'wppizza_add_helpers') ); |
| 71 |
|
| 72 |
/**set admin ajax**/ |
| 73 |
add_action('wp_ajax_wppizza_admin_'.$this->class_key.'_ajax', array($this, 'set_admin_ajax') ); |
| 74 |
|
| 75 |
/** admin ajax **/ |
| 76 |
add_action('wppizza_ajax_admin_'.$this->class_key.'', array( $this, 'admin_ajax')); |
| 77 |
|
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
/****************** |
| 83 |
* @since 3.19.1 |
| 84 |
* [admin ajax include file] |
| 85 |
*******************/ |
| 86 |
public function init_admin_lables(){ |
| 87 |
/*titles/labels throughout class*/ |
| 88 |
$this->submenu_caps_title = apply_filters('wppizza_filter_admin_label_caps_title_'.$this->class_key.'', __('Menu Items','wppizza-admin')); |
| 89 |
} |
| 90 |
|
| 91 |
/****************** |
| 92 |
* @since 3.0 |
| 93 |
* [admin ajax include file] |
| 94 |
*******************/ |
| 95 |
public function set_admin_ajax(){ |
| 96 |
require(WPPIZZA_PATH.'ajax/admin.ajax.wppizza.php'); |
| 97 |
die(); |
| 98 |
} |
| 99 |
|
| 100 |
/********************************************************* |
| 101 |
* |
| 102 |
* [add helpers] |
| 103 |
* @since 3.0 |
| 104 |
* |
| 105 |
* run on this page only or if saving this page |
| 106 |
($_POST[WPPIZZA_SLUG.'_'.$this->class_key]) |
| 107 |
*********************************************************/ |
| 108 |
function wppizza_add_helpers($current_screen){ |
| 109 |
if( !empty($_POST[WPPIZZA_SLUG.'_'.$this->class_key]) || ($current_screen->id == WPPIZZA_POST_TYPE && $current_screen->post_type == WPPIZZA_POST_TYPE)){ |
| 110 |
/***enqueue scripts and styles***/ |
| 111 |
add_action('admin_enqueue_scripts', array( $this, 'wppizza_enqueue_admin_scripts_and_styles')); |
| 112 |
} |
| 113 |
} |
| 114 |
/********************************************************* |
| 115 |
* |
| 116 |
* [class helpers] |
| 117 |
* @since 3.0 |
| 118 |
* |
| 119 |
*********************************************************/ |
| 120 |
public function wppizza_enqueue_admin_scripts_and_styles($hook) { |
| 121 |
|
| 122 |
/************ |
| 123 |
css |
| 124 |
***********/ |
| 125 |
/** chosen - currently unused on page **/ |
| 126 |
//wp_register_style(WPPIZZA_SLUG.'-chosen', plugins_url( 'css/wppizza-chosen.min.css', WPPIZZA_PLUGIN_PATH ), array(), WPPIZZA_VERSION); |
| 127 |
//wp_enqueue_style(WPPIZZA_SLUG.'-chosen'); |
| 128 |
|
| 129 |
|
| 130 |
/************ |
| 131 |
js |
| 132 |
***********/ |
| 133 |
|
| 134 |
/** chosen - currently unused on page **/ |
| 135 |
//wp_register_script(WPPIZZA_SLUG.'-chosen', plugins_url( 'js/chosen.jquery.min.js', WPPIZZA_PLUGIN_PATH ), array('jquery'), WPPIZZA_VERSION ,true); |
| 136 |
//wp_enqueue_script(WPPIZZA_SLUG.'-chosen'); |
| 137 |
|
| 138 |
wp_register_script(WPPIZZA_SLUG.'_'.$this->class_key.'', plugins_url( 'js/scripts.admin.'.$this->class_key.'.js', WPPIZZA_PLUGIN_PATH ), array('jquery'), WPPIZZA_VERSION ,true); |
| 139 |
wp_enqueue_script(WPPIZZA_SLUG.'_'.$this->class_key.''); |
| 140 |
} |
| 141 |
/******************************************************************************************************************************************************* |
| 142 |
* |
| 143 |
* [admin ajax] |
| 144 |
* |
| 145 |
********************************************************************************************************************************************************/ |
| 146 |
function admin_ajax($wppizza_options){ |
| 147 |
/****************************************************** |
| 148 |
[prize tier selection has been changed->add relevant price options input fields] |
| 149 |
******************************************************/ |
| 150 |
if($_POST['vars']['field']=='sizeschanged' && $_POST['vars']['id']!='' && isset($_POST['vars']['inpname']) && $_POST['vars']['inpname'] != '' ){ |
| 151 |
|
| 152 |
$set_size_id=(int)$_POST['vars']['id']; |
| 153 |
/**sizes**/ |
| 154 |
$sizes=''; |
| 155 |
if(is_array($wppizza_options['sizes'][$set_size_id])){ |
| 156 |
|
| 157 |
foreach($wppizza_options['sizes'][$set_size_id] as $a => $b){ |
| 158 |
/* |
| 159 |
if we use this function in 3rd party plugins (e.g if the name != WPPIZZA_SLUG) |
| 160 |
to output wppizza price tiers on a page, omit preset prices |
| 161 |
*/ |
| 162 |
//sanitise |
| 163 |
$inpNameIdent = wppizza_sanitize_input_name($_POST['vars']['inpname']); |
| 164 |
//omit prices |
| 165 |
$price = $inpNameIdent == WPPIZZA_SLUG ? wppizza_output_format_price($b['price']) : '' ; |
| 166 |
|
| 167 |
$sizes.="<input name='".$inpNameIdent."[prices][]' type='text' size='5' value='".$price."' />"; |
| 168 |
|
| 169 |
} |
| 170 |
} |
| 171 |
$obj['inp']['sizes']=$sizes; |
| 172 |
$obj['element']['sizes']='.'.WPPIZZA_SLUG.'_pricetiers';/**html element (by class name) to empty and replace with new input boxes**/ |
| 173 |
|
| 174 |
|
| 175 |
/**allow other meta boxes to hook into this*/ |
| 176 |
$obj=apply_filters('wppizza_ajax_action_admin_sizeschanged', $obj, $set_size_id); |
| 177 |
|
| 178 |
print"".json_encode($obj).""; |
| 179 |
exit(); |
| 180 |
} |
| 181 |
|
| 182 |
} |
| 183 |
/***************************************************** |
| 184 |
[sort admin column by title] |
| 185 |
*****************************************************/ |
| 186 |
function wppizza_items_sort( $request ) { |
| 187 |
if(isset ($request['post_type']) && $request['post_type']==''.WPPIZZA_POST_TYPE.''){ |
| 188 |
if ( !isset( $request['orderby'] ) || ( isset( $request['orderby'] ) && $request['orderby']=='title' ) ) { |
| 189 |
$request = array_merge( $request, array('orderby' => 'title')); |
| 190 |
} |
| 191 |
if ( !isset( $request['order'] )) { |
| 192 |
$request = array_merge( $request, array('order' => 'asc')); |
| 193 |
} |
| 194 |
} |
| 195 |
return $request; |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
/********************************************************* |
| 200 |
* |
| 201 |
* [add metabox container for classes to add to] |
| 202 |
* |
| 203 |
*********************************************************/ |
| 204 |
function wppizza_add_metaboxes() { |
| 205 |
add_meta_box( WPPIZZA_SLUG, WPPIZZA_NAME.' '.__('Options', 'wppizza-admin'), array($this, 'wppizza_render_metaboxes'), WPPIZZA_SLUG, 'normal', 'high'); |
| 206 |
} |
| 207 |
|
| 208 |
function wppizza_render_metaboxes( $meta_options ) { |
| 209 |
|
| 210 |
global $wppizza_options; |
| 211 |
/** |
| 212 |
add some parameters we probably want to use in metaboxes. |
| 213 |
add here to pass on to filter and not have to run it multiple times |
| 214 |
**/ |
| 215 |
/*meta data for menu item*/ |
| 216 |
$meta_values = get_post_meta($meta_options->ID, WPPIZZA_SLUG); |
| 217 |
|
| 218 |
/* set default for new items from sizes id 0 */ |
| 219 |
if(empty($meta_values)){ |
| 220 |
$default = array(); |
| 221 |
$default[0] = array(); |
| 222 |
$default[0]['item_tax_alt'] = false; |
| 223 |
$default[0]['sizes'] = 0; |
| 224 |
$default[0]['prices'] = array(); |
| 225 |
foreach($wppizza_options['sizes'][0] as $k=>$default_price){ |
| 226 |
$default[0]['prices'][$k] = $default_price['price']; |
| 227 |
} |
| 228 |
$default[0]['additives'] = array(); |
| 229 |
|
| 230 |
$meta_values = $default; |
| 231 |
} |
| 232 |
|
| 233 |
$meta_values = $meta_values[0]; |
| 234 |
/*available sizes*/ |
| 235 |
$wppizza_sizes = wppizza_sizes_available(true); |
| 236 |
|
| 237 |
/**add filter**/ |
| 238 |
$wppizza_meta_box=array(); |
| 239 |
$wppizza_meta_box=apply_filters('wppizza_filter_admin_metaboxes', $wppizza_meta_box, $meta_values, $wppizza_sizes, $wppizza_options); |
| 240 |
|
| 241 |
/** implode for output **/ |
| 242 |
$output=implode('',$wppizza_meta_box); |
| 243 |
/** add nonce **/ |
| 244 |
$output .= ''.wp_nonce_field( '' . WPPIZZA_PREFIX . '_ajax_nonce','' . WPPIZZA_PREFIX . '_ajax_nonce',true,false).''; |
| 245 |
print"".$output; |
| 246 |
} |
| 247 |
|
| 248 |
function wppizza_save_metaboxes($item_id, $item_details ) { |
| 249 |
|
| 250 |
/*** |
| 251 |
bypass, when doing "quickedit" (ajax) and /or "bulk edit" as it will otherwsie loose all meta info (i.e prices, additives etc)!!! |
| 252 |
***/ |
| 253 |
if ( defined('DOING_AJAX') || isset($_GET['bulk_edit'])){ |
| 254 |
return; |
| 255 |
} |
| 256 |
|
| 257 |
/* check for nonce, which will also bypass this on install */ |
| 258 |
$nonce = '' . WPPIZZA_PREFIX . '_ajax_nonce'; |
| 259 |
if (! isset( $_POST[$nonce] ) || !wp_verify_nonce( $_POST[$nonce] , $nonce ) ) { |
| 260 |
return; |
| 261 |
} |
| 262 |
|
| 263 |
// Check post type too |
| 264 |
if(!isset($item_details->post_type) || $item_details->post_type != WPPIZZA_POST_TYPE ){ |
| 265 |
return; |
| 266 |
} |
| 267 |
|
| 268 |
global $wppizza_options; |
| 269 |
/**add filter we can hook into from other pages to add meta data**/ |
| 270 |
$itemMeta = apply_filters('wppizza_filter_admin_save_metaboxes', $itemMeta = array(), $item_id, $wppizza_options); |
| 271 |
update_post_meta($item_id, WPPIZZA_POST_TYPE, $itemMeta); |
| 272 |
} |
| 273 |
|
| 274 |
/******************************************************* |
| 275 |
[show order column in wppizza list of post items table] |
| 276 |
******************************************************/ |
| 277 |
function wppizza_new_wppizza_column($header_text_columns) { |
| 278 |
$header_text_columns['wppizza-prices'] = __('Prices', 'wppizza-admin'); |
| 279 |
return $header_text_columns; |
| 280 |
} |
| 281 |
/** |
| 282 |
* show custom order column values |
| 283 |
*/ |
| 284 |
function wppizza_show_order_column($name, $id){ |
| 285 |
|
| 286 |
switch($name){ |
| 287 |
|
| 288 |
//ignore for now |
| 289 |
//case 'wppizza-menu_order': |
| 290 |
// $order = $post->menu_order; |
| 291 |
// echo $order; |
| 292 |
//break; |
| 293 |
|
| 294 |
case 'wppizza-prices': |
| 295 |
global $wppizza_options; |
| 296 |
$meta=get_post_meta($id, WPPIZZA_POST_TYPE, true ); |
| 297 |
$sizes= ( isset($meta['sizes']) && !empty($wppizza_options['sizes'][$meta['sizes']]) ) ? $wppizza_options['sizes'][$meta['sizes']] : array(); |
| 298 |
$str=''; |
| 299 |
if(is_array($sizes)){ |
| 300 |
/*do not use tables here or bulk edit won't work - no , dunno either why*/ |
| 301 |
$str.='<div class="wppizza-prices-column">'; |
| 302 |
foreach($sizes as $k=>$s){ |
| 303 |
$str.='<span>'.$s['lbl'].'<br />'.wppizza_output_format_price($meta['prices'][$k]).'</span>'; |
| 304 |
} |
| 305 |
$str.='</div>'; |
| 306 |
} |
| 307 |
echo $str; |
| 308 |
break; |
| 309 |
default: |
| 310 |
break; |
| 311 |
} |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
/** |
| 317 |
* show featured images column |
| 318 |
* since 3.10 |
| 319 |
*/ |
| 320 |
function wppizza_featured_image_column($column_name, $post_id){ |
| 321 |
if ($column_name == 'featured_image') { |
| 322 |
$tn = get_the_post_thumbnail($post_id, 'thumbnail'); |
| 323 |
if(empty($tn)){ |
| 324 |
echo '<div class="'.WPPIZZA_POST_TYPE.'-article-image-placeholder"></div>'; |
| 325 |
}else{ |
| 326 |
echo get_the_post_thumbnail($post_id, 'thumbnail'); |
| 327 |
} |
| 328 |
} |
| 329 |
} |
| 330 |
/** |
| 331 |
* show featured images column |
| 332 |
* since 3.10 |
| 333 |
*/ |
| 334 |
function wppizza_add_featured_image_column($defaults) { |
| 335 |
$i = 1; |
| 336 |
$columns = array(); |
| 337 |
foreach( $defaults as $key => $value ) { |
| 338 |
$columns[$key] = $value; |
| 339 |
if ( 1 == $i++ ) { |
| 340 |
$columns['featured_image'] = __('Image', 'default' ); |
| 341 |
} |
| 342 |
} |
| 343 |
return $columns; |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
/** |
| 350 |
* make column sortable / not in use / ignored |
| 351 |
* ignore for now |
| 352 |
*/ |
| 353 |
//function wppizza_order_column_register_sortable($columns){ |
| 354 |
//$columns['wppizza-menu_order'] = 'menu_order'; |
| 355 |
//$columns['prices'] = 'prices'; |
| 356 |
//return $columns; |
| 357 |
//} |
| 358 |
|
| 359 |
/***************************************************** |
| 360 |
* |
| 361 |
* [quickedit prices] |
| 362 |
* |
| 363 |
*****************************************************/ |
| 364 |
/*add element to quickedit*/ |
| 365 |
function wppizza_add_quick_edit($column, $post_type) { |
| 366 |
if ($column != 'wppizza-prices' || $post_type!=WPPIZZA_POST_TYPE ){ return;} |
| 367 |
|
| 368 |
echo'<fieldset class="inline-edit-col-right inline-edit-wppizza-prices" style="width:auto;border:1px dotted #cecece;margin:5px">'; |
| 369 |
echo'<div class="inline-edit-col column-'.$column.'">'; |
| 370 |
echo'<div style="font-weight:600;text-align:center;text-decoration:underline">'.__('Item Price(s)', 'wppizza-admin').'</div>'; |
| 371 |
echo'<div id="wppizza_quickedit_prices"></div>'; |
| 372 |
echo'</div>'; |
| 373 |
echo'</fieldset>'; |
| 374 |
|
| 375 |
} |
| 376 |
/*set js to insert values*/ |
| 377 |
function wppizza_quick_edit_js() { |
| 378 |
global $current_screen; |
| 379 |
if (($current_screen->post_type != WPPIZZA_POST_TYPE) || $current_screen->parent_base!='edit') {return;} |
| 380 |
echo'<script type="text/javascript">'.PHP_EOL; |
| 381 |
echo'function wppizza_set_prices(sizes, prices, labels, meta, nonce) {'.PHP_EOL; |
| 382 |
|
| 383 |
// refresh the quick menu properly |
| 384 |
echo'inlineEditPost.revert();'.PHP_EOL; |
| 385 |
echo'var itemSizes= sizes.split(":");'.PHP_EOL; |
| 386 |
echo'var itemPrices= prices.split(":");'.PHP_EOL; |
| 387 |
echo'var itemLabels= labels.split(":");'.PHP_EOL; |
| 388 |
|
| 389 |
echo'var doInputs="<div class=\'wppizza-prices-column\'>";'.PHP_EOL; |
| 390 |
echo'for(var i=0;i<itemSizes.length;i++){'.PHP_EOL; |
| 391 |
echo'doInputs+=\'<span>\'+itemLabels[i]+\'<br /><input type="text" name="wppizza[prices][\'+itemSizes[i]+\']" size="5" value="\'+itemPrices[i]+\'" /></span>\';'.PHP_EOL; |
| 392 |
echo'}'; |
| 393 |
|
| 394 |
echo'doInputs+="</div>";'.PHP_EOL; |
| 395 |
|
| 396 |
/* |
| 397 |
allow for other plugins to hook into displaying |
| 398 |
some other form fields or somtheing by simply doing |
| 399 |
echo'doInputs+="my addon";'.PHP_EOL; |
| 400 |
or somethig |
| 401 |
*/ |
| 402 |
do_action('wppizza_filter_quick_edit_js' ); |
| 403 |
|
| 404 |
echo'jQuery("#wppizza_quickedit_prices").html(doInputs);'.PHP_EOL; |
| 405 |
echo'}'.PHP_EOL; |
| 406 |
echo'</script>'.PHP_EOL; |
| 407 |
} |
| 408 |
|
| 409 |
function wppizza_expand_quick_edit_link($actions, $post) { |
| 410 |
global $wppizza_options; |
| 411 |
|
| 412 |
/* not wppizza post type , skip */ |
| 413 |
if ($post->post_type != WPPIZZA_POST_TYPE) {return $actions;} |
| 414 |
|
| 415 |
/* can this user edit the post ? if not, skip */ |
| 416 |
$can_edit_post = current_user_can( 'edit_post', $post->ID ); |
| 417 |
if ( !$can_edit_post || 'trash' == $post->post_status ) {return $actions;} |
| 418 |
|
| 419 |
/*do we need this ?*/ |
| 420 |
//$nonce = wp_create_nonce( 'wppizza_'.$post->ID); |
| 421 |
|
| 422 |
$getMeta=get_post_meta($post->ID, WPPIZZA_POST_TYPE, true ); |
| 423 |
$getSizes = ( isset($getMeta['sizes']) && !empty($wppizza_options['sizes'][$getMeta['sizes']]) ) ? $wppizza_options['sizes'][$getMeta['sizes']] : array() ; |
| 424 |
|
| 425 |
|
| 426 |
/* add other meta data as required to js function as json */ |
| 427 |
$meta = array(); |
| 428 |
$meta = apply_filters('wppizza_filter_expand_quick_edit_link_meta', $meta, $getMeta); |
| 429 |
$meta = json_encode($meta, JSON_FORCE_OBJECT); |
| 430 |
|
| 431 |
|
| 432 |
$sizes=array(); |
| 433 |
$prices=array(); |
| 434 |
$labels=array(); |
| 435 |
foreach($getSizes as $k=>$s){ |
| 436 |
$sizes[$k]=$k; |
| 437 |
$prices[$k]=wppizza_output_format_price($getMeta['prices'][$k]); |
| 438 |
$labels[$k]=$s['lbl']; |
| 439 |
} |
| 440 |
$jsSizes=implode(':',$sizes); |
| 441 |
$jsPrices=implode(':',$prices); |
| 442 |
$jsLabels=implode(':',$labels); |
| 443 |
|
| 444 |
/**hijack quick edit link*/ |
| 445 |
$actions['inline hide-if-no-js'] = '<a href="javascript:void(0)" class="editinline" title="'; |
| 446 |
$actions['inline hide-if-no-js'] .= esc_attr( __( 'Edit this item inline', 'default' ) ) . '"'; |
| 447 |
$actions['inline hide-if-no-js'] .= " onclick='"; |
| 448 |
/* filterable js functions for quickedit link, |
| 449 |
use htmlentities entities, in case there are some undesireable chars |
| 450 |
(especially in price lables , like quotes or apostrophies or something) |
| 451 |
*/ |
| 452 |
$actions['inline hide-if-no-js'] .= htmlentities(apply_filters('wppizza_filter_quick_edit_link_functions', "wppizza_set_prices(\"".$jsSizes."\",\"".$jsPrices."\",\"".$jsLabels."\",".$meta.");", $getMeta, $meta, $post->ID)); |
| 453 |
$actions['inline hide-if-no-js'] .= "' >"; |
| 454 |
$actions['inline hide-if-no-js'] .= __( 'Quick Edit', 'default' ); |
| 455 |
$actions['inline hide-if-no-js'] .= '</a>'; |
| 456 |
|
| 457 |
/**add id before [edit] link */ |
| 458 |
$actions['edit'] = 'ID: '.$post->ID.' | ' . $actions['edit']; |
| 459 |
|
| 460 |
|
| 461 |
return $actions; |
| 462 |
} |
| 463 |
|
| 464 |
function wppizza_save_quick_edit_data($post_id, $post){ |
| 465 |
// verify if this is an auto save routine. |
| 466 |
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {return $post_id;} |
| 467 |
|
| 468 |
//only run on inline (quickedit) save |
| 469 |
if ( !isset($_POST['action']) || $_POST['action'] != 'inline-save' ) {return $post_id;} |
| 470 |
|
| 471 |
// Check permissions |
| 472 |
if ( isset($_POST['post_type']) && WPPIZZA_POST_TYPE == $_POST['post_type'] ) { |
| 473 |
if ( !current_user_can( 'edit_page', $post_id ) ) |
| 474 |
return $post_id; |
| 475 |
} else { |
| 476 |
if ( !current_user_can( 'edit_post', $post_id ) ) |
| 477 |
return $post_id; |
| 478 |
} |
| 479 |
// Authentication passed now we save the data |
| 480 |
if (!empty($_POST[WPPIZZA_SLUG]['prices']) && is_array($_POST[WPPIZZA_SLUG]['prices']) && ($post->post_type != 'revision')) { |
| 481 |
|
| 482 |
/**current meta*/ |
| 483 |
$metaValues=get_post_meta($post_id, WPPIZZA_POST_TYPE, true ); |
| 484 |
|
| 485 |
/**get new prices*/ |
| 486 |
$metaValues['prices']=array(); |
| 487 |
foreach($_POST[WPPIZZA_SLUG]['prices'] as $k=>$price){ |
| 488 |
$metaValues['prices'][$k]=wppizza_validate_float_only($price,2);; |
| 489 |
} |
| 490 |
/* allow for other meta data to be saved too */ |
| 491 |
$metaValues = apply_filters('wppizza_filter_save_quick_edit_data', $metaValues, $post_id, $post ); |
| 492 |
|
| 493 |
update_post_meta($post_id, WPPIZZA_POST_TYPE, $metaValues); |
| 494 |
|
| 495 |
/* add action after meta was updated */ |
| 496 |
do_action('wppizza_after_update_meta_data', $post_id, $metaValues); |
| 497 |
|
| 498 |
return $metaValues['prices']; |
| 499 |
} |
| 500 |
return ; |
| 501 |
} |
| 502 |
|
| 503 |
/********************************************************* |
| 504 |
* |
| 505 |
* [define caps] |
| 506 |
* @since 3.0 |
| 507 |
* |
| 508 |
*********************************************************/ |
| 509 |
function wppizza_filter_define_caps($caps){ |
| 510 |
/**add editing capability for this posts**/ |
| 511 |
$caps[$this->class_key] = array(); |
| 512 |
$caps[$this->class_key]['name'] = $this->submenu_caps_title; |
| 513 |
$caps[$this->class_key]['cap'] = ''.WPPIZZA_SLUG.'_cap_'.$this->class_key.''; |
| 514 |
/* |
| 515 |
using one checkbox for multiple capabilities |
| 516 |
these will be set on install and update of plugin |
| 517 |
for all users with manage_options capabilities |
| 518 |
*/ |
| 519 |
$caps[$this->class_key]['multi_caps'] = array(); |
| 520 |
$caps[$this->class_key]['multi_caps']['read_post'] = 'read_'.WPPIZZA_SLUG.''; |
| 521 |
$caps[$this->class_key]['multi_caps']['read_private_post'] = 'read_private_'.WPPIZZA_SLUG.'s'; |
| 522 |
$caps[$this->class_key]['multi_caps']['edit_post'] = 'edit_'.WPPIZZA_SLUG.''; |
| 523 |
$caps[$this->class_key]['multi_caps']['edit_posts'] = 'edit_'.WPPIZZA_SLUG.'s'; |
| 524 |
$caps[$this->class_key]['multi_caps']['edit_others_posts'] = 'edit_others_'.WPPIZZA_SLUG.'s';//should this only be done for admins and editors at some point perhaps ? |
| 525 |
$caps[$this->class_key]['multi_caps']['edit_published_posts'] = 'edit_published_'.WPPIZZA_SLUG.'s'; |
| 526 |
$caps[$this->class_key]['multi_caps']['delete_post'] = 'delete_'.WPPIZZA_SLUG.''; |
| 527 |
$caps[$this->class_key]['multi_caps']['delete_posts'] = 'delete_'.WPPIZZA_SLUG.'s'; |
| 528 |
$caps[$this->class_key]['multi_caps']['delete_others_posts'] = 'delete_others_'.WPPIZZA_SLUG.'s'; |
| 529 |
$caps[$this->class_key]['multi_caps']['delete_published_posts'] = 'delete_published_'.WPPIZZA_SLUG.'s'; |
| 530 |
$caps[$this->class_key]['multi_caps']['publish_posts'] = 'publish_'.WPPIZZA_SLUG.'s'; |
| 531 |
|
| 532 |
|
| 533 |
/* other options , dont think these are necessary but leave them here for reference */ |
| 534 |
//$caps[$this->class_key]['multi_caps']['delete_private_posts'] = 'delete_private_'.WPPIZZA_SLUG.'s'; |
| 535 |
|
| 536 |
|
| 537 |
$caps[$this->class_key]['multi_caps'] = apply_filters('wppizza_filter_post_caps', $caps[$this->class_key]['multi_caps'] ); |
| 538 |
|
| 539 |
// let's not enable/list this option for now....probably not required anyway as one should also delete/reassign orders to someone else ... |
| 540 |
//$caps[$this->class_key.'-delete-customers']=array('name'=>__('Delete Customers', 'wppizza-admin') ,'cap'=>'wppizza_cap_delete_customers'); |
| 541 |
return $caps; |
| 542 |
} |
| 543 |
/********************************************************* |
| 544 |
* |
| 545 |
* [set required capability for this page] |
| 546 |
* @since 3.0 |
| 547 |
* |
| 548 |
*********************************************************/ |
| 549 |
function admin_option_page_capability($capability) { |
| 550 |
$capability = 'wppizza_cap_'.$this->class_key.''; |
| 551 |
return $capability; |
| 552 |
} |
| 553 |
} |
| 554 |
/*************************************************************** |
| 555 |
* |
| 556 |
* [ini] |
| 557 |
* |
| 558 |
***************************************************************/ |
| 559 |
$WPPIZZA_POSTS = new WPPIZZA_POSTS(); |
| 560 |
?> |