//投稿と固定ページ一覧にスラッグを付ける
function add_posts_columns_slug($columns) {
$columns['slug'] = 'スラッグ';
echo '';
return $columns;
}
add_filter( 'manage_posts_columns', 'add_posts_columns_slug' );
add_filter( 'manage_pages_columns', 'add_posts_columns_slug' );
/* スラッグを表示 */
function custom_posts_columns_slug($column_name, $post_id) {
if( $column_name == 'slug' ) {
$post = get_post($post_id);
$slug = $post->post_name;
echo esc_attr($slug);
}
}
add_action( 'manage_posts_custom_column', 'custom_posts_columns_slug', 10, 2 );
add_action( 'manage_pages_custom_column', 'custom_posts_columns_slug', 10, 2 );
カスタム投稿タイプで本文入力を消すと、Addクイッカーが使えないので、display:none で非表示にする
その他WP管理画面のCSS設定:https://mypacecreator.net/blog/archives/1041
//カスタム投稿タイプの本文の編集機能だけ非表示
add_action('admin_print_styles', 'admin_book_css_custom');
function admin_book_css_custom() {
global $typenow;
if($typenow == 'touroku'):
echo '';
endif;
}
//その他WP管理画面のCSS設定
add_action('admin_print_styles', 'admin_css_custom'); //admin_css_customは好きな名前でOK
function admin_css_custom() {
echo '';
}
//特定の固定ページのエディタを消す
function disable_visual_editor_in_page(){
global $typenow;
$post_id = $_GET['post'];
if( $typenow == 'page' ){
if ( in_array( $post_id, array('9', '2'), true ) ){
$hide_postdiv_css = '<style type="text/css">#postdiv, #postdivrich { display: none; }</style>';
echo $hide_postdiv_css;
}
}
}
add_action('load-post.php', 'disable_visual_editor_in_page');
add_action('load-post-new.php', 'disable_visual_editor_in_page');
//最近の投稿画面から特定のカテゴリを削除
class WP_Widget_Recent_Posts_Exclude extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "The most recent posts on your site") );
parent::__construct('recent-posts', __('Recent Posts with Exclude'), $widget_ops);
$this->alt_option_name = 'widget_recent_entries';
add_action( 'save_post', array(&$this, 'flush_widget_cache') );
add_action( 'deleted_post', array(&$this, 'flush_widget_cache') );
add_action( 'switch_theme', array(&$this, 'flush_widget_cache') );
}
function widget($args, $instance) {
$cache = wp_cache_get('widget_recent_posts', 'widget');
if ( !is_array($cache) )
$cache = array();
if ( ! isset( $args['widget_id'] ) )
$args['widget_id'] = $this->id;
if ( isset( $cache[ $args['widget_id'] ] ) ) {
echo $cache[ $args['widget_id'] ];
return;
}
ob_start();
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base);
if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
$number = 10;
$exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];
$r = new WP_Query(array('posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'category__not_in' => explode(',', $exclude) ));
if ($r->have_posts()) :
?>
<?php //echo print_r(explode(',', $exclude)); ?>
<?php echo $before_widget; ?>
<?php if ( $title ) echo $before_title . $title . $after_title; ?>
<ul>
<?php while ($r->have_posts()) : $r->the_post(); ?>
<li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>
<?php endwhile; ?>
</ul>
<?php echo $after_widget; ?>
<?php
// Reset the global $the_post as this query will have stomped on it
wp_reset_postdata();
endif;
$cache[$args['widget_id']] = ob_get_flush();
wp_cache_set('widget_recent_posts', $cache, 'widget');
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['number'] = (int) $new_instance['number'];
$instance['exclude'] = strip_tags( $new_instance['exclude'] );
$this->flush_widget_cache();
$alloptions = wp_cache_get( 'alloptions', 'options' );
if ( isset($alloptions['widget_recent_entries']) )
delete_option('widget_recent_entries');
return $instance;
}
function flush_widget_cache() {
wp_cache_delete('widget_recent_posts', 'widget');
}
function form( $instance ) {
$title = isset($instance['title']) ? esc_attr($instance['title']) : '';
$number = isset($instance['number']) ? absint($instance['number']) : 5;
$exclude = esc_attr( $instance['exclude'] );
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of posts to show:'); ?></label>
<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p>
<p>
<label for="<?php echo $this->get_field_id('exclude'); ?>"><?php _e( 'Exclude Category(s):' ); ?></label> <input type="text" value="<?php echo $exclude; ?>" name="<?php echo $this->get_field_name('exclude'); ?>" id="<?php echo $this->get_field_id('exclude'); ?>" class="widefat" />
<br />
<small><?php _e( 'Category IDs, separated by commas.' ); ?></small>
</p>
<?php
}
}
function WP_Widget_Recent_Posts_Exclude_init() {
unregister_widget('WP_Widget_Recent_Posts');
register_widget('WP_Widget_Recent_Posts_Exclude');
}
add_action('widgets_init', 'WP_Widget_Recent_Posts_Exclude_init');
//カテゴリ一覧から削除
function customize_category_list( $args ) {
$args['exclude'] = 9;//除外したいカテゴリーIDを指定
return $args;
}
add_filter( 'widget_categories_args', 'customize_category_list' );
funciton.phpファイル
//パスワード設定
function basic_auth($auth_list,$realm="Restricted Area",$failed_text="認証に失敗しました"){
if (isset($_SERVER['PHP_AUTH_USER']) and isset($auth_list[$_SERVER['PHP_AUTH_USER']])){
if ($auth_list[$_SERVER['PHP_AUTH_USER']] == $_SERVER['PHP_AUTH_PW']){
return $_SERVER['PHP_AUTH_USER'];}
}
header('WWW-Authenticate: Basic realm="'.$realm.'"');
header('HTTP/1.0 401 Unauthorized');
header('Content-type: text/html; charset='.mb_internal_encoding());
die($failed_text);
}
◆header.phpに下記タグを入れる
<?php
if(!is_home()):
if(get_post_type() === '制限かけたいページ'):
$userArray = array("ユーザー名" => "パスワード");
basic_auth($userArray);
endif;
endif;
?>
//タグの自動追加を停止させる
function custom_editor_settings( $initArray ){
$initArray['body_id'] = 'primary';
$initArray['body_class'] = 'post';
$initArray['valid_children'] = '+body[style],+div[div|span],+span[span]';
$initArray['verify_html'] = false;
//$initArray['entity_encoding'] = 'raw';
//$initArray['entities'] = '91,93';
return $initArray;
}
add_filter( 'tiny_mce_before_init', 'custom_editor_settings' );
もう一つ
//タグの自動追加を停止させる
function remove_p_on_images($content){
return preg_replace('/(\s*)(
)(\s*)<\/p>/iU', '\2', $content);
}
add_filter('the_content', 'remove_p_on_images');
//投稿画面でタイトルや本文編集エリアを非表示
function post_output_css() {
$pt = get_post_type();
if ($pt == 'page') {
$hide_postdiv_css = '';
echo $hide_postdiv_css;
}
}
add_action('admin_head', 'post_output_css');
function.php の一番最後に記述する
add_editor_style(array('/style.css', '/style-main.css'));
//SSL設定
function http_to_https($the_content){
$domain = $_SERVER["HTTP_HOST"];
$src_http_single = "src=\'http://".$domain;
$src_http_double = "src=\"http://".$domain;
$src_https_single = "src=\'https://".$domain;
$src_https_double = "src=\"https://".$domain;
$href_http_single = "href=\'http://".$domain;
$href_http_double = "href=\"http://".$domain;
$href_https_single = "href=\'https://".$domain;
$href_https_double = "href=\"https://".$domain;
$http = array($src_http_single, $src_http_double, $href_http_single, $href_http_double);
$https = array($src_https_single, $src_https_double, $href_https_single, $href_https_double);
$the_content = str_replace($http, $https, $the_content);
return $the_content;
}
add_filter('the_content', 'http_to_https');