本文整理汇总了PHP中Essential_Grid_Base::get_create_category_by_slug方法的典型用法代码示例。如果您正苦于以下问题:PHP Essential_Grid_Base::get_create_category_by_slug方法的具体用法?PHP Essential_Grid_Base::get_create_category_by_slug怎么用?PHP Essential_Grid_Base::get_create_category_by_slug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Essential_Grid_Base
的用法示例。
在下文中一共展示了Essential_Grid_Base::get_create_category_by_slug方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import_grids
public function import_grids($import_grids, $import_ids = true, $check_append = true)
{
if ($import_grids !== false && !empty($import_grids)) {
global $wpdb;
$c_grid = new Essential_Grid();
$base = new Essential_Grid_Base();
$table_name = $wpdb->prefix . Essential_Grid::TABLE_GRID;
$item_skin = new Essential_Grid_Item_Skin();
$grids = $c_grid->get_essential_grids();
foreach ($import_grids as $i_grid) {
if (!empty($import_ids) && is_array($import_ids)) {
$found = false;
foreach ($import_ids as $id) {
if ($i_grid['id'] == $id) {
$found = true;
break;
}
}
if (!$found) {
continue;
}
} else {
if ($import_ids != true) {
//only break if we do not want to import all
break;
}
}
//create/get category and tags if there are some selected
$check = json_decode($i_grid['postparams'], true);
if (isset($check['post_category']) && !empty($check['post_category'])) {
$slug_cats = array();
$the_cats = explode(',', $check['post_category']);
foreach ($the_cats as $cat) {
$raw = explode('_', $cat);
$catSlug = $raw[count($raw) - 1];
unset($raw[count($raw) - 1]);
$cat = implode('_', $raw);
$category = $base->get_create_category_by_slug($catSlug, $cat);
if ($category !== false) {
//only add if we have a ID
$slug_cats[] = $cat . '_' . $category;
}
}
$check['post_category'] = implode(',', $slug_cats);
$i_grid['postparams'] = json_encode($check);
}
$check = json_decode($i_grid['params'], true);
if (isset($check['entry-skin']) && !empty($check['entry-skin'])) {
$skin = $item_skin->get_id_by_handle($check['entry-skin']);
if (!empty($skin)) {
$check['entry-skin'] = $skin['id'];
}
$i_grid['params'] = json_encode($check);
}
$exist = false;
if (!empty($grids)) {
foreach ($grids as $grid) {
if ($grid->handle == $i_grid['handle']) {
$i_grid['id'] = $grid->id;
//this will force an update
$exist = true;
break;
}
}
}
if ($import_ids === true) {
//do not insert if handle exists. This is for the import demo data process
if ($exist) {
continue;
}
}
$append = true;
if ($exist) {
//skin exists - append or overwrite
if ($check_append) {
//check in data if append or overwrite
$do = $base->getVar($this->overwrite_data, 'element-overwrite-' . $i_grid['id'], 'append');
$append = $do == 'append' ? true : false;
}
}
if ($import_ids !== true) {
if ($append) {
//append
if ($exist) {
$i_grid['handle'] = $i_grid['handle'] . '-' . date('His');
$i_grid['name'] = $i_grid['name'] . '-' . date('His');
}
$response = $wpdb->insert($table_name, array('name' => $i_grid['name'], 'handle' => $i_grid['handle'], 'postparams' => $i_grid['postparams'], 'params' => $i_grid['params'], 'layers' => $i_grid['layers']));
} else {
//overwrite
$response = $wpdb->update($table_name, array('name' => $i_grid['name'], 'handle' => $i_grid['handle'], 'postparams' => $i_grid['postparams'], 'params' => $i_grid['params'], 'layers' => $i_grid['layers']), array('id' => $i_grid['id']));
}
} else {
//create or overwrite
if ($exist) {
$response = $wpdb->update($table_name, array('name' => $i_grid['name'], 'handle' => $i_grid['handle'], 'postparams' => $i_grid['postparams'], 'params' => $i_grid['params'], 'layers' => $i_grid['layers']), array('id' => $i_grid['id']));
} else {
$response = $wpdb->insert($table_name, array('name' => $i_grid['name'], 'handle' => $i_grid['handle'], 'postparams' => $i_grid['postparams'], 'params' => $i_grid['params'], 'layers' => $i_grid['layers']));
}
}
//.........这里部分代码省略.........