WordPress.org

Ready to get started?Download WordPress

Forums

Problem with database manipulation (1 post)

  1. alexandreuti
    Member
    Posted 1 year ago #

    I'm making a plugin for any visitor manipulate data in the database I created via shortcode, but occurs the error "Fatal error: Call to undefined function add_filter () in ... wp-admin \ includes \ plugin.php on line 1691 ". Does anyone have any suggestions or solution? Below is one example

    ----- In the file cidade.php I have

    <?php

    /*
    Plugin Name: Teste
    Plugin URI: http://www.unii.com.br
    Description: Create[x], Read[x], Update[x], Delete[ x] dados em uma tabela
    Author: UNII Web Technology
    Version: 1.0
    Author URI: http://www.unii.com.br
    */

    define( 'PLUGIN_PATH', plugin_dir_path(__FILE__) );
    require_once ( PLUGIN_PATH . '/includes/functions.php');

    require_once ( ABSPATH . '/wp-admin/includes/plugin.php' );

    add_action( 'admin_menu', 'adiciona_menu' );

    add_shortcode( 'lista_cidade', 'home_cidade' );

    ?>

    ----- In the functions.php file I have
    <?php
    define( 'PLUGIN_PATH', plugin_dir_path(__FILE__) );
    require_once ( PLUGIN_PATH . '/includes/forms.php');

    require_once ( ABSPATH . '/wp-admin/includes/plugin.php' );

    function adiciona_menu() {

    add_menu_page( 'teste','teste', 'manage_options',
    'teste-menu', 'options_default', plugins_url( 'icon.png', __FILE__ ) );

    add_submenu_page( 'teste-menu','Cidade', 'Cidade',
    'manage_options', 'cidade', 'home_cidade' );
    }

    ?>

    ----- In the file forms.php I have
    <?php

    require_once ( ABSPATH . '/wp-admin/includes/plugin.php' );

    function home_cidade () {

    <form method="post" action="<?php echo plugins_url('crud.php', __FILE__); ?>">
    <input type="hidden" name="func" value="salvar_cidade" />
    <input type="hidden" name="current_url" value="<?php echo the_permalink(); ?>"/>

    <table class="wp-list-table widefat fixed" >
    <tr>
    <td style="width: 100px">Cidade</td>
    <td><input type="text" name="cidade" size="60" /></td>
    </tr>
    </table>

    <input type="submit" value="salvar" class="button-primary"/>
    </form>
    }

    ?>

    ----- In the file crud.php I have

    <?php

    require_once ('../../../../wp-admin/includes/plugin.php' );

    if (isset ($_POST['cidade'])) {

    global $wpdb;
    $cidade_data = array();
    $cidade_data['cidade']=( isset( $_POST['cidade'] ) ? $_POST['cidade'] : '' );
    $curr_url = ( isset( $_POST['current_url'] ) ? $_POST['current_url'] : '' );

    $wpdb->query( $wpdb->prepare( "INSERT INTO cidade(cidade) VALUES (%s)",$cidade_data['cidade']));

    wp_redirect( $curr_url);
    exit;
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic