PluginProbe
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce / 1.6.9
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce v1.6.9
1.17.9 1.17.8 1.17.7 1.17.6 1.17.5 1.17.4 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.3.0 1.3.1 1.3.11 1.3.12 1.3.13 1.3.14 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 All 143 releases
erp / includes / framework / settings / integration.php

integration.php in ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce 1.6.9, at includes/framework/settings/integration.php

189 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use WeDevs\ERP\Framework\ERP_Settings_Page;
4
5 /**
6 * Integration class
7 */
8 class ERP_Integration_Settings extends ERP_Settings_Page {
9
10 /**
11 * Class constructor
12 */
13 public function __construct() {
14 $this->id = 'erp-integration';
15 $this->label = __( 'Integrations', 'erp' );
16
17 add_action( 'erp_admin_field_integrations', [ $this, 'integrations' ] );
18 }
19
20 /**
21 * Get settings array.
22 *
23 * @return array
24 */
25 public function get_settings() {
26 $fields = [
27 [
28 'title' => __( 'Integrations', 'erp' ),
29 'desc' => __( 'Various integrations to WP ERP. Click <strong>Configure</strong> to manage the settings.', 'erp' ),
30 'type' => 'title',
31 'id' => 'integration_settings',
32 ],
33
34 [ 'type' => 'integrations' ],
35 [ 'type' => 'sectionend', 'id' => 'script_styling_options' ],
36 ]; // End general settings
37
38 return apply_filters( 'erp_integration_settings', $fields );
39 }
40
41 /**
42 * Display integrations settings.
43 *
44 * @return void
45 */
46 public function integrations() {
47 $integrations = wperp()->integration->get_integrations(); ?>
48 <tr valign="top">
49 <td class="erp-settings-table-wrapper" colspan="2">
50 <table class="erp-settings-table widefat" cellspacing="0">
51 <thead>
52 <tr>
53 <?php
54 $columns = apply_filters( 'erp_integration_setting_columns', [
55 'name' => __( 'Integration', 'erp' ),
56 'description' => __( 'Description', 'erp' ),
57 'actions' => '',
58 ] );
59
60 foreach ( $columns as $key => $column ) {
61 echo '<th class="erp-settings-table-' . esc_attr( $key ) . '">' . esc_html( $column ) . '</th>';
62 } ?>
63 </tr>
64 </thead>
65 <tbody>
66 <?php
67 foreach ( $integrations as $integration_key => $integration ) {
68 echo '<tr>';
69
70 foreach ( $columns as $key => $column ) {
71 switch ( $key ) {
72 case 'name':
73 echo '<td class="erp-settings-table-' . esc_attr( $key ) . '">
74 <a href="' . esc_url( admin_url( 'admin.php?page=erp-settings&tab=erp-integration&section=' . esc_attr( strtolower( $integration_key ) ) ) ) . '">' . esc_html( $integration->get_title() ) . '</a>
75 </td>';
76 break;
77
78 case 'status':
79 case 'module':
80 case 'recipient':
81 echo '<td class="erp-settings-table-' . esc_attr( $key ) . '">
82
83 </td>';
84 break;
85
86 case 'description':
87 echo '<td class="erp-settings-table-' . esc_attr( $key ) . '">
88 <span class="help">' . esc_html( $integration->get_description() ) . '</span>
89 </td>';
90 break;
91
92 case 'actions':
93 echo '<td class="erp-settings-table-' . esc_attr( $key ) . '">
94 <a class="button alignright" href="' . esc_url( admin_url( 'admin.php?page=erp-settings&tab=erp-integration&section=' . strtolower( $integration_key ) ) ) . '">' . esc_html__( 'Configure', 'erp' ) . '</a>
95 </td>';
96 break;
97
98 default:
99 do_action( 'erp_integration_setting_column_' . $key, $integration );
100 break;
101 }
102 }
103 } ?>
104 </tbody>
105 </table>
106 </td>
107 </tr>
108
109 <style>p.submit { display: none; }</style>
110 <?php
111 }
112
113 /**
114 * Output the settings.
115 *
116 * @param bool $section (optional)
117 *
118 * @return void
119 */
120 public function output( $section = false ) {
121 $current_section = isset( $_GET['section'] ) ? sanitize_key( $_GET['section'] ) : false;
122
123 // Define integrations that can be customised here
124 $integrations = wperp()->integration->get_integrations();
125
126 if ( $current_section ) {
127 foreach ( $integrations as $integration_key => $integration ) {
128 if ( strtolower( $integration_key ) == $current_section ) {
129 $integration->admin_options();
130 break;
131 }
132 }
133 } else {
134 parent::output();
135 }
136 }
137
138 /**
139 * Save the settings.
140 *
141 * @param bool $section (optional)
142 *
143 * @return void
144 */
145 public function save( $section = false ) {
146 if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_POST['_wpnonce'] ), 'erp-settings-nonce' ) ) {
147 $current_section = isset( $_GET['section'] ) ? sanitize_text_field( wp_unslash( $_GET['section'] ) ) : false;
148
149 // saving individual integration settings
150 if ( $current_section ) {
151 $integrations = wperp()->integration->get_integrations();
152
153 foreach ( $integrations as $integration_key => $integration ) {
154 if ( strtolower( $integration_key ) == $current_section ) {
155 $settings = $integration->get_form_fields();
156 $update_options = [];
157
158 if ( $settings ) {
159 foreach ( $settings as $field ) {
160 if ( ! isset( $field['id'] ) || ! isset( $_POST[ $field['id'] ] ) ) {
161 continue;
162 }
163
164 $option_value = $this->parse_option_value( $field );
165
166 if ( ! is_null( $option_value ) ) {
167 $update_options[ $field['id'] ] = $option_value;
168 }
169 }
170 }
171
172 do_action( $integration->get_option_id() . '_action', $update_options );
173
174 $update_options = apply_filters( $integration->get_option_id() . '_filter', $update_options );
175
176 update_option( $integration->get_option_id(), $update_options );
177
178 break;
179 }
180 }
181 } else {
182 parent::save();
183 }
184 }
185 }
186 }
187
188 return new ERP_Integration_Settings();
189