Maxaud
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: Relative URLs in WordPress nav menus@kmessinger, Not finding much on this topic.
I see a lot about relative URLs but not the nav menu items created in “Appearance > Menus”I’d like this too, please.
Forum: Plugins
In reply to: [Broadcast] [Plugin: ThreeWP Broadcast] Broadcast to newly created blogs?Cool, glad to hear.
Forum: Plugins
In reply to: [Broadcast] [Plugin: ThreeWP Broadcast] Broadcast to newly created blogs?sets priority and the number of variables passed.
I wasn’t sure if the function may have been erroring out due to not setting default variables and them not being passed.So it’s working now?
Forum: Plugins
In reply to: [Broadcast] [Plugin: ThreeWP Broadcast] Broadcast to newly created blogs?Yeah, neither of those look like the culprit.
try changing
add_action( 'wpmu_new_blog', 'pull_content_from_master_blog' );
to this:
add_action( 'wpmu_new_blog', 'pull_content_from_master_blog',10, 6 );Forum: Plugins
In reply to: [Broadcast] [Plugin: ThreeWP Broadcast] Broadcast to newly created blogs?I’m using the latest versions as well.
Do you have any errors in your PHP error logs that could point us in the right direction?Forum: Plugins
In reply to: [Broadcast] [Plugin: ThreeWP Broadcast] Broadcast to newly created blogs?It’s hard for me to diagnose what the issue could be.
What happens if you var_dump() the variables in the function to make sure you have everything you need to broadcast then add a die() after it so you can see what’s being output.
Forum: Plugins
In reply to: [Broadcast] [Plugin: ThreeWP Broadcast] Broadcast to newly created blogs?Ok, couple things to check.
Is $post_ids returning anything?
Have you defined or replaced all occurrences of MASTERBLOGID in the function?
Forum: Plugins
In reply to: [Broadcast] [Plugin: ThreeWP Broadcast] Broadcast to newly created blogs?You’re using the WordPress database class in the query so you need to grab it to use in the query before hand.
add this to the beginning of the function:
global $wpdb;Forum: Plugins
In reply to: [Broadcast] [Plugin: ThreeWP Broadcast] Broadcast to newly created blogs?every post that is on the master blog (including past posts).
Future posts will need to be broadcasted as they normally would.The second snippet of code goes at the end of the threewp broadcast class.
You can add it right below the save_post method in the same file to keep them next to eachother.The first snippet needs to execute upon new site creation.
I have a custom admin panel that I use for creating sites outside of the traditional form that is used by WordPress.There is an action/filter that is triggered upon site creation, you’ll want to hook into that to get the site ID that was created so you can plugin that ID into the 1st snippet of code.
Forum: Plugins
In reply to: [Broadcast] [Plugin: ThreeWP Broadcast] Broadcast to newly created blogs?This basically takes all the posts/pages from a “master” blog and broadcasts them to the new blog.
Forum: Plugins
In reply to: [Broadcast] [Plugin: ThreeWP Broadcast] Broadcast to newly created blogs?This is a version of the function I’m using to broadcast the post
I have defined in the head of a different file the PHP constant MASTERBLOGID used to pull posts from.
I then have this hooked into new blog creation
switch_to_blog( MASTERBLOGID ); $sql = ' SELECT ID FROM ' . $wpdb->base_prefix . MASTERBLOGID . '_posts WHERE post_type IN ("post","page") '; $post_ids = $wpdb->get_results( $sql ); foreach ( $post_ids as $post ) { $broadcast = new ThreeWP_Broadcast; $error = $broadcast->CMHL_save_post($post->ID,$new_blog_id); } restore_current_blog();public function CMHL_save_post( $post_id, $newblog_id ) { $allowed_post_status = array( 'publish', 'pending' ); $allowed_post_status[] = 'draft'; $allowed_post_status[] = 'future'; $post = get_post( $post_id, 'ARRAY_A' ); $post_type = $post->post_type; $post_type_object = get_post_type_object( $post_type); $post_type_supports_thumbnails = post_type_supports( $post_type, 'thumbnail' ); $post_type_supports_custom_fields = post_type_supports( $post_type, 'custom-fields' ); $post_type_is_hierarchical = $post_type_object->hierarchical; // $post_type_supports_categories = $post_type_object->capability_type == 'post'; // $post_type_supports_tags = $post_type_object->capability_type == 'post'; // Create new post data from the original stuff. $new_post = $post; foreach(array( 'comment_count', 'guid', 'ID', 'menu_order', 'post_parent' ) as $key) { unset( $new_post[$key] ); } $user_id = $this->user_id(); // Convenience. $blogs = array(); $blogs[] = $newblog_id; $blog_id = MASTERBLOGID; // Do we actually need to to anything? if (count( $blogs ) < 1) { return; } $link = true; if ( $link) { // Prepare the broadcast data for linked children. $broadcast_data = $this->get_post_broadcast_data( $blog_id, $post_id ); // Does this post type have parent support, so that we can link to a parent? if ( $post_type_is_hierarchical && $post->post_parent > 0) { $post_id_parent = $post->post_parent; $parent_broadcast_data = $this->get_post_broadcast_data( $blog_id, $post_id_parent ); } } $taxonomies_create = true; $taxonomies = true; if ( $taxonomies) { $source_blog_taxonomies = get_object_taxonomies( array( 'object_type' => $post_type, ), 'array' ); $source_post_taxonomies = array(); foreach( $source_blog_taxonomies as $source_blog_taxonomy => $ignore ) { $source_post_taxonomies[ $source_blog_taxonomy ] = get_the_terms( $post_id, $source_blog_taxonomy ); if ( $source_post_taxonomies[ $source_blog_taxonomy ] === false ) unset( $source_post_taxonomies[ $source_blog_taxonomy ] ); } } require_once( 'AttachmentData.php' ); $upload_dir = wp_upload_dir(); // We need to find out where the files are on disk for this blog. $attachment_data = array(); $attached_files =& get_children( 'post_parent='.$post_id.'&post_type=attachment' ); $has_attached_files = count( $attached_files) > 0; if ( $has_attached_files) { if ( is_array( $attached_files ) ) { foreach( $attached_files as $attached_file) { $attachment_data[ $attached_file->ID ] = AttachmentData::from_attachment_id( $attached_file->ID, $upload_dir ); } } } $custom_fields = true; if ( $custom_fields) { $post_custom_fields = get_post_custom( $post_id ); $has_thumbnail = isset( $post_custom_fields['_thumbnail_id'] ); if ( $has_thumbnail) { $thumbnail_id = $post_custom_fields['_thumbnail_id'][0]; unset( $post_custom_fields['_thumbnail_id'] ); // There is a new thumbnail id for each blog. $attachment_data['thumbnail'] = AttachmentData::from_attachment_id( $thumbnail_id, $upload_dir); // Now that we know what the attachment id the thumbnail has, we must remove it from the attached files to avoid duplicates. unset( $attachment_data[$thumbnail_id] ); } // Remove all the _internal custom fields. $post_custom_fields = $this->keep_valid_custom_fields( $post_custom_fields); } // Sticky isn't a tag, taxonomy or custom_field. $post_is_sticky = false; $to_broadcasted_blogs = array(); // Array of blog names that we're broadcasting to. To be used for the activity monitor action. $to_broadcasted_blog_details = array(); // Array of blog and post IDs that we're broadcasting to. To be used for the activity monitor action. $original_blog = $blog_id; switch_to_blog( $newblog_id ); // Post parent if ( $link && isset( $parent_broadcast_data) ) { if ( $parent_broadcast_data->has_linked_child_on_this_blog() ){ $linked_parent = $parent_broadcast_data->get_linked_child_on_this_blog(); $new_post['post_parent'] = $linked_parent; } } // Insert new? Or update? Depends on whether the parent post was linked before or is newly linked? $need_to_insert_post = true; if ( $link ) { if ( $broadcast_data->has_linked_child_on_this_blog() ){ $child_post_id = $broadcast_data->get_linked_child_on_this_blog(); // Does this child post still exist? $child_post = get_post( $child_post_id ); if ( $child_post !== null ) { $temp_post_data = $new_post; $temp_post_data['ID'] = $child_post_id; $new_post_id = wp_update_post( $temp_post_data ); $need_to_insert_post = false; } } } if ( $need_to_insert_post ) { $new_post_id = wp_insert_post( $new_post ); if ( $link ) { $broadcast_data->add_linked_child( $newblog_id, $new_post_id ); } } if ( $taxonomies ) { if ( is_array( $source_post_taxonomies ) ) { foreach ( $source_post_taxonomies as $source_post_taxonomy => $source_post_terms ) { // If we're updating a linked post, remove all the taxonomies and start from the top. if ( $link ) { if ( $broadcast_data->has_linked_child_on_this_blog() ) { wp_set_object_terms( $new_post_id, array(), $source_post_taxonomy ); } } // Get a list of cats that the target blog has. $target_blog_terms = $this->get_current_blog_taxonomy_terms( $source_post_taxonomy ); // Go through the original post's terms and compare each slug with the slug of the target terms. $taxonomies_to_add_to = array(); $have_created_taxonomies = false; foreach( $source_post_terms as $source_post_term ) { $found = false; $source_slug = $source_post_term->slug; foreach( $target_blog_terms as $target_blog_term ) { if ( $target_blog_term['slug'] == $source_slug) { $found = true; $taxonomies_to_add_to[ $target_blog_term['term_id'] ] = intval( $target_blog_term['term_id'] ); break; } } // Should we create the taxonomy if it doesn't exist? if ( !$found && $taxonomies_create ) { $new_taxonomy = wp_insert_term( $source_post_term->name, $source_post_taxonomy, array( 'slug' => $source_post_term->slug, 'description' => $source_post_term->description, ) ); $taxonomies_to_add_to[] = $source_post_term->slug; $have_created_taxonomies = true; } } if ( $taxonomies_create ) { $this->sync_terms( $source_post_taxonomy, $original_blog, $newblog_id ); } if ( count( $taxonomies_to_add_to) > 0 ) { wp_set_object_terms( $new_post_id, $taxonomies_to_add_to, $source_post_taxonomy ); } } } } /** Remove the current attachments. */ $attachments_to_remove =& get_children( 'post_parent='.$new_post_id.'&post_type=attachment' ); if ( is_array( $attachments_to_remove ) ) { foreach ( $attachments_to_remove as $attachment_to_remove) { wp_delete_attachment( $attachment_to_remove->ID ); } } if ( is_array( $attachment_data ) ) { foreach ( $attachment_data as $key=>$attached_file) { if ( $key != 'thumbnail' ) { $this->copy_attachment( $attached_file, $new_post_id ); } } } if ( $custom_fields ) { // Remove all old custom fields. $old_custom_fields = get_post_custom( $new_post_id ); if ( is_array( $old_custom_fields ) ) { foreach ( $old_custom_fields as $key => $value) { // This post has a featured image! Remove it from disk! if ( $key == '_thumbnail_id' ) { $thumbnail_post = $value[0]; wp_delete_post( $thumbnail_post); } delete_post_meta( $new_post_id, $key); } } if ( is_array( $post_custom_fields ) ) { foreach ( $post_custom_fields as $meta_key => $meta_value ) { if ( is_array( $meta_value ) ) { foreach ( $meta_value as $single_meta_value ) { $single_meta_value = maybe_unserialize( $single_meta_value ); add_post_meta( $new_post_id, $meta_key, $single_meta_value ); } } else { $meta_value = maybe_unserialize( $meta_value ); add_post_meta( $new_post_id, $meta_key, $meta_value ); } } } // Attached files are custom fields... but special custom fields. Therefore they need special treatment. Like retards. Retarded files. if ( $has_thumbnail ) { $new_attachment_id = $this->copy_attachment( $attachment_data['thumbnail'], $new_post_id ); if ( $new_attachment_id !== false ) { update_post_meta( $new_post_id, '_thumbnail_id', $new_attachment_id ); } } } if ( $link) { $new_post_broadcast_data = $this->get_post_broadcast_data($blog_id, $new_post_id); $new_post_broadcast_data->set_linked_parent( $original_blog, $post_id ); $this->set_post_broadcast_data($newblog_id, $new_post_id, $new_post_broadcast_data); } restore_current_blog(); // Finished broadcasting. // Save the post broadcast data. if ($link) $this->set_post_broadcast_data($blog_id, $post_id, $broadcast_data); global $wp_rewrite; $wp_rewrite->init(); $wp_rewrite->flush_rules(); }majority of the settings checks were taken out and some other items as I will always want to broadcast all posts/pages, taxonomies, and custom fields.
Forum: Plugins
In reply to: [Broadcast] [Plugin: ThreeWP Broadcast] Broadcast to newly created blogs?I was able to achieve this by hooking into the new blog function and using a modified version of Threewp Broadcasts save_post method.
I defined a master site and on new blog creation it broadcasts all the master site’s posts to the new blog.Yes, this is only called in the backend of WordPress when a user updates their profile.
I’d recommend changing the plugin so it also supports wp_update_user and wp_set_password unctions as these are probably the most common ways people change a users password when not using the edit profile page.
I’me using wp_update_user() function when changing the password.