Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //-------------------------------------------------------------------
- remove admin menus
- //-------------------------------------------------------------------
- //-----------------------------
- function remove_menus(){
- //-----------------------------
- global $menu;
- $restricted = array(__('Dashboard'), __('Posts'),
- __('Media'), __('Links'), __('Pages'),
- __('Appearance'),
- __('Tools'), __('Users'),
- __('Settings'), __('Comments'), __('Plugins'));
- end ($menu);
- while (prev($menu)){
- $value = explode(' ', $menu[key($menu)][0]);
- if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
- }
- }
- //-----------------------------
- add_action('admin_menu', 'remove_menus');
- ?>
- <?php
- //-------------------------------------------------------------------
- // hide admin menu
- //-------------------------------------------------------------------
- add_action('admin_head', 'kill_adminmenu');
- //-----------------------------
- function kill_adminmenu(){
- //-----------------------------
- $GLOBALS['menu'] = array();
- echo "<style type='text/css'>#adminmenuwrap,
- #adminmenuback{display:none!important;}
- #wpcontent{margin-left:10px!important;}
- </style>";
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // customize login logo
- //-------------------------------------------------------------------
- //-----------------------------
- function my_custom_login_logo(){
- //-----------------------------
- echo '<style type="text/css">
- h1 a { background-image:url('.get_bloginfo('template_directory').
- '/images/custom-login-logo.gif) !important; }
- </style>';
- }
- //-----------------------------
- add_action('login_head', 'my_custom_login_logo');
- ?>
- <?php
- //-------------------------------------------------------------------
- // customize admin logo
- //-------------------------------------------------------------------
- //-----------------------------
- function my_custom_logo(){
- //-----------------------------
- echo '<style type="text/css">
- #header-logo { background-image: url('.get_bloginfo('template_directory').
- '/images/custom-logo.gif) !important; }
- </style>';
- }
- //-----------------------------
- add_action('admin_head', 'my_custom_logo');
- ?>
- <?php
- //-------------------------------------------------------------------
- // disable updates
- //-------------------------------------------------------------------
- if( !current_user_can( 'edit_users' ) ){
- add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 );
- add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) );
- // для 3.0+
- add_filter( 'pre_site_transient_update_core', create_function( '$a', "return null;" ) );
- ?>
- <?php
- //-------------------------------------------------------------------
- // Удаление виджетов из Консоли WordPress
- //-------------------------------------------------------------------
- //-----------------------------
- function clear_dash(){
- //-----------------------------
- $side = &$GLOBALS['wp_meta_boxes']['dashboard']['side']['core'];
- $normal = &$GLOBALS['wp_meta_boxes']['dashboard']['normal']['core'];
- unset($side['dashboard_quick_press']); //Быстрая публикация
- // unset($side['dashboard_recent_drafts']); //Полседние черновики
- unset($side['dashboard_primary']); //Блог WordPress
- unset($side['dashboard_secondary']); //Другие Нновости WordPress
- unset($normal['dashboard_incoming_links']); //Входящие ссылки
- // unset($normal['dashboard_right_now']); //Прямо сейчас
- unset($normal['dashboard_recent_comments']); //Последние комментарии
- unset($normal['dashboard_plugins']); //Последние Плагины
- }
- add_action('wp_dashboard_setup', 'clear_dash' );
- ?>
- <?php
- //-------------------------------------------------------------------
- // add dashboard widget
- //-------------------------------------------------------------------
- //-----------------------------
- function example_dashboard_widget_function(){
- //-----------------------------
- // Показать то, что вы хотите показать
- echo "Привет, мир. Я — великий виджет админки, созданный великими программистами";
- }
- // Создаем функцию, используя хук действия
- //-----------------------------
- function example_add_dashboard_widgets() {
- //-----------------------------
- wp_add_dashboard_widget('example_dashboard_widget', 'Пример виджета админки',
- 'example_dashboard_widget_function');
- }
- //-----------------------------
- // Хук в 'wp_dashboard_setup', чтобы зарегистрировать нашу функцию среди других
- add_action('wp_dashboard_setup', 'example_add_dashboard_widgets' );
- ?>
- <?php
- //-------------------------------------------------------------------
- // customize admin header colors
- //-------------------------------------------------------------------
- add_action('admin_head', 'custom_colors');
- //-----------------------------
- function custom_colors() {
- //-----------------------------
- echo '<style type="text/css">
- #wphead{background:#069}
- </style>';
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // add context help
- //-------------------------------------------------------------------
- //-----------------------------
- function my_admin_help($text, $screen) {
- //-----------------------------
- // Проверим, только ли для страницы настроек это применимо
- if (strcmp($screen, MY_PAGEHOOK) == 0 ) {
- $text = 'Вот некоторая полезная информация, которая поможет вам разобраться с плагином...';
- return $text;
- }
- // Пусть по умолчанию штуки с помощью будут и на других страницах панели управления
- return $text;
- }
- add_action( 'contextual_help', 'my_admin_help' );
- ?>
- <?php
- //-------------------------------------------------------------------
- // output error log at dashboard panel
- //-------------------------------------------------------------------
- //-----------------------------
- function slt_PHPErrorsWidget() {
- //-----------------------------
- $logfile = '/home/path/logs/php-errors.log'; // Полный пусть до лог файла
- $displayErrorsLimit = 100; // Максимальное количество ошибок, показываемых в виджете
- $errorLengthLimit = 300; // Максимальное число символов для описания каждой ошибки
- $fileCleared = false;
- $userCanClearLog = current_user_can( 'manage_options' );
- // Очистить файл?
- if( $userCanClearLog && isset( $_GET["slt-php-errors"] ) && $_GET["slt-php-errors"]=="clear" ){
- $handle = fopen( $logfile, "w" );
- fclose( $handle );
- $fileCleared = true;
- }
- // Читаем файл
- if( file_exists( $logfile ) ){
- $errors = file( $logfile );
- $errors = array_reverse( $errors );
- if ( $fileCleared ) echo '<p><em>Файл очищен.</em></p>';
- if ( $errors ) {
- echo '<p>'.count( $errors ).' ошибка';
- if ( $errors != 1 ) echo 's';
- echo '.';
- if ( $userCanClearLog )
- echo ' [ <b><a href="'.get_bloginfo("url").'/wp-admin/?slt-php-errors=clear"
- onclick="return confirm(\'Вы уверенны?\');">ОЧИСТИТЬ ЛОГ ФАЙЛ</a></b> ]';
- echo '</p>';
- echo '<div id="slt-php-errors"
- style="height:250px;overflow:scroll;padding:2px;
- background-color:#faf9f7;border:1px solid #ccc;">';
- echo '<ol style="padding:0;margin:0;">';
- $i = 0;
- foreach( $errors as $error ){
- echo '<li style="padding:2px 4px 6px;border-bottom:1px solid #ececec;">';
- $errorOutput = preg_replace( '/\[([^\]]+)\]/', '<b>[$1]</b>', $error, 1 );
- if( strlen( $errorOutput ) > $errorLengthLimit ){
- echo substr( $errorOutput, 0, $errorLengthLimit ).' [...]';
- }
- else
- echo $errorOutput;
- echo '</li>';
- $i++;
- if( $i > $displayErrorsLimit ){
- echo '<li style="padding:2px;border-bottom:2px solid #ccc;">
- <em>Набралось больше чем '. $displayErrorsLimit.' ошибок в файле...</em></li>';
- break;
- }
- }
- echo '</ol></div>';
- }
- else
- echo '<p>Ошибок пока нет.</p>';
- }
- else
- echo '<p><em>Произошла ошибка чтения лог файла.</em></p>';
- }
- // Добавляем виджет
- //-----------------------------
- function slt_dashboardWidgets(){
- //-----------------------------
- wp_add_dashboard_widget( 'slt-php-errors', 'PHP errors', 'slt_PHPErrorsWidget' );
- }
- //-----------------------------
- add_action( 'wp_dashboard_setup', 'slt_dashboardWidgets' );
- ?>
- <?php
- //-------------------------------------------------------------------
- // remove meta box
- //-------------------------------------------------------------------
- add_action('admin_init','customize_meta_boxes');
- //-----------------------------
- function customize_meta_boxes(){
- //-----------------------------
- if( current_user_can('moderate_comments') )
- return;
- remove_meta_box('postcustom', 'post', 'normal');
- }
- ?>
- //-------------------------------------------------------------------
- // rename login page
- //-------------------------------------------------------------------
- RewriteRule ^login$ http://site.ru/wp-login.php [NC,L]
- <?php
- //-------------------------------------------------------------------
- // rename admin and login pages
- //-------------------------------------------------------------------
- /* редирект с login на /wp-login.php и с admin на /wp-admin */
- add_action('template_redirect', 'kama_login_redirect');
- //-----------------------------
- function kama_login_redirect(){
- //-----------------------------
- if( strpos($_SERVER['REQUEST_URI'], 'login')!==false )
- $loc = '/wp-login.php';
- elseif( strpos($_SERVER['REQUEST_URI'], 'admin')!==false )
- $loc = '/wp-admin/';
- if( $loc ){
- header( 'Location: '.get_option('site_url').$loc, true, 303 );
- exit;
- }
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // output errors for admins
- //-------------------------------------------------------------------
- add_action('init', 'enable_errors');
- //-----------------------------
- function enable_errors(){
- //-----------------------------
- if( $GLOBALS['user_level'] < 5 )
- return;
- error_reporting(E_ALL ^ E_NOTICE);
- ini_set("display_errors", 1);
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // add new column in list view of custom posts
- //-------------------------------------------------------------------
- // создаем новую колонку
- //-----------------------------
- add_filter('manage_edit-post_columns',
- 'add_views_column', 4);
- //------------------------------------------
- function add_views_column( $columns ){
- //------------------------------------------
- $columns['views'] = 'Визиты';
- return $columns;
- }
- // заполняем колонку данными
- //-----------------------------
- add_filter('manage_post_posts_custom_column',
- 'fill_views_column', 5, 2);
- //---------------------------------------------------
- function fill_views_column($column_name, $post_id) {
- //---------------------------------------------------
- if( $column_name != 'views' )
- return;
- echo get_post_meta($post_id, 'views', 1);
- }
- // добавляем возможность сортировать колонку
- //-----------------------------
- add_filter('manage_edit-post_sortable_columns',
- 'add_views_sortable_column');
- //------------------------------------------------------
- function add_views_sortable_column($sortable_columns){
- //------------------------------------------------------
- $sortable_columns['views'] = 'views_views';
- return $sortable_columns;
- }
- //-----------------------------
- add_filter('pre_get_posts',
- 'add_column_views_request');
- //------------------------------------------------
- function add_column_views_request( $object ){
- //------------------------------------------------
- if( $object->get('orderby') != 'views_views' )
- return;
- $object->set('meta_key', 'views');
- $object->set('orderby', 'meta_value_num');
- }
- //-----------------------------
- add_filter('request',
- 'add_column_views_request');
- //----------------------------------------------
- function add_column_views_request( $vars ) {
- //----------------------------------------------
- if ( 'views_views' == $vars['orderby'] ){
- $vars['meta_key'] = 'views';
- $vars['orderby'] = 'meta_value_num';
- }
- return $vars;
- }
- //-----------------------------
- add_filter( 'posts_clauses',
- 'add_column_views_request', 10, 2 );
- //----------------------------------------------------------
- function add_column_views_request( $clauses, $wp_query ){
- //----------------------------------------------------------
- if( 'views_views' != $wp_query->query['orderby'] )
- return $clauses;
- global $wpdb;
- $clauses['join'] .= " LEFT JOIN {$wpdb->postmeta} ON {$wpdb->posts}.ID={$wpdb->postmeta}.post_id";
- //$clauses['where'] .= " AND {$wpdb->postmeta}.meta_key='views'";
- $clauses['orderby'] = " {$wpdb->postmeta}.meta_value+0 ";
- $clauses['orderby'] .= ( 'ASC' == strtoupper( $wp_query->get('order') ) ) ? 'ASC' : 'DESC';
- // еще изменяемые элементы
- //$clauses['groupby']
- //$clauses['distinct']
- //$clauses['fields'] // wp_posts.*
- //$clauses['limits'] // LIMIT 0, 20
- return $clauses;
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // подправим ширину колонки через css
- //-------------------------------------------------------------------
- add_action('admin_head', 'add_views_column_css');
- //-----------------------------
- function add_views_column_css(){
- //-----------------------------
- echo '<style type="text/css">.column-views{width:10%;}</style>';
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // sort posts by related taxonomy
- //-------------------------------------------------------------------
- //--------------------------------------------------
- function color_orderby( $orderby, $wp_query ) {
- //--------------------------------------------------
- global $wpdb;
- if ( isset( $wp_query->query['orderby'] ) && 'color' == $wp_query->query['orderby'] ) {
- $orderby = "(
- SELECT GROUP_CONCAT(name ORDER BY name ASC)
- FROM $wpdb->term_relationships
- INNER JOIN $wpdb->term_taxonomy USING (term_taxonomy_id)
- INNER JOIN $wpdb->terms USING (term_id)
- WHERE $wpdb->posts.ID = object_id
- AND taxonomy = 'color'
- GROUP BY object_id
- ) ";
- $orderby .= ( 'ASC' == strtoupper( $wp_query->get('order') ) ) ? 'ASC' : 'DESC';
- }
- return $orderby;
- }
- //--------------------------------------------------
- add_filter( 'posts_orderby', 'color_orderby', 10, 2 );
- ?>
- <?php
- //-------------------------------------------------------------------
- // user can see only his own posts or media elements
- //-------------------------------------------------------------------
- //---------------------------------------
- function ik_eyes_only( $wp_query ) {
- //---------------------------------------
- //are we looking at the Media Library or the Posts list?
- if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) !== false
- || strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit.php' ) !== false ) {
- //user level 5 converts to Editor
- if ( !current_user_can( 'level_5' ) ) {
- //restrict the query to current user
- global $current_user;
- $wp_query->set( 'author', $current_user->id );
- }
- }
- }
- //---------------------------------------
- add_filter('parse_query', 'ik_eyes_only' );
- ?>
- <?php
- //-------------------------------------------------------------------
- // user can see only his own attachments
- //-------------------------------------------------------------------
- $querystr = " SELECT wposts.post_date,wposts.post_content,wposts.post_title, guid
- FROM $wpdb->posts wposts
- WHERE wposts.post_author = $author
- AND wposts.post_type = 'attachment'
- ORDER BY wposts.post_date DESC";
- $pageposts = $wpdb->get_results($querystr, OBJECT);
- //-----------------------------------
- add_action('pre_get_posts','users_own_attachments');
- //---------------------------------------------------
- function users_own_attachments( $wp_query_obj ) {
- //---------------------------------------------------
- global $current_user, $pagenow;
- if( !is_a( $current_user, 'WP_User') )
- return;
- if( 'upload.php' != $pagenow )
- return;
- if( !current_user_can('delete_pages') )
- $wp_query_obj->set('author', $current_user->id );
- return;
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // Show only posts and media related to logged in author
- //-------------------------------------------------------------------
- add_action('pre_get_posts', 'query_set_only_author' );
- //-------------------------------------------------
- function query_set_only_author( $wp_query ) {
- //-------------------------------------------------
- global $current_user;
- if( is_admin() && !current_user_can('edit_others_posts') ) {
- $wp_query->set( 'author', $current_user->ID );
- add_filter('views_edit-post', 'fix_post_counts');
- add_filter('views_upload', 'fix_media_counts');
- }
- }
- // Fix post counts
- //-------------------------------------------------
- function fix_post_counts($views) {
- //-------------------------------------------------
- global $current_user, $wp_query;
- unset($views['mine']);
- $types = array(
- array( 'status' => NULL ),
- array( 'status' => 'publish' ),
- array( 'status' => 'draft' ),
- array( 'status' => 'pending' ),
- array( 'status' => 'trash' )
- );
- foreach( $types as $type ) {
- $query = array(
- 'author' => $current_user->ID,
- 'post_type' => 'post',
- 'post_status' => $type['status']
- );
- $result = new WP_Query($query);
- if( $type['status'] == NULL ):
- $class = ($wp_query->query_vars['post_status'] == NULL) ? ' class="current"' : '';
- $views['all'] =
- sprintf(
- '<a href="%1$s"%2$s>%4$s <span class="count">(%3$d)</span></a>',
- admin_url('edit.php?post_type=post'),
- $class,
- $result->found_posts,
- __('All')
- );
- elseif ( $type['status'] == 'publish' ):
- $class = ($wp_query->query_vars['post_status'] == 'publish') ? ' class="current"' : '';
- $views['publish'] =
- sprintf(
- '<a href="%1$s"%2$s>%4$s <span class="count">(%3$d)</span></a>',
- admin_url('edit.php?post_type=post'),
- $class,
- $result->found_posts,
- __('Publish')
- );
- elseif( $type['status'] == 'draft' ):
- $class = ($wp_query->query_vars['post_status'] == 'draft') ? ' class="current"' : '';
- $views['draft'] =
- sprintf(
- '<a href="%1$s"%2$s>%4$s <span class="count">(%3$d)</span></a>',
- admin_url('edit.php?post_type=post'),
- $class,
- $result->found_posts,
- __('Draft')
- );
- elseif ( $type['status'] == 'pending' ):
- $class = ($wp_query->query_vars['post_status'] == 'pending') ? ' class="current"' : '';
- $views['pending'] =
- sprintf(
- '<a href="%1$s"%2$s>%4$s <span class="count">(%3$d)</span></a>',
- admin_url('edit.php?post_type=post'),
- $class,
- $result->found_posts,
- __('Pending')
- );
- elseif( $type['status'] == 'trash' ):
- $class = ($wp_query->query_vars['post_status'] == 'trash') ? ' class="current"' : '';
- $views['trash'] =
- sprintf(
- '<a href="%1$s"%2$s>%4$s <span class="count">(%3$d)</span></a>',
- admin_url('edit.php?post_type=post'),
- $class,
- $result->found_posts,
- __('Trash')
- );
- endif;
- }
- return $views;
- }
- // Fix media counts
- //-------------------------------------------------
- function fix_media_counts($views) {
- //-------------------------------------------------
- global $wpdb, $current_user, $post_mime_types, $avail_post_mime_types;
- $views = array();
- $count = $wpdb->get_results( "
- SELECT post_mime_type, COUNT( * ) AS num_posts
- FROM $wpdb->posts
- WHERE post_type = 'attachment'
- AND post_author = $current_user->ID
- AND post_status != 'trash'
- GROUP BY post_mime_type
- ", ARRAY_A );
- foreach( $count as $row )
- $_num_posts[$row['post_mime_type']] = $row['num_posts'];
- $_total_posts = array_sum($_num_posts);
- $detached = isset( $_REQUEST['detached'] ) || isset( $_REQUEST['find_detached'] );
- if ( !isset( $total_orphans ) )
- $total_orphans = $wpdb->get_var("
- SELECT COUNT( * )
- FROM $wpdb->posts
- WHERE post_type = 'attachment'
- AND post_author = $current_user->ID
- AND post_status != 'trash'
- AND post_parent < 1
- ");
- $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
- foreach ( $matches as $type => $reals )
- foreach ( $reals as $real )
- $num_posts[$type] =
- ( isset( $num_posts[$type] ) ) ?
- $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real];
- $class = ( empty($_GET['post_mime_type']) &&
- !$detached && !isset($_GET['status']) ) ?
- ' class="current"' : '';
- $views['all'] =
- "<a href='upload.php'$class>" .
- sprintf( __('All <span class="count">(%s)</span>', 'uploaded files' ),
- number_format_i18n( $_total_posts )) . '</a>';
- foreach ( $post_mime_types as $mime_type => $label ) {
- $class = '';
- if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
- continue;
- if ( !empty($_GET['post_mime_type']) &&
- wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
- $class = ' class="current"';
- if ( !empty( $num_posts[$mime_type] ) )
- $views[$mime_type] = "<a href='upload.php?post_mime_type=$mime_type'$class>" .
- sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ),
- $num_posts[$mime_type] ) . '</a>';
- }
- $views['detached'] =
- '<a href="upload.php?detached=1"' . ( $detached ? ' class="current"' : '' ) .
- '>' .
- sprintf( __( 'Unattached <span class="count">(%s)</span>', 'detached files' ),
- $total_orphans ) .
- '</a>';
- return $views;
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // user can see only his own media-files
- //-------------------------------------------------------------------
- //-------------------------------------
- function my_files_only( $wp_query ) {
- //-------------------------------------
- if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) !== false ) {
- if ( !current_user_can( 'level_5' ) ) {
- global $current_user;
- $wp_query->set( 'author', $current_user->id );
- }
- } else
- if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/media-upload.php' ) !== false ) {
- if ( !current_user_can( 'level_5' ) ) {
- global $current_user;
- $wp_query->set( 'author', $current_user->id );
- }
- }
- }
- //-------------------------------------
- add_filter('parse_query', 'my_files_only' );
- ?>
- <?php
- //-------------------------------------------------------------------
- // user can see only his own media
- //-------------------------------------------------------------------
- /*
- Plugin Name: Manage Your Media Only
- Version: 0.1
- */
- //Manage Your Media Only
- //---------------------------------------------------
- function mymo_parse_query_useronly( $wp_query ) {
- //---------------------------------------------------
- if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) !== false ) {
- if ( !current_user_can( 'level_5' ) ) {
- global $current_user;
- $wp_query->set( 'author', $current_user->id );
- }
- }
- }
- //---------------------------------------------------
- add_filter('parse_query', 'mymo_parse_query_useronly' );
- ?>
- <?php
- //-------------------------------------------------------------------
- // redirect user to his page
- //-------------------------------------------------------------------
- global $current_user;
- get_currentuserinfo();
- $userredirect = get_bloginfo('home') . "/author/" .$current_user->user_nicename;
- ?>
- <?php
- //-------------------------------------------------------------------
- // remove post counts
- //-------------------------------------------------------------------
- function jquery_remove_counts()
- {
- ?>
- <script type="text/javascript">
- jQuery(function(){
- jQuery("ul.subsubsub").find("span.count").remove();
- });
- </script>
- <?php
- }
- add_action('admin_head', 'jquery_remove_counts');
- ?>
- <?php
- //-------------------------------------------------------------------
- // replace term_id by term slug in query
- //-------------------------------------------------------------------
- add_filter('parse_query',
- 'convert_large_feature_id_to_taxonomy_term_in_query');
- //----------------------------------------
- function
- convert_large_feature_id_to_taxonomy_term_in_query($query) {
- //----------------------------------------
- global $pagenow;
- $qv = &$query->query_vars;
- if ($pagenow=='edit.php' &&
- isset($qv['taxonomy']) && $qv['taxonomy']=='large_feature' &&
- isset($qv['term']) && is_numeric($qv['term'])) {
- $term = get_term_by('id',$qv['term'],'large_feature');
- $qv['term'] = $term->slug;
- }
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // show dropdown box of child terms of current term
- //-------------------------------------------------------------------
- // first get the current term
- $current_term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
- // then set the args for wp_dropdown_categories
- $args = array(
- 'child_of' => $current_term->term_id,
- 'taxonomy' => $current_term->taxonomy,
- 'hide_empty' => 0,
- 'hierarchical' => true,
- 'depth' => 2,
- 'title_li' => '',
- 'show_option_all' => All,
- 'hide_if_empty' => true
- );
- wp_dropdown_categories( $args );
- ?>
- <?php
- //-------------------------------------------------------------------
- // show today's posts in admin post view
- //-------------------------------------------------------------------
- add_filter( 'views_edit-post', 'wpse_add_my_view');
- //-------------------------------------
- function wpse_add_my_view($views){
- //-------------------------------------
- global $post_type_object;
- $post_type = $post_type_object->name;
- $y =mysql2date('Y', current_time('mysql') );
- $m =mysql2date('m', current_time('mysql') );
- $d =mysql2date('d', current_time('mysql') );
- $views['today'] = "<a href='edit.php?year=$y&monthnum=$m&day=$d&post_type=$post_type'>".
- __('Today','myplugin')."</a>";
- return $views;
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // query posts with specific meta values
- //-------------------------------------------------------------------
- query_posts( array(
- 'post_type' => 'product',
- 'meta_key' => 'price',
- 'meta_value' => 100,
- 'meta_compare' => '>'
- ) );
- query_posts( array(
- 'post_type' => 'product',
- 'meta_query' => array(
- array(
- 'key' => 'price',
- 'value' => array( 100, 200 ),
- 'compare' => 'BETWEEN',
- 'type' => 'numeric',
- ),
- array(
- 'key' => 'description',
- 'value' => 'round',
- 'compare' => 'NOT LIKE'
- )
- )
- ) );
- ?>
- <?php
- //-------------------------------------------------------------------
- // check attachment mime type before sending to editor
- //-------------------------------------------------------------------
- function WPSE_78285_Mime($html, $id) {
- //fetching attachment by post $id
- $attachment = get_post($id);
- $mime_type = $attachment->post_mime_type;
- //get an valid array of images types
- $image_exts = array( 'image/jpg', 'image/jpeg', 'image/jpe', 'image/gif', 'image/png' );
- //checking the above mime-type
- if (in_array($mime_type, $image_exts)) {
- // the image link would be great
- $src = wp_get_attachment_url( $id );
- // enter you custom output here, you will want to probably change this
- $html = '<a href="' . $src .
- '" class="your-class" data-src="/img/image1.jpg" rel="your-rel">
- <img src="'. $src .'" /></a>';
- return $html; // return new $html
- }
- return $html;
- }
- //-----------------------------
- add_filter('media_send_to_editor', 'WPSE_78285_Mime', 20, 2);
- ?>
- <?php
- //-------------------------------------------------------------------
- // add meta field (location) to attachment
- //-------------------------------------------------------------------
- //-------------------------------------------
- function my_add_attachment_location_field
- ( $form_fields, $post ) {
- //-------------------------------------------
- $field_value = get_post_meta( $post->ID, 'location', true );
- $form_fields['location'] = array(
- 'value' => $field_value ? $field_value : '',
- 'label' => __( 'Location' ),
- 'helps' => __( 'Set a location for this attachment' )
- );
- return $form_fields;
- }
- //-------------------------------------------
- add_filter( 'attachment_fields_to_edit',
- 'my_add_attachment_location_field', 10, 2 );
- //-------------------------------------------
- function my_save_attachment_location
- ( $attachment_id ) {
- //-------------------------------------------
- if ( isset( $_REQUEST['attachments'][$attachment_id]['location'] ) ) {
- $location = $_REQUEST['attachments'][$attachment_id]['location'];
- update_post_meta( $attachment_id, 'location', $location );
- }
- }
- //-------------------------------------------
- add_action( 'edit_attachment',
- 'my_save_attachment_location' );
- ?>
- <?php
- //-------------------------------------------------------------------
- // exclude certain categories from view on main page
- //-------------------------------------------------------------------
- //-------------------------------------
- function exclude_category( $query ) {
- //-------------------------------------
- if ( $query->is_home() && $query->is_main_query() ) {
- $query->set( 'cat', '-1,-1347' );
- }
- }
- //-------------------------------------
- add_action( 'pre_get_posts',
- 'exclude_category' );
- ?>
- <?php
- //-------------------------------------------------------------------
- // show certain types of posts on search page
- //-------------------------------------------------------------------
- //-------------------------------------
- function search_filter($query) {
- //-------------------------------------
- if ( !is_admin() && $query->is_main_query() ) {
- if ($query->is_search) {
- $query->set('post_type', 'post');
- $query->set('post_type', array( 'post', 'movie' ) );
- }
- }
- }
- //-------------------------------------
- add_action('pre_get_posts',
- 'search_filter');
- ?>
- <?php
- //-------------------------------------------------------------------
- // show 1 post on home page and 50 on movie archive page
- //-------------------------------------------------------------------
- //-----------------------------------------
- function hwl_home_pagesize( $query ) {
- //-----------------------------------------
- if ( is_admin() || ! $query->is_main_query() )
- return;
- if ( is_home() ) {
- // Display only 1 post for the original blog archive
- $query->set( 'posts_per_page', 1 );
- return;
- }
- if ( is_post_type_archive( 'movie' ) ) {
- // Display 50 posts for a custom post type called 'movie'
- $query->set( 'posts_per_page', 50 );
- return;
- }
- }
- //--------------------------------
- add_action( 'pre_get_posts',
- 'hwl_home_pagesize', 1 );
- ?>
- <?php
- //-------------------------------------------------------------------
- // add categories and tags to pages
- //-------------------------------------------------------------------
- //------------------------------------
- function add_page_cats_and_tags() {
- //------------------------------------
- register_taxonomy_for_object_type('post_tag', 'page');
- register_taxonomy_for_object_type('category', 'page');
- }
- //------------------------------------
- add_action( 'admin_init',
- 'add_page_cats_and_tags' );
- //------------------------------------
- // show pages as well
- // on category and tag pages
- //------------------------------------
- function my_expanded_request($q) {
- //------------------------------------
- if (isset($q['tag']) || isset($q['category_name'])) {
- $q['post_type'] = array('post', 'page');
- }
- return $q;
- }
- //------------------------------------
- add_filter('request',
- 'my_expanded_request');
- ?>
- <?php
- //-------------------------------------------------------------------
- // set gallery post type by default
- //-------------------------------------------------------------------
- add_filter('request',
- 'blog_art_request');
- //------------------------------------
- function blog_art_request($q) {
- //------------------------------------
- if (is_admin()) return;
- if (!empty($q) && !isset($q['p'])
- && !isset($q['page_id'])
- && !isset($q['name'])
- && !isset($q['pagename'])
- && !isset($q['post_type']))
- $q['post_type'] = 'gallery';
- return $q;
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // show gallery archive instead of post archive
- //-------------------------------------------------------------------
- add_filter('getarchives_where',
- 'blog_art_archive', 10, 2);
- //---------------------------------------
- function blog_art_archive($where, $r) {
- //---------------------------------------
- return str_replace("post_type = 'post'","post_type = 'gallery'",$where);
- }
- //------------------------------------
- add_filter('request',
- 'my_blog_request');
- //--------------------------------------------------
- // sort posts by title on admin page
- //--------------------------------------------------
- function my_blog_request($q) {
- //------------------------------------
- if (!is_admin()) return;
- if ($q['post_type'] == 'post') {
- $q['order'] = 'ASC';
- $q['orderby'] = 'title';
- }
- return $q;
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // show posts with tag = email
- //-------------------------------------------------------------------
- $querystr = "
- SELECT $wpdb->posts.*
- FROM $wpdb->posts, $wpdb->postmeta
- WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
- AND $wpdb->postmeta.meta_key = 'tag'
- AND $wpdb->postmeta.meta_value = 'email'
- AND $wpdb->posts.post_status = 'publish'
- AND $wpdb->posts.post_type = 'post'
- AND $wpdb->posts.post_date < NOW()
- ORDER BY $wpdb->posts.post_date DESC
- ";
- $pageposts = $wpdb->get_results($querystr, OBJECT);
- //--------------------------------------------
- ?>
- <?php if ($pageposts): ?>
- <?php global $post; ?>
- <?php foreach ($pageposts as $post): ?>
- <?php setup_postdata($post); ?>
- <div class="post" id="post-<?php the_ID(); ?>">
- <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
- <?php the_title(); ?></a></h2>
- <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
- <div class="entry">
- <?php the_content('Read the rest of this entry »'); ?>
- </div>
- <p class="postmetadata">
- Posted in <?php the_category(', ')
- ?> | <?php
- edit_post_link('Edit', '', ' | '); ?>
- <?php
- comments_popup_link('No Comments »', '1 Comment »', '% Comments »');
- ?></p>
- </div>
- <?php endforeach; ?>
- <?php else : ?>
- <h2 class="center">Not Found</h2>
- <p class="center">Sorry, but you are looking for something that isn't here.</p>
- <?php include (TEMPLATEPATH . "/searchform.php"); ?>
- <?php endif; ?>
- <?php
- //-------------------------------------------------------------------
- // remove all tabs from posts view
- //-------------------------------------------------------------------
- add_filter('views_edit-post', 'only_show_mine');
- //---------------------------------------
- function only_show_mine( $views ) {
- //---------------------------------------
- if (!current_user_can('promote_users')) {
- $views = array(); //remove all options
- //unset($views['all']);
- //unset($views['publish']);
- }
- return $views;
- }
- ?>
- <?php
- //-------------------------------------------------------------------
- // remove certain tabs from posts and movies view
- //-------------------------------------------------------------------
- function remove__views( $views ) {
- unset($views['all']);
- unset($views['publish']);
- unset($views['trash']);
- return $views;
- }
- //-------------------------------------------------
- add_action( 'views_edit-post', 'remove_views' );
- add_action( 'views_edit-movie', 'remove_views' );
- // This will remove "all", "publish", and "trash" from both posts and the custom post type "movie."
- // Removing these views from other post types is as simple as adding the following line:
- //-------------------------------------------------
- // add_ection( 'views_edit-{post-type-slug}', 'remove_views' );
- ?>
- <?php
- //-------------------------------------------------------------------
- // tweak the tabs in users view
- //-------------------------------------------------------------------
- add_filter( 'views_users', 'modify_views_users_so_15295853' );
- //---------------------------------------------------
- function modify_views_users_so_15295853( $views )
- //---------------------------------------------------
- {
- // Manipulate $views
- return $views;
- }
- ?>
- The content of $views in my system is:
- Array
- (
- [all] => <a href='users.php' class="current">All <span class="count">(7)</span></a>
- [administrator] =>
- <a href='users.php?role=administrator'>Administrator <span class="count">(1)</span></a>
- [editor] => <a href='users.php?role=editor'>Editor <span class="count">(1)</span></a>
- [subscriber] => <a href='users.php?role=subscriber'>Subscriber <span class="count">(5)</span></a>
- )
- <?php
- //-------------------------------------------------------------------
- // select upcoming events in taxonomy=locations
- //-------------------------------------------------------------------
- $locations_with_upcoming_events = $wpdb->get_results("
- SELECT DISTINCT t.*
- FROM wp_terms AS t
- INNER JOIN wp_term_taxonomy AS tt
- ON t.term_id = tt.term_id
- JOIN wp_term_relationships AS tr
- ON tr.term_taxonomy_id = tt.term_taxonomy_id
- JOIN wp_posts AS p
- ON p.ID = tr.object_id
- JOIN wp_postmeta AS pm1
- ON (p.ID = pm1.post_id AND pm1.meta_key = 'event-date')
- JOIN wp_postmeta AS pm2
- ON (p.ID = pm2.post_id AND pm2.meta_key = 'members-only')
- WHERE tt.taxonomy IN ('locations')
- AND p.post_type = 'event'
- AND ( pm1.meta_key = 'event-date' AND CAST(pm1.meta_value AS SIGNED) >= '".time()."')
- AND ( pm2.post_id IS NULL )
- ORDER BY t.name ASC;");
- ?>
- <?php
- //-------------------------------------------------------------------
- // add custom offset for posts pagination
- //-------------------------------------------------------------------
- add_action('pre_get_posts', 'myprefix_query_offset', 1 );
- //--------------------------------------------
- function myprefix_query_offset(&$query) {
- //--------------------------------------------
- //Before anything else, make sure this is the right query...
- if ( ! $query->is_posts_page ) {
- return;
- }
- //First, define your desired offset...
- $offset = 10;
- //Next, determine how many posts per page you want (we'll use WordPress's settings)
- $ppp = get_option('posts_per_page');
- //Next, detect and handle pagination...
- if ( $query->is_paged ) {
- //Manually determine page query offset (offset + current page (minus one) x posts per page)
- $page_offset = $offset + ( ($query->query_vars['paged']-1) * $ppp );
- //Apply adjust page offset
- $query->set('offset', $page_offset );
- }
- else {
- //This is the first page. Just use the offset...
- $query->set('offset',$offset);
- }
- }
- ?>
- WP_Query Object
- (
- [query_vars] => Array
- (
- [page] =>
- [pagename] => blog
- [error] =>
- [m] => 0
- [p] => 0
- [post_parent] =>
- [post_type] =>
- [subpost] =>
- [subpost_id] =>
- [attachment] =>
- [attachment_id] => 0
- [name] =>
- [static] =>
- [page_id] => 0
- [second] =>
- [minute] =>
- [hour] =>
- [day] => 0
- [monthnum] => 0
- [year] => 0
- [w] => 0
- [category_name] =>
- [tag] =>
- [cat] =>
- [tag_id] =>
- [author_name] =>
- [feed] =>
- [tb] =>
- [paged] => 0
- [comments_popup] =>
- [meta_key] =>
- [meta_value] =>
- [preview] =>
- [s] =>
- [sentence] =>
- [fields] =>
- [category__in] => Array
- (
- )
- [category__not_in] => Array
- (
- )
- [category__and] => Array
- (
- )
- [post__in] => Array
- (
- )
- [post__not_in] => Array
- (
- )
- [tag__in] => Array
- (
- )
- [tag__not_in] => Array
- (
- )
- [tag__and] => Array
- (
- )
- [tag_slug__in] => Array
- (
- )
- [tag_slug__and] => Array
- (
- )
- )
- [tax_query] =>
- [meta_query] =>
- [post_count] => 0
- [current_post] => -1
- [in_the_loop] =>
- [comment_count] => 0
- [current_comment] => -1
- [found_posts] => 0
- [max_num_pages] => 0
- [max_num_comment_pages] => 0
- [is_single] =>
- [is_preview] =>
- [is_page] =>
- [is_archive] =>
- [is_date] =>
- [is_year] =>
- [is_month] =>
- [is_day] =>
- [is_time] =>
- [is_author] =>
- [is_category] =>
- [is_tag] =>
- [is_tax] =>
- [is_search] =>
- [is_feed] =>
- [is_comment_feed] =>
- [is_trackback] =>
- [is_home] => 1
- [is_404] =>
- [is_comments_popup] =>
- [is_paged] =>
- [is_admin] =>
- [is_attachment] =>
- [is_singular] =>
- [is_robots] =>
- [is_posts_page] => 1
- [is_post_type_archive] =>
- [query_vars_hash] => 41032f87127fba65fb6743b1e97d8662
- [query_vars_changed] =>
- [thumbnails_cached] =>
- [query] => Array
- (
- [page] =>
- [pagename] => blog
- )
- [queried_object] => stdClass Object
- (
- [ID] => 16
- [post_author] => 1
- [post_date] => 2012-01-31 17:23:57
- [post_date_gmt] => 2012-01-31 17:23:57
- [post_content] =>
- [post_title] => Blog
- [post_excerpt] =>
- [post_status] => publish
- [comment_status] => open
- [ping_status] => open
- [post_password] =>
- [post_name] => blog
- [to_ping] =>
- [pinged] =>
- [post_modified] => 2012-01-31 17:23:57
- [post_modified_gmt] => 2012-01-31 17:23:57
- [post_content_filtered] =>
- [post_parent] => 0
- [guid] =>
- <?php
- //-------------------------------------------------------------------
- //-------------------------------------------------------------------
- add_filter('found_posts', 'myprefix_adjust_offset_pagination', 1, 2 );
- function myprefix_adjust_offset_pagination($found_posts, $query) {
- //Define our offset again...
- $offset = 10;
- //Ensure we're modifying the right query object...
- if ( $query->is_posts_page ) {
- //Reduce WordPress's found_posts count by the offset...
- return $found_posts - $offset;
- }
- }
- //-------------------------------------------------------------------
- // hooks order
- //-------------------------------------------------------------------
- ?>
- Loading my main page
- 16:33:53 - action:muplugins_loaded
- 16:33:53 - action:registered_taxonomy
- 16:33:53 - action:registered_post_type
- 16:33:54 - action:plugins_loaded
- 16:33:54 - action:sanitize_comment_cookies
- 16:33:54 - action:setup_theme
- 16:33:54 - action:load_textdomain
- 16:33:54 - filter:posts_search
- 16:33:54 - action:posts_selection
- 16:33:54 - action:register_sidebar
- 16:33:54 - action:after_setup_theme
- 16:33:54 - action:auth_cookie_malformed
- 16:33:54 - action:auth_cookie_valid
- 16:33:54 - action:set_current_user
- 16:33:54 - action:init
- 16:33:54 - action:widgets_init
- 16:33:54 - action:wp_register_sidebar_widget
- 16:33:54 - action:admin_bar_init
- 16:33:54 - action:add_admin_bar_menus
- 16:33:54 - action:load_textdomain
- 16:33:54 - action:wp_loaded
- 16:33:54 - filter:posts_search
- 16:33:54 - filter:posts_where
- 16:33:54 - filter:posts_join
- 16:33:54 - filter:posts_where_paged
- 16:33:54 - filter:posts_groupby
- 16:33:54 - filter:posts_join_paged
- 16:33:54 - filter:posts_orderby
- 16:33:54 - filter:posts_distinct
- 16:33:54 - filter:post_limits
- 16:33:54 - filter:posts_fields
- 16:33:54 - filter:posts_clauses
- 16:33:54 - action:posts_selection
- 16:33:54 - filter:posts_where_request
- 16:33:54 - filter:posts_groupby_request
- 16:33:54 - filter:posts_join_request
- 16:33:54 - filter:posts_orderby_request
- 16:33:54 - filter:posts_distinct_request
- 16:33:54 - filter:posts_fields_request
- 16:33:54 - filter:post_limits_request
- 16:33:54 - filter:posts_clauses_request
- 16:33:54 - filter:posts_request
- 16:33:54 - filter:posts_results
- 16:33:54 - filter:found_posts_query
- 16:33:54 - filter:found_posts
- 16:33:54 - filter:the_posts
- 16:33:54 - action:template_redirect
- 16:33:54 - action:get_header
- 16:33:54 - action:wp_head
- 16:33:54 - action:wp_enqueue_scripts
- 16:33:54 - action:wp_print_styles
- 16:33:54 - action:wp_print_scripts
- 16:33:54 - action:dynamic_sidebar
- 16:33:54 - filter:posts_search
- 16:33:54 - action:posts_selection
- 16:33:54 - action:begin_fetch_post_thumbnail_html
- 16:33:54 - action:end_fetch_post_thumbnail_html
- 16:33:55 - action:get_sidebar
- 16:33:56 - action:get_footer
- 16:33:56 - action:wp_footer
- 16:33:56 - action:wp_print_footer_scripts
- 16:33:56 - action:wp_before_admin_bar_render
- 16:33:56 - action:wp_after_admin_bar_render
- 16:33:56 - action:shutdown
- Saving a post
- 16:35:57 - action:muplugins_loaded
- 16:35:57 - action:registered_taxonomy
- 16:35:57 - action:registered_post_type
- 16:35:58 - action:plugins_loaded
- 16:35:58 - action:sanitize_comment_cookies
- 16:35:58 - action:setup_theme
- 16:35:58 - action:load_textdomain
- 16:35:58 - filter:posts_search
- 16:35:58 - action:posts_selection
- 16:35:58 - action:register_sidebar
- 16:35:58 - action:after_setup_theme
- 16:35:58 - action:auth_cookie_malformed
- 16:35:58 - action:auth_cookie_valid
- 16:35:58 - action:set_current_user
- 16:35:58 - action:init
- 16:35:58 - action:widgets_init
- 16:35:58 - action:wp_register_sidebar_widget
- 16:35:58 - action:admin_bar_init
- 16:35:58 - action:add_admin_bar_menus
- 16:35:58 - action:wp_loaded
- 16:35:58 - filter:posts_search
- 16:35:58 - filter:posts_where
- 16:35:58 - filter:posts_join
- 16:35:58 - filter:posts_where_paged
- 16:35:58 - filter:posts_groupby
- 16:35:58 - filter:posts_join_paged
- 16:35:58 - filter:posts_orderby
- 16:35:58 - filter:posts_distinct
- 16:35:58 - filter:post_limits
- 16:35:58 - filter:posts_fields
- 16:35:58 - filter:posts_clauses
- 16:35:58 - action:posts_selection
- 16:35:58 - filter:posts_where_request
- 16:35:58 - filter:posts_groupby_request
- 16:35:58 - filter:posts_join_request
- 16:35:58 - filter:posts_orderby_request
- 16:35:58 - filter:posts_distinct_request
- 16:35:58 - filter:posts_fields_request
- 16:35:58 - filter:post_limits_request
- 16:35:58 - filter:posts_clauses_request
- 16:35:58 - filter:posts_request
- 16:35:58 - filter:posts_results
- 16:35:58 - filter:found_posts_query
- 16:35:58 - filter:found_posts
- 16:35:58 - filter:the_posts
- 16:35:58 - action:template_redirect
- 16:35:58 - action:json_api-addlink-add_link
- 16:35:58 - action:clean_object_term_cache
- 16:35:58 - action:clean_post_cache
- 16:35:58 - action:transition_post_status
- 16:35:58 - action:private_to_published
- 16:35:58 - action:new_to_publish
- 16:35:58 - action:publish_videos
- 16:35:58 - action:save_post
- 16:35:58 - action:clean_object_term_cache
- 16:35:58 - action:clean_post_cache
- 16:35:58 - action:wp_insert_post
- 16:35:58 - action:add_post_meta
- 16:35:58 - action:added_post_meta
- 16:35:58 - action:add_term_relationship
- 16:35:58 - action:added_term_relationship
- 16:35:58 - action:edit_term_taxonomy
- 16:35:58 - action:edited_term_taxonomy
- 16:35:58 - action:clean_term_cache
- 16:35:58 - action:set_object_terms
- 16:35:58 - action:create_term
- 16:35:58 - action:create_videostags
- 16:35:58 - action:delete_option
- 16:35:58 - action:delete_option_videostags_children
- 16:35:58 - action:deleted_option
- 16:35:58 - action:add_option
- 16:35:58 - action:add_option_videostags_children
- 16:35:58 - action:added_option
- 16:35:58 - action:clean_term_cache
- 16:35:58 - action:created_term
- 16:35:58 - action:created_videostags
- 16:35:58 - action:add_term_relationship
- 16:35:58 - action:added_term_relationship
- 16:35:58 - action:edit_term_taxonomy
- 16:35:58 - action:edited_term_taxonomy
- 16:35:58 - action:set_object_terms
- 16:35:59 - action:http_api_debug
- 16:35:59 - action:set_object_terms
- 16:35:59 - action:add_post_meta
- 16:35:59 - action:added_post_meta
- 16:35:59 - action:clean_object_term_cache
- 16:35:59 - action:clean_post_cache
- 16:35:59 - action:add_attachment
- 16:35:59 - action:add_post_meta
- 16:35:59 - action:added_post_meta
- 16:35:59 - action:http_api_debug
- 16:35:59 - action:set_object_terms
- 16:35:59 - action:add_post_meta
- 16:35:59 - action:added_post_meta
- 16:35:59 - action:clean_object_term_cache
- 16:35:59 - action:clean_post_cache
- 16:36:00 - action:shutdown
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement