Updating failed after adding shortcode - wordpress

I have created a new plugin for youtube video slider. I have used below code for plugin creation. After activating this plugin, post and page update is not working. I am getting the error is "Updating failed"
I have used shortcode like this [az_youtube_slider] in my post.
Can you please anyone help me to fix the error.
Thanks in advance.
<?php
/*
Plugin Name: Assistanz youtube slider
Plugin URI: https://www.assistanz.com/
Description: Get videos from youtube assistanz channel and slider
Version: 1.0
Author: Safia
Author URI: https://assistanz.com/
License: GPLv2 or later
Text Domain: assistanz
*/
if(!defined('ABSPATH')) exit;
function az_youtube_slider($atts, $content = null) {
return "<p>Youtube video will come here</p>";
}
add_shortcode("az_youtube_slider", "az_youtube_slider");
?>

Use 'Classic Editor' plugin to fix your issue also your function will not work, please update your function with below.
function displayDate($atts, $content = null) {
return "<p>Youtube video will come here</p>";
}
add_shortcode("az_youtube_slider", "displayDate");

Related

how to remove wordpress documentation menu link in dashboard

I want to customize my dashboard by removing WordPress icon and it's menu on the top bar but I have no idea of how it works because am not an expert in WordPress please help me
Create a new file in the WordPress wp-content/plugins/ folder named admin-bar.php then add the following plugin header:
<?php
/*
Plugin Name: Admin Bar
Plugin URI: http://www.sitepoint.com/
Description: Modifies the WordPress admin bar
Version: 1.0
Author: Craig Buckler
Author URI: http://twitter.com/craigbuckler
License: MIT
*/
You can now activate this plugin in the WordPress administration panel. It won’t do anything yet but you can make additions, save then refresh to view the updates.
you can remove existing items with the remove_node() method. For this, we need to create a new function named update_adminbar() which is passed an WP_Admin_Bar object ($wp_adminbar). This function is called when the admin_bar_menu action hook is activated:
// update toolbar
function update_adminbar($wp_adminbar) {
// remove unnecessary items
$wp_adminbar->remove_node('wp-logo');
$wp_adminbar->remove_node('customize');
$wp_adminbar->remove_node('comments');
}
// admin_bar_menu hook
add_action('admin_bar_menu', 'update_adminbar', 999);
https://www.sitepoint.com/customize-wordpress-toolbar/
You can create a custom plugin and upload folder to your server with this one file in it. Make sure to save the file as exact plugin name. For example, "AdminBar.php"
<?php
/*
Plugin Name: AdminBar
Plugin URI:
Description: Code to hide the admin bar for non-admins only.
Version: 1.0
Author: Name Here
Author URI:
*/
function hide_admin_bar_settings()
{
?>
<style type="text/css">
.show-admin-bar {
display: none;
}
</style>
<?php
}
function disable_admin_bar()
{
if(!current_user_can('administrator'))
{
add_filter( 'show_admin_bar', '__return_false' );
add_action( 'admin_print_scripts-profile.php', 'hide_admin_bar_settings' );
}
}
add_action('init', 'disable_admin_bar', 9);

Removing a Wordpress Action from theme via plugin

Im adding a copyright link in footer of a theme using the
function copy() {
echo '<div class="copyright">Text</div>';
}
add_action('wp_footer', 'copy');
and trying to remove it writing a simple plugin like this one:
<?php
/*
Plugin Name: Link Remover
Plugin URI: http://domain/
Version: 1.0
Author: authorname
Description: Plugin description
*/
remove_action('wp_footer', 'copy');
?>
but it doesnt remove in this way is there any other method to do this?
thanks...
Try this:
function remove_copyright()
{
remove_action('wp_footer', 'copy');
}
add_action('init','remove_copyright', 15);

Addon to the FormCraft plugin doesn't work (Wordpress)

I'm trying to create an addon for the FormCraft Wordpress plugin and I'm having some trouble with it.
I've edited a demo addon based on the FormCraft documentation, added it to my Wordpress as a plugin. But it doesn't seem to work.
I tried just copy-pasting the demo addon from http://formcraft-wp.com/help/developing-an-add-on-for-formcraft/. But it also didn't work.
Here's the code:
<?php
/*
Plugin Name: FormCraft Demo Add-On
Plugin URI: http://ncrafts.net/
Description: Demo Add-on for FormCraft
Author: nCrafts
Author URI: http://ncrafts.net
Version: 1
Text Domain: formcraft-demo
*/
// Tell FormCraft our add-on exists
add_action('formcraft_addon_init', 'formcraft_demo_addon');
function formcraft_demo_addon()
{
register_formcraft_addon( 'demo_addon_settings', 0, 'Demo Addon', 'DemoController');
}
// We show a simple text field in the add-on's settings
function demo_addon_settings() {
echo "<input style='margin: 20px 10%; width: 80%' placeholder='Banned hosts' type='text' ng-model='Addons.DemoAddon.banned_hosts'>";
}
add_action('formcraft_after_save', 'your_function', 10, 4);
function your_function($content, $meta, $raw_content, $integrations)
{
file_get_contents('https://my-app.com/send_request?formcraft=true');
}
?>
Nothing is showing up in the settings and based on my server logs nothing is being sent in the formcraft_after_save action.
What am I missing?
author of FormCraft here.
Firstly, please make sure you are using FormCraft version 3.2.6 or above. Is the Demo Addon showing up when you edit any form, and go to Add-Ons -> Installed?
You can reach me directly at nish at ncrafts dot net as well.

Wordpress shortcode is not called

Okay, I have created a plugin and now want to provide shortcode to app.
Here is my only file in wp-content/plugins/my-plugin/my-plugin.php
<?php
/**
* Plugin Name: Latest Issue
* Author: Max Tsepkov
* Author URI: http://www.yogi.pw
*/
add_action('init', function() {
add_shortcode('my-plugin', function() {
// ... my code
return 'string';
});
});
I know that plugin is activated and the callback for init is called.
But the shortcode function is never get called.
I add text [my-plugin] to a widget, and it isn't replaced as well.
What do I do wrong? How to correctly register a shortcode?
I guess you PHP is at least 5.3, so you can make it work in a widget, you need to add this code.
add_filter('widget_text', 'do_shortcode');
I tested your code and it works.
Turned out, that some themes are not parsing shortcodes in widgets.
We can explicitly hook into theme filter and let it run shortcodes in widgets.
For details see https://wordpress.org/support/topic/how-to-make-shortcodes-work-in-a-widget
And there is no need for hook into init action. This code works:
<?php
/**
* Plugin Name: Latest Issue
* Author: Max Tsepkov
* Author URI: http://www.yogi.pw
*/
// Allow theme to parse shortcodes in widgets
add_filter('widget_text', 'do_shortcode');
add_shortcode('my-plugin', function() {
// ... my code
return 'string';
});

Wordpress Plugin Development - What am I doing wrong

What am I doing wrong....this doesnt seem to work... I keep getting the following error
Warning: Cannot modify header information - headers already sent by (output started at /home/puretige/public_html/wp-content/plugins/Pure Tiger/puretiger.php:13) in /home/puretige/public_html/wp-includes/option.php on line 568
Warning: Cannot modify header information - headers already sent by (output started at /home/puretige/public_html/wp-content/plugins/Pure Tiger/puretiger.php:13) in /home/puretige/public_html/wp-includes/option.php on line 569
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.
Please note I am very new to this....
<?php
/*
Plugin Name: Pure Tiger Hosting
Plugin URI: http://www.puretigerhosting.com/wordpressplugin
Description: Themes, Plugins and Support from within your admin panel.
Version: 1.00
Author: Pure Tiger Hosting
Author URI: http://www.puretigerhosting.com
License: GPL2
*/
?>
<?php
add_action('admin_menu','register_custom_menu_page');
add_action('admin_menu','register_my_custom_submenu_page');
add_action('admin_menu','register_my_custom_submenu_page2');
add_action('admin_menu','register_my_custom_submenu_page3');
Function register_custom_menu_page() {
add_menu_page('Pure Tiger', 'Pure Tiger','pure-tiger','add_users','','', 6);
}
/*-----------------------------Sub Pages--------------------------------------------*/
function register_my_custom_submenu_page() {
add_submenu_page( 'pure-tiger','Themes','Themes','PTthemes','','','my_custom_submenu_page_themes');
}
function register_my_custom_submenu_page2() {
add_submenu_page( 'pure-tiger','Plugins','Plugins','PTPlugins','','','my_custom_submenu_page_plugins');
}
function register_my_custom_submenu_page3() {
add_submenu_page( 'pure-tiger','Ask a Question','Ask a Question','question','','','my_custom_submenu_page_question');
}
/*-----------------------------Themes--------------------------------------------*/
function my_custom_submenu_page_themes() {
echo '<h3>Pure Tiger Themes</h3>';
}
/*-----------------------------Plugins--------------------------------------------*/
function my_custom_submenu_page_plugins() {
echo '<h3>Pure Tiger Plugins</h3>';
}
/*-----------------------------Support--------------------------------------------*/
function my_custom_submenu_page_question() {
echo '<h3>Pure Tiger Support</h3>';
}
?>
Try removing the open close php tags before your plugin declaration.
/*
Plugin Name: Pure Tiger Hosting
Plugin URI: http://www.puretigerhosting.com/wordpressplugin
Description: Themes, Plugins and Support from within your admin panel.
Version: 1.00
Author: Pure Tiger Hosting
Author URI: http://www.puretigerhosting.com
License: GPL2
*/
<?php
add_action('admin_menu','register_custom_menu_page');
//remaining code to follow....
Remove close ?> and open <?php tags after copyright notice. 2 newline prevent wordpress from sending headers.
<?php
/*
Plugin Name: Pure Tiger Hosting
Plugin URI: http://www.puretigerhosting.com/wordpressplugin
Description: Themes, Plugins and Support from within your admin panel.
Version: 1.00
Author: Pure Tiger Hosting
Author URI: http://www.puretigerhosting.com
License: GPL2
*/
add_action('admin_menu','register_custom_menu_page');
add_action('admin_menu','register_my_custom_submenu_page');
Check if this plugin trys to write a cookie.
If this is the case, then your plugin has to be initiated BEFORE any html code processing.
So you have to initiate the plugin in the top of your index.php, before the <!doctype ... >
Some reading about cookies : http://php.net/manual/en/features.cookies.php

Resources