wordpressdebuggingplugins

Debug Plugin Installation?


I'm developing a plugin, and all was going well until the most recent changes. Unfortunately, the previous version has been lost due to a hardware issue. And yes, I do make backups often while I'm developing a project. :-(

I am trying to figure out how to find the error that WP is having trouble with when it tries to install the plugin. I have debugging turned on, and can see the log file. But I do not see any errors/warnings from the installation attempt.

Is there a tool or method that can examine the plugin to identify what is missing from the plugin that shows where I should look?

After the update, when I try to install the plugin from the upload plugin admin page, I get the following error:

Unpacking the package…

Installing the plugin…

The package could not be installed. No valid plugins were found.

Plugin installation failed.

EDIT:

Without seeing your files, this would be impossible to debug. What's in your plugin's base file, e.g. index.php? Also and all was going well until the most recent changes what does this mean? What did you change?

The filename is csttoc_makeindex.php and the slugname is csttoc_makeindex.

I'm not asking for help with the actual debugging. I am asking for info on how to see what error the installation function is encountering.

The changes were lost, and there were several, because of a hardware failure. The only copy I had was what was in the editor (VScode) and on the server. My backups were lost after a power failure on the pc I was using for the backups. The only backup I do have was very early *n the development, and is very incomplete.

Code:

<?php
/*
    Contributors: sloanthrasher
    Tags: table of contents, toc, index, page index, headings  
    Requires at least: 5.0  
    Tested up to: 6.6
    Requires PHP: 7.2  
    Stable tag: 1.0  
    Donate link: https://sloansweb.com/say-thanks/
    Author: Sloan Thrasher
    Author URI: https://sloansweb.com/page-4/
    License: GPLv3 or later
    License URI: http://www.gnu.org/licenses/gpl-3.0.html

    A plugin to generate a dynamic, hierarchical table of contents (TOC) based on page headings using a customizable shortcode.
*/

if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly.
}

// Enqueue JavaScript and CSS


/**
 * Enqueues the csttoc-idx-script JavaScript file for use in the plugin.
 *
 * @return void
 */
function csttoc_enqueue_scripts()
{
    $ver = '1.0';

    wp_enqueue_script('csttoc-idx-script', plugins_url('js/csttoc-idx-script.js', __FILE__), array('jquery'), $ver, true);
}
add_action('wp_enqueue_scripts', 'csttoc_enqueue_scripts');

/**
 * Enqueues the selected style and plugin's stylesheet.
 *
 * @return void
 */
function csttoc_enqueue_assets()
{
    csttoc_enqueue_scripts();
    // Enqueue the selected style
    $options = get_option('csttoc_options');

    // Enqueue the plugin's stylesheet.
    $style = isset($options['style']) ? $options['style'] : 'css/csttoc_on_right.css';

    if ($style !== 'custom') {
        wp_enqueue_style('csttoc-style', plugins_url($style, __FILE__), array(), $ver);
    } else {
        if (isset($options['custom_css'])) {
            wp_add_inline_style('csttoc-style', $options['custom_css']);
        }
    }
}


/**
 * Generates a shortcode for displaying an index of headings on a page.
 *
 * @param array $atts An array of shortcode attributes.
 *                    - title: The title of the index (default: 'In This Article').
 *                    - selectors: The CSS selectors for the headings to include in the index (default: 'h2, h3, h4').
 * @return string The HTML for the index shortcode.
 */
function csttoc_index_shortcode($atts = [])
{
    csttoc_enqueue_assets();
    $options = get_option('csttoc_options');
    $default_selectors = isset($options['default_selectors']) ? $options['default_selectors'] : 'h2, h3, h4';
    $title = isset($atts['title']) && !empty($atts['title']) ? $atts['title'] : esc_html_e('In This Article');
    $selectors = isset($atts['selectors']) && !empty($atts['selectors']) ? $atts['selectors'] : $default_selectors;

    // Enqueue the selected style
    $options = get_option('csttoc_options');

    // Enqueue the plugin's stylesheet.
    $style = isset($options['style']) ? $options['style'] : 'css/csttoc_on_right.css';

    if ($style !== 'custom') {
        wp_enqueue_style('csttoc-style', plugins_url($style, __FILE__), array(), $ver);
    } else {
        if (isset($options['custom_css'])) {
            wp_add_inline_style('csttoc-style', $options['custom_css']);
        }
    }

    ob_start();
    ?>
    <div id="csttoc_pg_toc_list">
        <div class="csttoc-toc-heading"><i class="fa fa-spinner fa-spin" style="color:#f00;"></i></div>
        <div class="csttoc-toc-container"></div>
    </div>
    <script type="text/javascript">
        jQuery(document).ready(function ($) {
            csttoc_generateIdx('<?php echo esc_js($selectors); ?>');
            jQuery('.csttoc-toc-heading').html('<?php echo esc_html($title); ?>');
        });
    </script>
    <?php
    return ob_get_clean();
}
add_shortcode('csttoc_index', 'csttoc_index_shortcode');


/**
 * Adds the 'Index For A Page' plugin settings page to the WordPress admin menu.
 *
 * @return void
 */
function csttoc_admin_menu()
{
    add_management_page(esc_html_e('Index For A Page', 'csttoc_index', 'csttoc-settings'), esc_html_e('Index For A Page', 'csttoc_index', 'csttoc-settings'), 'manage_options', 'csttoc-settings', 'csttoc_settings_page');
}
add_action('admin_menu', 'csttoc_admin_menu');

/**
 * Displays the settings page for the 'Index For A Page' plugin.
 *
 * @return void
 */
function csttoc_settings_page()
{
    ?>
    <div class="wrap">
        <h1><i><?php esc_html_e('Index For A Page', 'csttoc_index', 'csttoc-settings'); ?></i><?php echo esc_html_e(' Settings', 'csttoc_index', 'csttoc-settings'); ?>
        </h1>
        <form method="post" action="options.php">
            <?php
            settings_fields('csttoc_settings_group');
            do_settings_sections('csttoc-settings');
            submit_button();
            ?>
        </form>
    </div>
    <?php
}

/**
 * Initializes the settings for the CSTTOC plugin.
 *
 * Registers the setting group, section, and fields for the plugin's settings page.
 *
 * @return void
 */
function csttoc_settings_init()
{
    register_setting('csttoc_settings_group', 'csttoc_options');

    add_settings_section('csttoc_section', esc_html_e('Index A Page Settings', 'csttoc_index', 'csttoc-settings'));

    add_settings_field('title', esc_html_e('Page Index Title', 'csttoc_title_callback', 'csttoc-settings', 'csttoc_section'));
    add_settings_field('default_selectors', esc_html_e('CSS Selectors', 'csttoc_selectors_callback', 'csttoc-settings', 'csttoc_section'));
    add_settings_field('style', esc_html_e('Page Index Style', 'csttoc_style_callback', 'csttoc-settings', 'csttoc_section'));
    add_settings_field('custom_css', esc_html_e('Custom CSS', 'csttoc_custom_css_callback', 'csttoc-settings', 'csttoc_section'));
}
add_action('admin_init', 'csttoc_settings_init');

/**
 * Outputs a description of the section for the CSTTOC plugin settings page.
 *
 * @return void
 */
function csttoc_section_callback()
{
    echo '<p>' . esc_html_e("Customize the default settings for the Page Index.", 'csttoc_custom_css_callback', 'csttoc-settings', 'csttoc_section') . '</p>';
}

/**
 * Outputs a text input field for the Page Index title setting.
 *
 * Retrieves the current title value from the csttoc_options array and uses it to populate the input field.
 * If no title value is set, it defaults to 'Page Index'.
 *
 * @return void
 */
function csttoc_title_callback()
{
    $options = get_option('csttoc_options');
    $default_title = isset($options['title']) ? $options['title'] : esc_html_e('Page Index', 'csttoc_custom_css_callback', 'csttoc-settings', 'csttoc_section');
    echo "<input type='text' name='csttoc_options[title]' value='" . esc_attr($default_title) . "' class='regular-text'>";
}

/**
 * Outputs a text input field for the default CSS selectors setting.
 *
 * @return void
 */
function csttoc_selectors_callback()
{
    $options = get_option('csttoc_options');
    $default_selectors = isset($options['default_selectors']) ? $options['default_selectors'] : 'h2, h3, h4';
    echo "<input type='text' name='csttoc_options[default_selectors]' value='" . esc_attr($default_selectors) . "' class='regular-text'>";
}

/**
 * Outputs a select input field for the Page Index style setting.
 *
 * Retrieves the current style value from the csttoc_options array and uses it to populate the select field.
 * If no style value is set, it defaults to 'css/csttoc_on_right.css'.
 *
 * @return void
 */
function csttoc_style_callback()
{
    $options = get_option('csttoc_options');
    $style = isset($options['style']) ? $options['style'] : 'css/csttoc_on_right.css';
    ?>
    <select name="csttoc_options[style]" id="csttoc_style_select">
        <option value="css/csttoc_on_left.css" <?php selected($style, 'css/csttoc_on_left.css'); ?>>
            <?php echo esc_html_e('On Left', 'csttoc_custom_css_callback', 'csttoc-settings', 'csttoc_section'); ?>
        </option>
        <option value="css/csttoc_on_right.css" <?php selected($style, 'css/csttoc_on_right.css'); ?>>
            <?php echo esc_html_e('On Right', 'csttoc_custom_css_callback', 'csttoc-settings', 'csttoc_section'); ?>
        </option>
        <option value="custom" <?php selected($style, 'custom'); ?>>
            <?php echo esc_html_e('Custom', 'csttoc_custom_css_callback', 'csttoc-settings', 'csttoc_section'); ?>
        </option>
    </select>
    <?php
}

/**
 * Outputs a textarea field for custom CSS input and toggles its visibility based on the selected style.
 *
 * @return void
 */
function csttoc_custom_css_callback()
{
    $options = get_option('csttoc_options');
    $custom_css = isset($options['custom_css']) ? $options['custom_css'] : '';
    ?>
    <textarea name="csttoc_options[custom_css]" rows="10" cols="50"
        class="large-text code"><?php echo esc_textarea($custom_css); ?></textarea>
    <script type="text/javascript">
        jQuery(document).ready(function ($) {
            function toggleCustomCss() {
                if ($('#csttoc_style_select').val() === 'custom') {
                    $('textarea[name="csttoc_options[custom_css]"]').closest('tr').show();
                } else {
                    $('textarea[name="csttoc_options[custom_css]"]').closest('tr').hide();
                }
            }
            toggleCustomCss();
            $('#csttoc_style_select').change(function () {
                toggleCustomCss();
            });
        });
    </script>
    <?php
}

Any tips or pointers to any tools I could use will be greatly appreciated!


Solution

  • Your plugin header format is wrong also you are forgot to add plugin name in header. Thats why the error encountered.

    /*
     * Plugin Name:       My Basics Plugin
     * Plugin URI:        https://example.com/plugins/the-basics/
     * Description:       Handle the basics with this plugin.
     * Version:           1.10.3
     * Requires at least: 5.2
     * Requires PHP:      7.2
     * Author:            John Smith
     * Author URI:        https://author.example.com/
     * License:           GPL v2 or later
     * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
     * Update URI:        https://example.com/my-plugin/
     * Text Domain:       my-basics-plugin
     * Domain Path:       /languages
     * Requires Plugins:  my-plugin, yet-another-plugin
     */

    follow this formate for your plugin header

    Refference