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

Expected filters/actions? #239

Open
strarsis opened this issue Jun 11, 2018 · 10 comments
Open

Expected filters/actions? #239

strarsis opened this issue Jun 11, 2018 · 10 comments
Labels

Comments

@strarsis
Copy link
Contributor

Does the Mesh plugin expect specific filters/actions for rendering the markup?
In a sage9 based one pager theme, for each page the blade render method is called,
but Mesh plugin is not adding the markup.
Must some specific filters/actions be called explicitly?

@strarsis strarsis changed the title Expected filters/hooks? Expected filters/actions? Jun 11, 2018
@aaronware
Copy link
Collaborator

By default Mesh will hook into "loop_end" (which is a default hook within pages). However this may not work if your home page is ONLY displaying the "blog" within your Website General Settings vs defining a "Front page"

Below is an example of what happens within the hook for loop_end

if ( ! $wp_query->is_main_query() ) {
			return;
		}

		if ( ! is_singular() ) {
			return;
		}

		// Do not show content on password protected posts.
		if ( post_password_required() ) {
			return;
		}

		$sections = mesh_display_sections( $wp_query->post->ID, false );

		echo apply_filters( 'mesh_loop_end', $sections, $wp_query->post->ID ); // WPCS: XSS ok, sanitization ok.

We also apply out own mesh_loop_end hook that you can use to filter further. If your theme doesn't utilize the "The Loop" You could also use mesh_display_sections( $yourPostId, true );

@strarsis
Copy link
Contributor Author

strarsis commented Jun 12, 2018

@aaronware:

do_action('loop_end');
Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function is_main_query() on string in /srv/www/web/app/plugins/mesh/class.mesh.php on line 911

Passing $post results in same error.

@aaronware
Copy link
Collaborator

Did you make a change to Mesh and received that error?

@aaronware
Copy link
Collaborator

like you wouldn't call do_action('loop_end'); directly. That do)action('loop_end') is called by WordPress core when any loop finishes. The check in mesh is to make sure it only tried to add mesh sections after loop_end of the main query.

@strarsis
Copy link
Contributor Author

strarsis commented Jun 12, 2018

No changes had been made to Mesh plugin, I removed its plugin folder and reinstalled it to be sure.

Can I trigger the loop_end action manually (each time a new page is rendered) so
Mesh knows that it should add the sections?

@aaronware
Copy link
Collaborator

I haven't ever built anything using Sage9 before. Are you using the laravel blade templates or the defaults? I'm not sure why it wouldn't find the_loop or have access to general hooks from WordPress.

@strarsis
Copy link
Contributor Author

strarsis commented Jun 12, 2018

@aaronware: It works with a single page with sage9 (laravel blade is used internally, yes).
But when I want to loop over many pages (one pager with multiple pages on front page),
I have to notify Mesh plugin that it now has to render the sections for each page.

This code is used for adding one pager support to a sage9 theme:
/~https://github.com/strarsis/sage9-onepager-lib/blob/master/Controls.php#L127

I can use mesh_display_sections( $post->ID, false ); for rendering the mesh sections,
but this will also change the global $post variable to current page, interfering with the original $post.

@aaronware
Copy link
Collaborator

Ahh ok. Can you send me an example of the code you are using? Or is that something you can just do from the admin of the theme once you generate it?

@strarsis
Copy link
Contributor Author

strarsis commented Jun 12, 2018

@aaronware: Sure! /~https://github.com/strarsis/sage9-onepager-lib/blob/mesh-templ/Controls.php#L127
The end variable is used for inserting the mesh sections correctly into a page section,
otherwise they would be inserted below the page container element.
The issue with the code is that calling mesh_display_sections also seem to change $post from
the page to be looped to front page each time.
Because of this the content of front page is shown and then the Mesh sections.

@strarsis
Copy link
Contributor Author

@aaronware: As a workaround it is possible to reset the $post to previous state by retrieving it again:

			$post = get_post( get_theme_mod( 'panel_' . $id ) );
			setup_postdata( $post );
			set_query_var( 'panel', $id );


			$template_data = array(
				'end' => mesh_display_sections( $post->ID, false )
			);

			// reset $post
			$post = get_post( get_theme_mod( 'panel_' . $id ) );
			setup_postdata( $post );
			set_query_var( 'panel', $id );

			echo \App\template(  'single-panels', $template_data  );


			wp_reset_postdata();

However, this is a workaround, ideally the $post is not changed or a different way is found for notifying Mesh plugin – and possibly other plugins that use these hooks for rendering.

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

No branches or pull requests

2 participants