WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] building a plugin (have some question need support) (5 posts)

  1. ssoulless
    Member
    Posted 1 year ago #

    Hi im building a plugin for wordpress, is my first plugin, i have made some modules for Drupal, but this is my first contribution to wordpress.

    I havent found the plugin how i need. If you think there is aplugin like this tell me and ill see it.

    What im doing is a plugin that registers a widget. I called the plugin WordPress TabbedPosts widget. This plugin will show in the settings of wordpress a list with all the posts (after i will add a way of find or filter those posts), each post have in front a checkbox.

    So the widget will recieve the ids of the posts that where selected with those checkboxes, and will show the posts and their content in a tab format, i mean, i tab per post, so title of the post in the tab, and if i click the tab it should show the content of the post, i can do that with jquery ui.

    each checkbox have of value the id of the post infront.

    now, i have the admin page of the plugin in the settings of wordpress, i have the the widget, but anything inside, just the title, in the admin page of the plugin i have the list of posts and one checkbox in front of each title post.

    this is the code of the form of that list in the admin page of the plugin

    <form id="form1" name="frm" action="options.php" method="POST">  
    
            <?php settings_fields('wppostabsgroup'); ?>
    
                <h1>Configuraciones de WordPress postabs</h1>
                <p>
                    <h3>Seleccione los artículos que quiere mostrar en formato pestaña</h3>
                </p>
                <table class="widefat">
                    <thead>
                        <tr>
                            <th>Título</th>
                            <th>postabbed</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                            <th>Título</th>
                            <th>postabbed</th>
                        </tr>
                    </tfoot>
                    <tbody>
    
                        <?php
                            $numCheckBox = 0;
                            global $post;
    
                            $myposts = get_posts( );
    
                            foreach( $myposts as $post ) : setup_postdata($post); ?>
                        <tr>
    	                       <td>
                                    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                               </td>
                               <td>
                                    <input type="checkbox" name="id"  value="<?php the_ID(); ?>" onClick="ct()">
                               </td>
                        </tr>
                            <?php
                                $numCheckBox++;
                                endforeach;
                            ?>
    
                    </tbody>
                </table>
                <p>
                <input type="submit" class="button-primary" value="Guardar configuración">
                </p>
    
            </form>

    I need just two things.

    first - I need a way of get the values of the checkboxes selected, (remember that the checkboxes have of value the id of the post), with those values i can search those ids in the public view of the widget for show them. But i dont understand the options.php, ho can i save those ids, or other way of get what i need?

    Second - if you see in each checkbox there is an onClick event, thats why i tried to get the values with javaScript, but i thing is not the correct way. I need to keep those checkboxes that the user has selected, because i dont want to loose the selection if you recharge the page or send the form, if i saved the checkboxes selected i can save the ids of the posts easier.

    Any help ?? =)

  2. ssoulless
    Member
    Posted 1 year ago #

    Well you can create another theme for that in the hacks forums... but there is a lot of those plugins already made in wordpresss.org.

  3. bcworkz
    Member
    Posted 1 year ago #

    Hi ssoulless.

    You should take a look at the Settings API. It takes over much of the work in handling and saving settings in the options table. Your front end code can directly access the settings with get_option().

    I don't wish to create any more work for you, but I have a few suggestions for your plugin. You might want to consider some sort of filter similar to what is on the Posts admin panel so it is easier to find posts to check off. You could even extend the list table class in order to have a similar interface. For that matter, you could add a custom column to the posts table similar to the checkbox already there to collect your settings. You'd probably need to use AJAX to capture the checkbox state since the posts table has no submit button.

  4. ssoulless
    Member
    Posted 1 year ago #

    Pretty great!!, i could found how to add values in the data base for work with them, with the add_option(); update_option(); get_option;

    is really great!
    In Drupal works different thats why i didnt know it, i have to read more the Wordpres´s API

    According with your suggestion, im trying first achieve put the selected posts, then i will add ajax and other ways for filter the posts in the list

  5. ssoulless
    Member
    Posted 1 year ago #

    Thanks it is resolved

Topic Closed

This topic has been closed to new replies.

About this Topic