Как получить чёрный пояс по WordPress? v2.0
-
Upload
yevhen-kotelnytskyi -
Category
Software
-
view
482 -
download
1
Transcript of Как получить чёрный пояс по WordPress? v2.0
![Page 1: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/1.jpg)
Как получить чёрный пояс
по WordPress? v. 2.0
Евгений КотельницкийKharkiv WordPress, 2016
![Page 2: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/2.jpg)
Евгений Котельницкий
+YevhenKotelnytskyi
@yeeevhenhttp://4coder.info/me
![Page 4: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/4.jpg)
План1. С чего мы начинали?
2. Что определяет уровень разработчика?
3. Через что проходит WP разработчик?
4. Что дальше?
![Page 5: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/5.jpg)
![Page 6: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/6.jpg)
Делаем первые шаги
![Page 7: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/7.jpg)
Шаг 1 - Регестрируем блог на WP.com
![Page 8: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/8.jpg)
Шаг 2 - Поднимаем WP на Shared-хостинге
![Page 9: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/9.jpg)
Шаг 3 - Устанавливаем темы
![Page 10: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/10.jpg)
Шаг 4 - Вносим правки в тему
![Page 11: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/11.jpg)
Шаг 5 - Устанавливаем плагины
![Page 12: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/12.jpg)
Шаг 6 - Изучаем админку
![Page 13: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/13.jpg)
WordPress User Roles
User Roles
● Super Admin – site network administration;
● Administrator – administration features within a single site;
● Editor – can publish and manage posts of other users;
● Author – can publish and manage their own posts;
● Contributor – can write posts but cannot publish them;
● Subscriber – can only manage their profile.
![Page 14: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/14.jpg)
Первый пояс есть!
![Page 15: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/15.jpg)
FTP / SFTP
![Page 16: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/16.jpg)
PhpMyAdmin
![Page 17: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/17.jpg)
Начинаем создавать темы осмысленно
Знакомимся с теорией:
● http://codex.wordpress.org/Theme_Development● http://codex.wordpress.org/Template_Hierarchy● http://codex.wordpress.org/Conditional_Tags● ...
![Page 18: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/18.jpg)
Plugins & MU plugins
![Page 19: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/19.jpg)
Post Types
Стандартные и пользовательские типы контента
● Post (post type: 'post')
● Page (post type: 'page')
● Attachment (post type: 'attachment')
● Revision (post type: 'revision')
● Navigation menu (post type: 'nav_menu_item')
● Custom Post Type (CPT): register_post_type()
![Page 20: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/20.jpg)
Taxonomies
Стандартная и пользовательская систематика
● Category (taxonomy: 'category')
● Tag (taxonomy: 'post_tag')
● Link Category (taxonomy: 'link_category')
● Post Formats (taxonomy: 'post_format')
● Custom Taxonomies: register_taxonomy()
![Page 21: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/21.jpg)
Data Access APIПолучаем доступ к данным
● WP_Query● WP_Tax_Query● WP_User_Query● get_posts ()● get_terms ()● get_option ()● get_post_meta ()● get_user_meta ()● ...
![Page 22: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/22.jpg)
Второй пояс получен!
![Page 23: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/23.jpg)
Database StructureПолучаем прямой доступ к данным
![Page 24: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/24.jpg)
Direct Database Access abstraction
<?php
global $wpdb;
$wpdb->query(
$wpdb->prepare(
"DELETE FROM $wpdb->postmeta
WHERE post_id = %d
AND meta_key = %s",
13, 'gargle' ) );
?>
![Page 25: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/25.jpg)
/**
* WordPress Database Access Abstraction
*/
class wpdb {
public function prepare( $query, $args );
public function show_errors( $show = true );
public function query( $query );
public function get_results( $query = null, $output = OBJECT ) {
public function get_row( $query = null, $output = OBJECT, $y = 0 );
public function get_col( $query = null , $x = 0 );
public function get_var( $query = null, $x = 0, $y = 0 );
public function update( $table, $data, $where, $format = null, $where_format = null );
...
Direct Database Access abstraction
![Page 26: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/26.jpg)
Система хуков
<?php
do_action( $tag, $arg_a, $arg_b, $etc );
add_action( $tag, $function_to_add, $priority = 10, $accepted_args = 1 );
?>
<?php
apply_filters( $tag, $value );
add_filter( $tag, $function_to_add, $priority, $accepted_args );
?>
Actions
Filters
![Page 27: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/27.jpg)
Достигнут новый пояс!
![Page 28: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/28.jpg)
Source Code Management Systems
![Page 29: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/29.jpg)
Стандарты кодирования
PHP Coding Standards
HTML Coding Standards
CSS Coding Standards
JavaScript Standards
![Page 30: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/30.jpg)
Localization
![Page 31: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/31.jpg)
Localization
<?php
load_textdomain( $domain, $mofile );
load_plugin_textdomain( $domain, $abs_rel_path, $plugin_rel_path );
?>
<?php
$translated = __( 'Hello World!', 'domain' );
?>
<?php _e( 'Hello World!', 'domain' ) ?>
![Page 32: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/32.jpg)
Localization & JS
<?php
// Register the script first
wp_register_script( 'some_handle', 'path/to/myscript.js' );
// Now we can localize the script with our data
$translation = array(
'some_str' => __( 'Some string', 'domain' ),
'a_value' => '10'
);
wp_localize_script( 'handle', 'object_name', $translation );
// The script can be enqueued now or later
wp_enqueue_script( 'handle' );
![Page 33: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/33.jpg)
Зелёный пояс!
![Page 34: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/34.jpg)
WP Network
![Page 35: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/35.jpg)
WP Network
<?php
switch_to_blog( $blog_id );
// Do something
restore_current_blog();
?>
![Page 36: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/36.jpg)
Network Database
● wp_blogs
● wp_blog_versions
● wp_registration_log
● wp_signups
● wp_site
● wp_sitemeta
![Page 37: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/37.jpg)
Быстродействие
![Page 38: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/38.jpg)
Синий пояс!
![Page 39: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/39.jpg)
WordPress User Roles
Super Admin capabilities
● manage_network
● manage_sites
● manage_network_users
● manage_network_plugins
● manage_network_themes
● manage_network_options
● ...
Subscriber capabilities
● read
![Page 40: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/40.jpg)
WordPress User Roles
class WP_Roles {
/**
* Add role name with capabilities to list.
*/
public function add_role( $role, $display_name, $capabilities = array() );
public function remove_role( $role );
/**
* Add capability to role.
*/
public function add_cap( $role, $cap, $grant = true );
public function remove_cap( $role, $cap );
...
![Page 41: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/41.jpg)
WordPress User class
class WP_User {
/**
* Add role to user.
*/
public function add_role( $role );
public function remove_role( $role );
public function set_role( $role );
/**
* Add capability and grant or deny access to capability.
*/
public function add_cap( $cap, $grant = true );
public function remove_cap( $cap );
...
![Page 42: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/42.jpg)
class WP_User {
/**
* Whether user has capability or role name.
* @return bool True, if user has capability;
* false, if user does not have capability.
*/
public function has_cap( $cap ) {
$caps = call_user_func_array( 'map_meta_cap', $args );
...
// Must have ALL requested caps
$capabilities = apply_filters(
'user_has_cap', $this->allcaps,
$caps, $args, $this );
...
WordPress User class
![Page 43: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/43.jpg)
Впервые задумываемся о безопасности
![Page 44: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/44.jpg)
Коричневый пояс!
![Page 45: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/45.jpg)
Как работает WordPress?WordPress environment setup class
class WP {
/**
* Sets up all of the variables required by the WordPress environment.
* @param string|array $query_args Passed to {@link parse_request()}
*/
public function main($query_args = '') {
$this->init();
$this->parse_request($query_args);
$this->send_headers();
$this->query_posts();
$this->handle_404();
$this->register_globals();
do_action_ref_array( 'wp', array( &$this ) );
}
...
![Page 46: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/46.jpg)
WP_Rewrite - “Роутинг”
![Page 47: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/47.jpg)
WP_Rewrite - “Роутинг”
class WP_Rewrite {
/**
* Retrieve the rewrite rules.
* @return array Rewrite rules.
*/
public function wp_rewrite_rules() {
$this->rules = get_option('rewrite_rules');
if ( empty($this->rules) ) {
$this->matches = 'matches';
$this->rewrite_rules();
update_option('rewrite_rules', $this->rules);
}
return $this->rules;
}
...
![Page 48: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/48.jpg)
WP_Rewrite - “Роутинг”Rewrite Rules
<?php
$rewrite = $wp_rewrite->wp_rewrite_rules();
array(
[robots\.txt$] => index.php?robots=1
[category/(.+?)/?$] => index.php?category_name=$matches[1]
[page/?([0-9]{1,})/?$] => index.php?&paged=$matches[1]
[search/(.+)/?$] => index.php?s=$matches[1]
[([0-9]{4})/?$] => index.php?year=$matches[1]
[.?.+?/attachment/([^/]+)/?$] => index.php?attachment=$matches[1]
[(.?.+?)(/[0-9]+)?/?$] => index.php?pagename=$matches[1]&page=$matches[2]
...
![Page 49: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/49.jpg)
WP_Rewrite - “Роутинг”Rewrite Rules filters
1. apply_filters( 'post_rewrite_rules', $post_rewrite );
2. apply_filters( 'date_rewrite_rules', $date_rewrite );
3. apply_filters( 'root_rewrite_rules', $root_rewrite );
4. apply_filters( 'comments_rewrite_rules', $comments_rewrite );
5. apply_filters( 'search_rewrite_rules', $search_rewrite );
6. apply_filters( 'author_rewrite_rules', $author_rewrite );
7. apply_filters( 'page_rewrite_rules', $page_rewrite );
8. apply_filters( $permastructname . '_rewrite_rules', $rules );
9. apply_filters( 'rewrite_rules_array', $this->rules );
![Page 50: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/50.jpg)
WP_Rewrite - “Роутинг”WP_Rewrite::add_rule ()
// http://example.com/properties/123/
add_action( 'init', '_rewrites_init' );
function _rewrites_init() {
add_rewrite_rule(
'properties/([0-9]+)/?$',
'index.php?pagename=properties&property_id=$matches[1]', 'top' );
}
add_filter( 'query_vars', '_query_vars' );
function _query_vars( $query_vars ) {
$query_vars[] = 'property_id';
return $query_vars;
}
![Page 51: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/51.jpg)
WP_Rewrite - “Роутинг”WP_Rewrite::add_permastruct ()
<?php
class WP_Rewrite {
/**
* Add a new permalink structure.
*/
public function add_permastruct( $name, $struct, $args = array() ) {
...
$this->extra_permastructs[ $name ] = $args;
}
...
?>
![Page 52: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/52.jpg)
WP_Rewrite - “Роутинг”WP_Rewrite::add_permastruct ()
<?php
// http://example.com/au/some-prize-category/some-competition/
$wp_rewrite->add_rewrite_tag('%competition%', '([^/]+)', 'competition=');
$wp_rewrite->add_rewrite_tag('%prize_category%', '([^/]+)', 'prize_category=');
$wp_rewrite->add_permastruct(
'competition',
'/au/%prize_category%/%competition%/',
array( 'walk_dirs' => false ));
?>
![Page 53: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/53.jpg)
WP_Query - The Query classWordPress environment setup class
class WP {
/**
* Sets up all of the variables required by the WordPress environment.
* @param string|array $query_args Passed to {@link parse_request()}
*/
public function main($query_args = '') {
$this->init();
$this->parse_request($query_args);
$this->send_headers();
$this->query_posts();
$this->handle_404();
$this->register_globals();
do_action_ref_array( 'wp', array( &$this ) );
}
...
![Page 54: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/54.jpg)
WP_Query - The Query classThe Main Query
/**
* WordPress environment setup class.
*/
class WP {
/**
* Set up the Loop based on the query variables.
*/
public function query_posts() {
global $wp_the_query;
$this->build_query_string();
$wp_the_query->query($this->query_vars);
}
...
![Page 55: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/55.jpg)
WP_Query - The Query class
class WP_Query {
/**
* Sets up the WordPress query by parsing query string.
* @return array List of posts.
*/
public function query( $query ) {
$this->init();
$this->query = $this->query_vars = wp_parse_args( $query );
return $this->get_posts();
}
/**
* Retrieve the posts based on query variables.
* @return array List of posts.
*/
public function get_posts() {
...
do_action_ref_array( 'pre_get_posts', array( &$this ) );
...
![Page 56: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/56.jpg)
WP_Query - The Query classQuery vars
/**
* Retrieve variable in the WP_Query class.
*
* @see WP_Query::get()
* @uses $wp_query
*
* @return mixed
*/
function get_query_var( $var, $default = '' ) {
global $wp_query;
return $wp_query->get( $var, $default );
}
![Page 57: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/57.jpg)
Чёрный пояс!
![Page 58: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/58.jpg)
Это всё?
![Page 59: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/59.jpg)
Это начало :)
![Page 60: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/60.jpg)
Highload & Perfomance,
Architecture, Supportability, Usability,
UNIX/Linux CLI, Stability, Unit
Testing, Continius integration,
… Communication skills,
Time management
![Page 61: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/61.jpg)
Вопросы?
![Page 62: Как получить чёрный пояс по WordPress? v2.0](https://reader034.fdocuments.us/reader034/viewer/2022042707/58eb7ea51a28ab01658b4667/html5/thumbnails/62.jpg)
Спасибо!