Making own plugin - wont show up in extensions

Hi All,

I’m learning as I go, but I’m trying to get an extension built to export all the data in a csv.

/*
Plugin Name: Export to CSV for MainWP
Description: Export to CSV Extension is an extension for MainWP. It allows you to export all your client data as a CSV. Requires the MainWP Dashboard 
Version: 0.0.1
Author: x
Author URI: x/
Documentation URI: x
MainWP Extension: true
*/

include_once 'css/mainwp-export-csv.css';
include_once 'js/mainwp-export-csv.js';

$childKey = false;

add_filter('mainwp_getextensions', 'get_this_extension');
$mainWPActivated = apply_filters('mainwp_activated_check', false);

if ($mainWPActivated !== false) {
activate_this_plugin();
} else {
add_action('mainwp_activated', 'activate_this_plugin');
}

function get_this_extension($extensions) {
$extensions[] = array(
	'plugin' => __FILE__,
	'callback' => 'export_csv_extension_settings',
	'name' => 'Export to CSV',
	'icon' => '../wp-content/plugins/mainwp-export-csv/images/trident.png'
	);
return $extensions;
}

function export_csv_extension_settings() {
do_action('export-csv-pageheader-extensions', __FILE__);
echo '<h1>Export to CSV</h1>';
do_action('export-csv-pagefooter-extensions', __FILE__);
}

function activate_this_plugin() {
global $childEnabled;
$childEnabled = apply_filters('mainwp_extension_enabled_check', __FILE__);
if (!$childEnabled) return;

$childKey = $childEnabled['key'];

//Code to initialize the plugin
}

When I clicked on disable, it disappears from the list of extensions - until I go back in to the WP admin plugins page and enable it again.

Is there a way to get it to stay on the extensions page but just as disabled?
How do I add information for the privacy so that it shows with a tick or yellow etc?

Hi @trident,

Thanks for reaching out. It is great to see interest in building a custom extension.

We reviewed your code and found that the mainwp_register_extension and the mainwp_extensions hooks do not exist in the MainWP code.

Please try the way all our extensions are developed; here is the basic code that is needed to hook in a simple one-page extension:

Here you can download the zip file to review it:

Explanation

In the __construct() system will check if the MainWP Dashboard plugin is activated or not, and it will hook in the extension via the mainwp_getextensions filter.

In the get_this_extension method, you can define the required parameters.
Since your extension won’t use the MainWP licensing system, the mainwp and the apiManager parameters are set to false. The callable parameter sets the “call” to the Method where you will place your “Settings” code.

So, the next method is settings(). Here, you can set your extension content and features.

For the end, you just need to pack your extension file along with the readme.txt in one directory (directory name and file name should be the same), zip it and install it to your dashboard.

For example:
/mainwp-csvexport-extension/
|__ mainwp-csvexport-extension.php
|__ readme.txt

Let us know if any additional help is needed. We will be happy to help.

3 Likes

@trident First of all, Welcome to the community!

As @bogdan has suggested - I would start with our “Single Page” version of our “Hello World” extension to get your code displaying correctly.

If this proves difficult & you run into additional problems, please feel free to @tag me directly as I am the MainWP Development communications specialist & can point you in the right direction.

2 Likes

Hi @kwcjr and @bogdan

Thank you so so much!!

I’ve rewritten the code using your supplied info!

/**
 * Plugin Name: MainWP Export to CSV
 * Plugin URI: https://mainwp.com
 * Description: The MainWP Export to CSV extension allows you to export the report data as CSV. This can then be used elsewhere. 
 * Version: 0.0.1
 * Author: Trident Marketing Anglia Ltd
 * Author URI: https://tridentmarketinguk.com/
 * Documentation URI: https://kb.tridentmarketinguk.com/docs/wp-export-csv/
 * MainWP Extension: true
 */

class MainWP_Export_CSV_Extension_Activator {

    protected $mainwpMainActivated = false;
    protected $childEnabled        = false;
    protected $childKey            = false;
    protected $childFile;
    protected $plugin_handle    = 'mainwp-export-csv';
    protected $product_id       = 'MainWP Export to CSV';
    protected $software_version = '0.0.1';

    public function __construct() {
        $this->childFile = __FILE__;

        add_filter('mainwp_getextensions', array(&$this, 'get_this_extension'));
        $this->mainwpMainActivated = apply_filters('mainwp_activated_check', false);

        if ($this->mainwpMainActivated !== false) {
            $this->activate_this_plugin();
        } else {
            add_action('mainwp_activated', array(&$this, 'activate_this_plugin'));
        }
        add_action('admin_notices', array(&$this, 'mainwp_error_notice'));
    }

    /**
     * Add your extension to MainWP via the 'mainwp_getextensions' filter.
     *
     * @param array $params Array containing the extensions info.
     *
     * @return array $params Updated array containing the extensions info.
     */
    public function get_this_extension($params) {
        $params[] = array(
            'plugin'     => __FILE__,
            'api'        => $this->plugin_handle,
            'mainwp'     => true,
            'callback'   => array(&$this, 'extension_page_content'),
            'apiManager' => false,
        );
        return $params;
    }

    /**
     * Displays the extension page with an adequate header and footer.
     */
    public function extension_page_content() {
        do_action('mainwp_pageheader_extensions', __FILE__);
        echo '<h1>Welcome to MainWP Export to CSV</h1>';
        do_action('mainwp_pagefooter_extensions', __FILE__);
    }

    /**
     * Activate the extension API license and initiate the extension.
     */
    public function activate_this_plugin() {
        $this->mainwpMainActivated = apply_filters('mainwp_activated_check', $this->mainwpMainActivated);
        $this->childEnabled        = apply_filters('mainwp_extension_enabled_check', __FILE__);
        $this->childKey            = $this->childEnabled['key'];
    }

    /**
     * Get the extension key.
     *
     * @return string
     */
    public function get_child_key() {
        return $this->childKey;
    }

    /**
     * Get the extension file.
     *
     * @return string
     */
    public function get_child_file() {
        return $this->childFile;
    }

    /**
     * Render the warning notice if the MainWP Dashboard plugin is not activated.
     */
    public function mainwp_error_notice() {
        global $current_screen;
        if ($current_screen->parent_base == 'plugins' && $this->mainwpMainActivated == false) {
            echo '<div class="error"><p>MainWP Export to CSV' . __('requires <a href="https://mainwp.com/" target="_blank">MainWP Dashboard Plugin</a> to be activated in order to work. Please install and activate <a href="https://mainwp.com/" target="_blank">MainWP Dashboard Plugin</a> first.', 'mainwp') . '</p></div>';
        }
    }
}

global $mainWPExportCSVExtensionActivator;
$mainWPExportCSVExtensionActivator = new MainWP_Export_CSV_Extension_Activator();

I’ve just checked it, if I disable the plugin, it disappears until i go back in to the main wordpress plugins file to enable it. Is there a way to get it to stay on the extensions page, but showing as disabled?

I’m also looking at the Rest API set up - I can’t seem to find any guidance on which url I would need to query to see the list of plugin updates that have been done… I know it can be done, but I’m just missing what to query?

Can you point me in the right direction for that too please?

@trident I have tested the “Hello-World” code we provided & that is the normal behavior of “Custom Extensions” that have not been release by us @ MainWP.

In a future update we will look into providing a method that stores Custom Extensions “data” so that they will stay on that page after “deactivation”.

With that said - you may continue with your extension as this doesn’t stop it from functioning whilst “activated”.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.