<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>Adam Patterson</title>
	<atom:link href="https://adampatterson.ca/feed/" rel="self" type="application/rss+xml" />
	<link>https://adampatterson.ca/</link>
	<description>Edmonton Developer</description>
	<lastBuildDate>Sun, 10 Dec 2023 02:27:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.1</generator>
<site xmlns="com-wordpress:feed-additions:1">123805354</site>	<item>
		<title>How to fix Nginx client_body_temp Permission denied on macOS</title>
		<link>https://adampatterson.ca/development/how-to-fix-nginx-client_body_temp-permission-denied-on-macos/</link>
		
		<dc:creator><![CDATA[Adam Patterson]]></dc:creator>
		<pubDate>Fri, 06 Oct 2023 01:07:42 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Trouble Shooting]]></category>
		<guid isPermaLink="false">https://www.adampatterson.ca/?p=1825</guid>

					<description><![CDATA[<p>I was working on a project that required file uploads like PDF/JPG. And it wouldn&#8217;t be a fun time unless something went wrong.In my case, I could upload a PDF but a JPG would thrown an error. My project is using Laravel Filament and the SpatieMediaLibraryFileUpload. Looking in the Chrome Network tab I could see...</p>
<p>The post <a href="https://adampatterson.ca/development/how-to-fix-nginx-client_body_temp-permission-denied-on-macos/">How to fix Nginx client_body_temp Permission denied on macOS</a> appeared first on <a href="https://adampatterson.ca">Adam Patterson</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>I was working on a project that required file uploads like PDF/JPG. And it wouldn&#8217;t be a fun time unless something went wrong.<br>In my case, I could upload a PDF but a JPG would thrown an error. My project is using <a href="https://filamentphp.com/" target="_blank" rel="noreferrer noopener nofollow">Laravel Filament</a> and the <code>SpatieMediaLibraryFileUpload</code>. Looking in the Chrome Network tab I could see a 500 error and the response shows a 500 error, but from Nginx and not Laravel.</p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="278" src="http://adampatterson.ca/wp-content/uploads/2023/08/image-1024x278.png" alt="" class="wp-image-1827" srcset="https://adampatterson.ca/wp-content/uploads/2023/08/image-1024x278.png 1024w, https://adampatterson.ca/wp-content/uploads/2023/08/image-300x81.png 300w, https://adampatterson.ca/wp-content/uploads/2023/08/image-768x209.png 768w, https://adampatterson.ca/wp-content/uploads/2023/08/image-625x170.png 625w, https://adampatterson.ca/wp-content/uploads/2023/08/image.png 1068w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>On an ARM macOS I ran  <code>tail -f /opt/homebrew/var/log/nginx/error.log</code> and could see the following error.</p>



<pre class="wp-block-code"><code class="">2023/08/11 09:53:43 [crit] 29890#0: *9 open() "/opt/homebrew/var/run/nginx/client_body_temp/0000000002" failed (13: Permission denied), client: 127.0.0.1, server: local.test, request: "POST /livewire/upload-file?expires=1691769523&amp;signature=61f7f20ef5a9047cec174fc9fa5dbb2b729b0f91394f75b23d41c0f358318463 HTTP/1.1", host: "local.test", referrer: "http://local.test/admin/inspections/5/submit"</code></pre>



<p>🤨 WTF!</p>



<figure class="wp-block-image size-full"><img decoding="async" width="554" height="194" src="http://adampatterson.ca/wp-content/uploads/2023/08/image-1.png" alt="" class="wp-image-1828" srcset="https://adampatterson.ca/wp-content/uploads/2023/08/image-1.png 554w, https://adampatterson.ca/wp-content/uploads/2023/08/image-1-300x105.png 300w" sizes="(max-width: 554px) 100vw, 554px" /></figure>



<p>I resolved the issue by by running <code>sudo chown -R $USER:_developer client_body_temp/</code></p>



<p>I am unclear why <code>nobody</code> was assigned to the folders, I also think that maybe my work laptop has the <code>_developer</code> group which I don&#8217;t think is standard.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="386" height="195" src="http://adampatterson.ca/wp-content/uploads/2023/08/image-3.png" alt="" class="wp-image-1832" srcset="https://adampatterson.ca/wp-content/uploads/2023/08/image-3.png 386w, https://adampatterson.ca/wp-content/uploads/2023/08/image-3-300x152.png 300w" sizes="(max-width: 386px) 100vw, 386px" /></figure>



<p>You won&#8217;t need to restart Nginx but retry the file upload.  <br><br>Hopefully you found this helpful!</p>
<p>The post <a href="https://adampatterson.ca/development/how-to-fix-nginx-client_body_temp-permission-denied-on-macos/">How to fix Nginx client_body_temp Permission denied on macOS</a> appeared first on <a href="https://adampatterson.ca">Adam Patterson</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1825</post-id>	</item>
		<item>
		<title>Fixing the &#8216;server busy or not enough resources&#8217; error in WordPress</title>
		<link>https://adampatterson.ca/general/fixing-the-server-busy-or-not-enough-resources-error-in-wordpress/</link>
		
		<dc:creator><![CDATA[Adam Patterson]]></dc:creator>
		<pubDate>Fri, 30 Dec 2022 19:26:38 +0000</pubDate>
				<category><![CDATA[General]]></category>
		<guid isPermaLink="false">https://www.adampatterson.ca/?p=1795</guid>

					<description><![CDATA[<p>If you are using Nginx as your web server, one solution to this error is to update the client_max_body_size setting in your Nginx configuration. This setting specifies the maximum size of the request body, in bytes. By default, it is set to 1 megabyte (1024 kilobytes). If you are trying to upload an image that...</p>
<p>The post <a href="https://adampatterson.ca/general/fixing-the-server-busy-or-not-enough-resources-error-in-wordpress/">Fixing the &#8216;server busy or not enough resources&#8217; error in WordPress</a> appeared first on <a href="https://adampatterson.ca">Adam Patterson</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>If you are using Nginx as your web server, one solution to this error is to update the <code>client_max_body_size</code> setting in your Nginx configuration. This setting specifies the maximum size of the request body, in bytes. By default, it is set to 1 megabyte (1024 kilobytes). If you are trying to upload an image that is larger than this size, you may receive the &#8220;server cannot process image&#8221; error.</p>



<p>To fix this error, you can try increasing the <code>client_max_body_size</code> setting in your Nginx configuration. Here&#8217;s how:</p>



<p>1) Open your Nginx configuration file. This is typically located at <code>/etc/nginx/nginx.conf</code> on a Linux server.</p>



<p>2) Find the <code>http</code> block in the configuration file and add the following line:</p>



<pre class="wp-block-code"><code lang="bash" class="language-bash">http {
    ...
    client_max_body_size [size];
}</code></pre>



<p>Replace <code>[size]</code> with the maximum size of the request body you want to allow, in bytes. For example, to set the maximum size to 10 megabytes, you would use <code>client_max_body_size 10m;</code>.</p>



<p>3) Save the configuration file, test and restart Nginx using the following command:</p>



<pre class="wp-block-code"><code lang="bash" class="language-bash"><code>sudo nginx -t</code>
# nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
# nginx: configuration file /etc/nginx/nginx.conf test is successful

<code>sudo systemctl restart nginx</code></code></pre>



<p>After increasing the <code>client_max_body_size</code> setting and restarting Nginx, you should be able to upload larger images to your WordPress website or blog without encountering the &#8220;server cannot process image&#8221; error.</p>



<p>However, if you are still experiencing this error after updating the <code>client_max_body_size</code> setting, there may be other factors at play. Here are a few additional things you can try:</p>



<ul class="wp-block-list">
<li>Update the <code>upload_max_filesize</code> setting in PHP. This setting specifies the maximum size of a file that can be uploaded to your server. If you are trying to upload an image that is larger than this size, you may receive the &#8220;server cannot process image&#8221; error. To fix this, you can increase the <code>upload_max_filesize</code> setting in your PHP configuration. This is typically located at <code>/etc/php/php.ini</code> or <code>/etc/php/8.2/fpm/php.ini</code> on a Linux server. Find the <code>upload_max_filesize</code> setting and increase it to a larger value, then save the file and restart your web server.</li>



<li>Reduce the size of the image you&#8217;re trying to upload. The suggested maximum size for images in WordPress is 2560 pixels. If your image is larger than this, you&#8217;ll need to resize it before uploading. You can use a free image editing tool like GIMP or Adobe Photoshop to resize your image.</li>



<li>Check your server&#8217;s resource usage. If the server is busy or has a high load, it may not have enough resources available to process your image. You can check your server&#8217;s resource usage by contacting your web host or using a tool like <strong>top</strong>. If the server&#8217;s resources are maxed out, you may need to upgrade to a more powerful hosting plan or consider moving to a different web host.</li>
</ul>
<p>The post <a href="https://adampatterson.ca/general/fixing-the-server-busy-or-not-enough-resources-error-in-wordpress/">Fixing the &#8216;server busy or not enough resources&#8217; error in WordPress</a> appeared first on <a href="https://adampatterson.ca">Adam Patterson</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1795</post-id>	</item>
		<item>
		<title>How to execute multiple versions of PHP on macOS using the CLI</title>
		<link>https://adampatterson.ca/development/how-to-execute-multiple-versions-of-php-on-macos-using-the-cli/</link>
		
		<dc:creator><![CDATA[Adam Patterson]]></dc:creator>
		<pubDate>Fri, 19 Aug 2022 22:12:31 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server]]></category>
		<guid isPermaLink="false">https://www.adampatterson.ca/?p=1776</guid>

					<description><![CDATA[<p>Many sites still required php 7.4 even though it&#8217;s older and now considered deprecated. That being said, it&#8217;s still important to test with newer versions of PHP. Combined with PHP having a quicker release cycle PHP 8, 8.1, and 8.2 are on their way. I have to work with a couple of versions regularly in...</p>
<p>The post <a href="https://adampatterson.ca/development/how-to-execute-multiple-versions-of-php-on-macos-using-the-cli/">How to execute multiple versions of PHP on macOS using the CLI</a> appeared first on <a href="https://adampatterson.ca">Adam Patterson</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Many sites still required php 7.4 even though it&#8217;s older and now considered deprecated.  That being said, it&#8217;s still important to test with newer versions of PHP. </p>



<p>Combined with PHP having a quicker release cycle PHP 8, 8.1, and 8.2 are on their way.</p>



<p>I have to work with a couple of versions regularly in the CLI, and the best way I found to do this was to create an alias.</p>



<p>Let&#8217;s assume that you installed your versions of PHP using brew, or already know where your version of PHP is.</p>



<p>Add the following to your bash profile.</p>



<pre class="wp-block-code"><code class="">alias php7='/usr/local/opt/php@7.4/bin/php'
alias php8='/usr/local/opt/php@8.0/bin/php'</code></pre>



<p>If you want you can install PHP 8.1 and 8.2 as well with <code>brew install php@8.X</code> and add another alias.</p>



<p>This will allow you to run <code>php8 composer</code>, you can do a quick test by creating an <code>index.php</code> file and adding <code>phpinfo()</code> to it.</p>



<pre class="wp-block-code"><code lang="bash" class="language-bash">php7 index.php | grep "PHP Version"
php8 index.php | grep "PHP Version"</code></pre>



<p>If you have an M1 mac, your system paths will be different. You can replace: </p>



<pre class="wp-block-code"><code class="">/usr/local/opt/</code></pre>



<p>with</p>



<pre class="wp-block-code"><code class="">/System/Volumes/Data/opt/homebrew/opt</code></pre>



<p>If you were to run <code>php -v</code> and see v7.4 then you can now run <code>php8 composer install</code> in most cases, this has worked perfectly, but if you need something a bit more permanent it&#8217;s still best to change your system environment.</p>



<p>Alternatively, if you want to change your version of PHP in the command line more permanently you can add this function to your <code>.bash_profile</code></p>



<pre title="" class="wp-block-code"><code lang="bash" class="language-bash">function phpv() {
    brew unlink php
    brew link --overwrite --force "php@$1"
    php -v
}</code></pre>



<p>And then run with <code>phpv 8.2</code></p>



<p>I can&#8217;t take credit for the above shell script, but I also can&#8217;t find the original post that I discovered it on.</p>
<p>The post <a href="https://adampatterson.ca/development/how-to-execute-multiple-versions-of-php-on-macos-using-the-cli/">How to execute multiple versions of PHP on macOS using the CLI</a> appeared first on <a href="https://adampatterson.ca">Adam Patterson</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1776</post-id>	</item>
		<item>
		<title>Super simple local wildcard SSL!</title>
		<link>https://adampatterson.ca/general/super-simple-local-wildcard-ssl/</link>
		
		<dc:creator><![CDATA[Adam Patterson]]></dc:creator>
		<pubDate>Wed, 27 Jan 2021 20:33:52 +0000</pubDate>
				<category><![CDATA[General]]></category>
		<guid isPermaLink="false">https://www.adampatterson.ca/?p=1697</guid>

					<description><![CDATA[<p>Working locally most of the time a secure site won&#8217;t be necessary but from time to time you will require a secure connection. Such as working with oAuth providers, and making sure that you don&#8217;t serve any mixed assets. Previously I used OpenSSL locally on my Mac, and it was&#8230; OK, but it was sort...</p>
<p>The post <a href="https://adampatterson.ca/general/super-simple-local-wildcard-ssl/">Super simple local wildcard SSL!</a> appeared first on <a href="https://adampatterson.ca">Adam Patterson</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Working locally most of the time a secure site won&#8217;t be necessary but from time to time you will require a secure connection. Such as working with oAuth providers, and making sure that you don&#8217;t serve any mixed assets.</p>



<p>Previously I used <a href="http://adampatterson.ca/2018/local-greenbar-https-ssl-with-mamp/" target="_blank" rel="noreferrer noopener">OpenSSL locally on my Mac</a>, and it was&#8230; OK, but it was sort of complicated and involved a lot of copy and paste.</p>



<p>To get started let&#8217;s start off by installing <a href="https://blog.filippo.io/mkcert-valid-https-certificates-for-localhost/" target="_blank" rel="noreferrer noopener nofollow">mkCert</a> using <a href="https://brew.sh/" target="_blank" rel="noreferrer noopener nofollow">HomeBrew</a>.  Create a new folder in your Sites directory called SSL, and navigate your way there in the terminal.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">brew install mkcert
brew install nss # if you use Firefox

mkcert -install

mkcert site.local '*.site.local'</code></pre>



<p>That was it! Your certificate is is ready to go, but now what?</p>



<h3 class="wp-block-heading">Configure MAMP</h3>



<p>Open&nbsp;<code>/Applications/MAMP/conf/apache/httpd.conf</code>&nbsp;and search for&nbsp;<code># Virtual hosts</code>.</p>



<p>Add a line under&nbsp;<code>httpd-vhosts.conf</code>&nbsp;called&nbsp;<code>httpd-secure-vhosts.conf</code>.</p>



<p>Open&nbsp;<code>/Applications/MAMP/conf/apache/httpd-secure-vhosts.conf</code>&nbsp;and add the following, changing the names and paths to reflect your needs.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">NameVirtualHost *:443

&lt;VirtualHost *:443>
	ServerName site.local
    ServerAlias *.site.local
    ServerAlias dev.smi
    ServerAlias *.dev.smi

	DocumentRoot "/Users/{username}}/Sites/web_path/"

    &lt;IfModule xsendfile_module>
        XSendFilePath "/Users/{username}}/Sites/web_path/"
    &lt;/IfModule>

    SSLEngine on

    SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL

    ErrorLog "/Applications/MAMP/logs/apache_ssl_error.log"
    TransferLog "/Applications/MAMP/logs/apache_ssl_access.log"
    CustomLog "/Applications/MAMP/logs/apache_ssl_request.log" "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

    SSLCertificateFile "/Users/{username}}/Sites/ssl/site.local+1.pem"
    SSLCertificateKeyFile "/Users/{username}}/Sites/ssl/site.local+1-key.pem"

    SSLSessionTickets on

    &lt;FilesMatch "\.(cgi|shtml|phtml|php)$">
        SSLOptions +StdEnvVars
    &lt;/FilesMatch>

    &lt;Directory "/Applications/MAMP/Library/cgi-bin">
        SSLOptions +StdEnvVars
    &lt;/Directory>

    BrowserMatch ".*MSIE.*" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0

	&lt;Directory "/Users/{username}}/Sites/web_path/">
		Options Includes FollowSymLinks ExecCGI
		AllowOverride All
		Order allow,deny
        Allow from all

	&lt;/Directory>

&lt;/VirtualHost></code></pre>



<p>Open&nbsp;<code>/Applications/MAMP/conf/apache/httpd.conf</code>&nbsp;again and look for&nbsp;<code>Include /Applications/MAMP/conf/apache/extra/httpd-ssl.conf</code> and uncomment that line.</p>



<p>I personally remove the VirtualHost from this file and leave it the <code>httpd-secure-vhosts.conf </code>file that we previously created.</p>



<p>By creating a wild card certificate you can simply add every new local site under that subdomain if you so choose.</p>
<p>The post <a href="https://adampatterson.ca/general/super-simple-local-wildcard-ssl/">Super simple local wildcard SSL!</a> appeared first on <a href="https://adampatterson.ca">Adam Patterson</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1697</post-id>	</item>
		<item>
		<title>Customize WordPress menu items based on Geographic Location</title>
		<link>https://adampatterson.ca/development/wordpress-custom-links-based-on-geo-location/</link>
		
		<dc:creator><![CDATA[Adam Patterson]]></dc:creator>
		<pubDate>Tue, 01 Sep 2020 00:20:31 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://www.adampatterson.ca/?p=1672</guid>

					<description><![CDATA[<p>The internet is a huge place, and not all of your visitors live in your region. At times it makes sense to adjust your site&#8217;s content based on their geography. In my free time I like to make stuff and post it on YouTube, and my &#8220;other&#8221; blog called Hey I&#8217;m A Maker. A lot...</p>
<p>The post <a href="https://adampatterson.ca/development/wordpress-custom-links-based-on-geo-location/">Customize WordPress menu items based on Geographic Location</a> appeared first on <a href="https://adampatterson.ca">Adam Patterson</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>The internet is a huge place, and not all of your visitors live in your region. At times it makes sense to adjust your site&#8217;s content based on their geography.</p>



<p>In my free time I like to make stuff and post it on <a href="https://www.youtube.com/imamakerca" target="_blank" rel="noreferrer noopener nofollow">YouTube</a>, and my &#8220;other&#8221; blog called <a href="https://imamaker.ca/" target="_blank" rel="noreferrer noopener">Hey I&#8217;m A Maker</a>. A lot of content creators will use affiliate links in order to make some extra income from their content. There are plenty of services out there to help you do this.</p>



<p>At the moment I have an Amazon Affiliate store that I tossed a few interesting items into. The issue is that I live in Canada and many of my viewers also live in Canada.  The Amazon stores are not transferable between <strong>.com</strong> and <strong>.ca</strong>.</p>



<p>I began looking into ways of routing the link based on Geography. I discovered a few paid services for $10-20 a month which was far more than I wanted to spend.</p>



<p>After some exploring, I learned that <a href="https://www.cloudflare.com/" target="_blank" rel="noreferrer noopener nofollow">Cloudflare</a> is able to add Geolocation headers to their responses. If you are interested you can read more on how to set that up <a href="https://support.cloudflare.com/hc/en-us/articles/200168236-Configuring-Cloudflare-IP-Geolocation" target="_blank" rel="noreferrer noopener nofollow">here</a>. </p>



<h3 class="wp-block-heading">Modify your WordPress theme</h3>



<p>Once I had enabled the IP Geolocation feature I was able to see my region as <code>CA</code> using the following code as a test.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">echo $_SERVER["HTTP_CF_IPCOUNTRY"];</code></pre>



<p>The goal I want to achieve here is to modify a nav item based on our geographical location. In my case, Canadian visitors should see my Canadian affiliate store.</p>



<p>In the following code snippets, I will assume that your menu location is called <code>primary</code> and that the link you want to modify was added as a <strong>custom link</strong>.</p>



<p>To get this started I want to modify the WordPress menu items before the HTML has been created. To do this I will use the filter <code>wp_nav_menu_objects</code>.</p>



<p>Create a function called <code>update_shop_link</code> which will accept two parameters, <code>$items</code> and <code>$args</code>.</p>



<p>By now you should have something that looks like this located in your <code>functions.php</code>.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">add_filter( 'wp_nav_menu_objects', 'update_shop_link', 10, 2 );
function update_shop_link( $items, $args ) {
    // Code here
}</code></pre>



<p>Next up, we want to only modify a link that is in our <code>primary</code> menu and to make sure that <code>HTTP_CF_IPCOUNTRY</code> is set.  </p>



<p>Once those are true we can set a variable <code>$region</code>, and then loop through the $items looking for a link that is of the type custom, and whose title is equal to <code>Shop</code>.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">if ( $args-&gt;theme_location == 'primary' &amp;&amp; array_key_exists( 'HTTP_CF_IPCOUNTRY', $_SERVER ) ) {
    $region = $_SERVER["HTTP_CF_IPCOUNTRY"];

    foreach ( $items as $key =&gt; $item ) {
        if ( $region === 'CA' &amp;&amp; $item-&gt;type === 'custom' &amp;&amp; $item-&gt;title === 'Shop' ) {
            // Code here
        }
    }
}</code></pre>



<p>Now we have found out shop link you can modify the URL by overwriting it.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">$item-&gt;url = 'https://www.amazon.ca/shop/adampatterson';</code></pre>



<h3 class="wp-block-heading">Wrapping it up</h3>



<p>That&#8217;s all there is to it, now let&#8217;s roll it all together.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">add_filter( 'wp_nav_menu_objects', 'update_shop_link', 10, 2 );
function update_shop_link( $items, $args ) {
	if ( $args-&gt;theme_location == 'primary' &amp;&amp; array_key_exists( 'HTTP_CF_IPCOUNTRY', $_SERVER ) ) {
		$region = $_SERVER["HTTP_CF_IPCOUNTRY"];

		foreach ( $items as $key =&gt; $item ) {
			if ( $region === 'CA' &amp;&amp; $item-&gt;type === 'custom' &amp;&amp; $item-&gt;title === 'Shop' ) {
				$item-&gt;url = 'https://www.amazon.ca/shop/adampatterson';
			}
		}
	}

	return $items;
}</code></pre>



<p>This method was specific to WordPress, but as long as you are using a server-side language you can intercept the region and do whatever you like.</p>



<p>You could even create a page like domain.com/shop that would automatically redirect to your Amazon store. If you really wanted that URL could redirect to a tiny URL that would allow you to collect some basic analytics.</p>



<p>If you enjoyed this then I would love it if you subscribed to my <a href="https://www.youtube.com/imamakerca" target="_blank" rel="noreferrer noopener">YouTube channel</a> or had a look at my site <a href="https://imamaker.ca/" target="_blank" rel="noreferrer noopener">Hey I&#8217;m A Maker</a>.</p>
<p>The post <a href="https://adampatterson.ca/development/wordpress-custom-links-based-on-geo-location/">Customize WordPress menu items based on Geographic Location</a> appeared first on <a href="https://adampatterson.ca">Adam Patterson</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1672</post-id>	</item>
		<item>
		<title>How to add and Use WordPress Custom Image sizes</title>
		<link>https://adampatterson.ca/general/how-to-add-and-use-wordpress-custom-image-sizes/</link>
					<comments>https://adampatterson.ca/general/how-to-add-and-use-wordpress-custom-image-sizes/#respond</comments>
		
		<dc:creator><![CDATA[Adam Patterson]]></dc:creator>
		<pubDate>Fri, 10 Jul 2020 15:24:00 +0000</pubDate>
				<category><![CDATA[General]]></category>
		<guid isPermaLink="false">https://www.adampatterson.ca/?p=1264</guid>

					<description><![CDATA[<p>Adding a custom image size to WordPress could not be easier. The following will create a size called Square that is 150 by 150 pixels, the parameter true will result in the cropping of an image. Now any time an new image is uploaded WordPress will generate a file something like image-150&#215;150.jpg. If you want...</p>
<p>The post <a href="https://adampatterson.ca/general/how-to-add-and-use-wordpress-custom-image-sizes/">How to add and Use WordPress Custom Image sizes</a> appeared first on <a href="https://adampatterson.ca">Adam Patterson</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Adding a custom image size to WordPress could not be easier. The following will create a size called Square that is 150 by 150 pixels, the parameter true will result in the cropping of an image.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">add_image_size('square', 150, 150, true);</code></pre>



<p>Now any time an new image is uploaded WordPress will generate a file something like image-150&#215;150.jpg.</p>



<p>If you want to be able to insert these images in your posts then you will need to register the size with the Media moda.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">add_filter('image_size_names_choose', 'add_image_sizes_editor');

function add_image_sizes_editor($sizes)
{
    return array_merge($sizes, [
        'square'   => __('Square', 'axe'),
    ]);
}</code></pre>



<p>Now when you create a post and want to add an image your custom sizes will be available to you.</p>
<p>The post <a href="https://adampatterson.ca/general/how-to-add-and-use-wordpress-custom-image-sizes/">How to add and Use WordPress Custom Image sizes</a> appeared first on <a href="https://adampatterson.ca">Adam Patterson</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://adampatterson.ca/general/how-to-add-and-use-wordpress-custom-image-sizes/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1264</post-id>	</item>
		<item>
		<title>Working with branches in Composer</title>
		<link>https://adampatterson.ca/development/working-with-branches-in-composer/</link>
					<comments>https://adampatterson.ca/development/working-with-branches-in-composer/#respond</comments>
		
		<dc:creator><![CDATA[Adam Patterson]]></dc:creator>
		<pubDate>Fri, 03 Jul 2020 15:05:00 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Composer]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[GitHub]]></category>
		<guid isPermaLink="false">https://www.adampatterson.ca/?p=1269</guid>

					<description><![CDATA[<p>From time to time, you will find that you are going to need to work on a new feature, maybe your main application has some changes that live in your composer package or maybe you are adding a new feature to your compose package. In both scenarios, you might be maintaining a couple of feature...</p>
<p>The post <a href="https://adampatterson.ca/development/working-with-branches-in-composer/">Working with branches in Composer</a> appeared first on <a href="https://adampatterson.ca">Adam Patterson</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>From time to time, you will find that you are going to need to work on a new feature, maybe your main application has some changes that live in your composer package or maybe you are adding a new feature to your compose package.</p>



<p>In both scenarios, you might be maintaining a couple of feature branches and would want to be able to check your work in your staging environment, at the very least not impact your team.</p>



<p>Luckily Composer makes this super simple.</p>



<p>Take the branch name and prepend <code>dev-</code> to it as in the example below.</p>



<pre class="wp-block-code"><code lang="json" class="language-json">{
  "require": {
    "app/core": "dev-branch-name"
  },
  "repositories": [
    {
      "type": "package",
      "package": {
        "name": "app/core",
        "version": "dev-branch-name",
        "source": {
          "url": "git@github.com:repo/app-core.git",
          "type": "git",
          "reference": "branch-name"
        }
      }
    }
  ]
}</code></pre>



<p>Maybe you want to check a specific commit, then try using a commit hash instead <code>dev-master#99226c9</code></p>



<p>Thats it, and I hope this helps. I know it has come in handy when deploying a docker container to a staging server.</p>
<p>The post <a href="https://adampatterson.ca/development/working-with-branches-in-composer/">Working with branches in Composer</a> appeared first on <a href="https://adampatterson.ca">Adam Patterson</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://adampatterson.ca/development/working-with-branches-in-composer/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1269</post-id>	</item>
		<item>
		<title>Simple Googe Geolocation</title>
		<link>https://adampatterson.ca/development/simple-googe-geolocation/</link>
		
		<dc:creator><![CDATA[Adam Patterson]]></dc:creator>
		<pubDate>Tue, 30 Jun 2020 03:02:02 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Geolocation]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Services]]></category>
		<guid isPermaLink="false">https://www.adampatterson.ca/?p=1570</guid>

					<description><![CDATA[<p>What is Geolocation? Geolocation is a method used to find the location of your internet device on earth. Imagine you lost your cell phone, and use the find my phone option. The location of your phone will be your device&#8217;s last known location. How does Geolocation work? There are two main types of data collection....</p>
<p>The post <a href="https://adampatterson.ca/development/simple-googe-geolocation/">Simple Googe Geolocation</a> appeared first on <a href="https://adampatterson.ca">Adam Patterson</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h3 class="wp-block-heading">What is Geolocation?</h3>



<p>Geolocation is a method used to find the location of your internet device on earth.  Imagine you lost your cell phone, and use the find my phone option. The location of your phone will be your device&#8217;s last known location.</p>



<h3 class="wp-block-heading">How does Geolocation work?</h3>



<p>There are two main types of data collection.</p>



<p><strong>The first is Device-Based</strong></p>



<p>You have probably visited a website that prompted you for permission to access your location. This request has to be made from a secure site using SSL and if you are on a mobile device will require location services to be enabled.</p>



<p><strong>The second is Server-Based.</strong></p>



<p>Every request made to a server will include your device IP, that IP is typically stored in a Database where a physical location is matched. This isn&#8217;t always accurate as IP addresses are released and renewed frequently. Depending on your network, or your companies network these results can be very different.</p>



<h3 class="wp-block-heading">Why would I want to use Geolocation?</h3>



<ul class="wp-block-list"><li>Any time you have multiple locations like a food chain</li><li>E-commerce site where you have products across the country</li><li>You operate in multiple countries and want to redirect the customer to the proper website</li><li>Present visitors with relevant content</li></ul>



<p>Geolocation is a quick and simple way to present information that is relevant to the customer and to make improvements to their websites.</p>



<h3 class="wp-block-heading">How do I use Geolocation then?</h3>



<p>Login to your Google <a href="https://console.cloud.google.com/" target="_blank" rel="noreferrer noopener" aria-label="Cloud Account  (opens in a new tab)">Cloud Account </a></p>



<p>Then Enable the API by heading to the <a rel="noreferrer noopener" aria-label="API's Library (opens in a new tab)" href="https://console.cloud.google.com/apis/library" target="_blank">API&#8217;s Library</a>. Next, search for and enable <code>Geolocation API</code>.</p>



<p><strong>NOTE</strong>: There could be a cost associated with this, Make sure to read and understand your Google cloud account and how their billing works.</p>



<p>Under your API &amp; Services, click on Credentials,  then Add a new API restriction and check <code>Geolocation API</code>.</p>



<p>If you don&#8217;t add the restriction you will likely see the following error.</p>



<pre class="wp-block-code"><code lang="json" class="language-json">{
   "error_message" : "This API project is not authorized to use this API. Please ensure that this API is activated in the APIs Console: Learn more: https://code.google.com/apis/console",
   "results" : [],
   "status" : "REQUEST_DENIED"
}</code></pre>



<p>Using curl, or a tool like Postman, make a POST request to  <code>https://www.googleapis.com/geolocation/v1/geolocate?key={{key}} </code></p>



<p>That&#8217;s it, you should see something resembling the following results</p>



<pre class="wp-block-code"><code lang="json" class="language-json">{
  "location": {
    "lat": 53.595340799999995,
    "lng": -113.5706112
  },
  "accuracy": 2435
}</code></pre>



<p>For more on Google&#8217;s Geolocation services check out their <a rel="noreferrer noopener" aria-label="documentation (opens in a new tab)" href="https://developers.google.com/maps/documentation/geolocation/intro" target="_blank">guide</a>.</p>



<p>If you don&#8217;t happen to have an API key then this <a href="https://developers.google.com/maps/documentation/geolocation/get-api-key" target="_blank" rel="noreferrer noopener" aria-label="guide (opens in a new tab)">guide</a> should get you on your way.</p>
<p>The post <a href="https://adampatterson.ca/development/simple-googe-geolocation/">Simple Googe Geolocation</a> appeared first on <a href="https://adampatterson.ca">Adam Patterson</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1570</post-id>	</item>
		<item>
		<title>WordPress Loop Helpers</title>
		<link>https://adampatterson.ca/wordpress/wordpress-loop-helpers/</link>
		
		<dc:creator><![CDATA[Adam Patterson]]></dc:creator>
		<pubDate>Fri, 12 Jun 2020 19:09:30 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Loop]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Theme]]></category>
		<guid isPermaLink="false">https://www.adampatterson.ca/?p=1651</guid>

					<description><![CDATA[<p>If you have ever used Laravel, you have probably also used Blade. Blade is a simple and powerful template language provided with Laravel. Blade has many wonderful features but one of them, as it relates to WordPress, is how it works with a The Loop. Normally in the WordPress loop you would set a variable...</p>
<p>The post <a href="https://adampatterson.ca/wordpress/wordpress-loop-helpers/">WordPress Loop Helpers</a> appeared first on <a href="https://adampatterson.ca">Adam Patterson</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>If you have ever used Laravel, you have probably also used Blade. Blade is a simple and powerful template language provided with Laravel. Blade has many wonderful features but one of them, as it relates to WordPress, is how it works with a <a rel="noreferrer noopener" href="https://laravel.com/docs/7.x/blade#the-loop-variable" target="_blank">The Loop</a>.</p>



<p>Normally in the WordPress loop you would set a variable outside of the while statement and increment int. This works fine, but i felt that I was messy.</p>



<p>At a minimum, I wanted to know the first post in the loop so that I could alter its presentation. Naturally adding the last posts in the loop would be a sinch.</p>



<p>After doing some digging into how <code>have_posts()</code> works I realized that it was pulling from <code>$wp_query</code> and since <code>$wp_query</code> has everything that I needed it was just a matter of creating a couple of methods.</p>



<p>Lets start off by creating our basic class, name space it whoever you want.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">class TheLoop
{
    public $index = 0;
    private $wp_query;
    public function __construct()
    {
        global $wp_query;
        $this->wp_query = $wp_query;
    }
}</code></pre>



<p>To keep things clean, I also added <code>have_posts()</code> which is also where I incremented the post loop.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">public function have_posts()
{
    $this->iterate();
    return $this->wp_query->have_posts();
}</code></pre>



<p>Next up we have to increment the post loop, nothing crazy here.<a href=""></a></p>



<pre class="wp-block-code"><code lang="php" class="language-php">private function iterate()
{
    $this->index = $this->index + 1;
}</code></pre>



<p>Now that we have recreated the <code>have_posts()</code> method and are iterating the post index, we can modify our Loop by creating a new instance of <code>TheLoop</code> and replacing  <code>have_posts()</code> with our new method.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">$loop = new Axe\Core\TheLoop;

while ($loop->have_posts()) : the_post();
   // Post Stuff
endwhile;</code></pre>



<p>As you can probably tell, nothing much changed here. If you were to do nothing else, your site would function exactly as it did before. But we have done two things. </p>



<p>We moved now have an instance of <code>$wp_query</code> and are iterating through the posts array tracking its current position.</p>



<p>Lets add two more methods <code>first()</code> and <code>last()</code>.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">public function first()
{
    return ($this->index == 1) ? true : false;
}

public function last()
{
    return ($this->index == count($this->wp_query->posts)) ? true : false;
}</code></pre>



<p>While these should be self-explanatory, first() checks to see if the index is equal to 1. <code>last()</code> checks to see if the index is the same as the total posts count for the current page.</p>



<p>For example, if you had 95 posts and are showing 10 posts per page then the last index would be 10 on the first page while the last index on the final page would be 5.</p>



<p>Let&#8217;s create a very basic example.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">$loop = new Axe\Core\TheLoop;

while ($loop->have_posts()) : the_post();
    if($loop->first()){
        // Do something special for the first post.
    } else {
        // The rest of the posts.
    }
endwhile;</code></pre>



<p>And that&#8217;s it!</p>



<p>If you want to check out the entire code have a look at my starter base theme called <a rel="noreferrer noopener" href="https://github.com/adampatterson/Axe/" target="_blank">Axe</a> and view full code for <a rel="noreferrer noopener" href="https://github.com/adampatterson/Axe/blob/master/lib/Core/TheLoop.php" target="_blank">TheLoop</a>.</p>
<p>The post <a href="https://adampatterson.ca/wordpress/wordpress-loop-helpers/">WordPress Loop Helpers</a> appeared first on <a href="https://adampatterson.ca">Adam Patterson</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1651</post-id>	</item>
		<item>
		<title>Laravel 7 Custom Email Verification Template</title>
		<link>https://adampatterson.ca/general/laravel-7-custom-email-verification-template/</link>
		
		<dc:creator><![CDATA[Adam Patterson]]></dc:creator>
		<pubDate>Fri, 24 Apr 2020 19:43:54 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Laravel]]></category>
		<category><![CDATA[PHP]]></category>
		<guid isPermaLink="false">https://www.adampatterson.ca/?p=1625</guid>

					<description><![CDATA[<p>I will be assuming that you have already got Laravel installed, setup and tour authentication is working. Otherwise, why would you be looking into customizing the email templates? 😁 The Laravel documentation for Email Verification will cover the setup by reading the documentation. But it stops just short of actually explaining how to customize the...</p>
<p>The post <a href="https://adampatterson.ca/general/laravel-7-custom-email-verification-template/">Laravel 7 Custom Email Verification Template</a> appeared first on <a href="https://adampatterson.ca">Adam Patterson</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>I will be assuming that you have already got Laravel installed, setup and tour authentication is working. Otherwise, why would you be looking into customizing the email templates? 😁</p>



<p>The Laravel documentation for <strong>Email Verification</strong> will cover the setup by reading the <a rel="noreferrer noopener" href="https://laravel.com/docs/7.x/verification" target="_blank">documentation</a>. But it stops just short of actually explaining how to customize the email template. I had spent a while trying to figure this out and found that I made it much harder on my self than it needed to be.</p>



<p>Much like customizing your Password Reset emails, we will start off by overwriting the <code>sendEmailVerificationNotification</code> method in our <strong>Users</strong> model.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">public function sendEmailVerificationNotification()
{
    $this->notify(new VerifyEmailNotification());
}</code></pre>



<p>Next create a new notification called <strong>VerifyEmailNotification</strong>.</p>



<pre class="wp-block-code"><code lang="bash" class="language-bash">php artisan make:notification VerifyEmailNotification</code></pre>



<p>Opening up <strong>VerifyEmailNotification</strong> and rather than extending <strong>Notification</strong>, we will extend <strong>VerifyEmail</strong>.</p>



<p>Now <strong>toMail</strong> in our new notification will overwrite the default method allowing us to change the template.</p>



<p>In order for an email verification to work, we are going to need a unique URL for each user, this luckily can be returned from the parent VerifyEmail notification by calling <code>$this-&gt;<em>verificationUrl</em>($notifiable);</code></p>



<p>Our completed <strong>toMail</strong> method will look like this.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">public function toMail($notifiable)
{
    $verificationUrl = $this->verificationUrl($notifiable);

    return (new MailMessage)->view('emails.user.verify', ['url' => $verificationUrl]);
}</code></pre>



<p>I opted to use the Blade templates for my emails, so I can output the URL on a CTA in the mail simply by writing <code>{{ $url }}</code>.</p>



<p>As I mentioned previously, I had trouble getting this to work as I expected. I wad incorrectly trying to trigger <strong>sendEmailVerificationNotification</strong> on the <strong>User</strong> model, which resulted in null values for the tokens.  </p>



<p>The only way I found to trigger the notification was to create new test accounts.</p>



<p>I hope this helps you out, and if you know how to manually trigger the Verification notification then please let me know!</p>
<p>The post <a href="https://adampatterson.ca/general/laravel-7-custom-email-verification-template/">Laravel 7 Custom Email Verification Template</a> appeared first on <a href="https://adampatterson.ca">Adam Patterson</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1625</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/

Database Caching 3/7 queries in 0.002 seconds using Redis

Served from: adampatterson.ca @ 2024-09-09 01:32:13 by W3 Total Cache
-->