export const newsReducer = (state = initialState, action:DataAction): DataState =>{
switch (action.type){
case DataActionTypes.FETCH_DATA_NEWS:
return {loading:true, error:null, data: []};
case DataActionTypes.FETCH_DATA_NEWS_SUCCESS:
return {loading:false, error:null, data: action.payload};
case DataActionTypes.FETCH_DATA_NEWS_ERROR:
return {loading:false, error:action.payload, data: []};
default:
return state
}
}
export const newReducer = (state = initialStateNew, action:DataActionNew): DataStateNew =>{
switch (action.type){
case DataActionTypes.FETCH_DATA_NEW:
return {loading:true, error:null, data: []};
case DataActionTypes.FETCH_DATA_NEW_SUCCESS:
return {loading:false, error:null, data: action.payload};
case DataActionTypes.FETCH_DATA_NEW_ERROR:
return {loading:false, error:action.payload, data: []};
default:
return state
}
}
removeThisComponent={removeComponent}
Encountered two children with the same key, `null`. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.
Call to undefined function wp_insert_post()
wp_localize_script('тут handle js', 'ajax', array(
'url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('ajax-custom-request'),
));
//ajax_init
add_action('init', 'auth_ajax_init');
function auth_ajax_init(){
//для не авторизированных
add_action('wp_ajax_nopriv_custom_request, 'custom_request_callback');
//для авторизированных
add_action('wp_ajax_custom_request', 'custom_request_callback');
}
function custom_request_callback(){
//Проверяем Ajax запрос на соответствие nonce коду, если не соответствует выходим
check_ajax_referer('ajax-custom-request', 'nonce_code');
//Если проверку прошли
//Здесь обрабатываем запрос, здесь доступна $_POST
wp_die();
}
let data = {
action: 'ajax-custom-request',
nonce_code: ajax.nonce,
data: здесь сериализуем данные для передачи,
};
$.post(ajax.url, data, function(data, textStatus) {
// здесь обработать ответ data
}, 'json');
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = true;
$content = file_get_contents($file);
$content = mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8');
$dom->loadHTML($content);
$dom->encoding = 'UTF-8';
$html = $dom->saveHTML();
file_put_contents($file, $html);