
WordPress
- 61 ответ
- 0 вопросов
68
Вклад в тег
add_role('newvabuser',
__('Новый пользователь','VAB'),
array(
'read'=>true,
'edit_posts'=>false,
'delete_posts'=>false,
'publish_posts'=>false,
'upload_files'=>true,
)
);
remove_role('newvabuser');
add_action('init','create_custom_post_types');
function create_custom_post_types(){
register_post_type('vabs',
array(
'labels'=>array(
'name'=>__('Новый тип записи','VAB'),
'singular_name'=>__('Новый тип записи','VAB'),
'menu_name'=>__('Новый тип записи','VAB'),
'add_new'=>__('Добавить новую','VAB'),
'add_new_item'=>__('Добавить новую','VAB'),
'edit_item'=>__('Редактировать','VAB'),
'new_item'=>__('Новая','VAB'),
'all_items'=>__('Все записи','VAB'),
'view_item'=>__('Просмотр','VAB'),
'search_items'=>__('Искать','VAB'),
'not_found'=>__('Записи не найдены','VAB'),
'not_found_in_trash'=>__('В корзине записи не найдены','VAB'),
'parent_item_colon'=>''
),
'public'=>true,
'has_archive'=>true,
'rewrite'=>array('slug'=>'vab'),
'capability_type'=>'vab',
'capabilities'=>array(
'publish_posts'=>'publish_vabs',
'edit_posts'=>'edit_vabs',
'edit_others_posts'=>'edit_others_vabs',
'delete_posts'=>'delete_vabs',
'delete_others_posts'=>'delete_others_vabs',
'read_private_posts'=>'read_private_vabs',
'edit_post'=>'edit_vabs',
'delete_post'=>'delete_vabs',
'read_post'=>'read_vabs',
'assign_terms' =>'edit_taxo',
'manage_terms'=>'manage_vab_terms',
'edit_terms'=>'manage_vab_terms',
'delete_terms'=>'delete_vab_terms',
'assign_terms'=>'edit_vab-type'
),
'supports'=>array('title','editor','thumbnail')
)
);
}
add_action('admin_init','add_vabs_caps');
function add_vabs_caps(){
$admins=get_role('newvabuser');
$admins->add_cap('edit_vabs');
$admins->add_cap('publish_vabs');
$admins->add_cap('read_vabs');
$admins->add_cap('read_private_vabs');
$admins->add_cap('delete_vabs');
$admins->add_cap('edit_taxo');
$admins->remove_cap('edit_others_vabs');
$admins->remove_cap('delete_others_vabs');
$admins->add_cap('manage_vab_terms');
$admins->add_cap('delete_vab_terms');
$admins->add_cap('edit_vab-type');
$admins->add_cap('manage_categories');
$admins->add_cap('edit_categories');
$admins->add_cap('delete_categories');
$admins->add_cap('assign_categoriess');
}
Обычные thumbnail и тд не пойдут. Так как они просто уменьшают саму картинку,
//получаем в шаблоне:
$attachment_src=wp_get_attachment_image_src(get_post_thumbnail_id(),'thumbnail');
//functions.php
add_filter('wp_handle_upload_prefilter','add_handle_upload');
if(!function_exists('add_handle_upload')){
function add_handle_upload($file){
add_image_size('mysize',600,200,array('center','center'));
return $file;
}}
//получаем в шаблоне:
$attachment_src=wp_get_attachment_image_src(get_post_thumbnail_id(),'mysize');
//functions.php
add_filter('wp_handle_upload_prefilter','add_handle_upload');
if(!function_exists('add_handle_upload')){
function add_handle_upload($file){
$tmp_name=$file['tmp_name'];
$image=new Imagick($tmp_name);
$image->chopImage(0,100,0,0);//отрезаем 100 px сверху
$imageprops=$image->getImageGeometry();//чтобы отрезать снизу надо узнать высоту и отнять 100 px и уже от нее отрезать все то, что ниже
$image->chopImage(0,100,0,$imageprops['height']-100);//отрезаем 100 px снизу
$image->writeImage($tmp_name);//перезаписываем временный файл
return $file;
}}
...
$customizer->get_setting('blogname')->transport='postMessage';
$customizer->get_setting('blogdescription')->transport='postMessage';
...
//$wp_customize->add_setting('header_h1',array('transport'=>'postMessage'));
(function($){
var api=wp.customize;
api('blogname',function(value){value.bind(function(to){$('.site-title a').text(to);});});
api('blogdescription',function(value){value.bind(function(to){$('.site-description a').text(to);});});
...
$wp_customize->add_setting('header_h1');
add_action( 'customize_register', 'hgjghjghj' );
function hgjghjghj($wp_customize){
$wp_customize->add_panel(
'panel_main_page',
array(
'title' => 'Контент на главной странице',
'priority' => 999,
)
);
$wp_customize->add_section(
'header_h1',
array(
'panel' => 'panel_main_page',
'title' => 'Заголовок (h1) страницы',
'priority' => 0,
)
);
$wp_customize->add_setting(
'header_h1',array('transport'=>'postMessage')
);
$wp_customize->add_control(
'header_h1',
array(
'section' => 'header_h1',
'label' => 'Текст заголовка',
'type' => 'text'
)
);
}
...
api('header_h1',function(value){value.bind(function(to){$('#qweqweqwe').text(to);});});
...
//подключаем js для превью через add_action('customize_preview_init','preview_customize_enqueue');
//либо пишем калбак функцию и пишем js в ней...
echo '<div id="qweqweqwe">'.get_theme_mod('header_h1').'</div>';
add_filter('template_include','VABch_include');
if(!function_exists('VABch_include')):function VABch_include($path){
if(is_singular('post')){
return get_stylesheet_directory().'/single-VAB.php';
}
return $path;}endif;
if(is_singular('post')){
скорректируйте данное условие под себя. Если оставить так, то все обычные записи будут выводится через шаблон single-VAB.php в корне темы. single-VAB.php то же на свой шаблон замените