Advertisement
Guest User

Untitled

a guest
Feb 5th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.73 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Sage includes
  5.  *
  6.  * The $sage_includes array determines the code library included in your theme.
  7.  * Add or remove files to the array as needed. Supports child theme overrides.
  8.  *
  9.  * Please note that missing files will produce a fatal error.
  10.  *
  11.  * @link https://github.com/roots/sage/pull/1042
  12.  */
  13. $sage_includes = [
  14.     'lib/assets.php', // Scripts and stylesheets
  15.     'lib/extras.php', // Custom functions
  16.     'lib/setup.php', // Theme setup
  17.     'lib/titles.php', // Page titles
  18.     'lib/wrapper.php', // Theme wrapper class
  19.     'lib/customizer.php' // Theme customizer
  20. ];
  21.  
  22. foreach ($sage_includes as $file) {
  23.     if (!$filepath = locate_template($file)) {
  24.         trigger_error(sprintf(__('Error locating %s for inclusion', 'sage'), $file), E_USER_ERROR);
  25.     }
  26.  
  27.     require_once $filepath;
  28. }
  29. unset($file, $filepath);
  30.  
  31.  
  32. //
  33.  
  34. add_action('template_redirect', function () {
  35.  
  36.     if (is_user_logged_in() && !is_user_member_of_blog())
  37.         die('Please ask the network administrator to get access to this blog.');
  38. });
  39.  
  40.  
  41. // Menus
  42. function register_my_menus_2()
  43. {
  44.     register_nav_menus(
  45.         array(
  46.             'pre-header-menu' => __('Pre Header Menu'),
  47.             'footer-menu-1' => __('Footer Menu 1'),
  48.             'footer-menu-2' => __('Footer Menu 2')
  49.         )
  50.     );
  51. }
  52.  
  53. add_action('init', 'register_my_menus_2');
  54.  
  55. // Function Includes
  56.  
  57. require_once('faq-type.php');
  58.  
  59. include_once 'function-invoice-packing-slips.php';
  60. include_once 'function-custom-search-filter.php';
  61. include_once 'function-acf-fields.php';
  62. //include_once 'function-woo-endpoints.php';
  63. include_once 'function-woo-general.php';
  64.  
  65.  
  66.  
  67. function delete_warning_scripts()
  68. {
  69.     global $wp;
  70.     $current_url = explode("/", home_url(add_query_arg(array(), $wp->request)));
  71.     if ($current_url[count($current_url) - 1] == 'edit.php' && $_GET['post_type'] == 'product') {
  72. // register your script location, dependencies and version
  73.         wp_register_script('custom_script', get_template_directory_uri() . '/custom_js/delete_duplicate_warn_script.js', array('jquery'), '1.0');
  74.         // enqueue the script
  75.         wp_enqueue_script('custom_script');
  76.     }
  77. }
  78.  
  79. function add_my_custom_menu()
  80. {
  81.     //add an item to the menu
  82.     add_menu_page(
  83.         'Data Report',
  84.         'Data Report',
  85.         'manage_options',
  86.         'data_report.php',
  87.         '',
  88.         '',
  89.         '105'
  90.     );
  91.     add_menu_page(
  92.         'Product Search',
  93.         'Product Search',
  94.         'manage_options',
  95.         'custom-search.php',
  96.         '',
  97.         '',
  98.         '106'
  99.     );
  100.     add_menu_page(
  101.         'Clone Site',
  102.         'Clone Site',
  103.         'manage_options',
  104.         'clone_site.php',
  105.         '',
  106.         '',
  107.         '104'
  108.     );
  109.     //add_menu_page('Data Report', 'Data Report', string $capability, string $menu_slug, callable $function = '', string $icon_url = '', int $position = null );
  110.     //add submenu page for signup listings
  111. }
  112.  
  113. add_action('admin_menu', 'add_my_custom_menu');
  114. add_action('admin_enqueue_scripts', 'delete_warning_scripts');
  115. add_action('wp_enqueue_scripts', 'bulk_discount_alert');
  116.  
  117. function bulk_discount_alert()
  118. {
  119.     if (is_product()) {
  120.         $ss_url = get_stylesheet_directory_uri();
  121.         wp_register_script('bulk_discount_alert', get_template_directory_uri() . '/custom_js/bulk_discount_alert.js', array('jquery'), '1.0');
  122.         wp_enqueue_script('bulk_discount_alert', "{$ss_url}/custom_js/bulk_discount_alert.js");
  123.     }
  124. }
  125.  
  126.  
  127.  
  128. function v_forcelogin()
  129. {
  130.  
  131.     // Exceptions for AJAX, Cron, or WP-CLI requests
  132.     if ((defined('DOING_AJAX') && DOING_AJAX) || (defined('DOING_CRON') && DOING_CRON) || (defined('WP_CLI') && WP_CLI)) {
  133.         return;
  134.     }
  135.  
  136.     // Redirect unauthorized visitors
  137.     if (!is_user_logged_in()) {
  138.       // Get URL
  139.         $url = isset($_SERVER['HTTPS']) && 'on' === $_SERVER['HTTPS'] ? 'https' : 'http';
  140.         $url .= '://' . $_SERVER['HTTP_HOST'];
  141.       // port is prepopulated here sometimes
  142.         if (strpos($_SERVER['HTTP_HOST'], ':') === false) {
  143.             $url .= in_array($_SERVER['SERVER_PORT'], array('80', '443')) ? '' : ':' . $_SERVER['SERVER_PORT'];
  144.         }
  145.         $url .= $_SERVER['REQUEST_URI'];
  146.  
  147.       // Apply filters
  148.         $bypass = apply_filters('v_forcelogin_bypass', false);
  149.         $whitelist = apply_filters('v_forcelogin_whitelist', array());
  150.         $redirect_url = apply_filters('v_forcelogin_redirect', $url);
  151.  
  152.       // Redirect
  153.         if (preg_replace('/\?.*/', '', $url) != preg_replace('/\?.*/', '', wp_login_url()) && !in_array($url, $whitelist) && !$bypass) {
  154.             wp_safe_redirect(wp_login_url($redirect_url), 302);
  155.             exit();
  156.         }
  157.     } else {
  158.       // Only allow Multisite users access to their assigned sites
  159.         if (function_exists('is_multisite') && is_multisite()) {
  160.             $current_user = wp_get_current_user();
  161.             if (!is_user_member_of_blog($current_user->ID) && !is_super_admin())
  162.                 wp_die(__("You're not authorized to access this site.", 'wp-force-login'), get_option('blogname') . ' &rsaquo; ' . __("Error", 'wp-force-login'));
  163.         }
  164.     }
  165. }
  166. add_action('template_redirect', 'v_forcelogin');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement