/** * Handles static insertion for posts. * * @remark Only category taxonomy allow/deny check is supported. Other types post_tags and custom taxonomies are not supported yet. */ public function doFilterForStaticInsertion($arrPostContent, $arrPostMeta = array()) { // if the publish key exists, it means it is an update if (isset($arrPostMeta['save']) && $arrPostMeta['save'] == 'Update') { return $arrPostContent; } // If it's auto-draft saving feature, do nothing. if (isset($arrPostContent['post_status']) && $arrPostContent['post_status'] != 'publish') { return $arrPostContent; } // The default disabled post types. if (in_array($arrPostContent['post_type'], array(AmazonAutoLinks_Commons::PostTypeSlug, AmazonAutoLinks_Commons::PostTypeSlugAutoInsert, 'revision', 'attachment', 'nav_menu_item'))) { return $arrPostContent; } /* $arrPostMeta structure [ID] => 278 [post_category] => Array ( [0] => 0 [1] => 10 [2] => 9 [3] => 1 ) [tax_input] => Array( [post_tag] => test ) */ $arrSubjectPostInfo = array('post_id' => $arrPostMeta['ID'], 'post_type' => $arrPostContent['post_type'], 'term_ids' => $arrPostMeta['post_category']) + self::$arrStructure_SubjectPageInfo; $strPre = ''; $strPost = ''; foreach ($this->arrFilterHooks['wp_insert_post_data'] as $intAutoInsertID) { if (!$this->isAutoInsertEnabledPage($intAutoInsertID, $arrSubjectPostInfo)) { continue; } $arrAutoInsertOptions = $this->arrAutoInsertOptions[$intAutoInsertID]; // position - above, below, or both, $strPosition = $arrAutoInsertOptions['static_position']; if ($strPosition == 'above' || $strPosition == 'both') { $oUnits = new AmazonAutoLinks_Units(array('id' => $arrAutoInsertOptions['unit_ids'])); $strPre .= $oUnits->getOutput(); } if ($strPosition == 'below' || $strPosition == 'both') { $oUnits = new AmazonAutoLinks_Units(array('id' => $arrAutoInsertOptions['unit_ids'])); $strPost .= $oUnits->getOutput(); } } $arrPostContent['post_content'] = $strPre . $arrPostContent['post_content'] . $strPost; return $arrPostContent; }