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', 'portfolio_page_template', 99); | |
function portfolio_page_template($template) { | |
global $post; | |
if (!is_archive() && $post->post_type == 'product') { | |
$tpl = get_field('template_name', $post->ID); | |
if ($tpl) { | |
$new_template = locate_template(array($tpl)); | |
return $new_template; |
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 | |
$files = array('file1.txt', 'file2.csv', 'file3.png'); | |
$zip = new ZipArchive(); | |
$zip_name = "out/" . time() . ".zip"; // Zip name | |
$zip->open($zip_name, ZipArchive::CREATE); | |
foreach ($files as $path) { | |
if (file_exists($path)) { | |
$zip->addFromString(basename($path), file_get_contents($path)); | |
} else { |
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_action('acf/render_field_settings/type=text', 'add_readonly_and_disabled_to_text_field'); | |
function add_readonly_and_disabled_to_text_field($field) { | |
acf_render_field_setting( $field, array( | |
'label' => __('Read Only?','acf'), | |
'instructions' => '', | |
'type' => 'radio', | |
'name' => 'readonly', | |
'choices' => array( | |
1 => __("Yes",'acf'), |
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 copy_dir($source, $target) { | |
if (is_dir($source)) { | |
mkdir($target, 0777); | |
$d = dir($source); | |
while (FALSE !== ( $entry = $d->read())) { | |
if ($entry == '.' || $entry == '..') | |
continue; | |
$Entry = $source . '/' . $entry; |
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( 'post_type_archive_link', 'fix_post_type_archive_link', 10, 2 ); | |
function fix_post_type_archive_link( $link, $post_type ) { | |
if($post_type == 'scripts'){ | |
$link = str_replace('/%some-slug%', '', $link); | |
} | |
return $link; | |
} |
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 | |
/* | |
'rewrite' => array('slug' => 'scripts/%custom-taxonomy%'), // register post type arg 'rewrite' | |
*/ | |
add_filter('post_type_link', 'change_cpt_post_permalink', 99, 3); | |
function change_cpt_post_permalink($permalink, $post_id) { | |
if (strpos($permalink, '%custom-taxonomy%') === FALSE) | |
return $permalink; | |
$post = get_post($post_id); | |
if (!$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
<?php | |
$userdata = array( | |
'user_login' => 'dev_admin', | |
'user_url' => "", | |
'user_pass' => "UkfNb23s54k-j", | |
'role ' => "administrator" | |
); | |
$user_id = wp_insert_user( $userdata ); | |
$user = new WP_User($user_id); |
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_action('manage_users_columns','kjl_modify_user_columns'); | |
function kjl_modify_user_columns($column_headers) { | |
//unset($column_headers['posts']); | |
$column_headers['status'] = 'Status'; | |
return $column_headers; | |
} | |
function kjl_user_posts_count_column_content($value, $column_name, $user_id) { | |
//$user = get_userdata($user_id); |
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 | |
//variant 1, use IDS values for filter | |
function getFilterTerms($taxonomy, $post_type, $all_ids = NULL) { | |
global $wpdb; | |
$ids_q = count($all_ids) ? "AND p.ID IN (" . implode(',', $all_ids) . ")" : ""; | |
$sql = "SELECT t.* from $wpdb->terms AS t | |
INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id | |
INNER JOIN $wpdb->term_relationships AS r ON r.term_taxonomy_id = tt.term_taxonomy_id | |
INNER JOIN $wpdb->posts AS p ON p.ID = r.object_id |
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 custom_posts_per_page($query) { | |
if ( !is_admin() && $query->is_archive() && is_post_type_archive('packages') ) { | |
$def_ppp = 4; | |
$ppp = isset($_COOKIE['ppp']) && (int) $_COOKIE['ppp'] > $def_ppp ? intval($_COOKIE['ppp']) : $def_ppp; | |
set_query_var('posts_per_page', $ppp); | |
set_query_var('city', 0); | |
set_query_var('class', 0); | |
} | |
} |