PluginProbe
Comments Extra Fields For Post,Pages and CPT / 4.2
Comments Extra Fields For Post,Pages and CPT v4.2
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.2, at classes/admin.class.php

191 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', 'wp-comment-fields',
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 wpcomment_load_template ( 'admin/settings-home.php', ['wpcomment_inputs'=>$wpcomment_inputs] );
73 }
74
75 /*
76 * returning NM_Inputs object
77 */
78 function get_all_inputs() {
79
80 $nm_inputs = WPComment_Inputs();
81 // registering all inputs here
82
83 $all_inputs = array (
84
85 'text' => $nm_inputs->get_input ( 'text' ),
86 'textarea' => $nm_inputs->get_input ( 'textarea' ),
87 'select' => $nm_inputs->get_input ( 'select' ),
88 'radio' => $nm_inputs->get_input ( 'radio' ),
89 'checkbox' => $nm_inputs->get_input ( 'checkbox' ),
90 );
91
92 return apply_filters('wpcomment_all_inputs', $all_inputs, $nm_inputs);
93 }
94
95
96 /*
97 * saving form meta in admin call
98 */
99 function save_meta_fields() {
100
101 $wpcomment_meta = isset($_REQUEST['wp-comment-fields']) ? $_REQUEST['wp-comment-fields'] : '';
102 $wpcomment_meta = apply_filters('wpcomment_meta_data_saving', $wpcomment_meta);
103 $wpcomment_meta = wpcomment_sanitize_array_data( $wpcomment_meta );
104 // wp_send_json($wpcomment_meta);
105 $wpcomment_meta = json_encode($wpcomment_meta);
106
107 update_option('wpcomment_meta_fields', $wpcomment_meta);
108
109 $resp = array ();
110 if ($wpcomment_meta) {
111
112 $args = array('page'=>'wp-comment-fields');
113 $redirect_to = add_query_arg($args, admin_url('admin.php'));
114
115 $resp = array (
116 'message' => __ ( 'Fields added successfully', 'wp-comment-fields' ),
117 'status' => 'success',
118 'redirect_to' => $redirect_to,
119 );
120 } else {
121 $resp = array (
122 'message' => __ ( 'No changes found.', 'wp-comment-fields' ),
123 'status' => 'success',
124 );
125 }
126
127 wp_send_json($resp);
128 }
129
130 // Saving Global settings
131 function save_form_settings(){
132
133 $keys = ['wpcomment_heading','wpcomment_cpt','wpcomment_disable_frontend'];
134
135 $settings = [];
136 foreach($keys as $k){
137 if( ! isset($_POST[$k]) ) continue;
138 $settings[$k] = sanitize_text_field($_POST[$k]);
139 }
140
141 update_option('wpcomment_settings', $settings);
142
143 $resp = array (
144 'message' => __ ( 'Settings saved successfully', 'wp-comment-fields' ),
145 'status' => 'success',
146 );
147
148 wp_send_json($resp);
149 }
150
151 /**
152 * rendering comment meta BOX in comments admin page
153 */
154 function comment_meta_box( $comment ) {
155
156 add_meta_box( 'wpcomment_mb_show', __( 'Comment Extra Fields' ), array( $this, 'show_comment_fields' ), 'comment', 'normal' );
157 }
158
159 /**
160 * rendering comment META in comments admin page
161 */
162 function show_comment_fields( $comment ) {
163
164 $comment_output = WPCOMMENT_FRONTEND()->get_comment_meta_by_comment_id(get_comment_ID());
165
166 // $comment_meta = get_comment_meta( get_comment_ID(), 'wpcomment_fields', true );
167 // $comment_output = wpcomment_render_comment_meta($comment_meta);
168
169 if($comment_output){
170 echo apply_filters('wpcomment_meta_admin', $comment_output, $comment);
171 }
172 }
173
174
175
176 function wpcomment_setting_wpml($value, $option, $raw_value) {
177
178 if( isset($option['type']) && isset($option['type']) == 'text' ) {
179 $value = wpcomment_wpml_translate($value, 'PPOM');
180 }
181
182 return $value;
183 }
184 }
185
186 function WPCOMMENT_ADMIN(){
187 return WPComment_Admin::get_instance();
188 }
189 if( is_admin() ) {
190 WPCOMMENT_ADMIN();
191 }