first
This commit is contained in:
45
wp-content/themes/simple-theme/functions/acf.php
Normal file
45
wp-content/themes/simple-theme/functions/acf.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
add_action('acf/init', 'theme_acf_op_init');
|
||||
function theme_acf_op_init()
|
||||
{
|
||||
// // Check function exists.
|
||||
if (function_exists('acf_add_options_page')) {
|
||||
// // Register options page.
|
||||
$option_page = acf_add_options_page(array(
|
||||
'page_title' => ('Глобальные Настройки'),
|
||||
'menu_title' => ('Глобальные Настройки'),
|
||||
'menu_slug' => 'theme-general-settings',
|
||||
'capability' => 'edit_posts',
|
||||
'position' => '2',
|
||||
'redirect' => false
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// ?? ACF
|
||||
// add_action('acf/init', 'register_acf_blocks');
|
||||
// function register_acf_blocks()
|
||||
// {
|
||||
// if (function_exists('acf_register_block_type')) {
|
||||
// // Register MyExample block
|
||||
// acf_register_block_type(array(
|
||||
// 'name' => 'myexample',
|
||||
// 'title' => __('MyExample'),
|
||||
// 'description' => __('A custom MyExample block.'),
|
||||
// 'category' => 'formatting',
|
||||
// 'icon' => 'layout',
|
||||
// 'keywords' => array('myexample'),
|
||||
// 'post_types' => array('post', 'page'),
|
||||
// 'mode' => 'auto',
|
||||
// // 'align' => 'wide', /* "left", "center", "right", "wide" and "full" */
|
||||
// 'render_template' => 'template-parts/blocks/myexample.php',
|
||||
// // 'render_callback' => 'myexample_block_render_callback',
|
||||
// // 'enqueue_style' => get_template_directory_uri() . '/template-parts/blocks/myexample/myexample.css',
|
||||
// // 'enqueue_script' => get_template_directory_uri() . '/template-parts/blocks/myexample/myexample.js',
|
||||
// // 'enqueue_assets' => 'myexample_block_enqueue_assets',
|
||||
// // 'supports' => array('multiple' => false,/* and more */),
|
||||
// ));
|
||||
// }
|
||||
// }
|
||||
// !! ACF
|
99
wp-content/themes/simple-theme/functions/base.php
Normal file
99
wp-content/themes/simple-theme/functions/base.php
Normal file
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
// ? add localization for this theme
|
||||
// load_theme_textdomain(gV('slug'), get_stylesheet_directory() . '/lang');
|
||||
|
||||
// add_action('after_setup_theme', function () {
|
||||
// add_theme_support('woocommerce');
|
||||
// });
|
||||
|
||||
add_action('after_setup_theme', function () {
|
||||
// // ?? Register Navigation Menus
|
||||
register_nav_menus(array(
|
||||
'main_menu' => __('Main menu', gV('slug')),
|
||||
'link_menu' => __('Link menu', gV('slug')),
|
||||
'mobile_menu' => __('Mobile menu', gV('slug')),
|
||||
'companies_menu' => __('Companies menu', gV('slug')),
|
||||
'products_menu' => __('Products menu', gV('slug')),
|
||||
'banks_menu' => __('Banks menu', gV('slug')),
|
||||
'cities_menu' => __('Cities menu', gV('slug')),
|
||||
'sub_header_menu' => __('Подменю в шапке', gV('slug')),
|
||||
'mobile_footer_menu' => __('Мобильное в футере', gV('slug')),
|
||||
));
|
||||
});
|
||||
|
||||
add_filter('get_the_archive_title', function ($title) {
|
||||
// ?? Change Archive Title
|
||||
if (is_category()) {
|
||||
$title = single_cat_title('', false);
|
||||
} elseif (is_tag()) {
|
||||
$title = single_tag_title('', false);
|
||||
} elseif (is_author()) {
|
||||
$title = '<span class="vcard">' . get_the_author() . '</span>';
|
||||
} elseif (is_tax()) { // for custom post types
|
||||
$title = sprintf(__('%1$s'), single_term_title('', false));
|
||||
} elseif (is_post_type_archive()) {
|
||||
$title = post_type_archive_title('', false);
|
||||
}
|
||||
return $title;
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @f echo get_stylesheet_directory_uri();
|
||||
*/
|
||||
function tUrl()
|
||||
{
|
||||
echo get_stylesheet_directory_uri();
|
||||
}
|
||||
/**
|
||||
* @return function
|
||||
* @f return get_stylesheet_directory_uri();
|
||||
*/
|
||||
function get_tUrl()
|
||||
{
|
||||
return get_stylesheet_directory_uri();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name File name
|
||||
* @param integer $dev File has [.min] true/false
|
||||
* @return function
|
||||
* @f wp_enqueue_style("$name-style",get_tUrl()."/css/$name".($dev?"":".min").".css",NULL,gV('ver'));
|
||||
*/
|
||||
|
||||
// function f_add_style($name, $dev)
|
||||
// {
|
||||
// wp_enqueue_style("$name-style", get_tUrl() . "/css/$name" . ($dev ? "" : ".min") . ".css", NULL, gV('ver'));
|
||||
// }
|
||||
|
||||
/**
|
||||
* @param string $name File name
|
||||
* @param integer $dev File has [.min] true/false
|
||||
* @param integer $footer Insert into Footer true/false
|
||||
* @return function
|
||||
* @f wp_enqueue_script("$name-script",get_tUrl()."/js/$name".($dev?"":".min").".css",NULL,gV('ver'),$footer);
|
||||
*/
|
||||
function f_add_script($name, $dev, $footer)
|
||||
{
|
||||
wp_enqueue_script("$name-script", get_tUrl() . "/js/$name" . ($dev ? "" : ".min") . ".js", NULL, gV('ver'), $footer);
|
||||
}
|
||||
/**
|
||||
* @param string $name File name
|
||||
* @param integer $url File link
|
||||
* @param integer $footer Insert into Footer true/false
|
||||
* @return function
|
||||
* @f wp_enqueue_script("$name-script", get_tUrl() . $url, NULL, gV('ver'), $footer);
|
||||
*/
|
||||
function f_add_c_script($name, $url, $footer)
|
||||
{
|
||||
wp_enqueue_script("$name-script", get_tUrl() . $url, NULL, gV('ver'), $footer);
|
||||
}
|
||||
|
||||
// add_filter('comment_form_default_fields', 'wpcourses_unset_url_field');
|
||||
// function wpcourses_unset_url_field ( $fields ) {
|
||||
// if ( isset($fields['url'] ))
|
||||
// unset ( $fields['url'] );
|
||||
// return $fields;
|
||||
// }
|
97
wp-content/themes/simple-theme/functions/get-video.php
Normal file
97
wp-content/themes/simple-theme/functions/get-video.php
Normal file
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
function getVimeoId($url)
|
||||
{
|
||||
if (preg_match('#(?:https?://)?(?:www.)?(?:player.)?vimeo.com/(?:[a-z]*/)*([0-9]{6,11})[?]?.*#', $url, $m)) {
|
||||
return $m[1];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function getYoutubeId($url)
|
||||
{
|
||||
$parts = parse_url($url);
|
||||
if (isset($parts['host'])) {
|
||||
$host = $parts['host'];
|
||||
if (
|
||||
false === strpos($host, 'youtube') &&
|
||||
false === strpos($host, 'youtu.be')
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (isset($parts['query'])) {
|
||||
parse_str($parts['query'], $qs);
|
||||
if (isset($qs['v'])) {
|
||||
return $qs['v'];
|
||||
} else if (isset($qs['vi'])) {
|
||||
return $qs['vi'];
|
||||
}
|
||||
}
|
||||
if (isset($parts['path'])) {
|
||||
$path = explode('/', trim($parts['path'], '/'));
|
||||
return $path[count($path) - 1];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function getVideoThumbnailByUrl($url, $format = 'small')
|
||||
{
|
||||
if (false !== ($id = getVimeoId($url))) {
|
||||
$hash = unserialize(file_get_contents("https://vimeo.com/api/v2/video/$id.php"));
|
||||
/**
|
||||
* thumbnail_small
|
||||
* thumbnail_medium
|
||||
* thumbnail_large
|
||||
*/
|
||||
if ('medium' === $format) {
|
||||
return preg_replace("/^http:/i", "https:", $hash[0]['thumbnail_medium']);
|
||||
} else if ('large' === $format) {
|
||||
return preg_replace("/^http:/i", "https:", $hash[0]['thumbnail_large']);
|
||||
}
|
||||
return preg_replace("/^http:/i", "https:", $hash[0]['thumbnail_small']);
|
||||
// return $hash[0]['thumbnail_small'];
|
||||
} elseif (false !== ($id = getYoutubeId($url))) {
|
||||
/**
|
||||
* http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
|
||||
* http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
|
||||
* http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
|
||||
* http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg
|
||||
*
|
||||
* http://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg
|
||||
* http://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg
|
||||
* http://img.youtube.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg
|
||||
* http://img.youtube.com/vi/<insert-youtube-video-id-here>/sddefault.jpg
|
||||
* http://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg
|
||||
*/
|
||||
if ('medium' === $format) {
|
||||
return 'https://img.youtube.com/vi/' . $id . '/hqdefault.jpg';
|
||||
} else if ('large' === $format) {
|
||||
return 'https://img.youtube.com/vi/' . $id . '/sddefault.jpg';
|
||||
} else if ('original' === $format) {
|
||||
return 'https://img.youtube.com/vi/' . $id . '/maxresdefault.jpg';
|
||||
}
|
||||
return 'https://img.youtube.com/vi/' . $id . '/mqdefault.jpg';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function getEmbedVideo($url)
|
||||
{
|
||||
$code = <<<EEE
|
||||
<style>
|
||||
.vec { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; }
|
||||
.vec iframe, .vec object, .vec embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
|
||||
</style>
|
||||
EEE;
|
||||
|
||||
if (false !== ($id = getVimeoId($url))) {
|
||||
$code .= <<<EEE
|
||||
<div class='vec'><iframe src='https://player.vimeo.com/video/$id' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div>
|
||||
EEE;
|
||||
} elseif (false !== ($id = getYoutubeId($url))) {
|
||||
$code .= <<<EEE
|
||||
<div class='vec'><iframe src='https://www.youtube.com/embed/$id' frameborder='0' allowfullscreen></iframe></div>
|
||||
EEE;
|
||||
} else {
|
||||
$code = false;
|
||||
}
|
||||
return $code;
|
||||
}
|
43
wp-content/themes/simple-theme/functions/scripts.php
Normal file
43
wp-content/themes/simple-theme/functions/scripts.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
add_action('wp_enqueue_scripts', function () {
|
||||
// ?? Scripts for Site (Header)
|
||||
// f_add_script('script_file_name', 0||1, false);
|
||||
|
||||
// ?? Scripts for Site (Footer)
|
||||
// f_add_script('simplebar', 0, true);
|
||||
// f_add_script('jquery.fancybox', 0, true);
|
||||
// f_add_script('bootstrap.bundle', 0, true);
|
||||
// f_add_script('swiper-bundle', 0, true);
|
||||
// f_add_script('js.cookie', 0, true);
|
||||
|
||||
// global $wp_query;
|
||||
wp_register_script("main-script", get_tUrl() . "/js/main" . (gV('dev') ? "" : ".min") . ".js", array('jquery'), 3);
|
||||
wp_enqueue_script('main-script');
|
||||
// ?? свои параметры для файла "main-script"
|
||||
wp_localize_script('main-script', 'siteVars', array(
|
||||
// 'query' => array(
|
||||
// 'raw_vars' => $wp_query->query_vars,
|
||||
// 'vars' => json_encode($wp_query->query_vars), // everything about your loop is here
|
||||
// 'current_page' => get_query_var('paged') ? get_query_var('paged') : 1,
|
||||
// 'max_page' => $wp_query->max_num_pages,
|
||||
// ),
|
||||
'site' => array(
|
||||
'url' => site_url(),
|
||||
'ajax' => admin_url('admin-ajax.php'),
|
||||
),
|
||||
// 'translate' => array(
|
||||
// 'wl_add_text' => __("Added to the wish list", gV('slug')),
|
||||
// 'wl_remove_text' => __("Removed from the wish list", gV('slug')),
|
||||
// ),
|
||||
));
|
||||
});
|
||||
|
||||
add_filter('script_loader_tag', function ($url) {
|
||||
// ?? Scripts loaded "defer"
|
||||
if (is_user_logged_in()) return $url; // don't break WP Admin
|
||||
if (FALSE === strpos($url, '.js')) return $url;
|
||||
if (strpos($url, 'jquery.js') || strpos($url, 'jquery-3.5.1.min.js')) return $url;
|
||||
return str_replace(' src', ' defer src', $url);
|
||||
});
|
||||
|
46
wp-content/themes/simple-theme/functions/styles.php
Normal file
46
wp-content/themes/simple-theme/functions/styles.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
// add_action('admin_enqueue_scripts', function () {
|
||||
// // ?? Styles for WP Admin-panel
|
||||
// f_add_style('admin-style', 1);
|
||||
// });
|
||||
|
||||
// add_action('wp_enqueue_scripts', function () {
|
||||
// ?? Styles for Site (Header)
|
||||
// if (gV('critical') == true) f_add_style('critical', 1);
|
||||
// f_add_style('main', gV('dev'));
|
||||
// });
|
||||
|
||||
add_action('get_footer', function () {
|
||||
// ?? Styles for Site (Footer)
|
||||
// f_add_style('simplebar', 0);
|
||||
|
||||
// wp_enqueue_style('jquery-scrollbar', get_tUrl() . '/css/jquery.scrollbar.css', NULL, gV('ver'));
|
||||
// wp_enqueue_script('jquery-scrollbar', get_tUrl() . '/js/jquery.scrollbar.min.js', NULL, gV('ver'), true);
|
||||
});
|
||||
|
||||
add_action('wp_enqueue_scripts', function () {
|
||||
// wp_dequeue_style('wp-block-library'); // WordPress core
|
||||
wp_dequeue_style('wp-block-library-theme'); // WordPress core
|
||||
wp_dequeue_style('wc-block-style'); // WooCommerce
|
||||
wp_dequeue_style('storefront-gutenberg-blocks'); // Storefront theme
|
||||
}, 100);
|
||||
|
||||
add_action('wp_head', function () {
|
||||
if (is_admin_bar_showing()) :
|
||||
?>
|
||||
<style type="text/css">
|
||||
.site-navigation .header-content.dense {
|
||||
margin-top: 32px !important;
|
||||
}
|
||||
#wpadminbar a {
|
||||
color: #c3c4c7 !important;
|
||||
}
|
||||
</style>
|
||||
<?php endif;
|
||||
});
|
||||
// add_action('admin_head', 'override_admin_bar_css_function'); // on backend area
|
||||
|
||||
add_action('get_header', function () {
|
||||
remove_action('wp_head', '_admin_bar_bump_cb');
|
||||
});
|
Reference in New Issue
Block a user