Upload In WordPress Not Working On Localhost

Problem:

When uploading pictures to WordPress on localhost in the WordPress uploader an error occurs.

 

Solution:

There is most likely something wrong with your local folder permissions. It is making it so that your local copy of WordPress can’t create a new folder for your uploaded files. Change all the folders permissions to be able to write files.

That should do the trick.

MAMP Local Server Permissions

I recently was working with WordPress on my local server using the mac based software MAMP.

Problem:

My theme is not appearing in my choices in WordPress.

Solution:

After doing a quick search, this more than likely seemed to be a permissions issue. Normally, you would change these permission by right clicking the files and changing the permission in your FTP software.

In my case, since this is a local server, I must change my permissions on my computer.

To do this, I  Right Click > Get Info > Scroll Down > Arrow Down Tab Labeled “Sharing & Permissions” > Change Permissions To “Read & Write”

Problem 2:

Being the slightly lazy when it comes to tasks like this, I wanted to change all permissions of all files at once rather than having to go an individually have to rinse and repeat this task over and over.

Solution 2:

Select the folder that you want to change the permissions on, then follow the directions above. Then…

Click the Lock Icon In The Bottom Right Corner > Enter Your Password > Click the Gear Icon At The Bottom Selecting the Dropdown > Select “Apply to Encosed Items” > Click OK

Note: There may be some permissions that this doesn’t fix such as a user not listed on the folder permissions but the user is listed on a particular file within the folder.

Passing Variables Between Functions In PHP

As the title states, we will be passing variables between functions.

Why is this important?

Functions sometimes need to share a piece of data. Or depending on what you are doing you might want all functions in that file to share a variable (also known as global variables).

The first way to pass the variable is to call another function within the first function:

<?php
 
firstFunction(); //Calls first function to show you the output was successful
 
function firstFunction(){
 
	$myVariable="It works!"; //Declare your variable
 
	secondFunction($myVariable); // Call your other function with variable parameter
 
return;
}
 
function secondFunction($myVar){ //Declare your 2nd Function and variable name in ()'s can be new
 
	echo $myVar; //Outputs the variable
 
return;
}
 
?>

Now the other way is to redefine the variable using a function:

<?php
 
$myVariable='The first value of this variable.';
 
echo $myVariable; // Outputs the first value of $myVariable
 
$myVariable = anotherFunction(); // Takes the value of anotherFunction and assigns it as the new variable for $myVariable
 
echo $myVariable; // Outputs the second value of $myVariable
 
function anotherFunction(){ //function that is called above that gives a new value
 
	$anotherVariable = 'Another value.'; // Creates another value
 
	return $anotherVariable; //returns that other value making the value of anotherFunction() = Another value.
}
 
?>

There are probably a number of other combinations that can be done. These are just 2 to get the job done.

Searching The Pages of An URL With A Bookmark

I find myself constantly searching the same sites for different thing. In my case, I wanted to search WordPress plugins quickly through Google.

I am constantly typing the same Google operators

site:websiteiwant.com/plugins/ + plugin keyword

over and over.

Problem:

A Google Chrome plugin which could save your search queries and reduce the redundancy of typing the search operators.

Solution:

  1. Simply go to Google without being logged in.
  2. Type in whatever your constant will be.
    site:websiteiwant.com/plugins/
  3. Bookmark it.
  4. Use to your hearts content.
  5. Conclusion

    I know its painfully easy, but I thought I would share how I made searching the same thing over and over, easier.

Calling Functions For A WordPress Plugin From A Separate File

So I searched all over trying to find the answer to this.

I’m relatively new to WordPress Plugin Development. Most plugins that I use with WordPress are composed of multiple files.

My goal was to have the functions in a centralized location, in a separate file similar to how most WordPress themes have a functions.php file.

After searching I don’t know how many times and phrases I ended up playing around with some plugins that I have and see if I could find what they did to accomplish this goal.

Lets Get Started

Lets call our plugin BrandardPlugin. For this example it will consist of 2 files:

BrandardPlugin.php

– Your main file.

functions.php

– Additional file, obviously containing functions.

Step 1: Coding the Main File

  1. Initialize the main function.
    add_action( 'init', 'bp_init' );
    //Change 'bp_init' to whatever your function will be named.
  2. Create that function, we’ll call it bp_init.
    function bp_init()
    {
    //This is where your external file will be named.
    }
  3. Inside the function (bp_init) add either
    include_once( dirname(__FILE__) . '/function.php' );

    Note:Can also be require_once

Step 2: Coding the Function File

  1. Create a php file the way you normally would.
    <?php 
    ?>
  2. Add a standard function.
    function thisFunction()
    {
    //This is what your function does.
    }

Step 3: Calling The Function

  1. In the Main file call the function.
    thisFunction();

Conclusion

There you have it.  This can be used by most files to communicate with one another in your plugin.