This would be an good use PHP 5.3+ anonymous functions.
Closure example:
<?php
function Twit_the_url( $post_ID )
{
//connect to twitter api
//send tweet with url
//get twitter response
//send response to admin notice :
add_action('admin_notices', function() use ($httpstatus) {
echo '<div class="error"><p>', esc_html($httpstatus), '</p></div>';
});
return $post_ID;
}
add_action( 'publish_post', 'Twit_the_url');
Alternatively, you could wrap up both the Twit_the_url
and admin_notices
callback into a class and use class property.
Related Posts:
- WordPress admin notice in plugin function
- How can I edit post data before it is saved?
- Auto Load Plugin Hooks inside Must Use Plugin
- How to only hook on Single.php after content?
- How to stop showing admin notice after close button has been clicked
- How can I log a user out of WordPress before the page loads?
- What is the ‘admin_action_’ . $_REQUEST[‘action’] hook used for?
- Autogenerate wordpress shortcodes using array?
- Enqueue style inside shortcode but its loaded at the bottom of page (before footer scripts)
- Is there a global action for when a plugin is uninstalled?
- Shortcode display outside the div
- Good tools for locating hooks in a wordpress page/admin interface/blog post?
- How to remove action from plugin?
- Very stubborn wp_register_script / add_action vs remove
- do_action and hook methods
- Is it possible to add an action to the currently running action?
- Is there an action that is called when a post is restored from the trash?
- Action on post publish
- How to add inline css/js inside a shortcode
- How to prevent action in ajax request, when in admin side?
- What is the purpose of $merged_filters?
- add action wp_head not working
- Can I use a method from an existing plugin as an action hook?
- What are the benefit in adding hook in the init() hook?
- Detect when any plugin is activated or deactivated
- Where to hook my plugin’s action
- Overwrite or Replace code in WP_Footer
- How do action and filter hooks understand where to look for the core function that we hooked our function to them
- Get posts from WP_Query and format them on admin_head
- Automatically add attributes to woocommerce product?
- Any hook for pre-plugin-update -either bulk or single plugin update
- wordpress plugin is not activating from widget
- When to load auto-login code?
- How to get all of the activate_plugin action parameters?
- Get Time Taken By Each Action Hook in WordPress
- Are functions in main plugin file called before function bound to register_activation_hook runs?
- Removing an action from wp_footer called in a class that’s inside a bigger class
- WordPress user account activation
- External Script Using WP – Hooks / Actions Not Working?
- Submit custom form from post content and execute in plugin
- add_action in a custom plugin
- What is @Action in WordPress?
- Add action to fire when a published post is updated
- _prime_post_caches in wordpress
- How passing values to construct function with Actions?
- add_action into another add_action not working
- Run a plugin just ‘once’ per page reload
- Using add_action before add_filter on a plugin?
- a weird attribute on every html tag
- Submit Form data to another page via Ajax (WordPress Way)
- Why do plugins often ask to add in to templates?
- Does using `add_action( ‘init’…` cause performance issues?
- remove_action not removing add_action from constructor
- How to get menu location in wp_update_nav_menu hook
- Are there action hooks for comments?
- WooCommerce: after install hook
- Advanced WordPress plugin activation detection
- how to execute some code after a post is published in WordPress [duplicate]
- How to remove products-links after the product title using remove_action
- Dequeue, Unregister, Remove Action – Not Working on Plugin
- wp_get_http has been deprecated. Use WP_Http instead
- Add action to custom Function
- How to use add_action for multiple instances of the same class
- How to hook into action/filter call
- Trying to get property of non-object wordpress error message
- Edit post image attributes on fly?
- update_option_{$option} not working (do function after options are saved)
- Hide all Admin Notices and move on a separate page
- Why do actions with class and public method don’t fire __construct()
- Changing wordpress/woocommerce notices default message to other languages (text)
- i create functions.php in plugin files but add_action (‘wp_head’, ‘function_name’) don’t work
- Sharing varible between two add_actions
- Hooking into the HTML header container
- Troubleshooting Admin_Notice
- Removing Plugin Action via Theme for Non-admins
- WPML – Hook when language is switched (change user language)
- Remove action added in plugin class from theme
- {status}_{post_type} does not run correctly?
- Creating Admin Submenu Page via Class Method
- How to get bulk actions handler to display simple “Hello World”?
- Help needed with woocommerce (wc stripe) filter
- Why is WP template_include overwritting all templates rather than specified page?
- Why can’t I shove an instance of a class into a variable from a do_action hook?
- Why doesn’t a form need an ‘action’ with a plugin that uses the post data?
- Passing a parameter to filter and action functions
- Run only on plug-in activation instead of wp_head
- Am I using an action hook correctly?
- A more elegant way to handle notices/warnings
- plugins_loaded action is not working properly
- Plugin Hook: Get posts
- Action hook “wp_insert_post” works but not for last imported post
- add_media_page function not creating submenu
- Remove action plugin
- Filter for modifying image on upload
- Is it possible to cancel a post status transition?
- Problem with executing a function on saving a post
- OOP Plugin: Where should I place the action hooks in the class?
- add query string to all pages after user logged in
- How wordpress plugin hooks works? [duplicate]
- Hook automatic_updates_complete to autoupdate plugin