PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.3.1
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.3.1
2.7.7 2.7.6 2.7.5 2.7.4 trunk 1.3 2.0.4 2.0.6 2.1.91 2.2.4 2.2.7 2.2.9 2.3.1 2.3.10 2.4.10 2.4.2 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.6.0 2.6.1 2.7.0 All 28 releases
insert-php / admin / includes / class.snippets.viewtable.php

class.snippets.viewtable.php in Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts 2.3.1, at admin/includes/class.snippets.viewtable.php

181 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Exit if accessed directly
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 class WINP_SnippetsViewTable extends Wbcr_FactoryViewtables410_Viewtable {
9
10 public function configure() {
11 /**
12 * Columns
13 */
14 $this->columns->clear();
15 //$this->columns->add('status', __('Status', 'insert-php'));
16 $this->columns->add( 'title', __( 'Snippet title', 'insert-php' ) );
17 $this->columns->add( 'winp_description', __( 'Description', 'insert-php' ) );
18 $this->columns->add( 'winp_actions', __( 'Status', 'insert-php' ) );
19 $this->columns->add( 'winp_where_use', __( 'Where use?', 'insert-php' ) );
20 $this->columns->add( 'winp_taxonomy-' . WINP_SNIPPETS_TAXONOMY, __( 'Tags', 'insert-php' ) );
21 $this->columns->add( 'winp_snippet_type', '' );
22
23 /**
24 * Scripts & styles
25 */
26 $this->styles->add( WINP_PLUGIN_URL . '/admin/assets/css/list-table.css' );
27 $this->runActions();
28 }
29
30
31 /**
32 * Column 'Type'
33 *
34 * @param $post
35 */
36 public function columnWinp_snippet_type( $post ) {
37 $type = WINP_Helper::getMetaOption( $post->ID, 'snippet_type', WINP_SNIPPET_TYPE_PHP );
38 $class = 'wbcr-inp-type-' . esc_attr( $type );
39 $type = $type == 'universal' ? 'uni' : $type;
40
41 echo '<div class="wbcr-inp-snippet-type-label ' . esc_attr( $class ) . '">' . esc_html( $type ) . '</div>';
42 }
43
44 public function columnWinp_description( $post ) {
45 echo esc_html( WINP_Helper::getMetaOption( $post->ID, 'snippet_description' ) );
46 }
47
48 /**
49 * Column 'Where_use'
50 *
51 * @param $post
52 */
53 public function columnWinp_where_use( $post ) {
54 $snippet_scope = WINP_Helper::getMetaOption( $post->ID, 'snippet_scope' );
55
56 if ( $snippet_scope == 'evrywhere' ) {
57 echo __( 'Run everywhere', 'insert-php' );
58 } else if ( $snippet_scope == 'auto' ) {
59 $items = [
60 WINP_SNIPPET_AUTO_HEADER => __( 'Header', 'insert-php' ),
61 WINP_SNIPPET_AUTO_FOOTER => __( 'Footer', 'insert-php' ),
62 WINP_SNIPPET_AUTO_BEFORE_POST => __( 'Insert Before Post', 'insert-php' ),
63 WINP_SNIPPET_AUTO_BEFORE_CONTENT => __( 'Insert Before Content', 'insert-php' ),
64 WINP_SNIPPET_AUTO_BEFORE_PARAGRAPH => __( 'Insert Before Paragraph', 'insert-php' ),
65 WINP_SNIPPET_AUTO_AFTER_PARAGRAPH => __( 'Insert After Paragraph', 'insert-php' ),
66 WINP_SNIPPET_AUTO_AFTER_CONTENT => __( 'Insert After Content', 'insert-php' ),
67 WINP_SNIPPET_AUTO_AFTER_POST => __( 'Insert After Post', 'insert-php' ),
68 WINP_SNIPPET_AUTO_BEFORE_EXCERPT => __( 'Insert Before Excerpt', 'insert-php' ),
69 WINP_SNIPPET_AUTO_AFTER_EXCERPT => __( 'Insert After Excerpt', 'insert-php' ),
70 WINP_SNIPPET_AUTO_BETWEEN_POSTS => __( 'Between Posts', 'insert-php' ),
71 WINP_SNIPPET_AUTO_BEFORE_POSTS => __( 'Before post', 'insert-php' ),
72 WINP_SNIPPET_AUTO_AFTER_POSTS => __( 'After post', 'insert-php' ),
73 ];
74
75 $snippet_location = WINP_Helper::getMetaOption( $post->ID, 'snippet_location', '' );
76
77 switch ( $snippet_location ) {
78 case WINP_SNIPPET_AUTO_HEADER:
79 case WINP_SNIPPET_AUTO_FOOTER:
80 $text = __( 'Everywhere', 'insert-php' ) . '[' . $items[ $snippet_location ] . ']';
81 break;
82
83 case WINP_SNIPPET_AUTO_BEFORE_POST:
84 case WINP_SNIPPET_AUTO_BEFORE_CONTENT:
85 case WINP_SNIPPET_AUTO_BEFORE_PARAGRAPH:
86 case WINP_SNIPPET_AUTO_AFTER_PARAGRAPH:
87 case WINP_SNIPPET_AUTO_AFTER_CONTENT:
88 case WINP_SNIPPET_AUTO_AFTER_POST:
89 $text = __( 'Posts, Pages, Custom post types', 'insert-php' ) . '[' . $items[ $snippet_location ] . ']';
90 break;
91
92 case WINP_SNIPPET_AUTO_BEFORE_EXCERPT:
93 case WINP_SNIPPET_AUTO_AFTER_EXCERPT:
94 case WINP_SNIPPET_AUTO_BETWEEN_POSTS:
95 case WINP_SNIPPET_AUTO_BEFORE_POSTS:
96 case WINP_SNIPPET_AUTO_AFTER_POSTS:
97 $text = __( 'Categories, Archives, Tags, Taxonomies', 'insert-php' ) . '[' . $items[ $snippet_location ] . ']';
98 break;
99
100 default:
101 $text = __( 'Everywhere', 'insert-php' );
102 }
103
104 echo __( 'Automatic insertion', 'insert-php' ) . ': ' . esc_html( $text );
105 } else {
106 $snippet_type = WINP_Helper::get_snippet_type( $post->ID );
107 $snippet_type = ( $snippet_type == WINP_SNIPPET_TYPE_UNIVERSAL ? '' : $snippet_type . '_' );
108
109 echo esc_html( apply_filters( 'wbcr/inp/viewtable/where_use', '[wbcr_' . $snippet_type . 'snippet id="' . $post->ID . '"]', $post->ID ) );
110 }
111 }
112
113 /**
114 * Column 'Actions'
115 *
116 * @param $post
117 */
118 public function columnWinp_actions( $post ) {
119 $post_id = (int) $post->ID;
120 $is_activate = (int) WINP_Helper::getMetaOption( $post_id, 'snippet_activate', 0 );
121 $icon = 'dashicons-controls-play';
122
123 if ( $is_activate ) {
124 $icon = 'dashicons-controls-pause';
125 }
126
127 echo '<a class="wbcr-inp-enable-snippet-button button" href="' . wp_nonce_url( admin_url( 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE . '&amp;post=' . $post_id . '&amp;action=wbcr_inp_activate_snippet' ), 'wbcr_inp_snippert_' . $post_id . '_action_nonce' ) . '"><span class="dashicons ' . esc_attr( $icon ) . '"></span></a>';
128 }
129
130 /*
131 * Activate/Deactivate snippet
132 */
133 protected function runActions() {
134 if ( WINP_Plugin::app()->request->get( 'post_type', '', true ) == WINP_SNIPPETS_POST_TYPE ) {
135 $post = WINP_Plugin::app()->request->get( 'post', 0 );
136 $action = WINP_Plugin::app()->request->get( 'action', '', 'sanitize_key' );
137
138 if ( ! empty( $action ) && ! empty( $post ) && 'wbcr_inp_activate_snippet' == $action ) {
139 $post_id = (int) $post;
140 $wpnonce = WINP_Plugin::app()->request->get( '_wpnonce', '' );
141
142 if ( ( ! empty( $wpnonce ) && ! wp_verify_nonce( $wpnonce, 'wbcr_inp_snippert_' . $post_id . '_action_nonce' ) ) || ! WINP_Plugin::app()->currentUserCan() ) {
143 wp_die( 'Permission error. You can not edit this page.' );
144 }
145
146 $is_activate = (int) WINP_Helper::getMetaOption( $post_id, 'snippet_activate', 0 );
147 $snippet_scope = WINP_Helper::getMetaOption( $post_id, 'snippet_scope' );
148 $snippet_type = WINP_Helper::get_snippet_type( $post_id );
149
150 /**
151 * Prevent activation of the snippet if it contains an error. This will not allow the user to break his site.
152 *
153 * @since 2.0.5
154 */
155 if ( ( 'evrywhere' == $snippet_scope || 'auto' == $snippet_scope ) && $snippet_type != WINP_SNIPPET_TYPE_TEXT && $snippet_type != WINP_SNIPPET_TYPE_CSS && $snippet_type != WINP_SNIPPET_TYPE_JS && ! $is_activate ) {
156 if ( WINP_Plugin::app()->getExecuteObject()->getSnippetError( $post_id ) ) {
157 wp_safe_redirect( add_query_arg( [
158 'action' => 'edit',
159 'post' => $post_id,
160 'wbcr_inp_save_snippet_result' => 'code-error',
161 ], admin_url( 'post.php' ) ) );
162 exit;
163 }
164 }
165
166 $status = ! $is_activate;
167
168 update_post_meta( $post_id, $this->plugin->getPrefix() . 'snippet_activate', $status );
169
170 $redirect_url = add_query_arg( [
171 'post_type' => WINP_SNIPPETS_POST_TYPE,
172 'wbcr_inp_snippet_updated' => 1,
173 ], admin_url( 'edit.php' ) );
174
175 wp_safe_redirect( $redirect_url );
176 exit;
177 }
178 }
179 }
180 }
181