Ejemplo n.º 1
0
    // bring in form
    $core_modules = [];
    foreach (Modules\Base::get_core_module_names() as $module) {
        $core_modules[$module] = "on";
    }
    return array_merge($new_val, $core_modules);
}, 10, 2);
// fire activation and deactivation hooks for modules
add_action('update_option_podlove_active_modules', function ($old_val, $new_val) {
    $deactivated_modules = array_keys(array_diff_assoc($old_val, $new_val));
    $activated_modules = array_keys(array_diff_assoc($new_val, $old_val));
    if ($deactivated_modules) {
        foreach ($deactivated_modules as $deactivated_module) {
            Log::get()->addInfo('Deactivate module "' . $deactivated_module . '"');
            do_action('podlove_module_was_deactivated', $deactivated_module);
            do_action('podlove_module_was_deactivated_' . $deactivated_module);
        }
    }
    if ($activated_modules) {
        foreach ($activated_modules as $activated_module) {
            Log::get()->addInfo('Activate module "' . $activated_module . '"');
            // init module before firing hooks
            $class = Modules\Base::get_class_by_module_name($activated_module);
            if (class_exists($class)) {
                $class::instance()->load();
            }
            do_action('podlove_module_was_activated', $activated_module);
            do_action('podlove_module_was_activated_' . $activated_module);
        }
    }
}, 10, 2);
Ejemplo n.º 2
0
    public function __construct($handle)
    {
        Settings::$pagehook = add_submenu_page($handle, 'Settings', 'Settings', 'administrator', 'podlove_settings_settings_handle', array($this, 'page'));
        add_settings_section('podlove_settings_general', __('General Settings', 'podlove'), function () {
            /* section head html */
        }, Settings::$pagehook);
        add_settings_field('podlove_setting_merge_episodes', sprintf('<label for="merge_episodes">%s</label>', __('Display episodes on front page together with blog posts', 'podlove')), function () {
            ?>
				<input name="podlove[merge_episodes]" id="merge_episodes" type="checkbox" <?php 
            checked(\Podlove\get_setting('merge_episodes'), 'on');
            ?>
>
				<?php 
        }, Settings::$pagehook, 'podlove_settings_general');
        add_settings_field('podlove_setting_hide_wp_feed_discovery', sprintf('<label for="hide_wp_feed_discovery">%s</label>', __('Hide default WordPress Feeds for blog and comments (no auto-discovery).', 'podlove')), function () {
            ?>
				<input name="podlove[hide_wp_feed_discovery]" id="hide_wp_feed_discovery" type="checkbox" <?php 
            checked(\Podlove\get_setting('hide_wp_feed_discovery'), 'on');
            ?>
>
				<?php 
        }, Settings::$pagehook, 'podlove_settings_general');
        add_settings_field('podlove_setting_custom_episode_slug', sprintf('<label for="custom_episode_slug">%s</label>', __('URL segment prefix for podcast episode posts. Leave empty to remove the prefix.', 'podlove')), function () {
            ?>
				<input name="podlove[custom_episode_slug]" id="custom_episode_slug" type="text" value="<?php 
            echo \Podlove\get_setting('custom_episode_slug');
            ?>
">
				<p>
					<span class="description"><?php 
            echo __('Must be a suitable URL part: lowercase characters, numbers and hyphens.', 'podlove');
            ?>
</span>
				</p>
				<?php 
        }, Settings::$pagehook, 'podlove_settings_general');
        add_settings_section('podlove_settings_modules', __('Modules', 'podlove'), function () {
            /* section head html */
        }, Settings::$pagehook);
        $modules = \Podlove\Modules\Base::get_all_module_names();
        foreach ($modules as $module_name) {
            $class = \Podlove\Modules\Base::get_class_by_module_name($module_name);
            if (!class_exists($class)) {
                continue;
            }
            $module = $class::instance();
            $module_options = $module->get_registered_options();
            if ($module_options) {
                register_setting(Settings::$pagehook, $module->get_module_options_name());
            }
            add_settings_field('podlove_setting_module_' . $module_name, sprintf('<label for="' . $module_name . '">%s</label>', $module->get_module_name()), function () use($module, $module_name, $module_options) {
                ?>
					<label for="<?php 
                echo $module_name;
                ?>
">
						<input name="podlove_active_modules[<?php 
                echo $module_name;
                ?>
]" id="<?php 
                echo $module_name;
                ?>
" type="checkbox" <?php 
                checked(\Podlove\Modules\Base::is_active($module_name), true);
                ?>
>
						<?php 
                echo $module->get_module_description();
                ?>
					</label>
					<?php 
                if ($module_options) {
                    ?>
<h4><?php 
                    echo __('Settings');
                    ?>
</h4><?php 
                    // prepare settings object because form framework expects an object
                    $settings_object = new \stdClass();
                    foreach ($module_options as $key => $value) {
                        $settings_object->{$key} = $module->get_module_option($key);
                    }
                    \Podlove\Form\build_for($settings_object, array('context' => $module->get_module_options_name(), 'submit_button' => false), function ($form) use($module_options) {
                        $wrapper = new \Podlove\Form\Input\TableWrapper($form);
                        foreach ($module_options as $module_option_name => $args) {
                            call_user_func_array(array($wrapper, $args['input_type']), array($module_option_name, $args['args']));
                        }
                    });
                }
            }, Settings::$pagehook, 'podlove_settings_modules');
        }
        register_setting(Settings::$pagehook, 'podlove');
        register_setting(Settings::$pagehook, 'podlove_active_modules');
    }
Ejemplo n.º 3
0
    public function __construct($handle)
    {
        Modules::$pagehook = add_submenu_page($handle, 'Modules', 'Modules', 'administrator', 'podlove_settings_modules_handle', array($this, 'page'));
        $this->init_page_documentation(self::$pagehook);
        add_settings_section('podlove_settings_modules', __('', 'podlove'), function () {
            /* section head html */
        }, Modules::$pagehook);
        $grouped_modules = array();
        $modules = \Podlove\Modules\Base::get_all_module_names();
        foreach ($modules as $module_name) {
            $class = \Podlove\Modules\Base::get_class_by_module_name($module_name);
            if (!class_exists($class)) {
                continue;
            }
            if ($class::is_core()) {
                continue;
            }
            $module = $class::instance();
            $module_options = $module->get_registered_options();
            if ($group = $module->get_module_group()) {
                add_settings_section('podlove_setting_module_group_' . $group, ucwords($group), function () {
                }, Modules::$pagehook);
            }
            if ($module_options) {
                register_setting(Modules::$pagehook, $module->get_module_options_name());
            }
            add_settings_field('podlove_setting_module_' . $module_name, sprintf('<label for="' . $module_name . '">%s</label>', $module->get_module_name()), function () use($module, $module_name, $module_options) {
                ?>
					<label for="<?php 
                echo $module_name;
                ?>
">
						<input name="podlove_active_modules[<?php 
                echo $module_name;
                ?>
]" id="<?php 
                echo $module_name;
                ?>
" type="checkbox" <?php 
                checked(\Podlove\Modules\Base::is_active($module_name), true);
                ?>
>
						<?php 
                echo $module->get_module_description();
                ?>
					</label>
					<?php 
                do_action('podlove_module_before_settings_' . $module_name);
                if ($module_options) {
                    ?>
<h4><?php 
                    echo __('Settings');
                    ?>
</h4><?php 
                    // prepare settings object because form framework expects an object
                    $settings_object = new \stdClass();
                    foreach ($module_options as $key => $value) {
                        $settings_object->{$key} = $module->get_module_option($key);
                    }
                    \Podlove\Form\build_for($settings_object, array('context' => $module->get_module_options_name(), 'submit_button' => false, 'form' => false), function ($form) use($module_options) {
                        $wrapper = new \Podlove\Form\Input\TableWrapper($form);
                        foreach ($module_options as $module_option_name => $args) {
                            call_user_func_array(array($wrapper, $args['input_type']), array($module_option_name, $args['args']));
                        }
                    });
                }
                do_action('podlove_module_after_settings_' . $module_name);
            }, Modules::$pagehook, $group ? 'podlove_setting_module_group_' . $group : 'podlove_settings_modules');
        }
        register_setting(Modules::$pagehook, 'podlove_active_modules');
    }