Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter bmeisler

    (@bmeisler)

    Thank you!!!!!

    set_transient did the trick…

    Thread Starter bmeisler

    (@bmeisler)

    OK, thanks for your help! Some useful information already – but still nothing is stopping the problem – either the data loads all the time…or not. I’m sending you a simplified version of what I’m trying to do – I’ve cut out all of my attempts of using current_screen, show_on, show_on_cb, etc. – just so you can see what I’m doing.

    Briefly, when the metaboxes are initialized, we call the function gd_module_test_get_templates which polls a list of module templates and uses that list to populate a combox box.

    I’ve come close with this – I can call that function only under certain conditions (eg, url params), but when I do, the list of modules gets echoed out (print_r($templates);, near the very end of the code) but the combo box is empty…

    Again the real problem is that this occurs on EVERY page,post, plugin, etc. and brings my whole admin page to a crawl.

    Here’s the code:

    <?php

    namespace GDModulesTest;
    
    class ModulesTest{
    
    	/**
    	 * Holds an instance of the object
    	 *
    	 * @var ModulesTest
    	 **/
    	private static $instance = null;
    
    	/**
    	 * Constructor
    	 */
    	private function __construct() {
    		// Set our title
    		$this->title = __( 'GD Modules Test', 'gd' );
    	}
    
    	/**
    	 * Returns the running object - implements the Singleton design pattern
    	 *
    	 * @return ModulesTest
    	 **/
    	public static function get_instance() {
    		if( is_null( self::$instance ) && is_admin()){
    			self::$instance = new self();
    			self::$instance->gd_mt_init();
    		}
    		return self::$instance;
    	}
    
    	public function gd_mt_init() {
    		$this->bootstrap_CMB2();
    		add_filter( 'cmb2_admin_init', array($this,'gd_module_test_metabox' ));
    	}
    
    	/**
    	 * Get the bootstrap!
    	 */
    	public function bootstrap_CMB2(){
    		if ( file_exists( __DIR__ . '/cmb2/init.php' ) ) {
    			require_once __DIR__ . '/cmb2/init.php';
    		} elseif ( file_exists( __DIR__ . '/CMB2/init.php' ) ) {
    			require_once __DIR__ . '/CMB2/init.php';
    		}
    	}
    
    	function gd_module_test_metabox() {
    
    		$prefix = 'gd_';
    
    		$module_templates = new_cmb2_box( array(
    			'id'           => 'module_metabox_templates',
    			'title'        => __( 'Module Templates', 'gd' ),
    			'object_types' => array( 'modules' ), // Post type
    			'context'      => 'normal',
    			'priority'     => 'low',
    			'show_names'   => true, // Show field names on the left
    		) );
    
    		$module_templates->add_field( array(
    			'name'    => __('Module Template', 'gd'),
    			'id'      => $prefix . 'module_template',
    			'type'    => 'select',
    			'options' => $this->gd_module_test_get_templates(),
    			'default' => 'custom',
    		) );
    	}
    
    	function gd_module_test_get_templates() {
    
    		$templates = array();
    
    		if ( is_dir( '../../app/themes/gd-employers-blog-sage/templates/modules/' ) ) {
    
    			$dir = opendir( '../../app/themes/gd-employers-blog-sage/templates/modules/' );
    
    			while ( false !== ( $template = readdir( $dir ) ) ) {
    				if ( ! is_dir( $template ) ) {
    
    					$template_name = explode( 'Template Name:', file_get_contents( '../../app/themes/gd-employers-blog-sage/templates/modules/' . $template ) );
    					if ( ! empty( $template_name[1] ) ) {
    						$template_name          = $template_name[1];
    						$template_name          = explode( '*/', $template_name );
    						$template_name          = $template_name[0];
    						$template_name          = trim( $template_name );
    						$templates[ $template ] = __( $template_name, 'cmb' );
    					}
    				}
    			}
    			closedir( $dir );
    
    			print_r($templates);//NOTE: this prints out on EVERY PAGE/POST/PLUGIN!
    			//this function should ONLY be called if we are actuall editing a module!
    
    			return $templates;
    		}
    	}
    }
    Thread Starter bmeisler

    (@bmeisler)

    Good question – yup, can add new posts just fine.

    I wish there was a good tutorial in the Codex for this. Lots of info on how to move a site, under many different circumstances – which is something I have yet to do, and hope to never to – but the documentation is very sparse (or non-existent?) on synching sites, which is something I’d like to do on a regular basis, and I think lots of other folks would to.

    I’ve got a local version of my site, and a staging version, and though I’ve managed to keep the content and .php files up to date, the database – not just the posts, but the menus, permalinks, plug-in settings, etc – have gotten totally out of synch with the live version. Would be great to just be able to synch up the databases as needed…

    Thread Starter bmeisler

    (@bmeisler)

    Glad to see I’m not the only one! I actually think that this would be a common problem, as the default post login screen (Profile) is some seriously bad UX…

    I can’t expect Radiok to fix this, as it would probably be pretty complicated.

    The easy fix, IMHO, would be to override the filter I placed in functions.php, so that I’d allow my “custom” redirect (going back to page of origin) in the case that the function was called from single.php (i.e., subscriber-only content pages). But this is a bit beyond my WordPress/PHP chops at this point.

    Can anybody help? Maybe I should post this as a generic help request for filters…if I ever figure it out, I’ll definitely post it…

    Thread Starter bmeisler

    (@bmeisler)

    Awesome sauce! Haven’t tested the whole system from top to bottom, but that works!

    (And if there’s any confusion, he meant to add those lines to “register-plus-redux.php” in your plug-ins folder…)

    Radiok, one more question? What would make this plug-in PERFECT (IMHO) is if:

    1. when the user clicked the login link from the email, their username and password would pre-populate the login field and

    2. More importantly, instead of going to the profile page after login, we went directly to the page the user was originally trying to get to.

    That is, I’m blocking certain pages on my site from non-registered users. They see the first few paragraphs and then a message to either register or sign in. Sign in takes them right to the page. Register sends them to a Welcome page that tells them to look in their email for a welcome message.

    Would be great to have them go straight to the page they were originally trying to read, rather than the profile, which I think might be confusing to my readers…

    Thanks!

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