Skip to content
This repository
Browse code

Initial commit: skeleton of the plugin

  • Loading branch information...
commit 7e0674e2c7eb0e36b38caf384313023509b356f3 0 parents
Daniel Bachhuber danielbachhuber authored

Showing 2 changed files with 127 additions and 0 deletions. Show diff stats Hide diff stats

  1. +127 0 ad-code-manager.php
  2. 0  readme.txt
127 ad-code-manager.php
... ... @@ -0,0 +1,127 @@
  1 +<?php
  2 +/*
  3 +Plugin Name: Ad Code Manager
  4 +Plugin URI: http://automattic.com
  5 +Description: Easy ad code management
  6 +Author: Daniel Bachhuber, Rinat Khaziev, Automattic
  7 +Version: 0.0
  8 +Author URI: http://automattic.com
  9 +
  10 +GNU General Public License, Free Software Foundation <http://creativecommons.org/licenses/GPL/2.0/>
  11 +
  12 +This program is free software; you can redistribute it and/or modify
  13 +it under the terms of the GNU General Public License as published by
  14 +the Free Software Foundation; either version 2 of the License, or
  15 +(at your option) any later version.
  16 +
  17 +This program is distributed in the hope that it will be useful,
  18 +but WITHOUT ANY WARRANTY; without even the implied warranty of
  19 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20 +GNU General Public License for more details.
  21 +
  22 +You should have received a copy of the GNU General Public License
  23 +along with this program; if not, write to the Free Software
  24 +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25 +
  26 +*/
  27 +define( 'AD_CODE_MANAGER_VERSION', '0.0' );
  28 +define( 'AD_CODE_MANAGER_ROOT' , dirname(__FILE__) );
  29 +define( 'AD_CODE_MANAGER_FILE_PATH' , AD_CODE_MANAGER_ROOT . '/' . basename(__FILE__) );
  30 +define( 'AD_CODE_MANAGER_URL' , plugins_url( plugin_basename(dirname(__FILE__)).'/') );
  31 +
  32 +class Ad_Code_Manager
  33 +{
  34 +
  35 + var $ad_tags = array();
  36 + var $script_url_whitelist = array();
  37 +
  38 + /**
  39 + * Instantiate the plugin
  40 + *
  41 + * @since ??
  42 + */
  43 + function __construct() {
  44 +
  45 + add_action( 'init', array( &$this, 'action_init' ) );
  46 + add_action( 'admin_init', array( &$this, 'action_admin_init' ) );
  47 +
  48 + }
  49 +
  50 + /**
  51 + * Code to run on WordPress' 'init' hook
  52 + *
  53 + * @since ??
  54 + */
  55 + function action_init() {
  56 +
  57 + // Allow new domains to be whitelisted
  58 +
  59 +
  60 + // Ad tags are only run on the frontend
  61 + if ( !is_admin() ) {
  62 + require_once AD_CODE_MANAGER_ROOT . '/template-tags.php';
  63 + add_action( 'acm_tag', array( &$this, 'action_acm_tag' ) );
  64 + }
  65 +
  66 + }
  67 +
  68 + /**
  69 + * Code to run on WordPress' 'admin_init' hook
  70 + *
  71 + * @since ??
  72 + */
  73 + function action_admin_init() {
  74 +
  75 + // @todo conditionally load the admin interface if that's enabled
  76 + // The admin interface should be enabled by a filter and off by default
  77 + // We'll need additional methods for:
  78 + // - Displaying the interface
  79 + // - Saving the data
  80 + // - Loading the ad codes in the database and registering them
  81 + // with the plugin using
  82 +
  83 + }
  84 +
  85 + /**
  86 + * Register an ad tag with the plugin so it can be used
  87 + * on the frontend of the site
  88 + *
  89 + * @since ???
  90 + *
  91 + * @param string $tag Ad tag for this instance of code
  92 + * @param string $script URL for ad tag
  93 + * @param array $where WordPress-style conditionals for where this code should be displayed
  94 + * @param int $priority What priority this registration runs at
  95 + * @param array $url_vars Replace tokens in $script with these values
  96 + * @return bool|WP_Error $success Whether we were successful in registering the ad tag
  97 + */
  98 + function register_ad_tag( $tag, $script, $where = array(), $priority = 10, $url_vars = array() ) {
  99 +
  100 + // @todo Run $script aganist a whitelist to make sure it's a safe URL
  101 + // @todo Sanitize all of the other input
  102 +
  103 + // @todo logic for saving the ad tag to $this->ad_tags so it's available to $this->action_acm_tag()
  104 + }
  105 +
  106 + /**
  107 + * Display the ad code based on what's registered
  108 + * and complicated sorting logic
  109 + *
  110 + * @uses do_action( 'acm_tag, 'your_tag_id' )
  111 + */
  112 + function action_acm_tag( $tag_id ) {
  113 +
  114 + // @todo possibly complicated logic for determining which
  115 + // script is executed while factoring in:
  116 + // - where it should be displayed
  117 + // - priority against other ad tags
  118 +
  119 + // @todo Parse the script URL and replace with any $url_vars
  120 +
  121 + echo '<script type="text/javascript" src="' . esc_url( $tag_url ) . '"></script>';
  122 +
  123 + }
  124 +
  125 +}
  126 +global $ad_code_manager;
  127 +$ad_code_manager = new Ad_Code_Manager();
0  readme.txt
No changes.

0 comments on commit 7e0674e

Please sign in to comment.
Something went wrong with that request. Please try again.