Skip to content

Instantly share code, notes, and snippets.

View dgoze's full-sized avatar
💭
I may be slow to respond.

Daniel dgoze

💭
I may be slow to respond.
View GitHub Profile
<?php
/*
* 1. Go to Settings > Permalinks and select any page as home page
* Then use the following code
*
* You can add those codes in your functions.php in the theme, if you think your theme won’t be changed.
* Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'.
* If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that,
* give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins,
* so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.
@dgoze
dgoze / Code.php
Created November 19, 2017 00:14 — forked from bappi-d-great/Code.php
Show posts based on user preference in wordpress
<?php
add_action( 'show_user_profile', 'extra_fields' );
add_action( 'edit_user_profile', 'extra_fields' );
add_action( 'personal_options_update', 'save_fields' );
add_action( 'edit_user_profile_update', 'save_fields' );
add_action( 'pre_get_posts', 'exclude_category' );
function extra_fields($user) {
$pref_cat = explode( ',', get_user_meta( $user->ID, 'pref_cat', true ) );
@dgoze
dgoze / searchreplacedb2.php
Created November 20, 2017 03:04 — forked from Fabax/searchreplacedb2.php
Wordpress : replace
<?php
/**
*
* Safe Search and Replace on Database with Serialized Data v2.0.1
*
* This script is to solve the problem of doing database search and replace when
* developers have only gone and used the non-relational concept of serializing
* PHP arrays into single database columns. It will search for all matching
* data on the database and change it, even if it's within a serialized PHP
* array.
@dgoze
dgoze / wordpress-missing-functions.php
Created November 20, 2017 03:27 — forked from daggerhart/wordpress-missing-functions.php
WordPress functions that I tend to write often
<?php
/**
* Get a WP_Post object by its slug ( post_name )
*
* @param $post_name
*
* @return WP_Post|null
*/
function get_post_by_slug( $post_name ) {
@dgoze
dgoze / bulk_delete_posts.php
Last active September 12, 2019 23:07 — forked from sabrina-zeidan/bulk_delete_posts.php
Bulk delete all posts
function bulk_delete_posts(){
$args = array( 'post_type' =>'post', 'posts_per_page' => -1, 'post_status' => 'any', 'fields' =>'ids');
$books = get_posts( $args );
foreach ($posts as $post) {
wp_delete_post( $post, true);
}
}
add_action( 'wp_head', 'bulk_delete_posts' );
@dgoze
dgoze / bulk_update_acf.php
Created December 2, 2017 19:40 — forked from sabrina-zeidan/bulk_update_acf.php
Get posts by meta value of Advanced Custom Filed using meta_query and update the field value [Wordpress]
function update_cover_image() {
$getposts = get_posts( array(
'numberposts' => -1,
'post_type' => 'post',
'post_status' => 'publish',
'fields' => 'ids',
'meta_query' => array(
array(
'key' => 'cover_image',
'compare' => 'LIKE',
@dgoze
dgoze / bulk_delete_comments.php
Created December 2, 2017 19:41 — forked from sabrina-zeidan/bulk_delete_comments.php
Bulk delete all comments [Wordpress]
function bulk_delete_comments(){
$args = array('fields' => 'ids','number' => '','status' => 'all');
$comments = get_comments( $args );
foreach ($comments as $comment) {
wp_delete_comment( $comment, true);
}
}
add_action( 'wp_head', 'bulk_delete_comments' );
@dgoze
dgoze / Related Posts Shortcode
Created December 2, 2017 19:42 — forked from Kenshino/Related Posts Shortcode
Related Posts Shortcode
@dgoze
dgoze / functions.php
Created December 4, 2017 02:04 — forked from lukecav/functions.php
Add Gravity Forms capabilities
* Add Gravity Forms capabilities
*/
add_filter('user_has_cap',
function( $caps ){
if (! empty( $caps['edit_pages'] ) ) { // user has edit capabilities
$caps['gravityforms_delete_entries'] = true;
$caps['gravityforms_edit_entries'] = true;
$caps['gravityforms_edit_entry_notes'] = true;
$caps['gravityforms_view_entries'] = true;
$caps['gravityforms_view_entry_notes'] = true;
@dgoze
dgoze / gforms-encrypt.php
Created December 4, 2017 02:37 — forked from jboullion/gforms-encrypt.php
Gravity Forms Description
//https://www.gravityhelp.com/documentation/article/gform_save_field_value/
add_filter( 'gform_save_field_value', 'jb_encrypt_value', 10, 4 );
function jb_encrypt_value( $value, $lead, $field, $form ) {
if($field->cssClass == 'secure'){
$encrypted = GFCommon::encrypt( $value );
return $encrypted;
}
return $value;