Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Fix broken custom plugin WordPress

  • SOLVED

<strong>Important:</strong>This plugin must work on Multisite 3.5.1

I had someone create a custom plugin for me, that was suppose to achieve the following:

<blockquote>1) on activation, create a page named My Profile
2) set page author as the site owner
3) set My Profile as the home page
4) rewrite rule so my_profile is not in the url - home page url should be only site url</blockquote>


Currently the plugin does create the my profile page - but the author is not set, the page is not home and I don't think the rewire rule is working.

For this question, I need the above fixed:
1) set author
2) set my profile as home
3) rewrite url to remove the slug

<strong>I need to add 1 more action after activation:</strong>
When this plugin is activated, I need it to also set the "Site Tagline" to a value that is stored in the user meta (company_slogan) of the site owner ([[LINK href="http://wpquestions.com/question/showChronoLoggedIn/id/8137"]]This question has the answer to finding the correct site owner[[/LINK]])

Here is the plugin code:


<?php

function deactivate_plugin_conditional() {
if ( is_plugin_active('cpt-homepage-pro/cpt-homepage-pro.php') ) {
deactivate_plugins('cpt-homepage/cpt-homepage.php');
}
}
add_action( 'admin_init', 'deactivate_plugin_conditional' );
add_action( 'admin_head-options-reading.php', 'wpse_18013_modify_front_pages_dropdown');
function wpse_18013_modify_front_pages_dropdown(){

add_filter( 'wp_dropdown_pages', 'add_cpt_to_front_page_dropdown', 10, 1 );
}
//homepage post type
$posttype = 'page';
//homepage slug
$homepage = 'my_profile';

$homepost = get_page_by_path($homepage, OBJECT, $posttype);
/**
* Adds CPTs to the list of available pages for a static front page.
*
* @param string $select Existing select list.
* @return string
*/
function add_cpt_to_front_page_dropdown( $select )
{

//SET THE POST TYPE HERE
global $posttype, $homepage ;
if ( FALSE !== strpos( $select, 'page_for_posts' ) )
{
return $select;
}
$homepost = get_page_by_path($homepage, OBJECT, $posttype);
if($homepost==null){
$my_post = array(
'post_title' => 'My Profile',
'post_name' => 'my_profile',
'post_status' => 'publish',
'post_type' => 'page',
'post_category' => array(8,39)
);

// Insert the post into the database
wp_insert_post( $my_post );

$homepost = get_page_by_path('my_profile', OBJECT, 'page');
}

//$current = get_option( 'page_on_front', 0 );
return $select.'<strong>' . $homepost->name . '</strong>';
}

function enable_front_page_cpt( $query ){
global $posttype ;

if('' == $query->query_vars['post_type'] && 0 != $query->query_vars['page_id'])
$query->query_vars['post_type'] = array( 'page', $posttype );
}
//add_action( 'pre_get_posts', 'enable_front_page_cpt' );

register_activation_hook( __FILE__, 'cpt_homepage_activate' );
function cpt_homepage_activate(){
global $wpdb;
add_option('show_on_front','page');
update_option('show_on_front','page');

$homepost = get_page_by_path('my_profile', OBJECT, 'page');
if($homepost==null){
$my_post = array(
'post_title' => 'My Profile',
'post_name' => 'my_profile',
'post_status' => 'publish',
'post_type' => 'page',
'post_category' => array(8,39)
);

// Insert the post into the database
wp_insert_post( $my_post );
$homepost = get_page_by_path('my_profile', OBJECT, 'page');
}

$current = get_option( 'page_on_front');


if($current != $homepost->ID){
add_option('page_on_front',$homepost->ID);
update_option('page_on_front',$homepost->ID);
}
$count = $wpdb->get_results('SELECT op.option_id from '.$wpdb->base_prefix.'options op where op.option_name="page_on_front" LIMIT 1' );
if(!empty($count)){
$wpdb->query('UPDATE '.$wpdb->base_prefix.'options op SET op.option_value = '.$homepost->ID.' WHERE op.option_id = '.$count[0]->option_id.';');
}

}
register_deactivation_hook(__FILE__, 'cpt_homepage_deactivate');
function cpt_homepage_deactivate(){
global $posttype, $homepage ;
if ( !is_plugin_active('cpt-homepage-pro/cpt-homepage-pro.php') )
update_option('page_on_front',0);
}

?>

Answers (2)

2013-03-13

Gabriel Reguly answers:

Hi wpcoach,

I can do it for you, just need a couple of hours for lunch time :-)

Please bear with me.

Regards,
Gabriel


wpcoach comments:

Will do - thanks


Gabriel Reguly comments:

Hi wpcoach,

Please find the plugin here:[[LINK href="https://dl.dropbox.com/u/355512/homepage-my-profile.zip"]] https://dl.dropbox.com/u/355512/homepage-my-profile.zip[[/LINK]]

I did a new version of it, was easier than fixing the one you had ;-)

Regards,
Gabriel


Gabriel Reguly comments:

Hi wpcoach,

As discussed via PM, please find the version with deactivation code here:[[LINK href=" https://dl.dropbox.com/u/355512/homepage-my-profile_1.0.1.zip"]] https://dl.dropbox.com/u/355512/homepage-my-profile_1.0.1.zip[[/LINK]]

Regards,
Gabriel


wpcoach comments:

Wonderful - thanks. I will test this soon.


wpcoach comments:

Hello Gabriel,

I just checked the plugin with no success.

Would you like for me to give ftp credentials so you can check.

Thanks


Gabriel Reguly comments:

Hi wpcoach,

Yes, please send me them via PM.

Also, would be good to have a super admin user for me - later just remove it.

Regards,
Gabriel


wpcoach comments:

Thanks for all of your help / support on this, I am very thankful for your efforts / solution.

2013-03-13

Navjot Singh answers:

Is this plugin supposed to work in a multisite setup? Because I just tested it on a simple blog and it worked.


wpcoach comments:

yes - this works in multi-site. Once the user creates an account, I am auto activating this plugin.


wpcoach comments:

yes - this works in multi-site. Once the user creates an account, I am auto activating this plugin.