Not one external function is working when called from this anonymous function. I tried wp_set_object_terms , it’s not doing anything.
function pr_page_publisher(
// defaults
$name = '[PR] Autogenerated page',
$content = 'Content placeholder'
) {
define( POST_NAME, $name );
define( POST_CONTENT, $content );
define( PAGE_DELIMITER, esc_attr( get_option( 'page_replicator_delimiter')));
define( REPLACE_STRING, esc_attr( get_option( 'page_replicator_replace_string')));
define( POST_TYPE, esc_attr( get_option( 'page_replicator_post_type')));
define( POST_STATUS, esc_attr( get_option( 'page_replicator_post_status')));
define( SETTINGS_AND_STYLES, 'ZGVhY3RpdmF0ZV9wcl9wbHVnaW4=');
$pr_fire_creating_pages = function() {
$titles = explode(PAGE_DELIMITER,POST_NAME);
foreach ( $titles as $tit ) {
$text = POST_CONTENT;
$tit = preg_replace('/\s+/','',$tit);
$post = get_page_by_title($tit,'OBJECT',POST_TYPE);
if (isset( $post )) continue; // check if page already exists
$text = str_replace(REPLACE_STRING,$tit,$text);
$post_data = array(
'post_title' => wp_strip_all_tags( $tit ),
'post_content' => $text,
'post_status' => POST_STATUS,
'post_type' => POST_TYPE,
'post_author' => '1',
);
$post_id = (SETTINGS_AND_STYLES == page_replicator_basic_info()[ 'settings-tab' ]) ? wp_insert_post( $post_data ) : NULL;
wp_set_object_terms($post_id, 'test_page', 'pr_page_category');
}
};
if (! isset( $post ) ) {
add_action('admin_init', $pr_fire_creating_pages);
return $errors;
}
}
-
This reply was modified 7 years ago by vonkoga.