50 przydatnych kodów WordPress cz. 1

Chciałem podzielić się kilkoma „kawałkami kodów” przydatnych przy tworzeniu stron na WordPress-ie
Zbieram je z sieci od kilku lat. Nie gwarantuję że będą działały w obecnej postaci (kopiuję je z moich notatek)
Nie będę rozpisywał się odnośnie ich funkcjonowania i zastosowania gdyż każdy kto choć trochę kojarzy kod od razu będzie widziała jakie ma on zastosowanie i będzie mógł go ponownie zmodyfikować wg. własnych potrzeb 😉
Mam nadzieje że się przydadzą.

 

—————————–
1. wyświetla treść z wpisu o id=11200
—————————–
<?php
$id = 11200;
$p = get_page($id);
echo apply_filters(’the_content’, $p->post_content);
?>

—————————–
2. Trochę if-ów w różnej wersji
—————————–
<?php if (is_404()) {echo'<meta name=”robots” content=”noindex,noarchive” />’;} ?>
<?php if ( is_search() ) {echo'<meta name=”robots” content=”noindex,noarchive” />’;}?>

<?php
if ( is_front_page() ) {echo’ <li class=”droplink”><a href=”#artykuly”><span class=”menu-icon icon-note”><span id=”menu1″>Artykuły</span></span></a></li>’;}
else {echo’ <li class=”droplink”><a href=”artykuly”><span class=”menu-icon icon-note”><span id=”menu1″>Artykuły</span></span></a></li>’;}
?>

<?php
if(is_user_logged_in())
echo do_shortcode('[responsive_menu]’);
else
echo do_shortcode('[responsive_menu menu_to_use=”logged-in-menu”]’);
?>

<?php if (is_front_page()) : ?>
<?php echo do_shortcode( '[rev_slider alias=”home-default”]’ ); ?>
<?php endif; ?>

 

if((is_home() && ($paged < 2 )) || is_single() || is_page() || is_category()){ echo '<meta name=”robots” content=”index,follow” />’; } else { echo '<meta name=”robots” content=”noindex,follow” />’; } ?>

<?php
if ( is_front_page() || is_home() || is_404() ) {
$heading = 'h1′;
$desc = 'h2′;
} else {
$heading = 'h2′;
$desc = 'h3′;
}
?>

<?php if ((in_category(’ab’)) || (in_category(’cd’))) : ?>
xxx
<?php endif; ?>

 

<?php if (!is_page(’kontakt’)){ ?>
xxx
<?php } ?>

 

<?php if( is_front_page() ) : ?>
<div>Dowolna treścccccccc</div>
<?php endif;?>

 

<?php if ( is_user_logged_in() ) {
the_excerpt();
} else {
the_content();
} ?>

<?php if (is_page(’ranking’)) { ?>s
<div class=”panel-body”><?php comments_template(); ?></div>
<?php } ?>

—————————–
3. Wiadomo co….
—————————–
<?php _e(’Sorry, no posts matched your criteria.’); ?>
<?php bloginfo( 'home’ ); ?>
<?php bloginfo( 'stylesheet_url’ ); ?>
<?php bloginfo( 'template_url’ ); ?>
<?php bloginfo(’description’); ?>
<?php bloginfo(’name’); ?>
<?php bloginfo(’siteurl’);?>
<?php bloginfo(’stylesheet_directory’);?>
<?php bloginfo(’url’); ?>
<?php bloginfo_rss( 'rss_url’ ) ?>
<?php echo get_template_directory_uri(); ?>
<?php get_footer(); ?>
<?php get_sidebar(); ?>
<?php get_the_excerpt();?>
<?php single_post_title(”); ?>
<?php the_author(); ?>
<?php the_content(’czytaj dalej’); ?>
<?php the_permalink();?>
<?php the_post_thumbnail(); ?>
<?php the_post_thumbnail_url(); ?>
<?php the_time(’d-m-Y’); ?>
<?php the_title();?>
<?php wp_head(); ?>
<?php wp_title(); ?>

 

<?php include(TEMPLATEPATH . „/searchform.php”); ?>

 

—————————–
4. Wyświetla custom filed – wyświetla pole własne
—————————–
<?php echo get_post_meta( get_the_ID(), 'vthumb2017′, true ); ?>
<?php $key=”videoembed”; echo get_post_meta($post->ID, $key, true); ?>
<?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'videoembed’, true);
wp_reset_query();
?>
<?php echo get_post_meta( get_the_ID(), 'videoembed’, true ); ?>

 

—————————–
5. include post / page content
—————————–
function cn_include_content($pid) {
$thepageinquestion = get_post($pid);
$content = $thepageinquestion->post_content;
$content = apply_filters(’the_content’, $content);
$content = str_replace(’]]>’, ’]]>’, $content);
echo $content;
}

<?php cn_include_content(69); ?>

 

—————————–
6. Zmiana wszystkich postów na autora 1
—————————–
UPDATE wp_posts SET post_author=1

 

—————————–
7. Wyszukaj wpis o id
—————————–
SELECT * FROM `wp_posts` WHERE id =’61775′
UPDATE `wp_posts` SET `post_date_gmt`=”2017-01-13 11:44:30″
UPDATE `wp_posts` SET `guid`=”okkk” WHERE `ID`=’6′

 

—————————–
8. Zmiana daty publikacji wpisów
—————————–
UPDATE `wp_posts` SET post_date=”2015-07-22 20:31:30″
WHERE post_date BETWEEN '2015-07-31 00:00:00′ AND '2015-12-14 00:00:00′
AND post_status=”publish”

 

—————————–
9. Wyszukaj i zmień w treści
—————————–
UPDATE wp_posts SET `post_content`
= REPLACE (`post_content`,
'http://example.com/’,
'http://myexample.com/’);

 

—————————–
10. Wpisy na strony
—————————–
update wp_posts set post_type = 'page’ WHERE post_type = 'post’

 

—————————–
11. Wybierz id wszystkich postów
—————————–
SELECT `ID` FROM `wp_posts`
SELECT `ID`, `guid` FROM `wp_posts`

 

—————————–
12. Mój kod JavaScript w Head
—————————–
add_action(’wp_head’, 'moj_kod_js’);
function moj_kod_js() {
echo <<<JS
<script type=”text/javascript”>
// Tutaj wpisz kod JavaScript
</script>
JS;
}

 

—————————–
13. Sortowanie – zmiana kolejności wyświetlania
—————————–
function wpzen_reorder_posts($query) {
if($query->is_main_query() && ($query->is_home() || $query->is_search() || $query->is_archive())) {
$query->set(’orderby’, 'modified’);
$query->set(’order’, 'desc’);
}
}
add_action(’pre_get_posts’, 'wpzen_reorder_posts’);

 

—————————–
14. Title ograniczony do 10 słów
—————————–
<?php
$trimtitle = get_the_title();
$shorttitle = wp_trim_words( $trimtitle, $num_words = 10, $more = '… ’ );
echo '<h2 class=”entry-title”>’ . '<a href=”’ . get_permalink() . '”>’ . $shorttitle . '</a></h2>’;
?>

 

—————————–
15. Reklamy w działach
—————————–
<?php if (is_category( 'dom’ )) {
echo '<script type=”text/javascript”>
var uri = \’https://imppl.tradedoubler.com/imp?type(js)pool(532196)a(2871871)\’ + new String (Math.random()).substring (2, 11);
document.write(\'<sc\’+\’ript type=”text/javascript” src=”\’+uri+\'” charset=”ISO-8859-1″></sc\’+\’ript>\’);
</script><div style=”padding-bottom:25px”></div>’;}

elseif (is_category( 'ksiazki’ )) {
echo '<div style=”margin-bottom: 20px;”><a href=”http://domena.pl/produkt/byc-audrey-hepburn/”><img src=”http://domena.pl/wp-content/uploads/2016/11/BycjakAudrey_750x200obcasy.jpg” /></a></div>’;}

elseif (is_category( 'lifestyle’ )) {
echo ’ <div style=”margin-bottom: 20px;”><a href=”http://domena.com/kopia-work-life-balance”><img src=”http://domena.pl/wp-content/uploads/2017/01/admonis-cat.png” /></a></div>’;}

else {
echo '<div style=”margin:0px 0px 30px 0px;>:728px; height:90px;margin-left:-25px”>
<script async src=”//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js”></script>
<!– obcasy-index –>
<ins class=”adsbygoogle”
style=”display:block”
data-ad-client=”ca-pub-7802076754061914″
data-ad-slot=”2836857822″
data-ad-format=”auto”></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>’;
}
?>

—————————–
16. bbPress – zamienia wszystkie linki w postach na [usunięto link]
—————————–
function bb_table_replace( $text ) {
$text = preg_replace(’/<a[\s]+[^>]*?href[\s]?=[\s\”\’]*(.*?)[\”\’]*.*?>([^<]+|.*?)?<\/a>/’, „<span style=\”color:#fa3800;\”>[usunięto_link]</span>”, $text);
return $text;
}
add_filter(’bbp_get_reply_content’, 'bb_table_replace’);

 

function unknown_filter_content( $_content ) {
$_content = preg_replace(
'/<a[\s]+[^>]*?href[\s]?=[\s\”\’]*(.*?)[\”\’]*.*?>([^<]+|.*?)?<\/a>/g’,
'[usunieto_link]’,
$_content
);
return $_content;
}
add_filter( 'the_content’, 'unknown_filter_content’ )

—————————–
17. Box-shadow CSS
—————————–
0 30px 50px 0 rgba(1, 1, 1, 0.15)
5px 5px 5px rgba(0, 0, 0, 0.05)
0 -3px 10px 0 rgba(0, 0, 0, 0.08)
0 0 4px rgba(0, 0, 0, 0.14), 0 4px 8px rgba(0, 0, 0, 0.28)
2px 2px 16px rgba(0, 0, 0, 0.3)
0 2px 12px rgba(0, 0, 0, 0.1)
0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 0 #d8d8d8 inset
0 4px 14px -7px #a8a8a8
0 8px 6px -6px rgba(0, 0, 0, 0.21)
0 0 10px rgba(0, 0, 0, 0.21)
0 1px 3px #c1c1c1
0 5px 5px -5px rgba(0,0,0,.1)
0 2px 4px rgba(0, 0, 0, 0.08)
0 4px 6px 1px rgba(50, 50, 50, 0.14)
0 1px 4px 0 rgba(0, 0, 0, 0.2)
0 5px 15px -5px #999999
0 1px 1px rgba(0, 0, 0, 0.05);

 

—————————–
18. Rozbicie daty ACF
—————————–
<?php
// get raw date
//$date = get_field(’date’, false, false);
$date = get_field(’czas_do’, false, false);
$day = substr( $date, 0, 2 );
$month = substr( $date, 2, 2 );
$year = substr( $date, 4 );
$date = date( 'j M Y’, mktime( 0, 0, 0, $month, $day, $year ) );
// make date object
//$date = new DateTime($date);
?>

<p class=”moja_data”>Ważne do: <?php echo $date; ?></p>

 

—————————–
19. Losuje liczbę
—————————–
<?php $losuj = rand(1,1111111111111);?>
<div id”<?=$losuj?>”Moja treść yee ;d!</div>

 

—————————–
20. #usuwa wszystkie zdjęcia z WordPress – ale tylko z Media, bo na serwerze zostaną
—————————–
# First:
DELETE FROM wp_postmeta
WHERE post_id IN
(
SELECT id
FROM wp_posts
WHERE post_type = 'attachment’
)
;

DELETE FROM wp_posts WHERE post_type = 'attachment’

—————————–
21. Kolejne kawałki
—————————–
<?php
$plik = rand(1,20) ;
print „<img src=’gfx/.”$plik.”.jpg’>”;
?>

 

<?
$t = array(’images/obrazek1.jpg’, 'grafika/grafika2.jpg’, 'obraz.png’, 'http://wp.pl/logo.jpg’);
echo '<img src=”’.$t[array_rand($t)].'” alt=”” />;
?>

 

<?php
$teksty[] = „<?php include(\”los1.txt\”) ?> „;
$teksty[] = „<?php include(\”los2.txt\”) ?> „;
$teksty[] = „<?php include(\”los3.txt\”) ?> „;
$teksty[] = „<?php include(\”los4.txt\”) ?> „;
srand ((float) microtime() * 10000000);
$tekst = $teksty[array_rand($teksty)];
eval($tekst);
?>

<?php
#tablica zawierająca nazwy plików – obrazków
$obrazki = array(„a.jpg”, „b.jpg”, „c.jpg”, „d.jpg”, „e.jpg”);

#inicjujemy generator licz losowych
srand ((float) microtime() * 10000000);

#wybieramy jeden losowy obrazek z tablicy
$obrazek = $obrazki[array_rand($obrazki)];

#wyświetlamy losowy obrazek
echo „<img src=$obrazek>”;
?>

 

—————————–
22. Losowe tagi w chmurze
—————————–

add_filter( 'the_content’, 'attachment_image_link_remove_filter’ );function attachment_image_link_remove_filter( $content ) { $content = preg_replace( array('{<a(.*?)(wp-att|wp-content\/uploads)[^>]*><img}’, '{ wp-image-[0-9]*” /></a>}’), array('<img’,'” />’), $content ); return $content; }
function custom_tag_cloud_widget($args) {
$args[’number’] = 16; //adding a 0 will display all tags
$args[’orderby’] = name; //adding a 0 will display all tags
$args[’order’] = RAND; //adding a 0 will display all tags
return $args;
}
add_filter( 'widget_tag_cloud_args’, 'custom_tag_cloud_widget’ );

 

—————————–
23. Reklama adsence w srodku content, po 3 akapicie
—————————–

add_filter(’the_content’, 'wpse_ad_content’);

function wpse_ad_content($content)
{
if (!is_single()) return $content;
$paragraphAfter = 3; //Enter number of paragraphs to display ad after.
$content = explode(„</p>”, $content);
$new_content = ”;
for ($i = 0; $i < count($content); $i++) {
if ($i == $paragraphAfter) {
$new_content.= '<div style=”>: 750px; height: 100px; padding: 6px 6px 6px 0; float: left; margin-left: 0; margin-right: 18px;”>’;
$new_content.= ’
<div id=\’div-gpt-ad-1357677375856-4\’ style=\’>:750px; height:100px;\’>
<script type=\’text/javascript\’>
googletag.cmd.push(function() { googletag.display(\’div-gpt-ad-1357677375856-4\’); });
</script>
</div>’;
$new_content.= '</div>’;
}

$new_content.= $content[$i] . „</p>”;
}

return $new_content;
}

 

———————————
24. Reklama adsence jako shortcode
———————————

/*
* Copy the code into your theme’s functions.php file
* Change the AdSense <script> for yours
*/
function showads() {
return '<div><script type=”text/javascript”><!–
google_ad_client = „pub-XXXXXXXXXXXXXX”;
google_ad_slot = „4668915978”;
google_ad_> = 468;
google_ad_height = 60;
//–>
</script>

<script type=”text/javascript”
src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”>
</script></div>’;
}

add_shortcode(’adsense’, 'showads’);

 

———————————
25. ACF – wpis znaleziono dzięki
———————————
<?php if ((is_single()) && ( get_field(’slowo1′) !=””)) { ?>
<div style=” padding: 10px 0;”><span style=”font-weight:bold”>Wpis znaleziono dzięki:</span>
<p style=”margin-top: 5px; margin-bottom: 5px;”>- <?php the_field(’slowo1′); ?></p>
<p style=”margin-top: 5px; margin-bottom: 5px;”>- <?php the_field(’slowo2′); ?></p>
<p style=”margin-top: 5px; margin-bottom: 5px;”>- <?php the_field(’slowo3′); ?></p>
</div>
<?php } ?>

———————————
26. Cała treśc tylko dla zalogowanych
———————————
add_filter( 'the_content’, function( $content ) {
if( ! is_user_logged_in() ){
return wp_trim_words( $content, 10, '…<p>Całość tylko dla zalogowanych</p>’ );
}
return $content;});

 

———————————
27. Podaje ile (liczbowo) zlazał wyników dla szukanej frazy
———————————
<?php echo $wp_query->found_posts; ?> <?php _e( ”, 'locale’ ); ?>: „<?php the_search_query(); ?>”

 

———————————
28. in_category – jeżeli jest w kategorii
———————————
<?php if ( !in_category( array( 'KONKURSY’, 'Regulamin’, /*etc*/ ) )) { ?>
<div id=”podzielsie” style=”height: 30px; margin-right: 0; padding-bottom: 15px;”></div>
<?php } else {?>
<div id=”podzielsie” style=”height: 30px; margin-right: 0; padding-bottom: 15px;”></div>
<?php } ?>

 

———————————
29. Remove ver. /js.js=v=xxx
———————————

function ewp_remove_script_version( $src ){
return remove_query_arg( 'ver’, $src );
}
add_filter( 'script_loader_src’, 'ewp_remove_script_version’, 15, 1 );
add_filter( 'style_loader_src’, 'ewp_remove_script_version’, 15, 1 );

 

———————————
30. rev = 3
———————————
define( 'WP_POST_REVISIONS’, 3 );

 

———————————
31. zakaz wykonywania .php z /upload
———————————
<IfModule mod_rewrite.c>
RewriteEngine On
# Wylaczenie uruchamiania plikow php w UPLOADS
RewriteRule ^wp\-content/uploads/.*\.(?:php[1-6]?|pht|phtml?)$ – [NC,F]
</IfModule>

———————————
32. wysylanie tylko tych plikow do /upload
———————————
<Files ~ „.*..*”>
Order Allow,Deny Deny from all
</Files>
<FilesMatch „.(jpg|jpeg|jpe|gif|png|tif|tiff)”>
Order Deny,Allow Allow from all
</FilesMatch>

 

———————————
33. Upload wszystkich typów plików dla administratora-
———————————
define( 'ALLOW_UNFILTERED_UPLOADS’, true );

———————————
34. external link nofollow
———————————

function nofollowexternal_changelink($message) {
global $mybb;
$message = preg_replace_callback(„/<a href=\”http://(.+)\” (.+)>(.+)<\\/a>/”, „replace_external”, $message);
return $message;
}

———————————
35. nowollow in ocntent
———————————
add_filter( 'the_content’, 'add_no_follow’ );
function add_no_follow($content)
{
if ( preg_match_all( '/<a[^>]+>/’, $content, $matches ) ) {
foreach ( $matches[0] as $old ) {
$new = preg_replace( '/ rel=”[^”]+”/’, ”, $old );
$new = preg_replace( '/>/’, ’ rel=”nofollow”>’, $new );
$re = sprintf(’|%s|’, preg_replace( '/\|/’, '\\|’, $old ) );
$content = preg_replace( $re, $new, $content );
}
}
return $content;
}

 

———————————
36. jqery to footer
———————————
<?php
/**
* Plugin Name: Enqueue jQuery in Footer
* Version: 0.0.1
* Plugin URI: http://wpgrafie.de/836/
* Description: Prints jQuery in footer on front-end.
* Author: Dominik Schilling
* Author URI: http://wpgrafie.de/
*/
function ds_enqueue_jquery_in_footer( &$scripts ) {

if ( ! is_admin() )
$scripts->add_data( 'jquery’, 'group’, 1 );
}
add_action( 'wp_default_scripts’, 'ds_enqueue_jquery_in_footer’ );

 

———————————
37. dodanie url do obrazka w Media dla kazdego obrazka
———————————
function muc_column( $cols ) { $cols[„media_url”] = „adresURL”; return $cols; } function muc_value( $column_name, $id ) { if ( $column_name == „media_url” ) echo '<input type=”text” >=”100%” onclick=”jQuery(this).select();” value=”’. wp_get_attachment_url( $id ). '” readonly=”true” />’; } add_filter( 'manage_media_columns’, 'muc_column’ ); add_action( 'manage_media_custom_column’, 'muc_value’, 10, 2 );

 

———————————
28. Dodaje 1sze zdjecie jako thumb jezeli nie dodano
———————————
function autoset_featured() {global $post; $already_has_thumb = has_post_thumbnail($post->ID);
if (!$already_has_thumb)
{$attached_image = get_children( „post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1” );
if ($attached_image) { foreach ($attached_image as $attachment_id => $attachment) { set_post_thumbnail($post->ID, $attachment_id); } } } } //end function add_action(’the_post’, 'autoset_featured’); add_action(’save_post’, 'autoset_featured’); add_action(’draft_to_publish’, 'autoset_featured’); add_action(’new_to_publish’, 'autoset_featured’); add_action(’pending_to_publish’, 'autoset_featured’); add_action(’future_to_publish’, 'autoset_featured’);

———————————
39. Ustawienie kosza w Mediach
———————————
define( 'MEDIA_TRASH’, true );

 

———————————
40. CF7 – pole wyboru adresu e-mial do wysyłki
———————————
[select your-recipient „Materiały prasowe|[email protected]” „Patronaty|[email protected]” „Konkursy|[email protected]” „Reklama|[email protected]” „Redakcja|[email protected]”]

 

———————————
41. Domyslna ikona wpisu
———————————

<?php $post_featured_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?>
<?php if(!empty($post_featured_image)) { ?>
<img style=”border-radius: 5px;float: left;margin-right: 10px;>: 45px;margin-bottom:10px” src=”<?php echo $post_featured_image; ?>” alt=”<?php the_title(); ?>”>
<?php } else {
echo '<img style=”border-radius: 5px;float: left;margin-right: 10px;>: 45px;margin-bottom:10px” src=”/wp-content/themes/ox/img/ikona-wpisu.png” />’;
}?>

 

function catch_that_image() {
global $post, $posts;
$first_img = ”;
ob_start();
ob_end_clean();
$output = preg_match_all(’/<img.+src=[\'”]([^\'”]+)[\'”].*>/i’, $post->post_content, $matches);
$first_img = $matches[1][0];

if(empty($first_img)) {
$first_img = „/wp-content/themes/delicacy/images/ikona-wpisu.png”;
}
return $first_img;
}

 

———————————
42. Uzyta pamiec i czas ladowania strony
———————————
Zapytania: <?php echo get_num_queries();
global $wpdb;
foreach ($wpdb->queries as $query)
echo $query[0].”\n”; ?>
Czas generowania: <?php timer_stop(1, 2); ?>s
Użyta pamięć: <?php echo number_format(memory_get_usage()/1024/1024, 2); ?>MB

 

———————————
43. Get category name
———————————
<h1><?php foreach((get_the_category()) as $category) { echo $category->cat_name . ’ ’; } ?></h1>
<a href=”<?php echo esc_url( $category_link ); ?>” title=”Category Name”>Category Name</a>

<?php
$category = get_the_category();
if($category[0]){
echo '<a href=”’.get_category_link($category[0]->term_id ).'” title=”’.$category[0]->cat_name.’ | Pozostałe uczelnie”>’.$category[0]->cat_name.'</a>’;
}
?>

<?php $term = get_term_by( 'slug’, get_query_var( 'term’ ), get_query_var( 'taxonomy’ ) );
echo $term->name; // will show the name ?>

 

———————————
44. Rozdzielenie galerii od tresci
———————————
<?php if(has_shortcode(get_the_content(), 'gallery’)) : ?>
<?php
$pattern = get_shortcode_regex();
preg_match(„/$pattern/s”, get_the_content(), $matches);
?>
<div id=”content”>
<?php echo strip_shortcodes(get_the_content()); ?>
</div>
<div id=”gallery”>
<?php echo do_shortcode($matches[0]); ?>
</div>
<?php endif; ?>

 

———————————
45. Własny typ wpisów
———————————
add_action( 'init’, 'create_atrakcje_post_type’ );
function create_atrakcje_post_type() {
register_post_type( 'domy’,
array(
'labels’ => array(
'name’ => __( 'Domy’ ),
'singular_name’ => __( 'Domy’ ),
),
'public’ => true,
'has_archive’ => true,

'rewrite’ => array(’slug’ => 'domy’),
'exclude_from_search’ => true,
'rewrite’ => true,
'capability_type’ => 'post’,
)
);

add_post_type_support( 'domy’, 'custom-fields’ );
add_post_type_support( 'domy’, 'excerpt’ );
add_post_type_support( 'domy’, 'thumbnail’ );
add_post_type_support( 'domy’, 'wpgeo’ );
register_taxonomy_for_object_type(’category’, 'domy’);
}

 

———————————
46. Max thumbs size 100%
———————————
<?php echo the_post_thumbnail( 'full’,’style=max->:100%;height:auto;’); ?>

 

———————————
47. CF7 responsive
———————————
input.wpcf7-form-control, textarea.wpcf7-form-control {>:99%;max->:99%; padding: 10px 1px !important;}

@media only screen and (min-> : 240px) {
.wpcf7-textarea,
.wpcf7-text {
max->: 100%;
padding: 10px 1px !important;
}
}

 

———————————
48. Przekierownaie po zalogowaniu
———————————
function my_login_redirect( $redirect_to, $request, $user ) {
//is there a user to check?
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
//check for admins
if ( in_array( 'administrator’, $user->roles ) ) {
// redirect them to the default place
return $redirect_to;
} else {
return home_url() . '/forum’;
}
} else {
return home_url() . '/forum’;
}
}

add_filter( 'login_redirect’, 'my_login_redirect’, 10, 3 );

 

function logout_redirect_home(){
wp_safe_redirect(home_url() . '/forum’);
exit;
}
add_action(’wp_logout’, 'logout_redirect_home’);

 

———————————
49. sanitize_file_name – czyli nazwy plików bez znaków specjalnych
———————————
add_action( 'sanitize_file_name’, 'iworks_sanitize_file_name’ );
if ( ! function_exists( 'iworks_sanitize_file_name’ ) ) {
function iworks_sanitize_file_name( $filename ) {
$de_from = array( 'ä’,’ö’,’ü’,’ß’,’Ä’,’Ö’,’Ü’ );
$de_to = array( 'ae’,’oe’,’ue’,’ss’,’Ae’,’Oe’,’Ue’ );
$filename = str_replace( $de_from, $de_to, $filename );
$pl_from = array( 'ą’, 'ć’, 'ę’, 'ł’, 'ń’, 'ó’, 'ś’, 'ź’, 'ż’, 'Ą’, 'Ć’, 'Ę’, 'Ł’, 'Ń’, 'Ó’, 'Ś’, 'Ź’, 'Ż’ );
$pl_to = array( 'a’, 'c’, 'e’, 'l’, 'n’, 'o’, 's’, 'z’, 'z’, 'A’, 'C’, 'E’, 'L’, 'N’, 'O’, 'S’, 'Z’, 'Z’ );
$filename = str_replace( $pl_from, $pl_to, $filename );
$filename = preg_replace( '/[^A-Za-z0-9\._]/’, ’-’, $filename );
$filename = preg_replace( '/[_ ]+/’, ’-’, $filename );
$filename = preg_replace( '/%20/’, ’-’, $filename );
return $filename;
}
}

 

———————————
50. Masowa zmiana daty wpisów
———————————
UPDATE wp_posts
SET post_date = '2015-01-01′
+ INTERVAL rand()*300 DAY
+ INTERVAL rand()*6000 SECOND
;

O PORTALU

Polecam tylko sprawdzone programy! Zdecydowana większość to darmowe programy do użytku zarówno w domu jaki i w firmie. Przeważnie są one rozpowszechniane na licencji GNU i Freeware. Dostępne tutaj w wersji przenośnej portable - czyli bez instalacji a więc wystarczy je uruchomić. Sprawdzone - używane przez mnie od kilku lat.

,