• Hi again.

    When I want to hook into the modules info hooks (any of them), the only way to do it is right after the file is included. After that there are two hooks for that:

    a filter: jetpack_short_module_description
    an action: ‘jetpack_learn_more_button_’ . $module

    Those are the only moments when I can hook the moduels information. The problem is that they are executed once for every module. I think that the plugin needs an extra hook after module-info.php is loaded. Here’s an example:

    include_once( JETPACK__PLUGIN_DIR . 'modules/module-info.php' );
    do_action( 'jetpack_modules_info_loaded' );

    That would solve the problem.

    Or even better (this file is loaded in another place too I think: Add the action at the end of modules-info.php.

    Cheers.

    https://wordpress.org/plugins/jetpack/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Brandon Kraft

    (@kraftbj)

    Code Wrangler

    Howdy,

    Could you tell me more about how you’re using these and would use a new one? I’m not quite seeing it so want to make sure I have a solid picture.

    Alternatively, feel free to open an enhancement request at http://github.com/Automattic/jetpack

    Cheers!

    Thread Starter Ignacio Cruz Moreno

    (@igmoweb)

    Sorry for the very late here.

    Just imagine that you want to change the description of one of the modules. Let’s say, for instance, that we are going to change Carousel description module.

    Currently, this is the description of Carousel included in module-info.php:

    function jetpack_carousel_more_info() {
    ?>
    	<div class="jp-info-img">
    		<img class="jp-info-img" src="<?php echo plugins_url( basename( dirname( dirname( __FILE__ ) ) ) . '/_inc/images/screenshots/carousel.png' ) ?>" alt="<?php esc_attr_e( 'Gallery Carousel Screenshot', 'jetpack' ) ?>" width="300" height="188" />
    	</div>
    
        <p><?php esc_html_e( 'With Carousel active, any standard WordPress galleries you have embedded in posts or pages will launch a gorgeous full-screen photo browsing experience with comments and EXIF metadata.', 'jetpack' ); ?></p>
    <?php
    }
    
    add_action( 'jetpack_learn_more_button_carousel', 'jetpack_carousel_learn_more_button' );
    add_action( 'jetpack_module_more_info_carousel', 'jetpack_carousel_more_info' );

    So , the idea is to remove those actions and put my own ones, I use a mu-plugin for that:

    remove_action( 'jetpack_learn_more_button_carousel', 'jetpack_carousel_learn_more_button' );
    remove_action( 'jetpack_module_more_info_carousel', 'jetpack_carousel_more_info' );

    But that did, ehm, nothing. The information is still there. But that’s logicall, when I remove those filters, modules-info.php is still not loaded.

    Let’s search then for a hook that is fired right after the file is included so I can remove those hooks. The file is included in class.jetpack-admin.php among other two files. Let’s see the code:

    function get_modules() {
    		include_once( JETPACK__PLUGIN_DIR . 'modules/module-info.php' );
    		$available_modules = $this->jetpack->get_available_modules();
    		$active_modules    = $this->jetpack->get_active_modules();
    		$modules           = array();
    
    		foreach ( $available_modules as $module ) {
    ...
    // Save the modules info in an array
    ...
    }

    Well, there’s not a hook there so the hooks included in modules-info.php are a little useless.

    There are several options to fix this and one of them would be to add a new action at the end of the module-info.php file:

    do_action( 'jetpack_module_info_loaded' );

    Or similar, of course. That hook will allow me to remove the actions that module-info.php added:

    add_action( 'jetpack_module_info_loaded', 'jetpack_hooks_remove_current_module_info_actions' );
    function jetpack_hooks_remove_current_module_info_actions() {
       remove_action( 'jetpack_learn_more_button_carousel', 'jetpack_carousel_learn_more_button' );
       remove_action( 'jetpack_module_more_info_carousel', 'jetpack_carousel_more_info' );
    }

    I don’t know if is clear enough πŸ™‚

    Thanks.

    Plugin Author Brandon Kraft

    (@kraftbj)

    Code Wrangler

    I’m on the same page now and don’t see a clear way of doing what you want with how it is now either.

    What about adding a filter instead? For example, you can change the short description (listed before clicking Learn More) via

    function change_info(){
    return 'Proof of concept only!';
    }
    add_filter('jetpack_short_module_description' , 'change_info');

    (changes all of them to “Proof of concept”, but could be used to filter specific modules).

    Would adding something like that for the modules work instead of a hook?

    Thread Starter Ignacio Cruz Moreno

    (@igmoweb)

    What would be the difference? We would need to remove the filter right after is added by Jetpack and before the information is displayed.

    Filter or action, both are the same.We need a hook after the file is loaded or change the way the texts are displayed.

    Let me know if my approach is wrong.

    Thanks.

    Plugin Author Brandon Kraft

    (@kraftbj)

    Code Wrangler

    The difference is you wouldn’t need to unhook anything, e.g. if you add the filter code above to a plugin right now, it’ll replace all of the short descriptions with “Proof of Concept”. No need to unhook the default content.

    Filters will output the default content, unless a function being added via add_filter says it should be different/modified. The action hook would require removing the existing one and adding a new one without the ability to modify the default content.

    Thread Starter Ignacio Cruz Moreno

    (@igmoweb)

    Oh, true, true, I don’t know what I was thinking about. A filter would be the best option.

    Thanks a lot, Brandon.

    Plugin Author Brandon Kraft

    (@kraftbj)

    Code Wrangler

    Cool. I opened a GitHub thread at https://github.com/Automattic/jetpack/issues/1008 for this. I’m not totally sure the best approach for adding the filters, so I want some more feedback from the team before proposing code for it.

    Cheers!

    I’d like to see this filter implemented too:

    Some of the modules stop other plugins from working, for example; photon doesn’t work with fancybox. I’d like to update the long description to let my clients know about conflicts in each of the modules.

    In class.jetpack-admin.php, I changed line 96 to:

    $module_array['long_description'] = apply_filters( 'jetpack_long_module_description', ob_get_clean(), $module );

    Is it possible to get this as a permanent change please?

    This would allow developers to add a filter such as:

    function custom_jetpack_more_info($module_description, $module_name) {
    	if($module_name == 'photon') $module_description .= "Photon doesn't play nice with Fancybox";
    	return $module_description;
    }
    add_filter( 'jetpack_long_module_description', 'custom_jetpack_more_info', 10, 2 );
    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic πŸš€

    Is it possible to get this as a permanent change please?

    Feel free to submit a pull request from that branch. We’ll review it and merge it if it looks good!

    Thanks!

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Hook after module-info.php is loaded’ is closed to new replies.