dimayakovlev / getsimple-cms-extended

GetSimple CMS Extended
https://github.com/dimayakovlev/getsimple-cms-extended
GNU General Public License v3.0
1 stars 0 forks source link

New actions on page cloning #36

Closed dimayakovlev closed 3 years ago

dimayakovlev commented 3 years ago

New actions:

dimayakovlev commented 3 years ago

Maybe better to add filter to filter clone page object instead page-clone action.

dimayakovlev commented 3 years ago

Maybe better to add filter to filter clone page object instead page-clone action.

Function XMLsave() execute filter xmlsave, so no need to add another filter. Plugins developers can use page-clone action to register xmlsave filter and it will be executed before saving cloned page object.

dimayakovlev commented 3 years ago

Example of using page-clone action to register filter xmlsave.

add_action('page-clone', function() {
  add_filter('xmlsave', function($xml) {
    $xml = new SimpleXMLElement($xml);
    $attr = $xml->attributes();
    if (isset($attr['counter'])) {
      $xml->attributes()->cloned = (int)$attr['counter'] + 1;
    } else {
      $xml->addAttribute('counter', 1);
    }
    return $xml->asXML();
  });
});