Wordpress Plugin Development - What am I doing wrong - wordpress

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

Related

Updating failed after adding shortcode

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");

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.

url of child theme in wordpress

I want to create a website in wordpress, for this I take a theme and create a child theme.
I copy in the folder of the child a style.css and header.php, because I want to modify the header too. I modify the file of the child.
In my style.css I add the line Template: with the name of the father theme
/*
Theme Name: Example
Theme URI: http://www.woothemes.com/
Version: 1.2.15
Description: Designed by WooThemes.
Author: WooThemes
Author URI: http://www.woothemes.com
Tags: woothemes
Template: mystile
Copyright: (c) 2009-2011 WooThemes.
License: GNU General Public License v2.0
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
I am using this line in the header.php
<?php $logo = esc_url( get_template_directory_uri() . 'images/logo.png' ); ?>
of my child theme to take a images but this line return the url of the father theme no his child!
I take this.
http://localhost/.../wp-content/themes/mystile/images/...
I I want this
http://localhost/.../wp-content/themes/example/images...
any idea
You need get_stylesheet_directory_uri, this function checks first in the child theme directory and then in the parent's. The one you're using only checks in the parent directory.
Bottom line: if a function doesn't behave as you expect, check the Codex. Much probably you'll find out why over there.
Add to functions.php:
// create a URL to the child theme
function get_template_directory_child() {
$directory_template = get_template_directory_uri();
$directory_child = str_replace('storefront', '', $directory_template) . 'child-storefront';
return $directory_child;
}

Resources