option_name = 'acfl'; add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); add_action( 'admin_menu', array( $this, 'admin_menu' ) ); add_action( 'admin_action_acfl_save', array( $this, 'admin_action_acfl_save' ) ); } function admin_menu() { add_submenu_page( 'edit.php?post_type=acf', __('Advanced Custom Fields Limiters','acfl'), __('Limiters','acfl'), 'manage_options', 'acfl', array( $this, 'options_page' ) ); } function admin_enqueue_scripts() { global $post; wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'acfl', plugins_url( 'acfl.js', __FILE__ ) ); wp_localize_script( 'acfl', 'acfl', $this->get_limits_localization() ); wp_enqueue_style( 'acfl', plugins_url( 'acfl.css', __FILE__ ) ); } function get_limits_localization() { if ( !$fields = get_option( $this->option_name ) ) return array(); $limits = array(); foreach( $fields as $field_id => $field_value ) { $limits['#acf-' . $field_id] = $field_value; } return $limits; } function get_character_field_types() { return array( 'text', 'textarea', 'number' ); } function admin_action_acfl_save() { global $wpdb; if ( empty($_POST['fields'] ) ) return false; $fields_option = array(); foreach( $_POST['fields'] as $field_id => $field_value ) { if ( $field_value ) $fields_option[ $field_id ] = preg_replace( '/[^0-9]/', '', $field_value ); } if ( !empty( $fields_option ) ) update_option( $this->option_name, $fields_option ); header( 'Location:' . admin_url( 'edit.php?post_type=acf&page=acfl&updated' ) ); } function options_page() { global $wpdb; ?>


get_character_field_types(); $fields_option = get_option( $this->option_name ); $groups = new WP_Query( array( 'post_type' => 'acf', 'posts_per_page' => -1 ) ); ?> have_posts() ) : ?> have_posts() ) : $groups->the_post(); ?> prepare ( " SELECT meta_key, meta_value FROM {$wpdb->postmeta} WHERE 1=1 AND post_id = %d AND meta_key LIKE %s ", get_the_ID(), 'field\_%' ); ?> get_results( $sql ) as $field ) : ?> meta_value); if ( !in_array( $f['type'], $character_fields ) ) continue; $field_limit = ''; if ( !empty( $fields_option[ $field->meta_key ] ) ) $field_limit = intval( $fields_option[ $field->meta_key ] ); $i++; ?>