sumakaki

function

Nov 8th, 2020 (edited)
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.87 KB | None | 0 0
  1. <?php
  2. /**
  3.  * homes functions and definitions
  4.  *
  5.  * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6.  *
  7.  * @package homes
  8.  */
  9.  
  10. if ( ! defined( '_S_VERSION' ) ) {
  11.     // Replace the version number of the theme on each release.
  12.     define( '_S_VERSION', '1.0.0' );
  13. }
  14.  
  15. if ( ! function_exists( 'homes_setup' ) ) :
  16.     /**
  17.      * Sets up theme defaults and registers support for various WordPress features.
  18.      *
  19.      * Note that this function is hooked into the after_setup_theme hook, which
  20.      * runs before the init hook. The init hook is too late for some features, such
  21.      * as indicating support for post thumbnails.
  22.      */
  23.     function homes_setup() {
  24.         /*
  25.          * Make theme available for translation.
  26.          * Translations can be filed in the /languages/ directory.
  27.          * If you're building a theme based on homes, use a find and replace
  28.          * to change 'homes' to the name of your theme in all the template files.
  29.          */
  30.         load_theme_textdomain( 'homes', get_template_directory() . '/languages' );
  31.  
  32.         // Add default posts and comments RSS feed links to head.
  33.         add_theme_support( 'automatic-feed-links' );
  34.  
  35.         /*
  36.          * Let WordPress manage the document title.
  37.          * By adding theme support, we declare that this theme does not use a
  38.          * hard-coded <title> tag in the document head, and expect WordPress to
  39.          * provide it for us.
  40.          */
  41.         add_theme_support( 'title-tag' );
  42.  
  43.         /*
  44.          * Enable support for Post Thumbnails on posts and pages.
  45.          *
  46.          * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
  47.          */
  48.         add_theme_support( 'post-thumbnails' );
  49.  
  50.         // This theme uses wp_nav_menu() in one location.
  51.         register_nav_menus(
  52.             array(
  53.                 'menu-1' => esc_html__( 'Primary', 'homes' ),
  54.             )
  55.         );
  56.  
  57.         /*
  58.          * Switch default core markup for search form, comment form, and comments
  59.          * to output valid HTML5.
  60.          */
  61.         add_theme_support(
  62.             'html5',
  63.             array(
  64.                 'search-form',
  65.                 'comment-form',
  66.                 'comment-list',
  67.                 'gallery',
  68.                 'caption',
  69.                 'style',
  70.                 'script',
  71.             )
  72.         );
  73.  
  74.         // Set up the WordPress core custom background feature.
  75.         add_theme_support(
  76.             'custom-background',
  77.             apply_filters(
  78.                 'homes_custom_background_args',
  79.                 array(
  80.                     'default-color' => 'ffffff',
  81.                     'default-image' => '',
  82.                 )
  83.             )
  84.         );
  85.  
  86.         // Add theme support for selective refresh for widgets.
  87.         add_theme_support( 'customize-selective-refresh-widgets' );
  88.  
  89.         /**
  90.          * Add support for core custom logo.
  91.          *
  92.          * @link https://codex.wordpress.org/Theme_Logo
  93.          */
  94.         add_theme_support(
  95.             'custom-logo',
  96.             array(
  97.                 'height'      => 250,
  98.                 'width'       => 250,
  99.                 'flex-width'  => true,
  100.                 'flex-height' => true,
  101.             )
  102.         );
  103.     }
  104. endif;
  105. add_action( 'after_setup_theme', 'homes_setup' );
  106.  
  107. /**
  108.  * Set the content width in pixels, based on the theme's design and stylesheet.
  109.  *
  110.  * Priority 0 to make it available to lower priority callbacks.
  111.  *
  112.  * @global int $content_width
  113.  */
  114. function homes_content_width() {
  115.     $GLOBALS['content_width'] = apply_filters( 'homes_content_width', 640 );
  116. }
  117. add_action( 'after_setup_theme', 'homes_content_width', 0 );
  118.  
  119. /**
  120.  * Register widget area.
  121.  *
  122.  * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  123.  */
  124. function homes_widgets_init() {
  125.     register_sidebar(
  126.         array(
  127.             'name'          => esc_html__( 'Sidebar', 'homes' ),
  128.             'id'            => 'sidebar-1',
  129.             'description'   => esc_html__( 'Add widgets here.', 'homes' ),
  130.             'before_widget' => '<section id="%1$s" class="widget %2$s">',
  131.             'after_widget'  => '</section>',
  132.             'before_title'  => '<h2 class="widget-title">',
  133.             'after_title'   => '</h2>',
  134.         )
  135.     );
  136. }
  137. add_action( 'widgets_init', 'homes_widgets_init' );
  138.  
  139. /**
  140.  * Enqueue scripts and styles.
  141.  */
  142. function homes_scripts() {
  143.     wp_enqueue_style( 'homes-style', get_stylesheet_uri(), array(), _S_VERSION );
  144.     wp_enqueue_style('header-style', get_template_directory_uri() . 'css/header-style.css',
  145.     array(), _S_VERSION, true);
  146.     wp_style_add_data( 'homes-style', 'rtl', 'replace' );
  147.  
  148.     wp_enqueue_script( 'homes-navigation', get_template_directory_uri() . '/js/navigation.js', array(), _S_VERSION, true );
  149.  
  150.     if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  151.         wp_enqueue_script( 'comment-reply' );
  152.     }
  153. }
  154. add_action( 'wp_enqueue_scripts', 'homes_scripts' );
  155.  
  156. /**
  157.  * Implement the Custom Header feature.
  158.  */
  159. require get_template_directory() . '/inc/custom-header.php';
  160.  
  161. /**
  162.  * Custom template tags for this theme.
  163.  */
  164. require get_template_directory() . '/inc/template-tags.php';
  165.  
  166. /**
  167.  * Functions which enhance the theme by hooking into WordPress.
  168.  */
  169. require get_template_directory() . '/inc/template-functions.php';
  170.  
  171. /**
  172.  * Customizer additions.
  173.  */
  174. require get_template_directory() . '/inc/customizer.php';
  175.  
  176. /**
  177.  * Load Jetpack compatibility file.
  178.  */
  179. if ( defined( 'JETPACK__VERSION' ) ) {
  180.     require get_template_directory() . '/inc/jetpack.php';
  181. }
  182.  
  183. add_action( 'init', 'register_post_types' );
  184. function register_post_types(){
  185.     register_post_type( 'house', [
  186.         'label'  => null,
  187.         'labels' => [
  188.             'name'               => 'houses', // основное название для типа записи
  189.             'singular_name'      => 'house', // название для одной записи этого типа
  190.             'add_new'            => 'Добавить квариру', // для добавления новой записи
  191.             'add_new_item'       => 'Название квариры', // заголовка у вновь создаваемой записи в админ-панели.
  192.             'edit_item'          => 'Редактирование квартиры', // для редактирования типа записи
  193.             'new_item'           => 'Новое описание квартиры', // текст новой записи
  194.             'view_item'          => 'Смотреть квариру', // для просмотра записи этого типа.
  195.             'search_items'       => 'Искать квариру', // для поиска по этим типам записи
  196.             'not_found'          => 'Не найдено квартир', // если в результате поиска ничего не было найдено
  197.             'not_found_in_trash' => 'Не найдено в корзине', // если не было найдено в корзине
  198.             'parent_item_colon'  => '', // для родителей (у древовидных типов)
  199.             'menu_name'          => 'Квартиры', // название меню
  200.         ],
  201.         'description'         => '',
  202.         'public'              => true,
  203.         // 'publicly_queryable'  => null, // зависит от public
  204.         // 'exclude_from_search' => null, // зависит от public
  205.         // 'show_ui'             => null, // зависит от public
  206.         // 'show_in_nav_menus'   => null, // зависит от public
  207.         'show_in_menu'        => true, // показывать ли в меню адмнки
  208.         // 'show_in_admin_bar'   => null, // зависит от show_in_menu
  209.         'show_in_rest'        => null, // добавить в REST API. C WP 4.7
  210.         'rest_base'           => null, // $post_type. C WP 4.7
  211.         'menu_position'       => null,
  212.         'menu_icon'           => 'dashicons-admin-home',
  213.         //'capability_type'   => 'post',
  214.         //'capabilities'      => 'post', // массив дополнительных прав для этого типа записи
  215.         //'map_meta_cap'      => null, // Ставим true чтобы включить дефолтный обработчик специальных прав
  216.         'hierarchical'        => false,
  217.         'supports'            => [ 'title', 'editor' ], // 'title','editor','author','thumbnail','excerpt','trackbacks','custom-fields','comments','revisions','page-attributes','post-formats'
  218.         'taxonomies'          => [],
  219.         'has_archive'         => false,
  220.         'rewrite'             => true,
  221.         'query_var'           => true,
  222.     ] );
  223. }
Add Comment
Please, Sign In to add comment