Support » Plugins and Hacks » Hacks » How to add user page with my plugin

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Hi, i use the below code in my plugin to create the page that contains the shortcode for the plugin, if the page is not there already – mybe you can use some of it:

    // Check if page containing [frontier-post] exists already, else create it
    	$tmp_id = $wpdb->get_var(
    		"SELECT id
    		  FROM $wpdb->posts
    		  WHERE post_type='page' AND
    		  post_status='publish' AND
    		 post_content LIKE '%[frontier-post]%'
    		");
    
    	if ( ((int)$tmp_id) <= 0)
    		{
    		// Add new page
    		$my_page = array(
                     'post_title' 		=> 'My Posts',
                     'post_content' 	=> '[frontier-post]',
                     'post_status' 		=> 'publish',
    				 'comment_status' 	=> 'closed',
                     'post_type' 		=> 'page',
    				);
    
    		// Insert the page into the database
            $tmp_id = wp_insert_post( $my_page );
    }
    	// save the page id so it can be reused in code and changed in settings
    	add_option("frontier_post_page_id", $tmp_id );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to add user page with my plugin’ is closed to new replies.