/** * Called remotely via AJAX notification. * Creates new pending ad slot. * @param void. * @return void */ public static function remoteCreateSlot() { // Data instance $data = new self(); // Compare tokens $clientToken = $_GET['dfp_token']; $serverToken = get_option('dfpSyncToken'); if ($clientToken !== $serverToken) { Auto_DFP_Admin::log('"CREATE SLOT" FAILED: TOKENS DID NOT MATCH.'); return FALSE; } // Format size $fSize = $_GET['dfp_tag_size']; $fSize = str_replace(' ', '', $fSize); $fSize = str_replace('X', 'x', $fSize); // Create size array for adUnit $size = explode('x', $fSize); // Make sure there's no spaces $adUnit = str_replace(' ', '_', $adUnit); // Get page id $page = intval($_GET['new_dfp_tag']); // Check slot can be created if (!$page || !$size) { Auto_DFP_Admin::log('Invalid new adUnit with: size=' . $_GET['dfp_tag_size'] . '&new_dfp_tag=' . $_GET['new_dfp_tag']); return FALSE; } // Build adUnit name $pageAtts = get_page($page); $adUnit = get_bloginfo('name'); $ancestors = $pageAtts->ancestors; // If page is not top level, build ad name based on ancestors if (count($ancestors)) { $ancestors = array_reverse($ancestors); foreach ($ancestors as $id) { $adUnit .= '_' . get_page($id)->post_name; } } $adUnit .= '_' . $pageAtts->post_name . '_' . $fSize; // Make sure there's no spaces $adUnit = str_replace(' ', '_', $adUnit); // Create slot $result = $data->createSlot($adUnit, $page, $size); }