PluginProbe
Comments Extra Fields For Post,Pages and CPT / 4.6
Comments Extra Fields For Post,Pages and CPT v4.6
trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 2.2 2.3 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 5.0 5.1 5.2
wp-comment-fields / classes / admin.class.php

admin.class.php in Comments Extra Fields For Post,Pages and CPT 4.6, at classes/admin.class.php

194 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * working behind the seen
4 */
5
6 /*
7 **========== Direct access not allowed ===========
8 */
9 if( ! defined('ABSPATH') ) die('Not Allowed');
10
11 class WPComment_Admin {
12
13 private static $ins;
14 private static $options;
15
16 function __construct() {
17
18 add_action ( 'admin_menu', array (
19 $this,
20 'add_comment_menu'
21 ) );
22
23 self::$options = get_option('wpcomment_settings', true);
24
25 // Saving settings and fields
26 add_action('wp_ajax_wpcomment_save_form_meta', array($this, 'save_meta_fields'));
27 add_action('wp_ajax_wpcomment_save_settings', array($this, 'save_form_settings'));
28
29 /*
30 * adding meta box in comments edit page
31 */
32 add_action( 'add_meta_boxes_comment', array( $this, 'comment_meta_box' ), 1 );
33
34
35 // adding wpml support for PPOM Settings
36 // add_filter('woocommerce_admin_settings_sanitize_option', array($this, 'wpcomment_setting_wpml'), 10, 3);
37
38 // add_action( 'woocommerce_admin_field_wpcomment_multi_select', array( $this, 'wpcomment_multi_select_role_setting' ),2,10 );
39
40 }
41
42 public static function get_instance() {
43 // create a new object if it doesn't exist.
44 is_null(self::$ins) && self::$ins = new self;
45 return self::$ins;
46 }
47
48 public static function get_option($k, $default=null){
49
50 return isset(self::$options[$k]) ? self::$options[$k] : $default;
51 }
52
53
54 /*
55 * creating menu page for this plugin
56 */
57 function add_comment_menu() {
58
59 add_comments_page( __( 'Comment Fields', 'wp-comment-fields' ),
60 __( 'Comment Fields', 'wp-comment-fields' ),
61 'manage_options', 'wpcomment',
62 array($this, 'comment_meta') );
63 }
64
65
66 /*
67 * CALLBACKS
68 */
69 function comment_meta() {
70
71 $wpcomment_inputs = $this->get_all_inputs();
72
73 ob_start();
74 wpcomment_load_template ( 'admin/settings-home.php', ['wpcomment_inputs'=>$wpcomment_inputs] );
75 echo ob_get_clean();
76 }
77
78 /*
79 * returning NM_Inputs object
80 */
81 function get_all_inputs() {
82
83 $nm_inputs = WPComment_Inputs();
84 // registering all inputs here
85
86 $all_inputs = array (
87
88 'text' => $nm_inputs->get_input ( 'text' ),
89 'textarea' => $nm_inputs->get_input ( 'textarea' ),
90 'select' => $nm_inputs->get_input ( 'select' ),
91 'radio' => $nm_inputs->get_input ( 'radio' ),
92 'checkbox' => $nm_inputs->get_input ( 'checkbox' ),
93 );
94
95 return apply_filters('wpcomment_all_inputs', $all_inputs, $nm_inputs);
96 }
97
98
99 /*
100 * saving form meta in admin call
101 */
102 function save_meta_fields() {
103
104 $wpcomment_meta = isset($_REQUEST['wpcomment']) ? $_REQUEST['wpcomment'] : '';
105 $wpcomment_meta = apply_filters('wpcomment_meta_data_saving', $wpcomment_meta);
106 $wpcomment_meta = wpcomment_sanitize_array_data( $wpcomment_meta );
107 // wp_send_json($wpcomment_meta);
108 $wpcomment_meta = json_encode($wpcomment_meta);
109
110 update_option('wpcomment_meta_fields', $wpcomment_meta);
111
112 $resp = array ();
113 if ($wpcomment_meta) {
114
115 $args = array('page'=>'wpcomment');
116 $redirect_to = add_query_arg($args, admin_url('admin.php'));
117
118 $resp = array (
119 'message' => __ ( 'Fields added successfully', 'wp-comment-fields' ),
120 'status' => 'success',
121 'redirect_to' => $redirect_to,
122 );
123 } else {
124 $resp = array (
125 'message' => __ ( 'No changes found.', 'wp-comment-fields' ),
126 'status' => 'success',
127 );
128 }
129
130 wp_send_json($resp);
131 }
132
133 // Saving Global settings
134 function save_form_settings(){
135
136 $keys = ['wpcomment_heading','wpcomment_cpt','wpcomment_disable_frontend'];
137
138 $settings = [];
139 foreach($keys as $k){
140 if( ! isset($_POST[$k]) ) continue;
141 $settings[$k] = sanitize_text_field($_POST[$k]);
142 }
143
144 update_option('wpcomment_settings', $settings);
145
146 $resp = array (
147 'message' => __ ( 'Settings saved successfully', 'wp-comment-fields' ),
148 'status' => 'success',
149 );
150
151 wp_send_json($resp);
152 }
153
154 /**
155 * rendering comment meta BOX in comments admin page
156 */
157 function comment_meta_box( $comment ) {
158
159 add_meta_box( 'wpcomment_mb_show', __( 'Comment Extra Fields' ), array( $this, 'show_comment_fields' ), 'comment', 'normal' );
160 }
161
162 /**
163 * rendering comment META in comments admin page
164 */
165 function show_comment_fields( $comment ) {
166
167 $comment_output = WPCOMMENT_FRONTEND()->get_comment_meta_by_comment_id(get_comment_ID());
168
169 // $comment_meta = get_comment_meta( get_comment_ID(), 'wpcomment_fields', true );
170 // $comment_output = wpcomment_render_comment_meta($comment_meta);
171
172 if($comment_output){
173 echo apply_filters('wpcomment_meta_admin', $comment_output, $comment);
174 }
175 }
176
177
178
179 function wpcomment_setting_wpml($value, $option, $raw_value) {
180
181 if( isset($option['type']) && isset($option['type']) == 'text' ) {
182 $value = wpcomment_wpml_translate($value, 'PPOM');
183 }
184
185 return $value;
186 }
187 }
188
189 function WPCOMMENT_ADMIN(){
190 return WPComment_Admin::get_instance();
191 }
192 if( is_admin() ) {
193 WPCOMMENT_ADMIN();
194 }