Just open up your php.ini file and set error_reporting to error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED.
Insert an image into a WordPress Post with a plugin.
So in a project I’m working on I need to use a normal form to insert a post into the database. My client wanted the form to also add an image to the post. Furthermore, the image must be inserted using normal WordPress methods. The code below is the minimum required to insert an image into the database and attach it to a specific post.
include_once(ABSPATH.'/wp-admin/includes/media.php');
include_once(ABSPATH.'/wp-admin/includes/file.php');
include_once(ABSPATH.'/wp-admin/includes/image.php');
// $id is the id of the post being inserted
// $name is actually the name of the form input that uploaded the file so WP can access it using $_FILE[$name]
media_handle_upload($name,$id);
If you are inserting a new post, it makes sense to have the line $id = wp_insert_post($post_data); before this.
I’m alive but still not talking to you.
There have been no posts for a while now and none of the updates to AJAXed WordPress or my other plugins have been pushed out. There is a lot of stuff (of the good kind) that is going on in my life currently, so I’ve put everything else on the back burner.
Thank you for your understanding.
P.S. Don’t you hate posts like this? Me too!
Short Ajax Script
I wanted to see how small you could make a fully functional AJAX script that worked cross-browser and degraded gracefully, so I went through an old custom AJAX script and made it as small as I possibly could. In the resulting AJAX scripts, the post version is 410 characters and the GET version is only 359 characters long. The scripts are fully functional and accept the following parameters: URL, DATA (in string form), and ELEMENT (to update).
The scripts could be a little smaller, but it would really kill readability.
“Get” AJAX Script
function a(l,d,u){
try{r = new XMLHttpRequest();}catch(e){try {r = new ActiveXObject('Msxml2.XMLHTTP');}catch(e){r = new ActiveXObject('Microsoft.XMLHTTP');}}
if(r){
r.onreadystatechange = function() {if (r.readyState == 4 && r.status == 200){document.getElementById(u).innerHTML = r.responseText;}}
r.open('GET', l+'?'+d, true);r.send(d);
}
}
“Post” AJAX Script
function b(l,d,u){
try{r = new XMLHttpRequest();} catch(e){try {r = new ActiveXObject('Msxml2.XMLHTTP');} catch(e){r = new ActiveXObject('Microsoft.XMLHTTP');}}
if(r){
r.onreadystatechange = function() {if (r.readyState == 4 && r.status == 200){document.getElementById(u).innerHTML=r.responseText;}}
r.open('POST', l, true);r.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');r.send(d);
}
}
Combined AJAX Script
This combined script also accepts a fourth parameter ‘p’ that should evaluate true if the data is to be sent by post.
function a(l,d,u,p){
try{r = new XMLHttpRequest();}catch(e){try {r = new ActiveXObject('Msxml2.XMLHTTP');}catch(e){r = new ActiveXObject('Microsoft.XMLHTTP');}}
if(r){
r.onreadystatechange = function() {if (r.readyState == 4 && r.status == 200){document.getElementById(u).innerHTML = r.responseText;}}
if(p){r.open('POST', l, true);r.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');}else{r.open('GET', l+'?'+d, true);}
}
}
Demo: (Sorry but you will have to go to the full page so the JavaScript is loaded.) Continue reading
Oh I am a gummy bear; yes, I am a gummy bear…
The best thing to come out of YouTube since the Kiwi: the Gummy bear song.
Oder, ich bin ein gummi Bär; ich bin ein gummi Bär.
All right, all right. Back to your regularly scheduled broadcasting.
Equality, the goal not the signpost.
The United States of America has a long history of inequality, from its treatment of Native Americans to women’s rights, it has tended to favor one group over others, but it has attempted to repair the damage it caused. However, even though America is the “land of opportunity,” its formerly oppressed peoples are not equal, but what does it mean to be equal? Is equality the government saying you must have the same number of employees from each arbitrarily defined “race?” Does equality mean that people should be forced to be equal? In examining this issue, one must define equality itself.
There are three forms of equality: equality of outcome, of opportunity, and of perception. Equality of perception is the most basic: it dictates that for people to be equal, each person should be perceived as being of equal worth. Equality of opportunity dictates that all people should have the same opportunities open to them if they put out the effort this is a central tenet of the “American Dream.” The final form of equality, equality of outcome, attempts to “level the playing field” by forcing people into certain roles and dictates that all individuals should tend towards the mean this form of equality is evident in socialist theory.
America has enacted laws that are based on equality of outcome to attempt to ensure that “minorities” and women have access to equal pay and to remove glass ceilings, but while these programs have repaired some of the damage, paraphrasing Milton Friedman, equality of outcome leaves most people without equality and without opportunity. This is because forced equality is not equality and only hides the real issue of inequality based on perceptions.
Equality is not saying that all people are physically and mentally equal, nobody would bet an average teenager could win a game of basketball against a professional player, nor can every six-year-old be a physicist because human beings are not inherently equal. However, “true equality” says that potentially everyone should have the same opportunities, that is to say, that potentially the toddler could play professional basketball and potentially the six-year-old could become a future Einstein regardless of superficial characteristics. While these two people may not actually be able to achieve their dreams, this does not mean they should be limited by what people perceive they are capable of. This is equality of perception.
Unlike equality of outcome, equality of perception creates equality of opportunity by dictating that all people should be allowed the same opportunities even if they aren’t capable of realizing them. This allows people to reach their own plateaus without unfair external pressures. However, when one attempts to use equality of outcome to create opportunity, one must take away opportunities from one person to give them to another, rather than allowing both individuals to reach their own, personal, peaks. This is not always a bad thing, during the civil rights era it was an important move to integrate America’s divided society; however, it was a first step, and only a first step. America must move beyond this first step to continue to answer its call as the “land of opportunity.”
Of course, many factors come into account throughout individual lives that change an individual’s capacity for different activities. Equality of perception requires that one realize the way we perceive people based on bias should not limit their opportunities because it does not reflect their abilities. This means that with equality of perception no human being is artificially kept from achieving their goals based on skin color, religion, national origin, or class. Equality of perception cannot be legislated, it can only be taught, but it will create freedom and lead the way to equality of opportunity, but focusing on equality of outcome just limits the freedoms upon which America was founded.
