码迷,mamicode.com
首页 > 其他好文 > 详细

hook (二)

时间:2017-12-08 23:57:06      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:exit   selected   nbsp   disabled   ems   textarea   lte   pre   inf   

1.仪表盘小挂件

///Add dashboard widgets
if ( ! function_exists( ‘add_dashboard_widgets‘ ) ) :
function welcome_dashboard_widget_function() {
echo "<ul><li><a href=‘post-new.php‘>发布内容</a></li><li><a href=‘edit.php‘>修改内容</a></li></ul>";
}
function add_dashboard_widgets() {
wp_add_dashboard_widget(‘welcome_dashboard_widget‘, ‘常规任务‘, ‘welcome_dashboard_widget_function‘);
}
add_action(‘wp_dashboard_setup‘, ‘add_dashboard_widgets‘ );
endif;

 2.//后台文章列表添加分类筛选下拉

add_action(‘restrict_manage_posts‘,‘overwrite_listings_by_category‘);  
function overwrite_listings_by_category() {  
    global $typenow;  
    global $wp_query;  
  
    if ($typenow==‘type_product_order‘) {  
        $taxonomy = ‘cat_product‘;  
        $category_taxonomy = get_taxonomy($taxonomy);  
        //return print_r($wp_query->query);  
        return wp_dropdown_categories(array(  
            ‘show_option_all‘ =>  __("Show All {$category_taxonomy->label}"),  
           // ‘taxonomy‘        =>  $taxonomy,  
            ‘name‘            =>  ‘cat‘,  
            ‘orderby‘         =>  ‘name‘,  
            ‘selected‘        =>  @$wp_query->query[‘author‘],  
            ‘hierarchical‘    =>  true,  
            ‘depth‘           =>  5,  
            ‘show_count‘      =>  true, // Show # listings in parens  
            ‘hide_empty‘      =>  false, // Don‘t show businesses w/o listings  
        ));  
    }  
} 

3.//后台文章列表添加自定义字段筛选

add_filter( ‘parse_query‘, ‘ba_admin_posts_filter‘ );
add_action( ‘restrict_manage_posts‘, ‘ba_admin_posts_filter_restrict_manage_posts‘ );

function ba_admin_posts_filter( $query )
{
    global $pagenow;
    $post_type = ‘type_product_order‘;
    $q_vars   = &$query->query_vars;
    if ( $_GET[‘post_type‘] == $post_type ) {
            //echo $_GET[‘field_ke_ke‘].‘------‘; 
            //$q_vars[‘meta_key‘] = $_GET[‘field_ke_ke‘];
        if(!empty($_GET[‘field_value_ke‘])){
            $q_vars[‘meta_key‘] = ‘state‘;
            $q_vars[‘meta_value‘] = $_GET[‘field_value_ke‘];
        }
           
        //if (isset($_GET[‘field_value_ke‘]) && $_GET[‘field_value_ke‘] != ‘‘){ 
            //echo $_GET[‘field_value_ke‘].‘======‘; exit;
            //$q_vars[‘meta_value‘] = $_GET[‘field_value_ke‘];
            
        //}
    }
}

function ba_admin_posts_filter_restrict_manage_posts()
{  if($_GET[‘post_type‘]==‘type_product_order‘)
    {
    global $wpdb;
    $sql = "SELECT DISTINCT meta_value FROM ".$wpdb->postmeta." WHERE meta_key like ‘state‘";
    $fields = $wpdb->get_results($sql, ARRAY_N);
    //p($fields);
?>
<select name="field_value_ke">
<option value=""><?php _e(‘状态‘); ?></option>
<?php

    $current = isset($_GET[‘field_value_ke‘])? $_GET[‘field_value_ke‘]:‘‘;
    foreach ($fields as $field) {
        if (substr($field[0],0,1) != "_"){
        printf
            (
                ‘<option value="%s"%s>%s</option>‘,
                $field[0],
                $field[0] == $current? ‘ selected="selected"‘:‘‘,
                get_state_name($field[0])
            );
        }
    }
    }

}

4.//添加分类表单

//add extra fields to category edit form hook
add_action ( ‘edit_category_form_fields‘, ‘extra_category_fields‘);
//add extra fields to category edit form callback function
function extra_category_fields( $tag ) {    //check for existing featured ID
    $t_id = $tag->term_id;
    $cat_meta = get_option( "category_$t_id");
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="cat_Image_url"><?php _e(‘Category Image Url‘); ?></label></th>
<td>
<input type="text" name="Cat_meta[img]" id="Cat_meta[img]" size="3" style="width:60%;" value="<?php echo $cat_meta[‘img‘] ? $cat_meta[‘img‘] : ‘‘; ?>"><br />
            <span class="description"><?php _e(‘Image for category: use full url with ‘); ?></span>
        </td>
</tr>
<tr class="form-field">
<th scope="row" valign="top"><label for="extra1"><?php _e(‘extra field‘); ?></label></th>
<td>
<input type="text" name="Cat_meta[extra1]" id="Cat_meta[extra1]" size="25" style="width:60%;" value="<?php echo $cat_meta[‘extra1‘] ? $cat_meta[‘extra1‘] : ‘‘; ?>"><br />
            <span class="description"><?php _e(‘extra field‘); ?></span>
        </td>
</tr>
<tr class="form-field">
<th scope="row" valign="top"><label for="extra2"><?php _e(‘extra field‘); ?></label></th>
<td>
<input type="text" name="Cat_meta[extra2]" id="Cat_meta[extra2]" size="25" style="width:60%;" value="<?php echo $cat_meta[‘extra2‘] ? $cat_meta[‘extra2‘] : ‘‘; ?>"><br />
            <span class="description"><?php _e(‘extra field‘); ?></span>
        </td>
</tr>
<tr class="form-field">
<th scope="row" valign="top"><label for="extra3"><?php _e(‘extra field‘); ?></label></th>
<td>
            <textarea name="Cat_meta[extra3]" id="Cat_meta[extra3]" style="width:60%;"><?php echo $cat_meta[‘extra3‘] ? $cat_meta[‘extra3‘] : ‘‘; ?></textarea><br />
            <span class="description"><?php _e(‘extra field‘); ?></span>
        </td>
</tr>
<?php
// save extra category extra fields hook
add_action ( ‘edited_category‘, ‘save_extra_category_fileds‘);
   // save extra category extra fields callback function
function save_extra_category_fileds( $term_id ) {
    if ( isset( $_POST[‘Cat_meta‘] ) ) {
        $t_id = $term_id;
        $cat_meta = get_option( "category_$t_id");
        $cat_keys = array_keys($_POST[‘Cat_meta‘]);
            foreach ($cat_keys as $key){
            if (isset($_POST[‘Cat_meta‘][$key])){
                $cat_meta[$key] = $_POST[‘Cat_meta‘][$key];
            }
        }
        //save the option array
        update_option( "category_$t_id", $cat_meta );
    }
}

5.更新,发布按钮操作

if(is_admin()){
  add_action(‘load-post.php‘, ‘call_admin_save_post‘);
}
function call_admin_save_post(){
 add_action( ‘save_post‘, ‘myplugin_save_postdata‘, 10, 3 );
}

  function myplugin_save_postdata($post_id, $post, $update ) {
}

6.//添加子页面 

add_action(‘admin_menu‘, ‘my_admin_menu‘); 
function my_admin_menu() { 
    add_submenu_page(‘edit.php?post_type=type_hotel‘, ‘筛选设置‘, ‘筛选设置‘, ‘manage_options‘, ‘hotel-filter-page-action‘,‘wpdocs_unsub_page_callback‘); 
}

7.//非管理员移除相关页面

function wpse28782_remove_menu_items() {
    if( !current_user_can( ‘administrator‘ ) ):
        remove_menu_page( ‘edit.php?post_type=type_law‘ );
        remove_menu_page( ‘edit.php?post_type=page‘ );
        remove_menu_page( ‘tools.php‘);
    endif;
}
add_action( ‘admin_menu‘, ‘wpse28782_remove_menu_items‘ );

8.//添加列表页面字段

add_action( ‘load-edit.php‘, function() {
  if(!current_user_can(‘level_10‘)){
     add_filter( ‘views_edit-type_infor‘, ‘talk_tabs‘ ); // talk is my custom post type
  }
});

# echo the tabs
function talk_tabs() {
      global $current_user,$wp_query;
             $count = $wp_query->post_count;
             if(empty($count)){ $count = 0 ; }
  ?>
<ul class="subsubsub">
  <li class="all"><a href="javascript:;" class="current">总数<span class="count">(<?php echo $count;?>)</span></a></li>
</ul>
<?php }

9.

//when change password disabled send email
add_filter( ‘send_password_change_email‘, ‘__return_false‘ );

10.登录限时

hook (二)

标签:exit   selected   nbsp   disabled   ems   textarea   lte   pre   inf   

原文地址:http://www.cnblogs.com/lc-hj/p/8007388.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!