class-wpml-tm-mcs-pagination-ajax.php
1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
use WPML\TM\Menu\McSetup\CfMetaBoxOption;
/**
* Class WPML_TM_MCS_Pagination_Ajax
*/
class WPML_TM_MCS_Pagination_Ajax {
/** @var WPML_TM_MCS_Custom_Field_Settings_Menu_Factory */
private $menu_factory;
public function __construct( WPML_TM_MCS_Custom_Field_Settings_Menu_Factory $menu_factory ) {
$this->menu_factory = $menu_factory;
}
/**
* Define Ajax hooks.
*/
public function add_hooks() {
add_action( 'wp_ajax_wpml_update_mcs_cf', array( $this, 'update_mcs_cf' ) );
}
/**
* Update custom fields form.
*/
public function update_mcs_cf() {
if ( isset( $_POST['nonce'] ) && wp_verify_nonce( $_POST['nonce'], 'icl_' . $_POST['type'] . '_translation_nonce' ) ) {
$args = array(
'items_per_page' => intval( $_POST['items_per_page'] ),
'page' => intval( $_POST['paged'] ),
'search' => isset( $_POST['search'] ) ? sanitize_text_field( $_POST['search'] ) : '',
'hide_system_fields' => ! isset( $_POST['show_system_fields'] ) || ! filter_var( $_POST['show_system_fields'], FILTER_VALIDATE_BOOLEAN ),
'show_cf_meta_box' => isset( $_POST['show_cf_meta_box'] ) && filter_var( $_POST['show_cf_meta_box'], FILTER_VALIDATE_BOOLEAN ),
);
$menu_item = null;
if ( 'cf' === $_POST['type'] ) {
$menu_item = $this->menu_factory->create_post();
CfMetaBoxOption::update( $args['show_cf_meta_box'] );
} elseif ( 'tcf' === $_POST['type'] ) {
$menu_item = $this->menu_factory->create_term();
}
if ( $menu_item ) {
$result = array();
ob_start();
$menu_item->init_data( $args );
$menu_item->render_body();
$result['body'] = ob_get_clean();
ob_start();
$menu_item->render_pagination( $args['items_per_page'], $args['page'] );
$result['pagination'] = ob_get_clean();
wp_send_json_success( $result );
}
}
wp_send_json_error(
array(
'message' => __( 'Invalid Request.', 'wpml-translation-management' ),
)
);
}
}