WordPress.org

Ready to get started?Download WordPress

Forums

Plugin Code Question (27 posts)

  1. dpskipper
    Member
    Posted 4 months ago #

    I am currently making a plugin that changes the default WP login page.
    Currently it is in very early stages. To change the WP logo on the login page, one has to do it inside the code. Could someone help me/give me required code to add some settings for the plugin. I want to have a box where users can add images from the media center and the plugin uses that as the image to use for the login screen. I would just like some help coding the settings area of the plugin. If you help me/give me some code that works, I would be happy to add you to the list of authors for the plugin.
    Many Thanks,
    William

  2. catacaustic
    Member
    Posted 4 months ago #

    You don't need to change any code in that file. The log oon the login page is set using CSS only. If you add a new CSS rule for that element you'll be able to over-ride that logo display and show the one that you want.

    To show you, this is what's ther now...

    .login h1 a {
      background-image: none, url("../images/wordpress-logo.svg?ver=20131107");
      ...
    }

    So, target .login h1 a in your CSS and you'll be able to change that to what ever you want to.

  3. dpskipper
    Member
    Posted 4 months ago #

    Ok, thanks, i was unsure how to make code work after having changing options in the settings. Do you have any other tips on how to add my plugin settings to the side bar and how to make the code in the plugin work with the custom information set in the setttings?
    If you want i can add you as a contributor to my plugin.
    Thanks,
    William

  4. catacaustic
    Member
    Posted 4 months ago #

    That's all very big questions, and I think that it's better that you'd learn that for yourself. :)

    I can give you osme ideas on where to look though.

    Start off with the menus:
    http://codex.wordpress.org/Function_Reference/add_menu_page
    http://codex.wordpress.org/Function_Reference/add_submenu_page

  5. dpskipper
    Member
    Posted 4 months ago #

    Ok, thanks for all your help, do you want to be added a a contribute for the plugin?

  6. catacaustic
    Member
    Posted 4 months ago #

    Thanks for the offer, but that's not necessary. If I actually did something then maybe, but for the help of giving you a few pointers, no I don't think that I'd deserve it for that. :)

  7. dpskipper
    Member
    Posted 4 months ago #

    I have another question. After some very hard work and coding i have some problems with adding a settings tab on the wordpress sidebar.
    For some reason the menu is added fine, but no subpages appear. The image is broken and when i click on the menu it comes up with a 404 error.
    Here is the code for the menu and subpages:
    add_action( 'admin_menu', 'register_my_custom_menu_page' );

    function register_my_custom_menu_page(){
    add_menu_page( 'custom menu title', 'Williams Custom WP Login Plugin', 'manage_options', '/public_html/dj-party-planner.com/wp-content/plugins/williams-custom-wp-login-plugin/settings-page.php', '', plugins_url( '/public_html/dj-party-planner.com/wp-content/plugins/williams-custom-wp-login-plugin/logo.png' ), 6 );
    }

    add_action('admin_menu', 'register_my_custom_submenu_page');

    function register_my_custom_submenu_page() {

    add_submenu_page(
    null //or 'options.php'
    , 'My Custom Submenu Page'
    , 'My Custom Submenu Page'
    , 'manage_options'
    , 'my-custom-submenu-page'
    , 'my_custom_submenu_page_callback'
    );

    }

    Here is the code for the settings page i'm trying to get to work.
    <?php
    echo "Admin Page Test";
    ?>

  8. catacaustic
    Member
    Posted 4 months ago #

    You've missed this important note ofr add_submenu-apge(0...

    Use NULL or set to 'options.php' if you want to create a page that doesn't appear in any menu (see example below).

    So, when you use NULL there, it doesn't add the sub-menu page to anything at all.

    1. You also don't need two separate functions to do this. Keep it as one, and it will simplfy your life a whole lot.
    2. You've also got the parameters around the wrong way, so I'm amazed that anything shows up at all!
    3. You have to add in the function name for these to display anything.
    4. Be careful when using a value for $position as you can't guarantee that another plugin won't over-write your position, and will remove your page/pages from the menu.
    5. And, as a final note, don't ever use hard-coded file paths anywhere. These change every time that your plugin is installed somewhere, so you can never rely on these being the same anywhere.
    function register_my_custom_menu(){
        add_menu_page( 'Custom WP Login', 'Williams Custom WP Login Plugin', 'manage_options', 'custom_login', 'my_custom_menu_page_callback', plugins_url( 'logo.png', __FILE__ ));
        add_submenu_page( 'custom_login', 'My Custom Submenu Page', 'My Custom Submenu Page', 'manage_options', 'custom_login_subpage', 'my_custom_submenu_page_callback');
    }
    
    add_action( 'admin_menu', 'register_my_custom_menu' );
  9. dpskipper
    Member
    Posted 4 months ago #

    Ok, i will use your wise information and try it out :)

  10. dpskipper
    Member
    Posted 4 months ago #

    Hmm, when i remove 'null or 'Options.php' just breaks my site

  11. catacaustic
    Member
    Posted 4 months ago #

    The example that I gave shows you what you need to have there. It needs to be the page slug of the main menu page that you're trying to add it to.

    Follow the code that I gave you above and it will work. I have tested it, and it adds the menus in exactly as you're looking for :)

  12. dpskipper
    Member
    Posted 4 months ago #

    Very happy for your help, just got a callback error on the page which needs tiding up.
    Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'my_custom_submenu_page_callback' not found or invalid function name in /home2/greennin/public_html/dj-party-planner.com/wp-includes/plugin.php on line 470

  13. catacaustic
    Member
    Posted 4 months ago #

    That's because you need to create teh functions to display the content for the admin pages that the menus link to.

  14. dpskipper
    Member
    Posted 4 months ago #

    ? Sorry for being so incompetent. But i really don't know what your talking about. example code?

  15. dpskipper
    Member
    Posted 4 months ago #

    Any way to add CSS classes as the image on the sidebar?

  16. catacaustic
    Member
    Posted 4 months ago #

    function register_my_custom_menu(){
        add_menu_page( 'Custom WP Login', 'Williams Custom WP Login Plugin', 'manage_options', 'custom_login', 'my_custom_menu_page_callback', plugins_url( 'logo.png', __FILE__ ));
        add_submenu_page( 'custom_login', 'My Custom Submenu Page', 'My Custom Submenu Page', 'manage_options', 'custom_login_subpage', 'my_custom_submenu_page_callback');
    }
    
    add_action( 'admin_menu', 'register_my_custom_menu' );
    
    function my_custom_menu_page_callback(  ) [
        echo '<p>Main custom page</p>';
    }
    
    function my_custom_submenu_page_callback(  ) [
        echo '<p>Sub custom page</p>';
    }
  17. dpskipper
    Member
    Posted 4 months ago #

    Where do I paste this code?
    Thanks for taking the time to code this BTW :) It means a lot to me.

  18. catacaustic
    Member
    Posted 4 months ago #

    You would put it where your other code was (after removing your old code that didn't work).

  19. dpskipper
    Member
    Posted 4 months ago #

    :(
    Parse error: syntax error, unexpected '[', expecting '{' in /home2/greennin/public_html/dj-party-planner.com/wp-content/plugins/williams-custom-wp-login-plugin/william-custom-login.php on line 36

  20. catacaustic
    Member
    Posted 4 months ago #

    So where is the [ on line 36? There's nothing like that in any of the code that I've given, so I can't help with that.

    You need to do some debugging yourself here. The error message tells you exactly what the problem is, and where you can find it. Use that information to go to that line, and fix what it says the problem is.

  21. dpskipper
    Member
    Posted 4 months ago #

    I tried exactly that. No avail.
    Here is all the main code except for the CSS:
    <?php
    /*

    function custom_login_css(){
    echo '<link rel="stylesheet" type="text/css" href="' . plugins_url( '/style.css' , __FILE__ ) . '"/> ';
    }
    add_action ('login_head','custom_login_css');

    add_filter('login_headerurl', 'custom_login_header_url');
    function custom_login_header_url($url){
    return 'http://titan-websites.com.com';
    }
    add_filter('login_headertitle', 'custom_login_header_title');

    function custom_login_header_title($title){

    return 'Designed and Developed by Titan Websites';

    }

    function register_my_custom_menu(){
    add_menu_page( 'Custom WP Login', 'Williams Custom WP Login Plugin', 'manage_options', 'custom_login', 'my_custom_menu_page_callback', plugins_url( 'logo.png', __FILE__ ));
    add_submenu_page( 'custom_login', 'My Custom Submenu Page', 'My Custom Submenu Page', 'manage_options', 'custom_login_subpage', 'my_custom_submenu_page_callback');
    }

    add_action( 'admin_menu', 'register_my_custom_menu' );

    function my_custom_menu_page_callback( ) [
    echo '<p>Main custom page</p>';
    }

    function my_custom_submenu_page_callback( ) [
    echo '<p>Sub custom page</p>';
    }

  22. catacaustic
    Member
    Posted 4 months ago #

    You should post code in backticks so that it formats corectly. :)

    But I was sort of wrong, the error was in the code that I gave you. BUT if you can't look at that line and see exactly what the problem is, then you are going to find it very hard to debug any issues in the future.

    I can see straight away where the problem is. Look at this line:

    function my_custom_menu_page_callback( ) [

    Does that look like a valid function opening statement? It's not. The [ there should be a { and that's what it's complaining about. I would hav eseen that if I had used my proper text editor too, but I wasn't so I missed it as well.

    So, this is a lesson... get a good text editor that shows syntax and highlites errors. There's a lot out there that work, so find one that works for you, and it will help to solve a lot of these issues.

  23. dpskipper
    Member
    Posted 4 months ago #

    UPDATE:
    After a bit of tinkering managed to get my site back live.
    Problem was even though i had fixed the '[' my ftp did not correctly upload the new document. Restarted FileZilla works like a charm.

  24. dpskipper
    Member
    Posted 4 months ago #

    You Sir will defiantly be added as a contributor if\when I upload this plugin to the repository. You have been an immense help to me. No all I have to do is make some text boxes and user input areas.

  25. dpskipper
    Member
    Posted 4 months ago #

    I have another question. How come the image is broken?

  26. catacaustic
    Member
    Posted 4 months ago #

    Which image do you mean? I'm guessing the icon for the menu item?

    If that's the case then I'd suggest using Firebug (or your preferred browsers developer tools) to find out if it's showing up, or isn't there and see what the URL that it's requesting is. You'll see where the problem is that way.

  27. dpskipper
    Member
    Posted 4 months ago #

    Ok

Reply

You must log in to post.

About this Topic