reduxframework / redux-framework

Redux is a simple, truly extensible options framework for WordPress themes and plugins!

Home Page:http://redux.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

validate_callback problem

mrjk990 opened this issue · comments

hello
i have problem wheni am using validate_callback function
when try to save post with empty season_id
i get an error notice at the top "1 warnings(s) were found!"
but the message did not showup under "select input"

even with value passed
the same error notice showup
i try to figure out what happning

so in file redux-framework\redux-core\inc\classes\class-redux-validation.php
i addit var_dump() under validate function
like this

		public function validate( array $plugin_options, array $options, array $sections ): array {
			$core = $this->core();
			var_dump($sections); die;

i see the sections from series_metabox not from season_metabox
but i save a post have section season_metabox !!
can you help me guys
i am stuck on this problem for 2 days
sorry for my poor english

<?php
function is_int_value($field, $value, $existing_value) {
		$error   = false;
		$warning = false;

		// Do your validation.
		if (intval($value) == 0 ) {
			$warning = true;
			$value   = $existing_value;
		}

		$return['value'] = $value;

		if ( true === $warning ) {
			$field['msg']      = 'your custom warning message';
			$return['warning'] = $field;
		}

		return $return;
}

Redux_Metaboxes::set_box(
	$opt_name,
	array(
		'id'         => 'series_metabox',
		'title'      => esc_html__( 'TV Show Data', 'egybest' ),
		'post_types' => array('episode'),
		'position'   => 'normal', // normal, advanced, side.
		'priority'   => 997,   // high, core, default, low.
		'context' => 'after_editor',
		'sections'   => array(
			array(
				'id'     => 'episode-data',
				'title'  => esc_html__( 'Episode information', 'egybest' ),
				'desc'   => '',
				'icon'   => 'el el-screen',
				'fields' => array(
					array(
						'id' 	=> 'seasons_id',
						'type' 	=> 'select',
						'data'  => 'posts',
						'title'    => esc_html__( 'Select Season', 'egybest' ),
						'ajax_save'	=> false, // Force page load when this changes
						'validate_callback' => 'is_int_value',
						'args'  => array(
							'post_type'      => 'season',
							'posts_per_page' => -1,
							'orderby'        => 'title',
							'order'          => 'ASC',
							'hide_empty' 	 => false,
						)
					)
				)
			)
		)
	)
);



// Season Meta Box
Redux_Metaboxes::set_box(
	$opt_name,
	array(
		'id'         => 'season_metabox',
		'title'      => esc_html__( 'TV Show Data ', 'egybest' ),
		'post_types' => array('season'),
		'position'   => 'normal', // normal, advanced, side.
		'priority'   => 998,   // high, core, default, low.
		'context' => 'after_editor',
		'sections'   => array(
			array(
				'title'  => esc_html__( 'Season information', 'egybest' ),
				'id'     => 'season_data',
				'desc'   => '',
				'icon'   => 'el el-screen',
				'fields' => array(
					array(
						'id' 		=> 'series_id',
						'type' 		=> 'select',
						'data'  	=> 'posts',
						'ajax_save'	=> false, // Force page load when this changes
						'title'		=> esc_html__( 'Select TV Show', 'egybest' ),
						'validate_callback' => 'is_int_value',
						'args'  => array(
							'post_type'      => 'tv_show',
							'posts_per_page' => -1,
							'orderby'        => 'title',
							'order'          => 'ASC',
							'hide_empty' 	 => false,
						),
					),
					array(
						'id'       => 'season_number',
						'type'     => 'number',
						'title'    => esc_html__( 'Season Number', 'egybest' ),
						'validate' => 'numeric',
					),
				),
			)
		)
	)
);

The first problem is you have custom code here. Redux does not have a number field nor a context field for metaboxes. If these are custom modifications made to the Redux core, we can't help with those. You also have custom post types I cannot easily recreate. If you want to send me your project, the entire theme, I'll take a look at it. We support Redux issues, but not custom code.

I'm waiting on a reply on this issue. If I don't hear back tomorrow, I'm closing the issue.

I apologize for keeping you waiting
it's 5:00 AM and today it's holiday in our country
give me some time because i am away from my computer

@kprovance i sent to you an email

A demo site won't do me any good. I need the theme itself so I can look at it here. I can't debug code on a live server easily.

I downloaded the theme for your site. All the metabox sections will now be evaluated through validation.

Also, you'll need to add $return['value'] = $value; back to your is_int_value routine.