Completed
Branch feature/397-review-wordlifts-s... (3d685b)
by David
02:44
created
src/admin/wordlift_admin_save_post.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -23,19 +23,19 @@  discard block
 block discarded – undo
23 23
  */
24 24
 function wl_transition_post_status( $new_status, $old_status, $post ) {
25 25
 
26
-	// wl_write_log( "wl_transition_post_status [ new status :: $new_status ][ old status :: $old_status ][ post ID :: $post->ID ]" );
27
-
28
-	// transition from *published* to any other status: delete the post.
29
-	if ( 'publish' === $old_status && 'publish' !== $new_status ) {
30
-		rl_delete_post( $post );
31
-	}
32
-
33
-	// when a post is published, then all the referenced entities must be published.
34
-	if ( 'publish' !== $old_status && 'publish' === $new_status ) {
35
-		foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) {
36
-			wl_update_post_status( $entity_id, 'publish' );
37
-		}
38
-	}
26
+    // wl_write_log( "wl_transition_post_status [ new status :: $new_status ][ old status :: $old_status ][ post ID :: $post->ID ]" );
27
+
28
+    // transition from *published* to any other status: delete the post.
29
+    if ( 'publish' === $old_status && 'publish' !== $new_status ) {
30
+        rl_delete_post( $post );
31
+    }
32
+
33
+    // when a post is published, then all the referenced entities must be published.
34
+    if ( 'publish' !== $old_status && 'publish' === $new_status ) {
35
+        foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) {
36
+            wl_update_post_status( $entity_id, 'publish' );
37
+        }
38
+    }
39 39
 }
40 40
 
41 41
 // hook save events.
@@ -49,49 +49,49 @@  discard block
 block discarded – undo
49 49
  */
50 50
 function rl_delete_post( $post ) {
51 51
 
52
-	$post_id = ( is_numeric( $post ) ? $post : $post->ID );
52
+    $post_id = ( is_numeric( $post ) ? $post : $post->ID );
53 53
 
54
-	// hide all entities that are not referenced by any published post.
55
-	foreach ( wl_core_get_related_entity_ids( $post_id ) as $entity_id ) {
54
+    // hide all entities that are not referenced by any published post.
55
+    foreach ( wl_core_get_related_entity_ids( $post_id ) as $entity_id ) {
56 56
 
57
-		// check if there is at least one referencing post published.
58
-		$is_published = array_reduce( wl_core_get_related_post_ids( $entity_id ), function ( $carry, $item ) {
57
+        // check if there is at least one referencing post published.
58
+        $is_published = array_reduce( wl_core_get_related_post_ids( $entity_id ), function ( $carry, $item ) {
59 59
                     $post = get_post( $item );
60 60
                     return ( $carry || ( 'publish' === $post->post_status ) );
61
-		} );
62
-		// set the entity to draft if no referencing posts are published.
63
-		if ( ! $is_published ) {
64
-			wl_update_post_status( $entity_id, 'draft' );
65
-		}
66
-	}
67
-
68
-	// get the entity URI (valid also for posts)
69
-	$uri_esc = wl_sparql_escape_uri( wl_get_entity_uri( $post_id ) );
70
-
71
-	wl_write_log( "rl_delete_post [ post id :: $post_id ][ uri esc :: $uri_esc ]" );
72
-
73
-	// create the SPARQL statement by joining the SPARQL prefixes and deleting any known predicate.
74
-	$stmt = rl_sparql_prefixes();
75
-	foreach ( wl_predicates() as $predicate ) {
76
-		$stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n" .
77
-		         "DELETE { ?s $predicate <$uri_esc> . } WHERE { ?s $predicate <$uri_esc> . };\n";
78
-	}
79
-
80
-	// if the post is an entity and has exported properties, delete the related predicates.
81
-	if ( Wordlift_Entity_Service::TYPE_NAME === $post->post_type ) {
82
-		$type = wl_entity_type_taxonomy_get_type( $post->ID );
83
-
84
-		if ( isset( $type['custom_fields'] ) ) {
85
-			foreach ( $type['custom_fields'] as $field => $params ) {
86
-				// TODO: enclose in <> only if predicate starts with http(s)://
87
-				$predicate = '<' . $params['predicate'] . '>';
88
-				$stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n";
89
-			}
90
-		}
91
-	}
92
-
93
-	// finally execute the query.
94
-	rl_execute_sparql_update_query( $stmt );
61
+        } );
62
+        // set the entity to draft if no referencing posts are published.
63
+        if ( ! $is_published ) {
64
+            wl_update_post_status( $entity_id, 'draft' );
65
+        }
66
+    }
67
+
68
+    // get the entity URI (valid also for posts)
69
+    $uri_esc = wl_sparql_escape_uri( wl_get_entity_uri( $post_id ) );
70
+
71
+    wl_write_log( "rl_delete_post [ post id :: $post_id ][ uri esc :: $uri_esc ]" );
72
+
73
+    // create the SPARQL statement by joining the SPARQL prefixes and deleting any known predicate.
74
+    $stmt = rl_sparql_prefixes();
75
+    foreach ( wl_predicates() as $predicate ) {
76
+        $stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n" .
77
+                    "DELETE { ?s $predicate <$uri_esc> . } WHERE { ?s $predicate <$uri_esc> . };\n";
78
+    }
79
+
80
+    // if the post is an entity and has exported properties, delete the related predicates.
81
+    if ( Wordlift_Entity_Service::TYPE_NAME === $post->post_type ) {
82
+        $type = wl_entity_type_taxonomy_get_type( $post->ID );
83
+
84
+        if ( isset( $type['custom_fields'] ) ) {
85
+            foreach ( $type['custom_fields'] as $field => $params ) {
86
+                // TODO: enclose in <> only if predicate starts with http(s)://
87
+                $predicate = '<' . $params['predicate'] . '>';
88
+                $stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n";
89
+            }
90
+        }
91
+    }
92
+
93
+    // finally execute the query.
94
+    rl_execute_sparql_update_query( $stmt );
95 95
 }
96 96
 
97 97
 /**
@@ -102,34 +102,34 @@  discard block
 block discarded – undo
102 102
  */
103 103
 function wl_update_post_status( $post_id, $status ) {
104 104
 
105
-	wl_write_log( "wl_update_post_status [ post ID :: $post_id ][ status :: $status ]" );
105
+    wl_write_log( "wl_update_post_status [ post ID :: $post_id ][ status :: $status ]" );
106 106
 
107
-	global $wpdb;
107
+    global $wpdb;
108 108
 
109
-	if ( ! $post = get_post( $post_id ) ) {
110
-		return;
111
-	}
109
+    if ( ! $post = get_post( $post_id ) ) {
110
+        return;
111
+    }
112 112
 
113
-	if ( $status === $post->post_status ) {
114
-		return;
115
-	}
113
+    if ( $status === $post->post_status ) {
114
+        return;
115
+    }
116 116
 
117
-	$wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) );
117
+    $wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) );
118 118
 
119
-	clean_post_cache( $post->ID );
119
+    clean_post_cache( $post->ID );
120 120
 
121
-	$old_status        = $post->post_status;
122
-	$post->post_status = $status;
121
+    $old_status        = $post->post_status;
122
+    $post->post_status = $status;
123 123
 
124
-	wp_transition_post_status( $status, $old_status, $post );
124
+    wp_transition_post_status( $status, $old_status, $post );
125 125
 
126
-	/** This action is documented in wp-includes/post.php */
127
-	do_action( 'edit_post', $post->ID, $post );
128
-	/** This action is documented in wp-includes/post.php */
129
-	do_action( "save_post_{$post->post_type}", $post->ID, $post, true );
130
-	/** This action is documented in wp-includes/post.php */
131
-	do_action( 'wl_linked_data_save_post', $post->ID );
132
-	/** This action is documented in wp-includes/post.php */
133
-	do_action( 'wp_insert_post', $post->ID, $post, true );
126
+    /** This action is documented in wp-includes/post.php */
127
+    do_action( 'edit_post', $post->ID, $post );
128
+    /** This action is documented in wp-includes/post.php */
129
+    do_action( "save_post_{$post->post_type}", $post->ID, $post, true );
130
+    /** This action is documented in wp-includes/post.php */
131
+    do_action( 'wl_linked_data_save_post', $post->ID );
132
+    /** This action is documented in wp-includes/post.php */
133
+    do_action( 'wp_insert_post', $post->ID, $post, true );
134 134
 }
135 135
 
Please login to merge, or discard this patch.
src/admin/wordlift_admin_shortcodes.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -9,12 +9,12 @@  discard block
 block discarded – undo
9 9
  * Loads the buttons in TinyMCE.
10 10
  */
11 11
 function wl_admin_shortcode_buttons() {
12
-	// Only add hooks when the current user has permissions AND is in Rich Text editor mode
13
-	if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) {
14
-		add_filter( 'mce_external_plugins', 'wl_admin_shortcode_buttons_register_tinymce_javascript' );
15
-		add_filter( 'mce_buttons', 'wl_admin_shortcode_register_buttons' );
16
-		add_action( 'admin_footer', 'wl_admin_inject_chord_dialog_dependencies' );
17
-	}
12
+    // Only add hooks when the current user has permissions AND is in Rich Text editor mode
13
+    if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) {
14
+        add_filter( 'mce_external_plugins', 'wl_admin_shortcode_buttons_register_tinymce_javascript' );
15
+        add_filter( 'mce_buttons', 'wl_admin_shortcode_register_buttons' );
16
+        add_action( 'admin_footer', 'wl_admin_inject_chord_dialog_dependencies' );
17
+    }
18 18
 }
19 19
 
20 20
 /**
@@ -26,9 +26,9 @@  discard block
 block discarded – undo
26 26
  */
27 27
 function wl_admin_shortcode_buttons_register_tinymce_javascript( $plugin_array ) {
28 28
 
29
-	$plugin_array['wl_shortcodes'] = plugin_dir_url( __FILE__ ) . 'js/wordlift_shortcode_tinymce_plugin.js';
29
+    $plugin_array['wl_shortcodes'] = plugin_dir_url( __FILE__ ) . 'js/wordlift_shortcode_tinymce_plugin.js';
30 30
 
31
-	return $plugin_array;
31
+    return $plugin_array;
32 32
 }
33 33
 
34 34
 /**
@@ -39,9 +39,9 @@  discard block
 block discarded – undo
39 39
  * @return array The buttons array including the *wl_shortcodes_menu*.
40 40
  */
41 41
 function wl_admin_shortcode_register_buttons( $buttons ) {
42
-	array_push( $buttons, 'wl_shortcodes_menu' );
42
+    array_push( $buttons, 'wl_shortcodes_menu' );
43 43
 
44
-	return $buttons;
44
+    return $buttons;
45 45
 }
46 46
 
47 47
 // init process for button control
@@ -55,16 +55,16 @@  discard block
 block discarded – undo
55 55
  */
56 56
 function wl_admin_inject_chord_dialog_dependencies() {
57 57
 
58
-	wp_enqueue_style( 'wp-color-picker' );
59
-	wp_enqueue_script( 'wp-color-picker' );
60
-	wp_enqueue_style( 'jquery-ui-slider' );
61
-	// Not included by default :|
62
-	// TODO include jquery ui css from the plugin creates css issues on the slider
63
-	// wp_enqueue_style('jquery-ui-css', plugins_url( 'css/jquery-ui/jquery-ui.min.css', __FILE__ ) );
64
-	wp_enqueue_style( 'wp-jquery-ui-css', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.all.css' );
58
+    wp_enqueue_style( 'wp-color-picker' );
59
+    wp_enqueue_script( 'wp-color-picker' );
60
+    wp_enqueue_style( 'jquery-ui-slider' );
61
+    // Not included by default :|
62
+    // TODO include jquery ui css from the plugin creates css issues on the slider
63
+    // wp_enqueue_style('jquery-ui-css', plugins_url( 'css/jquery-ui/jquery-ui.min.css', __FILE__ ) );
64
+    wp_enqueue_style( 'wp-jquery-ui-css', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.all.css' );
65 65
 
66
-	wp_enqueue_script( 'jquery' );
67
-	wp_enqueue_script( 'jquery-ui-core' );
68
-	wp_enqueue_script( 'jquery-ui-slider' );
66
+    wp_enqueue_script( 'jquery' );
67
+    wp_enqueue_script( 'jquery-ui-core' );
68
+    wp_enqueue_script( 'jquery-ui-slider' );
69 69
 
70 70
 }
Please login to merge, or discard this patch.
src/admin/wordlift_admin_sync.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -9,20 +9,20 @@  discard block
 block discarded – undo
9 9
  */
10 10
 function wl_admin_sync_to_redlink() {
11 11
 
12
-	$posts = get_posts( array(
13
-		'post_type'      => 'any',
14
-		'posts_per_page' => - 1
15
-	) );
12
+    $posts = get_posts( array(
13
+        'post_type'      => 'any',
14
+        'posts_per_page' => - 1
15
+    ) );
16 16
 
17
-	wl_write_log( "wl_admin_sync_to_redlink [ post count :: " . sizeof( $posts ) . " ]" );
17
+    wl_write_log( "wl_admin_sync_to_redlink [ post count :: " . sizeof( $posts ) . " ]" );
18 18
 
19
-	foreach ( $posts as $post ) {
20
-		echo esc_html( $post->post_title ) . '<br/>';
21
-		wl_linked_data_push_to_redlink( $post->ID );
22
-	}
19
+    foreach ( $posts as $post ) {
20
+        echo esc_html( $post->post_title ) . '<br/>';
21
+        wl_linked_data_push_to_redlink( $post->ID );
22
+    }
23 23
 
24
-	// Schedule the execution of SPARQL.
25
-	wl_shutdown();
24
+    // Schedule the execution of SPARQL.
25
+    wl_shutdown();
26 26
 }
27 27
 
28 28
 /**
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
  */
31 31
 function wl_admin_ajax_sync_to_redlink() {
32 32
 
33
-	// TODO: check appropriate permissions here.
34
-	wl_admin_sync_to_redlink();
35
-	die();
33
+    // TODO: check appropriate permissions here.
34
+    wl_admin_sync_to_redlink();
35
+    die();
36 36
 
37 37
 }
38 38
 
Please login to merge, or discard this patch.
src/includes/class-wordlift-activator.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -22,15 +22,15 @@
 block discarded – undo
22 22
  */
23 23
 class Wordlift_Activator {
24 24
 
25
-	/**
26
-	 * Short Description. (use period)
27
-	 *
28
-	 * Long Description.
29
-	 *
30
-	 * @since    1.0.0
31
-	 */
32
-	public static function activate() {
25
+    /**
26
+     * Short Description. (use period)
27
+     *
28
+     * Long Description.
29
+     *
30
+     * @since    1.0.0
31
+     */
32
+    public static function activate() {
33 33
 
34
-	}
34
+    }
35 35
 
36 36
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-deactivator.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -22,15 +22,15 @@
 block discarded – undo
22 22
  */
23 23
 class Wordlift_Deactivator {
24 24
 
25
-	/**
26
-	 * Short Description. (use period)
27
-	 *
28
-	 * Long Description.
29
-	 *
30
-	 * @since    1.0.0
31
-	 */
32
-	public static function deactivate() {
25
+    /**
26
+     * Short Description. (use period)
27
+     *
28
+     * Long Description.
29
+     *
30
+     * @since    1.0.0
31
+     */
32
+    public static function deactivate() {
33 33
 
34
-	}
34
+    }
35 35
 
36 36
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-entity-types-taxonomy-service.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -7,6 +7,6 @@
 block discarded – undo
7 7
  */
8 8
 class Wordlift_Entity_Types_Taxonomy_Service {
9 9
 
10
-	const TAXONOMY_NAME = 'wl_entity_type';
10
+    const TAXONOMY_NAME = 'wl_entity_type';
11 11
 
12 12
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-i18n.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -26,38 +26,38 @@
 block discarded – undo
26 26
  */
27 27
 class Wordlift_i18n {
28 28
 
29
-	/**
30
-	 * The domain specified for this plugin.
31
-	 *
32
-	 * @since    1.0.0
33
-	 * @access   private
34
-	 * @var      string    $domain    The domain identifier for this plugin.
35
-	 */
36
-	private $domain;
37
-
38
-	/**
39
-	 * Load the plugin text domain for translation.
40
-	 *
41
-	 * @since    1.0.0
42
-	 */
43
-	public function load_plugin_textdomain() {
44
-
45
-		load_plugin_textdomain(
46
-			$this->domain,
47
-			false,
48
-			dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
49
-		);
50
-
51
-	}
52
-
53
-	/**
54
-	 * Set the domain equal to that of the specified domain.
55
-	 *
56
-	 * @since    1.0.0
57
-	 * @param    string    $domain    The domain that represents the locale of this plugin.
58
-	 */
59
-	public function set_domain( $domain ) {
60
-		$this->domain = $domain;
61
-	}
29
+    /**
30
+     * The domain specified for this plugin.
31
+     *
32
+     * @since    1.0.0
33
+     * @access   private
34
+     * @var      string    $domain    The domain identifier for this plugin.
35
+     */
36
+    private $domain;
37
+
38
+    /**
39
+     * Load the plugin text domain for translation.
40
+     *
41
+     * @since    1.0.0
42
+     */
43
+    public function load_plugin_textdomain() {
44
+
45
+        load_plugin_textdomain(
46
+            $this->domain,
47
+            false,
48
+            dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
49
+        );
50
+
51
+    }
52
+
53
+    /**
54
+     * Set the domain equal to that of the specified domain.
55
+     *
56
+     * @since    1.0.0
57
+     * @param    string    $domain    The domain that represents the locale of this plugin.
58
+     */
59
+    public function set_domain( $domain ) {
60
+        $this->domain = $domain;
61
+    }
62 62
 
63 63
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-loader.php 1 patch
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -23,107 +23,107 @@
 block discarded – undo
23 23
  */
24 24
 class Wordlift_Loader {
25 25
 
26
-	/**
27
-	 * The array of actions registered with WordPress.
28
-	 *
29
-	 * @since    1.0.0
30
-	 * @access   protected
31
-	 * @var      array    $actions    The actions registered with WordPress to fire when the plugin loads.
32
-	 */
33
-	protected $actions;
34
-
35
-	/**
36
-	 * The array of filters registered with WordPress.
37
-	 *
38
-	 * @since    1.0.0
39
-	 * @access   protected
40
-	 * @var      array    $filters    The filters registered with WordPress to fire when the plugin loads.
41
-	 */
42
-	protected $filters;
43
-
44
-	/**
45
-	 * Initialize the collections used to maintain the actions and filters.
46
-	 *
47
-	 * @since    1.0.0
48
-	 */
49
-	public function __construct() {
50
-
51
-		$this->actions = array();
52
-		$this->filters = array();
53
-
54
-	}
55
-
56
-	/**
57
-	 * Add a new action to the collection to be registered with WordPress.
58
-	 *
59
-	 * @since    1.0.0
60
-	 * @param    string               $hook             The name of the WordPress action that is being registered.
61
-	 * @param    object               $component        A reference to the instance of the object on which the action is defined.
62
-	 * @param    string               $callback         The name of the function definition on the $component.
63
-	 * @param    int                  $priority         Optional. he priority at which the function should be fired. Default is 10.
64
-	 * @param    int                  $accepted_args    Optional. The number of arguments that should be passed to the $callback. Default is 1.
65
-	 */
66
-	public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
67
-		$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
68
-	}
69
-
70
-	/**
71
-	 * Add a new filter to the collection to be registered with WordPress.
72
-	 *
73
-	 * @since    1.0.0
74
-	 * @param    string               $hook             The name of the WordPress filter that is being registered.
75
-	 * @param    object               $component        A reference to the instance of the object on which the filter is defined.
76
-	 * @param    string               $callback         The name of the function definition on the $component.
77
-	 * @param    int                  $priority         Optional. he priority at which the function should be fired. Default is 10.
78
-	 * @param    int                  $accepted_args    Optional. The number of arguments that should be passed to the $callback. Default is 1
79
-	 */
80
-	public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
81
-		$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
82
-	}
83
-
84
-	/**
85
-	 * A utility function that is used to register the actions and hooks into a single
86
-	 * collection.
87
-	 *
88
-	 * @since    1.0.0
89
-	 * @access   private
90
-	 * @param    array                $hooks            The collection of hooks that is being registered (that is, actions or filters).
91
-	 * @param    string               $hook             The name of the WordPress filter that is being registered.
92
-	 * @param    object               $component        A reference to the instance of the object on which the filter is defined.
93
-	 * @param    string               $callback         The name of the function definition on the $component.
94
-	 * @param    int                  $priority         The priority at which the function should be fired.
95
-	 * @param    int                  $accepted_args    The number of arguments that should be passed to the $callback.
96
-	 * @return   array                                  The collection of actions and filters registered with WordPress.
97
-	 */
98
-	private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
99
-
100
-		$hooks[] = array(
101
-			'hook'          => $hook,
102
-			'component'     => $component,
103
-			'callback'      => $callback,
104
-			'priority'      => $priority,
105
-			'accepted_args' => $accepted_args
106
-		);
107
-
108
-		return $hooks;
109
-
110
-	}
111
-
112
-	/**
113
-	 * Register the filters and actions with WordPress.
114
-	 *
115
-	 * @since    1.0.0
116
-	 */
117
-	public function run() {
118
-
119
-		foreach ( $this->filters as $hook ) {
120
-			add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
121
-		}
122
-
123
-		foreach ( $this->actions as $hook ) {
124
-			add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
125
-		}
126
-
127
-	}
26
+    /**
27
+     * The array of actions registered with WordPress.
28
+     *
29
+     * @since    1.0.0
30
+     * @access   protected
31
+     * @var      array    $actions    The actions registered with WordPress to fire when the plugin loads.
32
+     */
33
+    protected $actions;
34
+
35
+    /**
36
+     * The array of filters registered with WordPress.
37
+     *
38
+     * @since    1.0.0
39
+     * @access   protected
40
+     * @var      array    $filters    The filters registered with WordPress to fire when the plugin loads.
41
+     */
42
+    protected $filters;
43
+
44
+    /**
45
+     * Initialize the collections used to maintain the actions and filters.
46
+     *
47
+     * @since    1.0.0
48
+     */
49
+    public function __construct() {
50
+
51
+        $this->actions = array();
52
+        $this->filters = array();
53
+
54
+    }
55
+
56
+    /**
57
+     * Add a new action to the collection to be registered with WordPress.
58
+     *
59
+     * @since    1.0.0
60
+     * @param    string               $hook             The name of the WordPress action that is being registered.
61
+     * @param    object               $component        A reference to the instance of the object on which the action is defined.
62
+     * @param    string               $callback         The name of the function definition on the $component.
63
+     * @param    int                  $priority         Optional. he priority at which the function should be fired. Default is 10.
64
+     * @param    int                  $accepted_args    Optional. The number of arguments that should be passed to the $callback. Default is 1.
65
+     */
66
+    public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
67
+        $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
68
+    }
69
+
70
+    /**
71
+     * Add a new filter to the collection to be registered with WordPress.
72
+     *
73
+     * @since    1.0.0
74
+     * @param    string               $hook             The name of the WordPress filter that is being registered.
75
+     * @param    object               $component        A reference to the instance of the object on which the filter is defined.
76
+     * @param    string               $callback         The name of the function definition on the $component.
77
+     * @param    int                  $priority         Optional. he priority at which the function should be fired. Default is 10.
78
+     * @param    int                  $accepted_args    Optional. The number of arguments that should be passed to the $callback. Default is 1
79
+     */
80
+    public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
81
+        $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
82
+    }
83
+
84
+    /**
85
+     * A utility function that is used to register the actions and hooks into a single
86
+     * collection.
87
+     *
88
+     * @since    1.0.0
89
+     * @access   private
90
+     * @param    array                $hooks            The collection of hooks that is being registered (that is, actions or filters).
91
+     * @param    string               $hook             The name of the WordPress filter that is being registered.
92
+     * @param    object               $component        A reference to the instance of the object on which the filter is defined.
93
+     * @param    string               $callback         The name of the function definition on the $component.
94
+     * @param    int                  $priority         The priority at which the function should be fired.
95
+     * @param    int                  $accepted_args    The number of arguments that should be passed to the $callback.
96
+     * @return   array                                  The collection of actions and filters registered with WordPress.
97
+     */
98
+    private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
99
+
100
+        $hooks[] = array(
101
+            'hook'          => $hook,
102
+            'component'     => $component,
103
+            'callback'      => $callback,
104
+            'priority'      => $priority,
105
+            'accepted_args' => $accepted_args
106
+        );
107
+
108
+        return $hooks;
109
+
110
+    }
111
+
112
+    /**
113
+     * Register the filters and actions with WordPress.
114
+     *
115
+     * @since    1.0.0
116
+     */
117
+    public function run() {
118
+
119
+        foreach ( $this->filters as $hook ) {
120
+            add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
121
+        }
122
+
123
+        foreach ( $this->actions as $hook ) {
124
+            add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
125
+        }
126
+
127
+    }
128 128
 
129 129
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-log-service.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -7,89 +7,89 @@
 block discarded – undo
7 7
  */
8 8
 class Wordlift_Log_Service {
9 9
 
10
-	const MESSAGE_TEMPLATE = '%-6s [%-40.40s] %s';
10
+    const MESSAGE_TEMPLATE = '%-6s [%-40.40s] %s';
11 11
 
12
-	const ERROR = 'ERROR';
13
-	const WARN = 'WARN';
14
-	const INFO = 'INFO';
15
-	const DEBUG = 'DEBUG';
16
-	const TRACE = 'TRACE';
12
+    const ERROR = 'ERROR';
13
+    const WARN = 'WARN';
14
+    const INFO = 'INFO';
15
+    const DEBUG = 'DEBUG';
16
+    const TRACE = 'TRACE';
17 17
 
18 18
 
19
-	/**
20
-	 * The class related to the logs.
21
-	 *
22
-	 * @since 1.0.0
23
-	 * @access private
24
-	 * @var string $class_name The class related to the logs.
25
-	 */
26
-	private $class_name;
19
+    /**
20
+     * The class related to the logs.
21
+     *
22
+     * @since 1.0.0
23
+     * @access private
24
+     * @var string $class_name The class related to the logs.
25
+     */
26
+    private $class_name;
27 27
 
28
-	/**
29
-	 * Create an instance of the Log service.
30
-	 * @since 1.0.0
31
-	 *
32
-	 * @param string $class_name The class related to the logs.
33
-	 */
34
-	public function __construct( $class_name ) {
28
+    /**
29
+     * Create an instance of the Log service.
30
+     * @since 1.0.0
31
+     *
32
+     * @param string $class_name The class related to the logs.
33
+     */
34
+    public function __construct( $class_name ) {
35 35
 
36
-		$this->class_name = $class_name;
36
+        $this->class_name = $class_name;
37 37
 
38
-	}
38
+    }
39 39
 
40
-	public static function get_logger( $class_name ) {
40
+    public static function get_logger( $class_name ) {
41 41
 
42
-		return new Wordlift_Log_Service( $class_name );
42
+        return new Wordlift_Log_Service( $class_name );
43 43
 
44
-	}
44
+    }
45 45
 
46
-	/**
47
-	 * Log a message.
48
-	 *
49
-	 * @since 1.0.0
50
-	 *
51
-	 * @param string $level The log level.
52
-	 * @param string $message The message to log.
53
-	 */
54
-	public function log( $level, $message ) {
46
+    /**
47
+     * Log a message.
48
+     *
49
+     * @since 1.0.0
50
+     *
51
+     * @param string $level The log level.
52
+     * @param string $message The message to log.
53
+     */
54
+    public function log( $level, $message ) {
55 55
 
56
-		// If we're tracing or debugging, but the debug flag isn't set, then we don't log.
57
-		if ( ( self::TRACE === $level || self::DEBUG === $level ) && ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) ) {
58
-			return;
59
-		}
56
+        // If we're tracing or debugging, but the debug flag isn't set, then we don't log.
57
+        if ( ( self::TRACE === $level || self::DEBUG === $level ) && ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) ) {
58
+            return;
59
+        }
60 60
 
61
-		error_log( sprintf( self::MESSAGE_TEMPLATE, $level, $this->class_name, $message ) );
61
+        error_log( sprintf( self::MESSAGE_TEMPLATE, $level, $this->class_name, $message ) );
62 62
 
63
-	}
63
+    }
64 64
 
65
-	public function error( $message ) {
65
+    public function error( $message ) {
66 66
 
67
-		$this->log( self::ERROR, $message );
67
+        $this->log( self::ERROR, $message );
68 68
 
69
-	}
69
+    }
70 70
 
71
-	public function warn( $message ) {
71
+    public function warn( $message ) {
72 72
 
73
-		$this->log( self::WARN, $message );
73
+        $this->log( self::WARN, $message );
74 74
 
75
-	}
75
+    }
76 76
 
77
-	public function info( $message ) {
77
+    public function info( $message ) {
78 78
 
79
-		$this->log( self::INFO, $message );
79
+        $this->log( self::INFO, $message );
80 80
 
81
-	}
81
+    }
82 82
 
83
-	public function debug( $message ) {
83
+    public function debug( $message ) {
84 84
 
85
-		$this->log( self::DEBUG, $message );
85
+        $this->log( self::DEBUG, $message );
86 86
 
87
-	}
87
+    }
88 88
 
89
-	public function trace( $message ) {
89
+    public function trace( $message ) {
90 90
 
91
-		$this->log( self::TRACE, $message );
91
+        $this->log( self::TRACE, $message );
92 92
 
93
-	}
93
+    }
94 94
 
95 95
 }
Please login to merge, or discard this patch.