programmatically add wpml string translation

First we need to register the string on wpml translation table.

The above function will return a string_id and we will need this id for icl_add_string_translation() function to add labels for other languages.

Alternatively, we can use icl_get_string_id() to get the string_id as:

How to Set an Expires Header in Apache

Enalbe mod_expires on server
LoadModule expires_module modules/mod_expires.so

present a pdf file for download via PHP after checking some rules

First we create a rule on htaccess and redirect the pdf files to a php with its path as query string

The sample code for the pdf-viewer.php.

Remove illegal characters from files during uploading on wordpress

wp_handle_upload_prefilter allows user to change the files during uploads.
http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_handle_upload_prefilter

ex.

Remove unnecessary
tags inside shortcodes by postponing the wp_autop

remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 12);

What is the difference between inversedBy and mappedBy on Doctrine?

  • mappedBy has to be specified on the inversed side of a (bidirectional) association
  • inversedBy has to be specified on the owning side of a (bidirectional) association

from doctrine documentation:

  • ManyToOne is always the owning side of a bidirectional assocation.
  • OneToMany is always the inverse side of a bidirectional assocation.
  • The owning side of a OneToOne assocation is the entity with the table containing the foreign key.

doctrine documentation:
http://docs.doctrine-project.org/en/latest/reference/unitofwork-associations.html