Last active
January 12, 2018 04:20
-
-
Save tcelestino/7335076 to your computer and use it in GitHub Desktop.
wordpress snippets
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
/* update table wp_post_meta */ | |
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, '/wp/', '/') WHERE 1=1; | |
/* update table wp_post */ | |
UPDATE wp_posts SET post_content = REPLACE(post_content, '/wp/', '/') WHERE 1=1 | |
UPDATE wp_posts SET guid = REPLACE(guid, '/wp/', '/') WHERE 1=1 |
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 | |
$taxonomies = get_object_taxonomies( (object) array( 'post_type' => 'companies' ) ); | |
foreach( $taxonomies as $taxonomy ) : | |
// Gets every "category" (term) in this taxonomy to get the respective posts | |
$terms = get_terms( $taxonomy ); | |
foreach( $terms as $term ) : | |
$args = array( | |
'taxonomy' => $taxonomy, | |
'term' => 'televisao', | |
'posts_per_page' => 2 | |
); | |
$posts = new WP_Query($args); | |
if( $posts->have_posts() ): while( $posts->have_posts() ) : $posts->the_post(); | |
var_dump($posts); | |
endwhile; endif; | |
endforeach; | |
endforeach;remove | |
wp_reset_query(); |
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 | |
// redirect to page with get url | |
if(isset($_GET["v2"])) : | |
include(dirname(__FILE__)."/v2/index.php"); | |
exit; | |
endif; | |
get_header(); |
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 wp_usermeta where user_id={change_id_user} and meta_key='wp_capabilities'; | |
#change role to | |
a:1:{s:13:"administrator";b:1;} |
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 | |
define( 'AUTOMATIC_UPDATER_DISABLED', true ); // disbale update version 3.7. Add this on file wp-config.php | |
// this define wp-home and site-url without config on admin | |
define('WP_HOME', 'http://www.example.com'); | |
define('WP_SITEURL', 'http://www.example.com'); |
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 | |
// create login | |
function auto_login( $user ) { | |
$username = $user; | |
if ( !is_user_logged_in() ) { | |
$user = get_userdatabylogin( $username ); | |
$user_id = $user->ID; | |
wp_set_current_user( $user_id, $user_login ); | |
wp_set_auth_cookie( $user_id ); | |
do_action( 'wp_login', $user_login ); | |
} | |
} | |
// customize wp_archive | |
add_filter( 'getarchives_where' , 'ucc_getarchives_where_filter' , 10 , 2 ); | |
function getarchives_where_filter( $where , $r ) { | |
$args = array( 'public' => true , '_builtin' => false ); | |
$output = 'names'; $operator = 'and'; | |
$post_types = get_post_types( $args , $output , $operator ); | |
$post_types = array_merge( $post_types , array( 'post','CUSTOM_POST_TYPE_NAME' ) ); | |
$post_types = "'" . implode( "' , '" , $post_types ) . "'"; | |
return str_replace( "post_type = 'post'" , "post_type IN ( $post_types )" , $where ); | |
} | |
// this update table update_option. Obs: comment this line when deploy site | |
add_action('init', 'update_urls'); | |
function update_urls() { | |
update_option('siteurl','http://example.com'); | |
update_option('home','http://example.com'); | |
} | |
remove_action( 'wp_head', 'rsd_link' ); | |
remove_action( 'wp_head', 'wlwmanifest_link' ); | |
remove_action( 'wp_head', 'wp_generator' ); | |
remove_action( 'wp_head', 'start_post_rel_link' ); | |
remove_action( 'wp_head', 'index_rel_link' ); | |
remove_action( 'wp_head', 'adjacent_posts_rel_link' ); | |
remove_action( 'wp_head', 'wp_shortlink_wp_head' ); | |
// count post most view | |
function mostViewPosts($postID) { | |
$count_key = '_post_views_count'; | |
$count = get_post_meta($postID, $count_key, true); | |
if ($count=='') { | |
$count = 0; | |
delete_post_meta($postID, $count_key); | |
add_post_meta($postID, $count_key, '0'); | |
} else { | |
$count++; | |
update_post_meta($postID, $count_key, $count); | |
} | |
} | |
// add class first and last item menu | |
add_filter('wp_nav_menu_objects', 'addLastClass'); | |
function addLastClass($items) { | |
$items[1]->classes[] = 'is-first'; | |
$items[count($items)]->classes[] = 'is-last'; | |
return $items; | |
} | |
function removeRules($rule = "") { | |
$wp_roles = new WP_Roles(); | |
$wp_roles->remove_role($rule); | |
} | |
add_filter('intermediate_image_sizes_advanced', 'remove_default_image_sizes'); | |
function remove_default_image_sizes( $sizes) { | |
unset( $sizes['thumbnail']); | |
unset( $sizes['medium']); | |
unset( $sizes['large']); | |
return $sizes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment