Wordpress useful
----- str_replace
<?php if(!empty($map)): ?><?php echo str_replace(array('[site-url]','[template-url]'),array(get_bloginfo('url'),get_bloginfo('template_url')), $map); ?><?php endif; ?>
----- WP QUERY $wp_query
$wp_query->found_posts
$wp_query->max_num_pages
<?php echo get_post_type( $post ) ?>
----- апостроф кавычки дефис
' " -
----- base dir __FILE__ dirname
$baseDir = dirname(__FILE__);
$baseDir = realpath($baseDir);
---- redirect to current url
<?php
$redirecturl = '';
foreach($_GET as $i => $k)
{
if(!empty($i))
{
$redirecturl .= get_bloginfo('url').'/'.'?'.$i.'='.$k;
}
}
?>
----- human date time ago timestamp
<?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?>
----- спец символы декодирование слоган с тегами html convert html decode
html_entity_decode(get_bloginfo('description'))
----- регулярка с поиском градуса
<?php
$result = '';
preg_match("/(\d+\s\°\;)|(\d+\°\;)/", $item['summary'], $result);
if(!empty($result))
{
echo '<strong class="temp">'.current($result).'</div>';
}
?>
----- init over all
add_action('init', 'upload_files_process');
function upload_files_process(){
----- check plugin is plugin active is active plugin
http://themergency.com/wordpress-tip-how-to-check-if-a-plugin-is-active/
----- upload file types
add_filter('upload_mimes', 'custom_upload_mimes');
function custom_upload_mimes ( $existing_mimes=array() )
{
// add your extension to the array
$existing_mimes['deb'] = 'application/x-deb';
// add as many as you like
// removing existing file types
unset( $existing_mimes['exe'] );
// add as many as you like
// and return the new full result
return $existing_mimes;
}
----- current url with parameters текущий урл с параметрами
if ( ! function_exists( 'get_current_page_url' ) ) {
function get_current_page_url() {
global $wp;
return add_query_arg( $_SERVER['QUERY_STRING'], '', home_url( $wp->request ) );
}
}
if ( ! function_exists( 'the_current_page_url' ) ) {
function the_current_page_url() {
echo get_current_page_url();
}
}
----- php in js php in javascript
$marker_image_url = get_bloginfo('template_url').'/images/map-pin.png';
var image = <?php echo json_encode($marker_image_url); ?>;
------ insert in table
global $wpdb;
$table_name = $wpdb->prefix . 'test';
$wpdb->insert( $table_name, array( 'email' => $_REQUEST["subscribe_mailchimp"] ), array( '%s' ) );
----- get current url
global $wp;
echo home_url( $wp->request );
\!h onchange redirect when select option
<select class="light-style sorting-select" name="sort-by" onchange="location=this.options[this.selectedIndex].value;">
<option class="hidden" value="default"><?php _e( 'Default sorting', DOMAIN ) ?></option>
<option value="<?php echo add_query_arg('sort-by', 'best-selling') ?>" ><?php _e( 'Best selling', DOMAIN ) ?></option>
<option value="most-recent"><?php _e( 'Most recent', DOMAIN ) ?></option>
<option value="price-low-high"><?php _e( 'Price, low to high', DOMAIN ) ?></option>
<option value="price-high-low"><?php _e( 'Price, high to low', DOMAIN ) ?></option>
<option value="a-z"><?php _e( 'Alphabetical, A to Z', DOMAIN ) ?></option>
<option value="z-a"><?php _e( 'Alphabetical, Z to A', DOMAIN ) ?></option>
</select>