Tuesday, 19 March 2024

Apple in talks to let Google’s Gemini power iPhone AI features
Apple is in talks to build Google’s Gemini artificial intelligence engine into the iPhone, Bloomberg News reported, citing people familiar with the situation.
The negotiations are about licensing Gemini for some new features coming to the iPhone software this year, the report said, adding that the terms or branding of an AI agreement or how it would be implemented have not been decided.
“This strategic partnership is a missing piece in the Apple AI strategy,” Wedbush analyst Daniel Ives said. Bloomberg
Alphabet shares jumped more than 6 per cent in morning trading on Monday (Tuesday AEDT), while Apple was up more than 2 per cent.
It is unlikely that any deal would be announced until June, when Apple plans to hold its annual conference of developers, and the iPhone maker also recently held talks with ChatGPT-maker OpenAI about using its model, according to the report.
Apple, Alphabet-owned Google and OpenAI did not immediately respond to Reuters requests for comment.
A potential deal between the firms could help Google expand the use of its AI services to more than 2 billion active Apple devices, boosting the search giant’s efforts to catch up with Microsoft-backed OpenAI.
It could also help allay investor fears about the slow roll-out of AI apps by Apple, which has lost the crown of the world’s most valuable firm after a 10 per cent decline in its shares this year.
The firms have a years-long partnership that makes Google the default search engine on Apple’s Safari web browser, and a generative AI tie-up may help the Alphabet unit navigate fears that services like ChatGPT could threaten its search dominance.
But the agreement could also invite sharper scrutiny from US regulators, who have sued Google on grounds that it unlawfully stifled competition by paying billions of dollars to Apple to maintain its monopoly in search.
“This strategic partnership is a missing piece in the Apple AI strategy and combines forces with Google for Gemini to power some of the AI features Apple is bringing to market,” said Daniel Ives, an analyst at Wedbush.
“This is a major win for Google to get onto the Apple ecosystem and have access to the golden installed base of Cupertino, with clearly a major licence fee attached to this,” he said, referring to Apple’s California headquarters.
Google in January partnered with Apple’s rival Samsung to deploy its genAI technology in the South Korean firm’s Galaxy S24 series of smartphones, as part of its efforts to boost the use of Gemini after some missteps during its roll-out.
Apple CEO Tim Cook said last month that the company was investing “significantly” in generative AI and would reveal more about its plans to put the technology to use later this year.
The Bloomberg report said Apple was planning to use its own homegrown AI models for some new capabilities in its upcoming iOS 18, but was seeking a partner to power genAI features, including functions for creating images and writing essays based on simple prompts.
Sunday, 17 March 2024

Testing your products for PHP version compatibility
With all versions of PHP 7 now officially EOL (end of life) any plugins you develop, or have developed, must support PHP 8. While WordPress does run on PHP 8, many plugins still do not support it fully. In this tutorial, we’ll look at how to can test your plugins for PHP compatibility, in order to get them updated.
Learning outcomes
- Explain why it’s important to test for PHP version compatibility
- Identify where to find information about PHP version changes
- Demonstrate how to test manually for PHP version compatibility
- Execute scanning of code for PHP version compatibility using PHPCompatibilityWP
Comprehension questions
- What does it mean when a PHP version is end-of-life?
- Where can you read about changes introduced by different PHP versions?
- What are two ways you can test your plugins for PHP version compatibility?
Introduction
Hey there, and welcome to Learn WordPress.
In this tutorial, you’re going to learn about testing your WordPress products for PHP version compatibility.
You will learn why it’s important to test for PHP version compatibility, where to find information about PHP version changes, as well as two methods to test your plugins and themes against newer PHP versions.
Why test for PHP version compatibility?
WordPress is written in PHP, and as such, it needs to be able to run on at least the minimum supported version of PHP that is available to web hosts. While WordPress recommends a specific minimum version of PHP, older PHP versions will eventually reach end of life, and will not receive any security updates in the near future.
For example, the current minimum recommended PHP version to run WordPress is 7.4, which reached end of life status on the 28th November 2022
WordPress core itself is considered compatible (with select explicit exceptions) with PHP 8.0 and PHP 8.1 and beta-compatible with PHP 8.2 and the PHP 8.3 release. However, they cannot guarantee that all plugins will be compatible with current or future versions of PHP.
As a plugin developer, it’s therefore important to have a process in place to test your plugins for PHP version compatibility.
Where to find information on PHP version changes
In order to know when and how PHP versions are going to change, it’s a good idea to refer to the official PHP website at https://www.php.net/.
On the Supported Versions page, you can find information about which versions are currently supported, at what level of support, and which versions are end of life.
At the time of this recording, all PHP 7.x versions are end of life, PHP 8.0 is supported for security fixes only, and PHP 8.1 and PHP 8.2 and 8.3 are actively supported, meaning bug and security flaws will be fixed. Note that PHP 8.0 will only be supported for security fixes till November 2023, which is around the time PHP 8.3 will be released, and then PHP 8.0 will be considered end of life.
In the Appendices section of the PHP documentation you can find the guides on migrating from older PHP versions, which list the most important changes between the old version and the new one. For example, the Migrating from PHP 7.4.x to PHP 8.0.x guide lists the most important changes between PHP 7.4 and PHP 8.0.
Example plugin
<?php
/**
* Plugin Name: WP Learn Compatibility
* Description: Learn to test a plugin for PHP Version Compatibility
* Version: 1.0.1
*
* @package wp-learn-compatibility
*/
/**
* Posts fetcher class
*/
class Post_Fetcher {
/**
* Array posts
*
* @var array
*/
protected $posts;
/**
* Fetch the WordPress posts
*/
public function post_fetcher() {
$this->posts = get_posts();
}
/**
* Fetch the posts and return the formatted HTML
*
* @return string
*/
public function fetch_posts() {
$post_html = '<div class="post">';
foreach ( $this->posts as $post ) {
if ( property_exists( $post, 'post_title' ) ) {
$post_html .= sprintf(
'<h4><a href="%s">%s</a></h4>',
get_permalink( $post->ID ),
$post->post_title
);
}
}
$post_html .= '</div>';
return $post_html;
}
}
add_shortcode( 'wp_learn_php_compatibility', 'wp_learn_php_compatibility_shortcode_render' );
/**
* Shortcode callback function for wp_learn_php_compatibility shortcode
*
* @return string
*/
function wp_learn_php_compatibility_shortcode_render() {
$post_fetcher = new post_fetcher();
$post_html = $post_fetcher->fetch_posts();
return $post_html;
}
For the purposes of this tutorial, look at an example plugin.
The plugin registers a shortcode, which fetches a list of posts and displays the post title of each post whenever the shortcode is used. The post_fetcher class handles the fetching of the posts.
Testing the shortcode on a page, you can see that it works as expected when running PHP 7.4.
How to test for PHP version compatibility
There are a few ways to test for PHP version compatibility, which require different combinations of newer PHP versions and installation of various tools. For the purposes of this tutorial, we will look at two possible methods, each with their own pros and cons.
Manual compatibility testing
The manual method involves you setting up a WordPress environment with the PHP version you want to test for, and then testing your plugin in that environment.
Setting up this environment can be done in a few ways, but the most common option would be to use a local development environment that supports changing PHP version, such as Mamp, Laragon, LocalWP, and DevKinsta.
For the purposes of this example we’ll test on PHP 8.1.
A quick way to check that you’re on the right version, is you create an info.php file in the root of your WordPress install, and use the following code:
<?php
phpinfo();
Then, navigate to the info.php file in your browser, and you should see the PHP version displayed.
Once you have your test environment set up, you need to enable WordPress debugging.
To do this, edit the wp-config.php
file, and update the line which defines the WP_DEBUG
constant, setting it to true
define( 'WP_DEBUG', true );
Additionally, add the WP_DEBUG_DISPLAY
constant and set it to false and add the WP_DEBUG_LOG
constant and set it to true, so that errors are logged to a debug.log
file in the wp-content
directory.
define( 'WP_DEBUG_DISPLAY', false );
define( 'WP_DEBUG_LOG', true );
You can also set your WP_DEBUG_LOG
constant to a custom location, by specifying the path to the file. For example:
define( 'WP_DEBUG_LOG', '/home/ubuntu/wp-local-env/sites/learnpress/logs/debug.' . date( 'Y-m-d' ) . '.log' );
Then, test your plugin, by refreshing the page. Notice that the shortcode functionality breaks.
If you look at the debug.log, you’ll see the following error displayed:
[24-Nov-2023 12:59:49 UTC] PHP Warning: foreach() argument must be of type array|object, null given in /home/ubuntu/wp-local-env/sites/learnpress/wp-content/plugins/wp-learn-php-compatibility/wp-learn-php-compatibility.php on line 36
Now, if you go to line 36 of the plugin file, you’ll see the following code, you’ll see that it’s trying to loop through the $this->posts
property, which is null for some reason. The reason might not be immediately obvious, so you might have to dig into the Migrating from PHP 7.4.x to PHP 8.0.x guide.
In the Backward Incompatible Changes section, you see the following change:
Methods with the same name as the class are no longer interpreted as constructors. The __construct() method should be used instead.
So in this case, our class constructor method needs to be updated.
Once that’s fixed, refresh the page, and you’ll see that the plugin is working again as expected.
While manual testing does work, it’s a tedious process. Fortunately you can also automate most tests using a tool called PHPUnit. This will allow you to continuously safeguard your code both against bugs and for PHP compatibility issues, but that’s outside of the scope of this tutorial.
Scanning your code using PHPCompatibilityWP
There are also tools you can use to test for PHP Compatibility, the most useful being the aptly named PHPCompatibility tool, which is a set of rules for the PHP_CodeSniffer tool.
PHP_CodeSniffer is a command line tool that can be used to scan your code for errors and warnings, and the PHPCompatibility tool is a set of rules that can be used with PHP_CodeSniffer to scan your code for PHP version compatibility.
For WordPress developers, there is a specific ruleset called PHPCompatibilityWP, which is a PHPCompatibility ruleset for WordPress projects.
What’s great about PHPCompatibility/PHPCompatibilityWP is that you don’t have to configure a different PHP version to use it. You can use it with your existing PHP version, and it will check your code against the rules for the PHP version you specify.
To install and use PHPCompatibilityWP, you need to install Composer, which is a dependency manager for PHP projects.
For Composer to work, you also need PHP installed on your computer, so that you can use the PHP CLI binary, which allows you to run PHP scripts in the terminal, instead of just in a browser.
Installing Composer is outside the scope of this lesson, but you can find instructions on the Composer website for both macOS/Linux and Windows operating systems.
You can find ways to install PHP on your system on the PHP website under the Installation and Configuration section.
Once you install PHP, make sure to add the path to the PHP CLI binary to the operating system path of your computer, so that you can run PHP commands from anywhere on your computer.
You can check that you have PHP installed by running the following command in your terminal:
php -v
Similarly, you can check that you have Composer installed by running the following command in your terminal:
composer -V
Once you have Composer installed, you can initialise the composer project by running the following command inside the plugin directory. If you’re already using Composer for your plugin, you can skip this step.
composer init
This will initialise a new Composer project in your plugin directory. You can accept the defaults for most of the questions, but when it asks you to define your dependencies (require) interactively and define your dev dependencies (require-dev) interactively?, you should answer no. You can also skip the PSR-4 autoload mapping.
Once this is done, you will have a composer.json
file, which is the file Composer uses to manage your project dependencies.
Next, you will need to install a Composer plugin to manage the installed_paths setting for PHP_CodeSniffer by running the following from the command. If you already have this plugin installed, you can ignore this.
composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
Then you can install the Composer installer plugin, and the PHPCompatibilityWP tool by running the following commands:
composer require --dev dealerdirect/phpcodesniffer-composer-installer:"^1.0"
composer require --dev phpcompatibility/phpcompatibility-wp:"*"
This will both setup and install the required dependencies in your composer.json file.
A note on PHPCompatibility and PHPCompatibilityWP versions.
Currently, the stable release of PHPCompatibility is 9.3.5, and the most recent sniffs are part of the upcoming version 10.0.0. release. The current stable version of PHPCompatibilityWP is 2.1.4
When version 10.0 of PHPCompatibility is released, version 3.0 of PHPCompatibilityWP will be released, which will depend on PHPCompatibility version 10.0.
In the meantime, it is possible to install the dev-develop branch of PHPCompatibility to run PHPCS with the cutting-edge additions of PHP 8 sniffs before their release in version 10.0.0 of PHPCompatibility as detailed in this WordPress VIP documentation.
To do this, run the following commands to alias the dev-develop branch of PHPCompatibility:
composer config minimum-stability dev
composer require --dev phpcompatibility/phpcompatibility-wp:"^2.1"
composer require --dev phpcompatibility/php-compatibility:"dev-develop as 9.99.99"
These commands will alias the develop
branch of PHPCompatibility to a 9.x version which is within the allowed range for PHPCompatibility, and set PHPCompatibilityWP to install the latest stable 2.1 version.
Once PHPCompatibility 10 and PHPCompatibilityWP 3 are released, it should be possible to update the PHPCompatibilityWP version constraint to “^3.0”, which will depend on version 10 of PHPCompatibility.
With all this installed, you can run the PHPCompatibilityWP tool on your plugin file.
The recommended way to do this is run PHPCompatibilityWP against a specific base version of PHP. In this example you can run it against version 7.4 of PHP and above by setting the testVersion
runtime variable to 7.4-
.
./vendor/bin/phpcs --runtime-set testVersion 7.4- -p wp-learn-php-compatibility.php --standard=PHPCompatibilityWP
And you will see this output:
W 1 / 1 (100%)
FILE: /Users/jonathanbossenger/wp-local-env/sites/learnpress/wp-content/plugins/wp-learn-php-compatibility/wp-learn-php-compatibility.php
-----------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------------------------
15 | WARNING | Use of deprecated PHP4 style class constructor is not supported since PHP 7.
-----------------------------------------------------------------------------------------------------------------------------------------
Time: 33ms; Memory: 8MB
Notice how the same error is reported as the manual method, but this time it’s a lot more specific. It tells us exactly what line the error is on, and what the error is.
So now we can fix the class constructor error.
Considerations
One of the considerations when using something like PHPCompatibilityWP is that it can’t pick up every single compatibility error.
For example, one of the other changes from PHP 7.4 to PHP 8.0 is the removal of the ability to use array_key_exists()
with objects, and instead something like property_exists()
should be used.
However, the PHPCompatibilityWP tool doesn’t know if the variable you’re passing to array_key_exists()
is an array or an object, so it can’t warn you about this.
This is where automating your manual tests would come in handy. When you run the tests in a new PHP environment, the tests would fail, altering you to a possible problem. And with logging enabled, you’d see the error logged to the log file.
Ultimately combining a tool like PHPCompatibility with automated testing and the manual testing process we’ve discussed, will allow you to ensure that your plugin is compatible with current and future versions of PHP.

Create Block Theme Improvements
There have been a few quality-of-life improvements to the Create Block Theme plugin over the course of the WordPress 6.3 and 6.4 releases. This tutorial will give you a brief introduction to these improvements.
Learning outcomes
- Describe the improvements that have been made to Create Block Theme for WordPress 6.3 and 6.4
Comprehension questions
- What improvements have been made to the Manage Your Theme Fonts page
- Name the four theme actions that have been added to the Site Editor
Introduction
Hey there, and welcome to Learn WordPress.
In this tutorial, you will learn about some of the improvements that have been made to the Create Block Theme plugin for WordPress 6.3 and 6.4.
What is Create Block Theme?
Create Block Theme is a WordPress plugin which extends the functionality of the block editor for theme developers.
Not only does it allow you to write any changes you have made to your theme in the site editor to your theme files, but it also allows you to create a new theme from scratch.
If this is the first time you are learning about Create Block Theme, you may want to check out the Streamline your Block Theme development with Create Block Theme and Manage your block theme fonts with Create Block Theme tutorials, which cover the basic functionality of this plugin.
Theme font previews
One of the improvements that has been made to Create Block Theme is the addition of theme font previews.
When you navigate to the Manage Theme Fonts page, you see a list of all the theme fonts that are installed for the current theme.
Clicking on the arrow next to a specific theme font will show you a preview of that font.
You can then select different options in the Preview Type dropdown to see how the font will look in different contexts.
The options included are:
- Heading
- Sentence
- and Paragraph
If the installed theme has more than one variant installed, you will also be able to preview the different variants.
It is also possible to change the demo text.
As well as the demo size.
Another addition to the Manage Theme Fonts page is the Theme Fonts overview on the right-hand side of the screen, which also includes the total size of the installed fonts.
This font preview is also available when you add a font. For example, if you choose to install a Google font, you will be able to preview the font before you install it.
Additionally, as you select variants to install, the list of variants and the total size of the installed fonts on the right-hand side is updated.
Site editor actions
The other addition to Create Block Theme is the ability to trigger theme-related actions from the site editor.
If you are editing a theme in the Site Editor, there is now a new Wrench icon in the top right-hand corner of the screen.
Clicking on this icon reveals the following four Create Block theme actions.
You can save the current changes to the theme files.
You can export your theme.
You can edit the theme metadata, like the theme name or theme description.
And finally, you can create a new theme based on your current changes, and either save it or export it.
This means that you no longer have to save your changes in the site editor, and then go all the way back to the main Create Block Theme page to save or export your theme.
Conclusion
And that wraps up this tutorial on the improvements that have been made to Create Block Theme.
Happy coding.
Friday, 10 March 2017

C++ Compilers
Compilers
C++ is a language that has evolved much over the years, and these tutorials explain many features added recently to the language. Therefore, in order to properly follow the tutorials, a recent compiler is needed. It shall support (even if only partially) the features introduced by the 2011 standard.
Many compiler vendors support the new features at different degrees. See the bottom of this page for some compilers that are known to support the features needed. Some of them are free!
If for some reason, you need to use some older compiler, you can access an older version of these tutorials here (no longer updated).
What is a compiler?
Computers understand only one language and that language consists of sets of instructions made of ones and zeros. This computer language is appropriately called machine language.A single instruction to a computer could look like this:
00000 | 10011110 |
A particular computer's machine language program that allows a user to input two numbers, adds the two numbers together, and displays the total could include these machine code instructions:
00000 | 10011110 |
00001 | 11110100 |
00010 | 10011110 |
00011 | 11010100 |
00100 | 10111111 |
00101 | 00000000 |
As you can imagine, programming a computer directly in machine language using only ones and zeros is very tedious and error prone. To make programming easier, high level languages have been developed. High level programs also make it easier for programmers to inspect and understand each other's programs easier.
This is a portion of code written in C++ that accomplishes the exact same purpose:
|
|
Even if you cannot really understand the code above, you should be able to appreciate how much easier it will be to program in the C++ language as opposed to machine language.
Because a computer can only understand machine language and humans wish to write in high level languages high level languages have to be re-written (translated) into machine language at some point. This is done by special programs called compilers, interpreters, or assemblers that are built into the various programming applications.
C++ is designed to be a compiled language, meaning that it is generally translated into machine language that can be understood directly by the system, making the generated program highly efficient. For that, a set of tools are needed, known as the development toolchain, whose core are a compiler and its linker.
Console programs
Console programs are programs that use text to communicate with the user and the environment, such as printing text to the screen or reading input from a keyboard.Console programs are easy to interact with, and generally have a predictable behavior that is identical across all platforms. They are also simple to implement and thus are very useful to learn the basics of a programming language: The examples in these tutorials are all console programs.
The way to compile console programs depends on the particular tool you are using.
The easiest way for beginners to compile C++ programs is by using an Integrated Development Environment (IDE). An IDE generally integrates several development tools, including a text editor and tools to compile programs directly from it.
Here you have instructions on how to compile and run console programs using different free Integrated Development Interfaces (IDEs):
IDE | Platform | Console programs |
---|---|---|
Code::blocks | Windows/Linux/MacOS | Compile console programs using Code::blocks |
Visual Studio Express | Windows | Compile console programs using VS Express 2013 |
Dev-C++ | Windows | Compile console programs using Dev-C++ |
If you happen to have a Linux or Mac environment with development features, you should be able to compile any of the examples directly from a terminal just by including C++11 flags in the command for the compiler:
Compiler | Platform | Command |
---|---|---|
GCC | Linux, among others... | g++ -std=c++0x example.cpp -o example_program |
Clang | OS X, among others... | clang++ -std=c++11 -stdlib=libc++ example.cpp -o example_program |
