Tag Archives: function

PHP random sentence spinning function

recycle_phpIn this article I'm presenting my solution for a very common PHP developer job interview task where it is required to create a random sentence spinning function. Input of this function is a PHP string that employs syntax telling our code where's the randomness and what are the possible substrings for each section of randomness. Basically it is required to create PHP code that's able to process strings like the following:

$string = '{Please|Just} make this {cool|awesome|random} test sentence {rotate {quickly|fast} and random|spin and be random}';

As you can probably guess the input sentence uses braces to declare sections of randomness and the pipe character to delimit substrings that should be used randomly inside their sections. Code also must be able to process nested sections of randomness.

Continue reading

PHP function for adding admin menu separator inside WordPress backend

WordPress admin menu separatorOften your WordPress plugin or theme adds admin submenu inside WordPress admin interface using add_menu_page() functions on admin_menu hook or using WordPress Settings API. When your code adds multiple submenu items wouldn't it be nice to create section on admin menu to reduce clutter? Unfortunately WordPress currently doesn't support adding admin menu separators so you must do it manually by filtering $menu global variable. Here's function for doing that together with an example that should demonstrate it's use.

Continue reading