refactoring wordpress code