i created a wordpress plugin .when i activated the plugin i got "plugin activated" flash msg. actually i want to customize this message to "connect to my-plugin" and also provide a link to this plugin settings page. i try
add_action( 'admin_notices', 'your_custom_function' );
function your_custom_function() {
echo "connect to my-plugin";
if( $error ) {
// Put everything here
}
}
results connect to my-plugin msg shown on every page in admin panel.i just want to show my custom msg only at the time of activation on plugins page only
also i got an error
The plugin generated 2 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.
I guess the one filter hook you are looking for is plugin_action_links_(plugin_file_name) which allows you to add custom links to your plugin entry on the Plugins page.
To display an activation message, see this tutorial.
You could have found these two with some research on your own.
Related
I'm building a WordPress plugin and want to display a message on activating the plugin and on its deactivation.
It should display the message one time on the plugins page in the dashboard.
I have tried it with admin_notices hook but the message continuously displayed.
Can anyone tell me any condition or method to achieve this or any WordPress hook?
Well you can show the message on activation of your plugin only once.
Here is how you can do it:
1) Register a new setting option in your plugin i.e. plugin_status
2) Write this code:
function when_my_plugin_activate() {
if (get_option('plugin_status') != 'active' && !is_plugin_active('your-plugin-folder/your-plugin-file.php')) {
echo 'Your Message Here!';
update_option('plugin_status', 'active');
}
}
add_action('admin_notices', 'when_my_plugin_activate');
3) Here is another code block on deactivation of the plugin to change the status:
function when_my_plugin_deactivate() {
update_option('plugin_status', 'inactive');
}
register_deactivation_hook(__FILE__, 'when_my_plugin_deactivate');
add a setting option and when display message change setting value and use if()
its deactivation
I want to display an activation message after activating the plugin.
I've seen a few questions on SO about this, but none of 'em work properly:
if (!get_option("startup")) {
echo "<div class='updated'><h3>Welcome to [name]</h3>";
update_option('startup', 'true');
}
That works.. kinda. It puts the HTML at the very top, even before the <!DOCTYPE>. Is there any way to put it at the right place? So in the body tag?
There's a few things you'll need to do here. Firstly, the register_activation_hook() function is used to hook into the activation of your plugin. And the admin_notices action is used to add a notice inside the admin area (you can't just print your notice out anywhere).
However, there's an additional complication in that you can't use the admin_notices action on plugin activation. This is because WordPress doesn't 'live activate' your plugin - it activates it in the background and suppresses the output in order to make sure, before completing the activation, that it doesn't trigger any fatal errors.
Fortunately, this blog post outlines a solution to this problem. The author of the post suggests using transients to save the 'state' of your plugin so that it can be retrieved once it has been activated.
Because that blog has a CC-BY-SA license like this site, I'll copy the code in here so it lives on. I've slightly condensed it to keep the length of this post down, but you can view the whole blog post for the full solution. I've also tested this to ensure it still works - and it does on my install of WordPress 4.5.3.
register_activation_hook( __FILE__, 'fx_admin_notice_example_activation_hook' );
function fx_admin_notice_example_activation_hook() {
set_transient( 'fx-admin-notice-example', true, 5 );
}
add_action( 'admin_notices', 'fx_admin_notice_example_notice' );
function fx_admin_notice_example_notice(){
/* Check transient, if available display notice */
if( get_transient( 'fx-admin-notice-example' ) ){
?>
<div class="updated notice is-dismissible">
<p>Thank you for using this plugin! <strong>You are awesome</strong>.</p>
</div>
<?php
/* Delete transient, only display this notice once. */
delete_transient( 'fx-admin-notice-example' );
}
}
I have created a magento plugin and I need to add custom notification to magento admin just below the admin menu where the LATEST and CRITICAL error are shown.
I have also tried the steps from this link https://www.openstream.ch/developer-blog/adding-magento-admin-notifications-to-your-extension/. The custom notification are not shown still.
What I need is to display my custom error notification in admin section default just like how other notifications are displayed.
Can anyone tell me the steps to do that?
I was also looking for the same solution. I decided to check opensource repositories and i happen to come across a working version of the "Openstream" turorial you had mentioned.
all you have to do is:
download the files from here
drop the files in your Magento app folder
edit the config.xml file with your feed address/directory
flush Magento cache
Refresh page and you should see your feed.
Here's another extension with similar features: custom notification
i haven't tried this one...
I hope one of these help you!
There is a singleton for that!
... } catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
add the exception or whatever you want. This doesn't need to be in a try catch.
Set Your Message.
Mage::getSingleton("core/session")->addSuccess("Add success message");
Mage::getSingleton("core/session")->addError(" Add error message");
Mage::getSingleton("core/session")->addNotice("Add notification message");
Display Your Message. (Optional If use custom Extension Or not Defined)
<?php echo $this->getChildHtml('global_messages'); ?>
3.Define Block in Layout. (Optional If use custom Extension Or not Defined)
<block type="core/messages" name="global_messages" as="global_messages"/>
I'm building a Wordpress plugin and as per the plugin functionality requirement I need to find out if a Wordpress theme has a particular hook or not and in case if it doesn't have then I need to perform some action. Say for eg. show an alert message.
The WordPress function has_action is used for this purpose.
Here's a really basic example showing how you can echo a message if the theme doesn't have the hook you need:
if(has_action('example_hook')) {
do_action('example_hook');
} else {
echo 'an example alert message';
}
There's some more about has_action in the Codex.
i created a wp plugin, now, whenever i change it through
a) editor,
b) manually in Sublime Text2 and then delete from wp, and re-upload the changed version
and go to page with shortcode that's supposed to trigger plugin, i see no changes. i now have just few words and no html tags whatsoever in php page its supposed to include, it still displays the old html table that was there
here's the code i use to activate the plugin when i 'install' it in WP
register_activation_hook( __FILE__, 'act');
function act(){
add_option('Activated_Plugin','Plugin-Slug');
/* activation code here */
}
function getxml( $atts ){
include 'getxml.php';
}
add_shortcode( 'boixml', 'getxml' );
Did you install W3 Total Cache or WP Super Cache plugins?
Try that link may it give you the key to solve that problem
http://codex.wordpress.org/WordPress_Optimization/Caching