/** * 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($aPostContent, $aPostMeta = array()) { // if the publish key exists, it means it is an update if (isset($aPostMeta['save']) && $aPostMeta['save'] == 'Update') { return $aPostContent; } // If it's auto-draft saving feature, do nothing. if (isset($aPostContent['post_status']) && $aPostContent['post_status'] != 'publish') { return $aPostContent; } // The default disabled post types. if (in_array($aPostContent['post_type'], array(AmazonAutoLinks_Registry::$aPostTypes['unit'], AmazonAutoLinks_Registry::$aPostTypes['auto_insert'], 'revision', 'attachment', 'nav_menu_item'))) { return $aPostContent; } /* $aPostMeta structure [ID] => 278 [post_category] => Array ( [0] => 0 [1] => 10 [2] => 9 [3] => 1 ) [tax_input] => Array( [post_tag] => test ) */ $aSubjectPostInfo = array('post_id' => $aPostMeta['ID'], 'post_type' => $aPostContent['post_type'], 'term_ids' => $aPostMeta['post_category']) + self::$aStructure_SubjectPageInfo; $sPre = ''; $sPost = ''; foreach ($this->aFilterHooks['wp_insert_post_data'] as $iAutoInsertID) { if (!$this->isAutoInsertEnabledPage($iAutoInsertID, $aSubjectPostInfo)) { continue; } $aAutoInsertOptions = $this->aAutoInsertOptions[$iAutoInsertID]; // position - above, below, or both, $sPosition = $aAutoInsertOptions['static_position']; if ($sPosition == 'above' || $sPosition == 'both') { $oUnits = new AmazonAutoLinks_Output(array('id' => $aAutoInsertOptions['unit_ids'])); $sPre .= $oUnits->get(); } if ($sPosition == 'below' || $sPosition == 'both') { $oUnits = new AmazonAutoLinks_Output(array('id' => $aAutoInsertOptions['unit_ids'])); $sPost .= $oUnits->get(); } } $aPostContent['post_content'] = $sPre . $aPostContent['post_content'] . $sPost; return $aPostContent; }