PluginProbe
Comments Extra Fields For Post,Pages and CPT / 2.2
Comments Extra Fields For Post,Pages and CPT v2.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
← All changes | classes/admin.class.php +171 -206 5.22.2 View file →
@@ -1,206 +1,171 @@
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 - // Verify nonce
104 - if ( ! isset( $_REQUEST['wpcomment_nonce'] ) || ! wp_verify_nonce( $_REQUEST['wpcomment_nonce'], 'wpcomment_save_form_meta_nonce' ) ) {
105 - wp_send_json_error( 'Invalid nonce.' );
106 - }
107 -
108 - // Check user capabilities
109 - if ( ! current_user_can( 'manage_options' ) ) {
110 - wp_send_json_error( 'Insufficient permissions.' );
111 - }
112 -
113 - // Proceed with processing the request
114 - $wpcomment_meta = isset( $_REQUEST['wpcomment'] ) ? $_REQUEST['wpcomment'] : '';
115 - $wpcomment_meta = apply_filters( 'wpcomment_meta_data_saving', $wpcomment_meta );
116 - $wpcomment_meta = wpcomment_sanitize_array_data( $wpcomment_meta );
117 -
118 - // Save meta fields
119 - update_option( 'wpcomment_meta_fields', json_encode( $wpcomment_meta ) );
120 -
121 - // Prepare response
122 - $args = array( 'page' => 'wpcomment' );
123 - $redirect_to = add_query_arg( $args, admin_url( 'admin.php' ) );
124 -
125 - $resp = array(
126 - 'message' => __( 'Fields added successfully', 'wp-comment-fields' ),
127 - 'status' => 'success',
128 - 'redirect_to' => $redirect_to,
129 - );
130 -
131 - wp_send_json( $resp );
132 - }
133 -
134 -
135 - // Saving Global settings
136 - function save_form_settings(){
137 -
138 - // Verify nonce
139 - if ( ! isset( $_REQUEST['wpcomment_nonce'] ) || ! wp_verify_nonce( $_REQUEST['wpcomment_nonce'], 'wpcomment_save_form_meta_nonce' ) ) {
140 - wp_send_json_error( 'Invalid nonce.' );
141 - }
142 -
143 - // Check user capabilities
144 - if ( ! current_user_can( 'manage_options' ) ) {
145 - wp_send_json_error( 'Insufficient permissions.' );
146 - }
147 -
148 - $keys = ['wpcomment_heading','wpcomment_cpt','wpcomment_disable_frontend'];
149 -
150 - $settings = [];
151 - foreach($keys as $k){
152 - if( ! isset($_POST[$k]) ) continue;
153 - $settings[$k] = sanitize_text_field($_POST[$k]);
154 - }
155 -
156 - update_option('wpcomment_settings', $settings);
157 -
158 - $resp = array (
159 - 'message' => __ ( 'Settings saved successfully', 'wp-comment-fields' ),
160 - 'status' => 'success',
161 - );
162 -
163 - wp_send_json($resp);
164 - }
165 -
166 - /**
167 - * rendering comment meta BOX in comments admin page
168 - */
169 - function comment_meta_box( $comment ) {
170 -
171 - add_meta_box( 'wpcomment_mb_show', __( 'Comment Extra Fields' ), array( $this, 'show_comment_fields' ), 'comment', 'normal' );
172 - }
173 -
174 - /**
175 - * rendering comment META in comments admin page
176 - */
177 - function show_comment_fields( $comment ) {
178 -
179 - $comment_output = WPCOMMENT_FRONTEND()->get_comment_meta_by_comment_id(get_comment_ID());
180 -
181 - // $comment_meta = get_comment_meta( get_comment_ID(), 'wpcomment_fields', true );
182 - // $comment_output = wpcomment_render_comment_meta($comment_meta);
183 -
184 - if($comment_output){
185 - echo apply_filters('wpcomment_meta_admin', $comment_output, $comment);
186 - }
187 - }
188 -
189 -
190 -
191 - function wpcomment_setting_wpml($value, $option, $raw_value) {
192 -
193 - if( isset($option['type']) && isset($option['type']) == 'text' ) {
194 - $value = wpcomment_wpml_translate($value, 'PPOM');
195 - }
196 -
197 - return $value;
198 - }
199 -}
200 -
201 -function WPCOMMENT_ADMIN(){
202 - return WPComment_Admin::get_instance();
203 -}
204 -if( is_admin() ) {
205 - WPCOMMENT_ADMIN();
206 -}
1 +<?php
2 +/*
3 + * working behind the seen
4 +*/
5 +
6 +
7 +class NM_PLUGIN_WPComments_Admin extends NM_PLUGIN_WPComments{
8 +
9 +
10 + var $menu_pages, $plugin_scripts_admin, $plugin_settings;
11 +
12 +
13 + function __construct(){
14 +
15 +
16 + //setting plugin meta saved in config.php
17 + $this -> plugin_meta = get_plugin_meta_wpcomment();
18 +
19 + //getting saved settings
20 + $this -> plugin_settings = get_option($this->plugin_meta['shortname'].'_settings');
21 +
22 +
23 + /*
24 + * [1]
25 + * TODO: change this for plugin admin pages
26 + */
27 + $this -> menu_pages = array(array('page_title' => $this->plugin_meta['name'],
28 + 'menu_title' => $this->plugin_meta['name'],
29 + 'cap' => 'manage_options',
30 + 'slug' => $this->plugin_meta['shortname'],
31 + 'callback' => 'main_settings',
32 + 'parent_slug' => '',),
33 + );
34 +
35 +
36 + /*
37 + * [2]
38 + * TODO: Change this for admin related scripts
39 + * JS scripts and styles to loaded
40 + * ADMIN
41 + */
42 + $this -> plugin_scripts_admin = array(array( 'script_name' => 'scripts-global',
43 + 'script_source' => '/js/nm-global.js',
44 + 'localized' => false,
45 + 'type' => 'js',
46 + 'page_slug' => $this->plugin_meta['shortname']
47 + ),
48 + array( 'script_name' => 'scripts-admin',
49 + 'script_source' => '/js/admin.js',
50 + 'localized' => true,
51 + 'type' => 'js',
52 + 'page_slug' => $this->plugin_meta['shortname'],
53 + 'depends' => array (
54 + 'jquery',
55 + 'jquery-ui-accordion',
56 + 'jquery-ui-draggable',
57 + 'jquery-ui-droppable',
58 + 'jquery-ui-sortable',
59 + 'jquery-ui-slider',
60 + 'jquery-ui-dialog',
61 + 'jquery-ui-tabs',
62 + 'media-upload',
63 + 'thickbox'
64 + )
65 + ),
66 + array (
67 + 'script_name' => 'ui-style',
68 + 'script_source' => '/js/ui/css/smoothness/jquery-ui-1.10.3.custom.min.css',
69 + 'localized' => false,
70 + 'type' => 'style',
71 + 'page_slug' => $this->plugin_meta ['shortname'],
72 + 'depends' => '',
73 + ),
74 +
75 + );
76 +
77 +
78 + add_action('admin_menu', array($this, 'add_menu_pages'));
79 + }
80 +
81 + function load_scripts_admin(){
82 +
83 + //localized vars in js
84 + $arrLocalizedVars = array( 'ajaxurl' => admin_url( 'admin-ajax.php' ),
85 + 'plugin_url' => $this -> plugin_meta['url']
86 + );
87 +
88 + //admin end scripts
89 +
90 + if($this -> plugin_scripts_admin){
91 + foreach($this -> plugin_scripts_admin as $script){
92 +
93 + //checking if it is style
94 + if( $script['type'] == 'js'){
95 + $depends = (isset($script['depends']) ? $script['depends'] : NULL);
96 + wp_enqueue_script ( $this->plugin_meta ['shortname'] . '-' . $script ['script_name'], $this->plugin_meta ['url'] . $script ['script_source'], $depends );
97 +
98 + //if localized
99 + if( $script['localized'] )
100 + wp_localize_script( $this -> plugin_meta['shortname'].'-'.$script['script_name'], $this -> plugin_meta['shortname'].'_vars', $arrLocalizedVars);
101 + }else{
102 +
103 + wp_enqueue_style($this -> plugin_meta['shortname'].'-'.$script['script_name'], $this -> plugin_meta['url'].$script['script_source'], __FILE__);
104 + }
105 + }
106 + }
107 +
108 + }
109 +
110 +
111 +
112 + /*
113 + * creating menu page for this plugin
114 + */
115 +
116 + function add_menu_pages(){
117 +
118 + foreach ($this -> menu_pages as $page){
119 +
120 + if ($page['parent_slug'] == ''){
121 +
122 + $menu = add_menu_page(sprintf(__("%s", 'nm-wpcomments'), $page['page_title']),
123 + sprintf(__("%s", 'nm-wpcomments'), $page['menu_title']),
124 + $page['cap'],
125 + $page['slug'],
126 + array($this, $page['callback']),
127 + $this->plugin_meta['logo']);
128 + }else{
129 +
130 + $menu = add_submenu_page($page['parent_slug'],
131 + sprintf(__("%s", 'nm-wpcomments'), $page['page_title']),
132 + sprintf(__("%s", 'nm-wpcomments'), $page['menu_title']),
133 + $page['cap'],
134 + $page['slug'],
135 + array($this, $page['callback'])
136 + );
137 +
138 + }
139 +
140 + //loading script for only plugin optios pages
141 + // page_slug is key in $plugin_scripts_admin which determine the page
142 + foreach ($this -> plugin_scripts_admin as $script){
143 +
144 + if (is_array($script['page_slug'])){
145 +
146 + if (in_array($page['slug'], $script['page_slug']))
147 + add_action('admin_print_scripts-'.$menu, array($this, 'load_scripts_admin'));
148 + }else if ($script['page_slug'] == $page['slug']){
149 + add_action('admin_print_scripts-'.$menu, array($this, 'load_scripts_admin'));
150 + }
151 + }
152 + }
153 +
154 +
155 + }
156 +
157 +
158 + //====================== CALLBACKS =================================
159 + function main_settings(){
160 +
161 + $this -> load_template('admin/settings.php');
162 +
163 + }
164 +
165 + function list_users(){
166 +
167 +
168 + }
169 +}
170 +
171 +new NM_PLUGIN_WPComments_Admin();