[wp-hackers] Enthusiastic working with WordPress for GSoC 2014

Ian Dunn ian at iandunn.name
Sat Mar 1 22:17:21 UTC 2014


On 3/1/14, 4:25 AM, Quincy Kwende wrote:
> I'm a student looking forward to take part in GSoC 2014. I would love to take part in the Form / Survey Plugin.
> In preparation for my participation, I have written a plugin by name "Quote me"(https://github.com/quincykwende/quote-me).
> I would be grateful if am pointed to the right direction.


Hi Quincy, we haven't started accepting applications yet, but keep an 
eye on the Codex page for specific instructions open up applications.

In the mean time, I skimmed through some of the code you referenced. I 
think you did a great job keeping it modular and organized (small 
functions that do 1 thing, files grouped into directories, etc); it's 
really nice to see that.

In most cases, you don't need to add custom database tables for your 
data, and it's considered a bad practice. Custom Post Types would be the 
appropriate way to implement a data store and CRUD interface for quotes. 
There should be plenty of articles about this on the web if you look around.

Check out the official coding standards on the Core Contributor 
Handbook. You're pretty close, but there are a few differences around 
white space. More is usually better :)


Instead of doing something like:

//sample data
	$value_1 = array( 'create_date' => time(), 'quote' => 'People eat meat 
and think they will become as strong as an ox, forgetting that the ox 
eats grass.', 'author' => 'Pino Caruso',);
	$value_2 = array( 'create_date' => time(), 'quote' => 'Nothing will 
benefit human health and increase the chances for survival of life on 
Earth as much as the evolution to a vegetarian diet.', 'author' => 
'Albert Einstein' );
	$value_3 = array( 'create_date' => time(), 'quote' => 'If you don\'t 
want to be beaten, imprisoned, mutilated, killed or tortured then you 
shouldn\'t condone such behaviour towards anyone, be they human or 
not.', 'author' => 'Moby');
	$value_4 = array( 'create_date' => time(), 'quote' => 'My body will not 
be a tomb for other creatures.', 'author' => 'Leonardo Da Vinci') ;

     //insert sample data
	$wpdb->insert( $table_name,  $value_1);
	$wpdb->insert( $table_name,  $value_2);
	$wpdb->insert( $table_name,  $value_3);
	$wpdb->insert( $table_name,  $value_4);



...you could just do:


$current_time() = time();

$values = array(
     array( 'create_date') => $current_time, 'quote' => '...', 'author' 
=> '...' ),
     array( 'create_date') => $current_time, 'quote' => '...', 'author' ),
     array( 'create_date') => $current_time, 'quote' => '...', 'author' ),
);

foreach ( $values as $value ) {
     $wpdb->insert ( $table_name, $value );
}

Also, $value isn't very meaningful as a variables name; it's generic and 
could refer to almost anything. $quotes would be better because it's 
specific and helps make the code self-documenting. Write the code with 
the expectation that another developer will come along 6 months later 
and will need to be able to quickly read the code and understand what's 
going on.


Good luck with your application, and don't hesitate to reach out if you 
have any other questions :)


More information about the wp-hackers mailing list