| 1 |
<?php |
| 2 |
|
| 3 |
class WINP_SnippetsViewTable extends Wbcr_FactoryViewtables401_Viewtable { |
| 4 |
|
| 5 |
public function configure() |
| 6 |
{ |
| 7 |
/** |
| 8 |
* Columns |
| 9 |
*/ |
| 10 |
|
| 11 |
$this->columns->clear(); |
| 12 |
$this->columns->add('title', __('Snippet title', 'insert-php')); |
| 13 |
$this->columns->add('description', __('Description', 'insert-php')); |
| 14 |
$this->columns->add('where_use', __('Where use?', 'insert-php')); |
| 15 |
$this->columns->add('status', __('Status', 'insert-php')); |
| 16 |
$this->columns->add('actions', __('Actions', 'insert-php')); |
| 17 |
|
| 18 |
/** |
| 19 |
* Scripts & styles |
| 20 |
*/ |
| 21 |
$this->styles->add(WINP_PLUGIN_URL . '/admin/assets/css/list-table.css'); |
| 22 |
|
| 23 |
//$this->scripts->add(OPANDA_BIZPANDA_URL . '/assets/admin/js/item-view.js'); |
| 24 |
//do_action('bizpanda_view_table_register_scripts', $this->scripts, $this->styles); |
| 25 |
|
| 26 |
$this->runActions(); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Column 'Title' |
| 31 |
*/ |
| 32 |
public function columnTitle($post) |
| 33 |
{ |
| 34 |
echo $post->post_title; |
| 35 |
} |
| 36 |
|
| 37 |
public function columnDescription($post) |
| 38 |
{ |
| 39 |
echo WINP_Helper::getMetaOption($post->ID, 'snippet_description'); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Column 'Where_use' |
| 44 |
*/ |
| 45 |
public function columnWhere_use($post) |
| 46 |
{ |
| 47 |
$snippet_scope = WINP_Helper::getMetaOption($post->ID, 'snippet_scope'); |
| 48 |
|
| 49 |
if( $snippet_scope == 'evrywhere' ) { |
| 50 |
echo __('Run everywhere', 'insert-php'); |
| 51 |
} else { |
| 52 |
echo '[wbcr_php_snippet id="' . $post->ID . '"]'; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Column 'Status' |
| 58 |
*/ |
| 59 |
public function columnStatus($post) |
| 60 |
{ |
| 61 |
$is_activate = (int)WINP_Helper::getMetaOption($post->ID, 'snippet_activate', 0); |
| 62 |
$status_class = "wbcr-inp-status-green"; |
| 63 |
|
| 64 |
if( !$is_activate ) { |
| 65 |
$status_class = "wbcr-inp-status-grey"; |
| 66 |
} |
| 67 |
echo '<div class="wbcr-inp-status-marker ' . $status_class . '"></div>'; |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Column 'Actions' |
| 72 |
*/ |
| 73 |
public function columnActions($post) |
| 74 |
{ |
| 75 |
$is_activate = (int)WINP_Helper::getMetaOption($post->ID, 'snippet_activate', 0); |
| 76 |
|
| 77 |
$button_text = __('Activate', 'insert-php'); |
| 78 |
|
| 79 |
if( $is_activate ) { |
| 80 |
$button_text = __('Deactivate', 'insert-php'); |
| 81 |
} |
| 82 |
|
| 83 |
echo '<a href="' . wp_nonce_url(admin_url('edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE . '&post=' . $post->ID . '&action=wbcr_inp_activate_snippet'), 'wbcr_inp_snippert_' . $post->ID . '_action_nonce') . '" class="button"><i class="icon ion-play"></i>' . $button_text . '</a>'; |
| 84 |
} |
| 85 |
|
| 86 |
/* |
| 87 |
* Activate/Deactivate snippet |
| 88 |
*/ |
| 89 |
protected function runActions() |
| 90 |
{ |
| 91 |
if( isset($_GET['post_type']) && $_GET['post_type'] == WINP_SNIPPETS_POST_TYPE ) { |
| 92 |
|
| 93 |
if( isset($_GET['action']) && isset($_GET['post']) && $_GET['action'] == 'wbcr_inp_activate_snippet' ) { |
| 94 |
|
| 95 |
$post_id = (int)$_GET['post']; |
| 96 |
|
| 97 |
if( (isset($_GET['_wpnonce']) && !wp_verify_nonce($_GET['_wpnonce'], 'wbcr_inp_snippert_' . $post_id . '_action_nonce')) || !current_user_can('manage_options') ) { |
| 98 |
wp_die('Permission error. You can not edit this page.'); |
| 99 |
} |
| 100 |
|
| 101 |
$is_activate = (int)WINP_Helper::getMetaOption($post_id, 'snippet_activate', 0); |
| 102 |
|
| 103 |
$status = !$is_activate; |
| 104 |
|
| 105 |
update_post_meta($post_id, $this->plugin->getPrefix() . 'snippet_activate', $status); |
| 106 |
|
| 107 |
$redirect_url = admin_url('edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE); |
| 108 |
$redirect_url = add_query_arg(array('wbcr_inp_snippet_updated' => 1), $redirect_url); |
| 109 |
|
| 110 |
wp_safe_redirect($redirect_url); |
| 111 |
exit; |
| 112 |
} |
| 113 |
} |
| 114 |
} |
| 115 |
} |
| 116 |
|