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 / ajax / snippet-library.php

snippet-library.php in Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts 2.3.1, at admin/ajax/snippet-library.php

148 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Ajax requests handler
4 *
5 * @author Webcraftic <wordpress.webraftic@gmail.com>
6 * @copyright (c) 2018 Webraftic Ltd
7 * @version 1.0
8 */
9
10 // Exit if accessed directly
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * Get snippet library table content
17 */
18 function wbcr_inp_ajax_get_snippet_library() {
19 if ( ! WINP_Plugin::app()->currentUserCan() ) {
20 wp_die( - 1, 403 );
21 }
22
23 check_ajax_referer( 'winp-snippet-library', 'winp_nonce' );
24 ?>
25 <div class="wrap">
26 <form id="winp-snippet-library-list" method="get">
27 <input type="hidden" name="page" value="<?php echo WINP_Plugin::app()->request->request( 'page', 1, true ); ?>"/>
28 <input type="hidden" name="order" value="<?php echo WINP_Plugin::app()->request->request( 'order', 'asc', true ); ?>"/>
29 <input type="hidden" name="orderby" value="<?php echo WINP_Plugin::app()->request->request( 'orderby', 'title', true ); ?>"/>
30 <div id="winp-snippet-library-table" style="">
31 <p><?php _e( 'Loading...', 'insert-php' ); ?></p>
32 <?php
33 wp_nonce_field( 'winp-ajax-custom-list-nonce', 'winp_ajax_custom_list_nonce' );
34 ?>
35 </div>
36 </form>
37 </div>
38 <?php
39 wp_die();
40 }
41
42 add_action( 'wp_ajax_winp_get_snippet_library', 'wbcr_inp_ajax_get_snippet_library' );
43
44 /**
45 * Snippet synchronization
46 */
47 function wbcr_inp_ajax_snippet_synchronization() {
48 if ( ! WINP_Plugin::app()->currentUserCan() ) {
49 wp_die( - 1, 403 );
50 }
51
52 $snippet_id = WINP_Plugin::app()->request->post( 'snippet_id', 0, 'intval' );
53 $snippet_name = WINP_Plugin::app()->request->post( 'snippet_name', '', true );
54
55 check_ajax_referer( "wbcr_inp_save_snippet_{$snippet_id}_as_template" );
56
57 $result = WINP_Plugin::app()->get_api_object()->synchronization( $snippet_id, $snippet_name );
58
59 exit( $result );
60 }
61
62 add_action( 'wp_ajax_winp_snippet_synchronization', 'wbcr_inp_ajax_snippet_synchronization' );
63
64 /**
65 * Snippet create from library
66 */
67 function wbcr_inp_ajax_snippet_create() {
68 if ( ! WINP_Plugin::app()->currentUserCan() ) {
69 wp_die( - 1, 403 );
70 }
71
72 check_ajax_referer( 'winp-ajax-custom-list-nonce', 'winp_ajax_custom_list_nonce' );
73
74 $snippet_id = WINP_Plugin::app()->request->post( 'snippet_id', 0, true );
75 $post_id = WINP_Plugin::app()->request->post( 'post_id', 0, true );
76 $common = WINP_Plugin::app()->request->post( 'common', 0 );
77 $result = WINP_Plugin::app()->get_api_object()->create_from_library( $snippet_id, $post_id, $common );
78
79 echo( $result );
80 exit();
81 }
82
83 add_action( 'wp_ajax_winp_snippet_create', 'wbcr_inp_ajax_snippet_create' );
84
85 /**
86 * Snippet delete from library
87 */
88 function wbcr_inp_ajax_snippet_delete() {
89 if ( ! WINP_Plugin::app()->currentUserCan() ) {
90 wp_die( - 1, 403 );
91 }
92
93 $snippet_id = WINP_Plugin::app()->request->post( 'snippet_id', 0, true );
94
95 check_ajax_referer( 'winp-ajax-snippet-delete-' . $snippet_id, 'winp_ajax_snippet_delete_nonce' );
96
97 $result = WINP_Plugin::app()->get_api_object()->delete_snippet( $snippet_id );
98
99 echo( $result );
100 exit();
101 }
102
103 add_action( 'wp_ajax_winp_snippet_delete', 'wbcr_inp_ajax_snippet_delete' );
104
105 /**
106 * Action wp_ajax for fetching the first time table structure
107 */
108 function wbcr_inp_ajax_sts_display_callback() {
109 if ( ! WINP_Plugin::app()->currentUserCan() ) {
110 wp_die( - 1, 403 );
111 }
112
113 check_ajax_referer( 'winp-ajax-custom-list-nonce', 'winp_ajax_custom_list_nonce' );
114
115 require_once( WINP_PLUGIN_DIR . '/admin/includes/class.snippets.table.php' );
116
117 // Create an instance of our package class...
118 $snippet_list_table = new WINP_Snippet_Library_Table( true );
119 // Fetch, prepare, sort, and filter our data...
120 $snippet_list_table->prepare_items();
121 ob_start();
122 $snippet_list_table->display();
123 $display = ob_get_clean();
124 die( json_encode( [
125 'display' => $display,
126 ] ) );
127 }
128
129 add_action( 'wp_ajax_winp_sts_display', 'wbcr_inp_ajax_sts_display_callback' );
130
131 /**
132 * Action wp_ajax for fetching ajax_response
133 */
134 function wbcr_inp_ajax_sts_history_callback() {
135 if ( ! WINP_Plugin::app()->currentUserCan() ) {
136 wp_die( - 1, 403 );
137 }
138
139 check_ajax_referer( 'winp-ajax-custom-list-nonce', 'winp_ajax_custom_list_nonce' );
140
141 require_once( WINP_PLUGIN_DIR . '/admin/includes/class.snippets.table.php' );
142
143 $snippet_list_table = new WINP_Snippet_Library_Table( true );
144 $snippet_list_table->ajax_response();
145 }
146
147 add_action( 'wp_ajax_winp_fetch_sts_history', [ $this, 'wbcr_inp_ajax_sts_history_callback' ] );
148