Skip to content

Wordpress

Searching for ц functions

Run in site directory

grep '@[a-z,_,0-9]*(' ./ -r --include=*.php

Disable FTP

define('FS_METHOD', 'direct');

Change domain in DB

SELECT option_value from wp_options where option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_options SET option_value = 'NEW' WHERE option_name = 'home' OR option_name = 'siteurl';

DEBUG and logging

File: ./wp-content/debug.log

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
define('SAVEQUERIES', true);        

Generate sitemap.xmp without plugins

Add to /wp-includes/functions.php

add_action( "save_post", "eg_create_sitemap" );   
function eg_create_sitemap() {
    $postsForSitemap = get_posts( array(
        'numberposts' => -1,
        'orderby'     => 'modified',
        'post_type'   => array( 'post', 'page' ),
        'order'       => 'DESC'
    ) );
    $sitemap = '';
    $sitemap .= "\n" . '' . "\n";    
    foreach( $postsForSitemap as $post ) {
        setup_postdata( $post );   
        $postdate = explode( " ", $post->post_modified );   
        $sitemap .= "\t" . '' . "\n" .
            "\t\t" . '' . get_permalink( $post->ID ) . '' .
            "\n\t\t" . '' . $postdate[0] . '' .
            "\n\t\t" . 'monthly' .
            "\n\t" . '' . "\n";
    }     
    $sitemap .= '';     
    $fp = fopen( ABSPATH . "sitemap.xml", 'w' );
    fwrite( $fp, $sitemap );
    fclose( $fp );
}

Switch to maintenance mode

Create file .maintenance in root directory with content:

 $value ) {
        if ( stristr($cookie, 'wordpress_logged_in_') )
        $loggedin = true;
        }
        return $loggedin;
    }
    if ( !stristr($_SERVER['REQUEST_URI'], '/wp-admin/') && !stristr($_SERVER['REQUEST_URI'], '/wp-login.php') && !is_user_logged_in() ) $upgrading = time();
?>

Disable themes update

Case 1: Rename the theme folder Inside the theme folder in Style.css, correct the name/version of the theme. Case 2: File functions.php. Add to the end

// обновление тем отключаем
remove_action( 'load-update-core.php', 'wp_update_themes' );
add_filter( 'pre_site_transient_update_themes', '__return_null' );

Hide posts with passwords

in file: functions.php

function wpb_password_post_filter( $where = '' ) {
    if (!is_single() && !is_admin()) {
        $where .= " AND post_password = ''";
    }
    return $where;
}
add_filter( 'posts_where', 'wpb_password_post_filter' );

Create administrator

Create "mu-plugins" directory in "wp-content" Create a new file new_admin.php, with content bellow

add_action( 'init', function () {

  $username = 'USERNAME';
  $password = 'PASSWORR';
  $email_address = '[email protected]';
  if ( ! username_exists( $username ) ) {
    $user_id = wp_create_user( $username, $password, $email_address );
    $user = new WP_User( $user_id );
    $user->set_role( 'administrator' );
  }

} );

Login to the site with this USERNAME/PASSWORD. After login - delete "wp-content/mu-plugins"