When adding fields to add pages and posts, or to get Custom Post Type ( CTP ), you have to record an action to save these new data. The implementation of this procedure is essentially always the same, changing only the fields and how to save, the extra data can reside in the 'custom field', or the table post meta, or on a personal or more tables.
Articles Tagged 'add_action ()'
WordPress Snippet: the action save_post
WordPress Snippet: is_page () on Custom Post Type
If you recorded your own Custom Post Type ( CPT ), especially if you type 'page', you could serve to determine if you are viewing that particular page, the 'single' so to speak. . In this case it is useless to try with is_page() or is_page_template() . The clean solution is the following:
1 2 3 4 5 6 | is_singular ( 'cpt_key' ) ) { if (is_singular ('cpt_key')) { ; global $ post; $post -> post_name == 'slug_pagina' ) { if ($ post -> post_name == 'slug_pagina') { / / Your code here ... type add_action (), wp_enqueue_scripts (), etc ... } } |
WordPress Snippet: add styles and scripts to Custom Post Type
Now that WordPress allows you to create types of custom post (CPT), it becomes useful to be able to add our styles and our script when you view or edit our posts. The best way to do that is compatible with release 3.3 is the following:
1 2 3 4 5 6 7 | , function ( ) { add_action ('admin_enqueue_scripts', function () { ; global $ typenow; $typenow == 'id_custom_post' ) { if ($ typenow == 'id_custom_post') { , 'css/customstyle.css' ) ; wp_enqueue_style ('key_style', 'css / customstyle.css'); , 'js/customscript.js' ) ; wp_enqueue_script ('key_script', 'js / customscript.js'); } }); |
WordPress Delete Post
WordPress allows you to listen for when a post - even custom type - is being eliminated. . There are two hook action that can be used: delete_post and deleted_post . At first the former should be attributed to a "is being eliminated" the post, even if it does not seem to be, or better.
Very short trick: WordPress, customize the Meta Box thumbnail
In reference to this comment : Metabox the thumbnails usually has the title set to "image evidence".
10 useful WordPress snippets
With the release of WordPress 3.0 will change many things for us developers. The date nature of this major release are many and very useful for those developing with this CMS now truly complete. We could say that if you close one era and opens a new and full of Possibilia. I pay tribute to the previous versions so with a number of useful snippets some very valid even with the new release.
WordPress: Add a panel on the bulletin board
It may be useful in developing a plugin and not only, place a panel of information, summary or otherwise, directly to the Dashboard (Dashboard) of WordPress, as is the case for standard board of the "Status", "Recent Comments "... etc
Wordpress allows you to add our panels in a simple way, exploiting the function wp_add_dashboard_widget() :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | / / First we add a hook through 'wp_dashboard_setup' / / To record our role in the creation , 'example_add_dashboard_widgets' ) ; add_action ('wp_dashboard_setup', 'example_add_dashboard_widgets'); / / This adds the panel to physically Dashboard example_add_dashboard_widgets function () { , wp_add_dashboard_widget ('example_dashboard_widget', 'Example Dashboard Widgets', ; 'Example_dashboard_widget_function'); } / / Draw the contents of the panel example_dashboard_widget_function function () { ; echo "Try My Widgets on Dashboard"; } |
The function wp_add_dashboard_widget() has the following synopsis:
1 2 3 4 5 6 7 8 9 10 | / / / / $ Widget_id - is a unique identifier type slug. / / Will be used also as a class in the style css / / $ Widget_name - Name displayed in the Widget Bar / / $ Callback - which will show the name of the FunZone conntenuto / / $ Control_callback - (Optional) Name of the function used to send / / Parameters via form / / , wp_add_dashboard_widget ($ widget_id, $callback , $control_callback = null ) Widget_name $, $ callback, $ control_callback = null) |
WordPress: extended user information
The information about a user or author of a WordPress blog can be extended easily. This could for example be useful to include the date of birth, bibliographic information, the address of the workplace or, extremely comfortable, a camp for special permission - to be checked later in the template.
The operation you are going to do does not require a plugin, but the code you need can be placed in the - usual - file functions.php .
Wordpress: remove the menu administration
It can be helpful at times, "obscure" some WordPress administration menu, especially if you developed a site / blog for a client and do not want to allow access to particularly sensitive features. There are already plugins that do this function but, for a personal check and complete, we see how this feature works in detail.
As always we exploit for the very useful Action made available by WordPress, in this case admin_menu . Using the global variable $menu can access the administration menu list. We can find the menu to "eliminate" in two ways: through the label or through the link pointed to (see commented shares in the example below). In the example given is "grayed-out" menu items Design, Settings, and Plugins:
1 2 3 4 5 6 7 8 9 10 11 12 13 | remove_menu_item function () { ; global $ menu; / / By label array ( 'Design' , 'Impostazioni' , 'Plugins' ) ; Removes $ = array ('Design', 'Settings', 'Plugins'); / / By link / / Removes $ = array ('themes.php', 'options-general.php', 'plugins.php'); $removes as $todel ) foreach ($ as $ Removes todel) $menu as $key => $sm ) if ( $sm [ 0 ] == $todel ) { unset ( $menu [ $key ] ) ; break ; } foreach ($ menu as $ key => $ level) if ($ sm [0] == $ todel) { unset ($ menu [$ key]) break;} / / By link / / Foreach ($ menu as $ key => $ level) if ($ sm [2] == $ todel) {unset ($ menu [$ key]) break;} } / / , 'remove_menu_item' ) ; add_action ('admin_menu', 'remove_menu_item'); |
Use the link as a key to the removal ( $sm[2] in parts sorpra commented in the code), is useful when you are not sure of the language - localization - with which you installed WordPress. With this technique, however, the menu is removed only at the interface, so you can still access the site via a direct link.






Latest Comments
Mark : Thank you very much, I've lit
I solved it by setting [cc_objc] / / OptionViewController.m - ...
Giovambattista Fazioli : @ Mark: I suggest you think a more correct approach. If you run the subclass of the tab ...
Mark : Excuse the spam .. I noticed that there is an error .. here is the correction [cc_objc] / PrimaClasse.h ** ** / # import ...
Marco : forgotten .. in [cci] OptionViewController [/ cci] for [cci] @ syntetize [/ cci] I put the delegate
louis : very clear and simple I have to admit that writing a pa hardly use delegates created by ...