'fail', 'error' => 'Some of the fields are not ')) if ( !isset($_REQUEST['contact_message']) || $_REQUEST['contact_message'] == '' ) throw new Exception('Message is not set'); //echo json_decode((object)array('status' => 'fail', 'error' => 'Some of the fields are not ')) if ( !isset($_REQUEST['contact_email']) || $_REQUEST['contact_email'] == '' ) throw new Exception('Email is not set'); //echo json_decode((object)array('status' => 'fail', 'error' => 'Some of the fields are not ')) $contact = get_kob_object( 'contact_settings' ); $to = $contact->contact_many->contact_form->value; if ( !$to || $contact->contact_many->contact_form->flag == false ) $to = get_option('admin_email'); $form_name = $_REQUEST['contact_name']; $form_email = $_REQUEST['contact_email']; $form_message = $_REQUEST['contact_message']; $subject = 'Contact Form submitted'; $text = $form_message; $text .= "\n" . 'From ' . $form_name . ' (' . $form_email . ')'; $text .= "\n" . 'This letter was generated by robot, please do not answer this'; $send_result = wp_mail( $to, $subject, $text ); if( !$send_result ) throw new Exception('Error while sending message'); echo json_encode((object)array('status' => 'ok', 'text' => 'Form submitted successfully')); } catch (Exception $e) { echo json_encode((object)array('status' => 'fail', 'text' => $e->getMessage())); } wp_die(); } add_action('wp_ajax_contact', 'process_contact'); add_action('wp_ajax_nopriv_contact', 'process_contact'); # Process subscribe form submission function process_subscribe() { try { if ( empty($_POST) || !wp_verify_nonce( $_POST['security-code-here'], 'subscribe' ) ) throw new Exception('Security code error'); $prefooter = get_kob_object('prefooter_settings'); $raw_api_key = $prefooter->prefooter_many->prefooter_columns->content->prefooter_column_subscribe->value->prefooter_column_subscribe_val_subtitle_api_key; $api_key_tokens = explode('-', $raw_api_key); $list_id = $prefooter->prefooter_many->prefooter_columns->content->prefooter_column_subscribe->value->prefooter_column_subscribe_val_subtitle_api_list; $api_key = $api_key_tokens[0]; // '54f86fa9704cfe780c843b03fa19c0aa'; $dc = $api_key_tokens[1]; // дата-центр MailChimp $email = $_REQUEST['email']; $url = "https://$dc.api.mailchimp.com/2.0/lists/subscribe.json"; $request = wp_remote_post( $url, array( 'body' => json_encode( array( 'apikey' => $api_key, 'id' => $list_id, 'email' => array( 'email' => $email ), ) ), ) ); $result = json_decode( wp_remote_retrieve_body( $request ) ); if ( $result->status == 'error' ) throw new Exception('Error while subscribing: ' . $result->error); echo json_encode((object)array('status' => 'ok', 'text' => 'Successfully subscribed!')); } catch (Exception $e) { echo json_encode((object)array('status' => 'fail', 'text' => $e->getMessage())); } wp_die(); } add_action('wp_ajax_subscribe', 'process_subscribe'); add_action('wp_ajax_nopriv_subscribe', 'process_subscribe'); # Add woocommerce support function woocommerce_support() { add_theme_support( 'woocommerce' ); } add_action( 'after_setup_theme', 'woocommerce_support' ); # Add reddy-section to wp admin bar's "customize" button function customize_toolbar() { global $wp_admin_bar; $arr = $wp_admin_bar->get_nodes(); if ( isset( $arr['customize'] ) ) { $customize = $arr['customize']; if ( is_post_type_archive( 'portfolio' ) ) $customize->href = admin_url( 'customize.php?reddy-section=section_portfolio&url=' . get_post_type_archive_link( 'portfolio' ) ); if ( is_page_template( 'templates/slider-page.php' ) ) $customize->href = admin_url( 'customize.php?reddy-section=section_slider&url=' . get_permalink() ); if ( is_page_template( 'templates/contact-page.php' ) ) $customize->href = admin_url( 'customize.php?reddy-section=section_contact&url=' . get_permalink() ); if ( is_home() ) $customize->href = admin_url( 'customize.php?reddy-section=section_blog&url=' . home_url('/') ); if ( is_category() ) { $categories = get_the_category(); $category_id = $categories[0]->cat_ID; $customize->href = admin_url( 'customize.php?reddy-section=section_blog&url=' . get_category_link( $category_id ) ); } if ( is_singular( 'portfolio' ) ) { $customize->href = admin_url( 'customize.php?reddy-section=section_portfolio&url=' . get_permalink() ); } foreach($arr as $key => $node) { if( $node->id == 'customize' ) $node = $customize; $wp_admin_bar->remove_node( $key ); $wp_admin_bar->add_node( $node ); } } } add_action( 'wp_before_admin_bar_render', 'customize_toolbar', 999 ); # Excerpt end to ellipsis function new_excerpt_more( $more ) { return '...'; } add_filter( 'excerpt_more', 'new_excerpt_more' ); # Excert length to 20 function custom_excerpt_length( $length ) { return 20; } add_filter( 'excerpt_length', 'custom_excerpt_length', 999 ); # Add .img-unwrap to embed p's function filter_ptags_on_embeds($content) { $content = preg_replace('/

(\s*)()(\s*)<\/p>/iU', '

\2

', $content); $content = preg_replace('/

(\s*)(.*<\/iframe>)(\s*)<\/p>/iU', '

\2

', $content); $content = preg_replace('/

(\s*)()(\s*)<\/p>/iU', '

\2

', $content); $content = preg_replace('/

(\s*)(.*<\/embed>)(\s*)<\/p>/iU', '

\2

', $content); return $content; } add_filter('the_content', 'filter_ptags_on_embeds');