Hacking WordPress The Ugly And Quick Way

Recently I’ve started a little project to see how I can do with IDN affiliate sites where there is a lot less competition than in English.

I’ve started out with Thai and selling a few casinos that are targeting Thais, ie they have the site translated to Thai and are supporting play with Thai baht.

I knew I wanted to base my site on WordPress and first out is / was tackling the ubiquitous table of casino reviews that is so common in the casino affiliate business. There is a reason for that, it offers a good overview for comparisons which might be all the visitor needs to make a decision, and if not every gambling site has its own review page one can click through to by way of a link in the table.

All this can be seen on the front page of the site คาสิโน.ws.

Let’s get to it on how this was accomplished without hacking custom proper plugins etc. First we take a look at the content-page.php of my theme which is basically a copy paste of the included twentyfifteen theme. Everything is basically happening at the top where I include review-list.php which defines a couple of my own functions, more on that later.

Note how I first store the content that WordPress could’ve normally just echoed and doing the same with my own content (the review table).

Further down I do a string replace with the help of the content stored in $the_content and the review table in $reviews. If I write {{reviews}} in the content it will be substituted with the review table.

require_once 'review-list.php';
$the_content = ob_get_clean();
$reviews = ob_get_clean(); 
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  // Post thumbnail.

  <header class="entry-header">
    <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>

  <div class="entry-content">
    <?php echo str_replace('{{reviews}}', $reviews, $the_content); ?>
    wp_link_pages( array(
      'before'      => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentyfifteen' ) . '</span>',
      'after'       => '</div>',
      'link_before' => '<span>',
      'link_after'  => '</span>',
      'pagelink'    => '<span class="screen-reader-text">' . __( 'Page', 'twentyfifteen' ) . ' </span>%',
      'separator'   => '<span class="screen-reader-text">, </span>',
    ) );

  <?php edit_post_link( __( 'Edit', 'twentyfifteen' ), '<footer class="entry-footer"><span class="edit-link">', '</span></footer>' ); ?>


Let’s continue with the contents of review-list.php.

Note that I’m using the WordPress database object and its get_results method, for access to my own wp_reviews MySQL table which basically looks like the real table which can be seen on the site linked to above. I have not bothered to create any hooks into wp admin to administer the wp_reviews table, I simply edit it directly with PHPMyAdmin.

As you can see I’ve rolled my own little translation logic by way of a simple text file. I couldn’t really see how I could get things to be in Thai whilst keeping the wp admin in English in any other way.

function aff_reviews(){
  global $wpdb;
  $base_path = '/wp-content/themes/wpaff/';
  $reviews = $wpdb->get_results("SELECT * FROM wp_reviews ORDER BY ordering");
  $ths = array(_tr('Casino'), _tr('Language'), _tr('Welcome Bonus'), _tr('Free Spins'), _tr('Score'), _tr('Review'), '');
  <table class="review-table">
        <th><?php echo $ths[0] ?></th>
          <?php echo $ths[1] ?>
        <th><?php echo $ths[2] ?></th>
        <th><?php echo $ths[3] ?></th>
        <th><?php echo $ths[4] ?></th>
        <th><?php echo $ths[5] ?></th>
        <th><?php echo $ths[6] ?></th>
    <?php foreach($reviews as $r): ?>
        <td><img class="logo-img" src="<?php echo $base_path."logos/{$r->logo}.png" ?>"/></td>
          <img class="lang-img" src="<?php echo $base_path."images/{$r->lang}.png" ?>"/>
        <td><?php echo $r->cur_sign.$r->welcome_bonus ?></td>
        <td><?php echo $r->free_spins.' '._tr('Free Spins') ?></td>
        <td><img src="<?php echo $base_path."images/grade{$r->score}.png" ?>"/></td>
        <td><a href="<?php echo $r->review_link ?>/"><?php echo $r->casino_name ?></a></td>
        <td><a class="goto-btn" target="_blank" rel="nofollow" href="<?php echo $base."go.php?casino={$r->go_link}" ?>"><?php echo _tr('Get Bonus!') ?></a></td>
    <?php endforeach ?>

function _tr($str){
  	return $_SESSION['aff_tr'][$str];
  $map = array();
  foreach(file(__DIR__ . '/translations.txt') as $line){
    $tmp = list($eng, $val) = explode('||', $line);
    $map[$eng] = $val;
  $_SESSION['aff_tr'] = $map;
  return empty($map[$str]) ? $str : $map[$str];

And for reference, the contents of the translation file:

Welcome Bonus||ยินดีต้อนรับโบนัส
Free Spins||ฟรีสปิน
Get Bonus!||รับโบนัส !

And that’s it, now you know how to do your own quick modifications / additions to inject content here and there. I’m doing review tables but one can easily imagine inserting ads instead, ads that are being rotated between various ad providers perhaps, with some A/B testing to see what performs best.

Related Posts

Tags: ,