mardi 23 février 2016

Adding html in wordpress plugin

I am writing my first wordpress plugin. It's supposed to send a message on plugin page whenever user saves/edits pages. The problem is I can't quite get it to print the messages.

Here is my code:

<?php

    /*
    Plugin Name: Monitor
    Plugin URI:
    Description: Test plugin monitoring user activities
    Author: 
    Version: 1.0
    Author URI: 
    */


if (!function_exists('p_update')) {  
    function p_update( $post_id ) {
        $post_title = get_the_title( $post_id );
        $post_url = get_permalink( $post_id );
        $message = "Changed: " . $post_title . "Link: " . $post_url ;
        echo "<p>test1</p>"
    }
}

if (!function_exists('p_publish')) {
    function p_publish( $post_id ){
        $post_title = get_the_title( $post_id );
        $post_url = get_permalink( $post_id );
        $message = "abc";
        echo "<p>test2</p>"
    }
}

if (!function_exists('plugin_menu')) {
    function plugin_menu() {
        add_menu_page( 'Monitor', 'Monitor', 'manage_options', __FILE__, 'plugin_options');
    }
}

if (!function_exists('plugin_options')) {
    function plugin_options() {
        if ( !current_user_can( 'manage_options' ) )  {
            wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
        }
    echo '<div class="wrap">';
    echo '<p>test</p>';
    echo '</div>';
    }
}

add_action( 'admin_menu', 'plugin_menu' );
add_action('save_post', p_update);
add_action('publish_post', p_publish);

?>

The plugin_menu function displays html properly, but other functions can't do that. What am I doing wrong? I'm sure there is some easy way of doing that but no tutorial I've seen adresses this problem.

Thank you in advance for your help.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire