Friday, January 24, 2014

Latest Posts Slide change effects for drop down menus WordPress Login Screen Logo unslider - simple


Currently I am working more intensively with creating WordPress plugins. Recently, I've already written jcpennies something to the basic structure of a WordPress plugin. Today I want to show you how to get the item to view boxes that are needed for example for a plugin adds. As can be seen in the picture, it is the aim to collect additional data when articles. add_meta_boxes
In the first step we need to tell WordPress that we want to make a new Metabox available. We just hang on an action. The code for this can be easily placed in the main plugin file. / * Adds the articleview a new metabox * / add_action ('add_meta_boxes', 'function');
At this point, some important information should be provided, including: $ id - The CSS ID $ post_type - for the contribution type the Metabox jcpennies to be made available? In our case, here 'post' are. $ Callback - What is the function to be called? More information can be found as usual at WordPress itself
For the actual design or the content design we use at this point the callback function. / / Optical design of the metabox function meta_box_content () {/ / nonce field wp_nonce_field ('meta_box_nonce', 'box_nonce');?> <p> <label For="param"> Param </ label> <input type = "text "name =" param "id =" param "value =" "/> </ p> <? php}
The structure of the function that is responsible for the look, it is very easy. In our example, it consists jcpennies of only one input field, everything else takes WordPress automatically. I have incorporated jcpennies at this point for minimum safety nor the nonce field. It is used to validate whether an action actually comes from your own blog.
First WordPress will need to inform you that the future is an additional function to be executed when saving an article. We hang back at an action. / * Hangs when saving the save function to * / add_action ('save_post', 'save_function');
In the save_function we can then write everything that has to do with the storage of the data. / / Storage function of the metabox function save_function ($ post_id) {/ / autosave if (defined ('DOING_AUTOSAVE') && DOING_AUTOSAVE) return; / / if our nonce field is not present, then protest if (isset ($ _POST ['meta_box_nonce! '!]) | | wp_verify_nonce ($ _POST [' meta_box_nonce '],' box_nonce! ')) return; / / user has no authorization if (current_user_can (' edit_post ')) return; / / save the asin if (isset ( $ _POST ['param'])) update_post_meta jcpennies ($ post_id, 'param', wp_kses ($ _POST ['param'], $ allowed));}
It is important within the function that, besides the validation jcpennies of the nonce field also auto-save, as well as the access authorization of users is checked. The actual part where the information of our Metabox are stored, can be found at the bottom of the function. With this type of information, I have decided to use the post_meta table. This is great for additional information about a product.
This saving is already done. Now we only need 1-2 small adjustments in our meta_box_content function, jcpennies so that we, the values are also displayed in the future. / / Optical design of the metabox function meta_box_content () {$ post_customs = get_post_custom ($ post-> ID); $ param = isset ($ post_customs ['param'])? esc_attr ($ post_customs ['param'] [0]):''; jcpennies / / nonce field wp_nonce_field ('meta_box_nonce', 'box_nonce');> <p> <label for="param"> Param </ label>? <input type = "text" name = "param" id = "param" value = "? <php echo $ param;?>" /> </ p> <php}?
And I read from all post_meta values to the article and find me then out the right one. Thus, the value is then ultimately displayed, the input field still needs a small addition in the value attribute. Conclusion
That's it for now. An extension of your WordPress plugins to such a Metabox's really not complicated and for the user a great thing to be very easy to collect additional data. Post navigation
You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> < del datetime = ""> <em> <i> <q cite=""> <strike> <strong>
Latest Posts Slide change effects for drop down menus WordPress Login Screen Logo unslider - simple jQuery Slider arrow keys to site navigation use WordPress plugin creation - the item overview a new Metabox Add contact

No comments:

Post a Comment