wp_create_nonce( 'wpc-ajax-nonce' ), 'condition_operators' => wpc_condition_operators(), 'condition_descriptions' => wpc_condition_descriptions(), ) ); } add_action( 'admin_enqueue_scripts', 'wpc_admin_enqueue_scripts', 5 ); } if ( ! function_exists( 'wpc_html_field' ) ) { /** * Output html field. * * Output a new HTML field. * * @since 1.0.0 * * @param array $args */ function wpc_html_field( $args = array() ) { $args = wp_parse_args( $args, array( 'id' => '', 'type' => 'text', 'name' => '', 'class' => '', 'value' => null, 'default' => '', 'placeholder' => '', 'custom_attributes' => isset( $args['custom_attr'] ) ? $args['custom_attr'] : array(), // BC ) ); $type = ! empty( $args['field'] ) ? $args['field'] : $args['type']; $class = is_array( $args['class'] ) ? implode( ' ', array_map( 'sanitize_html_class', $args['class'] ) ) : sanitize_html_class( $args['class'] ); $value = isset( $args['value'] ) ? $args['value'] : ''; $name = isset( $args['name'] ) ? $args['name'] : $args['id']; $custom_attributes = array(); if ( ! empty( $args['custom_attributes'] ) && is_array( $args['custom_attributes'] ) ) { foreach ( $args['custom_attributes'] as $k => $v ) { $custom_attributes[ $k ] = esc_attr( $k ) . '="' . esc_attr( $v ) . '"'; } } switch ( $type ) : case 'text' : case 'number' : ?> placeholder='' >get_formatted_name(); } $args['type'] = 'text'; wpc_html_field( $args ); break; default : case 'hook' : do_action( 'wp-conditions\html_field_hook', $args['type'], $args ); do_action( 'wp-conditions\html_field_type_' . $args['type'], $args ); break; endswitch; } } if ( ! function_exists( 'wpc_ajax_save_post_order' ) ) { /** * Save post order. * * Save the order of the posts in the overview table. * * @since 1.0.0 */ function wpc_ajax_save_post_order() { global $wpdb; check_ajax_referer( 'wpc-ajax-nonce', 'nonce' ); $args = wp_parse_args( $_POST['form'] ); if ( ! isset( $args['sort'] ) ) { die( '-1' ); } $menu_order = 0; foreach ( $args['sort'] as $sort ) : $wpdb->update( $wpdb->posts, array( 'menu_order' => $menu_order ), array( 'ID' => $sort ), array( '%d' ), array( '%d' ) ); $menu_order++; endforeach; die; } add_action( 'wp_ajax_wpc_save_post_order', 'wpc_ajax_save_post_order' ); }