/i', $content, $matches)){
$urls = array_unique($matches[1]);
$replace = wpjam_fetch_external_images($urls, $id);
return $replace ? WPJAM_Post::update($id, ['post_content'=>str_replace($urls, $replace, $content)]) : ($bulk ? true : wp_die('文章中无外部图片'));
}
return $bulk ? true : wp_die('文章中无图片');
}
public static function load($screen){
$base = $screen->base;
$object = wpjam_admin((in_array($base, ['post', 'edit', 'upload']) ? 'type' : 'tax').'_object');
if($base == 'post'){
self::get_setting('disable_trackbacks') && wpjam_style('label[for="ping_status"]{display:none !important;}');
self::get_setting('disable_autoembed') && $screen->is_block_editor && wpjam_script("wp.domReady(()=> wp.blocks.unregisterBlockType('core/embed'));\n");
}elseif(in_array($base, ['edit', 'upload'])){
$ptype = $screen->post_type;
$is_wc_shop = defined('WC_PLUGIN_FILE') && str_starts_with($ptype, 'shop_');
self::get_setting('post_list_author_filter', 1) && $object->supports('author') && add_action('restrict_manage_posts', function($ptype){ wp_dropdown_users([
'name' => 'author',
'capability' => 'edit_posts',
'orderby' => 'post_count',
'order' => 'DESC',
'show_option_all' => $ptype == 'attachment' ? '所有上传者' : '所有作者',
'selected' => (int)wpjam_param('author', 'data'),
'hide_if_only_one_author' => true,
]);
}, 1);
self::get_setting('post_list_sort_selector', 1) && !$is_wc_shop && add_action('restrict_manage_posts', function($ptype){
[$columns, , $sortable] = $GLOBALS['wp_list_table']->get_column_info();
$orderby = wpjam_reduce($sortable, fn($c, $v, $k)=> isset($columns[$k]) ? wpjam_set($c, $k, wp_strip_all_tags($columns[$k])) : $c, []);
echo wpjam_fields([
'orderby' => ['options'=>[''=>'排序','ID'=>'ID']+$orderby+($ptype != 'attachment' ? ['modified'=>'修改时间'] : [])],
'order' => ['options'=>['desc'=>'降序','asc'=>'升序']]
], [
'fields_type' => '',
'value_callback' => fn($k)=> sanitize_key(wpjam_param($k, 'data'))
])."\n";
}, 99);
if($ptype != 'attachment'){
($action = 'upload_external_images') && self::get_setting($action) && wpjam_register_list_table_action($action, [
'title' => '上传外部图片',
'page_title' => '上传外部图片',
'direct' => true,
'confirm' => true,
'bulk' => 2,
'order' => 9,
'callback' => [self::class, $action]
]);
wpjam_style('#bulk-titles, ul.cat-checklist{height:auto; max-height: 14em;}');
if($ptype == 'page'){
wpjam_style('.fixed .column-template{width:15%;}');
wpjam_register_posts_column('template', '模板', 'get_page_template_slug');
}
}
$width_columns = wpjam_map($object->get_taxonomies(['show_admin_column'=>true]), fn($v)=> '.fixed .column-'.$v->column_name);
$width_columns = array_merge($width_columns, $object->supports('author') ? ['.fixed .column-author'] : []);
$width_columns && wpjam_style(implode(',', $width_columns).'{width:'.(['14', '12', '10', '8', '7'][count($width_columns)-1] ?? '6').'%}');
wpjam_style('.fixed .column-date{width:100px;}');
}elseif(in_array($base, ['edit-tags', 'term'])){
$base == 'edit-tags' && wpjam_style(['.fixed th.column-slug{width:16%;}', '.fixed th.column-description{width:22%;}']);
array_map(fn($v)=> $object->supports($v) ? '' : wpjam_style('.form-field.term-'.$v.'-wrap{display: none;}'), ['slug', 'description', 'parent']);
}
if($base == 'edit-tags' || ($base == 'edit' && !$is_wc_shop)){
wpjam_script(self::get_setting('post_list_ajax', 1) ? <<<'JS'
setTimeout(()=> {
wpjam.delegate('#the-list', '.editinline');
wpjam.delegate('#doaction');
}, 300);
JS : "wpjam.list_table.ajax = false;\n");
$base == 'edit' && wpjam_script(<<<'JS'
inlineEditPost.setBulk = wpjam.enhance(inlineEditPost.setBulk, ()=> $('#the-list').trigger('bulk_edit'));
inlineEditPost.edit = wpjam.enhance(inlineEditPost.edit, function(id){
return ($('#the-list').trigger('quick_edit', typeof(id) === 'object' ? this.getId(id) : id), false);
});
JS);
if(self::get_setting('post_list_ajax', 1)){
$pairs[] = ['/(]*>.*?<\/a>.*?)(<\/strong>)/is', '$1 [row_action name="set" class="row-action" dashicon="edit"]$2'];
if($base == 'edit'){
$pairs[] = ['/(| get_taxonomies(['show_in_quick_edit'=>true]), fn($c, $t)=> $c.'|'.preg_quote($t->column_name), 'column-author').')[^\']*\'.*?>.*?)(<\/td>)/is', '$1 $3'];
}
}
if(self::get_setting('post_list_set_thumbnail', 1)
&& $object->supports($base == 'edit' ? 'thumbnail,images' : 'thumbnail')
&& ($base != 'edit'|| $ptype != 'product' || !defined('WC_PLUGIN_FILE'))
){
$pairs[] = [' '[row_action name="set" class="wpjam-thumbnail-wrap" fallback="1"]'.self::get_the_thumbnail($id, $base).'[/row_action]'];
}
isset($pairs) && add_filter('wpjam_single_row', fn($row, $id)=> array_reduce($pairs, fn($c, $p)=> is_callable($p[1]) ? str_replace($p[0], $p[1]($id).$p[0], $c) : wpjam_preg_replace($p[0], $p[1], $c), $row), 10, 2);
}
}
public static function init(){
self::get_setting('remove_post_tag') && unregister_taxonomy_for_object_type('post_tag', 'post');
self::get_setting('remove_page_thumbnail') && remove_post_type_support('page', 'thumbnail');
self::get_setting('add_page_excerpt') && add_post_type_support('page', 'excerpt');
self::get_setting('404_optimization') && wpjam_hook('old_slug_redirect_post_id', fn($id)=> $id ?: self::find_by_name(get_query_var('name'), get_query_var('post_type')));
if(self::get_setting('excerpt_optimization')){
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
if(self::get_setting('excerpt_optimization') != 2){
remove_filter('the_excerpt', 'wp_filter_content_tags');
remove_filter('the_excerpt', 'shortcode_unautop');
wpjam_hook('get_the_excerpt', fn($text='', $post=null)=> $text ?: wpjam_get_post_excerpt($post, (self::get_setting('excerpt_length') ?: 200)), 9, 2);
}
}
}
}
wpjam_register_option('wpjam-basic', [
'title' => '文章设置',
'plugin_page' => 'wpjam-posts',
'current_tab' => 'posts',
'site_default' => true,
'model' => 'WPJAM_Basic_Posts',
'admin_load' => ['base'=>['edit', 'upload', 'post', 'edit-tags', 'term']],
'menu_page' => ['parent'=>'wpjam-basic', 'position'=>4, 'function'=>'tab', 'tabs'=>[
'posts' => ['title'=>'文章设置', 'order'=>20, 'summary'=>__FILE__, 'function'=>'option', 'option_name'=>'wpjam-basic']
]],
]);
|