Add Wordpress Hook for current action if needed

@return boolean
548570
private function runHookCurrentAction()
    {
        //Check if needed add the hook
        if (!$this->getMbRequest()->isMocaBonitaPage() || $this->getMbRequest()->isBlogAdmin()) {
            return false;
        }

        //Check if a user is logged in Wordpress
        if ($this->mbRequest->isLogged()) {
            //Check if the current request is ajax
            if ($this->mbRequest->isAjax()) {
                //add hook admin_ajax
                $actionHook = "wp_ajax_{$this->getAction()}";
            } else {
                //add hook admin_post
                $actionHook = "admin_post_{$this->getAction()}";
            }

        } else {
            //Check if the current request is ajax
            if ($this->mbRequest->isAjax()) {
                //add hook nopriv_ajax
                $actionHook = "wp_ajax_nopriv_{$this->getAction()}";
            } else {
                //add hook nopriv_post
                $actionHook = "admin_post_nopriv_{$this->getAction()}";
            }
        }

        //Register WordpressHook
        MbWPActionHook::addAction($actionHook, $this, 'sendContent');

        return true;
    }
1247240
public function run()
    {
        if (!defined('ABSPATH')) {
            return;
        }

        // Required for 'add_filter' & 'add_action' function.
        require_once ABSPATH.(defined('WPINC') ? WPINC : 'wp-includes').'/plugin.php';

        // Load mu-plugins just before ordinary plugins.
        // wp-settings.php, Line 301: "foreach ( wp_get_active_and_valid_plugins() as $plugin ) {"
        add_filter('pre_option_active_plugins', ($callback = function ($plugins) use (&$callback) {
            remove_filter('pre_option_active_plugins', $callback);

            $this->loadPlugins();

            return $plugins;
        }));

        $this->addActivePluginsFilter();

        // Activate admin filters
        add_action('wp_loaded', function () {
            $this->addAdminFilter();
        });
    }
511839
public function hooks()
    {
        // Register metabox
        // on admin init.
        $this->hook->action(
            'admin_init',
            [$this->metabox, 'register']
        )->dispatch();

        // Save all metabox meta
        // data on post save.
        $this->hook->action('save_post', function ($id) {
            $this->metabox->getModel()->setContext('post');

            $this->metabox->save($id);
        })->dispatch();

        // Save metabox meta data
        // on the comment save.
        $this->hook->action('edit_comment', function ($id) {
            $this->metabox->getModel()->setContext('comment');

            $this->metabox->save($id);
        })->dispatch();
    }
157512
public function get_visual_hook() {

		printf(
			'<div class="filter-container"><p class="filter-name">%s</p>%s</div>',
			current_filter(),
			empty( $this->options['show_hooked_callable'] ) ? '' : $this->hooked->get_hooked_list( current_filter(), false )
		);
	}
1003489
public function activate()
    {
        $muPluginDir = WP_CONTENT_DIR . '/mu-plugins';

        if (!is_dir($muPluginDir)) {
            wp_mkdir_p($muPluginDir);
        }

        if (!is_dir($this->destination)) {
            wp_mkdir_p($this->destination);
        }

        $data = "<?php\n"
              . "/*\n"
              . "Plugin Name: StaticWP MU\n"
              . "Description: Converts your blog into a static site. This part of StaticWP"
                          . " allows StaticWP to bypass as much Wordpress as possible.\n"
              . "Author: Shane Logsdon\n"
              . 'Version: ' . STATICWP_VERSION . "\n"
              . "Author URI: http://www.slogsdon.com/\n"
              . "License: MIT\n"
              . "*/\n"
              . "\n"
              . "require_once '" . plugin_dir_path($this->file) . $this->plugin . ".php';\n";
        file_put_contents($muPluginDir . '/' . $this->plugin . '-mu.php', $data);

        // Can't use View::page :(
        $notice = 'Thanks for installing StaticWP! Might we suggest <a href="'
                . self::url('preload')
                . '">preloading your site</a>?';
        $this->addNotice($notice);
    }
1300912
public function whereUsedMetaBox()
    {
        if (empty(self::$enabled)) {
            return;
        }

        global $post;
        $module = $this;

        if (is_null($post)) {
            return;
        }

        $usage = self::getModuleUsage($post->ID);

        add_meta_box('modularity-usage', 'Module usage', function () use ($module, $usage) {
            if (count($usage) == 0) {
                echo '<p>' . __('This modules is not used yet.', 'modularity')  . '</p>';
                return;
            }

            echo '<p>' . __('This module is used on the following places:', 'modularity') . '</p><p><ul class="modularity-usage-list">';

            foreach ($usage as $page) {
                echo '<li><a href="' . get_permalink($page->post_id) . '">' . $page->post_title . '</a></li>';
            }

            echo '</ul></p>';
        }, self::$enabled, 'side', 'default');
    }
1172391
def method_added(method_name)
      # do nothing if the method that was added was an actual hook method, or
      # if it already had hooks added to it
      return if hooks.include?(method_name) || hooked_methods.include?(method_name)
      add_hooks_to(method_name)
    end
1143496
protected function insert_object() {
		// If the "prev_create" filter returns false we'll bail out of the create and return
		// false, indicating that the save failed. This provides a chance for any
		// hooks to cancel create operations if validations fail or whatever.
		if ( false === apply_filters( $this->prefix( 'prev_create' ), true ) ) {
			return false;
		}

		/**
		 * Fires creating action.
		 *
		 * @param static $wp_object Current object instance.
		 */
		do_action( $this->prefix( 'creating' ), $this );

		$insert_id = $this->perform_insert();

		if ( is_int( $insert_id ) && $insert_id > 0 ) {
			// Set new ID after insert success.
			$this->id = $insert_id;

			$this->exists = true;

			$this->recently_created = true;

			/**
			 * Fires after wp-object is created.
			 *
			 * @param static $wp_object Current object instance.
			 */
			do_action( $this->prefix( 'created' ), $this );

			return true;
		}

		return false;
	}
533412
protected function onSetupCoreHooks()
    {
        $is_theme  = $this->Config->§specs['§type'] === 'theme';
        $is_plugin = $this->Config->§specs['§type'] === 'plugin';

        add_action('wp_loaded', [$this->Utils->§RestAction, 'onWpLoaded']);
        add_action('wp_loaded', [$this->Utils->§TransientShortlink, 'onWpLoaded']);

        if ($this->Wp->is_admin) {
            add_action('admin_init', [$this->Utils->§AppStats, 'onAdminInit']);
            add_action('admin_init', [$this->Utils->§Updater, 'onAdminInit']);

            if ($this->is_core) {
                add_action('network_admin_menu', [$this->Utils->{'§CoreOnly\\MenuPages'}, 'onNetworkAdminMenu']);
                add_action('admin_menu', [$this->Utils->{'§CoreOnly\\MenuPages'}, 'onAdminMenu']);
                add_action('admin_enqueue_scripts', [$this->Utils->§StylesScripts, 'enqueueMenuPageLibs']);
            }
            add_filter('admin_body_class', [$this->Utils->§MenuPage, 'onAdminBodyClass']);
            add_action('all_admin_notices', [$this->Utils->§Notices, 'onAllAdminNotices']);

            if ($is_plugin) { // This is specifically for a plugin, and only for a plugin.
                add_filter('plugin_action_links_'.plugin_basename($this->Config->§specs['§file']), [$this->Utils->§MenuPage, 'onPluginActionLinks']);
            }
        }
        if ($is_theme || $is_plugin) { // This attaches in all contexts for compatibility w/ third-party update tools; e.g., ManageWP.
            add_filter(// This is so WordPress will know about available updates for our products; i.e., those not listed @ WordPress.org.
                'site_transient_update_'.$this->Config->§specs['§type'].'s', // i.e., a `get_site_transient()` filter.
                [$this->Utils->§Updater, 'onGetSiteTransientUpdate'.$this->Config->§specs['§type'].'s']
            );
        }
        if ($this->is_core) { // Deals with OPcache resets in core.
            add_action('upgrader_process_complete', [$this->Utils->§Updater, 'onUpgraderProcessComplete']);
        }
    }
141370
protected function registerHooks()
    {
        // Our callbacks are registered only on the admin side even for guest and frontend callbacks
        if (is_admin())
        {
            switch ($this->accessType)
            {
                case 'guest':
                    Hooks::action('wp_ajax_nopriv_' . static::$ACTION, $this, 'doAjax');
                    break;

                case 'logged':
                    Hooks::action('wp_ajax_' . static::$ACTION, $this, 'doAjax');
                    break;

                case 'any':
                    Hooks::action('wp_ajax_nopriv_' . static::$ACTION, $this, 'doAjax');
                    Hooks::action('wp_ajax_' . static::$ACTION, $this, 'doAjax');
                    break;

                default:
                    throw new \InvalidArgumentException("Invalid value for the Ajax access type parameter: "
                        . $this->accessType);
            }
        }

        // If we have global variables
        Hooks::filter('baobab/ajax/global_data', $this, 'addGlobalVariables');
    }
787618
protected function supportedHooks() {
    return array_map(function ($file) {
      return pathinfo($file, PATHINFO_FILENAME);
    }, array_diff(scandir($this->templatePath . '/d8/hook'), ['.', '..']));
  }
138363
private function setup_bootstrap_hooks() {

		if ( $this->config['skip-plugins'] ) {
			$this->setup_skip_plugins_filters();
		}

		if ( $this->config['skip-themes'] ) {
			WP_CLI::add_wp_hook( 'setup_theme', array( $this, 'action_setup_theme_wp_cli_skip_themes' ), 999 );
		}

		if ( $this->cmd_starts_with( array( 'help' ) ) ) {
			// Try to trap errors on help.
			$help_handler = array( $this, 'help_wp_die_handler' ); // Avoid any cross PHP version issues by not using $this in anon function.
			WP_CLI::add_wp_hook(
				'wp_die_handler',
				function () use ( $help_handler ) {
					return $help_handler;
				}
			);
		} else {
			WP_CLI::add_wp_hook(
				'wp_die_handler',
				function() {
					return '\WP_CLI\Utils\wp_die_handler';
				}
			);
		}

		// Prevent code from performing a redirect
		WP_CLI::add_wp_hook( 'wp_redirect', 'WP_CLI\\Utils\\wp_redirect_handler' );

		WP_CLI::add_wp_hook(
			'nocache_headers',
			function( $headers ) {
				// WordPress might be calling nocache_headers() because of a dead db
				global $wpdb;
				if ( ! empty( $wpdb->error ) ) {
					Utils\wp_die_handler( $wpdb->error );
				}
				// Otherwise, WP might be calling nocache_headers() because WP isn't installed
				Utils\wp_not_installed();
				return $headers;
			}
		);

		// ALTERNATE_WP_CRON might trigger a redirect, which we can't handle
		if ( defined( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON ) {
			WP_CLI::add_wp_hook(
				'muplugins_loaded',
				function() {
					remove_action( 'init', 'wp_cron' );
				}
			);
		}

		// Get rid of warnings when converting single site to multisite
		if ( defined( 'WP_INSTALLING' ) && $this->is_multisite() ) {
			$values = array(
				'ms_files_rewriting'             => null,
				'active_sitewide_plugins'        => array(),
				'_site_transient_update_core'    => null,
				'_site_transient_update_themes'  => null,
				'_site_transient_update_plugins' => null,
				'WPLANG'                         => '',
			);
			foreach ( $values as $key => $value ) {
				WP_CLI::add_wp_hook(
					"pre_site_option_$key",
					function () use ( $values, $key ) {
						return $values[ $key ];
					}
				);
			}
		}

		// Always permit operations against sites, regardless of status
		WP_CLI::add_wp_hook( 'ms_site_check', '__return_true' );

		// Always permit operations against WordPress, regardless of maintenance mode
		WP_CLI::add_wp_hook(
			'enable_maintenance_mode',
			function() {
				return false;
			}
		);

		// Use our own debug mode handling instead of WP core
		WP_CLI::add_wp_hook(
			'enable_wp_debug_mode_checks',
			function( $ret ) {
				Utils\wp_debug_mode();
				return false;
			}
		);

		// Never load advanced-cache.php drop-in when WP-CLI is operating
		WP_CLI::add_wp_hook(
			'enable_loading_advanced_cache_dropin',
			function() {
				return false;
			}
		);

		// In a multisite installation, die if unable to find site given in --url parameter
		if ( $this->is_multisite() ) {
			$run_on_site_not_found = false;
			if ( $this->cmd_starts_with( array( 'cache', 'flush' ) ) ) {
				$run_on_site_not_found = 'cache flush';
			}
			if ( $this->cmd_starts_with( array( 'search-replace' ) ) ) {
				// Table-specified
				// Bits: search-replace <search> <replace> [<table>...]
				// Or not against a specific blog
				if ( count( $this->arguments ) > 3
					|| ! empty( $this->assoc_args['network'] )
					|| ! empty( $this->assoc_args['all-tables'] )
					|| ! empty( $this->assoc_args['all-tables-with-prefix'] ) ) {
					$run_on_site_not_found = 'search-replace';
				}
			}
			if ( $run_on_site_not_found
				&& Utils\wp_version_compare( '4.0', '>=' ) ) {
				WP_CLI::add_wp_hook(
					'ms_site_not_found',
					function() use ( $run_on_site_not_found ) {
						// esc_sql() isn't yet loaded, but needed.
						if ( 'search-replace' === $run_on_site_not_found ) {
							require_once ABSPATH . WPINC . '/formatting.php';
						}
						// PHP 5.3 compatible implementation of run_command_and_exit().
						$runner = WP_CLI::get_runner();
						$runner->run_command( $runner->arguments, $runner->assoc_args );
						exit;
					},
					1
				);
			}
			WP_CLI::add_wp_hook(
				'ms_site_not_found',
				function( $current_site, $domain, $path ) {
					$url         = $domain . $path;
					$message     = $url ? "Site '{$url}' not found." : 'Site not found.';
					$has_param   = isset( WP_CLI::get_runner()->config['url'] );
					$has_const   = defined( 'DOMAIN_CURRENT_SITE' );
					$explanation = '';
					if ( $has_param ) {
						$explanation = 'Verify `--url=<url>` matches an existing site.';
					} else {
						$explanation = "Define DOMAIN_CURRENT_SITE in 'wp-config.php' or use `--url=<url>` to override.";

						if ( $has_const ) {
							$explanation = 'Verify DOMAIN_CURRENT_SITE matches an existing site or use `--url=<url>` to override.';
						}
					}
					if ( $explanation ) {
						$message .= ' ' . $explanation;
					}
					WP_CLI::error( $message );
				},
				10,
				3
			);
		}

		// The APC cache is not available on the command-line, so bail, to prevent cache poisoning
		WP_CLI::add_wp_hook(
			'muplugins_loaded',
			function() {
				if ( $GLOBALS['_wp_using_ext_object_cache'] && class_exists( 'APC_Object_Cache' ) ) {
					WP_CLI::warning( 'Running WP-CLI while the APC object cache is activated can result in cache corruption.' );
					WP_CLI::confirm( 'Given the consequences, do you wish to continue?' );
				}
			},
			0
		);

		// Handle --user parameter
		if ( ! defined( 'WP_INSTALLING' ) ) {
			$config = $this->config;
			WP_CLI::add_wp_hook(
				'init',
				function() use ( $config ) {
					if ( isset( $config['user'] ) ) {
						$fetcher = new \WP_CLI\Fetchers\User();
						$user    = $fetcher->get_check( $config['user'] );
						wp_set_current_user( $user->ID );
					} else {
						add_action( 'init', 'kses_remove_filters', 11 );
					}
				},
				0
			);
		}

		// Avoid uncaught exception when using wp_mail() without defined $_SERVER['SERVER_NAME']
		WP_CLI::add_wp_hook(
			'wp_mail_from',
			function( $from_email ) {
				if ( 'wordpress@' === $from_email ) {
					$sitename = strtolower( Utils\parse_url( site_url(), PHP_URL_HOST ) );
					if ( substr( $sitename, 0, 4 ) === 'www.' ) {
						$sitename = substr( $sitename, 4 );
					}
					$from_email = 'wordpress@' . $sitename;
				}
				return $from_email;
			}
		);

		// Don't apply set_url_scheme in get_site_url()
		WP_CLI::add_wp_hook(
			'site_url',
			function( $url, $path, $scheme, $blog_id ) {
				if ( empty( $blog_id ) || ! is_multisite() ) {
					$url = get_option( 'siteurl' );
				} else {
					switch_to_blog( $blog_id );
					$url = get_option( 'siteurl' );
					restore_current_blog();
				}
				if ( $path && is_string( $path ) ) {
					$url .= '/' . ltrim( $path, '/' );
				}
				return $url;
			},
			0,
			4
		);

		// Set up hook for plugins and themes to conditionally add WP-CLI commands.
		WP_CLI::add_wp_hook(
			'init',
			function () {
				do_action( 'cli_init' );
			}
		);
	}
535948
public function hooks()
    {
        $this->hook->action(
            'show_user_profile',
            [$this->profile, 'fill']
        )->dispatch();

        $this->hook->action(
            'edit_user_profile',
            [$this->profile, 'fill']
        )->dispatch();

        $this->hook->action(
            'personal_options_update',
            [$this->profile, 'save']
        )->dispatch();

        $this->hook->action(
            'edit_user_profile_update',
            [$this->profile, 'save']
        )->dispatch();
    }
250332
private function add_menu_action() {
            if ( $this->is_activation_mode() ) {
                if ( $this->is_plugin() || ( $this->has_settings_menu() && ! $this->is_free_wp_org_theme() ) ) {
                    $this->override_plugin_menu_with_activation();
                } else {
                    /**
                     * Handle theme opt-in when the opt-in form shows as a dialog box in the themes page.
                     */
                    if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) ) {
                        add_action( 'load-themes.php', array( &$this, '_install_with_current_user' ) );
                    } else if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ||
                                fs_request_get_bool( 'pending_activation' )
                    ) {
                        add_action( 'load-themes.php', array( &$this, '_install_with_new_user' ) );
                    }
                }
            } else {
                if ( ! $this->is_registered() ) {
                    // If not registered try to install user.
                    if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) {
                        $this->_install_with_new_user();
                    }
                } else if (
                    fs_request_is_action( 'sync_user' ) &&
                    ( ! $this->has_settings_menu() || $this->is_free_wp_org_theme() )
                ) {
                    $this->_handle_account_user_sync();
                }
            }
        }
1200364
protected function shouldOutput()
    {
        global $current_screen;

        $options = get_option('modularity-options');
        $enabled = isset($options['enabled-post-types']) && is_array($options['enabled-post-types']) ? $options['enabled-post-types'] : array();

        $validPostType = in_array($current_screen->id, $enabled);

        $action = $current_screen->action;
        if (empty($action)) {
            $action = (isset($_GET['action']) && !empty($_GET['action'])) ? $_GET['action'] : null;
        }

        $validAction = in_array($action, array(
            'add',
            'edit'
        ));

        return ($validPostType && $validAction) || $current_screen->id == 'admin_page_modularity-editor';
    }
564188
public function hookCallback()
    {
        $name = $this->getModel()->getName();

        // Check Ajax referer
        check_ajax_referer($name, 'nonce');

        // Call custom callback function
        $data = $this->callback();

        // Build JSON data
        wp_send_json_success($data);

        // Stops everything
        wp_die();
    }
1347619
public function actionAdd() 
	{
		$model=new OmmuPages;

		// Uncomment the following line if AJAX validation is needed
		$this->performAjaxValidation($model);

		if(isset($_POST['OmmuPages'])) {
			$model->attributes=$_POST['OmmuPages'];
			
			if($model->save()) {
				Yii::app()->user->setFlash('success', Yii::t('phrase', 'Pages success created.'));
				$this->redirect(array('manage'));
			}
		}

		$this->pageTitle = Yii::t('phrase', 'Add Page');
		$this->pageDescription = '';
		$this->pageMeta = '';
		$this->render('admin_add', array(
			'model'=>$model,
		));
	}