Wednesday, August 11, 2021

Wordpress rename uploaded images based on the post_title

 https://stackoverflow.com/questions/63571688/wordpress-rename-uploaded-images-based-on-the-post-title


This code works with post types (posts, pages, products). Change filename and ads alt, title, caption and description meta to image.

But when its about attributes, categories keeps the filename and add it to alt, title, etc.

function file_renamer( $filename ) {
    $info = pathinfo( $filename );
    $ext  = empty( $info['extension'] ) ? '' : '.' . $info['extension'];
    $name = basename( $filename, $ext );


    if( $post_id = array_key_exists("post_id", $_POST) ? $_POST["post_id"] : null) {
        if($post = get_post($post_id)) {
            return $post->post_title . $ext;
        }
    }
    
    $my_image_title = $post;
    

    $file['name'] = $my_image_title  . - uniqid() . $ext; // uniqid method
    // $file['name'] = md5($name) . $ext; // md5 method
    // $file['name'] = base64_encode($name) . $ext; // base64 method

    return $filename;


  }
add_filter( 'sanitize_file_name', 'file_renamer', 10, 1 );

/* Automatically set the image Title, Alt-Text, Caption & Description upon upload
--------------------------------------------------------------------------------------*/
add_action( 'add_attachment', 'my_set_image_meta_upon_image_upload' );
function my_set_image_meta_upon_image_upload( $post_ID ) {

    // Check if uploaded file is an image, else do nothing

    if ( wp_attachment_is_image( $post_ID ) ) {
        
       // Get the parent post ID, if there is one

        if( isset($_REQUEST['post_id']) ) {
          $post_id = $_REQUEST['post_id'];
          } else {
          $post_id = false;
          }


            if ($post_id != false) {
        $my_image_title = get_the_title($post_id);
            } else {
        $my_image_title = get_post( $post_ID )->post_title;
            }
        // Sanitize the title:  remove hyphens, underscores & extra spaces:
        $my_image_title = preg_replace( '%\s*[-_\s]+\s*%', ' ',  $my_image_title );

        // Sanitize the title:  capitalize first letter of every word (other letters lower case):
        $my_image_title = ucwords( strtolower( $my_image_title ) );

        // Create an array with the image meta (Title, Caption, Description) to be updated
        // Note:  comment out the Excerpt/Caption or Content/Description lines if not needed
        $my_image_meta = array(
            'ID'        => $post_ID,            // Specify the image (ID) to be updated
            'post_title'    => $my_image_title,     // Set image Title to sanitized title
            'post_excerpt'  => $my_image_title,     // Set image Caption (Excerpt) to sanitized title
            'post_content'  => $my_image_title,     // Set image Description (Content) to sanitized title
        );

        // Set the image Alt-Text
        update_post_meta( $post_ID, '_wp_attachment_image_alt', $my_image_title );

        // Set the image meta (e.g. Title, Excerpt, Content)
        wp_update_post( $my_image_meta );

    } 
}

I was try to find a way to take the title from attribute or category name to add it to metas but no luck. If you have any idea i do appreciate it. I'm not so good to WordPress codex.

Hope this code help.

Saturday, July 17, 2021

Solution for WordPress WP-Options Issue – Database Upgrade Required

 Solution for WordPress WP-Options Issue – Database Upgrade Required

If your blogging platform is WordPress and your webpage is redirecting to a page where you are getting a message as “Database upgrade required” even if your wordpress and database is up to date then read the instruction provided below to resolve the issue.

Problem Scenario: Webpage URL redirected to a WordPress page where the instruction appears as “Database upgrade required” or Installation Window for WordPress appears even the wordpress is already installed and up to date. The message appearing is that  “your wordpress database is out-of-date, and must be upgraded before you can continue”.

database upgrade 1

Solution:

This is a common problem with WordPress and you don’t need to be afraid of data loss. If you will browse your wordpress database, you will find that all your posts, pages, plug-in, themes are available at their places and nothing go deleted. This is a problem related with a table named as “WP_Options” of WordPress database. The wp_options table contains some general information related to the blog which appears in the setting tab of admin. It also contains some information about the plug-in installed for the blog.

There are mainly two reasons for this issue in your WordPress blog.

  1. The Option Name db_version in WP_Options table is not equal to the field wp_db_version of version.php. You can have a look at the Version.php located under wp-include folder of your wordpress blog.
  2. The Option Name “siteurl” in WP_Options table is not populated properly.

Follow the below mentioned steps to resolve the issue-:

  • Open the phpMyadmin from your blog’s host to have a look into the WordPress database
  • Browse the table WP_Options to see the Option_Value for the Option_Name db_version. For WordPress version 2.7.1, the db_version should be equal to 9872. Other db_versions are as below,
  • WordPress Versiondb_version
    2.912329
    2.8.110850
    2.7.19872
    2.79872
    2.6.58204
    2.6.38204
    2.6.28204
    2.6.18204
    2.68201
    2.5.17796
    2.57558
    2.3.36124
    2.3.26124
    2.3.16124
    2.36124
  • Open the PHP file version.php which is located in wp-include folder of your wordpress blog, and check the field $wp_db_version. It should be equal to the db_version of WP_Options table.
  • Below is the screenshot of version.php file from wp-include where you can see the $wp_db_version field as 9872 which refers to the wordpress version as 2.7.1
    5-17-2009 1-23-27 AM
    It should be equal to the db_version populated in WP_Options table. Here is the screenshot from the same table,
    5-17-2009 1-22-17 AM
  • If the fields are having same value, then the issue is with the Option_Name “siteurl” of WP_Options table. Check the value for the same. It should have the URL of your blog’s home page. Update the Option_Value of this field, and reload the home page of your blog. Here is the screenshot of WP_Options table showing the option_name “siteurl”,

siteurl

In case the problem is still there for your blog, then “check all” the  tables from the wordpress database and  select “Check Table” from the option list. Once done, then try to reload the blog’s page. Here is the screenshot for “Check Table” option,

phpmyadmin1

I hope that the problem related with your wordpress blog resolved by this time or you will have to restore the WP_Options table from previous backups. Please let us know your feedback thru comments section.

Sanjeev Mishra is a professional blogger and an Internet Marketing Consultant based in India. He has built the Internet Techies to provide you updates in technology and web application area.

Friday, March 26, 2021

Cara Install Manual IonCube Loader di OpenLiteSpeed CyberPanel

 https://hosteko.com/kb/cara-install-manual-ioncube-loader-di-openlitespeed-cyberpanel/

cara ceknya jika sdh dipasang ; https://www.smackcoders.com/blog/how-to-install-ioncube-loaders-simple-steps-for-various-hosting-types.html

Ioncube Loader di butuhkan untuk website-website yang menggunakan enkripsi menggunakan Ioncube Loader. biasanya script di encripsi, untuk melindungi dari pembajakan ataupun orang yang sengaja ingin mencari celah keamanan dari sebuah script. Berikut ini, adalah Cara Install Manual IonCube Loader di OpenLiteSpeed CyberPanel:

  • Silahkan login ke root server anda
  • Jalankan perintah berikut untuk mengunduh paket ioncube
wget https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.zip
unzip ioncube_loaders_lin_x86-64.zip
  • Copy ekstensi ke masing-masing php

untuk php 5.6

cp ioncube/ioncube_loader_lin_5.6.so /usr/local/lsws/lsphp56/lib64/php/modules/ioncube_loader_lin_5.6.so

untuk php 7.0

cp ioncube/ioncube_loader_lin_7.0.so /usr/local/lsws/lsphp70/lib64/php/modules/ioncube_loader_lin_7.0.so

untuk php 7.1

cp ioncube/ioncube_loader_lin_7.1.so /usr/local/lsws/lsphp71/lib64/php/modules/ioncube_loader_lin_7.1.so

untuk php 7.2

cp ioncube/ioncube_loader_lin_7.2.so /usr/local/lsws/lsphp72/lib64/php/modules/ioncube_loader_lin_7.2.so

untuk php 7.3

cp ioncube/ioncube_loader_lin_7.3.so /usr/local/lsws/lsphp73/lib64/php/modules/ioncube_loader_lin_7.3.so

untuk php 7.4

cp ioncube/ioncube_loader_lin_7.4.so /usr/local/lsws/lsphp74/lib64/php/modules/ioncube_loader_lin_7.4.so

  • Tambahkan konfigurasi ke PHP.ini

untuk php 5.6

echo "zend_extension = /usr/local/lsws/lsphp56/lib64/php/modules/ioncube_loader_lin_5.6.so" \
    > '/usr/local/lsws/lsphp56/etc/php.d/00-ioncube.ini'

untuk php 7.0

echo "zend_extension = /usr/local/lsws/lsphp70/lib64/php/modules/ioncube_loader_lin_7.0.so" \
    > '/usr/local/lsws/lsphp70/etc/php.d/00-ioncube.ini'

untuk php 7.1

echo "zend_extension = /usr/local/lsws/lsphp71/lib64/php/modules/ioncube_loader_lin_7.1.so" \
    > '/usr/local/lsws/lsphp71/etc/php.d/00-ioncube.ini'

untuk php 7.2

echo "zend_extension = /usr/local/lsws/lsphp72/lib64/php/modules/ioncube_loader_lin_7.2.so" \
    > '/usr/local/lsws/lsphp72/etc/php.d/00-ioncube.ini'

untuk php 7.3

echo "zend_extension = /usr/local/lsws/lsphp73/lib64/php/modules/ioncube_loader_lin_7.3.so" \
    > '/usr/local/lsws/lsphp73/etc/php.d/00-ioncube.ini'

untuk php 7.4

echo "zend_extension = /usr/local/lsws/lsphp74/lib64/php/modules/ioncube_loader_lin_7.4.so" \
    > '/usr/local/lsws/lsphp74/etc/php.d/00-ioncube.ini'
    • Restart Openlitespeed
    systemctl restart lsws

    ==========
    Merubah Versi PHP untuk web WP 
    jika di WP versi PHP nya misal masih 7.1 sedangkan yg diminta 7.4, maka ubah dulu di https://serverdfsf.server.com:8090/websites/websitesdfs.com/member.websitesdfs.com 
    kemudian lakukan reboot dari terminal. maka setelah web online, WP akan berubah PHP nya 

    Thursday, December 10, 2020

    EXPRESS.JS dan Node.js di cyberpanel

     Ini yg sudah saya coba berhasil

    SETUP EXPRESS.JS APPLICATION ON CYBERPANEL/OPENLITESPEED


    Ini yang saya coba belum berhasil:

    Node.js Apps with OpenLiteSpeed

    https://www.rumahweb.com/journal/cara-mudah-deploy-node-js-di-developer-hosting/


    https://github.com/jesseokeya/Forbes400

    https://forbes400.herokuapp.com/

    https://forbes400.herokuapp.com/api/forbes400/industries/technology



    Ini Belum saya baca:

    Wednesday, August 26, 2020

    Setting VPS untuk hosting Wordpress Supercepat dg OpenLiteSpeed

    https://openlitespeed.org/kb/cyberpanel-control-panel-for-openlitespeed/


    https://cyberpanel.net/docs/installing-cyberpanel/


    jika permalink bermaslah, maka perlu update grace restart openlitespeed, untuk akalinya buka  

    ubah permalink di wordpress

    kemudian masuk ke cyberpanel https://alamatip:8090/websites/websitenyaapa.com

    kemudian pilih rewrite rules. setelah itu save..

    maka setelah itu akan bisa 

    ==========

    untuk setting email..

    1. pastikan NS domain diarahkan keserver ini secara langsung (bukan cloudflare(jika pakai cloudflare, pastikan DNS only settingnya) maupun private NS) dengan merubah NS menjadi :

    NS91.webserver.net

    NS92.webserver.net


    2. create website.. centang ssl email dkim opendir. pastikan ketika dibuka mail.namadomain.com sudah menjadi ssl.

    3. buat email info@namadomain.com

    4. setting di gmail

    ------------

    Jika cara diatas tidak bisa, karena NS tidak mau diarahkan langsung ke server. tetapi bisanya melalui cloudflare. berikut ini caranya:

    1. arahkan NS domain ke cloudflare, tetapi pause cloudflarenya. adapun setting DNS nya di cloudflare adalah sbb:


    2. di sever litespeed keluarkan ssl untuk mail server mail.namadomain.com


    3. Sekarang cobalah untuk add email tsb di pop3 gmail. jika berhasil, maka email akan bekerja dengan baik.


    4. setting SMTP gmail



    5. tes kirim terima email..

    6. aktifkan kembali cloudflare


    untuk melengkapi setting email :

    https://blog.cyberpanel.net/2018/01/28/how-to-setup-spf-dkim-and-dmarc-inside-cyberpanel-manually/


    https://www.quicksprout.com/email-deliverability/

    ======

    5 Des 2020

    Masalah:

    Bebeberapa hari ini menyelesaikan masalah, yang saya alamai:

    a. ketika buka web terminal https://server.domainkita.com:8090/Terminal/ tidak bisa kebuka malah mengarah ke https://server.domainkita.com:8090

    b. Wordpress ketika mau pasang plugin/update plugin minta login FTP

    c. diterminal terkadang muncul pesan "No space left on device (28)"

    Penyebabnya :

    Adalah inode yg 100%, jika di cek dengan df -i  kelihatan bahwa inode nya sudah 100%:


    padahal spacenya masih 14%, tetapi karena filenya banyak sehingga inodenya 100%.


    Solusinya :

    a. Hapus file log dan cachedata https://cyberpersons.com/2020/01/25/solved-disk-quota-exceeded/   https://www.beginnor.com/disk-space-usage-cyberpanel/

    Delete Large log files in lsws/logs

    rm -rf /usr/local/lsws/logs/*

    Remove OpenLiteSpeed Cache folder

    rm -rf /usr/local/lsws/cachedata


    b. Hapus file cache atau semacamnya yg tidak beguna dari disk

    How to fix “No space left on device (28)” in Rsync, PHP, MySQL, Magento, WordPress and more

    Gunakan cara ini untuk cek dimana file" yang menimbulkan inode menjadi banyak.. 

    How To Count Inode Usage In Linux?

    df -i
    untuk cek inode..


    kemudian saya pindah ke /home

    dan ketikkan perintah :
    find . -printf "%h\n" | cut -d/ -f-2 | sort | uniq -c | sort -rn

    untuk cek mana" yang banyak filenya.. kemudian telusuri ke direktori" yang banyak file tdk berguna utk dihapus.


    setelah itu semua masalah tersebut akan teratasi Biidznillah

    --

    Solusi lebih Baik

    Ternyata file terbanyaknya  karena session php... /var/lib/php/sessions


    Solusinya : 

    Pakai script yg di run di cronjob : http://www.queryadmin.com/1634/bash-script-delete-php-session-files-free-inodes/

    A quick command to delete all sess_* files on /var/lib/php/sessions is this: Gunakan ini.. ini yang benar.. tidak ada huruf s nya.. /var/lib/php/session

    update : 15-Januari-2024 lokasi session php nya adalah :  /var/lib/lsphp/session 


    find /var/lib/lsphp/session -type f -cmin +24 -name "sess_*" -exec rm -f {} \;

    Inode untuk sessios di sever saya sudah hampir 13 juta.. untuk menghapus dengan cara diatas ternyata berjam".. setelah eksekusi perintah tersebut.. saya biarkan berjam".. dan hasilnya inode yg bebas semakin meningkat.. ini tampilan setelah menjalankan beberapa jam.. inode yg belum dipakai 51%


    Setelah mungkin sekitar 10 jam lebih inode yang dipakai hampir 13 jutaan.. sekarang tinggal sedikit.. yang dipakai masih 5% ternyata..




     

     

    saya tahu alamat tersebut dari ini https://www.digitalocean.com/community/questions/how-to-properly-delete-php-sessions-files-to-free-inodes

    untuk edit cronjob menggunakan terminal.. ketik saja : crontab -e

    edit di terminalnya menggunakan vi namafilenya..   Ini perintah" nya : https://help.dreamhost.com/hc/en-us/articles/115006413028-Creating-and-editing-a-file-via-SSH

    Kita lihat bagaimana hasilnya ya.. semoga berhasil


    bisa baca":

    https://www.getpagespeed.com/server-setup/php/cleanup-php-sessions-like-a-pro

    https://stackoverflow.com/questions/654310/cleanup-php-session-files

    https://wpjohnny.com/cyberpanel-cheatsheet/

    https://www.cyberhosting.org/category/cyberpanel/

    ===========

    Cara Mudah Upgrade Cyberpanel :

    a. Sebelum ini lakukan snapshoot dulu..

    Sebelum melakukan Perubahan besar di server.. Saya anjurkan buat snapshot dulu di penyedia VPS nya.. nanti apa bila terjadi hal" yang sulit diprediksi, kita bisa kembalikan kondisi seperti saat kita buat snapshoot.


    b. gunakan cara mudah berikut ini  Upgrading CyberPanel   

    ===================

    https://forums.cyberpanel.net/discussion/171/some-donts-after-installing-cyberpanel


    [Tutorial] How to fix permission and user/group problem on CyberPanel.

    https://forums.cyberpanel.net/discussion/137/tutorial-how-to-fix-permission-and-user-group-problem-on-cyberpanel#latest

    =====

    Sebelum melakukan Perubahan besar di server.. Saya anjurkan buat snapshot dulu di penyedia VPS nya.. nanti apa bila terjadi hal" yang sulit diprediksi, kita bisa kembalikan kondisi seperti saat kita buat snapshoot.



    Ini kasus yg saya alami, tidak bisa masuk cyberpanel dan muncul seperti itu..

    Setelah dicari" tidak ketemu masalahnya.. akhirnya saya pencel tombol roolback..

    setelah beberapa saat.. server kembali normal..

     

    ==========

    Terkadang web terminal muncul begini : Error connecting to backend or connection closed.

    jangan panik.. 

    pemecahannya ada disini https://cyberpanel.net/docs/web-terminal/

    caranya pastikan https://server91.namdomain.com:8090 sudah aktif ssl nya.. jika belum aktifkan dengan cara https://cyberpanel.net/docs/2-cyberpanel-on-ssl/

    setelah aktif ssl nya reboot ssh server 


    ------------

    Terkadang https://server.domainkita.com:8090/Terminal/ tidak bisa kebuka malah mengarah ke https://server.domainkita.com:8090/base  cara berikut ini bisa digunakan

    Terkadang wordpress ketika mau pasang plugin/update plugin minta login FTP.., cara berikut ini bisa digunakan, dan WP bisa normal lagi 

    setelah berjalan beberapa waktu space vps akan membengkak.. atasi dengan cara ini

    https://www.beginnor.com/disk-space-usage-cyberpanel/

    Delete Large log files in lsws/logs

    rm -rf /usr/local/lsws/logs/*


    You can delete log files in a cron job. Login as root via SSH. Open crontab

    crontab -e

    Add

    0 0 * * * find /usr/local/lsws/logs/ -name ‘*log.*’ -delete


    saya coba ubah petiknya menjadi :  (masih dicoba semoga berhasil)
    0 0 * * * find /usr/local/lsws/logs/ -name '*log.*' -delete

    Remove OpenLiteSpeed Cache folder

    rm -rf /usr/local/lsws/cachedata


    https://openlitespeed.org/kb/litespeed-cache-on-openlitespeed-without-plugins/  (masih dicoba semoga berhasil)

    Linux Command via Cron

    A cron job should be set to clear out old cache files that are past the set Time To Live (TTL).

    To do this, you should run the crontab either as the root user or as the cache owner for self-management.

    crontab -e

    The virtual host cache root directory is normally located in /usr/local/lsws/cachedata

    */10 * * * * root find /virtualhost/cache/root/directory/ -type f -mmin +8 -delete 2>/dev/null

    */10 * * * * root find /virtualhost/cache/root/directory/ -type f -mmin +8 -delete 2>/dev/null

    Note: This cron job deletes cached files that are more than 8 minutes old every 10 minutes. Since the cache TTL is set at 120 seconds (2 minutes), it is safe to delete these files as they are way past their TTL.


    untuk setting waktunya bisa cek" https://crontab.guru/


    saya kemudian melakukan update di web terminal (jangan gunakan terminal ssh karena sy gagal ) dengan cara berikut.. akhirnya semuanya berjalan normal...

    https://cyberpanel.net/docs/upgrading-cyberpanel/

    -----------

    untuk melacakdirekoti mana yang menghabiskan disk..

    masuk ke home

    kemudian lakukakn perintah ini :  du -hs * | sort -rh | head -20

    tunggu biasanya butuh waktu lama

    https://cyberpersons.com/2020/01/25/solved-disk-quota-exceeded/




    ---------

    terkadang kita kita membutuhkan untuk menghapus file dalam jumlah banyak.. cara yg sangat cepat setelah masuk direktori yang akan dikosongkan. berikan perinth ini maka direksori tsb akan kosong dalam beberpa saat.. 


    time perl -e 'for(<*>){((stat)[9]<(unlink))}'


    https://www.slashroot.in/which-is-the-fastest-method-to-delete-files-in-linux

    ----------


    kadang kita tidak bisa upload.. gunakan cara ini utk setting masing" domain :

    https://cyberpanel.net/docs/5-change-upload-limit-for-filemanager/

    php_value upload_max_filesize "200M"

    php_value post_max_size "250M"


    jika untuk semua https://server.namadomain.com:8090/managephp/editPHPConfigs

    pilih PHP versinya.. kemudian save

    -------

    ini cara meningkatkan upload phpmyadmin

    https://cyberpanel.net/docs/4-change-upload-limit-for-phpmyadmin/


    penting banget run 

    systemctl restart lscpd
    • di terminal.. tanpa ini tidak akan berefek

    ------------

    terkadang terjadi sesuatu, sehingga seluruh website tidak bisa diakses.. silahkan cek Server Status kemudian service status. biasanya openlitespeed tidak nyla bahkan di restart juga tetap tidak nyala..

    cara yang saya gunakan.. buka terminal..  kemudian lakukan perintah :

    yum -y update

    tunggu sampai benar" selesai.. jangan terburu" menutup terminal, meskipun ada pesan warning.. tetap tunggu sampai complete..

    setelah itu cek cek Server Status kemudian service status. biasanya sudah normal..

    https://forums.cyberpanel.net/discussion/3668/open-litespeed-stops-automatically

    ==================

    4 des 2020

    karena masih m

    https://cyberpanel.net/docs/upgrading-cyberpanel/


    ------------


    https://www.cyberhosting.org/category/cyberpanel/

     https://www.vpsserver.com/community/tutorials/4002/how-to-install-openlitespeed-with-php-7-3-and-mariadb-10-4-on-centos-7/



    https://openlitespeed.org/kb/setup-ols-with-more-than-one-php-build/



    https://letswp.io/host-multiple-sites-with-openlitespeed-vhost-templates/