Advertisement
Guest User

function.php

a guest
Dec 14th, 2017
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.61 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Odin functions and definitions.
  4.  *
  5.  * Sets up the theme and provides some helper functions, which are used in the
  6.  * theme as custom template tags. Others are attached to action and filter
  7.  * hooks in WordPress to change core functionality.
  8.  *
  9.  * For more information on hooks, actions, and filters,
  10.  * see http://codex.wordpress.org/Plugin_API
  11.  *
  12.  * @package Odin
  13.  * @since 2.2.0
  14.  */
  15.  
  16. define('VERSION', '1.0.3');
  17.  
  18.  
  19. function mailtrap($phpmailer) {
  20.     $phpmailer->isSMTP();
  21.     $phpmailer->Host = 'smtp.mailtrap.io';
  22.     $phpmailer->SMTPAuth = true;
  23.     $phpmailer->Port = 2525;
  24.     $phpmailer->Username = '18bbd30e953f63';
  25.     $phpmailer->Password = 'df157129a86998';
  26. }
  27.  
  28. add_action('phpmailer_init', 'mailtrap');
  29.  
  30.     /*
  31.         Enviando contato para a gestão de Leads do Eleve Crm
  32.     */
  33.     add_action('wpcf7_before_send_mail', 'wpcf7_to_web_service');
  34.     function wpcf7_to_web_service ($WPCF7_ContactForm) {
  35.  
  36.         $submission = WPCF7_Submission::get_instance();
  37.  
  38.         $posted_data =& $submission->get_posted_data();
  39.  
  40.         if(!empty($posted_data))
  41.         {
  42.             $api_url = 'http://localhost/eleve/crm/api/1.0/leads';
  43.             $data_contato['token_conta']   = '6ec23dad0d30abd';
  44.             $data_contato['nome_lead']     = $posted_data['nome'];
  45.             $data_contato['email_lead']    = $posted_data['email'];
  46.  
  47.             if (isset($posted_data['form_planos']) && $posted_data['form_planos'] == 1)
  48.             {
  49.                 $data_contato['telefone_lead'] = $posted_data['telefone'];
  50.                 $data_contato['origem_lead']   = 'planos-site-optcon-rh';
  51.  
  52.                 $empresa = array(
  53.                     'campo'      => 'Empresa',
  54.                     'campo_slug' => 'empresa',
  55.                     'valor'      => $posted_data['empresa']
  56.                 );
  57.  
  58.                 $assunto  = array(
  59.                     'campo'      => 'Assunto',
  60.                     'campo_slug' => 'assunto',
  61.                     'valor'      => $posted_data['assunto']
  62.                 );
  63.  
  64.                 $data_contato['custom']  = array($empresa, $assunto);
  65.              } else if (isset($posted_data['form_contato']) && $posted_data['form_contato'] == 1)
  66.              {
  67.                 $data_contato['origem_lead']   = 'contato-site-optcon-rh';
  68.  
  69.                 $assunto  = array(
  70.                     'campo'      => 'Assunto',
  71.                     'campo_slug' => 'assunto',
  72.                     'valor'      => $posted_data['assunto']
  73.                 );
  74.  
  75.                 $mensagem = array(
  76.                     'campo'      => 'Mensagem',
  77.                     'campo_slug' => 'mensagem',
  78.                     'valor'      => $posted_data['mensagem']
  79.                 );
  80.              }
  81.  
  82.                $args = array(
  83.                     'body' => $data_contato,
  84.                     'timeout' => '5',
  85.                     'redirection' => '5',
  86.                     'httpversion' => '1.0',
  87.                     'blocking' => true,
  88.                     'headers' => array('Content-Type: application/json'),
  89.                     'cookies' => array()
  90.                 );
  91.  
  92.                 $response = wp_remote_post( $api_url, $args );
  93.  
  94.         }
  95.     }
  96.  
  97.  
  98.  
  99.  
  100.  
  101. /**
  102.  * Sets content width.
  103.  */
  104. if ( ! isset( $content_width ) ) {
  105.     $content_width = 600;
  106. }
  107.  
  108. if ( ENV == 'development' ) {
  109.     function mailtrap($phpmailer) {
  110.       $phpmailer->isSMTP();
  111.       $phpmailer->Host = 'smtp.mailtrap.io';
  112.       $phpmailer->SMTPAuth = true;
  113.       $phpmailer->Port = 2525;
  114.       $phpmailer->Username = '49efdfc29ec556';
  115.       $phpmailer->Password = 'a8a0d797c97bd8';
  116.     }
  117.  
  118.     add_action('phpmailer_init', 'mailtrap');
  119. }
  120.  
  121. /**
  122.  * Odin Classes.
  123.  */
  124. require_once get_template_directory() . '/core/classes/class-bootstrap-nav.php';
  125. require_once get_template_directory() . '/core/classes/class-shortcodes.php';
  126. //require_once get_template_directory() . '/core/classes/class-shortcodes-menu.php';
  127. require_once get_template_directory() . '/core/classes/class-thumbnail-resizer.php';
  128. // require_once get_template_directory() . '/core/classes/class-theme-options.php';
  129. // require_once get_template_directory() . '/core/classes/class-options-helper.php';
  130. require_once get_template_directory() . '/core/classes/class-post-type.php';
  131. // require_once get_template_directory() . '/core/classes/class-taxonomy.php';
  132. // require_once get_template_directory() . '/core/classes/class-metabox.php';
  133. // require_once get_template_directory() . '/core/classes/abstracts/abstract-front-end-form.php';
  134. // require_once get_template_directory() . '/core/classes/class-contact-form.php';
  135. // require_once get_template_directory() . '/core/classes/class-post-form.php';
  136. // require_once get_template_directory() . '/core/classes/class-user-meta.php';
  137. // require_once get_template_directory() . '/core/classes/class-post-status.php';
  138. //require_once get_template_directory() . '/core/classes/class-term-meta.php';
  139.  
  140. /**
  141.  * Odin Widgets.
  142.  */
  143. require_once get_template_directory() . '/core/classes/widgets/class-widget-like-box.php';
  144.  
  145. if ( ! function_exists( 'odin_setup_features' ) ) {
  146.  
  147.     /**
  148.      * Setup theme features.
  149.      *
  150.      * @since 2.2.0
  151.      */
  152.     function odin_setup_features() {
  153.  
  154.         /**
  155.          * Add support for multiple languages.
  156.          */
  157.         load_theme_textdomain( 'odin', get_template_directory() . '/languages' );
  158.  
  159.         /**
  160.          * Register nav menus.
  161.          */
  162.         register_nav_menus(
  163.             array(
  164.                 'main-menu' => __( 'Main Menu', 'odin' )
  165.             )
  166.         );
  167.  
  168.         /*
  169.          * Add post_thumbnails suport.
  170.          */
  171.         add_theme_support( 'post-thumbnails' );
  172.  
  173.         /**
  174.          * Add feed link.
  175.          */
  176.         add_theme_support( 'automatic-feed-links' );
  177.  
  178.         /**
  179.          * Support Custom Header.
  180.          */
  181.         $default = array(
  182.             'width'         => 0,
  183.             'height'        => 0,
  184.             'flex-height'   => false,
  185.             'flex-width'    => false,
  186.             'header-text'   => false,
  187.             'default-image' => '',
  188.             'uploads'       => true,
  189.         );
  190.  
  191.         add_theme_support( 'custom-header', $default );
  192.  
  193.         /**
  194.          * Support Custom Background.
  195.          */
  196.         $defaults = array(
  197.             'default-color' => '',
  198.             'default-image' => '',
  199.         );
  200.  
  201.         add_theme_support( 'custom-background', $defaults );
  202.  
  203.         /**
  204.          * Support Custom Editor Style.
  205.          */
  206.         add_editor_style( 'assets/css/editor-style.css' );
  207.  
  208.         /**
  209.          * Add support for infinite scroll.
  210.          */
  211.         add_theme_support(
  212.             'infinite-scroll',
  213.             array(
  214.                 'type'           => 'scroll',
  215.                 'footer_widgets' => false,
  216.                 'container'      => 'content',
  217.                 'wrapper'        => false,
  218.                 'render'         => false,
  219.                 'posts_per_page' => get_option( 'posts_per_page' )
  220.             )
  221.         );
  222.  
  223.         /**
  224.          * Add support for Post Formats.
  225.          */
  226.         // add_theme_support( 'post-formats', array(
  227.         //     'aside',
  228.         //     'gallery',
  229.         //     'link',
  230.         //     'image',
  231.         //     'quote',
  232.         //     'status',
  233.         //     'video',
  234.         //     'audio',
  235.         //     'chat'
  236.         // ) );
  237.  
  238.         /**
  239.          * Support The Excerpt on pages.
  240.          */
  241.         // add_post_type_support( 'page', 'excerpt' );
  242.  
  243.         /**
  244.          * Switch default core markup for search form, comment form, and comments to output valid HTML5.
  245.          */
  246.         add_theme_support(
  247.             'html5',
  248.             array(
  249.                 'search-form',
  250.                 'comment-form',
  251.                 'comment-list',
  252.                 'gallery',
  253.                 'caption'
  254.             )
  255.         );
  256.  
  257.         /*
  258.          * Let WordPress manage the document title.
  259.          * By adding theme support, we declare that this theme does not use a
  260.          * hard-coded <title> tag in the document head, and expect WordPress to
  261.          * provide it for us.
  262.          */
  263.         add_theme_support( 'title-tag' );
  264.  
  265.         /*
  266.          * Enable support for custom logo.
  267.          *
  268.          *  @since Odin 2.2.10
  269.          */
  270.         add_theme_support( 'custom-logo', array(
  271.             'height'      => 240,
  272.             'width'       => 240,
  273.             'flex-height' => true,
  274.         ) );
  275.     }
  276. }
  277.  
  278. add_action( 'after_setup_theme', 'odin_setup_features' );
  279.  
  280. /**
  281.  * Register widget areas.
  282.  *
  283.  * @since 2.2.0
  284.  */
  285. function odin_widgets_init() {
  286.     register_sidebar(
  287.         array(
  288.             'name' => __( 'Main Sidebar', 'odin' ),
  289.             'id' => 'main-sidebar',
  290.             'description' => __( 'Site Main Sidebar', 'odin' ),
  291.             'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  292.             'after_widget' => '</aside>',
  293.             'before_title' => '<h3 class="widgettitle widget-title">',
  294.             'after_title' => '</h3>',
  295.         )
  296.     );
  297. }
  298.  
  299. add_action( 'widgets_init', 'odin_widgets_init' );
  300.  
  301. /**
  302.  * Flush Rewrite Rules for new CPTs and Taxonomies.
  303.  *
  304.  * @since 2.2.0
  305.  */
  306. function odin_flush_rewrite() {
  307.     flush_rewrite_rules();
  308. }
  309.  
  310. add_action( 'after_switch_theme', 'odin_flush_rewrite' );
  311.  
  312. /**
  313.  * Load site scripts.
  314.  *
  315.  * @since 2.2.0
  316.  */
  317. function odin_enqueue_scripts() {
  318.     $template_url = get_template_directory_uri();
  319.  
  320.     // Loads Odin main stylesheet.
  321.     wp_enqueue_style( 'odin-style', get_stylesheet_uri(), array(), null, 'all' );
  322.  
  323.     // jQuery.
  324.     wp_enqueue_script( 'jquery' );
  325.  
  326.     // Html5Shiv
  327.     wp_enqueue_script( 'html5shiv', $template_url . '/assets/js/html5.js' );
  328.     wp_script_add_data( 'html5shiv', 'conditional', 'lt IE 9' );
  329.  
  330.     // General scripts.
  331.     if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
  332.         // Bootstrap.
  333.         wp_enqueue_script( 'bootstrap', $template_url . '/assets/js/libs/bootstrap.min.js', array(), null, true );
  334.  
  335.         // FitVids.
  336.         wp_enqueue_script( 'fitvids', $template_url . '/assets/js/libs/jquery.fitvids.js', array(), null, true );
  337.  
  338.         // Main jQuery.
  339.         wp_enqueue_script( 'odin-main', $template_url . '/assets/js/main.js', array(), null, true );
  340.     } else {
  341.         // Grunt main file with Bootstrap, FitVids and others libs.
  342.         wp_enqueue_script( 'odin-main-min', $template_url . '/assets/js/main.min.js', array(), null, true );
  343.     }
  344.  
  345.     // Grunt watch livereload in the browser.
  346.     // wp_enqueue_script( 'odin-livereload', 'http://localhost:35729/livereload.js?snipver=1', array(), null, true );
  347.  
  348.     // Load Thread comments WordPress script.
  349.     if ( is_singular() && get_option( 'thread_comments' ) ) {
  350.         wp_enqueue_script( 'comment-reply' );
  351.     }
  352. }
  353.  
  354. add_action( 'wp_enqueue_scripts', 'odin_enqueue_scripts', 1 );
  355.  
  356. /**
  357.  * Odin custom stylesheet URI.
  358.  *
  359.  * @since  2.2.0
  360.  *
  361.  * @param  string $uri Default URI.
  362.  * @param  string $dir Stylesheet directory URI.
  363.  *
  364.  * @return string      New URI.
  365.  */
  366. function odin_stylesheet_uri( $uri, $dir ) {
  367.     return $dir . '/assets/css/style.css';
  368. }
  369.  
  370. add_filter( 'stylesheet_uri', 'odin_stylesheet_uri', 10, 2 );
  371.  
  372. /**
  373.  * Query WooCommerce activation
  374.  *
  375.  * @since  2.2.6
  376.  *
  377.  * @return boolean
  378.  */
  379. if ( ! function_exists( 'is_woocommerce_activated' ) ) {
  380.     function is_woocommerce_activated() {
  381.         return class_exists( 'woocommerce' ) ? true : false;
  382.     }
  383. }
  384.  
  385. /**
  386.  * Core Helpers.
  387.  */
  388. require_once get_template_directory() . '/core/helpers.php';
  389.  
  390. /**
  391.  * WP Custom Admin.
  392.  */
  393. require_once get_template_directory() . '/inc/admin.php';
  394.  
  395. /**
  396.  * Comments loop.
  397.  */
  398. require_once get_template_directory() . '/inc/comments-loop.php';
  399.  
  400. /**
  401.  * Custom Partners.
  402.  */
  403. require_once get_template_directory() . '/inc/custom-post-types.php';
  404.  
  405. /**
  406.  * WP optimize functions.
  407.  */
  408. require_once get_template_directory() . '/inc/optimize.php';
  409.  
  410. /**
  411.  * Custom template tags.
  412.  */
  413. require_once get_template_directory() . '/inc/template-tags.php';
  414.  
  415. /**
  416.  * WooCommerce compatibility files.
  417.  */
  418. // if ( is_woocommerce_activated() ) {
  419. //  add_theme_support( 'woocommerce' );
  420. //  require get_template_directory() . '/inc/woocommerce/hooks.php';
  421. //  require get_template_directory() . '/inc/woocommerce/functions.php';
  422. //  require get_template_directory() . '/inc/woocommerce/template-tags.php';
  423. // }
  424.  
  425. /**
  426.  * Remove wordpress admin bar.
  427.  */
  428. show_admin_bar( false );
  429.  
  430. /**
  431.  * Remove post menu item.
  432.  */
  433. add_action( 'admin_menu','remove_default_post_type' );
  434. function remove_default_post_type() {
  435.     remove_menu_page( 'edit.php' );
  436. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement