This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url = "url to file"; | |
$tmp = download_url( $url ); | |
/* Does a file with this name already exist in the media library? */ | |
$filename = remove_accents( preg_replace("/\\.[^.\\s]{3,4}$/", "", basename( $url ) ) ); | |
global $wpdb; | |
$poststable = $wpdb->prefix . "posts"; | |
$filename_exists = $wpdb->get_col( "SELECT post_name FROM $poststable WHERE post_name LIKE '$filename' AND post_type = 'attachment'" ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT * FROM $termstable AS terms | |
JOIN ".$wpdb->prefix."term_taxonomy AS termtax ON terms.term_id = termtax.term_id | |
WHERE termtax.taxonomy = '$taxonomy' | |
AND terms.name LIKE '%$searchterm%' COLLATE utf8_swedish_ci | |
ORDER BY termtax.count DESC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'template_include', 'my_prefix_template' ); | |
function my_prefix_template( $template ) { | |
$template_filename = "foobar.php"; | |
if ( !file_exists( get_stylesheet_directory() . "/" . $template_filename ) ) { | |
$template = plugin_dir_path( __FILE__ ) . '/' . $template_filename; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Custom columns on edit terms screens i admin | |
* */ | |
add_filter( 'manage_edit-{taxonomy-slug}_columns', 'hip_{taxonomy-slug}_columns_head' ); | |
add_filter( 'manage_{taxonomy-slug}_custom_column', 'hip_{taxonomy-slug}_columns_content_taxonomy', 10, 3 ); | |
function hip_{taxonomy-slug}_columns_head( $columns ) { | |
unset( $columns['posts'] ); // unset the posts column | |
unset( $columns['slug'] ); // unset the slug column |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'attachment_fields_to_edit', 'hip_edit_media_custom_field', 11, 2 ); | |
add_filter( 'attachment_fields_to_save', 'hip_save_media_custom_field', 11, 2 ); | |
function hip_edit_media_custom_field( $form_fields, $post ) { | |
$form_fields['image_source'] = array( | |
'label' => __( 'Bildkälla', 'ds' ), | |
'input' => 'text', | |
'value' => get_post_meta( $post->ID, 'image_source', true ), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function hip_toolbar_items() { | |
global $wp_admin_bar; | |
$args = array( | |
'id' => 'id', | |
'title' => __( 'Title', 'textdomain' ), | |
'href' => admin_url(), | |
); | |
$wp_admin_bar->add_menu( $args ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'get_pages', 'hip_exclude_from_wp_list_pages', 10, 2 ); | |
/** | |
* Exclude pages with meta value 'hide_page_in_menus' set to 1 from wp_list_pages | |
* @param array $pages | |
* @param array $args | |
* @return array $pages | |
*/ | |
function hip_exclude_from_wp_list_pages( $pages, $args ) { | |
// Check for 'walker' key to see if this is being used by wp_list_pages() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$args = array( | |
'post_type' => 'product', | |
'meta_query' => array( | |
'relation' => 'OR', | |
array( | |
'key' => 'color', | |
'value' => 'blue', | |
'compare' => 'NOT LIKE' | |
), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Move advanced meta boxes to below after the title | |
*/ | |
function hip_mc_move_settings_box() { | |
# Get the globals: | |
global $post, $wp_meta_boxes; | |
$posttype = "post"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Autosave, do nothing | |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) | |
return; | |
// AJAX | |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) | |
return; | |
// Check user permissions | |
if ( ! current_user_can( 'edit_post', $post_id ) ) | |
return; | |
// Return if it's a post revision |
OlderNewer