Welcome to ManageWP.org

Register to share, discuss and vote for the best WordPress stories every day, find new ideas and inspiration for your business and network with other members of the WordPress community. Join the #1 WordPress news community!

×

2 min read Jakub Mikita
Development | btb.works | 10 days ago

How to run PHPUnit with a database via GitHub Actions

As of March 2020, GitHub seems to remove the default MySQL installation from its ubuntu-latest container. Now it’s required to set up the database service in order to use it.

How to run PHPUnit with a database via GitHub Actions

Development | btb.works | 10 days ago

As of March 2020, GitHub seems to remove the default MySQL installation from its ubuntu-latest container. Now it’s required to set up the database service in order to use it. Because we at BracketSpace are testing our WordPress plugins with PHPUnit it’s required to run them along with the database.
Let me show you how to set up the GitHub workflow file to use multiple PHP versions.
name: Test

on: push

jobs:
phpunit:
name: PHPUnit
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.0', '7.1', '7.2', '7.3', '7.4']
services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: wordpress_test
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Composer dependencies
run: composer install -o --no-dev --no-progress
- name: Setup PHP
uses: shivammathur/setup-php@v1
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo,

1 min read Jakub Mikita
Development | btb.works | Feb. 21, 2020

Close unclosed HTML tags in PHP

Simple WordPress PHP function which closes unclosed HTML tags. Can fix broken HTML and allow safe output without any layout breaks.

Close unclosed HTML tags in PHP

Development | btb.works | Feb. 21, 2020

Recently I stumped upon a handy WordPress function which closes HTML tags. The function name is force_balance_tags().
Taking as an example unclosed list items:
echo force_balance_tags( '<ul>
<li>this
<li>is
<li>a
<li>list
</ul>' );
It will produce something like this:
<ul>
<li>this
</li><li>is
</li><li>a
</li><li>list
</li></ul>

3 min read Jakub Mikita
Development | btb.works | Jan. 30, 2020

How to fix a broken serialization

Fixing database serialization issues and recovering corrupted serialized string with a simple script

How to fix a broken serialization

Development | btb.works | Jan. 30, 2020

Serialization is a way to store multidimensional data as a string. It’s commonly used in the WordPress database, because of the architecture of the tables. When it breaks (for various reasons) it’s a disaster. But not with our handy-dandy scripts. Fixing a database dump with broken serialization
Steps are simple:
Create the database dump (you should have a .sql file)
Run the script: `./fix-serialization.php database.sql`
Upload the .sql file back to the server
The script has been created by an awesome WordPress developer – Wojtek Szałkiewicz.
Recovering the corrupted serialized array
If you have a variable with a string which cannot be unserialized, try to use the below function:
/**
* Extract what remains from an unintentionally truncated serialized string
*
* @param string The serialized array
*/
public function repairSerializedArray($serialized)
{
$tmp = preg_replace('/^a:\d+:\{/', '', $serialized);
return $this->repairSerializedArray_R($tmp); // operates on and whittles down the actual argument
}

/**
* The recursive function that does all of the heavy lifing. Do not call directly.

* @param string The broken serialzized array
* @return string Returns

2 min read Jakub Mikita
Development | btb.works | Jan. 20, 2020

How to access the WordPress admin without password

Logging in as an administrator, the easy way with a short snippet. Site files access required.

How to access the WordPress admin without password

Development | btb.works | Jan. 20, 2020

How many times you forgot the password or login to the website you managing. I forgot a lot of times, mostly because I didn’t save the password in the Password manager. Or I don’t get the credentials from my client. Luckily, there’s an easy way to login to the WordPress admin panel, having only the file access. The short answer is: use the wp_set_auth_cookie() function! It will save a session cookie for the provided user ID. Session cookie means you are logged in.
Here’s the snippet I’ve been using for a long time if I don’t know the user ID (plot twist – it’s not always 1).
add_action( 'send_headers', function() {
if ( ! isset( $_GET['secure-hash-295g785j46v-change-this'] )