• Would be great if you could add a filter for default settings.
    We’re using your plugin in our themes and would like to choose ‘manual’ for location type right after the plugin’s installation / activation.
    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author dFactory

    (@dfactory)

    Hi,
    It’s not that easy as the options assignment happens in plugin class constructor.
    What you can do however is to detect the PVC activation using this: https://codex.ww.wp.xz.cn/Plugin_API/Action_Reference/activated_plugin
    And update the PVC post_views_counter_settings_display option.

    Regards,
    Bartosz / dfactory team

    Thread Starter ninetienne

    (@ninetienne)

    Seems like a solution.

    Could you please provide some more details, how to update the post_views_counter_settings_display option? It’s a serialized array, and I’m afraid to mess it up.

    Thanks a lot!

    Plugin Author dFactory

    (@dfactory)

    It would be something like this, but you have to test it:

    /**
     * Hook into activated_plugin action.
     * 
     * @param string $plugin
     */
    function custom_pvc_activation_action( $plugin ) {
    	// check if PVC constant is defined,use it to get PVC path anc compare to activated plugin
        if( defined( 'POST_VIEWS_COUNTER_PATH' ) && $plugin == plugin_basename( POST_VIEWS_COUNTER_PATH . 'post-views-counter.php' ) ) {
    		// get display options
    		$display_options = get_option( 'post_views_counter_settings_display' );
    		// set position value
    		$display_options['position'] = 'manual';
    		// update options
    		update_option( 'post_views_counter_settings_display', $display_options );
        }
    }
    add_action( 'activated_plugin', 'custom_pvc_activation_action' );
    Thread Starter ninetienne

    (@ninetienne)

    Thank you so much!

    Thread Starter ninetienne

    (@ninetienne)

    I’ve just tested it, and it’s working fine. Thanks a lot!

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

The topic ‘Filter for default settings’ is closed to new replies.