__( 'NG word function', 'acf-booster' ), 'instructions' => '', 'type' => 'radio', 'name' => 'ng-type-select', 'choices' => array( 0 => __( 'Do not use in this field', 'acf-booster' ), 1 => __( 'Use NG word lists', 'acf-booster' ), 2 => __( 'Set a unique word', 'acf-booster' ), ), 'layout' => 'horizontal', ) ); acf_render_field_setting( $field, array( 'label' => __( 'Unique word', 'acf-booster' ), 'instructions' => __( 'Enter words separated by a comma', 'acf-booster' ), 'name' => 'unique_ng_word', 'type' => 'text', ), true ); } if ( get_field( 'counter-control', 'option' ) ) { acf_render_field_setting( $field, array( 'label' => __( 'Type Counter', 'acf-booster' ), 'instructions' => __( 'display the input characters?', 'acf-booster' ), 'name' => 'show_count', 'type' => 'true_false', 'ui' => 1, 'default_value' => 0, ), true ); } } /** * my_acf_field_group_admin_enqueue_scripts * * Check ON/OFF of each function and load field group setting screens javascript * * @param void * @return void */ public function my_acf_field_group_admin_enqueue_scripts() { if ( get_field( 'ngword-control', 'option' ) ) { wp_register_script( 'render-ngword-setting.js', plugin_dir_url( __FILE__ ) . '/js/render-ngword-setting.js', false, 1 ); wp_enqueue_script( 'render-ngword-setting.js' ); } if ( get_field( 'counter-control', 'option' ) ) { wp_register_script( 'render-counter-setting.js', plugin_dir_url( __FILE__ ) . '/js/render-counter-setting.js', false, 1 ); wp_enqueue_script( 'render-counter-setting.js' ); } } /** * check_words * * Create endpoint to get NG word with ajax * * @param void * @return json */ public function check_words() { if ( get_field( 'ngword-control', 'option' ) ) { if ( isset( $_POST['target_field'] ) ) { $target = str_replace( 'acf-', '', sanitize_key( $_POST['target_field'] ) ); $object = get_field_object( $target ); if ( $object['ng-type-select'] == 2 ) { echo json_encode( $object['unique_ng_word'] ); } elseif ( $object['ng-type-select'] == 1 ) { echo json_encode( get_field( 'word-list', 'option' ) ); } else { echo json_encode( 'undefined' ); } } } die(); } /** * block_post * * Block posts containing NG words on the server side * * @param $valid(mixed) * @param $value(mixed) * @param $field(array) * @param $input(string) * @return $valid */ public function block_post( $valid, $value, $field, $input ) { if ( ! $valid || $field['key'] == acfb_word_key ) { return $valid; } if ( get_field( 'ngword-control', 'option' ) ) { foreach ( $field as $key => $fieldkey ) { $object = get_field_object( $fieldkey ); if ( $object['ng-type-select'] == 2 ) { $uq_word_list = explode( ',', $object['unique_ng_word'] ); foreach ( $uq_word_list as $word ) { if ( ! empty( $word ) && strpos( $value, $word ) !== false ) { $valid = 'Contains NG word'; } } return $valid; } elseif ( $object['ng-type-select'] == 1 ) { $setting_word = explode( ',', get_field( 'word-list', 'option' ) ); foreach ( $setting_word as $word ) { if ( ! empty( $word ) && strpos( $value, $word ) !== false ) { $valid = 'Contains NG word'; } } return $valid; } } } } } $launch = ACF_BOOSTER::getInstance();