Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestions for documentation Custom Modules #33

Open
xberg opened this issue Mar 29, 2016 · 3 comments
Open

Suggestions for documentation Custom Modules #33

xberg opened this issue Mar 29, 2016 · 3 comments

Comments

@xberg
Copy link

xberg commented Mar 29, 2016

Hi,
I followed your documentation carefully and was successful in creating custom modules but here 2 suggestions:

  • your folder structure has changed since you wrote the docs. The modules folder has changed location
  • you don't really explain the full steps on how to create a parent custom module: I tried and failed. So I went with a child of post.
  • it was not obvious for me that you had to refresh the cache after creating a custom module.
@kminh
Copy link
Collaborator

kminh commented Mar 30, 2016

Thank you @xberg . We will discuss more about this when I start working on enhancements for the module API.

@orditeck
Copy link

orditeck commented Apr 9, 2018

@kminh @OddOneOut,

in the docs, it says:

You might ask: “If I add more modules, what will happen when this plugin gets updated?” No worry, you have the option to set a custom module directory that will take precedence over the default module directory. Simply speaking, this plugin will look for modules in the custom directory first, and when it can not find the requested module file, it will look for modules in the default one, in the exact same way described above.

Where do I have the option to set a custom module directory that will take precedence over the default module directory?

Thanks.

@orditeck
Copy link

orditeck commented Apr 9, 2018

Looking in the plugin's code, I ended up adding this in my functions.php:

// Specify where Better WordPress Google XML Sitemaps has to go to find custom modules
add_filter('bwp_gxs_module_dir', function(){
    return get_stylesheet_directory() . '/framework/bwp_gxs';
});

// Add our custom WordPress Google XML Sitemaps modules
add_action('bwp_gxs_modules_built', function(){
    global $bwp_gxs;
    $bwp_gxs->add_module('post', 'programs');
});

In framework/bwp_gxs, I created a file named post_programs.php.

Here's my post_programs.php file:

<?php

class BWP_GXS_MODULE_post_programs extends BWP_GXS_MODULE
{
    protected function generate_data()
    {
        $api = new \Path\To\My\API;
        $programs = $api->get('programs');

        if($programs && $programs->data) {
            foreach($programs->data as $program) {
                $this->data[] = [
                    'location'  => $program->slug,
                    'lastmod'   => date('Y-m-01'),
                    'freq'      => 'monthly'
                ];
            }
            return true;
        } else {
            return false;
        }
    }
}

Hope it can help someone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants