public static function fix_toolset_association_on_import_export($layout, $action = 'export', $args = array()) { if (null === $layout) { throw new Exception(__(sprintf("Layout parameter should be an object, %s given.", gettype($layout)), 'ddl-layouts')); } $args = apply_filters('ddl-fix_toolset_association_on_import_export-data', $args, $layout, $action); if (!is_array($args) || sizeof($args) === 0) { throw new Exception(__(sprintf("Third argument should be an array containing at least one object with 'property', 'post_type' and 'db_field' properties. Argument has size of %d instead.", sizeof($args)), 'ddl-layouts')); } foreach ($layout as $key => $val) { if (is_object($val) || is_array($val)) { foreach ($args as $arg) { $arg = (object) $arg; if (is_object($val) && property_exists($val, $arg->property)) { if ('export' === $action) { $value = WPDD_Layouts::get_post_property_from_ID((int) $val->{$arg->property}, $arg->db_field); if ($arg->property == 'target_id') { $value = $value . ';' . WPDD_Layouts::get_post_property_from_ID((int) $val->{$arg->property}, 'post_type'); } } elseif ('import' === $action) { if ($arg->property == 'target_id') { $temp = explode(';', $val->{$arg->property}); if (isset($temp[0]) && isset($temp[1])) { $val->{$arg->property} = $temp[0]; $arg->post_type = $temp[1]; } } $value = WPDD_Layouts::get_post_ID_by_slug($val->{$arg->property}, $arg->post_type); } if ($value && is_null($value) === false) { $val->{$arg->property} = $value; } } } try { self::fix_toolset_association_on_import_export($val, $action, $args); } catch (Exception $e) { printf("Error: %s in %s at %d", $e->getMessage(), $e->getFile(), $e->getLine()); } } if (is_object($layout)) { $layout->{$key} = $val; } elseif (is_array($layout)) { $layout[$key] = $val; } } return $layout; }
function ddl_layout_slug_exists($slug) { $res = WPDD_Layouts::get_post_ID_by_slug($slug, WPDDL_LAYOUTS_POST_TYPE); return $res != null && $res != 0 && $res != false; }