Почему стоит участвовать
в разработке WordPress
Сергей Бирюков
WordCamp Russia 2015
Обо мне
Сергей Бирюков
● Разработчик ядра WordPress
core.trac.wordpress.org
● Локализатор WP в России
ru.wordpress.org
sergeybiryukov.ru
@SergeyBiryukov
Зачем смотреть,
как устроен WordPress?
Как следить
за разработкой WordPress?
● make.wordpress.org/core/
● wp-svn
● wp-trac
wp-admin/edit-form-advanced.php
wp-admin/includes/meta-boxes.php
wp-includes/default-filters.php
grep, ack, cmd-f и т.д.
PhpStorm 8
PHPXref
Codex
developer.wordpress.org
add_action( 'publish_post' )
add_filter( 'all', function( $stuff ) {
echo '<code>' .
current_filter() .
'</code>';
return $stuff;
});
add_filter( 'gettext',
function( $new, $old, $domain ) {
if ( 'Set featured image' === $old ) {
if ( 'company' === get_post_type() ) {
$new = __( 'Set company logo', 'mydomain' );
}
}
return $new;
}, 10, 3 );
add_filter( 'admin_post_thumbnail_html',
function( $output, $post_id ) {
if ( 'company' === get_post_type( $post_id ) ) {
$output =
str_replace( __( 'Set featured image' ),
'Select / Upload a company logo', $output );
$output =
str_replace( __( 'Remove featured image' ),
'Remove company logo', $output );
}
return $output;
}, 10, 2 );
Для фильтров и действий
важен контекст
apply_filters( 'media_view_strings', $strings, $post )
remove_post_type_support()
Экран редактирования —
одна большая форма
<textarea name="excerpt" id="attachment_caption">
<?php echo $post->post_excerpt; ?>
</textarea>
Произвольные таксономии
add_action( 'save_post', function( $post_id, $post ) {
// Не забываем проверить nonce и привилегии
if ( isset( $_POST['my_tax_ui'] ) ) {
// array_map()
$terms = $_POST['my_tax_ui'];
wp_set_object_terms( $post_id, $terms, 'my_tax' );
} else {
wp_delete_object_term_relationships( $post_id, 'my_tax' );
}
}, 10, 2 );
<select name="tax_input['my_tax'][]">
add_action( 'save_post', function( $post_id, $post ) {
// Не забываем проверить nonce и привилегии
If ( ! isset( $_POST['my_tax_ui'] ) ) {
wp_delete_object_term_relationships(
$post_id, 'my_tax'
);
}
}, 10, 2 );
<input type="hidden"
name="tax_input['my_tax'][]"
value="0" />
add_rewrite_endpoint( 'export', EP_PAGES )
site.com/some-page/export/
site.com/some-page/export/json/
get_query_var( 'export' )
add_filter( 'request', function( $vars ) {
if ( isset( $vars['export'] )
&& empty( $vars['export'] ) ) {
$vars['export'] = '1';
}
return $vars;
});
get_query_var( 'export', null )
Сложные запросы
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'age',
'terms' => array( '5' ),
),
array(
'relation' => 'OR',
array(
'taxonomy' => 'academic_skills',
'terms' => array( 'reading', 'writing' ),
),
array(
'taxonomy' => 'skills',
'terms' => array( 'focus', 'flexibility' ),
),
),
)
term_id + taxonomy = term_taxonomy_id
sergeybiryukov.ru
@SergeyBiryukov
Спасибо! Вопросы?

Looking into WordPress Core, WordCamp Russia 2015