• Resolved Bani S

    (@dhanykoe)


    Hello
    Thanks for an awesome plugin.

    i try to create a plugin using your sample plugin. My plan is all my wp_customize setting will not display before license key validate.

    i had try use this code to check license key validate

    /*** Verify license key is active and expire date has not passed ***/
    	$api_params = array(
    		'slm_action' => 'slm_check',
    
    		'secret_key' => MYPLUGIN_CUSTOMIZER_PLUGIN_SECRET_KEY,
    
    		'license_key' => get_option('my_license_key'), //replace with your license key field name.
    
    	);
    	// Send query to the license manager server
    	$response = wp_remote_get(add_query_arg($api_params, MYPLUGIN_CUSTOMIZER_PLUGIN_SERVER_URL), array('timeout' => 20, 'sslverify' => false));
    
    	$license_data = json_decode(wp_remote_retrieve_body($response));
    	global $active, $message;
    	if($license_data->result == 'success' && $license_data->status == 'active'){ ?>
    		<script>alert('Activated');</script>
    	<?php }else{ ?>
                  <script>alert('Deactivated');</script>
    	<?php } 
    	?>

    Result is working and i get an alert Activated, but when i change the script alert to do action, code below :

    if($license_data->result == 'success' && $license_data->status == 'active'){ 
    	add_action( 'plugins_loaded', array( $this, 'custom_customizer_running' ) ); } 

    nothing happen when check appereance->customize, my custom customize is still not appear.

    Thanks for help

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Bani S

    (@dhanykoe)

    already solved,

    working like a charm…

    thanks

    Plugin Support mbrsolution

    (@mbrsolution)

    Hi, what was the solution to your problem? I am curious to know.

    Thank you

    Thread Starter Bani S

    (@dhanykoe)

    hi @mbrsolution,

    it’s was wrong to put action hook on result of verify key license.

    i should put on my __construct function to call the function.

    function __construct() {
            //register an activation hook for the plugin
            register_activation_hook( __FILE__, array( $this, 'custom_customize_license_menu' ) );
    		add_action('admin_menu', array( $this, 'custom_customize_license_menu' ) );
    		add_action( 'plugins_loaded', array( $this, 'custom_customizer_running' ) );
        }
    
    function custom_customizer_running(){
    		add_action( 'customize_register', array( $this, 'action_register_customizer' ), 30, 1 );
    	}

    Now, the license key verify i put on action_register_customizer function

    function action_register_customizer($wp_customize) {
    /*** Verify license key is active and expire date has not passed ***/
    	$api_params = array(
    		'slm_action' => 'slm_check',
    
    		'secret_key' => MYPLUGIN_CUSTOMIZER_PLUGIN_SECRET_KEY,
    
    		'license_key' => get_option('license_key'), //replace with your license key field name.
    
    	);
    	// Send query to the license manager server
    	$response = wp_remote_get(add_query_arg($api_params, MYPLUGIN_CUSTOMIZER_PLUGIN_SERVER_URL), array('timeout' => 20, 'sslverify' => false));
    
    	$license_data = json_decode(wp_remote_retrieve_body($response));
    	global $active, $message;	
    	if($license_data->result == 'success' && $license_data->status == 'active' ){ 
    ALL MY CUSTOMIZE SETTING PUT HERE
    }
    }

    for me this solve my problem, i don’t know if this is the best way because i’m a beginner, but hope this can help others with same issue with me

    Plugin Support mbrsolution

    (@mbrsolution)

    Thank you for sharing. I am sure some will find your solution helpful.

    Enjoy the plugin.

    Kind regards

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Running add_action after validating license plugin’ is closed to new replies.