You appear to be a bot. Output may be restricted
Description
Validate the action against the given parameters
-import – Copy the source content into a new post -update – Update the local (target) post -compare – Compare the contents of each post -delete – Delete the local (target) post -undo – Undo the most recent revision to the local (target) post
action | source | target | Processing |
---|---|---|---|
import | – | – | Invalid – neither source not target set |
import | – | set | Invalid – no |
import | set | – | Import into a new post with the same post type – or selected post type |
import | set | set | Update the target post with the contents from the source – including ALL post meta |
update | – | – | Invalid |
update | – | set | Invalid |
update | set | – | Invalid – action should be import – so we just do that |
update | set | set | same as for Import |
delete | n/a | – | |
delete | n/a | set | |
undo | set | ||
compare | set | set | Compare the two posts. Any other combination is invalid |
Usage
oik_clone_validate_action( $action, $source, $target );
Parameters
- $action
- ( mixed ) required –
- $source
- ( mixed ) required –
- $target
- ( mixed ) required –
Returns
void
TO DO
Should we invoke a filter to find out which actions are supported or do we make them classes and invoke a method?
Source
File name: oik-clone/admin/oik-clone-actions.php
Lines:
1 to 55 of 55
function oik_clone_validate_action( $action, $source, $target ) { $valid = false; switch ( $action ) { case "import": if ( $source ) { p( "Performing import" ); if ( $target ) { p( "updating post $target from $source" ); $action = "update"; } else { p( "creating new post from $source" ); } } else { p( "Invalid - no source specified" ); } $valid = $action; break; case "update": if ( $source ) { p( "Performing update" ); if ( $target ) { p( "updating post $target from $source" ); } else { p( "creating new post from $source" ); $action = "update"; } } else { p( "Invalid - no source specified" ); } $valid = $action; break; case "compare": if ( $source && $target ) { $valid = $action; } break; case "delete": case "undo": // It must be the target that's set case "view": // It must be either the source of the target that's set case "edit": // It must be the target that's set default: // It's invalid } return( $valid ); }