Tag: php

  • WooCommerce products filter by tags within admin

    Need the ability to filter the WooCommerce products list within admin by tags? Snippet of code below is for you. This concept can be edited for other purposes.

    This can be easily changed to work in different scenarios.

    Found this snippet on the following website.

    https://businessbloomer.com/woocommerce-display-custom-filters-wp-dashboard-products/


  • WordPress remove Yoast SEO post filters

    Yoast SEO is a great SEO tool, I install it on most of the websites I build, but somes times I just dont need or want the filters it adds at the top of the admin posts pages. The most annoying one is when it adds it to products on a WooCommerce store.

    Below snippet will remove the Yoast SEO filters from admin.

    This could be upgraded for future use, for example only remove fields on WooCommerce product lists.

  • Fix for WooCommerce schema data missing brand and mpn

    Fix for WooCommerce schema data missing brand and mpn

    UPDATED 25/10/2021 to comply with latest google changes.

    Today I came across and issue where Google Search Console was complaning products “brand” and “mpn” where missing from the products schema / rich snippets data. You can checking using the rich snippet testing tool by Google found here.

    https://search.google.com/structured-data/testing-tool

    I fixed my issue by adding a WordPress filter using the “woocommerce_structured_data_product” filter option. This allows you to add new data to the already generated WooCommerce data.

    This is an example. You will need to change for your implementation.

  • Laravel, time zones and carbon

    Laravel defaults to storing all dates in UTC format, this is highly recommended as UTC time never changes unlike other time zones which have daylight savings. It is best practice to store and read dates in UTC, and then convert UTC to your required time zone for the user interface.

    Great article below of a good way to implement time zones using Carbon within your Laravel app.

    https://andrew.cool/blog/49/Easy-timezones-in-Laravel-with-Carbon

  • Easy mobile browser detection for several major languages and web servers

    All app’s and websites these days need to work for several devices including desktop, tablets and mobiles. It’s not always simple detecting the type of device being used and it can sometimes be tedious adding support to your app for something which seems very simple.

    Does your chosen platform not have a pre-defined way of detecting a mobile browser? Check out Detect Mobile Browsers, has several copy / paste examples for several programming languages.

    http://detectmobilebrowsers.com/

    Remember Apache, IIS and nginx detection examples also present for doing for pesky redirects.

  • WordPress: Update user / admin password via database

    WordPress: Update user / admin password via database

    Forgot your WordPress admin login details or a previous developer is unwilling to give you the WordPress login details, well the answer is very simple. As long as you have database access you can use the website below to generate a new password hashsum, simply replace the origional password value with the new hashsum and you will have access again. (more…)

  • PHP: Show PHP errors messages for debugging code

    PHP: Show PHP errors messages for debugging code

    Need to easily debug some php code? simple add the following code to your script to enable PHP error reporting and display error messages. This allows you to quickly debug without making configuration changes to servers PHP configuration.

    It is good practice to hide error messages for security reasons, error messages could be used by hackers to gather information and vulnerabilities.

    This code is provided as it and may require changes to work for your needs.

  • PHP: Get Page URLs / Directoy Listings

    A simple function to easily process a website or file and return an array of all the URLs found. The main purpose I created this was to make it easy to process “Directory Listings Pages” which is a page which shows all the files and folders in a websites directory if there inst a default/index page or the directory listings is enabled.

    I have used it to find images on another website (which has directory listings enabled) and display the found URLs / Images on another website. It it up to you how you use it but I am not sure what its limit are in terms of URLs per page.

  • PHP: Compare floats & why its different to a normal comparison

    Comparing two bits of data in PHP is quite simple but there are special occasions when a simple comparison of data needs to be slightly different. One of the common issues is comparing float numbers, a common mistake is comparing two float numbers the same way in which you would compare two integers or two strings.

    What does float, double or real number look like?
    1.234
    1.2e4
    7E-10

    This is due to how PHP stores float numbers (also known as doubles or real numbers) which gives this type of data a very limited precision resulting in numbers being slightly off, for a more in-depth explanation please read the following article http://php.net/manual/en/language.types.float.php.

    This issue only occurs once a calculation is performed on a float number.

    The best way of comparing two floats to get an accurate comparison is to convert the value to an alternative data type such as a integer, string or use “bccomp” which allows you to compare 2 float data types together up to the precision you specify (bccomp can also be used to determine which of the two floats is higher or lower).

    Read up on bccomp: http://php.net/manual/en/function.bccomp.php

    Is Match Comparison

    Greater or Lower Comparison

  • PHP: Random sequence function

    PHP: Random sequence function

    Here is a function I have created which is used to generate a sequence of random numbers, letters and symbols. I currently use it on a number of projects including http://passworded.co.uk which is a simple password generator. (more…)