ํƒœ๊ทธ ๋ณด๊ด€๋ฌผ: wp-admin

wp-admin

์›Œ๋“œ ํ”„๋ ˆ์Šค ํ…Œ๋งˆ์˜ functions.php ํŒŒ์ผ์—์„œ ์ฝ”๋“œ๋ฅผ ๊ตฌ์„ฑ ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ? ์‚ฌ์šฉ์ž ์ •์˜ ๊ธฐ๋Šฅ์ด์žˆ๋Š” ๊ฒฝ์šฐ ๋ชจ๋“ 

WordPress์— ๋Œ€ํ•œ ์‚ฌ์šฉ์ž ์ •์˜๊ฐ€ ๋งŽ์„์ˆ˜๋ก์ด ํŒŒ์ผ์„ ๊ตฌ์„ฑํ•˜๊ฑฐ๋‚˜ ๋ถ„ํ•  ํ•ด์•ผํ•˜๋Š”์ง€์— ๋Œ€ํ•ด ๋” ๋งŽ์ด ์ƒ๊ฐํ•˜๊ธฐ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

๋” ๊ตฌ์ฒด์ ์œผ๋กœ, ๊ด€๋ฆฌ ์˜์—ญ์—๋งŒ ์ ์šฉ๋˜๋Š” ์‚ฌ์šฉ์ž ์ •์˜ ๊ธฐ๋Šฅ๊ณผ ๊ณต์šฉ ์›น ์‚ฌ์ดํŠธ์—๋งŒ ์ ์šฉ๋˜๋Š” ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž ์ •์˜ ๊ธฐ๋Šฅ์ด์žˆ๋Š” ๊ฒฝ์šฐ ๋ชจ๋“  ๊ด€๋ฆฌ ๊ธฐ๋Šฅ์„ ์ž์ฒด ํŒŒ์ผ์— ํฌํ•จํ•˜๊ฑฐ๋‚˜ ํ•จ๊ป˜ ๊ทธ๋ฃนํ™” ํ•ด์•ผํ•˜๋Š” ์ด์œ ๊ฐ€ ์žˆ์Šต๋‹ˆ๊นŒ?

ํŒŒ์ผ์„ ๋ณ„๋„์˜ ํŒŒ์ผ๋กœ ๋‚˜๋ˆ„๊ฑฐ๋‚˜ ๊ทธ๋ฃนํ™”ํ•˜๋ฉด WordPress ์›น ์‚ฌ์ดํŠธ ์†๋„๊ฐ€ ๋นจ๋ผ์ง€๊ฑฐ๋‚˜ WordPress / PHP๊ฐ€ is_admin ์ฝ”๋“œ ์ ‘๋‘์‚ฌ๊ฐ€์žˆ๋Š” ๊ธฐ๋Šฅ์„ ์ž๋™์œผ๋กœ ๊ฑด๋„ˆ ๋›ฐ๋‚˜์š”?

ํฐ ํ•จ์ˆ˜ ํŒŒ์ผ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฐ€์žฅ ์ข‹์€ ๋ฐฉ๋ฒ•์€ ๋ฌด์—‡์ž…๋‹ˆ๊นŒ (๊ด‘์‚ฐ์€ 1370 ์ค„์ž…๋‹ˆ๋‹ค).



๋‹ต๋ณ€

ํ…Œ๋งˆ์˜ ์ฝ”๋“œ functions.php๊ฐ€ ์••๋„๋˜๊ธฐ ์‹œ์ž‘ ํ•˜๋Š” ์‹œ์ ์— ๋„๋‹ฌํ•˜๋ฉด ์ฝ”๋“œ ๋ฅผ ์—ฌ๋Ÿฌ ํŒŒ์ผ๋กœ ๋‚˜๋ˆŒ ์ค€๋น„๊ฐ€ ๋œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋‚˜๋Š”์ด ์‹œ์ ์—์„œ ๊ฑฐ์˜ ๋‘ ๋ฒˆ์งธ ๋ณธ์„ฑ์œผ๋กœํ•˜๋Š” ๊ฒฝํ–ฅ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ…Œ๋งˆ์˜ ํฌํ•จ ํŒŒ์ผ functions.phpํŒŒ์ผ

๋‚ด ํ…Œ๋งˆ ๋””๋ ‰ํ† ๋ฆฌ ์•„๋ž˜์— โ€œincludesโ€ ๋ผ๋Š” ์„œ๋ธŒ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ž‘์„ฑ ํ•˜๊ณ  ๋‹น์‹œ์˜ ๋ง์— ๋”ฐ๋ผ ๊ตฌ์„ฑ๋˜๋Š” ํฌํ•จ ํŒŒ์ผ๋กœ ์ฝ”๋“œ๋ฅผ ์„ธ๊ทธ๋จผํŠธ ํ™”ํ•œ๋‹ค (์ด๋Š” ์‚ฌ์ดํŠธ๊ฐ€ ๋ฐœ์ „ํ•จ์— ๋”ฐ๋ผ ์ง€์†์ ์œผ๋กœ ์ฝ”๋“œ๋ฅผ ๋ฆฌํŒฉํ„ฐ๋งํ•˜๊ณ  ์ด๋™์‹œํ‚ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค). ์‹ค์ œ ์ฝ”๋“œ๋ฅผ ๋„ฃ์Šต๋‹ˆ๋‹ค functions.php. ๋ชจ๋“  ๊ฒƒ์€ ํฌํ•จ ํŒŒ์ผ์— ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค. ๋‹จ์ง€ ๋‚ด ์ทจํ–ฅ.

์˜ˆ๋ฅผ ๋“ค์–ด ์—ฌ๊ธฐ WordPress Answers์˜ ์งˆ๋ฌธ์— ๋Œ€ํ•œ ๋‹ต๋ณ€์„ ํ…Œ์ŠคํŠธํ•˜๋Š” ๋ฐ ์‚ฌ์šฉํ•˜๋Š” ํ…Œ์ŠคํŠธ ์„ค์น˜๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ์งˆ๋ฌธ์— ๋Œ€๋‹ต ํ•  ๋•Œ๋งˆ๋‹ค ๋‹ค์‹œ ํ•„์š”ํ•  ๋•Œ๋ฅผ ๋Œ€๋น„ํ•˜์—ฌ ์ฝ”๋“œ๋ฅผ ๋ณด๊ด€ํ•˜์‹ญ์‹œ์˜ค. ์ด๊ฒƒ์€ ์‹ค์ œ ์‚ฌ์ดํŠธ์—์„œ ์ˆ˜ํ–‰ ํ•  ์ž‘์—…์ด ์•„๋‹ˆ์ง€๋งŒ ์ฝ”๋“œ๋ฅผ ๋‚˜๋ˆ„๋Š” ๋ฉ”์ปค๋‹ˆ์ฆ˜์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.

<?php 
/*
 * functions.php
 * 
 */
require_once( __DIR__ . '/includes/null-meta-compare.php');
require_once( __DIR__ . '/includes/older-examples.php');
require_once( __DIR__ . '/includes/wp-admin-menu-classes.php');
require_once( __DIR__ . '/includes/admin-menu-function-examples.php');

// WA: Adding a Taxonomy Filter to Admin List for a Custom Post Type?
// http://wordpress.stackexchange.com/questions/578/
require_once( __DIR__ . '/includes/cpt-filtering-in-admin.php'); 
require_once( __DIR__ . '/includes/category-fields.php');
require_once( __DIR__ . '/includes/post-list-shortcode.php');
require_once( __DIR__ . '/includes/car-type-urls.php');
require_once( __DIR__ . '/includes/buffer-all.php');
require_once( __DIR__ . '/includes/get-page-selector.php');

// http://wordpress.stackexchange.com/questions/907/
require_once( __DIR__ . '/includes/top-5-posts-per-category.php'); 

// http://wordpress.stackexchange.com/questions/951/
require_once( __DIR__ . '/includes/alternate-category-metabox.php');  

// http://lists.automattic.com/pipermail/wp-hackers/2010-August/034384.html
require_once( __DIR__ . '/includes/remove-status.php');  

// http://wordpress.stackexchange.com/questions/1027/removing-the-your-backup-folder-might-be-visible-to-the-public-message-generate
require_once( __DIR__ . '/includes/301-redirects.php');  

๋˜๋Š” ํ”Œ๋Ÿฌ๊ทธ์ธ ๋งŒ๋“ค๊ธฐ

๋‹ค๋ฅธ ์˜ต์…˜์€ ๊ธฐ๋Šฅ๋ณ„๋กœ ์ฝ”๋“œ๋ฅผ ๊ทธ๋ฃนํ™”ํ•˜๊ณ  ์ž์‹ ์˜ ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ๋งŒ๋“œ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋‚˜๋ฅผ ์œ„ํ•ด ํ…Œ๋งˆ functions.phpํŒŒ์ผ ์—์„œ ์ฝ”๋”ฉ์„ ์‹œ์ž‘ ํ•˜๊ณ  ์ฝ”๋“œ๊ฐ€ ์™„์„ฑ ๋  ๋•Œ๊นŒ์ง€ ๋Œ€๋ถ€๋ถ„์˜ ์ฝ”๋“œ๋ฅผ ํ”Œ๋Ÿฌ๊ทธ์ธ์œผ๋กœ ์˜ฎ๊ฒผ์Šต๋‹ˆ๋‹ค.

๊ทธ๋Ÿฌ๋‚˜ PHP ์ฝ”๋“œ ๊ตฌ์„ฑ์œผ๋กœ๋ถ€ํ„ฐ ํฐ ์„ฑ๋Šฅ ํ–ฅ์ƒ์€ ์—†์Šต๋‹ˆ๋‹ค

๋ฐ˜๋ฉด์— PHP ํŒŒ์ผ์„ ๊ตฌ์„ฑํ•˜๋Š” ๊ฒƒ์€ ์ˆœ์„œ ๋ฐ ์œ ์ง€ ๊ด€๋ฆฌ ์„ฑ์„ ๋งŒ๋“œ๋Š” ๋ฐ 99 %, ์„ฑ๋Šฅ์— ๋Œ€ํ•ด 1 %์ž…๋‹ˆ๋‹ค ( HTTP๋ฅผ ํ†ตํ•ด ๋ธŒ๋ผ์šฐ์ €์—์„œ ํ˜ธ์ถœํ•˜๋Š” ์กฐ์ง .js๋ฐ .cssํŒŒ์ผ์€ ์™„์ „ํžˆ ๋‹ค๋ฅธ ๊ฒฝ์šฐ์ด๋ฉฐ ์„ฑ๋Šฅ์— ํฐ ์˜ํ–ฅ์„ ๋ฏธ์นฉ๋‹ˆ๋‹ค). ์„œ๋ฒ„์˜ PHP ์ฝ”๋“œ๋Š” ์„ฑ๋Šฅ ์ธก๋ฉด์—์„œ ์ค‘์š”ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  ์ฝ”๋“œ ์กฐ์ง์€ ๊ฐœ์ธ ์ทจํ–ฅ์ž…๋‹ˆ๋‹ค

๋งˆ์ง€๋ง‰์œผ๋กœ ์ฝ”๋“œ ๊ตฌ์„ฑ์€ ๊ฐœ์ธ ์ทจํ–ฅ์ž…๋‹ˆ๋‹ค. ์–ด๋–ค ์‚ฌ๋žŒ๋“ค์€ ์ฝ”๋“œ๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ๋ฐฉ์‹์ด ์‹ซ์€ ๊ฒƒ์ฒ˜๋Ÿผ ์ฝ”๋“œ๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ๋ฐฉ์‹์„ ์‹ซ์–ดํ•ฉ๋‹ˆ๋‹ค. ๋งˆ์Œ์— ๋“œ๋Š” ๊ฒƒ์„ ์ฐพ์•„์„œ ๊ณ ์ˆ˜ํ•˜์ง€๋งŒ ์‹œ๊ฐ„์ด ์ง€๋‚จ์— ๋”ฐ๋ผ ๋” ๋งŽ์ด ๋ฐฐ์šฐ๊ณ  ๋” ํŽธํ•˜๊ฒŒ ์ „๋žต์„ ๋ฐœ์ „์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


๋‹ต๋ณ€

๋Šฆ์€ ๋‹ต๋ณ€

์˜ฌ๋ฐ”๋ฅธ ๋ฐฉ๋ฒ•์œผ๋กœ ํŒŒ์ผ์„ ํฌํ•จ์‹œํ‚ค๋Š” ๋ฐฉ๋ฒ• :

function wpse1403_bootstrap()
{
    // Here we load from our includes directory
    // This considers parent and child themes as well    
    locate_template( array( 'inc/foo.class.php' ), true, true );
}
add_action( 'after_setup_theme', 'wpse1403_bootstrap' );

ํ”Œ๋Ÿฌ๊ทธ์ธ์—์„œ๋„ ๋งˆ์ฐฌ๊ฐ€์ง€์ž…๋‹ˆ๋‹ค.

์˜ฌ๋ฐ”๋ฅธ ๊ฒฝ๋กœ ๋˜๋Š” URi๋ฅผ ์–ป๋Š” ๋ฐฉ๋ฒ•

๋˜ํ•œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํŒŒ์ผ ์‹œ์Šคํ…œ API ํ•จ์ˆ˜๋ฅผ ์‚ดํŽด๋ณด์‹ญ์‹œ์˜ค.

  • home_url()
  • plugin_dir_url()
  • plugin_dir_path()
  • admin_url()
  • get_template_directory()
  • get_template_directory_uri()
  • get_stylesheet_directory()
  • get_stylesheet_directory_uri()
  • ๊ธฐํƒ€

์˜ ์ˆ˜๋ฅผ ์ค„์ด๋Š” ๋ฐฉ๋ฒ• include/require

๋””๋ ‰ํ† ๋ฆฌ์—์„œ ๋ชจ๋“  ํŒŒ์ผ ์„ ๊ฐ€์ ธ์™€์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ

foreach ( glob( 'path/to/folder/*.php' ) as $file )
    include $file;

์ด๋Š” ์‹คํŒจ (ํ”„๋กœ๋•์…˜ ์‚ฌ์šฉ์— ์ ํ•ฉ) /๋กœ๋“œ ํ•  ์ˆ˜์—†๋Š” ํŒŒ์ผ์„ ๋ฌด์‹œํ•ฉ๋‹ˆ๋‹ค.

์ด ๋™์ž‘์„ ๋ณ€๊ฒฝํ•˜๋ ค๋ฉด ๊ฐœ๋ฐœ ์ค‘์— ๋‹ค๋ฅธ ๊ตฌ์„ฑ์„ ์‚ฌ์šฉํ•˜๋ ค๊ณ  ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

$files = ( defined( 'WP_DEBUG' ) AND WP_DEBUG )
    ? glob( 'path/to/folder/*.php', GLOB_ERR )
    : glob( 'path/to/folder/*.php' )

foreach ( $files as $file )
    include $file;

ํŽธ์ง‘ : OOP / SPL ์ ‘๊ทผ

๋ฐฉ๊ธˆ ๋Œ์•„์™€์„œ์ด ๋‹ต๋ณ€์ด ์ ์  ๋” ๋งŽ์€์ง€์ง€๋ฅผ ๋ฐ›๊ณ  ์žˆ์Œ์„ ๋ณด์•˜์„ ๋•Œ, ๋‚˜๋Š” PHP 5.3+ ์„ธ๊ณ„์—์„œ ์š”์ฆ˜ ์–ด๋–ป๊ฒŒํ•˜๊ณ  ์žˆ๋Š”์ง€ ๋ณด์—ฌ์ค„ ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ ์˜ˆ์ œ๋Š”์ด๋ผ๋Š” ํ…Œ๋งˆ ํ•˜์œ„ ํด๋”์—์„œ ๋ชจ๋“  ํŒŒ์ผ์„๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค src/. ์—ฌ๊ธฐ์—๋Š” ๋ฉ”๋‰ด, ์ด๋ฏธ์ง€ ๋“ฑ๊ณผ ๊ฐ™์€ ํŠน์ • ์ž‘์—…์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ชจ๋“  ๋‹จ์ผ ํŒŒ์ผ์ด๋กœ๋“œ ๋  ๋•Œ ์ด๋ฆ„์„ ์‹ ๊ฒฝ ์“ฐ์ง€ ์•Š์•„๋„๋ฉ๋‹ˆ๋‹ค. ์ด ๋””๋ ‰ํ† ๋ฆฌ์— ๋‹ค๋ฅธ ํ•˜์œ„ ํด๋”๊ฐ€ ์žˆ์œผ๋ฉด ๋ฌด์‹œ๋ฉ๋‹ˆ๋‹ค.

์ด \FilesystemIterator๋Š” PHP 5.3+์ž…๋‹ˆ๋‹ค supercedor ์˜ค๋ฒ„ \DirectoryIterator. ๋‘˜ ๋‹ค PHP SPL์˜ ์ผ๋ถ€์ž…๋‹ˆ๋‹ค. PHP 5.2์—์„œ๋Š” ๋‚ด์žฅ SPL ํ™•์žฅ ๊ธฐ๋Šฅ์„ ๋Œ ์ˆ˜ ์žˆ์—ˆ์ง€๋งŒ (๋ชจ๋“  ์„ค์น˜ ์ค‘ 1 % ๋ฏธ๋งŒ์ด ๊ทธ๋žฌ์Šต๋‹ˆ๋‹ค) SPL์€ ์ด์ œ PHP ํ•ต์‹ฌ์˜ ์ผ๋ถ€์ž…๋‹ˆ๋‹ค.

<?php

namespace Theme;

$files = new \FilesystemIterator( __DIR__.'/src', \FilesystemIterator::SKIP_DOTS );
foreach ( $files as $file )
{
    /** @noinspection PhpIncludeInspection */
    ! $files->isDir() and include $files->getRealPath();
}

์ด์ „์—๋Š” ์—ฌ์ „ํžˆ PHP 5.2.x๋ฅผ ์ง€์›ํ–ˆ์ง€๋งŒ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์†”๋ฃจ์…˜์„ ์‚ฌ์šฉ \FilterIteratorํ–ˆ์Šต๋‹ˆ๋‹ค. src/Filters๋””๋ ‰ํ† ๋ฆฌ์˜ A ๋Š” ํด๋”์˜ ์  ํฌ์ธํ„ฐ๊ฐ€ ์•„๋‹Œ ํŒŒ์ผ ๋งŒ ๊ฒ€์ƒ‰ํ•˜๊ณ  a \DirectoryIterator๋Š” ๋ฐ˜๋ณต ๋ฐ๋กœ๋“œ๋ฅผ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

namespace Theme;

use Theme\Filters\IncludesFilter;

$files = new IncludesFilter( new \DirectoryIterator( __DIR__.'/src' ) );
foreach ( $files as $file )
{
    include_once $files->current()->getRealPath();
}

๋Š” \FilterIterator๋งŒํผ ๊ฐ„๋‹จํ–ˆ๋‹ค :

<?php

namespace Theme\Filters;

class IncludesFilter extends \FilterIterator
{
    public function accept()
    {
        return
            ! $this->current()->isDot()
            and $this->current()->isFile()
            and $this->current()->isReadable();
    }
}

ํ˜„์žฌ๊นŒ์ง€๋Š” PHP 5.2๊ฐ€ ์ฃฝ๊ณ  / EOL์ด ์•„๋‹ˆ๋ผ (๊ทธ๋ฆฌ๊ณ  5.3๋„), ๋” ๋งŽ์€ ์ฝ”๋“œ์™€ ๊ฒŒ์ž„์— ํŒŒ์ผ์ด ํ•˜๋‚˜ ๋” ์žˆ๋‹ค๋Š” ์‚ฌ์‹ค์ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋‚˜์ค‘์— ๋‚˜์•„๊ฐˆ ํ•„์š”๊ฐ€ ์—†์œผ๋ฉฐ PHP 5.2.x๋ฅผ ์ง€์›ํ•  ์ด์œ ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.

์š”์•ฝ

๋” ์ž์„ธํ•œ ๋‚ด์šฉ์€ WPKrauts์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค .

ํŽธ์ง‘ ๋ถ„๋ช…ํžˆ ์˜ฌ๋ฐ”๋ฅธ ๋ฐฉ๋ฒ•์€ ๋„ค์ž„ ์ŠคํŽ˜์ด์Šค๋ฅผ ํ†ตํ•ด ์ด๋ฏธ ์ •์˜ ๋œ ์ ์ ˆํ•œ ๋””๋ ‰ํ† ๋ฆฌ์— ๋ชจ๋“  ๊ฒƒ์„ ๋„ฃ์–ด PSR-4 ์ž๋™๋กœ๋“œ๋ฅผ namespace์œ„ํ•ด ์ค€๋น„๋œ d ์ฝ”๋“œ ๋ฅผ ์‚ฌ์šฉ ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ Composer ์™€ a ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ข…์†์„ฑ์„ ๊ด€๋ฆฌํ•˜๊ณ  PHP ์ž๋™ ๋กœ๋”๋ฅผ ์ž๋™์œผ๋กœ ๋นŒ๋“œํ•˜์‹ญ์‹œ์˜ค (์ด๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ํŒŒ์ผ์„ ์ž๋™์œผ๋กœ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค ). WP Starter ๋Š” PHP ์„ธ๊ณ„์—์„œ ์‚ฌ์‹ค์ƒ์˜ ํ‘œ์ค€์ด๋ฉฐ, ๊ฐ€์žฅ ์‰ฌ์šด ๋ฐฉ๋ฒ•์ด๋ฉฐ ์‚ฌ์ „ ์ž๋™ํ™”๋˜๊ณ  ๋‹จ์ˆœํ™”๋˜์—ˆ์Šต๋‹ˆ๋‹ค .composer.jsonuse \<namespace>\ClassName


๋‹ต๋ณ€

๋ณด์ผ๋Ÿฌ ํ”Œ๋ ˆ์ดํŠธ์—์„œ ์‚ฌ์šฉ์ž ์ •์˜ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ…Œ๋งˆ ๋””๋ ‰ํ† ๋ฆฌ์—์„œ ํ•จ์ˆ˜๋ผ๋Š” ํด๋”๋ฅผ ์ฐพ์œผ์‹ญ์‹œ์˜ค (์—†๋Š” ๊ฒฝ์šฐ). ๊ทธ๋Ÿฐ ๋‹ค์Œ ํ•ด๋‹น ํด๋”์—์„œ ์ฐพ์€ ๋ชจ๋“  .php ํŒŒ์ผ์˜ ๋ฐฐ์—ด์„ ๋งŒ๋“ค๊ณ  (์žˆ๋Š” ๊ฒฝ์šฐ) include ()๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋“ค ๊ฐ๊ฐ์—.

์ด๋ ‡๊ฒŒํ•˜๋ฉด ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ์„ ์ž‘์„ฑํ•ด์•ผ ํ•  ๋•Œ๋งˆ๋‹ค ํ•จ์ˆ˜ ํด๋”์— PHP ํŒŒ์ผ์„ ์ถ”๊ฐ€ํ•˜๊ธฐ ๋งŒํ•˜๋ฉด ์‚ฌ์ดํŠธ์— ์ฝ”๋“œ๋ฅผ ์ฝ”๋”ฉ ํ•  ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.

<?php
/* 
FUNCTIONS for automatically including php documents from the functions folder.
*/
//if running on php4, make a scandir functions
if (!function_exists('scandir')) {
  function scandir($directory, $sorting_order = 0) {
    $dh = opendir($directory);
    while (false !== ($filename = readdir($dh))) {
      $files[] = $filename;
    }
    if ($sorting_order == 0) {
      sort($files);
    } else {
      rsort($files);
    }
    return ($files);
  }
}
/*
* this function returns the path to the funtions folder.
* If the folder does not exist, it creates it.
*/
function get_function_directory_extension($template_url = FALSE) {
  //get template url if not passed
  if (!$template_url)$template_url = get_bloginfo('template_directory');


  //replace slashes with dashes for explode
  $template_url_no_slash = str_replace('/', '.', $template_url);

  //create array from URL
  $template_url_array = explode('.', $template_url_no_slash);

  //--splice array

  //Calculate offset(we only need the last three levels)
  //We need to do this to get the proper directory, not the one passed by the server, as scandir doesn't work when aliases get involved.
  $offset = count($template_url_array) - 3;

  //splice array, only keeping back to the root WP install folder (where wp-config.php lives, where the front end runs from)
  $template_url_array = array_splice($template_url_array, $offset, 3);
  //put back togther as string
  $template_url_return_string = implode('/', $template_url_array);
  fb::log($template_url_return_string, 'Template'); //firephp

  //creates current working directory with template extention and functions directory    
  //if admin, change out of admin folder before storing working dir, then change back again.
  if (is_admin()) {
    $admin_directory = getcwd();
    chdir("..");
    $current_working_directory = getcwd();
    chdir($admin_directory);
  } else {
    $current_working_directory = getcwd();
  }
  fb::log($current_working_directory, 'Directory'); //firephp

  //alternate method is chdir method doesn't work on your server (some windows servers might not like it)
  //if (is_admin()) $current_working_directory = str_replace('/wp-admin','',$current_working_directory);

  $function_folder = $current_working_directory . '/' . $template_url_return_string . '/functions';


  if (!is_dir($function_folder)) mkdir($function_folder); //make folder, if it doesn't already exist (lazy, but useful....ish)
  //return path
  return $function_folder;

}

//removed array elements that do not have extension .php
function only_php_files($scan_dir_list = false) {
  if (!$scan_dir_list || !is_array($scan_dir_list)) return false; //if element not given, or not array, return out of function.
  foreach ($scan_dir_list as $key => $value) {
    if (!strpos($value, '.php')) {

      unset($scan_dir_list[$key]);
    }
  }
  return $scan_dir_list;
}
//runs the functions to create function folder, select it,
//scan it, filter only PHP docs then include them in functions

add_action('wp_head', fetch_php_docs_from_functions_folder(), 1);
function fetch_php_docs_from_functions_folder() {

  //get function directory
  $functions_dir = get_function_directory_extension();
  //scan directory, and strip non-php docs
  $all_php_docs = only_php_files(scandir($functions_dir));

  //include php docs
  if (is_array($all_php_docs)) {
    foreach ($all_php_docs as $include) {
      include($functions_dir . '/' . $include);
    }
  }

}

๋‹ต๋ณ€

ํด๋” ์•ˆ์˜ ํŒŒ์ผ์— ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค. ์ด ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋ฉด ์ƒˆ ํŒŒ์ผ์„ ์ถ”๊ฐ€ ํ•  ๋•Œ ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ์„ ์‰ฝ๊ฒŒ ์ถ”๊ฐ€ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๋‚˜๋Š” ํ•ญ์ƒ ํด๋ž˜์Šค ๋˜๋Š” ๋„ค์ž„ ์ŠคํŽ˜์ด์Šค๋กœ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค-ํ•จ์ˆ˜, ๋ฉ”์†Œ๋“œ ๋“ฑ์˜ ๋„ค์ž„ ์ŠคํŽ˜์ด์Šค์— ๋Œ€ํ•ด ๋” ๋งŽ์€ ์ œ์–ด๊ถŒ์„ ๋ถ€์—ฌํ•˜์‹ญ์‹œ์˜ค.

์ž‘์€ ์˜ˆ ์•„๋ž˜; ๋˜ํ•œ ํด๋ž˜์Šค * .php์— ๋Œ€ํ•œ ๊ณ„์•ฝ๊ณผ ํ•จ๊ป˜ ์‚ฌ์šฉ

public function __construct() {

    $this->load_classes();
}

/**
 * Returns array of features, also
 * Scans the plugins subfolder "/classes"
 *
 * @since   0.1
 * @return  void
 */
protected function load_classes() {

    // load all files with the pattern class-*.php from the directory classes
    foreach( glob( dirname( __FILE__ ) . '/classes/class-*.php' ) as $class )
        require_once $class;

}

ํ…Œ๋งˆ์—์„œ ๋‚˜๋Š” ์ข…์ข… ๋‹ค๋ฅธ ์‹œ๋‚˜๋ฆฌ์˜ค๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ง€์› ID์—์„œ externel ํŒŒ์ผ์˜ ๊ธฐ๋Šฅ์„ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค (์˜ˆ ์ฐธ์กฐ). externel ํŒŒ์ผ์˜ ๊ธฐ๋Šฅ์„ ์‰ฝ๊ฒŒ ๋น„ํ™œ์„ฑํ™” ํ•  ๊ฒฝ์šฐ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค. WP ํ•ต์‹ฌ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๊ณ  require_if_theme_supports()์ง€์› ID๊ฐ€ ํ™œ์„ฑํ™” ๋œ ๊ฒฝ์šฐ์—๋งŒ๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ ์˜ˆ์—์„œ๋Š” ํŒŒ์ผ์„๋กœ๋“œํ•˜๊ธฐ ์ „์— ์ค„ ์—์„œ์ด ์ง€์›๋˜๋Š” ID๋ฅผ ์ •์˜ํ–ˆ์Šต๋‹ˆ๋‹ค.

    /**
     * Add support for Theme Customizer
     * 
     * @since  09/06/2012
     */
    add_theme_support( 'documentation_customizer', array( 'all' ) );
    // Include the theme customizer for options of theme options, if theme supported
    require_if_theme_supports( 
        'documentation_customizer',
        get_template_directory() . '/inc/theme-customize.php'
    );

์ด ํ…Œ๋งˆ ์˜ ์ €์žฅ์†Œ ์—์„œ ๋” ๋งŽ์€ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค .


๋‹ต๋ณ€

๋„คํŠธ์›Œํฌ ์„ค์น˜๋ฅผ ํ†ตํ•ด ์•ฝ 50 ๊ฐœ์˜ ๊ณ ์œ  ํ•œ ์‚ฌ์šฉ์ž ์ •์˜ ํŽ˜์ด์ง€ ์œ ํ˜•์ด์žˆ๋Š” ์„œ๋ฒ„๋ฅผ ๋‹ค๋ฅธ ์–ธ์–ด๋กœ ์‚ฌ์ดํŠธ๋ฅผ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค. ํ”Œ๋Ÿฌ๊ทธ์ธ ํ†ค๊ณผ ํ•จ๊ป˜.

์šฐ๋ฆฌ๋Š” ์–ด๋Š ์‹œ์ ์—์„œ ๊ทธ๊ฒƒ์„ ๋ชจ๋‘ ๋ถ„ํ• ํ•ด์•ผํ–ˆ์Šต๋‹ˆ๋‹ค. 20-30k ์ค„์˜ ์ฝ”๋“œ๊ฐ€์žˆ๋Š” ํ•จ์ˆ˜ ํŒŒ์ผ์€ ์ „ํ˜€ ์žฌ๋ฏธ ์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

์šฐ๋ฆฌ๋Š” ์ฝ”๋“œ๋ฒ ์ด์Šค๋ฅผ ๋” ์ž˜ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ๋ชจ๋“  ์ฝ”๋“œ๋ฅผ ๋ฆฌํŒฉํ† ๋งํ•˜๊ธฐ๋กœ ๊ฒฐ์ •ํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ธฐ๋ณธ ์›Œ๋“œ ํ”„๋ ˆ์Šค ํ…Œ๋งˆ ๊ตฌ์กฐ๋Š” ์ž‘์€ ์‚ฌ์ดํŠธ์—๋Š” ์ ํ•ฉํ•˜์ง€๋งŒ ๋” ํฐ ์‚ฌ์ดํŠธ์—๋Š” ์ ํ•ฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

์šฐ๋ฆฌ์˜ ์ƒˆ๋กœ์šด functions.php์—๋Š” ์‚ฌ์ดํŠธ๋ฅผ ์‹œ์ž‘ํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ๊ฒƒ๋งŒ ํฌํ•จ๋˜์–ด ์žˆ์ง€๋งŒ ํŠน์ • ํŽ˜์ด์ง€์— ์†ํ•˜๋Š” ๊ฒƒ์€ ์—†์Šต๋‹ˆ๋‹ค.

์ด์ œ ์šฐ๋ฆฌ๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” ํ…Œ๋งˆ ๋ ˆ์ด์•„์›ƒ์€ MCV ๋””์ž์ธ ํŒจํ„ด๊ณผ ๋น„์Šทํ•˜์ง€๋งŒ ์ ˆ์ฐจ ์  ์ฝ”๋”ฉ ์Šคํƒ€์ผ์ž…๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด ํšŒ์› ํŽ˜์ด์ง€ :

page-member.php . ํŽ˜์ด์ง€๋ฅผ ์ดˆ๊ธฐํ™”ํ•ฉ๋‹ˆ๋‹ค. ์˜ฌ๋ฐ”๋ฅธ ์•„์•ฝ์Šค ํ•จ์ˆ˜ ๋˜๋Š” ์œ ์‚ฌํ•œ ํ˜ธ์ถœ. MCV ์Šคํƒ€์ผ์˜ ์ปจํŠธ๋กค๋Ÿฌ ๋ถ€ํ’ˆ๊ณผ ๋™์ผ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

functions-member.php . ์ด ํŽ˜์ด์ง€์™€ ๊ด€๋ จ๋œ ๋ชจ๋“  ๊ธฐ๋Šฅ์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ ํšŒ์›์„์œ„ํ•œ ๊ธฐ๋Šฅ์ด ํ•„์š”ํ•œ ๋‹ค๋ฅธ ์„œ๋ฒ„ ํŽ˜์ด์ง€์—๋„ ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

content-member.php . HTML์— ๋Œ€ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ MCV์˜ ๋ชจ๋ธ๊ณผ ๋™๋“ฑํ•˜๊ฒŒ ์ค€๋น„ํ•ฉ๋‹ˆ๋‹ค.

layout-member.php . HTML ๋ถ€๋ถ„.

Efter๋Š” ์ด๋Ÿฌํ•œ ๋ณ€๊ฒฝ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜์—ฌ ๊ฐœ๋ฐœ ์‹œ๊ฐ„์ด 50 % ์‰ฝ๊ฒŒ ๋‹จ์ถ•๋˜์—ˆ์œผ๋ฉฐ ์ด์ œ ์ œํ’ˆ ์†Œ์œ ์ž๊ฐ€ ์ƒˆ๋กœ์šด ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋ฐ ์–ด๋ ค์›€์„ ๊ฒช๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๐Ÿ™‚


๋‹ต๋ณ€

์ž์‹ ํ…Œ๋งˆ functions.php ํŒŒ์ผ์—์„œ :

    require_once( get_stylesheet_directory() . '/inc/custom.php' );

๋‹ต๋ณ€

functions.php์—์„œ ํ•„์š”ํ•œ ํŒŒ์ผ์„ ํ˜ธ์ถœํ•˜๋Š” ๋” ์šฐ์•„ํ•œ ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

require_once locate_template ( โ€˜/ inc / functions / shortcodes.phpโ€™);