Requirements
- Target to map source post IDs to target post IDs within post content
- Post content fields supported to include: post_content, post_excerpt, post_title and (possibly) post_content_filtered
- Mapping should also be performed on postmeta fields which support links and/or shortcode expansion: text, textarea and other specialized fields
- Mapping to be performed against integers which can be identified as IDs by the context in which they’re used; parameters to shortcodes, within links.
- Optional mapping of source to target URLs
- Ability to prevent mapping, for certain edge cases
Example
Suppose the post content contains the [gallery] shortcode using theids=
parameter.
which contains a sequence of post IDs of the attached images to display.
Each of the source image’s post IDs will need to be mapped to a different target post ID.
So “gallery ids=s1,s2,s3″ will become “gallery ids=t1,t2,t3″
Note: I’ve used prefixes to the post IDs to prevent mapping when this requirement gets cloned.
Other examples
There are zillions of shortcodes which use IDs to identify the content to be included or excluded. Here are just a few examples, again using sn for post IDs and http://example.com for the source domain which may also need to be mapped.
[bw_link s1]
[nivo ids=s1,s2,s3]
<a href="http://example.com?p=s1">Link to s1 on http://example.com</li>
<a href="http://elsewhere.com?p=s1">Link to a different s1 on another domain</li>
I have been thinking about addressing this problem for nearly s2 years now.
[bw_pages posts_per_page=s3]
e.g. The source of this page is http://example.com/?p=s1
It has been cloned to http://example.biz/?p=t1
Proposed solution
Source- Parse for IDs in the content
- For each ID found determine the target mapping
- Include this in the ‘mapping’ array
- Parse for IDs in the content
- For each ID found lookup the target mapping
- Verify the target mapping
- Apply the mapping to the content
Exclusions
The proposed solution doesn’t take into account all the other instances where unique IDs are used to identify content:
- IDs associated with taxonomies
- IDs associated with users
- IDs associated with WordPress Multisite blogs
- IDs associated with Comments
- IDs which reference content in custom tables
- IDs stored in the options table
The proposed solution doesn’t cater for logic which ensures that slug names are unique
oik-clone – Technical requirements