add_action('get_header', 'wp_maintenance_mode'); /** * codex functions and definitions * * @link https://developer.wordpress.org/themes/basics/theme-functions/ * * @package codex */ if ( ! defined( '_S_VERSION' ) ) { // Replace the version number of the theme on each release. define( '_S_VERSION', '1.0.0' ); } /** * Sets up theme defaults and registers support for various WordPress features. * * Note that this function is hooked into the after_setup_theme hook, which * runs before the init hook. The init hook is too late for some features, such * as indicating support for post thumbnails. */ function codex_setup() { // Add default posts and comments RSS feed links to head. add_theme_support( 'automatic-feed-links' ); /* * Let WordPress manage the document title. * By adding theme support, we declare that this theme does not use a * hard-coded
',
'save_tags' => '',
'sanitize_callback' => static function( string $text, object $rg ){
return strip_tags( $text, $rg->save_tags );
},
], $args );
$rg = apply_filters( 'kama_excerpt_args', $rg );
if( ! $rg->text ){
if(!empty($rg->post)){
$rg->text = $rg->post->post_excerpt ?: $rg->post->post_content;
}
else{
$rg->text = $post->post_excerpt ?: $post->post_content;
}
}
$text = $rg->text;
// strip content shortcodes: [foo]some data[/foo]. Consider markdown
$text = preg_replace( '~\[([a-z0-9_-]+)[^\]]*\](?!\().*?\[/\1\]~is', '', $text );
// strip others shortcodes: [singlepic id=3]. Consider markdown
$text = preg_replace( '~\[/?[^\]]*\](?!\()~', '', $text );
// strip direct URLs
$text = preg_replace( '~(?<=\s)https?://.+\s~', '', $text );
$text = trim( $text );
// echo $text;
//
if( ! $rg->ignore_more && strpos( $text, '' ) ){
preg_match( '/(.*)/s', $text, $mm );
$text = trim( $mm[1] );
// $text_append = sprintf( ' %s', get_permalink( $post ), $post->ID, $rg->more_text );
}
// text, excerpt, content
else {
$text = call_user_func( $rg->sanitize_callback, $text, $rg );
$has_tags = false !== strpos( $text, '<' );
// collect html tags
if( $has_tags ){
$tags_collection = [];
$nn = 0;
$text = preg_replace_callback( '/<[^>]+>/', static function( $match ) use ( & $tags_collection, & $nn ){
$nn++;
$holder = "~$nn";
$tags_collection[ $holder ] = $match[0];
return $holder;
}, $text );
}
// cut text
$cuted_text = mb_substr( $text, 0, $rg->maxchar );
if( $text !== $cuted_text ){
// del last word, it not complate in 99%
$text = preg_replace( '/(.*)\s\S*$/s', '\\1...', trim( $cuted_text ) );
}
// bring html tags back
if( $has_tags ){
$text = strtr( $text, $tags_collection );
$text = force_balance_tags( $text );
}
}
// add tags. Simple analog of wpautop()
if( $rg->autop ){
$text = preg_replace(
[ "/\r/", "/\n{2,}/", "/\n/" ],
[ '', '
', '
' ],
"
$text
"
);
}
$text = apply_filters( 'kama_excerpt', $text, $rg );
if( isset( $text_append ) ){
$text .= $text_append;
}
$text = trim( preg_replace("/\n{2,}/", "\n\n", $text) );
return $text;
}
function get_text_fields($_fields = array(), $_post = array()){
$result = array();
if(!empty($_fields)){
foreach($_fields as $_field => $_name){
if(!empty($_post[$_field])){
$_value = $_post[$_field];
if(is_array($_value)){
$_value = implode(", ", array_diff($_value, array('')) );
}
if(!empty($_value)){
$result[] = "".$_name.": ".$_value."
";
}
}
}
}
return implode("\n", $result);
}
function admin_email_send($data = array()){
if(empty($data['headers'])){
$data['headers'] = array(
'From: noreply@'.$_SERVER['HTTP_HOST'].' ',
'Content-type: text/html; charset=utf-8',
);
}
if(empty($data['attachments'])){
$data['attachments'] = null;
}
if(empty($admin_email)){
$admin_email = get_field('admin_email', 'option');
}
if(empty($admin_email)){
$admin_email = get_option('admin_email');
}
if(!empty($admin_email)){
$responce = wp_mail( $admin_email, $data['subject'], $data['message'], $data['headers'], $data['attachments'] );
}
}
add_action( 'wp_ajax_js_form', 'ajax_js_form' );
add_action( 'wp_ajax_nopriv_js_form', 'ajax_js_form' );
function ajax_js_form(){
// $_SERVER['HTTP_HOST'] = 'барбекю26.рф';
$_SERVER['AJAX'] = array(
'_POST' => $_POST,
);
if(!empty($_POST['callback'])){
$_SERVER['AJAX']['callback'] = $_POST['callback'];
}
$_type = !empty($_POST['type']) ? $_POST['type'] : '';
$_fields = array();
if(!empty($_POST['_fields'])){
$base64 = base64_decode( $_POST['_fields'] );
if(!empty($base64)){
$unserialize = unserialize( $base64 );
if(!empty($unserialize)){
$_fields = $unserialize;
}
}
unset($_POST['_fields']);
}
$_post = $_POST;
$post_name = md5( microtime() );
$guid = "https://".$_SERVER['HTTP_HOST']."/application/?id=".$post_name;
$post_title = "Заявка с сайта ".$_SERVER['HTTP_HOST'];
$post_content = get_text_fields($_fields, $_post);
$attachments = [];
if($_type == 'review'){
if(!empty($_POST['product_id'])){
$data = array(
'comment_post_ID' => $_POST['product_id'],
'comment_author' => $_POST['name'],
'comment_content' => $_POST['text'],
'comment_type' => 'review',
'comment_date' => current_time('mysql'),
'comment_approved' => 0,
);
$comment_ID = wp_insert_comment($data);
if(is_numeric($comment_ID)){
add_comment_meta( $comment_ID, 'rating', $_POST['rating'], true);
}
}
$subject = 'Отзыв на сайте';
$message = $post_content;
}
else{
$meta_input = array(
'_fields' => $_fields,
'_post' => $_post,
);
$post_data = array(
'post_name' => $post_name,
'post_content' => $post_content,
'guid' => $guid,
'meta_input' => $meta_input,
'post_status' => 'private',
'post_type' => 'application',
);
$post_id = wp_insert_post( $post_data );
if(is_numeric($post_id)){
$post_title = $post_title." №".$post_id;
$_post_data = array(
'ID' => $post_id,
'post_title' => $post_title,
);
$upload_files = array(
'upload_file' => 'file',
);
foreach($upload_files as $key => $value){
$media_ids = upload_files($key, $post_id);
if(!empty($media_ids)){
$_post_data['meta_input'][$value] = $media_ids;
}
}
wp_update_post( $_post_data );
}
$subject = $post_title;
$message = $post_content;
}
if(!empty($media_ids)){
$_args = array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'post__in' => $media_ids,
);
$wp_query_attachment = new WP_Query($_args);
if(!empty($wp_query_attachment->posts)){
foreach ($wp_query_attachment->posts as $post){
$attachments[] = get_path_form_url($post->guid);
}
}
}
if(!empty($subject) && !empty($message)){
admin_email_send( array(
'subject' => $subject,
'message' => $message,
'attachments' => $attachments,
) );
// telegram_message($subject."\n".$message);
}
if(!empty($_SERVER['AJAX'])){
wp_die( json_encode($_SERVER['AJAX']) );
}
}
function upload_files($name = '', $post_id = 0){
$result = [];
if(!empty($_FILES[$name])){
$files = $_FILES[$name];
if(!empty($files['name'])){
foreach($files['name'] as $key => $value){
if(!empty($value)){
$file = array(
'name' => $files['name'][ $key ],
'type' => $files['type'][ $key ],
'tmp_name' => $files['tmp_name'][ $key ],
'error' => $files['error'][ $key ],
'size' => $files['size'][ $key ],
);
$media_id = media_handle_sideload($file, $post_id);
if(is_numeric($media_id)){
$result[] = $media_id;
}
}
}
}
}
return $result;
}
function get_path_form_url($url){
$data = parse_url($url);
if(!empty($data['path'])){
return ABSPATH . substr($data['path'], 1);
}
}
add_filter( 'show_admin_bar', '__return_false' );
add_action('add_meta_boxes', 'true_add_metabox');
function true_add_metabox() {
add_meta_box(
'application_metabox',
'Метаданные',
'application_metabox_callback',
'application',
'normal',
'default'
);
}
function application_metabox_callback( $post ) {
$_meta = get_post_meta( $post->ID );
$_fields = array();
$_post = array();
if(!empty($_meta['_fields'][0])){
$_fields = unserialize($_meta['_fields'][0]);
}
if(!empty($_meta['_post'][0])){
$_post = unserialize($_meta['_post'][0]);
}
?>
Warning: Cannot modify header information - headers already sent by (output started at /home/fas5018853/fashtech.ru/docs/wp-content/themes/codex/functions.php:1) in /home/fas5018853/fashtech.ru/docs/wp-includes/pluggable.php on line 1535
Warning: Cannot modify header information - headers already sent by (output started at /home/fas5018853/fashtech.ru/docs/wp-content/themes/codex/functions.php:1) in /home/fas5018853/fashtech.ru/docs/wp-includes/pluggable.php on line 1538