Guest User

Contact form 7

a guest
Sep 22nd, 2015
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.30 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * vantage functions and definitions
  5.  *
  6.  * @package vantage
  7.  * @since vantage 1.0
  8.  * @license GPL 2.0
  9.  */
  10.  
  11. define( 'SITEORIGIN_THEME_VERSION' , '1.4.2' );
  12. define('SITEORIGIN_THEME_ENDPOINT', 'http://updates.siteorigin.com/');
  13.  
  14. if( file_exists( get_template_directory() . '/premium/functions.php' ) ){
  15.     include get_template_directory() . '/premium/functions.php';
  16. }
  17. else {
  18.     include get_template_directory() . '/upgrade/upgrade.php';
  19. }
  20.  
  21. // Include all the SiteOrigin extras
  22. include get_template_directory() . '/extras/settings/settings.php';
  23. include get_template_directory() . '/extras/premium/premium.php';
  24. include get_template_directory() . '/extras/update/update.php';
  25. include get_template_directory() . '/extras/adminbar/adminbar.php';
  26. include get_template_directory() . '/extras/plugin-activation/plugin-activation.php';
  27. include get_template_directory() . '/extras/metaslider/metaslider.php';
  28.  
  29. // Load the theme specific files
  30. include get_template_directory() . '/inc/panels.php';
  31. include get_template_directory() . '/inc/settings.php';
  32. include get_template_directory() . '/inc/extras.php';
  33. include get_template_directory() . '/inc/template-tags.php';
  34. include get_template_directory() . '/inc/gallery.php';
  35. include get_template_directory() . '/inc/metaslider.php';
  36. include get_template_directory() . '/inc/widgets.php';
  37. include get_template_directory() . '/inc/menu.php';
  38. include get_template_directory() . '/inc/woocommerce.php';
  39. include get_template_directory() . '/inc/seo.php';
  40. include get_template_directory() . '/tour/tour.php';
  41.  
  42. include get_template_directory() . '/fontawesome/icon-migration.php';
  43.  
  44.  
  45. if ( ! function_exists( 'vantage_setup' ) ) :
  46. /**
  47.  * Sets up theme defaults and registers support for various WordPress features.
  48.  *
  49.  * Note that this function is hooked into the after_setup_theme hook, which runs
  50.  * before the init hook. The init hook is too late for some features, such as indicating
  51.  * support post thumbnails.
  52.  *
  53.  * @since vantage 1.0
  54.  */
  55. function vantage_setup() {
  56.  
  57.     // Initialize SiteOrigin settings
  58.     siteorigin_settings_init();
  59.    
  60.     // Make the theme translatable
  61.     load_theme_textdomain( 'vantage', get_template_directory() . '/languages' );
  62.  
  63.     // Add default posts and comments RSS feed links to head
  64.     add_theme_support( 'automatic-feed-links' );
  65.  
  66.     // Enable support for Post Thumbnails
  67.     add_theme_support( 'post-thumbnails' );
  68.  
  69.     add_theme_support( 'siteorigin-panels', array(
  70.         'home-page' => true,
  71.         'margin-bottom' => 35,
  72.         'home-page-default' => 'default-home',
  73.         'home-demo-template' => 'home-panels.php',
  74.         'responsive' => siteorigin_setting( 'layout_responsive' ),
  75.     ) );
  76.  
  77.     // This theme uses wp_nav_menu() in one location.
  78.     register_nav_menus( array(
  79.         'primary' => __( 'Primary Menu', 'vantage' ),
  80.     ) );
  81.  
  82.     // Enable support for Post Formats
  83.     add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link' ) );
  84.  
  85.     // We support WooCommerce
  86.     add_theme_support('woocommerce');
  87.     // define('WOOCOMMERCE_USE_CSS', false);
  88.  
  89.     set_post_thumbnail_size(720, 380, true);
  90.     add_image_size('vantage-thumbnail-no-sidebar', 1080, 380, true);
  91.     add_image_size('vantage-slide', 960, 480, true);
  92.     add_image_size('vantage-carousel', 272, 182, true);
  93.     add_image_size('vantage-grid-loop', 436, 272, true);
  94.  
  95.     add_theme_support( 'site-logo', array(
  96.         'size' => 'full',
  97.     ) );
  98.  
  99.     if( !defined('SITEORIGIN_PANELS_VERSION') && !siteorigin_plugin_activation_is_activating('siteorigin-panels') ){
  100.         // Only include panels lite if the panels plugin doesn't exist
  101.         include get_template_directory() . '/inc/panels-lite/panels-lite.php';
  102.     }
  103.  
  104.     add_theme_support('siteorigin-premium-teaser', array(
  105.         'customizer' => true,
  106.         'settings' => true,
  107.     ));
  108.  
  109.     global $content_width, $vantage_site_width;
  110.     if ( ! isset( $content_width ) ) $content_width = 720; /* pixels */
  111.  
  112.     if ( ! isset( $vantage_site_width ) ) {
  113.         $vantage_site_width = siteorigin_setting('layout_bound') == 'full' ? 1080 : 1010;
  114.     }
  115.  
  116.     $container = 'content';
  117.     $render_function = '';
  118.     $wrapper = true;
  119.     // The posts_per_page setting only works when type is 'scroll'.
  120.     // When type is set to 'click' either explicitly or automatically,
  121.     // due to there being footer widgets, it uses the "Blog pages show at most X posts" setting
  122.     // under Settings > Reading instead. :(
  123.     // https://wordpress.org/support/topic/posts_per_page-not-having-any-effect
  124.     $posts_per_page = 7;
  125.     if ( siteorigin_setting( 'blog_archive_layout' ) == 'circleicon' ) {
  126.         $container = 'vantage-circleicon-loop';
  127.         $render_function = 'vantage_infinite_scroll_render';
  128.         $wrapper = false;
  129.         $posts_per_page = 6;
  130.     }
  131.     else if ( siteorigin_setting( 'blog_archive_layout' ) == 'grid' ) {
  132.         $container = 'vantage-grid-loop';
  133.         $render_function = 'vantage_infinite_scroll_render';
  134.         $wrapper = false;
  135.         $posts_per_page = 8;
  136.     }
  137.  
  138.     add_filter( 'infinite_scroll_settings', 'vantage_infinite_scroll_settings' );
  139.  
  140.     add_theme_support( 'infinite-scroll', array(
  141.         'container' => $container,
  142.         'footer' => 'page',
  143.         'render' => $render_function,
  144.         'wrapper' => $wrapper,
  145.         'posts_per_page' => $posts_per_page,
  146.         'type' => 'click',
  147. //      'footer_widgets' => 'sidebar-footer',
  148.     ) );
  149. }
  150. endif; // vantage_setup
  151. add_action( 'after_setup_theme', 'vantage_setup' );
  152.  
  153. // Override Jetpack Infinite Scroll default behaviour of ignoring explicit posts_per_page setting when type is 'click'.
  154. function vantage_infinite_scroll_settings( $settings ) {
  155.     if ( $settings['type'] == 'click' ) {
  156.         if( siteorigin_setting( 'blog_archive_layout' ) == 'circleicon' ) {
  157.             $settings['posts_per_page'] = 6;
  158.         }
  159.         else if ( siteorigin_setting( 'blog_archive_layout' ) == 'grid' ) {
  160.             $settings['posts_per_page'] = 8;
  161.         }
  162.     }
  163.     return $settings;
  164. }
  165.  
  166. function vantage_infinite_scroll_render() {
  167.     ob_start();
  168.     get_template_part( 'loops/loop', siteorigin_setting( 'blog_archive_layout' ) );
  169.     $var = ob_get_clean();
  170.     // Strip leading and trailing whitespace.
  171.     $var = trim( $var );
  172.     // Remove the opening and closing div tags for subsequent pages of posts for correct circleicon and grid layouts.
  173.     $var = preg_replace( '/^<div.+>/', '', $var );
  174.     $var = preg_replace( '/<\/div>$/', '', $var );
  175.     echo $var;
  176. }
  177.  
  178. /**
  179.  * Setup the WordPress core custom background feature.
  180.  *
  181.  * @since vantage 1.0
  182.  */
  183. function vantage_register_custom_background() {
  184.  
  185.     if(siteorigin_setting('layout_bound') == 'boxed') {
  186.         $args = array(
  187.             'default-color' => 'e8e8e8',
  188.             'default-image' => '',
  189.         );
  190.  
  191.         $args = apply_filters( 'vantage_custom_background_args', $args );
  192.         add_theme_support( 'custom-background', $args );
  193.     }
  194.  
  195. }
  196. add_action( 'after_setup_theme', 'vantage_register_custom_background' );
  197.  
  198. /**
  199.  * Register widgetized area and update sidebar with default widgets
  200.  *
  201.  * @since vantage 1.0
  202.  */
  203. function vantage_widgets_init() {
  204.     register_sidebar( array(
  205.         'name' => __( 'Sidebar', 'vantage' ),
  206.         'id' => 'sidebar-1',
  207.         'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  208.         'after_widget' => '</aside>',
  209.         'before_title' => '<h3 class="widget-title">',
  210.         'after_title' => '</h3>',
  211.     ) );
  212.  
  213.     register_sidebar( array(
  214.         'name' => __( 'Footer', 'vantage' ),
  215.         'id' => 'sidebar-footer',
  216.         'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  217.         'after_widget' => '</aside>',
  218.         'before_title' => '<h3 class="widget-title">',
  219.         'after_title' => '</h3>',
  220.     ) );
  221.  
  222.     register_sidebar( array(
  223.         'name' => __( 'Header', 'vantage' ),
  224.         'id' => 'sidebar-header',
  225.         'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  226.         'after_widget' => '</aside>',
  227.         'before_title' => '<h3 class="widget-title">',
  228.         'after_title' => '</h3>',
  229.     ) );
  230. }
  231. add_action( 'widgets_init', 'vantage_widgets_init' );
  232.  
  233. function vantage_print_styles(){
  234.     if( !siteorigin_setting('layout_responsive') ) return;
  235.  
  236.     // Create the footer widget CSS
  237.     $sidebars_widgets = wp_get_sidebars_widgets();
  238.     $count = isset($sidebars_widgets['sidebar-footer']) ? count($sidebars_widgets['sidebar-footer']) : 1;
  239.     $count = max($count,1);
  240.  
  241.     ?>
  242.     <style type="text/css" media="screen">
  243.         #footer-widgets .widget { width: <?php echo round(100/$count,3) . '%' ?>; }
  244.         @media screen and (max-width: 640px) {
  245.             #footer-widgets .widget { width: auto; float: none; }
  246.         }
  247.     </style>
  248.     <?php
  249. }
  250. add_action('wp_head', 'vantage_print_styles', 11);
  251.  
  252. /**
  253.  * Enqueue scripts and styles
  254.  */
  255. function vantage_scripts() {
  256.     wp_enqueue_style( 'vantage-style', get_stylesheet_uri(), array(), SITEORIGIN_THEME_VERSION );
  257.     wp_enqueue_style( 'vantage-fontawesome', get_template_directory_uri().'/fontawesome/css/font-awesome.css', array(), '4.2.0' );
  258.     $in_footer = siteorigin_setting( 'general_js_enqueue_footer' );
  259.     $js_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
  260.     wp_enqueue_script( 'vantage-flexslider' , get_template_directory_uri() . '/js/jquery.flexslider' . $js_suffix . '.js' , array('jquery'), '2.1', $in_footer );
  261.     wp_enqueue_script( 'vantage-touch-swipe' , get_template_directory_uri() . '/js/jquery.touchSwipe' . $js_suffix . '.js' , array( 'jquery' ), '1.6.6', $in_footer );
  262.     wp_enqueue_script( 'vantage-main' , get_template_directory_uri() . '/js/jquery.theme-main' . $js_suffix . '.js', array( 'jquery' ), SITEORIGIN_THEME_VERSION, $in_footer );
  263.  
  264.     if( siteorigin_setting( 'layout_fitvids' ) ) {
  265.         wp_enqueue_script( 'vantage-fitvids' , get_template_directory_uri() . '/js/jquery.fitvids' . $js_suffix . '.js' , array('jquery'), '1.0', $in_footer );
  266.     }
  267.  
  268.     if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  269.         wp_enqueue_script( 'comment-reply', $in_footer );
  270.     }
  271.  
  272.     if ( is_singular() && wp_attachment_is_image() ) {
  273.         wp_enqueue_script( 'vantage-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation' . $js_suffix . '.js', array( 'jquery' ), '20120202', $in_footer );
  274.     }
  275. }
  276. add_action( 'wp_enqueue_scripts', 'vantage_scripts' );
  277.  
  278. /**
  279.  * Enqueue any webfonts we need
  280.  */
  281. function vantage_web_fonts(){
  282.     if( !siteorigin_setting('logo_image') ) {
  283.         wp_enqueue_style('vantage-google-webfont-roboto', '//fonts.googleapis.com/css?family=Roboto:300');
  284.     }
  285. }
  286. add_action( 'wp_enqueue_scripts', 'vantage_scripts' );
  287.  
  288. function vantage_wp_head(){
  289.     ?>
  290.     <!--[if lt IE 9]>
  291.         <script src="<?php echo get_template_directory_uri(); ?>/js/html5.js" type="text/javascript"></script>
  292.     <![endif]-->
  293.     <!--[if (gte IE 6)&(lte IE 8)]>
  294.         <script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/js/selectivizr.js"></script>
  295.     <![endif]-->
  296.     <?php
  297. }
  298. add_action('wp_head', 'vantage_wp_head');
  299.  
  300. /**
  301.  * Display some text in the text area.
  302.  */
  303. function vantage_top_text_area(){
  304.     echo wp_kses_post( siteorigin_setting('logo_header_text') );
  305. }
  306. add_action('vantage_support_text', 'vantage_top_text_area');
  307.  
  308. /**
  309.  * Display the scroll to top link.
  310.  */
  311. function vantage_back_to_top() {
  312.     if( !siteorigin_setting('navigation_display_scroll_to_top') ) return;
  313.     ?><a href="#" id="scroll-to-top" title="<?php esc_attr_e('Back To Top', 'vantage') ?>"><span class="vantage-icon-arrow-up"></span></a><?php
  314. }
  315. add_action('wp_footer', 'vantage_back_to_top');
  316.  
  317. /**
  318.  * @return mixed
  319.  */
  320. function vantage_get_query_variables(){
  321.     global $wp_query;
  322.     $vars = $wp_query->query_vars;
  323.     foreach($vars as $k => $v) {
  324.         if(empty($vars[$k])) unset ($vars[$k]);
  325.     }
  326.     unset($vars['update_post_term_cache']);
  327.     unset($vars['update_post_meta_cache']);
  328.     unset($vars['cache_results']);
  329.     unset($vars['comments_per_page']);
  330.  
  331.     return $vars;
  332. }
  333.  
  334. /**
  335.  * Render the slider.
  336.  */
  337. function vantage_render_slider(){
  338.  
  339.     if( is_front_page() && siteorigin_setting('home_slider') != 'none' ) {
  340.         $settings_slider = siteorigin_setting( 'home_slider' );
  341.         $slider_stretch = siteorigin_setting( 'home_slider_stretch' );
  342.  
  343.         if(!empty($settings_slider)) {
  344.             $slider = $settings_slider;
  345.         }
  346.     }
  347.  
  348.     if( is_page() && get_post_meta(get_the_ID(), 'vantage_metaslider_slider', true) != 'none' ) {
  349.         $page_slider = get_post_meta(get_the_ID(), 'vantage_metaslider_slider', true);
  350.         if( !empty($page_slider) ) {
  351.             $slider = $page_slider;
  352.         }
  353.         $slider_stretch = get_post_meta(get_the_ID(), 'vantage_metaslider_slider_stretch', true);
  354.         if( $slider_stretch === '' ) {
  355.             // We'll default to whatever the home page slider stretch setting is
  356.             $slider_stretch = siteorigin_setting('home_slider_stretch');
  357.         }
  358.     }
  359.  
  360.     if( empty($slider) ) return;
  361.  
  362.     global $vantage_is_main_slider;
  363.     $vantage_is_main_slider = true;
  364.  
  365.     ?><div id="main-slider" <?php if( $slider_stretch ) echo 'data-stretch="true"' ?>><?php
  366.  
  367.  
  368.     if($slider == 'demo') get_template_part('slider/demo');
  369.     elseif( substr($slider, 0, 5) == 'meta:' ) {
  370.         list($null, $slider_id) = explode(':', $slider);
  371.         $slider_id = intval($slider_id);
  372.  
  373.         echo do_shortcode("[metaslider id=" . $slider_id . "]");
  374.     }
  375.  
  376.     ?></div><?php
  377.     $vantage_is_main_slider = false;
  378. }
  379.  
  380. function vantage_post_class_filter($classes){
  381.     $classes[] = 'post';
  382.  
  383.     if( has_post_thumbnail() && !is_singular() ) {
  384.         $classes[] = 'post-with-thumbnail';
  385.         $classes[] = 'post-with-thumbnail-' . siteorigin_setting('blog_featured_image_type');
  386.     }
  387.  
  388.     $classes = array_unique($classes);
  389.     return $classes;
  390. }
  391. add_filter('post_class', 'vantage_post_class_filter');
  392.  
  393. /**
  394.  * Filter the posted on parts to remove the ones disabled in settings.
  395.  *
  396.  * @param $parts
  397.  * @return mixed
  398.  */
  399. function vantage_filter_vantage_post_on_parts($parts){
  400.     if(!siteorigin_setting('blog_post_author')) $parts['by'] = '';
  401.     if(!siteorigin_setting('blog_post_date')) $parts['on'] = '';
  402.  
  403.     return $parts;
  404. }
  405. add_filter('vantage_post_on_parts', 'vantage_filter_vantage_post_on_parts');
  406.  
  407. /**
  408.  * Get the site width.
  409.  *
  410.  * @return int The side width in pixels.
  411.  */
  412. function vantage_get_site_width(){
  413.     return apply_filters('vantage_site_width', !empty($GLOBALS['vantage_site_width']) ? $GLOBALS['vantage_site_width'] : 1080);
  414. }
  415.  
  416. /**
  417.  * Add the responsive header
  418.  */
  419. function vantage_responsive_header(){
  420.     if( siteorigin_setting('layout_responsive') ) {
  421.         ?><meta name="viewport" content="width=device-width, initial-scale=1" /><?php
  422.     }
  423.     else {
  424.         ?><meta name="viewport" content="width=1280" /><?php
  425.     }
  426. }
  427. add_action('wp_head', 'vantage_responsive_header');
  428.  
  429. /**
  430.  
  431.  * Handles the site title, copyright symbol and year string replace for the Footer Copyright theme option.
  432.  
  433.  */
  434. function vantage_footer_site_info_sub($copyright){
  435.  
  436.     return str_replace(
  437.  
  438.         array('{site-title}', '{copyright}', '{year}'),
  439.  
  440.         array(get_bloginfo('name'), '&copy;', date('Y')),
  441.  
  442.         $copyright
  443.  
  444.     );
  445.  
  446. }
  447.  
  448. add_filter( 'vantage_site_info', 'vantage_footer_site_info_sub' );
  449.  
  450.  
  451.  
  452. /**
  453.  * Remove the text - 'You may use these <abbr title="HyperText Markup
  454.  * Language">HTML</abbr> tags ...'
  455.  * from below the comment entry box.
  456.  */
  457.  
  458. add_filter('comment_form_defaults', 'remove_comment_styling_prompt');
  459.  
  460. function remove_comment_styling_prompt($defaults) {
  461.     $defaults['comment_notes_after'] = '';
  462.     return $defaults;
  463. }
  464.  
  465. function create_user_from_registration($cfdata) {
  466.    
  467.     if (!isset($cfdata->posted_data) && class_exists('WPCF7_Submission')) {
  468.         // Contact Form 7 version 3.9 removed $cfdata->posted_data and now
  469.         // we have to retrieve it from an API
  470.         $submission = WPCF7_Submission::get_instance();
  471.         if ($submission) {
  472.             $formdata = $submission->get_posted_data();
  473.         }
  474.     } elseif (isset($cfdata->posted_data)) {
  475.         // For pre-3.9 versions of Contact Form 7
  476.         $formdata = $cfdata->posted_data;
  477.     } else {
  478.         // We can't retrieve the form data
  479.         return $cfdata;
  480.     }
  481.     // Check this is the user registration form
  482.     if ( $cfdata->title() == 'RegisterNewUser') {
  483.         $password = wp_generate_password( 12, false );
  484.         $email = $formdata['wp-email'];
  485.         $name = $formdata['wp-name'];
  486.         // Construct a username from the user's name
  487.         $username = strtolower(str_replace(' ', '', $name));
  488.         $name_parts = explode(' ',$name);
  489.         if ( !email_exists( $email ) ) {
  490.             // Find an unused username
  491.             $username_tocheck = $username;
  492.             $i = 1;
  493.             while ( username_exists( $username_tocheck ) ) {
  494.                 $username_tocheck = $username . $i++;
  495.             }
  496.             $username = $username_tocheck;
  497.             // Create the user
  498.             $userdata = array(
  499.                 'user_login' => $username,
  500.                 'user_pass' => $password,
  501.                 'user_email' => $email,
  502.                 'nickname' => reset($name_parts),
  503.                 'display_name' => $name,
  504.                 'first_name' => reset($name_parts),
  505.                 'last_name' => end($name_parts),
  506.                 'role' => 'subscriber'
  507.             );
  508.             $user_id = wp_insert_user( $userdata );
  509.             if ( !is_wp_error($user_id) ) {
  510.                 // Email login details to user
  511.                 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
  512.                 $message = "Welcome! Your login details are as follows:" . "\r\n";
  513.                 $message .= sprintf(__('Username: %s'), $username) . "\r\n";
  514.                 $message .= sprintf(__('Password: %s'), $password) . "\r\n";
  515.                 $message .= wp_login_url() . "\r\n";
  516.                 wp_mail($email, sprintf(__('[%s] Your username and password'), $blogname), $message);
  517.             }
  518.         }
  519.     }
  520.     return $cfdata;
  521. }
  522. add_action('wpcf7_before_send_mail', 'create_user_from_registration', 1);
Advertisement
Add Comment
Please, Sign In to add comment